Skip to content

Commit 4a49d04

Browse files
committed
Removed editor coroutine and relying on editor delayed call instead
1 parent 1c5f602 commit 4a49d04

1 file changed

Lines changed: 13 additions & 11 deletions

File tree

Editor/AssetCreationMenu.cs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,8 @@
44
using System.IO;
55
using UnityEngine.Assertions;
66
using System.Text;
7-
using System.Collections;
87
using System.Linq;
98
using System.Text.RegularExpressions;
10-
using Unity.EditorCoroutines.Editor;
119

1210
namespace EG.ScriptableObjectSystem.Editor
1311
{
@@ -26,16 +24,20 @@ public class AssetCreationMenu : UnityEditor.Editor
2624

2725
private class EditorAssetIconReplacer : UnityEditor.Editor
2826
{
29-
public IEnumerator AddIcon(string scriptPath, string iconName)
27+
public void EditScriptIcon(string scriptPath, string iconName)
3028
{
29+
EditorApplication.delayCall += EditScriptIconInternal;
3130
AssetDatabase.Refresh();
32-
33-
yield return null; //Wait just for one editor frame
3431

35-
var monoImporter = AssetImporter.GetAtPath(scriptPath) as MonoImporter;
36-
var icon = AssetDatabase.LoadAssetAtPath<Texture2D>(_packageRelativePath + iconName);
37-
monoImporter.SetIcon(icon);
38-
monoImporter.SaveAndReimport();
32+
void EditScriptIconInternal()
33+
{
34+
EditorApplication.delayCall -= EditScriptIconInternal;
35+
36+
var monoImporter = AssetImporter.GetAtPath(scriptPath) as MonoImporter;
37+
var icon = AssetDatabase.LoadAssetAtPath<Texture2D>(_packageRelativePath + iconName);
38+
monoImporter.SetIcon(icon);
39+
monoImporter.SaveAndReimport();
40+
}
3941
}
4042
}
4143

@@ -126,7 +128,7 @@ private static void CreateSOEventScript(string creationPath, string eventName, s
126128
//5-Add Custom Icon:
127129
var filePathInProject = GetPathInProjectAssets(filePath);
128130
var iconClass = new EditorAssetIconReplacer();
129-
EditorCoroutineUtility.StartCoroutineOwnerless(iconClass.AddIcon(filePathInProject, EventIconRelativepath));
131+
iconClass.EditScriptIcon(filePathInProject, EventIconRelativepath);
130132
}
131133

132134
private static void CreateSOEventListenerScript(string creationPath, string eventName, string listenerName, string eventNamespace, string[] argTypes)
@@ -169,7 +171,7 @@ private static void CreateSOEventListenerScript(string creationPath, string even
169171
//5-Add Custom Icon:
170172
var filePathInProject = GetPathInProjectAssets(filePath);
171173
var iconClass = new EditorAssetIconReplacer();
172-
EditorCoroutineUtility.StartCoroutineOwnerless(iconClass.AddIcon(filePathInProject, EventListenerIconRelativePath));
174+
iconClass.EditScriptIcon(filePathInProject, EventListenerIconRelativePath);
173175
}
174176

175177
private static string ReplaceNamespaceTag(string eventNamespace, string contents)

0 commit comments

Comments
 (0)