mirror of
https://github.com/DCFApixels/DragonECS-Unity.git
synced 2025-09-17 17:34:34 +08:00
fix references repairer
This commit is contained in:
parent
45c9c0a24c
commit
ac5b7ddbac
@ -67,6 +67,7 @@ namespace DCFApixels.DragonECS.Unity.Editors
|
||||
|
||||
if (componentProperty == null)
|
||||
{
|
||||
//Debug.Log(prop.displayName);
|
||||
throw new NullReferenceException();
|
||||
}
|
||||
}
|
||||
|
@ -47,7 +47,7 @@ namespace DCFApixels.DragonECS
|
||||
if (_components == null) { return; }
|
||||
foreach (var item in _components)
|
||||
{
|
||||
item.OnValidate(this);
|
||||
item?.OnValidate(this);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
@ -160,6 +160,15 @@ namespace DCFApixels.DragonECS.Unity.RefRepairer.Editors
|
||||
}
|
||||
using (EcsGUI.Layout.BeginVertical(_panel))
|
||||
{
|
||||
if (_missingRefContainer != null)
|
||||
{
|
||||
Debug.Log(_missingRefContainer.IsEmptyX);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log("NULL");
|
||||
}
|
||||
|
||||
const string LIST_EMPTY_MESSAGE = "List of Missings is Empty";
|
||||
const string COLLECT_BUTTON = "Collect Missings";
|
||||
if (_missingRefContainer.IsEmpty)
|
||||
@ -287,6 +296,11 @@ namespace DCFApixels.DragonECS.Unity.RefRepairer.Editors
|
||||
{
|
||||
_selectedMissingsResolvingData = null;
|
||||
RepaireFileUtility.RepaieAsset(_missingRefContainer);
|
||||
if (_missingRefContainer.IsEmpty)
|
||||
{
|
||||
_isNoFound = true;
|
||||
MetaIDRegistry.instance.Reinit();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -15,6 +15,7 @@ namespace DCFApixels.DragonECS.Unity.RefRepairer.Editors
|
||||
{
|
||||
internal class MissingRefContainer
|
||||
{
|
||||
// обязательно распологать так чтобы записи сссылающиеся на один и тот же ассет шли подряд друг за другом
|
||||
public CollectedAssetMissingRecord[] collectedMissingTypesBuffer = null;
|
||||
public int collectedMissingTypesBufferCount = 0;
|
||||
public readonly Dictionary<TypeData, MissingsResolvingData> MissingsResolvingDatas = new Dictionary<TypeData, MissingsResolvingData>();
|
||||
@ -22,6 +23,10 @@ namespace DCFApixels.DragonECS.Unity.RefRepairer.Editors
|
||||
{
|
||||
get { return collectedMissingTypesBufferCount == 0; }
|
||||
}
|
||||
public int IsEmptyX
|
||||
{
|
||||
get { return collectedMissingTypesBufferCount; }
|
||||
}
|
||||
|
||||
#region Clear/RemoveResolved
|
||||
public void Clear()
|
||||
@ -35,53 +40,57 @@ namespace DCFApixels.DragonECS.Unity.RefRepairer.Editors
|
||||
}
|
||||
public void RemoveResolved()
|
||||
{
|
||||
int offset = 0;
|
||||
int i = 0;
|
||||
int newLength = collectedMissingTypesBufferCount;
|
||||
bool isReturn = true;
|
||||
for (; i < newLength; i++)
|
||||
int startI = 0;
|
||||
int newCollectedMissingTypesBufferCount = collectedMissingTypesBufferCount;
|
||||
bool isNoResolved = true;
|
||||
// тут проверяется что есть разрешенные миссинги
|
||||
// или просто скипается часть с не разрешенными миссингами
|
||||
for (; startI < collectedMissingTypesBufferCount; startI++)
|
||||
{
|
||||
ref var collectedMissingType = ref collectedMissingTypesBuffer[i];
|
||||
ref var collectedMissingType = ref collectedMissingTypesBuffer[startI];
|
||||
if (collectedMissingType.IsResolvedOrNull)
|
||||
{
|
||||
if (collectedMissingType.ResolvingData != null)
|
||||
{
|
||||
MissingsResolvingDatas.Remove(collectedMissingType.ResolvingData.OldTypeData);
|
||||
}
|
||||
offset = 1;
|
||||
newLength--;
|
||||
isReturn = false;
|
||||
newCollectedMissingTypesBufferCount--;
|
||||
isNoResolved = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (isReturn) { return; }
|
||||
if (isNoResolved) { return; }
|
||||
// тут один разрешенный миссинг уже найден
|
||||
|
||||
int nextI = i + offset;
|
||||
for (; nextI < newLength; nextI++)
|
||||
int nextI = startI + 1;
|
||||
for (; nextI < collectedMissingTypesBufferCount;)
|
||||
{
|
||||
ref var collectedMissingType = ref collectedMissingTypesBuffer[i];
|
||||
ref var collectedMissingType = ref collectedMissingTypesBuffer[nextI];
|
||||
if (collectedMissingType.IsResolvedOrNull)
|
||||
{
|
||||
if (collectedMissingType.ResolvingData != null)
|
||||
{
|
||||
MissingsResolvingDatas.Remove(collectedMissingType.ResolvingData.OldTypeData);
|
||||
}
|
||||
offset++;
|
||||
newLength--;
|
||||
newCollectedMissingTypesBufferCount--;
|
||||
nextI++;
|
||||
}
|
||||
else
|
||||
{
|
||||
collectedMissingTypesBuffer[i] = collectedMissingTypesBuffer[nextI];
|
||||
i++;
|
||||
collectedMissingTypesBuffer[startI] = collectedMissingTypesBuffer[nextI];
|
||||
startI++;
|
||||
nextI++;
|
||||
}
|
||||
}
|
||||
|
||||
for (i = newLength; i < collectedMissingTypesBufferCount; i++)
|
||||
|
||||
//очистка хвостовой части откуда все уехало
|
||||
for (startI = newCollectedMissingTypesBufferCount; startI < collectedMissingTypesBufferCount; startI++)
|
||||
{
|
||||
collectedMissingTypesBuffer[i] = default;
|
||||
collectedMissingTypesBuffer[startI] = default;
|
||||
}
|
||||
|
||||
collectedMissingTypesBufferCount = newLength;
|
||||
collectedMissingTypesBufferCount = newCollectedMissingTypesBufferCount;
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
@ -39,43 +39,40 @@ namespace DCFApixels.DragonECS.Unity.RefRepairer.Editors
|
||||
{
|
||||
if (container.IsEmpty) { return; }
|
||||
|
||||
UnityObjectDataBase unityObjectData = null;
|
||||
FileScope fileScope = default;
|
||||
for (int i = 0; i < container.collectedMissingTypesBufferCount; i++)
|
||||
{
|
||||
ref var missing = ref container.collectedMissingTypesBuffer[i];
|
||||
if (missing.IsNull) { continue; }
|
||||
|
||||
var unityObjectData = missing.UnityObject;
|
||||
using (var file = new FileScope(unityObjectData.GetLocalAssetPath()))
|
||||
if (unityObjectData != missing.UnityObject)
|
||||
{
|
||||
// òóò èòåðèðóþñü ïî áëîêó missingsResolvingDatas ñ îäèíàêîâûì þíèòè îáúåêòîì, òàê êàê òàêèå èäåóò ïîäðÿò
|
||||
do
|
||||
unityObjectData = missing.UnityObject;
|
||||
fileScope.Dispose();
|
||||
fileScope = new FileScope(unityObjectData.GetLocalAssetPath());
|
||||
}
|
||||
|
||||
int lineIndex = NextRefLine(fileScope.lines, 0);
|
||||
while (lineIndex > 0)
|
||||
{
|
||||
var line = fileScope.lines[lineIndex];
|
||||
|
||||
// Êàê ñêàçàííî â äîêóìåíòàöèè ê ìåòîäó Replace
|
||||
// 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
|
||||
line = line.Replace(missing.ResolvingData.OldSerializedInfoLine, missing.ResolvingData.NewSerializedInfoLine);
|
||||
bool isChanged = !ReferenceEquals(fileScope.lines[lineIndex], line);
|
||||
|
||||
if (isChanged)
|
||||
{
|
||||
int lineIndex = NextRefLine(file.lines, 0);
|
||||
while (lineIndex > 0)
|
||||
{
|
||||
var line = file.lines[lineIndex];
|
||||
|
||||
// Êàê ñêàçàííî â äîêóìåíòàöèè ê ìåòîäó Replace
|
||||
// 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
|
||||
line = line.Replace(missing.ResolvingData.OldSerializedInfoLine, missing.ResolvingData.NewSerializedInfoLine);
|
||||
bool isChanged = !ReferenceEquals(file.lines[lineIndex], line);
|
||||
|
||||
|
||||
if (isChanged)
|
||||
{
|
||||
file.lines[lineIndex] = line;
|
||||
break;
|
||||
}
|
||||
lineIndex = NextRefLine(file.lines, lineIndex);
|
||||
}
|
||||
|
||||
missing = ref container.collectedMissingTypesBuffer[i++];
|
||||
} while (unityObjectData == missing.UnityObject);
|
||||
i--;//÷òîáû èòåðàöèÿ íå ïîëîìàëàñü
|
||||
fileScope.lines[lineIndex] = line;
|
||||
break;
|
||||
}
|
||||
lineIndex = NextRefLine(fileScope.lines, lineIndex);
|
||||
}
|
||||
}
|
||||
fileScope.Dispose();
|
||||
|
||||
container.RemoveResolved();
|
||||
}
|
||||
public struct FileScope : IDisposable
|
||||
@ -92,6 +89,7 @@ namespace DCFApixels.DragonECS.Unity.RefRepairer.Editors
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (string.IsNullOrEmpty(FilePath)) { return; }
|
||||
File.WriteAllLines(FilePath, lines);
|
||||
AssetDatabase.ImportAsset(LocalAssetPath, ImportAssetOptions.ForceUpdate);
|
||||
AssetDatabase.Refresh();
|
||||
|
Loading…
Reference in New Issue
Block a user