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);
@@ -43,7 +43,7 @@ public class UmaDatabaseController
/// <summary> outgame/dress/ </summary>
public static string CostumePath = "outgame/dress/";
public List<UmaDatabaseEntry> MetaEntries;
public Dictionary<string, UmaDatabaseEntry> MetaEntries;
public List<DataRow> CharaData;
public List<DataRow> MobCharaData;
public List<FaceTypeData> FaceTypeData;
@@ -99,12 +99,12 @@ public class UmaDatabaseController
}
}
static List<UmaDatabaseEntry> ReadMeta(SqliteConnection conn)
static Dictionary<string,UmaDatabaseEntry> ReadMeta(SqliteConnection conn)
{
SqliteCommand sqlite_cmd = conn.CreateCommand();
sqlite_cmd.CommandText = "SELECT m,n,h,c,d FROM a";
SqliteDataReader sqlite_datareader = sqlite_cmd.ExecuteReader();
List<UmaDatabaseEntry> meta = new List<UmaDatabaseEntry>();
Dictionary<string, UmaDatabaseEntry> meta = new Dictionary<string, UmaDatabaseEntry>();
while (sqlite_datareader.Read())
{
UmaDatabaseEntry entry = null;
@@ -112,17 +112,16 @@ public class UmaDatabaseController
{
entry = new UmaDatabaseEntry()
{
Type = (UmaFileType)Enum.Parse(typeof(UmaFileType), sqlite_datareader["m"] as String),
Name = sqlite_datareader["n"] as String,
Url = sqlite_datareader["h"] as String,
Type = (UmaFileType)Enum.Parse(typeof(UmaFileType), sqlite_datareader["m"] as string),
Name = sqlite_datareader["n"] as string,
Url = sqlite_datareader["h"] as string,
Checksum = sqlite_datareader["c"].ToString(),
Prerequisites = sqlite_datareader["d"] as String
Prerequisites = sqlite_datareader["d"] as string
};
}
catch(Exception e) { Debug.LogError("Error caught: " + e); }
if (entry != null)
meta.Add(entry);
if (entry != null) meta.Add(entry.Name, entry);
}
return meta;
}
+38 -40
View File
@@ -812,7 +812,7 @@ public class UmaViewerBuilder : MonoBehaviour
//load BG
string nameVar = $"snd_bgm_live_{songid}_oke";
UmaDatabaseEntry BGawb = Main.AbList.FirstOrDefault(a => a.Name.Contains(nameVar) && a.Name.EndsWith("awb"));
UmaDatabaseEntry BGawb = Main.AbSounds.FirstOrDefault(a => a.Name.Contains(nameVar) && a.Name.EndsWith("awb"));
if (BGawb != null)
{
var BGclip = LoadAudio(BGawb);
@@ -905,7 +905,7 @@ public class UmaViewerBuilder : MonoBehaviour
if (CurrentLyrics.Count > 0) CurrentLyrics.Clear();
string lyricsVar = $"live/musicscores/m{songid}/m{songid}_lyrics";
UmaDatabaseEntry lyricsAsset = Main.AbList.FirstOrDefault(a => a.Name.Contains(lyricsVar));
UmaDatabaseEntry lyricsAsset = Main.AbList[lyricsVar];
AssetBundle bundle = UmaAssetManager.LoadAssetBundle(lyricsAsset);
TextAsset asset = bundle.LoadAsset<TextAsset>(Path.GetFileNameWithoutExtension(lyricsVar));
string[] lines = asset.text.Split("\n"[0]);
@@ -935,16 +935,7 @@ public class UmaViewerBuilder : MonoBehaviour
{
foreach (string prerequisite in entry.Prerequisites.Split(';'))
{
if (prerequisite.StartsWith(UmaDatabaseController.CharaPath))
{
RecursiveLoadAsset(Main.AbChara.FirstOrDefault(ab => ab.Name == prerequisite), true, SetParent);
}
else if (prerequisite.StartsWith(UmaDatabaseController.MotionPath))
{
RecursiveLoadAsset(Main.AbMotions.FirstOrDefault(ab => ab.Name == prerequisite), true, SetParent);
}
else
RecursiveLoadAsset(Main.AbList.FirstOrDefault(ab => ab.Name == prerequisite), true, SetParent);
RecursiveLoadAsset(Main.AbList[prerequisite], true, SetParent);
}
}
LoadAsset(entry, IsSubAsset, SetParent);
@@ -953,7 +944,7 @@ public class UmaViewerBuilder : MonoBehaviour
public void LoadAsset(UmaDatabaseEntry entry, bool IsSubAsset = false, Transform SetParent = null)
{
Debug.Log("Loading " + entry.Name);
var bundle = UmaAssetManager.LoadAssetBundle(entry);
var bundle = UmaAssetManager.LoadAssetBundle(entry, isRecursive: false);
LoadBundle(bundle, IsSubAsset, SetParent);
}
@@ -1443,10 +1434,7 @@ public class UmaViewerBuilder : MonoBehaviour
public void LoadAssetPath(string path, Transform SetParent)
{
foreach (var asset in UmaViewerMain.Instance.AbList.Where(a => a.Name == path))
{
RecursiveLoadAsset(asset, false, SetParent);
}
RecursiveLoadAsset(UmaViewerMain.Instance.AbList[path], false, SetParent);
}
private void LoadTear(GameObject go)
@@ -1468,7 +1456,7 @@ public class UmaViewerBuilder : MonoBehaviour
private void LoadFaceMorph(int id, string costumeId)
{
if (!CurrentUMAContainer.Head) return;
var locatorEntry = Main.AbList.FirstOrDefault(a => a.Name == "3d/animator/drivenkeylocator");
var locatorEntry = Main.AbList["3d/animator/drivenkeylocator"];
var bundle = UmaAssetManager.LoadAssetBundle(locatorEntry);
var locator = Instantiate(bundle.LoadAsset("DrivenKeyLocator"), CurrentUMAContainer.transform) as GameObject;
locator.name = "DrivenKeyLocator";
@@ -1668,8 +1656,17 @@ public class UmaViewerBuilder : MonoBehaviour
string[] param = clip.name.Split('_');
if (param.Length > 4)
{
int index = int.Parse(param[4]) + 1;
var nextMotion = Main.AbMotions.FirstOrDefault(a => a.Name.EndsWith($"{param[0]}_{param[1]}_{param[2]}_{param[3]}_0{index}"));
int index = int.Parse(param[4]);
if(index == 1)
{
foreach(var entry in Main.AbMotions.Where(a => a.Name.Contains($"{param[0]}_{param[1]}_{param[2]}_{param[3]}_")))
{
UmaAssetManager.LoadAssetBundle(entry, isRecursive: false);
}
}
index++;
var nextMotion = Main.AbMotions.FirstOrDefault(a => a.Name.EndsWith($"{param[0]}_{param[1]}_{param[2]}_{param[3]}_0{index}"));
var aevent = new AnimationEvent
{
time = clip.length * 0.99f,
@@ -1821,8 +1818,7 @@ public class UmaViewerBuilder : MonoBehaviour
public Sprite LoadCharaIcon(string id)
{
string value = $"chara/chr{id}/chr_icon_{id}";
var entry = UmaViewerMain.Instance.AbList.FirstOrDefault(a => a.Name.Equals(value));
if (entry != null)
if (UmaViewerMain.Instance.AbList.TryGetValue(value,out UmaDatabaseEntry entry))
{
AssetBundle assetBundle = UmaAssetManager.LoadAssetBundle(entry, true);
if (assetBundle.Contains($"chr_icon_{id}"))
@@ -1839,16 +1835,16 @@ public class UmaViewerBuilder : MonoBehaviour
public Sprite LoadMobCharaIcon(string id)
{
string value = $"mob/mob_chr_icon_{id}_000001_01";
var entry = UmaViewerMain.Instance.AbList.FirstOrDefault(a => a.Name.Equals(value));
if (entry == null) { return null; }
string path = entry.FilePath;
AssetBundle assetBundle = UmaAssetManager.LoadAssetBundle(entry, true);
if (assetBundle.Contains($"mob_chr_icon_{id}_000001_01"))
{
Texture2D texture = (Texture2D)assetBundle.LoadAsset($"mob_chr_icon_{id}_000001_01");
Sprite sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), Vector2.zero);
assetBundle.Unload(false);
return sprite;
if (UmaViewerMain.Instance.AbList.TryGetValue(value,out UmaDatabaseEntry entry)) {
string path = entry.FilePath;
AssetBundle assetBundle = UmaAssetManager.LoadAssetBundle(entry, true);
if (assetBundle.Contains($"mob_chr_icon_{id}_000001_01"))
{
Texture2D texture = (Texture2D)assetBundle.LoadAsset($"mob_chr_icon_{id}_000001_01");
Sprite sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), Vector2.zero);
assetBundle.Unload(false);
return sprite;
}
}
return null;
}
@@ -1865,15 +1861,17 @@ public class UmaViewerBuilder : MonoBehaviour
public Sprite LoadLiveIcon(int musicid)
{
string value = $"live/jacket/jacket_icon_l_{musicid}";
var entry = UmaViewerMain.Instance.AbList.FirstOrDefault(a => a.Name.Equals(value));
if (entry == null) return null;
AssetBundle assetBundle = UmaAssetManager.LoadAssetBundle(entry, true);
if (assetBundle.Contains($"jacket_icon_l_{musicid}"))
if (UmaViewerMain.Instance.AbList.TryGetValue(value, out UmaDatabaseEntry entry))
{
Texture2D texture = (Texture2D)assetBundle.LoadAsset($"jacket_icon_l_{musicid}");
Sprite sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), Vector2.zero);
assetBundle.Unload(false);
return sprite;
AssetBundle assetBundle = UmaAssetManager.LoadAssetBundle(entry, true);
if (assetBundle.Contains($"jacket_icon_l_{musicid}"))
{
Texture2D texture = (Texture2D)assetBundle.LoadAsset($"jacket_icon_l_{musicid}");
Sprite sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), Vector2.zero);
assetBundle.Unload(false);
return sprite;
}
}
return null;
}
+9 -9
View File
@@ -16,7 +16,7 @@ public class UmaViewerMain : MonoBehaviour
public List<CharaEntry> MobCharacters = new List<CharaEntry>();
public List<LiveEntry> Lives = new List<LiveEntry>();
public List<CostumeEntry> Costumes = new List<CostumeEntry>();
public List<UmaDatabaseEntry> AbList = new List<UmaDatabaseEntry>();
public Dictionary<string,UmaDatabaseEntry> AbList = new Dictionary<string, UmaDatabaseEntry>();
public List<UmaDatabaseEntry> AbMotions = new List<UmaDatabaseEntry>();
public List<UmaDatabaseEntry> AbSounds = new List<UmaDatabaseEntry>();
public List<UmaDatabaseEntry> AbChara = new List<UmaDatabaseEntry>();
@@ -28,12 +28,12 @@ public class UmaViewerMain : MonoBehaviour
Instance = this;
new Config();
Application.targetFrameRate = 120;
AbList = UmaDatabaseController.Instance.MetaEntries.ToList();
AbChara = AbList.Where(ab => ab.Name.StartsWith(UmaDatabaseController.CharaPath)).ToList();
AbMotions = AbList.Where(ab => ab.Name.StartsWith(UmaDatabaseController.MotionPath)).ToList();
AbEffect = AbList.Where(ab => ab.Name.StartsWith(UmaDatabaseController.EffectPath)).ToList();
AbSounds = AbList.Where(ab => ab.Name.EndsWith(".awb") || ab.Name.EndsWith(".acb")).ToList();
CostumeList = AbList.Where(ab => ab.Name.StartsWith(UmaDatabaseController.CostumePath)).ToList();
AbList = UmaDatabaseController.Instance.MetaEntries;
AbChara = AbList.Where(ab => ab.Key.StartsWith(UmaDatabaseController.CharaPath)).Select(ab=>ab.Value).ToList();
AbMotions = AbList.Where(ab => ab.Key.StartsWith(UmaDatabaseController.MotionPath)).Select(ab => ab.Value).ToList();
AbEffect = AbList.Where(ab => ab.Key.StartsWith(UmaDatabaseController.EffectPath)).Select(ab => ab.Value).ToList();
AbSounds = AbList.Where(ab => ab.Key.EndsWith(".awb") || ab.Key.EndsWith(".acb")).Select(ab => ab.Value).ToList();
CostumeList = AbList.Where(ab => ab.Key.StartsWith(UmaDatabaseController.CostumePath)).Select(ab => ab.Value).ToList();
}
private IEnumerator Start()
@@ -142,7 +142,7 @@ public class UmaViewerMain : MonoBehaviour
loadingUI.LoadingProgressChange(5, 11, "Loading Live Data");
yield return null;
var asset = AbList.FirstOrDefault(a => a.Name.Equals("livesettings"));
var asset = AbList["livesettings"];
if (asset != null)
{
string filePath = asset.FilePath;
@@ -193,7 +193,7 @@ public class UmaViewerMain : MonoBehaviour
UI.LoadLivePanels();
loadingUI.LoadingProgressChange(-1, -1);
UmaAssetManager.LoadAssetBundle(AbList.FirstOrDefault(e => e.Name.Equals("shader")), true); //Load Shader First
UmaAssetManager.LoadAssetBundle(AbList["shader"], true); //Load Shader First
}
public void OpenUrl(string url)
+33 -15
View File
@@ -614,14 +614,14 @@ public class UmaViewerUI : MonoBehaviour
public void LoadPropPanel()
{
var pageentrys = new List<PageManager.Entry>();
foreach (var prop in Main.AbList.Where(a => a.Name.Contains("pfb_chr_prop") && !a.Name.Contains("clothes")))
foreach (var prop in Main.AbList.Where(a => a.Key.Contains("pfb_chr_prop") && !a.Key.Contains("clothes")))
{
var pageentry = new PageManager.Entry();
pageentry.Name = Path.GetFileName(prop.Name);
pageentry.Name = Path.GetFileName(prop.Key);
pageentry.OnClick = (container) =>
{
HighlightChildImage(PropList.content, container);
Builder.LoadProp(prop);
Builder.LoadProp(prop.Value);
};
pageentrys.Add(pageentry);
}
@@ -631,15 +631,15 @@ public class UmaViewerUI : MonoBehaviour
public void LoadMapPanel()
{
var pageentrys = new List<PageManager.Entry>();
foreach (var scene in Main.AbList.Where(a => ((a.Name.StartsWith("3d/env") && Path.GetFileName(a.Name).StartsWith("pfb_")) || a.Name.StartsWith("cutt/cutt_son") && Path.GetFileName(a.Name).StartsWith("cutt_son"))))
foreach (var scene in Main.AbList.Where(a => ((a.Key.StartsWith("3d/env") && Path.GetFileName(a.Key).StartsWith("pfb_")) || a.Key.StartsWith("cutt/cutt_son") && Path.GetFileName(a.Key).StartsWith("cutt_son"))))
{
var pageentry = new PageManager.Entry();
pageentry.Name = Path.GetFileName(scene.Name);
pageentry.Name = Path.GetFileName(scene.Key);
pageentry.FontSize = 19;
pageentry.OnClick = (container) =>
{
HighlightChildImage(SceneList.content, container);
Builder.LoadProp(scene);
Builder.LoadProp(scene.Value);
};
pageentrys.Add(pageentry);
}
@@ -726,10 +726,10 @@ public class UmaViewerUI : MonoBehaviour
Action<CharaEntry> action = delegate (CharaEntry achara)
{
string nameVar = mini ? $"pfb_mbdy{achara.Id}" : $"pfb_bdy{achara.Id}";
foreach (var entry in Main.AbList.Where(a => !a.Name.Contains("clothes") && a.Name.Contains(nameVar)))
foreach (var entry in Main.AbList.Where(a => !a.Key.Contains("clothes") && a.Key.Contains(nameVar)))
{
var container = Instantiate(UmaContainerCostumePrefab, costumeList.content).GetComponent<UmaUIContainer>();
string[] split = entry.Name.Split('_');
string[] split = entry.Key.Split('_');
string costumeId = split[split.Length - 1];
var dressdata = Main.Costumes.FirstOrDefault(a => (a.CharaId == achara.Id && a.BodyTypeSub == int.Parse(costumeId)));
container.Name = container.name = GetCostumeName(costumeId, (dressdata == null ? costumeId : dressdata.DressName));
@@ -745,9 +745,15 @@ public class UmaViewerUI : MonoBehaviour
{
HighlightChildImage(costumeList.content, container);
var list = new List<UmaDatabaseEntry>();
list.AddRange(Main.AbChara.FindAll(a => a.Name.Contains($"{achara.Id}")));
list.AddRange(Main.AbChara.Where(a => a.Name.StartsWith(UmaDatabaseController.BodyPath) && a.Name.Contains(chara.Id.ToString())));
list.AddRange(Main.AbChara.Where(a => a.Name.StartsWith(UmaDatabaseController.HeadPath) && a.Name.Contains(chara.Id.ToString())));
list.AddRange(Main.AbChara.Where(a => a.Name.StartsWith("3d/chara/tail")));
list.Add(Main.AbList["3d/animator/drivenkeylocator"]);
list.Add(Main.AbMotions.FirstOrDefault(a => a.Name.EndsWith($"anm_eve_chr{chara.Id}_00_idle01_loop")));
Builder.UnloadUma();
UmaAssetManager.UnloadAllBundle(true);
//UmaAssetManager.UnloadAllBundle(true);
UmaAssetManager.PreLoadAndRun(list , delegate {
StartCoroutine(Builder.LoadUma(achara, costumeId, mini));
});
@@ -791,7 +797,20 @@ public class UmaViewerUI : MonoBehaviour
else
{
HighlightChildImage(costumeList.content, container);
StartCoroutine(Builder.LoadUma(chara, costumeId, mini));
var list = new List<UmaDatabaseEntry>();
list.AddRange(Main.AbChara.Where(a => a.Name.StartsWith(UmaDatabaseController.BodyPath) && a.Name.Contains(chara.Id.ToString())));
list.AddRange(Main.AbChara.Where(a => a.Name.StartsWith(UmaDatabaseController.HeadPath) && a.Name.Contains(chara.Id.ToString())));
list.AddRange(Main.AbChara.Where(a => a.Name.StartsWith("3d/chara/tail")));
list.Add(Main.AbList["3d/animator/drivenkeylocator"]);
list.Add(Main.AbMotions.FirstOrDefault(a => a.Name.EndsWith($"anm_eve_chr{chara.Id}_00_idle01_loop")));
Builder.UnloadUma();
//UmaAssetManager.UnloadAllBundle(true);
UmaAssetManager.PreLoadAndRun(list, delegate {
StartCoroutine(Builder.LoadUma(chara, costumeId, mini));
});
//StartCoroutine(Builder.LoadUma(achara, costumeId, mini));
}
});
}
@@ -962,13 +981,12 @@ public class UmaViewerUI : MonoBehaviour
void ListBackgrounds()
{
var bglist = Main.AbList.Where(a => a.Name.StartsWith("bg/bg"));
var pageentrys = new List<PageManager.Entry>();
foreach (var entry in bglist)
foreach (var entry in Main.AbList.Where(a => a.Key.StartsWith("bg/bg")))
{
var pageentry = new PageManager.Entry();
pageentry.Name = Path.GetFileName(entry.Name);
pageentry.Sprite = Builder.LoadSprite(entry);
pageentry.Name = Path.GetFileName(entry.Key);
pageentry.Sprite = Builder.LoadSprite(entry.Value);
if (pageentry.Sprite == null) continue;
pageentry.OnClick = (container) =>
{
@@ -371,7 +371,7 @@ namespace Gallop.Live
};
//Get live parts info
UmaDatabaseEntry partAsset = UmaViewerMain.Instance.AbList.FirstOrDefault(a => a.Name.Contains(string.Format(LIVE_PART_PATH, live.MusicId)));
UmaDatabaseEntry partAsset = UmaViewerMain.Instance.AbList[string.Format(LIVE_PART_PATH, live.MusicId)];
Debug.Log(partAsset.Name);