mirror of
https://github.com/DCFApixels/DragonECS-Unity.git
synced 2025-09-18 01:54:35 +08:00
add repaire refs tool
This commit is contained in:
parent
bb6c2cec43
commit
5e2c03be1e
@ -127,6 +127,11 @@ namespace DCFApixels.DragonECS.Unity.Editors
|
||||
.Where(type => TypeMeta.IsHasMetaID(type))
|
||||
.Select(type => type.ToMeta())
|
||||
.ToArray();
|
||||
|
||||
foreach (var item in _serializableTypeWithMetaIDMetas)
|
||||
{
|
||||
_metaIDTypePairs[item.MetaID] = item.Type;
|
||||
}
|
||||
//Array.Sort(_serializableTypes, (a, b) => string.Compare(a.AssemblyQualifiedName, b.AssemblyQualifiedName, StringComparison.Ordinal));
|
||||
|
||||
//_noHiddenSerializableTypes = _serializableTypes.Where(o => {
|
||||
|
@ -3,6 +3,7 @@ using DCFApixels.DragonECS.Unity.RefRepairer.Editors;
|
||||
using System.Linq;
|
||||
using UnityEditor;
|
||||
using UnityEditor.SceneManagement;
|
||||
using UnityEditorInternal;
|
||||
using UnityEngine;
|
||||
|
||||
namespace DCFApixels.DragonECS.Unity.Editors
|
||||
@ -20,24 +21,52 @@ namespace DCFApixels.DragonECS.Unity.Editors
|
||||
}
|
||||
|
||||
private MissingRefContainer _missingRefContainer = new MissingRefContainer();
|
||||
private MissingsResolvingData[] _cachedMissingsResolvingDatas = null;
|
||||
|
||||
private ReorderableList _reorderableList;
|
||||
|
||||
private void InitList()
|
||||
{
|
||||
if(_reorderableList == null)
|
||||
{
|
||||
_reorderableList = new ReorderableList(_cachedMissingsResolvingDatas, typeof(MissingsResolvingData), false, false, false, false);
|
||||
_reorderableList.headerHeight = 0;
|
||||
_reorderableList.footerHeight = 0;
|
||||
}
|
||||
_reorderableList.list = _cachedMissingsResolvingDatas;
|
||||
}
|
||||
|
||||
private void OnGUI()
|
||||
{
|
||||
if (_missingRefContainer.IsEmplty)
|
||||
{
|
||||
if(GUILayout.Button("Collect missing references"))
|
||||
if (GUILayout.Button("Collect missing references"))
|
||||
{
|
||||
if (TryInit())
|
||||
{
|
||||
_missingRefContainer.Collect();
|
||||
_cachedMissingsResolvingDatas = _missingRefContainer.MissingsResolvingDatas.Values.ToArray();
|
||||
InitList();
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (GUILayout.Button("Repaire missing references"))
|
||||
{
|
||||
Debug.Log(_missingRefContainer.IsEmplty);
|
||||
var x = _missingRefContainer.collectedMissingTypesBuffer[0];
|
||||
Debug.Log(x.ResolvingData.NewTypeData.AutoToString());
|
||||
RepaireFileUtility.RepaieAsset(_missingRefContainer);
|
||||
}
|
||||
|
||||
_missingRefContainer.MissingsResolvingDatas
|
||||
if (_missingRefContainer.MissingsResolvingDatas.Count != _cachedMissingsResolvingDatas.Length)
|
||||
{
|
||||
_cachedMissingsResolvingDatas = _missingRefContainer.MissingsResolvingDatas.Values.ToArray();
|
||||
InitList();
|
||||
}
|
||||
|
||||
_reorderableList.DoLayoutList();
|
||||
}
|
||||
|
||||
|
||||
|
@ -3,7 +3,6 @@ using DCFApixels.DragonECS.Unity.Editors;
|
||||
using DCFApixels.DragonECS.Unity.RefRepairer.Internal;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
@ -57,33 +56,9 @@ namespace DCFApixels.DragonECS.Unity.RefRepairer.Editors
|
||||
private void Update()
|
||||
{
|
||||
var typeMetas = UnityEditorUtility._serializableTypeWithMetaIDMetas;
|
||||
StringBuilder sb = null;
|
||||
foreach (var meta in typeMetas)
|
||||
{
|
||||
var type = meta.Type;
|
||||
string name = null;
|
||||
if (type.DeclaringType == null)
|
||||
{
|
||||
name = type.Name;
|
||||
}
|
||||
else
|
||||
{
|
||||
Type iteratorType = type;
|
||||
if (sb == null)
|
||||
{
|
||||
sb = new StringBuilder();
|
||||
}
|
||||
sb.Clear();
|
||||
sb.Append(iteratorType.Name);
|
||||
while ((iteratorType = iteratorType.DeclaringType) != null)
|
||||
{
|
||||
sb.Insert(0, '/');
|
||||
sb.Insert(0, iteratorType.Name);
|
||||
}
|
||||
name = sb.ToString();
|
||||
}
|
||||
|
||||
var key = new TypeData(name, type.Namespace, type.Assembly.GetName().Name);
|
||||
var key = new TypeData(meta.Type);
|
||||
var metaID = meta.MetaID;
|
||||
|
||||
//Debug.LogWarning(type + " " + metaID);
|
||||
|
@ -1,4 +1,5 @@
|
||||
#if UNITY_EDITOR
|
||||
using DCFApixels.DragonECS.Unity.Editors;
|
||||
using DCFApixels.DragonECS.Unity.RefRepairer.Internal;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@ -17,7 +18,6 @@ namespace DCFApixels.DragonECS.Unity.RefRepairer.Editors
|
||||
public CollectedAssetMissingRecord[] collectedMissingTypesBuffer = null;
|
||||
public int collectedMissingTypesBufferCount = 0;
|
||||
public readonly Dictionary<TypeData, MissingsResolvingData> MissingsResolvingDatas = new Dictionary<TypeData, MissingsResolvingData>();
|
||||
public MissingsResolvingData[] MissingsResolvingDataValues;
|
||||
public bool IsEmplty
|
||||
{
|
||||
get { return collectedMissingTypesBufferCount == 0; }
|
||||
@ -38,6 +38,7 @@ namespace DCFApixels.DragonECS.Unity.RefRepairer.Editors
|
||||
int offset = 0;
|
||||
int i = 0;
|
||||
int newLength = collectedMissingTypesBufferCount;
|
||||
bool isReturn = true;
|
||||
for (; i < newLength; i++)
|
||||
{
|
||||
ref var collectedMissingType = ref collectedMissingTypesBuffer[i];
|
||||
@ -49,10 +50,11 @@ namespace DCFApixels.DragonECS.Unity.RefRepairer.Editors
|
||||
}
|
||||
offset = 1;
|
||||
newLength--;
|
||||
isReturn = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (i >= newLength) { return; }
|
||||
if (isReturn) { return; }
|
||||
|
||||
int nextI = i + offset;
|
||||
for (; nextI < newLength; nextI++)
|
||||
@ -98,7 +100,6 @@ namespace DCFApixels.DragonECS.Unity.RefRepairer.Editors
|
||||
CollectByScriptableObjects();
|
||||
CollectByScenes();
|
||||
|
||||
MissingsResolvingDataValues = MissingsResolvingDatas.Values.ToArray();
|
||||
for (int i = collectedMissingTypesBufferCount; i < oldCollectedMissingTypesBufferCount; i++)
|
||||
{
|
||||
collectedMissingTypesBuffer[i] = default;
|
||||
@ -107,11 +108,19 @@ namespace DCFApixels.DragonECS.Unity.RefRepairer.Editors
|
||||
}
|
||||
private void Add(UnityObjectDataBase unityObjectData, ref ManagedReferenceMissingType missing)
|
||||
{
|
||||
var typeData = new TypeData(missing);
|
||||
if (MissingsResolvingDatas.TryGetValue(typeData, out var resolvingData) == false)
|
||||
var oldTypeData = new TypeData(missing);
|
||||
if (MissingsResolvingDatas.TryGetValue(oldTypeData, out var resolvingData) == false)
|
||||
{
|
||||
resolvingData = new MissingsResolvingData(typeData);
|
||||
MissingsResolvingDatas.Add(typeData, resolvingData);
|
||||
resolvingData = new MissingsResolvingData(oldTypeData);
|
||||
MissingsResolvingDatas.Add(oldTypeData, resolvingData);
|
||||
|
||||
if (MetaIDRegistry.instance.TryGetMetaID(oldTypeData, out string metaID))
|
||||
{
|
||||
if (UnityEditorUtility.TryGetTypeForMetaID(metaID, out Type type))
|
||||
{
|
||||
resolvingData.NewTypeData = new TypeData(type);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (collectedMissingTypesBufferCount >= collectedMissingTypesBuffer.Length)
|
||||
@ -255,7 +264,7 @@ namespace DCFApixels.DragonECS.Unity.RefRepairer.Editors
|
||||
return localIdProp.intValue;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//internal class ContainerMissingTypes
|
||||
//{
|
||||
|
@ -2,7 +2,6 @@
|
||||
using DCFApixels.DragonECS.Unity.RefRepairer.Internal;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
@ -37,10 +36,9 @@ namespace DCFApixels.DragonECS.Unity.RefRepairer.Editors
|
||||
return $"type: {{class: {typeData.ClassName}, ns: {typeData.NamespaceName}, asm: {typeData.AssemblyName}}}";
|
||||
}
|
||||
public static void RepaieAsset(MissingRefContainer container)
|
||||
{
|
||||
if (container.collectedMissingTypesBufferCount <= 0) { return; }
|
||||
{
|
||||
if (container.IsEmplty) { return; }
|
||||
|
||||
//MissingsResolvingData[] missingsResolvingDatas = container.MissingsResolvingDatas.Values.Where(o => o.IsResolved).ToArray();
|
||||
for (int i = 0; i < container.collectedMissingTypesBufferCount; i++)
|
||||
{
|
||||
ref var missing = ref container.collectedMissingTypesBuffer[i];
|
||||
@ -49,13 +47,10 @@ namespace DCFApixels.DragonECS.Unity.RefRepairer.Editors
|
||||
var unityObjectData = missing.UnityObject;
|
||||
using (var file = new FileScope(unityObjectData.GetLocalAssetPath()))
|
||||
{
|
||||
int startRepaierLineIndex = 0;//Ýòî íóæíî ÷òîáû ñêèïàòü óæå "îòðåìîíòèðîâàííóþ" ÷àñòü ôàéë.
|
||||
|
||||
// òóò èòåðèðóþñü ïî áëîêó missingsResolvingDatas ñ îäèíàêîâûì þíèòè îáúåêòîì, òàê êàê òàêèå èäåóò ïîäðÿò
|
||||
do
|
||||
{
|
||||
//bool isAnySkiped = false;
|
||||
int lineIndex = NextRefLine(file.lines, startRepaierLineIndex);
|
||||
int lineIndex = NextRefLine(file.lines, 0);
|
||||
while (lineIndex > 0)
|
||||
{
|
||||
var line = file.lines[lineIndex];
|
||||
@ -64,22 +59,14 @@ namespace DCFApixels.DragonECS.Unity.RefRepairer.Editors
|
||||
// A string that is equivalent to this instance except that all instances of oldChar are replaced with newChar.
|
||||
// If oldChar is not found in the current instance, the method returns the current instance unchanged.
|
||||
// À êîíêðåòíî ñòðî÷êè "returns the current instance unchanged", ìîæíî ñäåëàòü óïðîùåííóþ ïðîâåðêó ÷åðåç ReferenceEquals
|
||||
string oldLine = line;
|
||||
line = line.Replace(missing.ResolvingData.OldSerializedInfoLine, missing.ResolvingData.NewSerializedInfoLine);
|
||||
bool isChanged = !ReferenceEquals(oldLine, line);
|
||||
bool isChanged = !ReferenceEquals(file.lines[lineIndex], line);
|
||||
|
||||
|
||||
if (isChanged == false)
|
||||
{
|
||||
//isAnySkiped = true;
|
||||
}
|
||||
else
|
||||
if (isChanged)
|
||||
{
|
||||
file.lines[lineIndex] = line;
|
||||
break;
|
||||
//if (isAnySkiped == false)
|
||||
//{
|
||||
// startRepaierLineIndex = lineIndex;
|
||||
//}
|
||||
}
|
||||
lineIndex = NextRefLine(file.lines, lineIndex);
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
#if UNITY_EDITOR
|
||||
using System;
|
||||
using System.Text;
|
||||
using UnityEditor;
|
||||
|
||||
namespace DCFApixels.DragonECS.Unity.RefRepairer.Internal
|
||||
@ -36,6 +37,37 @@ namespace DCFApixels.DragonECS.Unity.RefRepairer.Internal
|
||||
NamespaceName = namespaceName;
|
||||
AssemblyName = assemblyName;
|
||||
}
|
||||
|
||||
[ThreadStatic]
|
||||
private static StringBuilder sb;
|
||||
public TypeData(Type type)
|
||||
{
|
||||
string name = null;
|
||||
if (type.DeclaringType == null)
|
||||
{
|
||||
name = type.Name;
|
||||
}
|
||||
else
|
||||
{
|
||||
Type iteratorType = type;
|
||||
if (sb == null)
|
||||
{
|
||||
sb = new StringBuilder();
|
||||
}
|
||||
sb.Clear();
|
||||
sb.Append(iteratorType.Name);
|
||||
while ((iteratorType = iteratorType.DeclaringType) != null)
|
||||
{
|
||||
sb.Insert(0, '/');
|
||||
sb.Insert(0, iteratorType.Name);
|
||||
}
|
||||
name = sb.ToString();
|
||||
}
|
||||
|
||||
ClassName = name;
|
||||
NamespaceName = type.Namespace;
|
||||
AssemblyName = type.Assembly.GetName().Name;
|
||||
}
|
||||
public bool Equals(TypeData other)
|
||||
{
|
||||
return ClassName == other.ClassName &&
|
||||
|
Loading…
Reference in New Issue
Block a user