@@ -22,15 +22,16 @@ public class AssetCreationMenu : UnityEditor.Editor
2222 private const string NoArgsSOEventListenerTemplatePath = "/CustomScriptTemplates/NoArgsSOEventListenerTemplate.txt" ;
2323
2424 private static string _packageRelativePath ;
25+ private static UnityEditor . PackageManager . PackageInfo _packageInfo ;
2526
26- private class IconReplacementClass : UnityEditor . Editor
27+ private class EditorAssetIconReplacer : UnityEditor . Editor
2728 {
2829 public IEnumerator AddIcon ( string scriptPath , string iconName )
2930 {
3031 AssetDatabase . Refresh ( ) ;
3132
3233 yield return null ; //Wait just for one editor frame
33-
34+
3435 var monoImporter = AssetImporter . GetAtPath ( scriptPath ) as MonoImporter ;
3536 var icon = AssetDatabase . LoadAssetAtPath < Texture2D > ( _packageRelativePath + iconName ) ;
3637 monoImporter . SetIcon ( icon ) ;
@@ -41,7 +42,7 @@ public IEnumerator AddIcon(string scriptPath, string iconName)
4142 [ MenuItem ( "Assets/Create/EspidiGames/SO Events/So Event Creation Window" , false , 0 ) ]
4243 static void OpenScriptableObjectEventCreationWindow ( )
4344 {
44- SetPackageName ( ) ;
45+ SetPackageData ( ) ;
4546 ScriptableObjectEventCreationWindow . OpenWindow ( ) ;
4647 }
4748
@@ -126,7 +127,7 @@ private static void CreateSOEventScript(string creationPath, string eventName, s
126127
127128 //5-Add Custom Icon:
128129 var filePathInProject = GetPathInProjectAssets ( filePath ) ;
129- var iconClass = new IconReplacementClass ( ) ;
130+ var iconClass = new EditorAssetIconReplacer ( ) ;
130131 EditorCoroutineUtility . StartCoroutineOwnerless ( iconClass . AddIcon ( filePathInProject , EventIconRelativepath ) ) ;
131132 }
132133
@@ -172,7 +173,7 @@ private static void CreateSOEventListenerScript(string creationPath, string even
172173
173174 //5-Add Custom Icon:
174175 var filePathInProject = GetPathInProjectAssets ( filePath ) ;
175- var iconClass = new IconReplacementClass ( ) ;
176+ var iconClass = new EditorAssetIconReplacer ( ) ;
176177 EditorCoroutineUtility . StartCoroutineOwnerless ( iconClass . AddIcon ( filePathInProject , EventListenerIconRelativePath ) ) ;
177178 }
178179
@@ -234,14 +235,17 @@ private static string[] GenerateEventArguments(ArgInfo[] argsList)
234235
235236 private static string GetPathInProjectAssets ( string fullPath )
236237 {
238+ const string AssetsFolder = "Assets" ;
239+ const string PackagesFolder = "Packages" ;
240+
237241 var splitPath = fullPath . Split ( Path . DirectorySeparatorChar ) ;
238242
239243 var sb = new StringBuilder ( ) ;
240244 var flag = false ;
241245
242246 for ( int i = 0 ; i < splitPath . Length ; i ++ )
243247 {
244- if ( splitPath [ i ] == "Assets" || splitPath [ i ] == "Packages" )
248+ if ( splitPath [ i ] == AssetsFolder || splitPath [ i ] == PackagesFolder )
245249 {
246250 flag = true ;
247251 }
@@ -256,13 +260,21 @@ private static string GetPathInProjectAssets(string fullPath)
256260 }
257261 }
258262
259- return sb . ToString ( ) ;
263+ var path = sb . ToString ( ) ;
264+
265+ if ( path . StartsWith ( PackagesFolder ) )
266+ {
267+ path = path . Replace ( _packageInfo . displayName , _packageInfo . name ) ;
268+ }
269+
270+ return path ;
260271 }
261272
262- private static void SetPackageName ( )
273+ private static void SetPackageData ( )
263274 {
264275 var assembly = typeof ( AssetCreationMenu ) . Assembly ;
265276 var packageInfo = UnityEditor . PackageManager . PackageInfo . FindForAssembly ( assembly ) ;
277+ _packageInfo = UnityEditor . PackageManager . PackageInfo . FindForAssembly ( assembly ) ;
266278 _packageRelativePath = string . Format ( PackageRelativePathPattern , packageInfo . name ) ;
267279 }
268280 }
0 commit comments