improve performance

This commit is contained in:
CroakFang
2023-07-14 23:24:05 +08:00
parent 97a6322f13
commit ff406c4632
6 changed files with 113 additions and 99 deletions
+24 -25
View File
@@ -47,9 +47,12 @@ public class UmaAssetManager : MonoBehaviour
for(int i = 0; i < result.Count; i++)
{
LoadAB(result[i]);
OnLoadProgressChange?.Invoke(i, result.Count, null);
yield return null;
var exist = LoadAB(result[i]);
if (!exist)
{
OnLoadProgressChange?.Invoke(i, result.Count, null);
yield return null;
}
}
OnLoadProgressChange?.Invoke(-1, result.Count, null);
@@ -57,35 +60,39 @@ public class UmaAssetManager : MonoBehaviour
OnDone?.Invoke();
}
public static AssetBundle LoadAssetBundle(UmaDatabaseEntry entry, bool neverUnload = false)
public static AssetBundle LoadAssetBundle(UmaDatabaseEntry entry, bool neverUnload = false, bool isRecursive = true)
{
if (Exist(entry)) return Get(entry);
var Main = UmaViewerMain.Instance;
List<UmaDatabaseEntry> result = new List<UmaDatabaseEntry>();
SearchAB(Main, entry, ref result);
foreach(var e in result)
if (Exist(entry)) return Get(entry);
if (isRecursive)
{
LoadAB(e, neverUnload);
var Main = UmaViewerMain.Instance;
List<UmaDatabaseEntry> result = new List<UmaDatabaseEntry>();
SearchAB(Main, entry, ref result);
foreach (var e in result)
{
LoadAB(e, neverUnload);
}
return Get(entry.Name);
}
return Get(entry.Name);
LoadAB(entry, neverUnload);
return Get(entry);
}
private static void LoadAB(UmaDatabaseEntry entry, bool neverUnload = false)
private static bool LoadAB(UmaDatabaseEntry entry, bool neverUnload = false)
{
string filePath = entry.FilePath;
if (Exist(entry.Name))
{
return;
return true;
}
else if (File.Exists(filePath))
{
AssetBundle bundle = AssetBundle.LoadFromFile(filePath);
if (!bundle)
{
Debug.Log(filePath + " exists and doesn't work");
UmaViewerUI.Instance?.ShowMessage(filePath + " exists and doesn't work", UIMessageType.Error);
return;
}
AddOrUpdate(entry.Name, bundle, neverUnload);
if (!neverUnload)
@@ -98,6 +105,7 @@ public class UmaAssetManager : MonoBehaviour
Debug.LogError($"{entry.Name} - {filePath} does not exist");
UmaViewerUI.Instance?.ShowMessage($"{entry.Name} - {filePath} does not exist", UIMessageType.Error);
}
return false;
}
private static void SearchAB(UmaViewerMain Main, UmaDatabaseEntry entry,ref List<UmaDatabaseEntry> result)
@@ -106,16 +114,7 @@ public class UmaAssetManager : MonoBehaviour
{
foreach (string prerequisite in entry.Prerequisites.Split(';'))
{
if (prerequisite.StartsWith(UmaDatabaseController.CharaPath))
{
SearchAB(Main , Main.AbChara.FirstOrDefault(ab => ab.Name == prerequisite),ref result);
}
else if (prerequisite.StartsWith(UmaDatabaseController.MotionPath))
{
SearchAB(Main, Main.AbMotions.FirstOrDefault(ab => ab.Name == prerequisite), ref result);
}
else
SearchAB(Main, Main.AbList.FirstOrDefault(ab => ab.Name == prerequisite), ref result);
SearchAB(Main, Main.AbList[prerequisite], ref result);
}
}
result.Add(entry);