Skip to content

Commit 1afd96d

Browse files
committed
v1.3.0: more stable on code generation
1 parent a1dd782 commit 1afd96d

File tree

2 files changed

+28
-9
lines changed

2 files changed

+28
-9
lines changed

Editor/USGEngine.cs

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using System.Text;
1010
using UnityEditor;
1111
using UnityEngine;
12+
using UnityEditor.Callbacks;
1213

1314

1415
namespace SatorImaging.UnitySourceGenerator
@@ -19,6 +20,8 @@ public class USGEngine : AssetPostprocessor
1920
public static bool IgnoreOverwriteSettingByAttribute = false;
2021

2122

23+
const string EDITOR_PREFS_LENGTH = "__STMG_USG__TARGET_LENGTH";
24+
const string EDITOR_PREFS_PREFIX = "__STMG_USG__TARGET_";
2225
const int BUFFER_LENGTH = 61_440;
2326
const int BUFFER_MAX_CHAR_LENGTH = BUFFER_LENGTH / 3; // worst case of UTF-8
2427
const string GENERATOR_PREFIX = ".";
@@ -64,24 +67,40 @@ static void OnPostprocessAllAssets(
6467
// menu command but OnPostprocessAllAssets event doesn't work as expected.
6568
// (script runs with static field cleared even though .Clear() is only in ProcessingFiles().
6669
// it's weird that event happens and asset paths retrieved but hashset items gone.)
67-
////EditorApplication.delayCall += () =>
70+
// NOTE: Use EditorPrefs as a temporary storage.
71+
var nPaths = 0;
72+
for (int i = 0; i < importedAssets.Length; i++)
6873
{
69-
ProcessingFiles(importedAssets);
74+
if (!IsAppropriateTarget(importedAssets[i])) continue;
75+
EditorPrefs.SetString(EDITOR_PREFS_PREFIX + nPaths++, importedAssets[i]);
76+
Debug.Log($"[USG]: Saved into EditorPrefs: {importedAssets[i]}");
77+
}
78+
EditorPrefs.SetInt(EDITOR_PREFS_LENGTH, nPaths);
79+
80+
// NOTE: [DidReloadScripts] is executed before AssetPostprocessor, cannot be used.
81+
EditorApplication.delayCall += () =>
82+
{
83+
ProcessingFiles();
7084
};
7185
}
7286

7387

7488
readonly static HashSet<string> s_updatedGeneratorNames = new();
75-
static void ProcessingFiles(string[] targetPaths)
89+
static void ProcessingFiles()
7690
{
7791
bool somethingUpdated = false;
78-
for (int i = 0; i < targetPaths.Length; i++)
92+
93+
var nPaths = EditorPrefs.GetInt(EDITOR_PREFS_LENGTH, 0);
94+
EditorPrefs.DeleteKey(EDITOR_PREFS_LENGTH);
95+
for (int i = 0; i < nPaths; i++)
7996
{
80-
// NOTE: Do NOT early return in this method.
81-
// check path here to allow generator class can be lie outside of Assets/ folder.
82-
if (!IsAppropriateTarget(targetPaths[i])) continue;
97+
var key = EDITOR_PREFS_PREFIX + i;
98+
//if (!EditorPrefs.HasKey(key)) continue;
99+
100+
var path = EditorPrefs.GetString(key);
101+
EditorPrefs.DeleteKey(key);
83102

84-
if (ProcessFile(targetPaths[i]))
103+
if (ProcessFile(path))
85104
somethingUpdated = true;
86105
}
87106

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "com.sator-imaging.alt-source-generator",
33
"displayName": "Alternative Source Generator for Unity",
4-
"version": "1.2.1",
4+
"version": "1.3.0",
55
"unity": "2021.3",
66
"description": "Ease-of-Use Source Generator Alternative for Unity.",
77
"author": {

0 commit comments

Comments
 (0)