@@ -8,26 +8,7 @@ namespace Giezi.Tools
88{
99 public static class SOContextMenu
1010 {
11- private static SOData _soData = null ;
12-
13- public static SOData SOData
14- {
15- get
16- {
17- if ( _soData == null )
18- {
19- Debug . Log ( AssetDatabase . GUIDToAssetPath ( "50b31bd74d19a40b293ceaeefd1c650e" ) ) ;
20- _soData = AssetDatabase . LoadAssetAtPath < SOData > (
21- AssetDatabase . GUIDToAssetPath ( "50b31bd74d19a40b293ceaeefd1c650e" ) ) ;
22- Debug . Log ( _soData ) ;
23- }
24- return _soData ;
25- }
26- }
2711
28- // private const string GieziToolsCreateSOvariantChildKey = "Giezi.Tools.CreateSoVariant.Child";
29- // private const string GieziToolsCreateSOvariantParentKey = "Giezi.Tools.CreateSoVariant.Parent";
30-
3112 [ MenuItem ( "Assets/Create/Create SO Variant" , false , 2000 ) ]
3213 static void CreateSOVariant ( )
3314 {
@@ -36,65 +17,38 @@ static void CreateSOVariant()
3617
3718 string assetPath = AssetDatabase . GetAssetPath ( activeObject ) ;
3819 string newAssetPath = GetNewAssetName ( assetPath ) ;
39-
20+
4021 ScriptableObject newAsset = ScriptableObject . CreateInstance ( soType ) ;
4122
4223 AssetDatabase . CreateAsset ( newAsset , newAssetPath ) ;
4324 EditorUtility . SetDirty ( newAsset ) ;
4425
45- // PlayerPrefs.SetString(GieziToolsCreateSOvariantChildKey, newAssetPath);
46- // PlayerPrefs.SetString(GieziToolsCreateSOvariantParentKey, assetPath);
47- SOData . SOVariantCreationData = new SOVariantCreationData ( ( ScriptableObject ) activeObject , newAsset ) ;
48-
49- EditorUtility . SetDirty ( SOData ) ;
26+ SOVariantHelper < ScriptableObject > . SetParent ( newAsset , ( ScriptableObject ) activeObject ) ;
5027
5128 AssetDatabase . SaveAssets ( ) ;
52-
53- AssetDatabase . Refresh ( ) ;
54- EditorUtility . RequestScriptReload ( ) ;
5529 }
56-
30+
5731 [ MenuItem ( "Assets/Create/Create SO Variant" , true ) ]
5832 static bool ValidateCreateSOVariant ( )
5933 {
6034 return ( Selection . activeObject is ScriptableObject &&
6135 Selection . activeObject . GetType ( ) . IsDefined ( typeof ( SOVariantAttribute ) , true ) ) ;
6236 }
63-
64- [ UnityEditor . Callbacks . DidReloadScripts ]
65- static void SetParentAfterReload ( )
66- {
67- if ( SOData . SOVariantCreationData == null || ! SOData . SOVariantCreationData . CreateSoVariant )
68- return ;
69-
70- if ( SOData . SOVariantCreationData . Child == null )
71- return ;
72-
73- ScriptableObject parent = SOData . SOVariantCreationData . Parent ;
74- ScriptableObject child = SOData . SOVariantCreationData . Child ;
75-
76-
77- SOVariantHelper < ScriptableObject > . SetParent ( child , parent ) ;
78-
79- SOData . SOVariantCreationData = null ;
80-
81- Debug . Log ( $ "<color=orange>SOVariant: </color>Created new SO Variant { child . name } with parent.") ;
82- }
83-
37+
8438 private static string GetNewAssetName ( string assetPath )
8539 {
8640 string newAssetPath = Path . Combine ( Path . GetDirectoryName ( assetPath ) ,
8741 Path . GetFileNameWithoutExtension ( assetPath ) + " Variant" + Path . GetExtension ( assetPath ) ) ;
88-
42+
8943 int counter = 0 ;
90-
44+
9145 while ( AssetDatabase . LoadAssetAtPath < ScriptableObject > ( newAssetPath ) != null )
9246 {
9347 counter ++ ;
9448 newAssetPath = Path . Combine ( Path . GetDirectoryName ( assetPath ) ,
9549 Path . GetFileNameWithoutExtension ( assetPath ) + " Variant_" + counter + Path . GetExtension ( assetPath ) ) ;
9650 }
97-
51+
9852 return newAssetPath ;
9953 }
10054 }
0 commit comments