using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using LzFramework; using EduCoderTool; using Newtonsoft.Json; namespace DisComputer { /* * @func 电脑拆装流程控制 * @author lz * @data 2020/05/29 * */ public class PcControl : Singleton { public List spareAnimationInfos; 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.GetKeyDown(KeyCode.U)) { SetUnloadState(7); } if (Input.GetKeyDown(KeyCode.B)) { SetLoadState(7); } //重置安装模式 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 SetUnloadState(int step) { for(int i = 0; i < spareAnimationInfos.Count; i++) { if (i < step) { Debug.LogFormat("*** Set UnloadMode 隐藏 {0} ", spareAnimationInfos[i].type); spareAnimationInfos[i].control.spareAnimation.SetUnloadState(); }else { Debug.LogFormat("*** Set UnloadMode 显示 {0} ", spareAnimationInfos[i].type); spareAnimationInfos[i].control.spareAnimation.SetLoadState(); } } curSpIndex = step; SetNextSpareType(); } /// /// 设置装机步数 /// /// public void SetLoadState(int step) { for (int i = 0; i < spareAnimationInfos.Count; i++) { if(i < step) { Debug.LogFormat("*** Set loadMode 显示 {0} ", spareAnimationInfos[i].type); spareAnimationInfos[i].control.spareAnimation.SetLoadState(); } else { Debug.LogFormat("*** Set loadMode 隐藏 {0} ", spareAnimationInfos[i].type); spareAnimationInfos[i].control.spareAnimation.SetUnloadState(); } } curSpIndex = 8 - step; SetNextSpareType(); } /// /// 注册零件控制事件 /// 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); WebData webData = new WebData(); webData.Data = ""; webData.GameState = "Success"; string json = JsonConvert.SerializeObject(webData); WebConnecter.Singleton.SendDataToWeb(json); 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); WebData webData = new WebData(); webData.Data = ""; webData.GameState = "Success"; string json = JsonConvert.SerializeObject(webData); WebConnecter.Singleton.SendDataToWeb(json); 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) { for(int i = 0; i < spareAnimationInfos.Count; i++) { if(spareAnimationInfos[i].type == type) { curSpControl = spareAnimationInfos[i].control; } } curSpControl.ActiveRegistType(type); } } [Serializable] public class SpareAnimationInfo { public SpareType type; public SpareItemControl control; } }