GameManagers.cs 15 KB

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