using System.Collections.Generic; using UnityEngine; using System.IO; using MU3; using System; public class Main : MonoBehaviour { private GameObject chara; private GameObject weapon; private string basePath = "F:/Ongeki_Unity/ab/"; private Dictionary> CharaAssetsNames = new Dictionary>(); private Dictionary> WeaponAssetsNames = new Dictionary>(); private Dictionary CharaWeapon = new Dictionary(); void Start() { loadCommonAssets(); loadCharaCSV(); loadWeaponCSV(); loadChara("ch_001000"); //var bundlec = AssetBundle.LoadFromFile(basePath + "ch_000000_01_003"); //var ac = bundlec.LoadAsset("ch_000000_01_003"); //chara.GetComponent().runtimeAnimatorController = ac; } private void loadCommonAssets() { DirectoryInfo TheFolder = new DirectoryInfo(Application.streamingAssetsPath + "/common"); foreach (FileInfo NextFile in TheFolder.GetFiles()) { if (!NextFile.FullName.EndsWith(".meta")) { AssetBundle.LoadFromFile(NextFile.FullName); // Debug.Log(NextFile.FullName); } } } private void loadCharaCSV() { var lines = CSVReader.ReadCSV(Application.streamingAssetsPath + "/data/chara.csv"); foreach (var line in lines) { CharaWeapon[line[0]] = line[1] != string.Empty ? line[1] : null; var assets = new List(); foreach (var asset in line.GetRange(2, 7)) { if (asset != string.Empty) { assets.Add(asset); } } CharaAssetsNames[line[0]] = assets; } } private void loadWeaponCSV() { var lines = CSVReader.ReadCSV(Application.streamingAssetsPath + "/data/weapon.csv"); foreach (var line in lines) { var assets = new List(); foreach (var asset in line.GetRange(1, 4)) { if (asset != string.Empty) { assets.Add(asset); } } WeaponAssetsNames[line[0]] = assets; } } void loadChara(string charaName) { var assetNames = new List(); CharaAssetsNames.TryGetValue(charaName, out assetNames); loadPrefab(charaName, assetNames, ref chara); if (CharaWeapon[charaName] != null) { loadWeapon(CharaWeapon[charaName]); } } void loadWeapon(string weaponName) { var assetNames = new List(); WeaponAssetsNames.TryGetValue(weaponName, out assetNames); loadPrefab(weaponName, assetNames, ref weapon); } void loadPrefab(string prefabName, List assetNames, ref GameObject model) { if (model != null) { Destroy(model); } List bundles = new List(); foreach (var assetName in assetNames) { var assetPath = basePath + assetName; if (File.Exists(assetPath)) { var bundle = AssetBundle.LoadFromFile(assetPath); bundles.Add(bundle); } } var prefabAssetPath = basePath + prefabName; if (File.Exists(prefabAssetPath)) { var bundle = AssetBundle.LoadFromFile(prefabAssetPath); bundles.Add(bundle); model = (GameObject)Instantiate(bundle.LoadAsset(prefabName)); } Animator animator = model.GetComponent(); if (animator) { animator.cullingMode = AnimatorCullingMode.AlwaysAnimate; } foreach (AssetBundle bundle in bundles) { bundle.Unload(false); } } void Update() { if (Input.GetMouseButtonDown(0)) { //Animator animator = model.GetComponent(); //RuntimeAnimatorController rac = animator.runtimeAnimatorController; //foreach (AnimationClip a in rac.animationClips) //{ // //Debug.Log(a); //} ////animator.Play(Animator.StringToHash("Extra_Attack_C_001_ref"), 0); ////model.GetComponent().SetTrigger(Animator.StringToHash("Attack_A")); ////weapon.GetComponent().SetTrigger(Animator.StringToHash("Attack_A")); ////animator.SetInteger(Animator.StringToHash("State"), 2); ////Animator animator2 = weapon.GetComponent(); ////animator2.SetInteger(Animator.StringToHash("State"), 2); chara.GetComponent().SetBool(Animator.StringToHash("Holding"), true); weapon.GetComponent().SetBool(Animator.StringToHash("Holding"), true); MotionEffectManager mem = chara.GetComponent(); mem.isAttached = true; mem.attachmentMotionIndex = 0; mem.initialize(); mem.TriggerEffect("StartEffect_attack_c_003"); MotionEffectManager mem2 = weapon.GetComponent(); mem2.isAttached = true; mem2.attachmentMotionIndex = 0; mem2.initialize(); mem2.TriggerEffect("StartEffect_attack_c_002"); } } }