Skip to content

Commit c9d070d

Browse files
authored
Merge pull request #4 from danigfedev/Edit_Script_Icon_Bugfix
Edit script icon bugfix and removed Editor coroutines dependencies
2 parents 1c5f602 + 0c72f55 commit c9d070d

File tree

4 files changed

+20
-32
lines changed

4 files changed

+20
-32
lines changed

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)

Editor/EspidiGames.SOEventSystem.Editor.asmdef

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
"name": "EspidiGames.SOEventSystem.Editor",
33
"rootNamespace": "",
44
"references": [
5-
"GUID:478a2357cc57436488a56e564b08d223",
65
"GUID:2c34241bc039bf74eab5e91e0d89b976"
76
],
87
"includePlatforms": [

Editor/ScriptableObjectEventCreationWindow.cs

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
using System.Collections;
21
using System.Linq;
3-
using Unity.EditorCoroutines.Editor;
42
using UnityEditor;
53
using UnityEngine;
64

@@ -29,25 +27,17 @@ public class ScriptableObjectEventCreationWindow : EditorWindow
2927

3028
public static void OpenWindow()
3129
{
32-
//Calling this opens window normally (non-modal)
3330
_window = GetWindow<ScriptableObjectEventCreationWindow>(true, "Select Randomized Selected Objects");
3431
SetWindowSize(InitialWindowDimensions);
35-
EditorCoroutineUtility.StartCoroutineOwnerless(_window.MakeWindowModal());
36-
}
37-
38-
/// <summary>
39-
/// Coroutine that skips one editor frame and then makes Window modal.
40-
/// Necessary to open window from Project panel (right click -> Create/EspidiGames/SO Events / Open window)
41-
///For whatever reason, opening from that context menu left the window completely blank
42-
/// (it was working from unity menus though))
43-
/// </summary>
44-
private IEnumerator MakeWindowModal()
45-
{
46-
yield return null; //Wait just for one editor frame
4732

48-
this.ShowModalUtility();
33+
EditorApplication.delayCall += MakeWindowModal;
34+
void MakeWindowModal()
35+
{
36+
EditorApplication.delayCall -= MakeWindowModal;
37+
_window.ShowModalUtility();
38+
}
4939
}
50-
40+
5141
private void OnGUI()
5242
{
5343
EditorGUILayout.Space();

package.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@
1313
"email": "danigfe.dev@gmail.com",
1414
"url": "https://github.com/danigfedev"
1515
},
16-
"dependencies": {
17-
"com.unity.editorcoroutines": "1.0.0"
18-
},
1916
"keywords": [
2017
"so",
2118
"scriptableobject",

0 commit comments

Comments
 (0)