From 3c3fb1891df1a32a297f97e2f6e79019b128dc30 Mon Sep 17 00:00:00 2001 From: Mikhail <99481254+DCFApixels@users.noreply.github.com> Date: Sun, 29 Sep 2024 23:31:12 +0800 Subject: [PATCH] update stash --- src/Internal/ArrayUtility.cs.meta | 11 ++ src/Internal/Editor/UnityEditorUtility.cs | 12 +- src/RefRepairer/Editor/RefRepairerWindow.cs | 1 + src/RefRepairer/MetaIDRegistry.cs | 165 ++++++------------ src/RefRepairer/MetaIDRegistry.cs.meta | 11 ++ ...RepaireUtility.cs => MissingRefUtility.cs} | 87 +-------- ...lity.cs.meta => MissingRefUtility.cs.meta} | 0 src/RefRepairer/RepairerFile.cs | 45 ++++- src/RefRepairer/Utils.meta | 8 + .../Utils/ContainerMissingTypes.cs | 19 ++ .../Utils/ContainerMissingTypes.cs.meta | 11 ++ src/RefRepairer/Utils/MissingTypeData.cs | 18 ++ src/RefRepairer/Utils/MissingTypeData.cs.meta | 11 ++ src/RefRepairer/Utils/SceneObjectData.cs | 19 ++ src/RefRepairer/Utils/SceneObjectData.cs.meta | 11 ++ src/RefRepairer/Utils/TypeData.cs | 55 ++++++ src/RefRepairer/Utils/TypeData.cs.meta | 11 ++ src/RefRepairer/Utils/UnityObjectData.cs | 19 ++ src/RefRepairer/Utils/UnityObjectData.cs.meta | 11 ++ src/RefRepairer/Utils/UnityObjectDataBase.cs | 16 ++ .../Utils/UnityObjectDataBase.cs.meta | 11 ++ 21 files changed, 354 insertions(+), 198 deletions(-) create mode 100644 src/Internal/ArrayUtility.cs.meta create mode 100644 src/RefRepairer/MetaIDRegistry.cs.meta rename src/RefRepairer/{RefRepaireUtility.cs => MissingRefUtility.cs} (72%) rename src/RefRepairer/{RefRepaireUtility.cs.meta => MissingRefUtility.cs.meta} (100%) create mode 100644 src/RefRepairer/Utils.meta create mode 100644 src/RefRepairer/Utils/ContainerMissingTypes.cs create mode 100644 src/RefRepairer/Utils/ContainerMissingTypes.cs.meta create mode 100644 src/RefRepairer/Utils/MissingTypeData.cs create mode 100644 src/RefRepairer/Utils/MissingTypeData.cs.meta create mode 100644 src/RefRepairer/Utils/SceneObjectData.cs create mode 100644 src/RefRepairer/Utils/SceneObjectData.cs.meta create mode 100644 src/RefRepairer/Utils/TypeData.cs create mode 100644 src/RefRepairer/Utils/TypeData.cs.meta create mode 100644 src/RefRepairer/Utils/UnityObjectData.cs create mode 100644 src/RefRepairer/Utils/UnityObjectData.cs.meta create mode 100644 src/RefRepairer/Utils/UnityObjectDataBase.cs create mode 100644 src/RefRepairer/Utils/UnityObjectDataBase.cs.meta diff --git a/src/Internal/ArrayUtility.cs.meta b/src/Internal/ArrayUtility.cs.meta new file mode 100644 index 0000000..dd6543d --- /dev/null +++ b/src/Internal/ArrayUtility.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 1071dcd31ebdf5042a289eb27d8e12d6 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/src/Internal/Editor/UnityEditorUtility.cs b/src/Internal/Editor/UnityEditorUtility.cs index 3fb9793..1cf68d0 100644 --- a/src/Internal/Editor/UnityEditorUtility.cs +++ b/src/Internal/Editor/UnityEditorUtility.cs @@ -123,7 +123,10 @@ namespace DCFApixels.DragonECS.Unity.Editors serializableTypes.AddRange(targetTypes); } _serializableTypes = serializableTypes.ToArray(); - _serializableTypeWithMetaIDMetas = serializableTypes.Where(type => TypeMeta.IsHasMetaID(type)).Select(type => type.GetMeta()).ToArray(); + _serializableTypeWithMetaIDMetas = serializableTypes + .Where(type => TypeMeta.IsHasMetaID(type)) + .Select(type => type.ToMeta()) + .ToArray(); //Array.Sort(_serializableTypes, (a, b) => string.Compare(a.AssemblyQualifiedName, b.AssemblyQualifiedName, StringComparison.Ordinal)); //_noHiddenSerializableTypes = _serializableTypes.Where(o => { @@ -134,6 +137,13 @@ namespace DCFApixels.DragonECS.Unity.Editors internal static readonly Type[] _serializableTypes; internal static readonly TypeMeta[] _serializableTypeWithMetaIDMetas; + private static readonly Dictionary _metaIDTypePairs = new Dictionary(); + + public static bool TryGetTypeForMetaID(string metaID, out Type type) + { + return _metaIDTypePairs.TryGetValue(metaID, out type); + } + //private static Type[] _noHiddenSerializableTypes; private static SparseArray colorBoxeStyles = new SparseArray(); diff --git a/src/RefRepairer/Editor/RefRepairerWindow.cs b/src/RefRepairer/Editor/RefRepairerWindow.cs index c942ece..2e84d86 100644 --- a/src/RefRepairer/Editor/RefRepairerWindow.cs +++ b/src/RefRepairer/Editor/RefRepairerWindow.cs @@ -1,4 +1,5 @@ #if UNITY_EDITOR +using DCFApixels.DragonECS.Unity.RefRepairer.Editors; using System.Collections.Generic; using System.Linq; using UnityEditor; diff --git a/src/RefRepairer/MetaIDRegistry.cs b/src/RefRepairer/MetaIDRegistry.cs index d6b9d22..3576c5d 100644 --- a/src/RefRepairer/MetaIDRegistry.cs +++ b/src/RefRepairer/MetaIDRegistry.cs @@ -1,104 +1,88 @@ #if UNITY_EDITOR -using DCFApixels.DragonECS.Unity.Internal; +using DCFApixels.DragonECS.Unity.Editors; +using DCFApixels.DragonECS.Unity.RefRepairer.Internal; using System; using System.Collections.Generic; -using System.Runtime.CompilerServices; using UnityEditor; using UnityEngine; -namespace DCFApixels.DragonECS.Unity.Editors +namespace DCFApixels.DragonECS.Unity.RefRepairer.Editors { + [InitializeOnLoad] [FilePath(EcsUnityConsts.LOCAL_CACHE_FOLDER + "/" + nameof(MetaIDRegistry) + ".prefs", FilePathAttribute.Location.ProjectFolder)] internal class MetaIDRegistry : ScriptableSingleton, ISerializationCallbackReceiver { - [SerializeField] - private TypeDataList[] _typeDataLists; - [SerializeField] - private int _typeDataListsCount = 0; - [SerializeField] - private TypeDataNode[] _typeDataNodes; - [SerializeField] - private int _typeDataNodesCount = 0; #region [SerializeField] + [Serializable] private struct Pair { - public string metaID; - public int listIndex; - public Pair(string metaID, int listIndex) + public TypeDataSerializable key; + public string value; + public Pair(TypeDataSerializable key, string value) { - this.metaID = metaID; - this.listIndex = listIndex; + this.key = key; + this.value = value; } } - private Pair[] _metaIDListIndexPairsSerializable; + [SerializeField] + private Pair[] _typeKeyMetaIDPairsSerializable; #endregion - private Dictionary _metaIDListIndexPairs = new Dictionary(); + private Dictionary _typeKeyMetaIDPairs = new Dictionary(); + private bool _isChanged = false; + + public bool TryGetMetaID(TypeData key, out string metaID) + { + return _typeKeyMetaIDPairs.TryGetValue(key, out metaID); + } + static MetaIDRegistry() + { + EditorApplication.update += BeforeCompilation; + } + private static void BeforeCompilation() + { + EditorApplication.update -= BeforeCompilation; + instance.TryGetMetaID(default, out _); + instance.Update(); + } #region Update + public void Reinit() + { + _typeKeyMetaIDPairs.Clear(); + Update(); + } private void Update() { var typeMetas = UnityEditorUtility._serializableTypeWithMetaIDMetas; - bool isChanged = false; - - for (int i = 0; i < _typeDataListsCount; i++) - { - _typeDataLists[i].containsFlag = false; - } foreach (var meta in typeMetas) { var type = meta.Type; + var key = new TypeData(type.Name, type.Namespace, type.Assembly.FullName); + var metaID = meta.MetaID; - var name = type.Name; - var nameSpace = type.Namespace; - var assembly = type.Assembly.FullName; - - if (_metaIDListIndexPairs.TryGetValue(meta.MetaID, out int listIndex) == false) + if (_typeKeyMetaIDPairs.TryGetValue(key, out string keyMetaID) == false) { - if (_typeDataLists.Length <= _typeDataListsCount) + if (keyMetaID != metaID) { - Array.Resize(ref _typeDataLists, _typeDataLists.Length << 1); + _typeKeyMetaIDPairs[key] = null; //Таким образом помечаются моменты когда не однозначно какой идентификатор принадлежит этому имени + _isChanged = true; } - listIndex = _typeDataListsCount++; - _metaIDListIndexPairs.Add(meta.MetaID, listIndex); - isChanged = true; } - - ref var listRef = ref _typeDataLists[listIndex]; - listRef.containsFlag = true; - if (listRef.count > 0 && _typeDataNodes[listRef.startNode].EqualsWith(name, nameSpace, assembly)) + else { - continue; - } - - if (_typeDataNodes.Length <= _typeDataNodesCount) - { - Array.Resize(ref _typeDataNodes, _typeDataNodes.Length << 1); - } - int nodeIndex = _typeDataNodesCount++; - ref var nodeRef = ref _typeDataNodes[nodeIndex]; - isChanged = true; - - nodeRef = new TypeDataNode(name, nameSpace, assembly); - nodeRef.next = listRef.startNode; - listRef.startNode = listIndex; - listRef.count++; - } - - for (int i = 0; i < _typeDataListsCount; i++) - { - ref var list = ref _typeDataLists[i]; - if (list.containsFlag == false) - { - _metaIDListIndexPairs.Remove(); + _typeKeyMetaIDPairs[key] = metaID; + _isChanged = true; } } - if (isChanged) + if (_isChanged) { EditorUtility.SetDirty(this); + _isChanged = false; + Save(true); } } #endregion @@ -106,65 +90,22 @@ namespace DCFApixels.DragonECS.Unity.Editors #region ISerializationCallbackReceiver void ISerializationCallbackReceiver.OnAfterDeserialize() { - _metaIDListIndexPairs.Clear(); - if (_typeDataNodes == null) + _typeKeyMetaIDPairs.Clear(); + foreach (var pair in _typeKeyMetaIDPairsSerializable) { - _typeDataLists = new TypeDataList[256]; - _typeDataListsCount = 0; - _typeDataNodes = new TypeDataNode[256]; - _typeDataNodesCount = 0; - } - else - { - foreach (var pair in _metaIDListIndexPairsSerializable) + if (string.IsNullOrEmpty(pair.value) == false) { - _metaIDListIndexPairs[pair.metaID] = pair.listIndex; + _typeKeyMetaIDPairs[pair.key] = pair.value; } } - Update(); } void ISerializationCallbackReceiver.OnBeforeSerialize() { int i = 0; - _metaIDListIndexPairsSerializable = new Pair[_metaIDListIndexPairs.Count]; - foreach (var pair in _metaIDListIndexPairs) + _typeKeyMetaIDPairsSerializable = new Pair[_typeKeyMetaIDPairs.Count]; + foreach (var pair in _typeKeyMetaIDPairs) { - _metaIDListIndexPairsSerializable[i++] = new Pair(pair.Key, pair.Value); - } - } - #endregion - - #region Utils - [Serializable] - public struct TypeDataList - { - public string metaID_key; - public bool containsFlag; - public int startNode; - public int count; - } - [Serializable] - public struct TypeDataNode : ILinkedNext - { - public readonly string Name; - public readonly string Namespace; - public readonly string Assembly; - public int next; - - public bool EqualsWith(string name, string nameSpace, string assembly) - { - return name == Name && nameSpace == Namespace && assembly == Assembly; - } - public TypeDataNode(string name, string nameSpace, string assembly) : this() - { - Name = name; - Namespace = nameSpace; - Assembly = assembly; - } - int ILinkedNext.Next - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - get { return next; } + _typeKeyMetaIDPairsSerializable[i++] = new Pair(pair.Key, pair.Value); } } #endregion diff --git a/src/RefRepairer/MetaIDRegistry.cs.meta b/src/RefRepairer/MetaIDRegistry.cs.meta new file mode 100644 index 0000000..6632389 --- /dev/null +++ b/src/RefRepairer/MetaIDRegistry.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: fcb53d0894c939c49b3e12c6286f4750 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/src/RefRepairer/RefRepaireUtility.cs b/src/RefRepairer/MissingRefUtility.cs similarity index 72% rename from src/RefRepairer/RefRepaireUtility.cs rename to src/RefRepairer/MissingRefUtility.cs index 8ab0436..c5c93b5 100644 --- a/src/RefRepairer/RefRepaireUtility.cs +++ b/src/RefRepairer/MissingRefUtility.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using DCFApixels.DragonECS.Unity.RefRepairer.Internal; +using System.Collections.Generic; using System.Linq; using System.Reflection; using UnityEditor; @@ -7,7 +8,7 @@ using UnityEngine; using UnityEngine.SceneManagement; using UnityObject = UnityEngine.Object; -namespace DCFApixels.DragonECS.Unity.Editors +namespace DCFApixels.DragonECS.Unity.RefRepairer.Editors { public static class UnityObjectExtensions { @@ -21,7 +22,7 @@ namespace DCFApixels.DragonECS.Unity.Editors } } - internal class RefRepaireUtility + internal class MissingRefUtility { private readonly Dictionary _missingTypes = new Dictionary(); @@ -163,7 +164,7 @@ namespace DCFApixels.DragonECS.Unity.Editors } } - private void AddMissingType(ManagedReferenceMissingType missingType, BaseUnityObjectData unityObject) + private void AddMissingType(ManagedReferenceMissingType missingType, UnityObjectDataBase unityObject) { var typeData = new TypeData(missingType); var missingTypeData = new MissingTypeData(missingType, unityObject); @@ -173,85 +174,9 @@ namespace DCFApixels.DragonECS.Unity.Editors _missingTypes.Add(typeData, containerMissingTypes); } - containerMissingTypes.Add(missingTypeData); + containerMissingTypes.ManagedReferencesMissingTypeDatas.Add(missingTypeData); } #endregion } - - - - - - public class ContainerMissingTypes - { - public readonly TypeData TypeData; - - private readonly List _managedReferencesMissingTypeDatas = new List(); - - public IReadOnlyCollection ManagedReferencesMissingTypeDatas => _managedReferencesMissingTypeDatas; - - public ContainerMissingTypes(TypeData typeData) - { - TypeData = typeData; - } - - public void Add(MissingTypeData missingTypeData) => _managedReferencesMissingTypeDatas.Add(missingTypeData); - - public void Remove(MissingTypeData missingTypeData) => _managedReferencesMissingTypeDatas.Remove(missingTypeData); - - public void RemoveAt(int index) => _managedReferencesMissingTypeDatas.RemoveAt(index); - } - public struct MissingTypeData - { - public readonly ManagedReferenceMissingType Data; - public readonly BaseUnityObjectData UnityObject; - - public MissingTypeData(ManagedReferenceMissingType missingType, BaseUnityObjectData unityObject) - { - Data = missingType; - UnityObject = unityObject; - } - } - public struct TypeData - { - public readonly string AssemblyName; - public readonly string NamespaceName; - public readonly string ClassName; - - public TypeData(ManagedReferenceMissingType missingType) - { - AssemblyName = missingType.assemblyName; - NamespaceName = missingType.namespaceName; - ClassName = missingType.className; - } - } - public abstract class BaseUnityObjectData - { - public string LocalAssetPath => AssetDatabase.GUIDToAssetPath(AssetGuid); - public abstract GUID AssetGuid { get; } - } - public class SceneObjectData : BaseUnityObjectData - { - public readonly string SceneName; - - public override GUID AssetGuid { get; } - - public SceneObjectData(Scene scene) - { - SceneName = scene.name; - AssetGuid = AssetDatabase.GUIDFromAssetPath(scene.path); - } - } - public class UnityObjectData : BaseUnityObjectData - { - public readonly UnityObject UnityObject; - public override GUID AssetGuid { get; } - - public UnityObjectData(UnityObject unityObject, string pathToPrefab) - { - UnityObject = unityObject; - AssetGuid = AssetDatabase.GUIDFromAssetPath(pathToPrefab); - } - } } \ No newline at end of file diff --git a/src/RefRepairer/RefRepaireUtility.cs.meta b/src/RefRepairer/MissingRefUtility.cs.meta similarity index 100% rename from src/RefRepairer/RefRepaireUtility.cs.meta rename to src/RefRepairer/MissingRefUtility.cs.meta diff --git a/src/RefRepairer/RepairerFile.cs b/src/RefRepairer/RepairerFile.cs index 7f81db4..647eeca 100644 --- a/src/RefRepairer/RepairerFile.cs +++ b/src/RefRepairer/RepairerFile.cs @@ -1,19 +1,56 @@ +using DCFApixels.DragonECS.Unity.RefRepairer.Internal; using System; using System.IO; using UnityEditor; using UnityEngine; -namespace DCFApixels.DragonECS.Unity.Editors +namespace DCFApixels.DragonECS.Unity.RefRepairer.Editors { - public static class FileRepaireUtility + internal static class FileRepaireUtility { private const string REFLINE_PATTERN = "- rid:"; - public static void Replace(string filePath) + public static void Replace(string[] fileLines, string oldTypeData, string newTypeData) { + for (int i = 0; i < fileLines.Length; i++) + { + if (fileLines[i].Contains(REFLINE_PATTERN)) + { + fileLines[++i].Replace(oldTypeData, newTypeData); + } + } + } + public static string GenerateReplacedLine(TypeData typeData) + { + return $"type: {{class: {typeData.ClassName}, ns: {typeData.NamespaceName}, asm: {typeData.AssemblyName}}}"; + } + public static string GenerateReplacedLine(ManagedReferenceMissingType typeData) + { + return $"type: {{class: {typeData.className}, ns: {typeData.namespaceName}, asm: {typeData.assemblyName}}}"; + } + public struct FileScope : IDisposable + { + public readonly string FilePath; + public readonly string LocalAssetPath; + public string[] lines; + public FileScope(string localAssetPath) + { + LocalAssetPath = localAssetPath; + FilePath = $"{Application.dataPath.Replace("/Assets", "")}/{localAssetPath}"; + lines = File.ReadAllLines(localAssetPath); + } + + public void Dispose() + { + File.WriteAllLines(FilePath, lines); + AssetDatabase.ImportAsset(LocalAssetPath, ImportAssetOptions.ForceUpdate); + AssetDatabase.Refresh(); + } } } - public class RepairerFile + + + internal class RepairerFile { private readonly Type _type; private readonly string[] _fileLines; diff --git a/src/RefRepairer/Utils.meta b/src/RefRepairer/Utils.meta new file mode 100644 index 0000000..035c7f4 --- /dev/null +++ b/src/RefRepairer/Utils.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 070d3c08bbce7714c9edbd903bb370c9 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/src/RefRepairer/Utils/ContainerMissingTypes.cs b/src/RefRepairer/Utils/ContainerMissingTypes.cs new file mode 100644 index 0000000..4785701 --- /dev/null +++ b/src/RefRepairer/Utils/ContainerMissingTypes.cs @@ -0,0 +1,19 @@ +#if UNITY_EDITOR +using DCFApixels.DragonECS.Unity.RefRepairer.Internal; +using System.Collections.Generic; + +namespace DCFApixels.DragonECS.Unity.RefRepairer.Editors +{ + internal class ContainerMissingTypes + { + public readonly TypeData TypeData; + public readonly string ReplacedLine; + public readonly List ManagedReferencesMissingTypeDatas = new List(); + public ContainerMissingTypes(TypeData typeData) + { + TypeData = typeData; + ReplacedLine = FileRepaireUtility.GenerateReplacedLine(typeData); + } + } +} +#endif \ No newline at end of file diff --git a/src/RefRepairer/Utils/ContainerMissingTypes.cs.meta b/src/RefRepairer/Utils/ContainerMissingTypes.cs.meta new file mode 100644 index 0000000..c098b7b --- /dev/null +++ b/src/RefRepairer/Utils/ContainerMissingTypes.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 7999f2711e8e3e040b8ae48ce5acec71 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/src/RefRepairer/Utils/MissingTypeData.cs b/src/RefRepairer/Utils/MissingTypeData.cs new file mode 100644 index 0000000..245873a --- /dev/null +++ b/src/RefRepairer/Utils/MissingTypeData.cs @@ -0,0 +1,18 @@ +#if UNITY_EDITOR +using UnityEditor; + +namespace DCFApixels.DragonECS.Unity.RefRepairer.Editors +{ + internal readonly struct MissingTypeData + { + public readonly ManagedReferenceMissingType Data; + public readonly UnityObjectDataBase UnityObject; + + public MissingTypeData(ManagedReferenceMissingType missingType, UnityObjectDataBase unityObject) + { + Data = missingType; + UnityObject = unityObject; + } + } +} +#endif \ No newline at end of file diff --git a/src/RefRepairer/Utils/MissingTypeData.cs.meta b/src/RefRepairer/Utils/MissingTypeData.cs.meta new file mode 100644 index 0000000..c97f73a --- /dev/null +++ b/src/RefRepairer/Utils/MissingTypeData.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 447f4a0f7419475438468e8f08d8b7cd +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/src/RefRepairer/Utils/SceneObjectData.cs b/src/RefRepairer/Utils/SceneObjectData.cs new file mode 100644 index 0000000..eea6246 --- /dev/null +++ b/src/RefRepairer/Utils/SceneObjectData.cs @@ -0,0 +1,19 @@ +#if UNITY_EDITOR +using UnityEditor; +using UnityEngine.SceneManagement; + +namespace DCFApixels.DragonECS.Unity.RefRepairer.Editors +{ + internal class SceneObjectData : UnityObjectDataBase + { + private readonly GUID _assetGUID; + public readonly string SceneName; + public sealed override GUID AssetGuid { get { return _assetGUID; } } + public SceneObjectData(Scene scene) + { + _assetGUID = AssetDatabase.GUIDFromAssetPath(scene.path); + SceneName = scene.name; + } + } +} +#endif \ No newline at end of file diff --git a/src/RefRepairer/Utils/SceneObjectData.cs.meta b/src/RefRepairer/Utils/SceneObjectData.cs.meta new file mode 100644 index 0000000..f27167a --- /dev/null +++ b/src/RefRepairer/Utils/SceneObjectData.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 495419751a448a848853d4df10955da7 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/src/RefRepairer/Utils/TypeData.cs b/src/RefRepairer/Utils/TypeData.cs new file mode 100644 index 0000000..d286315 --- /dev/null +++ b/src/RefRepairer/Utils/TypeData.cs @@ -0,0 +1,55 @@ +#if UNITY_EDITOR +using System; +using UnityEditor; + +namespace DCFApixels.DragonECS.Unity.RefRepairer.Internal +{ + [Serializable] + internal struct TypeDataSerializable + { + public string ClassName; + public string NamespaceName; + public string AssemblyName; + public TypeDataSerializable(string typeName, string namespaceName, string assemblyName) + { + ClassName = typeName; + NamespaceName = namespaceName; + AssemblyName = assemblyName; + } + 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); } + } + internal readonly struct TypeData : IEquatable + { + 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; + } + public TypeData(string typeName, string namespaceName, string assemblyName) + { + ClassName = typeName; + NamespaceName = namespaceName; + AssemblyName = assemblyName; + } + public bool Equals(TypeData other) + { + return ClassName == other.ClassName && + NamespaceName == other.NamespaceName && + AssemblyName == other.AssemblyName; + } + public override bool Equals(object obj) + { + return Equals((TypeData)obj); + } + public override int GetHashCode() + { + return HashCode.Combine(ClassName, NamespaceName, AssemblyName); + } + } +} +#endif \ No newline at end of file diff --git a/src/RefRepairer/Utils/TypeData.cs.meta b/src/RefRepairer/Utils/TypeData.cs.meta new file mode 100644 index 0000000..43cc95d --- /dev/null +++ b/src/RefRepairer/Utils/TypeData.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: bc54327da1808fb4ebb37e955e774b6c +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/src/RefRepairer/Utils/UnityObjectData.cs b/src/RefRepairer/Utils/UnityObjectData.cs new file mode 100644 index 0000000..1ada726 --- /dev/null +++ b/src/RefRepairer/Utils/UnityObjectData.cs @@ -0,0 +1,19 @@ +#if UNITY_EDITOR +using UnityEditor; +using UnityObject = UnityEngine.Object; + +namespace DCFApixels.DragonECS.Unity.RefRepairer.Editors +{ + internal class UnityObjectData : UnityObjectDataBase + { + private readonly GUID _assetGUID; + public readonly UnityObject UnityObject; + public sealed override GUID AssetGuid { get { return _assetGUID; } } + public UnityObjectData(UnityObject unityObject, string pathToPrefab) + { + _assetGUID = AssetDatabase.GUIDFromAssetPath(pathToPrefab); + UnityObject = unityObject; + } + } +} +#endif \ No newline at end of file diff --git a/src/RefRepairer/Utils/UnityObjectData.cs.meta b/src/RefRepairer/Utils/UnityObjectData.cs.meta new file mode 100644 index 0000000..3426824 --- /dev/null +++ b/src/RefRepairer/Utils/UnityObjectData.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 0037513c31abb5d4ebd572d2fd17ccec +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/src/RefRepairer/Utils/UnityObjectDataBase.cs b/src/RefRepairer/Utils/UnityObjectDataBase.cs new file mode 100644 index 0000000..497ff7d --- /dev/null +++ b/src/RefRepairer/Utils/UnityObjectDataBase.cs @@ -0,0 +1,16 @@ +#if UNITY_EDITOR +using UnityEditor; + +namespace DCFApixels.DragonECS.Unity.RefRepairer.Editors +{ + internal abstract class UnityObjectDataBase + { + //public string LocalAssetPath => AssetDatabase.GUIDToAssetPath(AssetGuid); + public abstract GUID AssetGuid { get; } + public string GetLocalAssetPath() + { + return AssetDatabase.GUIDToAssetPath(AssetGuid); + } + } +} +#endif \ No newline at end of file diff --git a/src/RefRepairer/Utils/UnityObjectDataBase.cs.meta b/src/RefRepairer/Utils/UnityObjectDataBase.cs.meta new file mode 100644 index 0000000..b14ee8f --- /dev/null +++ b/src/RefRepairer/Utils/UnityObjectDataBase.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: ee1ba8deebb294644b74bfe99f1fc2bc +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: