GameManagers.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450
  1. using DG.Tweening;
  2. using System;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using UnityEngine;
  7. using UnityEngine.UI;
  8. public class GameManagers : MonoSingleton<GameManagers>
  9. {
  10. // Start is called before the first frame update
  11. public Animator main_anim; //主动画
  12. private AnimatorStateInfo info;
  13. public GameObject rotattionGames;//大楼主体 控制旋转
  14. public AudioSource startAudioSource;//判断初始声音是否播放完毕
  15. private float startAudioSoureceLength;
  16. public List<GameObject> changToScenesButton;//界面按钮
  17. public GameObject buttonFX;
  18. public Animator obj_MrRoom_anim;
  19. public Animator obj_Exhibition_anim;
  20. public Animator obj_Cafe_anim;
  21. public Animator obj_Basketball_anim;
  22. public GameObject ui_Main;//大屏UI——影创介绍
  23. public GameObject ui_Main_1;//大屏UI--子介绍
  24. public GameObject point_End_UiMain_Obj;//位移结束的位置
  25. public GameObject point_End_UiMain_1_Obj;
  26. public GameObject ui1;//主楼文字UI动画
  27. public List<GameObject> userSelectionPanelScButton_List;
  28. public List<GameObject> userSelectionPanelScButtonClickFX_List;
  29. public List<GameObject> userSelectionPanelScButtonEnterFX_List;
  30. public GameObject gameObj_hengfu;
  31. public string device_sn;
  32. /// <summary>
  33. /// 主动画 -15
  34. /// 会议室 -15
  35. /// 展厅 74.08
  36. /// 篮球场 172.653
  37. /// 咖啡厅 250.633
  38. /// </summary>
  39. ///
  40. private void Awake()
  41. {
  42. // AppManager.Instance.functionChangeAction += FunctionChangeHandler;
  43. }
  44. private void OnDestroy()
  45. {
  46. // AppManager.Instance.functionChangeAction -= FunctionChangeHandler;
  47. }
  48. //private void FunctionChangeHandler(List<FunctionInfo> fis)
  49. //{
  50. // for (int i = 0, count = fis.Count; i < count; i++)
  51. // {
  52. // SetFunction(fis[i]);
  53. // }
  54. //}
  55. //public void SetFunction(FunctionInfo functionInfo)
  56. //{
  57. // SetFunction((int)functionInfo.moduleID, (int)functionInfo.functionID, functionInfo.functionType, functionInfo.functionValues);
  58. //}
  59. ////手动点击
  60. //public void ClickIntoScenesOrOpenFunction(int moduleID, int functionID, FunctionType fType = FunctionType.GotoScence, List<FunctionValue> functionValues = null)
  61. //{
  62. //}
  63. //private void SetFunction(int moduleID, int functionID, FunctionType fType = FunctionType.GotoScence, List<FunctionValue> functionValues = null)
  64. //{
  65. // switch (fType)
  66. // {
  67. // case FunctionType.None:
  68. // break;
  69. // case FunctionType.GotoScence:
  70. // break;
  71. // case FunctionType.Switch:
  72. // break;
  73. // case FunctionType.RangeValue:
  74. // break;
  75. // case FunctionType.FlowValue:
  76. // SetFunction(moduleID, functionID, functionValues);
  77. // if (functionChangleAction != null)
  78. // {
  79. // functionChangleAction(moduleID, functionID, fType, functionValues);
  80. // }
  81. // break;
  82. // case FunctionType.TextEdit:
  83. // SetFunction(moduleID, functionID, functionValues);
  84. // ChangeTexts(functionValues[0].textValue);
  85. // break;
  86. // default:
  87. // break;
  88. // }
  89. //}
  90. //public static void SetFunction(int moduleID, int functionID, List<FunctionValue> functionValues)
  91. //{
  92. // List<FunctionInfo> tempList = new List<FunctionInfo>();
  93. // FunctionInfo temp = AppManager.Instance.functionInfos.FirstOrDefault(f => f.moduleID == moduleID && f.functionID == functionID);
  94. // if (temp != null)
  95. // {
  96. // temp.functionValues = GameUtil.Instance.GetFunctionValues(functionValues);
  97. // tempList.Add(temp);
  98. // if (temp.functionType == FunctionType.GotoScence)
  99. // {
  100. // uint currModuleID = temp.moduleID;
  101. // ModuleInfo moduleInfo = AppManager.Instance.moduleInfos.FirstOrDefault(m => m.moduleID == currModuleID);
  102. // if (moduleInfo != null)
  103. // {
  104. // List<FunctionInfo> gotoScenceFunctions = moduleInfo.functions.FindAll(f => f.functionType == FunctionType.GotoScence);
  105. // if (gotoScenceFunctions != null)
  106. // {
  107. // FunctionInfo fi = gotoScenceFunctions.FirstOrDefault(f => f != temp && f.functionValues[0].value == (int)FunctionState.Open);
  108. // if (fi != null)
  109. // {
  110. // fi.functionValues[0].value = (int)CCS.App.FunctionState.Close;
  111. // tempList.Add(fi);
  112. // }
  113. // }
  114. // }
  115. // List<FunctionInfo> otherFunctions = AppManager.Instance.functionInfos.FindAll(f => f.moduleID != moduleInfo.moduleID && f.moduleID > 0 && f.functionValues[0].value == (int)FunctionState.Open);
  116. // otherFunctions.ForEach(f => f.functionValues[0].value = (int)FunctionState.Close);
  117. // tempList.AddRange(otherFunctions);
  118. // }
  119. // }
  120. // NetManager.Instance.SendFunctionInfo(tempList);
  121. //}
  122. void Start()
  123. {
  124. Init();
  125. startAudioSoureceLength = startAudioSource.clip.length;
  126. device_sn = "ABD123456";
  127. // wrapWaitForStartTimer= WaitForStartTimer((startAudioSoureceLength + 6f));
  128. }
  129. /// <summary>
  130. /// 功能状态发生变化
  131. /// </summary>
  132. //public Action<int, int, FunctionType, List<FunctionValue>> functionChangleAction;
  133. //public Action<FunctionInfo, FunctionInfo> functionColliderGameObjectAction;
  134. private void Init()
  135. {
  136. changToScenesButton.ForEach(scObj =>
  137. {
  138. scObj.GetComponent<Button>().onClick.AddListener(() =>
  139. {
  140. onUserClick(scObj.name);
  141. });
  142. //scObj.GetComponent<Button>().onEnter.AddListener(() =>
  143. //{
  144. // buttonFX.GetComponent<ButtonFX>().moveToEndV3 = scObj.transform.position;
  145. // buttonFX.GetComponent<ButtonFX>().userEnterClick(true, scObj.name);
  146. //});
  147. //scObj.GetComponent<Button>().onExit.AddListener(() =>
  148. //{
  149. // buttonFX.GetComponent<ButtonFX>().userEnterClick(false, scObj.name);
  150. //});
  151. });
  152. }
  153. private void ChangeTexts(string textValue)
  154. {
  155. // ChengeTextFunction.Instance.SetInfo(textValue);
  156. }
  157. private string buttonNames;
  158. private void onUserClick(string ButtonName)
  159. {
  160. if (buttonNames == ButtonName)
  161. return;
  162. switch (ButtonName)
  163. {
  164. case "Button0":
  165. StartCoroutine(WaitForChildrenAnimEnd(currentReturnAnimName, "MainAnimation", new Vector3(0, -10f, 0), 3));
  166. break;
  167. case "Button1":
  168. StartCoroutine(WaitForChildrenAnimEnd(currentReturnAnimName, "fragmentAnimationToBasketballCourt", new Vector3(0, 172.653f, 0), 3));
  169. break;
  170. case "Button2":
  171. StartCoroutine(WaitForChildrenAnimEnd(currentReturnAnimName, "fragmentAnimationToCafe", new Vector3(0, 255.633f, 0), 3));
  172. break;
  173. case "Button3":
  174. StartCoroutine(WaitForChildrenAnimEnd(currentReturnAnimName, "fragmentAnimationToExhibitionHall", new Vector3(0, 74.08f, 0), 3));
  175. break;
  176. case "Button4":
  177. StartCoroutine(WaitForChildrenAnimEnd(currentReturnAnimName, "fragmentAnimationToConferenceRoom", new Vector3(0, -15f, 0), 3));
  178. break;
  179. }
  180. buttonFX.GetComponent<ButtonFX>().userEnterClick(false, ButtonName);
  181. buttonFX.GetComponent<ButtonFX>().userClickButtonStr(ButtonName);
  182. buttonNames = ButtonName;
  183. }
  184. public void userSelectionPanelScButton(Transform btn)
  185. {
  186. switch (btn.name)
  187. {
  188. case "Button0":
  189. StartCoroutine(WaitForChildrenAnimEnd(currentReturnAnimName, "MainAnimation", new Vector3(0, -10f, 0), 3));
  190. break;
  191. case "Button1":
  192. StartCoroutine(WaitForChildrenAnimEnd(currentReturnAnimName, "fragmentAnimationToBasketballCourt", new Vector3(0, 172.653f, 0), 3));
  193. break;
  194. case "Button2":
  195. StartCoroutine(WaitForChildrenAnimEnd(currentReturnAnimName, "fragmentAnimationToCafe", new Vector3(0, 255.633f, 0), 3));
  196. break;
  197. case "Button3":
  198. StartCoroutine(WaitForChildrenAnimEnd(currentReturnAnimName, "fragmentAnimationToExhibitionHall", new Vector3(0, 74.08f, 0), 3));
  199. break;
  200. case "Button4":
  201. StartCoroutine(WaitForChildrenAnimEnd(currentReturnAnimName, "fragmentAnimationToConferenceRoom", new Vector3(0, -15f, 0), 3));
  202. break;
  203. }
  204. }
  205. private IEnumerator wrapWaitForStartTimer;
  206. IEnumerator WaitForStartTimer(float timer)
  207. {
  208. yield return new WaitForSeconds(timer);
  209. Debug.LogError("我执行了");
  210. main_anim.SetBool("isToConferenceRoom", true);
  211. //while (true)
  212. //{
  213. // Debug.LogError("我执行了");
  214. // yield return new WaitForSeconds(1);
  215. //}
  216. }
  217. private bool isOneMove = true;
  218. private void MoveToUI()
  219. {
  220. if (isOneMove)
  221. {
  222. // ui_Main.transform.DOMove(point_End_UiMain_Obj.transform.position, 2);
  223. // ui_Main_1.transform.DOMove(point_End_UiMain_1_Obj.transform.position, 2);
  224. isOneMove = false;
  225. }
  226. }
  227. // Update is called once per frame
  228. void Update()
  229. {
  230. if (Input.GetKeyDown(KeyCode.Y))
  231. {
  232. StartCoroutine(WaitForChildrenAnimEnd(currentReturnAnimName, "MainAnimation", new Vector3(0, -10f, 0), 3));
  233. }
  234. if (Input.GetKeyDown(KeyCode.U))
  235. {
  236. StartCoroutine(WaitForChildrenAnimEnd(currentReturnAnimName, "fragmentAnimationToConferenceRoom", new Vector3(0, -15f, 0), 3));
  237. }
  238. else if (Input.GetKeyDown(KeyCode.I))
  239. {
  240. StartCoroutine(WaitForChildrenAnimEnd(currentReturnAnimName, "fragmentAnimationToExhibitionHall", new Vector3(0, 74.08f, 0), 3));
  241. }
  242. else if (Input.GetKeyDown(KeyCode.O))
  243. {
  244. StartCoroutine(WaitForChildrenAnimEnd(currentReturnAnimName, "fragmentAnimationToBasketballCourt", new Vector3(0, 172.653f, 0), 3));
  245. }
  246. else if (Input.GetKeyDown(KeyCode.P))//咖啡厅
  247. {
  248. StartCoroutine(WaitForChildrenAnimEnd(currentReturnAnimName, "fragmentAnimationToCafe", new Vector3(0, 255.633f, 0), 3));
  249. }
  250. StartPlayMainAnim();
  251. }
  252. /// <summary>
  253. /// 延迟等待子级动画播放完毕后 执行
  254. /// </summary>
  255. /// <param name="timer"></param>
  256. /// <returns></returns>
  257. public IEnumerator WaitForChildrenAnimEnd(string animName, string mianAnimName, Vector3 GotoAngel, float timer)
  258. {
  259. //ui_Main.transform.DOMove(point_End_UiMain_Obj.transform.position, 1);
  260. //ui_Main_1.transform.DOMove(point_End_UiMain_1_Obj.transform.position, 1);
  261. if (obj_MrRoom_anim.gameObject.transform.parent.gameObject.activeSelf || obj_Exhibition_anim.gameObject.activeSelf || obj_Cafe_anim.transform.parent.gameObject.activeSelf || obj_Basketball_anim.transform.parent.gameObject.activeSelf)
  262. {
  263. OBJ_Games_AnimPlay(animName);
  264. }
  265. else
  266. {
  267. timer = 0;
  268. }
  269. yield return new WaitForSeconds(timer);
  270. main_anim.Play(mianAnimName);
  271. GoToAnimAngel(GotoAngel, 2);
  272. }
  273. public void GoToAnimAngel(Vector3 v3, float timers)
  274. {
  275. rotattionGames.transform.DOLocalRotate(v3, timers).SetEase(Ease.Flash);
  276. }
  277. public string currentReturnAnimName;
  278. private void StartPlayMainAnim()
  279. {
  280. info = main_anim.GetCurrentAnimatorStateInfo(0);
  281. if (info.IsName("MainAnimation"))
  282. {
  283. currentReturnAnimName = "MainAnimation";
  284. if (info.normalizedTime > 0.1f)
  285. {
  286. ui1.SetActive(true);
  287. }
  288. if(info.normalizedTime > 0.2f)
  289. {
  290. gameObj_hengfu.SetActive(true);
  291. }
  292. }
  293. else
  294. {
  295. ui1.GetComponent<Animator>().Play("ReturnKUANG13Animation");
  296. main_anim.SetBool("isToConferenceRoom", false);
  297. }
  298. if (info.IsName("fragmentAnimationToConferenceRoom"))
  299. {
  300. MoveToUI();
  301. currentReturnAnimName = "ReturnExhibitionHallAnimation";
  302. if (info.normalizedTime > 0.8f)//将要结束
  303. {
  304. OBJ_Games_AnimPlay(currentReturnAnimName);
  305. }
  306. if (info.normalizedTime > 0.94f)//会议室动画播放完毕后
  307. {
  308. GoToAnimAngel(new Vector3(0, 74.08f, 0), 2f);
  309. }
  310. }
  311. if (info.IsName("fragmentAnimationToExhibitionHall"))//展厅动画播放完毕后
  312. {
  313. MoveToUI();
  314. currentReturnAnimName = "ReturnMrRoomFXAnimation";
  315. if (info.normalizedTime > 0.8f)//将要结束
  316. {
  317. OBJ_Games_AnimPlay(currentReturnAnimName);
  318. }
  319. if (info.normalizedTime > 0.94f)
  320. {
  321. GoToAnimAngel(new Vector3(0, 172.653f, 0), 2f);
  322. }
  323. }
  324. if (info.IsName("fragmentAnimationToBasketballCourt"))
  325. {
  326. MoveToUI();
  327. currentReturnAnimName = "ReturnBasketballCourtAnimation";
  328. if (info.normalizedTime > 0.8f)//将要结束
  329. {
  330. OBJ_Games_AnimPlay(currentReturnAnimName);
  331. }
  332. if (info.normalizedTime > 0.94f)
  333. {
  334. GoToAnimAngel(new Vector3(0, 255.633f, 0), 2f);
  335. }
  336. }
  337. if (info.IsName("fragmentAnimationToCafe"))
  338. {
  339. MoveToUI();
  340. currentReturnAnimName = "ReturnCafeAnimation";
  341. if (info.normalizedTime > 0.9f)//将要结束
  342. {
  343. OBJ_Games_AnimPlay(currentReturnAnimName);
  344. }
  345. if (info.normalizedTime > 0.99f)
  346. {
  347. GoToAnimAngel(new Vector3(0, -9f, 0), 2f);
  348. }
  349. }
  350. }
  351. private void OBJ_Games_AnimPlay(string str)
  352. {
  353. switch (str)
  354. {
  355. case "ReturnExhibitionHallAnimation":
  356. obj_Exhibition_anim.Play("ReturnExhibitionHallAnimation");
  357. break;
  358. case "ReturnMrRoomFXAnimation":
  359. obj_MrRoom_anim.Play("ReturnMrRoomFXAnimation");
  360. break;
  361. case "ReturnBasketballCourtAnimation":
  362. obj_Basketball_anim.Play("ReturnBasketballCourtAnimation");
  363. break;
  364. case "ReturnCafeAnimation":
  365. obj_Cafe_anim.Play("ReturnCafeAnimation");
  366. break;
  367. }
  368. }
  369. }