using System.Collections; using System.Collections.Generic; using UnityEngine; using MU3.Sys; using System.IO; using System; public class Main : MonoBehaviour { private GameObject model; private GameObject weapon; private List modelList = new List(); private int idx = 15; private int count = 1; private string basePath = "F:/Ongeki_Unity/ab/"; private string[] textureSuffixes = { "_body_no", "_body_sp", "_body_di", "_body_bl", "_face_di", "_head_no", "_head_sp" }; // Start is called before the first frame update void Start() { AssetBundle.LoadFromFile(basePath + "preloadshaders"); DirectoryInfo TheFolder = new DirectoryInfo(basePath); foreach (FileInfo NextFile in TheFolder.GetFiles()) { // Debug.Log(NextFile.Name); bool flag = false; if (NextFile.Name == "preloadshaders") { flag = true; } if (!NextFile.Name.StartsWith("ch_", StringComparison.OrdinalIgnoreCase)) { flag = true; } foreach (string suffix in textureSuffixes) { if (NextFile.Name.EndsWith(suffix, StringComparison.OrdinalIgnoreCase)) { flag = true; } } if (!flag) modelList.Add(NextFile.Name); } count = modelList.Count; loadModel(modelList[idx % count]); } void loadModel(string modelName) { List abs = new List(); if (modelName == "ch_001008") { abs.Add(AssetBundle.LoadFromFile(basePath + "we_001008_bl")); abs.Add(AssetBundle.LoadFromFile(basePath + "we_001008_di")); abs.Add(AssetBundle.LoadFromFile(basePath + "we_001008_no")); abs.Add(AssetBundle.LoadFromFile(basePath + "we_001008_sp")); } if (modelName == "ch_001008_201") { abs.Add(AssetBundle.LoadFromFile(basePath + "we_001008_201_bl")); abs.Add(AssetBundle.LoadFromFile(basePath + "we_001008_201_di")); } if (modelName == "ch_001008_202") { abs.Add(AssetBundle.LoadFromFile(basePath + "we_001008_202_bl")); abs.Add(AssetBundle.LoadFromFile(basePath + "we_001008_202_di")); } AssetBundle.LoadFromFile(basePath + "000000/ch_000000_101_body_no"); AssetBundle.LoadFromFile(basePath + "000000/ch_000000_101_body_sp"); foreach (string suffix in textureSuffixes) { string texturePath = basePath + modelName.Substring(0, 9) + suffix; if (File.Exists(texturePath)) { abs.Add(AssetBundle.LoadFromFile(texturePath)); } } var bundle = AssetBundle.LoadFromFile(basePath + modelName); abs.Add(bundle); foreach (var name in bundle.GetAllAssetNames()) { model = (GameObject)Instantiate(bundle.LoadAsset(name)); } foreach (AssetBundle ab in abs) { ab.Unload(false); } Renderer[] renderers = model.GetComponentsInChildren(); for (int i = 0; i < renderers.Length; i++) { for (int j = 0; j < renderers[i].materials.Length; j++) { Material material = renderers[i].materials[j]; if (material.shader.name == "MU3/ToonEdge/Skin" || material.shader.name == "MU3/ToonEdge/Face" || material.shader.name == "MU3/ToonEdge/Face Prior") { material.SetColor(Const.ShaderPropertyID_ModifiedColor, Color.white); material.SetFloat(Const.ShaderPropertyID_ModifiedBlendRate, 0.1f); material.SetFloat(Const.ShaderPropertyID_ModifiedBrightness, 2.0f); } } } loadWeapon(modelName.Substring(3, modelName.Length - 3)); } void loadWeapon(string weaponId) { List abs = new List(); var weaponPath = basePath + "we_" + weaponId; if (File.Exists(weaponPath)) { var bundle = AssetBundle.LoadFromFile(weaponPath); abs.Add(bundle); foreach (var name in bundle.GetAllAssetNames()) { weapon = (GameObject)Instantiate(bundle.LoadAsset(name)); } Animator animator = weapon.GetComponent(); if (animator) { animator.cullingMode = AnimatorCullingMode.AlwaysAnimate; } } foreach (string suffix in textureSuffixes) { string texturePath = weaponPath + suffix; if (File.Exists(texturePath)) { abs.Add(AssetBundle.LoadFromFile(texturePath)); } } foreach (AssetBundle ab in abs) { ab.Unload(false); } } void Update() { if (Input.GetMouseButtonDown(0)) { idx++; Destroy(model); Destroy(weapon); loadModel(modelList[idx % count]); } } }