You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

196 lines
5.5 KiB

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<string, List<string>> CharaAssetsNames = new Dictionary<string, List<string>>();
private Dictionary<string, List<string>> WeaponAssetsNames = new Dictionary<string, List<string>>();
private Dictionary<string, string> CharaWeapon = new Dictionary<string, string>();
void Start()
{
loadCommonAssets();
loadCharaCSV();
loadWeaponCSV();
loadChara("ch_001000");
//var bundlec = AssetBundle.LoadFromFile(basePath + "ch_000000_01_003");
//var ac = bundlec.LoadAsset<AnimatorOverrideController>("ch_000000_01_003");
//chara.GetComponent<Animator>().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<string>();
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<string>();
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<string>();
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<string>();
WeaponAssetsNames.TryGetValue(weaponName, out assetNames);
loadPrefab(weaponName, assetNames, ref weapon);
}
void loadPrefab(string prefabName, List<string> assetNames, ref GameObject model)
{
if (model != null)
{
Destroy(model);
}
List<AssetBundle> bundles = new List<AssetBundle>();
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<Animator>();
if (animator)
{
animator.cullingMode = AnimatorCullingMode.AlwaysAnimate;
}
foreach (AssetBundle bundle in bundles)
{
bundle.Unload(false);
}
}
void Update()
{
if (Input.GetMouseButtonDown(0))
{
//Animator animator = model.GetComponent<Animator>();
//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<Animator>().SetTrigger(Animator.StringToHash("Attack_A"));
////weapon.GetComponent<Animator>().SetTrigger(Animator.StringToHash("Attack_A"));
////animator.SetInteger(Animator.StringToHash("State"), 2);
////Animator animator2 = weapon.GetComponent<Animator>();
////animator2.SetInteger(Animator.StringToHash("State"), 2);
chara.GetComponent<Animator>().SetBool(Animator.StringToHash("Holding"), true);
weapon.GetComponent<Animator>().SetBool(Animator.StringToHash("Holding"), true);
MotionEffectManager mem = chara.GetComponent<MotionEffectManager>();
mem.isAttached = true;
mem.attachmentMotionIndex = 0;
mem.initialize();
mem.TriggerEffect("StartEffect_attack_c_003");
MotionEffectManager mem2 = weapon.GetComponent<MotionEffectManager>();
mem2.isAttached = true;
mem2.attachmentMotionIndex = 0;
mem2.initialize();
mem2.TriggerEffect("StartEffect_attack_c_002");
}
}
}