using DG.Tweening; using System; using System.Collections; using System.Collections.Generic; using System.Linq; using UnityEngine; public class GameManagers : MonoSingleton { // 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 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 userSelectionPanelScButton_List; public List userSelectionPanelScButtonClickFX_List; public List userSelectionPanelScButtonEnterFX_List; public GameObject gameObj_hengfu; public string device_sn; /// /// 主动画 -15 /// 会议室 -15 /// 展厅 74.08 /// 篮球场 172.653 /// 咖啡厅 250.633 /// /// private void Awake() { // AppManager.Instance.functionChangeAction += FunctionChangeHandler; } private void OnDestroy() { // AppManager.Instance.functionChangeAction -= FunctionChangeHandler; } //private void FunctionChangeHandler(List 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 functionValues = null) //{ //} //private void SetFunction(int moduleID, int functionID, FunctionType fType = FunctionType.GotoScence, List 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 functionValues) //{ // List tempList = new List(); // 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 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 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)); } /// /// 功能状态发生变化 /// //public Action> functionChangleAction; //public Action functionColliderGameObjectAction; private void Init() { changToScenesButton.ForEach(scObj => { scObj.GetComponent().onClick.AddListener(() => { onUserClick(scObj.name); }); scObj.GetComponent().onEnter.AddListener(() => { buttonFX.GetComponent().moveToEndV3 = scObj.transform.position; buttonFX.GetComponent().userEnterClick(true, scObj.name); }); scObj.GetComponent().onExit.AddListener(() => { buttonFX.GetComponent().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().userEnterClick(false, ButtonName); buttonFX.GetComponent().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(); } /// /// 延迟等待子级动画播放完毕后 执行 /// /// /// 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().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; } } }