improve assetbundles loading

This commit is contained in:
左右看
2023-07-02 00:47:02 +08:00
parent 1642fabc93
commit e19124cd2c
14 changed files with 127 additions and 60 deletions
+4
View File
@@ -76,10 +76,14 @@ public class UmaContainer : MonoBehaviour
public GameObject PhysicsContainer;
public float BodyScale = 1;
[Header("Live")]
public bool IsLive = false;
[Header("Other")]
public CharaShaderEffectData ShaderEffectData;
private List<MaterialHelper> Materials = new List<MaterialHelper>();
public void Initialize(bool smile)
{
TrackTarget = new GameObject("TrackTarget").transform;
+49 -8
View File
@@ -11,6 +11,7 @@ using System.IO;
using System.Linq;
using UmaMusumeAudio;
using UnityEngine;
using static UnityEngine.Rendering.VirtualTexturing.Debugging;
using Random = UnityEngine.Random;
public class UmaViewerBuilder : MonoBehaviour
@@ -84,6 +85,22 @@ public class UmaViewerBuilder : MonoBehaviour
yield break;
}
public IEnumerator LoadLiveUma(List<LiveCharacterSelect> characters)
{
UnloadAllBundle();
for (int i = 0; i < characters.Count; i++)
{
CurrentUMAContainer = new GameObject($"Chara_{characters[i].CharaEntry.Id}_{characters[i].CostumeId}").AddComponent<UmaContainer>();
CurrentUMAContainer.IsLive = true;
CurrentUMAContainer.CharaData = UmaDatabaseController.ReadCharaData(characters[i].CharaEntry);
CurrentUMAContainer.transform.parent = Gallop.Live.Director.instance.charaObjs[i];
LoadNormalUma(characters[i].CharaEntry, characters[i].CostumeId);
}
yield break;
}
private void LoadNormalUma(CharaEntry chara, string costumeId)
{
int id = chara.Id;
@@ -653,6 +670,8 @@ public class UmaViewerBuilder : MonoBehaviour
a.CostumeId = "00";
}
});//fill empty
GameObject MainLive = new GameObject("Live");
GameObject Director = new GameObject("Director");
@@ -661,6 +680,8 @@ public class UmaViewerBuilder : MonoBehaviour
Instantiate(mController, MainLive.transform);
Destroy(Director);
StartCoroutine(LoadLiveUma(characters));
}
//Use CriWare Library
@@ -848,6 +869,20 @@ public class UmaViewerBuilder : MonoBehaviour
}
}
public AssetBundle LoadOrGet(UmaDatabaseEntry entry)
{
if ((Main.LoadedBundles.ContainsKey(entry.Name)))
{
return Main.LoadedBundles[entry.Name];
}
else
{
var bundle = AssetBundle.LoadFromFile(entry.FilePath);
Main.LoadedBundles.Add(entry.Name, bundle);
return bundle;
}
}
public void RecursiveLoadAsset(UmaDatabaseEntry entry, bool IsSubAsset = false, Transform SetParent = null )
{
if (!string.IsNullOrEmpty(entry.Prerequisites))
@@ -872,10 +907,12 @@ public class UmaViewerBuilder : MonoBehaviour
public void LoadAsset(UmaDatabaseEntry entry, bool IsSubAsset = false, Transform SetParent = null)
{
Debug.Log("Loading " + entry.Name);
if (Main.LoadedBundles.ContainsKey(entry.Name)) return;
string filePath = entry.FilePath;
if (File.Exists(filePath))
if (Main.LoadedBundles.ContainsKey(entry.Name))
{
LoadBundle(Main.LoadedBundles[entry.Name], IsSubAsset, SetParent);
}
else if (File.Exists(filePath))
{
AssetBundle bundle = AssetBundle.LoadFromFile(filePath);
if (bundle == null)
@@ -982,7 +1019,10 @@ public class UmaViewerBuilder : MonoBehaviour
break;
}
case Shader sha:
ShaderList.Add(sha);
if (!ShaderList.Contains(sha))
{
ShaderList.Add(sha);
}
break;
case Texture2D tex2D:
@@ -1355,6 +1395,8 @@ public class UmaViewerBuilder : MonoBehaviour
{
var container = CurrentOtherContainer;
var prop = Instantiate(go, SetParent ? SetParent : container.transform);
/*
foreach (Renderer r in prop.GetComponentsInChildren<Renderer>())
{
foreach (Material m in r.sharedMaterials)
@@ -1363,6 +1405,7 @@ public class UmaViewerBuilder : MonoBehaviour
m.shader = Shader.Find("Unlit/Transparent Cutout");
}
}
*/
}
public void LoadAssetPath(string path, Transform SetParent)
@@ -1393,8 +1436,7 @@ public class UmaViewerBuilder : MonoBehaviour
{
if (!CurrentUMAContainer.Head) return;
var locatorEntry = Main.AbList.FirstOrDefault(a => a.Name == "3d/animator/drivenkeylocator");
var bundle = AssetBundle.LoadFromFile(locatorEntry.FilePath);
Main.LoadedBundles.Add(locatorEntry.Name, bundle);
var bundle = LoadOrGet(locatorEntry);
var locator = Instantiate(bundle.LoadAsset("DrivenKeyLocator"), CurrentUMAContainer.transform) as GameObject;
locator.name = "DrivenKeyLocator";
@@ -1406,8 +1448,7 @@ public class UmaViewerBuilder : MonoBehaviour
var mangaObjects = new List<GameObject>();
mangaEntry.ForEach(entry =>
{
AssetBundle ab = AssetBundle.LoadFromFile(entry.FilePath);
Main.LoadedBundles.Add(entry.Name, ab);
AssetBundle ab = LoadOrGet(entry);
var obj = ab.LoadAsset(Path.GetFileNameWithoutExtension(entry.Name)) as GameObject;
obj.SetActive(false);
+1
View File
@@ -351,6 +351,7 @@ public class UmaViewerUI : MonoBehaviour
foreach (var prop in extraMorph.BindProperties)
{
var container = Instantiate(UmaContainerSliderPrefab, TargetList.content).GetComponent<UmaUIContainer>();
Debug.Log(morph.name);
container.Name = $"{morph.locator.name}({prop.Type})";
container.Slider.value = prop.Value;
switch (prop.Type)
@@ -28,6 +28,10 @@ namespace Gallop.Live.Cutt
private void Awake()
{
InitializeTimeLineData();
if (Director.instance)
{
Director.instance._liveTimelineControl = this;
}
}
public void InitializeTimeLineData()
@@ -6,6 +6,7 @@ using System.Runtime.CompilerServices;
using UnityEngine;
using Gallop.Live.Cutt;
using static Director;
using UnityEditor.SceneManagement;
namespace Gallop.Live
{
@@ -150,11 +151,11 @@ namespace Gallop.Live
private const float LiveTotalTimeMargin = 0;
private const float MaxOutlineOffLength = 99999;
private const int FINALIZE_CAMERA_DEPTH = 19;
private static Director _instance;
private static Director _instance = null;
[SerializeField]
private Director.State _state;
private bool _isDestroyed;
private LiveTimelineControl _liveTimelineControl;
public LiveTimelineControl _liveTimelineControl; //Edited to public
private bool _isFinished;
private readonly RandomTable<float> _randomTable;
private RandomRatioTable _blinkLightRandomRatioTable;
@@ -167,7 +168,7 @@ namespace Gallop.Live
private bool _isEnableBloom;
private bool _isBloom;
private bool _isDof;
private StageController _stageController;
public StageController _stageController; //Edited to public
private bool _isEnabledStageController;
public RenderTexture[] MonitorTextureArray;
[SerializeField]
@@ -255,7 +256,7 @@ namespace Gallop.Live
private Vector3 _tempRateVector;
private Vector3 _tempAttachRateVector;
public static Director Instance { get; }
public static Director instance => _instance;
public static bool HasInstance { get; }
public LiveTimelineControl LiveTimelineControl { get; }
public Director.DisplayMode displayMode { get; set; }
@@ -303,18 +304,38 @@ namespace Gallop.Live
public static RegisterInfo[] EffectRegisterInfoArray { get; set; }
public static Dictionary<string, List<string>> FlashSeCueNameDict { get; set; }
//Testing
//
public LiveEntry live;
private const string CUTT_PATH = "cutt/cutt_son{0}/cutt_son{0}";
private const string STAGE_PATH = "3d/env/live/live{0}/pfb_env_live{0}_controller000";
private UmaViewerBuilder Builder => UmaViewerBuilder.Instance;
public List<Transform> charaObjs;
private void Awake()
{
if (live != null)
{
_instance = this;
Debug.Log(string.Format(CUTT_PATH, live.MusicId));
Debug.Log(live.BackGroundId);
Builder.LoadAssetPath(string.Format(CUTT_PATH, live.MusicId), this.gameObject.transform);
Builder.LoadAssetPath(string.Format(STAGE_PATH, live.BackGroundId), this.gameObject.transform);
//Make CharacterObject
var characterStandPos = this._liveTimelineControl.transform.Find("CharacterStandPos");
int counter = 0;
foreach (Transform trans in characterStandPos.GetComponentsInChildren<Transform>()) {
if (trans == characterStandPos)
{
continue;
}
var newObj = Instantiate(trans, this.transform);
newObj.gameObject.name = string.Format("CharacterObject{0}", counter);
charaObjs.Add(newObj.transform);
counter++;
};
}
}
}
@@ -1,3 +1,4 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
@@ -7,12 +8,45 @@ namespace Gallop.Live
{
public class StageController : MonoBehaviour
{
[System.Serializable]
[Serializable]
public class StageObjectUnit
{
public string UnitName; // 0x10
public GameObject[] ChildObjects; // 0x18
public bool IsEnabled { get; set; }
public int UnitNameHash { get; set; }
public int[] ChildObjectNameHashArray { get; set; }
}
[SerializeField]
public class StageObjectSelect
{
public enum Condition
{
Random = 0,
Direct = 1
}
[SerializeField] // RVA: 0xEBE0 Offset: 0xEBE0 VA: 0x7FF85CCBEBE0
private string _prefabName; // 0x10
[SerializeField] // RVA: 0xEBE0 Offset: 0xEBE0 VA: 0x7FF85CCBEBE0
private StageController.StageObjectSelect.Condition _condition; // 0x18
[SerializeField] // RVA: 0xEBE0 Offset: 0xEBE0 VA: 0x7FF85CCBEBE0
private int _selectIndex; // 0x1C
[SerializeField] // RVA: 0xEBE0 Offset: 0xEBE0 VA: 0x7FF85CCBEBE0
private GameObject[] _stageObjectArray; // 0x20
private bool _isEnabled; // 0x28
}
[Serializable]
public class MipmapBias
{
public float _stage;
}
public List<GameObject> _stageObjects;
public StageController.StageObjectUnit[] _stageObjectUnits;
public StageController.StageObjectSelect[] _stageObjectSelects;
public List<GameObject> _audienceObjects;
public Vector3 _cyalumeOffsetPosition;
public List<Material> _washLightMaterials;
@@ -36,13 +70,17 @@ namespace Gallop.Live
private void Awake()
{
InitializeStage();
if (Director.instance)
{
Director.instance._stageController = this;
}
}
public void InitializeStage()
{
foreach (GameObject stage_part in _stageObjects)
{
Instantiate(stage_part, transform.parent);
Instantiate(stage_part, transform);
}
}
}