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.

369 lines
13 KiB

using System.Collections.Generic;
using UnityEngine;
using System.IO;
using MU3;
using System;
using UnityEngine.UI;
public class Main : MonoBehaviour
{
#region var
private GameObject chara;
private GameObject weapon;
private GameObject weaponL;
private GameObject weaponR;
private GameObject attachment;
5 months ago
private RuntimeAnimatorController originAnimator;
private string basePath = "F:/Ongeki_Unity/ab/";
public Dictionary<string, List<string>> charaAssetsNames = new Dictionary<string, List<string>>();
public Dictionary<string, List<string>> weaponAssetsNames = new Dictionary<string, List<string>>();
public Dictionary<string, List<string>> attachmentAssetsNames = new Dictionary<string, List<string>>();
public Dictionary<string, string> charaWeapon = new Dictionary<string, string>();
public Dictionary<string, string> attachmentPosition = new Dictionary<string, string>();
#endregion
void Start()
{
loadCommonAssets();
loadCharaCSV();
loadWeaponCSV();
loadAttachmentCSV();
GameObject.Find("charaDropdown").GetComponent<Dropdown>().value = 14;
}
#region Init
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 options = new List<Dropdown.OptionData>();
var lines = CSVReader.ReadCSV(Application.streamingAssetsPath + "/data/chara.csv");
foreach (var line in lines)
{
charaWeapon[line[0]] = line[2] != string.Empty ? line[2] : null;
var assets = new List<string>();
foreach (var asset in line.GetRange(3, 7))
{
if (asset != string.Empty) assets.Add(asset);
}
charaAssetsNames[line[0]] = assets;
options.Add(new Dropdown.OptionData(line[1]));
}
GameObject.Find("charaDropdown").GetComponent<Dropdown>().AddOptions(options);
}
private void loadWeaponCSV()
{
var options = new List<Dropdown.OptionData>();
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(2, 4))
{
if (asset != string.Empty) assets.Add(asset);
}
weaponAssetsNames[line[0]] = assets;
options.Add(new Dropdown.OptionData(line[1]));
}
GameObject.Find("weaponLDropdown").GetComponent<Dropdown>().AddOptions(options);
GameObject.Find("weaponRDropdown").GetComponent<Dropdown>().AddOptions(options);
}
private void loadAttachmentCSV()
{
var options = new List<Dropdown.OptionData>();
var lines = CSVReader.ReadCSV(Application.streamingAssetsPath + "/data/attachment.csv");
foreach (var line in lines)
{
var assets = new List<string>();
foreach (var asset in line.GetRange(3, 2))
{
if (asset != string.Empty) assets.Add(asset);
}
attachmentAssetsNames[line[0]] = assets;
attachmentPosition[line[0]] = line[2];
options.Add(new Dropdown.OptionData(line[1]));
}
GameObject.Find("attachmentDropdown").GetComponent<Dropdown>().AddOptions(options);
}
#endregion
#region Chara
public void removeChara()
{
if (attachment != null) Destroy(attachment);
}
public void loadChara(string charaName)
{
removeChara();
removeWeapon();
removeAttachment();
var assetNames = new List<string>();
charaAssetsNames.TryGetValue(charaName, out assetNames);
loadPrefab(charaName, assetNames, ref chara);
if (charaWeapon[charaName] != null) loadWeapon(charaWeapon[charaName]);
}
#endregion
# region Weapon
public void removeWeapon()
{
if (weapon != null) Destroy(weapon);
if (weaponL != null) Destroy(weaponL);
if (weaponR != null) Destroy(weaponR);
}
public void loadWeapon(string weaponName)
{
removeWeapon();
var assetNames = new List<string>();
weaponAssetsNames.TryGetValue(weaponName, out assetNames);
loadPrefab(weaponName, assetNames, ref weapon);
}
public void loadWeaponL(string weaponName)
{
if (weapon != null) Destroy(weapon);
var assetNames = new List<string>();
weaponAssetsNames.TryGetValue(weaponName, out assetNames);
loadPrefab(weaponName, assetNames, ref weaponL);
Transform parent = Utils.findChildRecursive(chara.transform, "pos_l_weapon");
if (parent != null)
{
for (int i = parent.childCount -1; i >=0 ; i--)
Destroy(parent.GetChild(i).gameObject);
Transform childL = Utils.findChildRecursive(weaponL.transform, "l_weapon");
Transform childR = Utils.findChildRecursive(weaponL.transform, "r_weapon");
if (childL != null)
{
addWeaponButtonListener(childL.gameObject.AddComponent<RemoveAnimationTransfrom>(), "L");
childL.SetParent(parent, true);
}
if (childR != null)
{
addWeaponButtonListener(childR.gameObject.AddComponent<RemoveAnimationTransfrom>(), "L");
childR.SetParent(parent, true);
}
}
}
public void loadWeaponR(string weaponName)
{
if (weapon != null) Destroy(weapon);
var assetNames = new List<string>();
weaponAssetsNames.TryGetValue(weaponName, out assetNames);
loadPrefab(weaponName, assetNames, ref weaponR);
Transform parent = Utils.findChildRecursive(chara.transform, "pos_r_weapon");
if (parent != null)
{
for (int i = parent.childCount -1; i >=0 ; i--)
Destroy(parent.GetChild(i).gameObject);
Transform childL = Utils.findChildRecursive(weaponR.transform, "l_weapon");
Transform childR = Utils.findChildRecursive(weaponR.transform, "r_weapon");
if (childL != null)
{
addWeaponButtonListener(childL.gameObject.AddComponent<RemoveAnimationTransfrom>(), "R");
childL.SetParent(parent, true);
}
if (childR != null)
{
addWeaponButtonListener(childR.gameObject.AddComponent<RemoveAnimationTransfrom>(), "R");
childR.SetParent(parent, true);
}
}
}
#endregion
#region Attachment
public void removeAttachment()
{
if (attachment != null) Destroy(attachment);
}
public void loadAttachment(string attachmentName)
{
var assetNames = new List<string>();
attachmentAssetsNames.TryGetValue(attachmentName, out assetNames);
if (attachmentPosition[attachmentName] == "右手")
{
loadPrefab(attachmentName, assetNames, ref weaponR);
Transform parent = Utils.findChildRecursive(chara.transform, "pos_r_weapon");
if (parent != null)
{
for (int i = parent.childCount -1; i >=0 ; i--)
Destroy(parent.GetChild(i).gameObject);
weaponR.transform.SetParent(parent, false);
}
}
else
{
removeAttachment();
loadPrefab(attachmentName, assetNames, ref attachment);
Transform parent = Utils.findChildRecursive(chara.transform, "spine_a");
if (parent != null) attachment.transform.SetParent(parent, false);
attachment.transform.rotation = attachment.transform.localRotation;
if (attachmentName == "at_020102")
{
attachment.transform.localPosition = new Vector3(0, 0.1f, 0);
attachment.transform.localRotation = Quaternion.Euler(0, -7f, -30);
}
}
}
#endregion
5 months ago
#region Animator
public void loadAnimator(int i)
{
if (i == 0)
{
chara.GetComponent<Animator>().runtimeAnimatorController = originAnimator;
}
else
{
string[] names = {
"",
"ch_000000_01_002",
"ch_000000_01_003",
"ch_000000_02_002",
"ch_000000_02_003",
"ch_000000_03_002",
"ch_000000_03_003",
"ch_000000_04_002",
"ch_000000_04_003",
"ch_000000_05_002",
"ch_000000_05_003",
"ch_000000_06_002",
"ch_000000_06_003",
};
var animatorName = names[i];
var bundle = AssetBundle.LoadFromFile(basePath + animatorName);
var aoc = bundle.LoadAsset<AnimatorOverrideController>(animatorName);
if (originAnimator == null)
originAnimator = chara.GetComponent<Animator>().runtimeAnimatorController;
chara.GetComponent<Animator>().runtimeAnimatorController = aoc;
bundle.Unload(false);
}
}
#endregion
#region Internal
void addWeaponButtonListener(RemoveAnimationTransfrom rat, string LR)
{
GameObject.Find(string.Format("weapon{0}x", LR)).GetComponent<Button>().onClick.RemoveAllListeners();
GameObject.Find(string.Format("weapon{0}x", LR)).GetComponent<Button>().onClick.AddListener(rat.xReverse);
GameObject.Find(string.Format("weapon{0}y", LR)).GetComponent<Button>().onClick.RemoveAllListeners();
GameObject.Find(string.Format("weapon{0}y", LR)).GetComponent<Button>().onClick.AddListener(rat.yReverse);
GameObject.Find(string.Format("weapon{0}z", LR)).GetComponent<Button>().onClick.RemoveAllListeners();
GameObject.Find(string.Format("weapon{0}z", LR)).GetComponent<Button>().onClick.AddListener(rat.zReverse);
GameObject.Find(string.Format("weapon{0}p", LR)).GetComponent<Button>().onClick.RemoveAllListeners();
GameObject.Find(string.Format("weapon{0}p", LR)).GetComponent<Button>().onClick.AddListener(rat.zPlus);
GameObject.Find(string.Format("weapon{0}m", LR)).GetComponent<Button>().onClick.RemoveAllListeners();
GameObject.Find(string.Format("weapon{0}m", LR)).GetComponent<Button>().onClick.AddListener(rat.zMinus);
}
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 (var bundle in bundles) bundle.Unload(false);
}
#endregion
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);
///
//chara.GetComponent<Animator>().SetTrigger(Animator.StringToHash("Attack_A"));
//weaponL.GetComponent<Animator>().SetTrigger(Animator.StringToHash("Attack_A"));
//weaponR.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");
}
}
}