DragonECS-Unity/src/Internal/MonoScriptsAssetProcessor.cs

78 lines
2.3 KiB
C#
Raw Normal View History

2024-09-27 22:04:00 +08:00
#if UNITY_EDITOR
2025-03-20 14:15:38 +08:00
using DCFApixels.DragonECS.Unity.Internal;
2024-09-27 22:04:00 +08:00
using System;
using System.Collections.Generic;
using UnityEditor;
namespace DCFApixels.DragonECS.Unity.Editors
{
internal class MonoScriptsAssetProcessor : AssetPostprocessor
{
2025-03-13 16:24:52 +08:00
private static long _timeTicks;
public static long Version
{
get { return _timeTicks; }
}
2024-09-27 22:04:00 +08:00
private static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths, bool didDomainReload)
{
_removedScriptGuids.Clear();
_newScriptIDs.Clear();
foreach (string str in importedAssets)
{
ProcessAssetPath(str);
}
foreach (string str in deletedAssets)
{
RemoveAssetPath(str);
}
2025-03-23 21:15:37 +08:00
foreach (var str in movedFromAssetPaths)
2025-03-13 16:24:52 +08:00
{
2025-03-23 21:15:37 +08:00
RemoveAssetPath(str);
2025-03-13 16:24:52 +08:00
}
2025-03-23 21:15:37 +08:00
foreach (string str in movedAssets)
2024-09-27 22:04:00 +08:00
{
2025-03-23 21:15:37 +08:00
ProcessAssetPath(str);
2024-09-27 22:04:00 +08:00
}
2024-10-01 18:26:20 +08:00
//if (didDomainReload)
//{
// Debug.Log("Domain has been reloaded");
//}
2025-03-13 16:24:52 +08:00
_timeTicks = DateTime.Now.Ticks;
2024-09-27 22:04:00 +08:00
}
private static List<string> _removedScriptGuids = new List<string>();
private static List<string> _newScriptIDs = new List<string>();
2025-03-20 14:15:38 +08:00
public static ReadOnlyList<string> RemovedScriptPaths
2024-09-27 22:04:00 +08:00
{
get { return _removedScriptGuids; }
}
2025-03-20 14:15:38 +08:00
public static ReadOnlyList<string> NewScriptPaths
2024-09-27 22:04:00 +08:00
{
get { return _newScriptIDs; }
}
private static void RemoveAssetPath(string filePath)
{
if (IsScript(filePath) == false) { return; }
_removedScriptGuids.Add(filePath);
}
private static void ProcessAssetPath(string filePath)
{
if (IsScript(filePath) == false) { return; }
_newScriptIDs.Add(filePath);
}
private static bool IsScript(string filePath)
{
2025-03-14 17:40:39 +08:00
if (filePath.Length <= 3) { return false; }
2024-09-27 22:04:00 +08:00
int i = filePath.Length - 3;
return filePath[i++] == '.'
&& filePath[i++] == 'c'
&& filePath[i++] == 's';
}
}
}
#endif