diff --git a/Assets/Scenes/CameraOrbit.cs b/Assets/Scenes/CameraOrbit.cs new file mode 100644 index 0000000..65c5f6f --- /dev/null +++ b/Assets/Scenes/CameraOrbit.cs @@ -0,0 +1,66 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class CameraOrbit : MonoBehaviour +{ + public float distance; // 摄像头与指定点的距离 + public float xSpeed = 120.0f; // 水平旋转速度 + public float ySpeed = 120.0f; // 垂直旋转速度 + public bool canScroll = true; + + private float x = 0.0f; + private float y = 0.0f; + private float z = 1.0f; + + void Start() + { + Vector3 angles = transform.eulerAngles; + x = angles.y; + y = angles.x; + distance = Vector3.Distance(transform.position, new Vector3(0, z, 0)); + } + + void LateUpdate() + { + if (Input.GetMouseButton(1)) + { + x += Input.GetAxis("Mouse X") * xSpeed * distance * 0.02f; + y -= Input.GetAxis("Mouse Y") * ySpeed * 0.02f; + + Quaternion rotation = Quaternion.Euler(y, x, 0); + Vector3 position = rotation * new Vector3(0.0f, 0.0f, -distance) + new Vector3(0, z, 0); + + transform.rotation = rotation; + transform.position = position; + } + + else if (Input.GetAxis("Mouse ScrollWheel") != 0 && canScroll) + { + if (Input.GetAxis("Mouse ScrollWheel") < 0) + { + if (Camera.main.fieldOfView <= 100) + Camera.main.fieldOfView += 2; + if (Camera.main.orthographicSize <= 20) + Camera.main.orthographicSize += 0.5F; + } + if (Input.GetAxis("Mouse ScrollWheel") > 0) + { + if (Camera.main.fieldOfView > 2) + Camera.main.fieldOfView -= 2; + if (Camera.main.orthographicSize >= 1) + Camera.main.orthographicSize -= 0.5F; + } + } + + else if (Input.GetMouseButton(0)) + { + var d = Input.GetAxis("Mouse Y") * ySpeed * 0.0005f; + z -= d; + Vector3 position = transform.position; + position.y -= d; + transform.position = position; + + } + } + } diff --git a/Assets/Scenes/CameraOrbit.cs.meta b/Assets/Scenes/CameraOrbit.cs.meta new file mode 100644 index 0000000..b9d6110 --- /dev/null +++ b/Assets/Scenes/CameraOrbit.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 0cb73ef3772e98f47a94b0f5bbc321f2 +timeCreated: 1712770517 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scenes/Main.cs b/Assets/Scenes/Main.cs index 6fab169..0a34628 100644 --- a/Assets/Scenes/Main.cs +++ b/Assets/Scenes/Main.cs @@ -3,31 +3,34 @@ 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; private string basePath = "F:/Ongeki_Unity/ab/"; - private Dictionary> CharaAssetsNames = new Dictionary>(); - private Dictionary> WeaponAssetsNames = new Dictionary>(); - private Dictionary CharaWeapon = new Dictionary(); + public Dictionary> charaAssetsNames = new Dictionary>(); + public Dictionary> weaponAssetsNames = new Dictionary>(); + public Dictionary> attachmentAssetsNames = new Dictionary>(); + public Dictionary charaWeapon = new Dictionary(); + public Dictionary attachmentPosition = new Dictionary(); + #endregion void Start() { loadCommonAssets(); loadCharaCSV(); loadWeaponCSV(); + loadAttachmentCSV(); - loadChara("ch_001000"); - - - - - - - + + GameObject.Find("charaDropdown").GetComponent().value = 14; //var bundlec = AssetBundle.LoadFromFile(basePath + "ch_000000_01_003"); @@ -35,12 +38,11 @@ public class Main : MonoBehaviour //chara.GetComponent().runtimeAnimatorController = ac; - - } + #region Init private void loadCommonAssets() { DirectoryInfo TheFolder = new DirectoryInfo(Application.streamingAssetsPath + "/common"); @@ -57,70 +59,209 @@ public class Main : MonoBehaviour private void loadCharaCSV() { + var options = new List(); var lines = CSVReader.ReadCSV(Application.streamingAssetsPath + "/data/chara.csv"); foreach (var line in lines) { - CharaWeapon[line[0]] = line[1] != string.Empty ? line[1] : null; + charaWeapon[line[0]] = line[2] != string.Empty ? line[2] : null; var assets = new List(); - foreach (var asset in line.GetRange(2, 7)) + foreach (var asset in line.GetRange(3, 7)) { - if (asset != string.Empty) - { - assets.Add(asset); - } + if (asset != string.Empty) assets.Add(asset); } - CharaAssetsNames[line[0]] = assets; + charaAssetsNames[line[0]] = assets; + options.Add(new Dropdown.OptionData(line[1])); } + GameObject.Find("charaDropdown").GetComponent().AddOptions(options); } - private void loadWeaponCSV() + private void loadWeaponCSV() { + var options = new List(); 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)) + foreach (var asset in line.GetRange(2, 4)) { - if (asset != string.Empty) - { - assets.Add(asset); - } + if (asset != string.Empty) assets.Add(asset); } - WeaponAssetsNames[line[0]] = assets; + weaponAssetsNames[line[0]] = assets; + options.Add(new Dropdown.OptionData(line[1])); } + GameObject.Find("weaponLDropdown").GetComponent().AddOptions(options); + GameObject.Find("weaponRDropdown").GetComponent().AddOptions(options); } + private void loadAttachmentCSV() + { + var options = new List(); + var lines = CSVReader.ReadCSV(Application.streamingAssetsPath + "/data/attachment.csv"); + foreach (var line in lines) + { + var assets = new List(); + 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().AddOptions(options); + } + #endregion - - void loadChara(string charaName) + #region Chara + public void removeChara() + { + if (attachment != null) Destroy(attachment); + } + public void loadChara(string charaName) { + removeChara(); + removeWeapon(); + removeAttachment(); var assetNames = new List(); - CharaAssetsNames.TryGetValue(charaName, out assetNames); + charaAssetsNames.TryGetValue(charaName, out assetNames); loadPrefab(charaName, assetNames, ref chara); - if (CharaWeapon[charaName] != null) - { - loadWeapon(CharaWeapon[charaName]); - } + if (charaWeapon[charaName] != null) loadWeapon(charaWeapon[charaName]); } + #endregion + - void loadWeapon(string weaponName) + # 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(); - WeaponAssetsNames.TryGetValue(weaponName, out assetNames); + weaponAssetsNames.TryGetValue(weaponName, out assetNames); loadPrefab(weaponName, assetNames, ref weapon); } + public void loadWeaponL(string weaponName) + { + if (weapon != null) Destroy(weapon); + var assetNames = new List(); + 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(), "L"); + childL.SetParent(parent, true); + } + if (childR != null) + { + addWeaponButtonListener(childR.gameObject.AddComponent(), "L"); + childR.SetParent(parent, true); + } + } + } - void loadPrefab(string prefabName, List assetNames, ref GameObject model) + public void loadWeaponR(string weaponName) + { + if (weapon != null) Destroy(weapon); + var assetNames = new List(); + 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(), "R"); + childL.SetParent(parent, true); + } + if (childR != null) + { + addWeaponButtonListener(childR.gameObject.AddComponent(), "R"); + childR.SetParent(parent, true); + } + } + } + #endregion + + + + #region Attachment + public void removeAttachment() + { + if (attachment != null) Destroy(attachment); + } + public void loadAttachment(string attachmentName) { - if (model != null) + var assetNames = new List(); + 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 { - Destroy(model); + 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 + + + + #region Internal + void addWeaponButtonListener(RemoveAnimationTransfrom rat, string LR) + { + GameObject.Find(string.Format("weapon{0}x", LR)).GetComponent