diff --git a/src/Internal/Editor/UnityEditorUtility.cs b/src/Internal/Editor/UnityEditorUtility.cs index 8d33618..965b31b 100644 --- a/src/Internal/Editor/UnityEditorUtility.cs +++ b/src/Internal/Editor/UnityEditorUtility.cs @@ -224,13 +224,11 @@ namespace DCFApixels.DragonECS.Unity.Editors } //private static Type[] _noHiddenSerializableTypes; - private static GUIContent _singletonIconContent = null; private static GUIContent _singletonContent = null; private static GUIStyle _inputFieldCenterAnhor = null; private static Dictionary _scriptsAssets = new Dictionary(256); - internal static void ResetValues(this SerializedProperty property, bool isExpand = false) { ResetValues_Internal(property.Copy(), isExpand, property.depth); diff --git a/src/Internal/MonoScriptsAssetProcessor.cs b/src/Internal/MonoScriptsAssetProcessor.cs index 85e94de..0450392 100644 --- a/src/Internal/MonoScriptsAssetProcessor.cs +++ b/src/Internal/MonoScriptsAssetProcessor.cs @@ -1,4 +1,5 @@ #if UNITY_EDITOR +using DCFApixels.DragonECS.Unity.Internal; using System; using System.Collections.Generic; using UnityEditor; @@ -50,11 +51,11 @@ namespace DCFApixels.DragonECS.Unity.Editors private static List _removedScriptGuids = new List(); private static List _newScriptIDs = new List(); - public static IReadOnlyCollection RemovedScriptPaths + public static ReadOnlyList RemovedScriptPaths { get { return _removedScriptGuids; } } - public static IReadOnlyCollection NewScriptPaths + public static ReadOnlyList NewScriptPaths { get { return _newScriptIDs; } } diff --git a/src/Internal/ScriptsCache.cs b/src/Internal/ScriptsCache.cs index 151749d..9606dc6 100644 --- a/src/Internal/ScriptsCache.cs +++ b/src/Internal/ScriptsCache.cs @@ -61,19 +61,13 @@ namespace DCFApixels.DragonECS.Unity.Editors { if (MonoScriptsAssetProcessor.Version <= _version) { return; } - if (MonoScriptsAssetProcessor.RemovedScriptPaths.Count > 0) + var paths = MonoScriptsAssetProcessor.RemovedScriptPaths; + if (paths.Count > 0) { List removedKeys = new List(); - uint pathsLength = (uint)MonoScriptsAssetProcessor.RemovedScriptPaths.Count; - string[] paths = new string[pathsLength]; - int i = 0; - foreach (var path in MonoScriptsAssetProcessor.RemovedScriptPaths) - { - paths[i++] = path; - } foreach (var metaIDScriptPathPair in _metaIDScriptPathPairs) { - for (uint j = 0; j < pathsLength; j++) + for (int j = 0; j < paths.Count; j++) { if (paths[j] == metaIDScriptPathPair.Value) { @@ -88,10 +82,11 @@ namespace DCFApixels.DragonECS.Unity.Editors } } - if (MonoScriptsAssetProcessor.NewScriptPaths.Count > 0) + paths = MonoScriptsAssetProcessor.NewScriptPaths; + if (paths.Count > 0) { List metaIDs = new List(); - foreach (var assetPath in MonoScriptsAssetProcessor.NewScriptPaths) + foreach (var assetPath in paths) { ExtractMetaIDs(AssetDatabase.LoadAssetAtPath(assetPath).text, metaIDs); foreach (var metaID in metaIDs) diff --git a/src/Internal/Utils/ReadOnlyList.cs b/src/Internal/Utils/ReadOnlyList.cs new file mode 100644 index 0000000..87e7b99 --- /dev/null +++ b/src/Internal/Utils/ReadOnlyList.cs @@ -0,0 +1,40 @@ +using System.Collections; +using System.Collections.Generic; + +namespace DCFApixels.DragonECS.Unity.Internal +{ + internal readonly struct ReadOnlyList : IEnumerable, IReadOnlyList + { + private readonly List _list; + public ReadOnlyList(List list) + { + _list = list; + } + public int Count + { + get { return _list.Count; } + } + public T this[int index] + { + get { return _list[index]; } + set { _list[index] = value; } + } + public bool Contains(T item) + { + return _list.Contains(item); + } + public List.Enumerator GetEnumerator() + { + return _list.GetEnumerator(); + } + IEnumerator IEnumerable.GetEnumerator() + { + return _list.GetEnumerator(); + } + IEnumerator IEnumerable.GetEnumerator() + { + return _list.GetEnumerator(); + } + public static implicit operator ReadOnlyList(List a) { return new ReadOnlyList(a); } + } +} diff --git a/src/Internal/Utils/ReadOnlyList.cs.meta b/src/Internal/Utils/ReadOnlyList.cs.meta new file mode 100644 index 0000000..4345e3e --- /dev/null +++ b/src/Internal/Utils/ReadOnlyList.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: d6be8f1171a60d646b862ec8472c55ef +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/src/Tools/DeepDebugger/Editors/DeepDebuggerWindow.cs b/src/Tools/DeepDebugger/Editors/DeepDebuggerWindow.cs index 0611cda..1bf3be5 100644 --- a/src/Tools/DeepDebugger/Editors/DeepDebuggerWindow.cs +++ b/src/Tools/DeepDebugger/Editors/DeepDebuggerWindow.cs @@ -1,5 +1,7 @@ #if UNITY_EDITOR using DCFApixels.DragonECS.Unity.Internal; +using DCFApixels.DragonECS.Unity.RefRepairer.Editors; +using DCFApixels.DragonECS.Unity.RefRepairer.Internal; using UnityEditor; using UnityEngine; @@ -20,18 +22,36 @@ namespace DCFApixels.DragonECS.Unity.Editors } #endif + public enum Page + { + ScriptsCache, + MetaIDRegistry, + } + private Page _page; private Vector2 pos; private void OnGUI() { - var dicst = ScriptsCache.MetaIDScriptPathPairs; - - pos = GUILayout.BeginScrollView(pos); + _page = (Page)EditorGUILayout.EnumPopup(_page); + switch (_page) + { + case Page.ScriptsCache: + DrawScriptsCache(); + break; + case Page.MetaIDRegistry: + DrawMetaIDRegistry(); + break; + } + } + + private void DrawScriptsCache() + { if (GUILayout.Button("Reset")) { ScriptsCache.Reinit(); } - + var dicst = ScriptsCache.MetaIDScriptPathPairs; + pos = GUILayout.BeginScrollView(pos); foreach (var (metaID, scriptPath) in dicst) { GUILayout.Label("", GUILayout.ExpandWidth(true)); @@ -42,6 +62,28 @@ namespace DCFApixels.DragonECS.Unity.Editors } GUILayout.EndScrollView(); } + + private void DrawMetaIDRegistry() + { + if (GUILayout.Button("Reset")) + { + MetaIDRegistry.instance.Reinit(); + } + var dicst = MetaIDRegistry.instance.TypeKeyMetaIDPairs; + pos = GUILayout.BeginScrollView(pos); + foreach (var (typeData, scriptPath) in dicst) + { + GUILayout.Label("", GUILayout.ExpandWidth(true)); + Rect rect = GUILayoutUtility.GetLastRect(); + var (leftRect, rightRect) = rect.HorizontalSliceLerp(0.5f); + Rect preLeftRect = default; + (preLeftRect, leftRect) = rect.HorizontalSliceLeft(18f); + GUI.Label(preLeftRect, typeData.ToType() == null ? "-" : "+"); + GUI.Label(leftRect, typeData.ToString()); + GUI.Label(rightRect, scriptPath); + } + GUILayout.EndScrollView(); + } } } #endif diff --git a/src/Tools/RefRepairer/Editor/MetaIDRegistry.cs b/src/Tools/RefRepairer/Editor/MetaIDRegistry.cs index a107a8f..502346b 100644 --- a/src/Tools/RefRepairer/Editor/MetaIDRegistry.cs +++ b/src/Tools/RefRepairer/Editor/MetaIDRegistry.cs @@ -28,11 +28,18 @@ namespace DCFApixels.DragonECS.Unity.RefRepairer.Editors private Pair[] _typeKeyMetaIDPairsSerializable; #endregion private Dictionary _typeKeyMetaIDPairs = new Dictionary(); + internal IReadOnlyDictionary TypeKeyMetaIDPairs => _typeKeyMetaIDPairs; private bool _isChanged = false; public bool TryGetMetaID(TypeData key, out string metaID) { - return _typeKeyMetaIDPairs.TryGetValue(key, out metaID); + bool result = _typeKeyMetaIDPairs.TryGetValue(key, out metaID); + if(result && string.IsNullOrEmpty(metaID)) + { + result = false; + _typeKeyMetaIDPairs.Remove(key); + } + return result; } @@ -43,7 +50,7 @@ namespace DCFApixels.DragonECS.Unity.RefRepairer.Editors private static void BeforeCompilation() { EditorApplication.update -= BeforeCompilation; - instance.TryGetMetaID(default, out _); + instance.TryGetMetaID(TypeData.Empty, out _); instance.Update(); } @@ -55,25 +62,26 @@ namespace DCFApixels.DragonECS.Unity.RefRepairer.Editors } private void Update() { - var typeMetas = UnityEditorUtility._serializableTypeWithMetaIDMetas; + if (UnityEditorUtility.IsHasAnyMetaIDCollision) { return; } + var typeMetas = UnityEditorUtility._typeWithMetaIDMetas; foreach (var meta in typeMetas) { - var key = new TypeData(meta.Type); + var typeKey = new TypeData(meta.Type); var metaID = meta.MetaID; //Debug.LogWarning(type + " " + metaID); - if (_typeKeyMetaIDPairs.TryGetValue(key, out string keyMetaID)) + if (_typeKeyMetaIDPairs.TryGetValue(typeKey, out string storedMetaID)) { - if (keyMetaID != metaID) + if (storedMetaID != metaID) { - _typeKeyMetaIDPairs[key] = null; //Таким образом помечаются моменты когда не однозначно какой идентификатор принадлежит этому имени + _typeKeyMetaIDPairs[typeKey] = string.Empty; //Таким образом помечаются моменты когда не однозначно какой идентификатор принадлежит этому имени _isChanged = true; } } else { - _typeKeyMetaIDPairs[key] = metaID; + _typeKeyMetaIDPairs[typeKey] = metaID; _isChanged = true; } } @@ -92,10 +100,9 @@ namespace DCFApixels.DragonECS.Unity.RefRepairer.Editors _typeKeyMetaIDPairs.Clear(); foreach (var pair in _typeKeyMetaIDPairsSerializable) { - if (string.IsNullOrEmpty(pair.value) == false) - { - _typeKeyMetaIDPairs[pair.key] = pair.value; - } + if (string.IsNullOrEmpty(pair.value) || pair.key.IsEmpty) { continue; } + + _typeKeyMetaIDPairs[pair.key] = pair.value; } } void ISerializationCallbackReceiver.OnBeforeSerialize() diff --git a/src/Tools/RefRepairer/MissingsResolvingData.cs b/src/Tools/RefRepairer/MissingsResolvingData.cs index a61bae8..bb039e9 100644 --- a/src/Tools/RefRepairer/MissingsResolvingData.cs +++ b/src/Tools/RefRepairer/MissingsResolvingData.cs @@ -1,7 +1,6 @@ #if UNITY_EDITOR using DCFApixels.DragonECS.Unity.RefRepairer.Internal; using System; -using System.Reflection; namespace DCFApixels.DragonECS.Unity.RefRepairer.Editors { @@ -9,8 +8,13 @@ namespace DCFApixels.DragonECS.Unity.RefRepairer.Editors { public readonly TypeData OldTypeData; public readonly string OldSerializedInfoLine; + private TypeData _newTypeData; private string _newSerializedInfoLine; + + private Type _chachedNewType = null; + private bool _chachedNewTypeInited = false; + public MissingsResolvingData(TypeData oldTypeData) { OldTypeData = oldTypeData; @@ -18,13 +22,7 @@ namespace DCFApixels.DragonECS.Unity.RefRepairer.Editors } public bool IsResolved { - get - { - //return - // string.IsNullOrEmpty(_newTypeData.ClassName) == false && - // string.IsNullOrEmpty(_newTypeData.AssemblyName) == false; - return FindNewType() != null; - } + get { return FindNewType() != null; } } public bool IsEmpty { @@ -35,34 +33,6 @@ namespace DCFApixels.DragonECS.Unity.RefRepairer.Editors string.IsNullOrEmpty(_newTypeData.AssemblyName); } } - private Type _chachedNewType = null; - private bool _chachedNewTypeInited = false; - public Type FindNewType() - { - if (_chachedNewTypeInited == false) - { - if (string.IsNullOrEmpty(_newTypeData.AssemblyName) == false) - { - Assembly assembly = null; - try - { - assembly = Assembly.Load(_newTypeData.AssemblyName); - } - catch { } - if (assembly == null) - { - _chachedNewType = null; - } - else - { - string fullTypeName = $"{_newTypeData.NamespaceName}.{_newTypeData.ClassName}"; - _chachedNewType = assembly.GetType(fullTypeName); - } - _chachedNewTypeInited = true; - } - } - return _chachedNewType; - } public TypeData NewTypeData { get { return _newTypeData; } @@ -85,6 +55,15 @@ namespace DCFApixels.DragonECS.Unity.RefRepairer.Editors return _newSerializedInfoLine; } } + + public Type FindNewType() + { + if (_chachedNewTypeInited == false) + { + _chachedNewType = _newTypeData.ToType(); + } + return _chachedNewType; + } } } #endif \ No newline at end of file diff --git a/src/Tools/RefRepairer/TypeData.cs b/src/Tools/RefRepairer/TypeData.cs index 8fb88fb..7a78879 100644 --- a/src/Tools/RefRepairer/TypeData.cs +++ b/src/Tools/RefRepairer/TypeData.cs @@ -1,5 +1,6 @@ #if UNITY_EDITOR using System; +using System.Reflection; using System.Text; using UnityEditor; @@ -11,6 +12,7 @@ namespace DCFApixels.DragonECS.Unity.RefRepairer.Internal public string ClassName; public string NamespaceName; public string AssemblyName; + public bool IsEmpty { get { return string.IsNullOrWhiteSpace(ClassName); } } public TypeDataSerializable(string typeName, string namespaceName, string assemblyName) { ClassName = typeName; @@ -19,17 +21,19 @@ namespace DCFApixels.DragonECS.Unity.RefRepairer.Internal } public static implicit operator TypeDataSerializable(TypeData type) { return new TypeDataSerializable(type.ClassName, type.NamespaceName, type.AssemblyName); } public static implicit operator TypeData(TypeDataSerializable type) { return new TypeData(type.ClassName, type.NamespaceName, type.AssemblyName); } + public override string ToString() { return $"{{{AssemblyName}, {NamespaceName}, {ClassName}}}"; } } internal readonly struct TypeData : IEquatable { + public static readonly TypeData Empty = new TypeData(string.Empty, string.Empty, string.Empty); public readonly string ClassName; public readonly string NamespaceName; public readonly string AssemblyName; public TypeData(ManagedReferenceMissingType managedReferenceMissingType) { - ClassName = managedReferenceMissingType.className; - NamespaceName = managedReferenceMissingType.namespaceName; - AssemblyName = managedReferenceMissingType.assemblyName; + ClassName = managedReferenceMissingType.className ?? string.Empty; + NamespaceName = managedReferenceMissingType.namespaceName ?? string.Empty; + AssemblyName = managedReferenceMissingType.assemblyName ?? string.Empty; } public TypeData(string typeName, string namespaceName, string assemblyName) { @@ -37,12 +41,12 @@ namespace DCFApixels.DragonECS.Unity.RefRepairer.Internal NamespaceName = namespaceName; AssemblyName = assemblyName; } - + public bool IsEmpty { get { return string.IsNullOrWhiteSpace(ClassName); } } [ThreadStatic] private static StringBuilder sb; public TypeData(Type type) { - string name = null; + string name = string.Empty; if (type.DeclaringType == null) { name = type.Name; @@ -65,7 +69,7 @@ namespace DCFApixels.DragonECS.Unity.RefRepairer.Internal } ClassName = name; - NamespaceName = type.Namespace; + NamespaceName = type.Namespace ?? string.Empty; AssemblyName = type.Assembly.GetName().Name; } public bool Equals(TypeData other) @@ -74,13 +78,48 @@ namespace DCFApixels.DragonECS.Unity.RefRepairer.Internal NamespaceName == other.NamespaceName && AssemblyName == other.AssemblyName; } - public override bool Equals(object obj) + public override bool Equals(object obj) { return Equals((TypeData)obj); } + public override int GetHashCode() { - return Equals((TypeData)obj); + int hash1 = ClassName.GetHashCode(); + int hash2 = NamespaceName.GetHashCode(); + int hash3 = AssemblyName.GetHashCode(); + return hash1 ^ hash2 ^ hash3; } - public override int GetHashCode() + public override string ToString() { return $"{{{AssemblyName}, {NamespaceName}, {ClassName}}}"; } + } + internal static class TypeDataExtensions + { + public static Type ToType(this TypeData sefl) { - return HashCode.Combine(ClassName, NamespaceName, AssemblyName); + return ToType(sefl.AssemblyName, sefl.NamespaceName, sefl.ClassName); + } + public static Type ToType(this TypeDataSerializable sefl) + { + return ToType(sefl.AssemblyName, sefl.NamespaceName, sefl.ClassName); + } + private static Type ToType(string AssemblyName, string NamespaceName, string ClassName) + { + Type result = null; + if (string.IsNullOrEmpty(AssemblyName) == false) + { + Assembly assembly = null; + try + { + assembly = Assembly.Load(AssemblyName); + } + catch { } + if (assembly == null) + { + result = null; + } + else + { + string fullTypeName = $"{NamespaceName}.{ClassName}"; + result = assembly.GetType(fullTypeName); + } + } + return result; } } }