|
@@ -0,0 +1,384 @@
|
|
|
+using System.Collections;
|
|
|
+using System.Collections.Generic;
|
|
|
+using UnityEngine;
|
|
|
+using Sirenix.OdinInspector;
|
|
|
+using System;
|
|
|
+using UnityEngine.UI;
|
|
|
+using System.IO;
|
|
|
+using System.Linq;
|
|
|
+using QFramework;
|
|
|
+
|
|
|
+public class MoveItemManager : MonoBehaviour
|
|
|
+{
|
|
|
+ [TabGroup("配置相关")]
|
|
|
+ [LabelText("设备名称")]
|
|
|
+ [ValidateInput("IsValid")]
|
|
|
+ public string deviceName;
|
|
|
+
|
|
|
+ private bool IsValid(string value)
|
|
|
+ {
|
|
|
+ return !string.IsNullOrEmpty(value);
|
|
|
+ }
|
|
|
+ [TabGroup("配置相关")]
|
|
|
+ [TableList]
|
|
|
+ public List<MoveItemInfo> moveItemInfos;
|
|
|
+ [TabGroup("配置相关")]
|
|
|
+ [LabelText("播完反向播放")]
|
|
|
+ public bool m_Reverse;
|
|
|
+
|
|
|
+
|
|
|
+ [TabGroup("UI相关")]
|
|
|
+ [LabelText("播放按钮")]
|
|
|
+ public Button m_PlayButton;
|
|
|
+ [TabGroup("UI相关")]
|
|
|
+ [LabelText("关闭按钮")]
|
|
|
+ public Button m_CloseButton;
|
|
|
+
|
|
|
+ private void Awake()
|
|
|
+ {
|
|
|
+ ResKit.Init();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void Start()
|
|
|
+ {
|
|
|
+ m_PlayButton?.onClick.AddListener(OnPlayButtonClick);
|
|
|
+
|
|
|
+ m_CloseButton?.onClick.AddListener(OnCloseBtnClick);
|
|
|
+
|
|
|
+ PlayMoveItemByIndex(0);
|
|
|
+
|
|
|
+ UIKit.OpenPanel<PrinciplePanel>(new PrinciplePanelData() { TitleName = deviceName});
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 正向播放
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="index"></param>
|
|
|
+ public void PlayMoveItemByIndex(int index = 0)
|
|
|
+ {
|
|
|
+ StopAllCoroutines();
|
|
|
+
|
|
|
+ Debug.Log("播放" + moveItemInfos[index].moveItem.name);
|
|
|
+
|
|
|
+ StartCoroutine(AudioHelper.LoadSpecifiedAudioFile("Config/Audios/内部结构拆解/" + deviceName, "拆下" + moveItemInfos[index].moveItem.name,
|
|
|
+ len =>
|
|
|
+ {
|
|
|
+ if (len > moveItemInfos[index].moveItem.m_Duration)
|
|
|
+ {
|
|
|
+ Debug.Log("音频长");
|
|
|
+ useAudioCtrl = true;
|
|
|
+ }else
|
|
|
+ {
|
|
|
+ Debug.Log("动画长");
|
|
|
+ useAudioCtrl = false;
|
|
|
+ }
|
|
|
+ },
|
|
|
+ () =>
|
|
|
+ {
|
|
|
+ if (useAudioCtrl)
|
|
|
+ {
|
|
|
+ Debug.Log("音频回调");
|
|
|
+ OnPlayMoveItemByIndexCallBack(index);
|
|
|
+ }
|
|
|
+
|
|
|
+ }));
|
|
|
+
|
|
|
+ StartCoroutine(MovePathByItem(moveItemInfos[index], false,
|
|
|
+ () =>
|
|
|
+ {
|
|
|
+ if (!useAudioCtrl)
|
|
|
+ {
|
|
|
+ Debug.Log("动画回调");
|
|
|
+ OnPlayMoveItemByIndexCallBack(index);
|
|
|
+ }
|
|
|
+ }));
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 正向播放完成一条回调
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="index"></param>
|
|
|
+ public void OnPlayMoveItemByIndexCallBack(int index)
|
|
|
+ {
|
|
|
+ moveItemInfos[index].moveItem.gameObject.SetActive(false);
|
|
|
+ moveItemInfos[index].finish = true;
|
|
|
+
|
|
|
+ if (index + 1 > moveItemInfos.Count - 1)
|
|
|
+ {
|
|
|
+ Debug.Log("正播播放序列完成");
|
|
|
+ if (m_Reverse)
|
|
|
+ {
|
|
|
+ PlayMoveItemByReverseIndex(moveItemInfos.Count - 1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ PlayMoveItemByIndex(index + 1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 使用音频控制结束
|
|
|
+ /// </summary>
|
|
|
+ bool useAudioCtrl;
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 反向播放
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="index"></param>
|
|
|
+ public void PlayMoveItemByReverseIndex(int index)
|
|
|
+ {
|
|
|
+ StopAllCoroutines();
|
|
|
+
|
|
|
+ Debug.Log("反向播放" + moveItemInfos[index].moveItem.name);
|
|
|
+
|
|
|
+ StartCoroutine(AudioHelper.LoadSpecifiedAudioFile("Config/Audios/内部结构拆解/" + deviceName, "安装" + moveItemInfos[index].moveItem.name,len =>
|
|
|
+ {
|
|
|
+ if (len > moveItemInfos[index].moveItem.m_Duration)
|
|
|
+ {
|
|
|
+ Debug.Log("音频长");
|
|
|
+ useAudioCtrl = true;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ Debug.Log("动画长");
|
|
|
+ useAudioCtrl = false;
|
|
|
+ }
|
|
|
+ },
|
|
|
+ () =>
|
|
|
+ {
|
|
|
+ if (useAudioCtrl)
|
|
|
+ {
|
|
|
+ Debug.Log("音频回调");
|
|
|
+ OnPlayMoveItemByReverseIndexCallBack(index);
|
|
|
+ }
|
|
|
+ }));
|
|
|
+
|
|
|
+ StartCoroutine(MovePathByItem(moveItemInfos[index], true,
|
|
|
+ () =>
|
|
|
+ {
|
|
|
+ if (!useAudioCtrl)
|
|
|
+ {
|
|
|
+ Debug.Log("动画回调");
|
|
|
+ OnPlayMoveItemByReverseIndexCallBack(index);
|
|
|
+ }
|
|
|
+ }));
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 反向播放完成一条回调
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="index"></param>
|
|
|
+ public void OnPlayMoveItemByReverseIndexCallBack(int index)
|
|
|
+ {
|
|
|
+ moveItemInfos[index].finish = false;
|
|
|
+
|
|
|
+ if (index - 1 < 0)
|
|
|
+ {
|
|
|
+ Debug.Log("反向播放序列完成");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ PlayMoveItemByReverseIndex(index - 1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ IEnumerator MovePathByItem(MoveItemInfo moveItemInfo, bool isReverse, Action finishedCallBack = null)
|
|
|
+ {
|
|
|
+ float timer = 0;
|
|
|
+ float lerp = 0;
|
|
|
+
|
|
|
+ while (timer < moveItemInfo.moveItem.m_Duration)
|
|
|
+ {
|
|
|
+ MoveItem moveItem = moveItemInfo.moveItem;
|
|
|
+
|
|
|
+ moveItem.gameObject.SetActive(true);
|
|
|
+ moveItem.OpenHighter(true);
|
|
|
+
|
|
|
+ lerp = isReverse? (1 - timer / moveItem.m_Duration) :timer / moveItem.m_Duration;
|
|
|
+
|
|
|
+ if (moveItem.m_UserGlobalDirection)
|
|
|
+ {
|
|
|
+ moveItemInfo.moveItem.transform.position = Vector3.Lerp(moveItemInfo.initPosition,
|
|
|
+ moveItemInfo.initPosition + moveItem.m_Direction, lerp);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ moveItemInfo.moveItem.transform.position = Vector3.Lerp(moveItemInfo.initPosition,
|
|
|
+ moveItemInfo.initPosition + moveItem.transform.TransformDirection(moveItem.m_Direction), lerp);
|
|
|
+ }
|
|
|
+
|
|
|
+ timer += Time.deltaTime;
|
|
|
+
|
|
|
+ yield return new WaitForEndOfFrame();
|
|
|
+ }
|
|
|
+ moveItemInfo.moveItem?.OpenHighter(false);
|
|
|
+ finishedCallBack.Invoke();
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 获取所有的组件
|
|
|
+ /// </summary>
|
|
|
+ [TabGroup("配置相关")]
|
|
|
+ [Button("获取所有的组件")]
|
|
|
+ [GUIColor("GetColor")]
|
|
|
+ private void GetAllMoveItems()
|
|
|
+ {
|
|
|
+ moveItemInfos = new List<MoveItemInfo>();
|
|
|
+
|
|
|
+ MoveItem[] moveItems = transform.GetComponentsInChildren<MoveItem>();
|
|
|
+
|
|
|
+ foreach (var item in moveItems)
|
|
|
+ {
|
|
|
+ MoveItemInfo moveItemInfo = new MoveItemInfo();
|
|
|
+
|
|
|
+ moveItemInfo.moveItem = item;
|
|
|
+
|
|
|
+ moveItemInfo.initPosition = item.transform.position;
|
|
|
+
|
|
|
+ moveItemInfos.Add(moveItemInfo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private Color GetColor()
|
|
|
+ {
|
|
|
+ if (moveItemInfos.Count == 0 || moveItemInfos == null)
|
|
|
+ {
|
|
|
+ return Color.red;
|
|
|
+ }else
|
|
|
+ {
|
|
|
+ return Color.green;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 播放按钮点击
|
|
|
+ /// </summary>
|
|
|
+ private void OnPlayButtonClick()
|
|
|
+ {
|
|
|
+ if (Time.timeScale == 0)
|
|
|
+ {
|
|
|
+ Time.timeScale = 1;
|
|
|
+
|
|
|
+ if (m_PlayButton)
|
|
|
+ {
|
|
|
+ m_PlayButton.transform.Find("Text").GetComponent<Text>().text = "暂停";
|
|
|
+ }
|
|
|
+
|
|
|
+ AudioHelper.AudioPlay();
|
|
|
+
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ Time.timeScale = 0;
|
|
|
+
|
|
|
+ if (m_PlayButton)
|
|
|
+ {
|
|
|
+ m_PlayButton.transform.Find("Text").GetComponent<Text>().text = "播放";
|
|
|
+ }
|
|
|
+
|
|
|
+ AudioHelper.AudioPause();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void OnCloseBtnClick()
|
|
|
+ {
|
|
|
+ Application.Quit();
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 导出部件数据
|
|
|
+ /// </summary>
|
|
|
+ [TabGroup("工具相关")]
|
|
|
+ [Button("导出所有部件名称到表格")]
|
|
|
+ private void ExportPartData()
|
|
|
+ {
|
|
|
+ List<MoveData> partMarkNames = new List<MoveData>();
|
|
|
+
|
|
|
+ foreach (var item in moveItemInfos)
|
|
|
+ {
|
|
|
+ MoveData partMarkName = new MoveData();
|
|
|
+ partMarkName.moveName = "拆下" + item.moveItem.name;
|
|
|
+
|
|
|
+ if (partMarkNames.Find(t => t.moveName == partMarkName.moveName) == null) partMarkNames.Add(partMarkName);
|
|
|
+ }
|
|
|
+
|
|
|
+ foreach (var item in moveItemInfos)
|
|
|
+ {
|
|
|
+ MoveData partMarkName = new MoveData();
|
|
|
+ partMarkName.moveName = "安装" + item.moveItem.name;
|
|
|
+
|
|
|
+ if (partMarkNames.Find(t => t.moveName == partMarkName.moveName) == null) partMarkNames.Add(partMarkName);
|
|
|
+ }
|
|
|
+
|
|
|
+ ExcelHelper.WriteInfoToExcel<MoveData>(Application.streamingAssetsPath + "/" + deviceName + GlobalConfig.excelSuffix, partMarkNames);
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 重命名音频名称
|
|
|
+ /// </summary>
|
|
|
+ [TabGroup("工具相关")]
|
|
|
+ [Button("重命名音频名称")]
|
|
|
+ private void ReNameAudioClipName()
|
|
|
+ {
|
|
|
+ //表格路径
|
|
|
+ string tmpExcelPath = PathHelper.CombineFilePath(PathHelper.m_ReadOnlyPath,deviceName) + GlobalConfig.excelSuffix;
|
|
|
+
|
|
|
+ //音频路径完整路径信息
|
|
|
+ string audioPath = PathHelper.CombineFilePath(PathHelper.m_ReadOnlyPath, "Config/Audios/内部结构拆解/" + deviceName);
|
|
|
+
|
|
|
+ List<MoveData> tmpMoveDatas = ExcelHelper.ReadInfoFromExcel<MoveData>(tmpExcelPath,1);
|
|
|
+
|
|
|
+ DirectoryInfo directoryInfo = new DirectoryInfo(audioPath);
|
|
|
+
|
|
|
+ FileInfo[] files = directoryInfo.GetFiles("*.mp3");
|
|
|
+
|
|
|
+ FileInfo[] sortedFiles = files.OrderBy(f => int.Parse(Path.GetFileNameWithoutExtension(f.FullName))).ToArray();
|
|
|
+
|
|
|
+ if (tmpMoveDatas.Count != sortedFiles.Length)
|
|
|
+ {
|
|
|
+ Debug.LogError("重命名失败");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ for (int i = 0; i < tmpMoveDatas.Count; i++)
|
|
|
+ {
|
|
|
+ string newPath = Path.Combine(directoryInfo.FullName, tmpMoveDatas[i].moveName) + ".mp3";
|
|
|
+
|
|
|
+ sortedFiles[i].MoveTo(newPath);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+[Serializable]
|
|
|
+public class MoveItemInfo
|
|
|
+{
|
|
|
+ [GUIColor("FinishedStateColor")]
|
|
|
+ public MoveItem moveItem;
|
|
|
+ [LabelText("父级对象")]
|
|
|
+ /// <summary>
|
|
|
+ /// 初始化位置
|
|
|
+ /// </summary>
|
|
|
+ [HideInInspector]
|
|
|
+ public Vector3 initPosition;
|
|
|
+ [LabelText("是否完成")]
|
|
|
+ public bool finish;
|
|
|
+
|
|
|
+ private Color FinishedStateColor()
|
|
|
+ {
|
|
|
+ if (finish)
|
|
|
+ {
|
|
|
+ return new Color(0.7f, 1f, 0.7f);
|
|
|
+ }
|
|
|
+
|
|
|
+ return GUI.color;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+public class MoveData
|
|
|
+{
|
|
|
+ public string moveName;
|
|
|
+}
|