using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using LzFramework; namespace DisComputer { /* * @func 电脑拆装流程控制 * @author lz * @data 2020/05/29 * */ public class PcControl : Singleton { public SpareItemControl zhubanControl; public SpareItemControl yingPanControl; public SpareItemControl dianYuanControl; public SpareItemControl guangQuControl; public SpareItemControl xianKaControl; public SpareItemControl cpuControl; public SpareItemControl neiCunTiaoControl; public SpareItemControl jiXiangControl; private int curSpIndex = 0; //当前控制器下标 private SpareType curSpType; private SpareItemControl curSpControl; // Start is called before the first frame update void Start() { } private void Update() { if ( Input.GetKey(KeyCode.U) &&Input.GetKeyDown(KeyCode.Alpha1)) { jiXiangControl.spareAnimation.OnUnLoadAct(); } if (Input.GetKey(KeyCode.R) && Input.GetKeyDown(KeyCode.Alpha1)) { jiXiangControl.spareAnimation.OnLoadAct(); } if (Input.GetKey(KeyCode.U) && Input.GetKeyDown(KeyCode.Alpha2)) { neiCunTiaoControl.spareAnimation.OnUnLoadAct(); } if (Input.GetKey(KeyCode.R) && Input.GetKeyDown(KeyCode.Alpha2)) { neiCunTiaoControl.spareAnimation.OnLoadAct(); } if (Input.GetKey(KeyCode.U) && Input.GetKeyDown(KeyCode.Alpha3)) { yingPanControl.spareAnimation.OnUnLoadAct(); } if (Input.GetKey(KeyCode.R) && Input.GetKeyDown(KeyCode.Alpha3)) { yingPanControl.spareAnimation.OnLoadAct(); } if (Input.GetKey(KeyCode.U) && Input.GetKeyDown(KeyCode.Alpha4)) { xianKaControl.spareAnimation.OnUnLoadAct(); } if (Input.GetKey(KeyCode.R) && Input.GetKeyDown(KeyCode.Alpha4)) { xianKaControl.spareAnimation.OnLoadAct(); } if (Input.GetKey(KeyCode.U) && Input.GetKeyDown(KeyCode.Alpha5)) { cpuControl.spareAnimation.OnUnLoadAct(); } if (Input.GetKey(KeyCode.R) && Input.GetKeyDown(KeyCode.Alpha5)) { cpuControl.spareAnimation.OnLoadAct(); } if (Input.GetKey(KeyCode.U) && Input.GetKeyDown(KeyCode.Alpha6)) { dianYuanControl.spareAnimation.OnUnLoadAct(); } if (Input.GetKey(KeyCode.R) && Input.GetKeyDown(KeyCode.Alpha6)) { dianYuanControl.spareAnimation.OnLoadAct(); } if (Input.GetKey(KeyCode.U) && Input.GetKeyDown(KeyCode.Alpha7)) { guangQuControl.spareAnimation.OnUnLoadAct(); } if (Input.GetKey(KeyCode.R) && Input.GetKeyDown(KeyCode.Alpha7)) { guangQuControl.spareAnimation.OnLoadAct(); } if (Input.GetKey(KeyCode.U) && Input.GetKeyDown(KeyCode.Alpha8)) { zhubanControl.spareAnimation.OnUnLoadAct(); } if (Input.GetKey(KeyCode.R) && Input.GetKeyDown(KeyCode.Alpha8)) { zhubanControl.spareAnimation.OnLoadAct(); } //重置安装模式 if (Input.GetKeyDown(KeyCode.Space)) { if(GameConfig.state == GameState.Load) { GameConfig.state = GameState.Unload; } else { GameConfig.state = GameState.Load; } Debug.LogFormat(">>>>>>>>>> cur SP index {0}", curSpIndex); curSpIndex--; ReadyLoadNextStep(0); } } /// /// 注册零件控制事件 /// public void RegistSpareControl() { curSpControl.spareAnimation.OnLoadFinishHandle.RemoveAllListeners(); curSpControl.spareAnimation.OnUnLoadFinishHandle.RemoveAllListeners(); curSpControl.spareAnimation.OnLoadFinishHandle.AddListener(LoadFinish); curSpControl.spareAnimation.OnUnLoadFinishHandle.AddListener(UnloadFinish); } /// /// 提示零件 /// /// 零件下标 public void ProgressTipSpare(SpareType type) { SetSpareControl(type); RegistSpareControl(); curSpControl.ShowOutline(); } //当前数据是否已经准备 bool isReadyed = false; /// /// 准备拆卸下一个步骤数据 /// public void ReadyUnloadNextStep(float delay) { if (!isReadyed) { isReadyed = true; //隐藏零件展示 RendereSpareControl.Instance.HideSpareRenderer(); curSpIndex++; } Debug.LogFormat(" *** cur index {0}",curSpIndex); if (curSpIndex > 8)//拆装成功 { Debug.LogFormat("拆卸成功!!!"); StartCoroutine(FinishUnLoadMode()); curSpIndex = 8; } else { CommonTool.WaitTimeAfterDo(this, delay, () => { SetNextSpareType(); }); } } /// /// 准备安装下一个步骤数据 /// public void ReadyLoadNextStep(float delay) { if (!isReadyed) { isReadyed = true; curSpIndex--; Debug.LogFormat(" ----- cur index {0}", curSpIndex); } Debug.LogFormat(" *** cur index {0}", curSpIndex); if (curSpIndex <= 0) {//全部安装成功 curSpIndex = 1; StartCoroutine(FinishLoadMode()); } else { CommonTool.WaitTimeAfterDo(this, delay, () => { SetNextSpareType(); }); } } /// /// 隐藏高光 /// public void HideTipSpare() { if (curSpControl) { curSpControl.DisableAllOutLine(); } } /// /// 完成拆卸模式 /// IEnumerator FinishUnLoadMode() { yield return new WaitForSeconds(2.50f); string tipStr = string.Format("恭喜你顺利通过拆卸课程,接下来进入组装课程!加油!!"); MessageContainer.SendMessage("",this,MsgName.MainViewQuitFocuseMode); yield return new WaitForSeconds(0.5f); LzFramework.UI.TTUIPage.ShowPage(tipStr); } /// /// 完成安装模式 /// /// IEnumerator FinishLoadMode() { yield return new WaitForSeconds(2.50f); string tipStr = string.Format("恭喜你顺利通过安装课程,并掌握了计算机拆装!!"); MessageContainer.SendMessage("", this, MsgName.MainViewQuitFocuseMode); yield return new WaitForSeconds(0.50f); LzFramework.UI.TTUIPage.ShowPage(tipStr); } /// /// 当前拆卸完成 /// void UnloadFinish() { Debug.LogFormat("当前{0}拆除成功",curSpType.ToString()); isReadyed = false; MessageContainer.SendMessage("quit", this, MsgName.TipViewShowOperation); HideTipSpare(); //显示零件展示 RendereSpareControl.Instance.ShowSpareRenderer(curSpType); } /// /// 当前组装完成 /// void LoadFinish() { isReadyed = false; Debug.LogFormat("当前{0}安装成功", curSpType.ToString()); HideTipSpare(); string spareName = CommonTool.GetSpareName(curSpType); string tip = string.Format("恭喜你完成了{0}的安装", spareName); MessageContainer.SendMessage(tip, this, MsgName.TipViewShowPoint); MessageContainer.SendMessage("temp", this, MsgName.MainViewGrowthBar,0.5f); //准备安装下一个 ReadyLoadNextStep(1.5f); } /// /// 设置下一步数据 /// void SetNextSpareType() { SpareType[] types = Enum.GetValues(typeof(SpareType))as SpareType[]; curSpType = types[curSpIndex]; ShowOperationTip(); SetSpareControl(curSpType); ProgressTipSpare(curSpType); } /// /// 显示操作提示 /// void ShowOperationTip() { string spareName = CommonTool.GetSpareName(curSpType); string tipStr = ""; if (GameConfig.state == GameState.Load) { tipStr = string.Format("{0}组装\n请打开背包选择零件放置正确安装位置,进行操作(鼠标滚轮缩放,鼠标右键旋转)", spareName); } else { tipStr = string.Format("{0}拆装\n请在左侧选择正确工具,进行操作(鼠标滚轮缩放,鼠标右键旋转)", spareName); } MessageContainer.SendMessage(tipStr, this, MsgName.TipViewShowOperation); } /// /// 设置当前零件控制 /// /// void SetSpareControl(SpareType type) { switch (type) { case SpareType.Cpu: curSpControl = cpuControl; break; case SpareType.DianYuan: curSpControl = dianYuanControl; break; case SpareType.GuangQu: curSpControl = guangQuControl; break; case SpareType.JiXiang: curSpControl = jiXiangControl; break; case SpareType.NeiCun: curSpControl = neiCunTiaoControl; break; case SpareType.Null: break; case SpareType.XianKa: curSpControl = xianKaControl; break; case SpareType.YingPan: curSpControl = yingPanControl; break; case SpareType.ZhuBan: curSpControl = zhubanControl; break; } curSpControl.ActiveRegistType(type); } } }