using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using LzFramework; using EduCoderTool; using Newtonsoft.Json; namespace DisComputer { /* * @func 电脑拆装流程控制 * @author lz * @date 2020/05/29 * */ public class PcControl : Singleton { [Header("零件动画信息")] public List spareAnimationInfos; [Header("零件容器控制")] public List spareContainerInfos; private int curSpIndex = -1; //当前控制器下标 private SpareType curSpType; private SpareItemControl curSpControl; // Start is called before the first frame update void Start() { } /// /// 显示当前选择机型零件 /// public void ShowSelectPcSpare() { StartCoroutine(AsycShowModle()); } IEnumerator AsycShowModle() { for (int i = 0; i < spareContainerInfos.Count; i++) { spareContainerInfos[i].container.ShowSpareGo(); yield return new WaitForSeconds(0.05f); } } /// /// 设置当前零件模型 /// /// public void SelectSpareModle() { List infos = GameDataConfig.Instance.gameSpareInfos(); for (int k = 0; k < infos.Count; k++) { SpareInfo info = infos[k]; for (int i = 0; i < spareContainerInfos.Count; i++) { if (info.type == spareContainerInfos[i].type) { spareContainerInfos[i].container.SelectSpareControl(info); } } } } /// /// 设置拆机步数 /// /// public void SetUnloadState(int step) { if(step == 0 && GameDataConfig.Instance.pcId == 1) { GamePCLighter.Instance.ShowLight(); } for (int i = 0; i < spareContainerInfos.Count; i++) { if (i < step) { //Debug.LogFormat("*** Set UnloadMode 隐藏 {0} ", spareAnimationInfos[i].type); spareContainerInfos[i].container.curSpareControl.spareAnimation.SetUnloadState(); spareContainerInfos[i].container.curSpareControl.DisableLoadColor(); spareContainerInfos[i].container.curSpareControl.DisableAllOutLine(); } else { //Debug.LogFormat("*** Set UnloadMode 显示 {0} ", spareAnimationInfos[i].type); spareContainerInfos[i].container.curSpareControl.spareAnimation.SetLoadState(); spareContainerInfos[i].container.curSpareControl.DisableLoadColor(); spareContainerInfos[i].container.curSpareControl.DisableAllOutLine(); } } curSpIndex = step; SetNextSpareType(); } /// /// 设置装机步数 /// /// public void SetLoadState(int step) { step = 7 - step; for (int i = spareContainerInfos.Count - 1; i >= 0; i--) { //Debug.LogFormat("i {0} step {1}",i,step); if (i <= step) { //Debug.LogFormat("*** Set loadMode 隐藏 {0} ", spareAnimationInfos[i].type); spareContainerInfos[i].container.curSpareControl.spareAnimation.SetUnloadState(); spareContainerInfos[i].container.curSpareControl.DisableLoadColor(); spareContainerInfos[i].container.curSpareControl.DisableAllOutLine(); } else { //Debug.LogFormat("*** Set loadMode 显示 {0} ", spareAnimationInfos[i].type); spareContainerInfos[i].container.curSpareControl.spareAnimation.SetLoadState(); spareContainerInfos[i].container.curSpareControl.DisableLoadColor(); spareContainerInfos[i].container.curSpareControl.DisableAllOutLine(); } } curSpIndex = step; SetNextSpareType(); } /// /// 注册零件控制事件 /// void RegistSpareControl() { curSpControl.spareAnimation.OnLoadFinishHandle.RemoveAllListeners(); curSpControl.spareAnimation.OnUnLoadFinishHandle.RemoveAllListeners(); curSpControl.spareAnimation.OnLoadFinishHandle.AddListener(LoadFinish); curSpControl.spareAnimation.OnUnLoadFinishHandle.AddListener(UnloadFinish); } /// /// 准备拆卸下一个步骤数据 /// public void ReadyUnloadNextStep(float delay) { //隐藏零件展示 RendereSpareControl.Instance.HideSpareRenderer(); curSpIndex++; Debug.LogFormat(" --- unload mode cur index {0}", curSpIndex); if (curSpIndex > 7)//拆装成功 { Debug.LogFormat("拆卸成功!!!"); StartCoroutine(FinishUnLoadMode()); curSpIndex = 8; } else { CommonTool.WaitTimeAfterDo(this, delay, () => { SetNextSpareType(); }); } } /// /// 准备安装下一个步骤数据 /// public void ReadyLoadNextStep(float delay) { curSpIndex--; Debug.LogFormat(" *** cur index {0}", curSpIndex); if (curSpIndex <= -1) {//全部安装成功 curSpIndex = -1; if (GameDataConfig.Instance.pcId == 1) GamePCLighter.Instance.ShowLight(); StartCoroutine(FinishLoadMode()); } else { CommonTool.WaitTimeAfterDo(this, delay, () => { SetNextSpareType(); }); } } /// /// 设置下一步数据 /// public void SetNextSpareType() { SpareType[] types = Enum.GetValues(typeof(SpareType)) as SpareType[]; curSpType = types[curSpIndex]; ShowOperationTip(); SetSpareControl(curSpType); } /// /// 隐藏高光 /// public void HideTipSpare() { if (curSpControl) { curSpControl.DisableAllOutLine(); } } /// /// 变更当前零件皮肤 /// public void ChangeCurSpareSkin(SpareInfo info) { if (curSpControl.gameObject!= null) { SpareSkinner skinner = curSpControl.GetComponent(); if (skinner != null) { skinner.SetCurSkin(info.name); //设置灯光 GamePCLighter.Instance.SetLightColor(info.name); } } } /// /// 完成拆卸模式 /// 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() { MessageContainer.SendMessage("", this, MsgName.TipViewHideOperation); HideTipSpare(); //显示零件展示 数据 SpareInfo info = GetCurSpareInfo(); if (info != null) RendereSpareControl.Instance.ShowSpareRenderer(info); } /// /// 当前组装完成 /// void LoadFinish() { 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 ShowOperationTip() { string spareName = CommonTool.GetSpareName(curSpType); string tipStr = ""; if (GameConfig.state == GameState.Load) { tipStr = string.Format("{0}组装\n按住鼠标左键可移动目标\n点击鼠标右键选择零件类型\n鼠标滚轮缩放视距,右键控制目标旋转", spareName); } else { tipStr = string.Format("{0}拆装\n请在左侧选择正确工具,进行操作\n鼠标滚轮缩放视距,右键控制目标旋转", spareName); } MessageContainer.SendMessage(tipStr, this, MsgName.TipViewShowOperation); } /// /// 设置当前零件控制 /// /// void SetSpareControl(SpareType type) { for (int i = 0; i < spareContainerInfos.Count; i++) { if (spareContainerInfos[i].type == type) { if (curSpControl != null) { curSpControl.HideArrowTip(); } curSpControl = spareContainerInfos[i].container.curSpareControl; } } if (curSpControl) { curSpControl.ActiveRegistType(type); curSpControl.ShowArrowTip(); RegistSpareControl(); } } /// /// 返回当前零件信息 /// /// SpareInfo GetCurSpareInfo() { List infos = GameDataConfig.Instance.gameSpareInfos(); for (int i = 0;i < infos.Count; i++) { if (infos[i].type == curSpType) return infos[i]; } return null; } } [Serializable] public class SpareAnimationInfo { public SpareType type; public SpareItemControl control; } [Serializable] public class SpareContainerInfo { public SpareType type; public SpareContainer container; } }