Skip to content

Commit bda5d9d

Browse files
authored
Merge pull request #113 from cnlohr/master
Add mechanism to refresh UdonSharp Assets
2 parents c665c16 + f7a5d08 commit bda5d9d

1 file changed

Lines changed: 52 additions & 2 deletions

File tree

Assets/UdonSharp/Editor/UdonSharpProgramAsset.cs

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ public static UdonSharpProgramAsset[] GetAllUdonSharpPrograms()
257257

258258
foreach (UdonSharpProgramAsset fallbackAsset in fallbackAssets1)
259259
{
260-
if (!_programAssetCache.Contains(fallbackAsset))
260+
if (_programAssetCache != null && fallbackAsset != null && !_programAssetCache.Contains(fallbackAsset))
261261
{
262262
Debug.LogWarning($"Repairing program asset {fallbackAsset} which Unity has broken");
263263
neededFallback = true;
@@ -271,7 +271,7 @@ public static UdonSharpProgramAsset[] GetAllUdonSharpPrograms()
271271
var fallbackAssets2 = AssetDatabase.FindAssets($"t:{nameof(UdonProgramAsset)}").Select(e => AssetDatabase.LoadAssetAtPath<UdonProgramAsset>(AssetDatabase.GUIDToAssetPath(e))).OfType<UdonSharpProgramAsset>();
272272
foreach (UdonSharpProgramAsset fallbackAsset in fallbackAssets2)
273273
{
274-
if (!_programAssetCache.Contains(fallbackAsset))
274+
if (_programAssetCache != null && fallbackAsset != null && !_programAssetCache.Contains(fallbackAsset))
275275
{
276276
Debug.LogWarning($"Repairing program asset {fallbackAsset} which Unity has broken pass 2");
277277
neededFallback = true;
@@ -300,6 +300,56 @@ public static UdonSharpProgramAsset[] GetAllUdonSharpPrograms()
300300
return (UdonSharpProgramAsset[])_programAssetCache.Clone();
301301
}
302302

303+
[MenuItem("Window/Udon Sharp/Refresh All UdonSharp Assets")]
304+
static public void UdonSharpCheckAbsent()
305+
{
306+
Debug.Log( "Checking Absent" );
307+
308+
int cycles = -1;
309+
int lastNumAssets;
310+
int currentNumAssets;
311+
string[] udonSharpDataAssets;
312+
313+
// Loop until we stop picking up assets.
314+
do
315+
{
316+
udonSharpDataAssets = AssetDatabase.FindAssets($"t:{nameof(UdonSharpProgramAsset)}");
317+
lastNumAssets = udonSharpDataAssets.Length;
318+
string[] udonSharpNames = new string[udonSharpDataAssets.Length];
319+
Debug.Log( $"Found {udonSharpDataAssets.Length} assets." );
320+
321+
_programAssetCache = new UdonSharpProgramAsset[udonSharpDataAssets.Length];
322+
323+
for (int i = 0; i < _programAssetCache.Length; ++i)
324+
{
325+
udonSharpDataAssets[i] = AssetDatabase.GUIDToAssetPath(udonSharpDataAssets[i]);
326+
}
327+
328+
foreach(string s in AssetDatabase.GetAllAssetPaths() )
329+
{
330+
if(!udonSharpDataAssets.Contains(s))
331+
{
332+
Type t = AssetDatabase.GetMainAssetTypeAtPath(s);
333+
if (t != null && t.FullName == "UdonSharp.UdonSharpProgramAsset")
334+
{
335+
Debug.Log( $"Trying to recover {s}" );
336+
Selection.activeObject = AssetDatabase.LoadAssetAtPath<UnityEngine.Object>(s);
337+
}
338+
}
339+
}
340+
341+
ClearProgramAssetCache();
342+
343+
GetAllUdonSharpPrograms();
344+
345+
currentNumAssets = AssetDatabase.FindAssets($"t:{nameof(UdonSharpProgramAsset)}").Length;
346+
Debug.Log( $"Checking to see if we need to re-run. Last: {lastNumAssets}, This: {currentNumAssets}" );
347+
cycles++;
348+
} while( lastNumAssets != currentNumAssets );
349+
350+
Debug.Log( $"Completed {cycles} refresh cycles, found {lastNumAssets} assets." );
351+
}
352+
303353
[PublicAPI]
304354
public static bool AnyUdonSharpScriptHasError()
305355
{

0 commit comments

Comments
 (0)