123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449 |
- using DG.Tweening;
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Linq;
- using UnityEngine;
- public class GameManagers : MonoSingleton<GameManagers>
- {
- // Start is called before the first frame update
- public Animator main_anim; //主动画
- private AnimatorStateInfo info;
- public GameObject rotattionGames;//大楼主体 控制旋转
- public AudioSource startAudioSource;//判断初始声音是否播放完毕
- private float startAudioSoureceLength;
- public List<GameObject> changToScenesButton;//界面按钮
- public GameObject buttonFX;
- public Animator obj_MrRoom_anim;
- public Animator obj_Exhibition_anim;
- public Animator obj_Cafe_anim;
- public Animator obj_Basketball_anim;
- public GameObject ui_Main;//大屏UI——影创介绍
- public GameObject ui_Main_1;//大屏UI--子介绍
- public GameObject point_End_UiMain_Obj;//位移结束的位置
- public GameObject point_End_UiMain_1_Obj;
- public GameObject ui1;//主楼文字UI动画
- public List<GameObject> userSelectionPanelScButton_List;
- public List<GameObject> userSelectionPanelScButtonClickFX_List;
- public List<GameObject> userSelectionPanelScButtonEnterFX_List;
- public GameObject gameObj_hengfu;
- public string device_sn;
- /// <summary>
- /// 主动画 -15
- /// 会议室 -15
- /// 展厅 74.08
- /// 篮球场 172.653
- /// 咖啡厅 250.633
- /// </summary>
- ///
- private void Awake()
- {
- // AppManager.Instance.functionChangeAction += FunctionChangeHandler;
- }
- private void OnDestroy()
- {
- // AppManager.Instance.functionChangeAction -= FunctionChangeHandler;
- }
- //private void FunctionChangeHandler(List<FunctionInfo> fis)
- //{
- // for (int i = 0, count = fis.Count; i < count; i++)
- // {
- // SetFunction(fis[i]);
- // }
- //}
- //public void SetFunction(FunctionInfo functionInfo)
- //{
- // SetFunction((int)functionInfo.moduleID, (int)functionInfo.functionID, functionInfo.functionType, functionInfo.functionValues);
- //}
- ////手动点击
- //public void ClickIntoScenesOrOpenFunction(int moduleID, int functionID, FunctionType fType = FunctionType.GotoScence, List<FunctionValue> functionValues = null)
- //{
- //}
- //private void SetFunction(int moduleID, int functionID, FunctionType fType = FunctionType.GotoScence, List<FunctionValue> functionValues = null)
- //{
- // switch (fType)
- // {
- // case FunctionType.None:
- // break;
- // case FunctionType.GotoScence:
- // break;
- // case FunctionType.Switch:
- // break;
- // case FunctionType.RangeValue:
- // break;
- // case FunctionType.FlowValue:
- // SetFunction(moduleID, functionID, functionValues);
- // if (functionChangleAction != null)
- // {
- // functionChangleAction(moduleID, functionID, fType, functionValues);
- // }
- // break;
- // case FunctionType.TextEdit:
- // SetFunction(moduleID, functionID, functionValues);
- // ChangeTexts(functionValues[0].textValue);
- // break;
- // default:
- // break;
- // }
- //}
- //public static void SetFunction(int moduleID, int functionID, List<FunctionValue> functionValues)
- //{
- // List<FunctionInfo> tempList = new List<FunctionInfo>();
- // FunctionInfo temp = AppManager.Instance.functionInfos.FirstOrDefault(f => f.moduleID == moduleID && f.functionID == functionID);
- // if (temp != null)
- // {
- // temp.functionValues = GameUtil.Instance.GetFunctionValues(functionValues);
- // tempList.Add(temp);
- // if (temp.functionType == FunctionType.GotoScence)
- // {
- // uint currModuleID = temp.moduleID;
- // ModuleInfo moduleInfo = AppManager.Instance.moduleInfos.FirstOrDefault(m => m.moduleID == currModuleID);
- // if (moduleInfo != null)
- // {
- // List<FunctionInfo> gotoScenceFunctions = moduleInfo.functions.FindAll(f => f.functionType == FunctionType.GotoScence);
- // if (gotoScenceFunctions != null)
- // {
- // FunctionInfo fi = gotoScenceFunctions.FirstOrDefault(f => f != temp && f.functionValues[0].value == (int)FunctionState.Open);
- // if (fi != null)
- // {
- // fi.functionValues[0].value = (int)CCS.App.FunctionState.Close;
- // tempList.Add(fi);
- // }
- // }
- // }
- // List<FunctionInfo> otherFunctions = AppManager.Instance.functionInfos.FindAll(f => f.moduleID != moduleInfo.moduleID && f.moduleID > 0 && f.functionValues[0].value == (int)FunctionState.Open);
- // otherFunctions.ForEach(f => f.functionValues[0].value = (int)FunctionState.Close);
- // tempList.AddRange(otherFunctions);
- // }
- // }
- // NetManager.Instance.SendFunctionInfo(tempList);
- //}
- void Start()
- {
- Init();
- startAudioSoureceLength = startAudioSource.clip.length;
- device_sn = DeviceSN.Instance.SendSerialBy16();
- // wrapWaitForStartTimer= WaitForStartTimer((startAudioSoureceLength + 6f));
- }
- /// <summary>
- /// 功能状态发生变化
- /// </summary>
- //public Action<int, int, FunctionType, List<FunctionValue>> functionChangleAction;
- //public Action<FunctionInfo, FunctionInfo> functionColliderGameObjectAction;
- private void Init()
- {
- changToScenesButton.ForEach(scObj =>
- {
- scObj.GetComponent<SCButton>().onClick.AddListener(() =>
- {
- onUserClick(scObj.name);
- });
- scObj.GetComponent<SCButton>().onEnter.AddListener(() =>
- {
- buttonFX.GetComponent<ButtonFX>().moveToEndV3 = scObj.transform.position;
- buttonFX.GetComponent<ButtonFX>().userEnterClick(true, scObj.name);
- });
- scObj.GetComponent<SCButton>().onExit.AddListener(() =>
- {
- buttonFX.GetComponent<ButtonFX>().userEnterClick(false, scObj.name);
- });
- });
- }
- private void ChangeTexts(string textValue)
- {
- // ChengeTextFunction.Instance.SetInfo(textValue);
- }
- private string buttonNames;
- private void onUserClick(string ButtonName)
- {
- if (buttonNames == ButtonName)
- return;
- switch (ButtonName)
- {
- case "Button0":
- StartCoroutine(WaitForChildrenAnimEnd(currentReturnAnimName, "MainAnimation", new Vector3(0, -10f, 0), 3));
- break;
- case "Button1":
- StartCoroutine(WaitForChildrenAnimEnd(currentReturnAnimName, "fragmentAnimationToBasketballCourt", new Vector3(0, 172.653f, 0), 3));
- break;
- case "Button2":
- StartCoroutine(WaitForChildrenAnimEnd(currentReturnAnimName, "fragmentAnimationToCafe", new Vector3(0, 255.633f, 0), 3));
- break;
- case "Button3":
- StartCoroutine(WaitForChildrenAnimEnd(currentReturnAnimName, "fragmentAnimationToExhibitionHall", new Vector3(0, 74.08f, 0), 3));
- break;
- case "Button4":
- StartCoroutine(WaitForChildrenAnimEnd(currentReturnAnimName, "fragmentAnimationToConferenceRoom", new Vector3(0, -15f, 0), 3));
- break;
- }
- buttonFX.GetComponent<ButtonFX>().userEnterClick(false, ButtonName);
- buttonFX.GetComponent<ButtonFX>().userClickButtonStr(ButtonName);
- buttonNames = ButtonName;
- }
- public void userSelectionPanelScButton(Transform btn)
- {
- switch (btn.name)
- {
- case "Button0":
- StartCoroutine(WaitForChildrenAnimEnd(currentReturnAnimName, "MainAnimation", new Vector3(0, -10f, 0), 3));
- break;
- case "Button1":
- StartCoroutine(WaitForChildrenAnimEnd(currentReturnAnimName, "fragmentAnimationToBasketballCourt", new Vector3(0, 172.653f, 0), 3));
- break;
- case "Button2":
- StartCoroutine(WaitForChildrenAnimEnd(currentReturnAnimName, "fragmentAnimationToCafe", new Vector3(0, 255.633f, 0), 3));
- break;
- case "Button3":
- StartCoroutine(WaitForChildrenAnimEnd(currentReturnAnimName, "fragmentAnimationToExhibitionHall", new Vector3(0, 74.08f, 0), 3));
- break;
- case "Button4":
- StartCoroutine(WaitForChildrenAnimEnd(currentReturnAnimName, "fragmentAnimationToConferenceRoom", new Vector3(0, -15f, 0), 3));
- break;
- }
- }
- private IEnumerator wrapWaitForStartTimer;
- IEnumerator WaitForStartTimer(float timer)
- {
- yield return new WaitForSeconds(timer);
- Debug.LogError("我执行了");
- main_anim.SetBool("isToConferenceRoom", true);
- //while (true)
- //{
- // Debug.LogError("我执行了");
- // yield return new WaitForSeconds(1);
- //}
- }
- private bool isOneMove = true;
- private void MoveToUI()
- {
- if (isOneMove)
- {
- // ui_Main.transform.DOMove(point_End_UiMain_Obj.transform.position, 2);
- // ui_Main_1.transform.DOMove(point_End_UiMain_1_Obj.transform.position, 2);
- isOneMove = false;
- }
- }
- // Update is called once per frame
- void Update()
- {
- if (Input.GetKeyDown(KeyCode.Y))
- {
- StartCoroutine(WaitForChildrenAnimEnd(currentReturnAnimName, "MainAnimation", new Vector3(0, -10f, 0), 3));
- }
- if (Input.GetKeyDown(KeyCode.U))
- {
- StartCoroutine(WaitForChildrenAnimEnd(currentReturnAnimName, "fragmentAnimationToConferenceRoom", new Vector3(0, -15f, 0), 3));
- }
- else if (Input.GetKeyDown(KeyCode.I))
- {
- StartCoroutine(WaitForChildrenAnimEnd(currentReturnAnimName, "fragmentAnimationToExhibitionHall", new Vector3(0, 74.08f, 0), 3));
- }
- else if (Input.GetKeyDown(KeyCode.O))
- {
- StartCoroutine(WaitForChildrenAnimEnd(currentReturnAnimName, "fragmentAnimationToBasketballCourt", new Vector3(0, 172.653f, 0), 3));
- }
- else if (Input.GetKeyDown(KeyCode.P))//咖啡厅
- {
- StartCoroutine(WaitForChildrenAnimEnd(currentReturnAnimName, "fragmentAnimationToCafe", new Vector3(0, 255.633f, 0), 3));
- }
- StartPlayMainAnim();
- }
- /// <summary>
- /// 延迟等待子级动画播放完毕后 执行
- /// </summary>
- /// <param name="timer"></param>
- /// <returns></returns>
- public IEnumerator WaitForChildrenAnimEnd(string animName, string mianAnimName, Vector3 GotoAngel, float timer)
- {
- //ui_Main.transform.DOMove(point_End_UiMain_Obj.transform.position, 1);
- //ui_Main_1.transform.DOMove(point_End_UiMain_1_Obj.transform.position, 1);
- 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)
- {
- OBJ_Games_AnimPlay(animName);
- }
- else
- {
- timer = 0;
- }
- yield return new WaitForSeconds(timer);
- main_anim.Play(mianAnimName);
- GoToAnimAngel(GotoAngel, 2);
- }
- public void GoToAnimAngel(Vector3 v3, float timers)
- {
- rotattionGames.transform.DOLocalRotate(v3, timers).SetEase(Ease.Flash);
- }
- public string currentReturnAnimName;
- private void StartPlayMainAnim()
- {
- info = main_anim.GetCurrentAnimatorStateInfo(0);
- if (info.IsName("MainAnimation"))
- {
- currentReturnAnimName = "MainAnimation";
- if (info.normalizedTime > 0.1f)
- {
- ui1.SetActive(true);
-
-
- }
- if(info.normalizedTime > 0.2f)
- {
- gameObj_hengfu.SetActive(true);
- }
-
- }
- else
- {
- ui1.GetComponent<Animator>().Play("ReturnKUANG13Animation");
- main_anim.SetBool("isToConferenceRoom", false);
- }
- if (info.IsName("fragmentAnimationToConferenceRoom"))
- {
- MoveToUI();
- currentReturnAnimName = "ReturnExhibitionHallAnimation";
- if (info.normalizedTime > 0.8f)//将要结束
- {
- OBJ_Games_AnimPlay(currentReturnAnimName);
- }
- if (info.normalizedTime > 0.94f)//会议室动画播放完毕后
- {
- GoToAnimAngel(new Vector3(0, 74.08f, 0), 2f);
- }
- }
- if (info.IsName("fragmentAnimationToExhibitionHall"))//展厅动画播放完毕后
- {
- MoveToUI();
- currentReturnAnimName = "ReturnMrRoomFXAnimation";
- if (info.normalizedTime > 0.8f)//将要结束
- {
- OBJ_Games_AnimPlay(currentReturnAnimName);
- }
- if (info.normalizedTime > 0.94f)
- {
- GoToAnimAngel(new Vector3(0, 172.653f, 0), 2f);
- }
- }
- if (info.IsName("fragmentAnimationToBasketballCourt"))
- {
- MoveToUI();
- currentReturnAnimName = "ReturnBasketballCourtAnimation";
- if (info.normalizedTime > 0.8f)//将要结束
- {
- OBJ_Games_AnimPlay(currentReturnAnimName);
- }
- if (info.normalizedTime > 0.94f)
- {
- GoToAnimAngel(new Vector3(0, 255.633f, 0), 2f);
- }
- }
- if (info.IsName("fragmentAnimationToCafe"))
- {
- MoveToUI();
- currentReturnAnimName = "ReturnCafeAnimation";
- if (info.normalizedTime > 0.9f)//将要结束
- {
- OBJ_Games_AnimPlay(currentReturnAnimName);
- }
- if (info.normalizedTime > 0.99f)
- {
- GoToAnimAngel(new Vector3(0, -9f, 0), 2f);
- }
- }
- }
- private void OBJ_Games_AnimPlay(string str)
- {
- switch (str)
- {
- case "ReturnExhibitionHallAnimation":
- obj_Exhibition_anim.Play("ReturnExhibitionHallAnimation");
- break;
- case "ReturnMrRoomFXAnimation":
- obj_MrRoom_anim.Play("ReturnMrRoomFXAnimation");
- break;
- case "ReturnBasketballCourtAnimation":
- obj_Basketball_anim.Play("ReturnBasketballCourtAnimation");
- break;
- case "ReturnCafeAnimation":
- obj_Cafe_anim.Play("ReturnCafeAnimation");
- break;
- }
- }
- }
|