You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
437 lines
12 KiB
437 lines
12 KiB
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<PcControl>
|
|
{
|
|
|
|
[Header("零件动画信息")]
|
|
public List<SpareAnimationInfo> spareAnimationInfos;
|
|
|
|
[Header("零件容器控制")]
|
|
public List<SpareContainerInfo> spareContainerInfos;
|
|
|
|
|
|
private int curSpIndex = -1;
|
|
|
|
//当前控制器下标
|
|
private SpareType curSpType;
|
|
|
|
private SpareItemControl curSpControl;
|
|
// Start is called before the first frame update
|
|
void Start()
|
|
{
|
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 显示当前选择机型零件
|
|
/// </summary>
|
|
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);
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 设置当前零件模型
|
|
/// </summary>
|
|
/// <param name="info"></param>
|
|
public void SelectSpareModle()
|
|
{
|
|
List<SpareInfo> 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);
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 设置拆机步数
|
|
/// </summary>
|
|
/// <param name="step"></param>
|
|
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();
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 设置装机步数
|
|
/// </summary>
|
|
/// <param name="step"></param>
|
|
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();
|
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 注册零件控制事件
|
|
/// </summary>
|
|
void RegistSpareControl()
|
|
{
|
|
curSpControl.spareAnimation.OnLoadFinishHandle.RemoveAllListeners();
|
|
curSpControl.spareAnimation.OnUnLoadFinishHandle.RemoveAllListeners();
|
|
|
|
curSpControl.spareAnimation.OnLoadFinishHandle.AddListener(LoadFinish);
|
|
curSpControl.spareAnimation.OnUnLoadFinishHandle.AddListener(UnloadFinish);
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// 准备拆卸下一个步骤数据
|
|
/// </summary>
|
|
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();
|
|
});
|
|
}
|
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 准备安装下一个步骤数据
|
|
/// </summary>
|
|
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();
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 设置下一步数据
|
|
/// </summary>
|
|
public void SetNextSpareType()
|
|
{
|
|
SpareType[] types = Enum.GetValues(typeof(SpareType)) as SpareType[];
|
|
curSpType = types[curSpIndex];
|
|
ShowOperationTip();
|
|
SetSpareControl(curSpType);
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// 隐藏高光
|
|
/// </summary>
|
|
public void HideTipSpare()
|
|
{
|
|
if (curSpControl)
|
|
{
|
|
curSpControl.DisableAllOutLine();
|
|
}
|
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 变更当前零件皮肤
|
|
/// </summary>
|
|
public void ChangeCurSpareSkin(SpareInfo info)
|
|
{
|
|
if (curSpControl.gameObject!= null)
|
|
{
|
|
SpareSkinner skinner = curSpControl.GetComponent<SpareSkinner>();
|
|
if (skinner != null)
|
|
{
|
|
skinner.SetCurSkin(info.name);
|
|
//设置灯光
|
|
GamePCLighter.Instance.SetLightColor(info.name);
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// 完成拆卸模式
|
|
/// </summary>
|
|
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("恭喜你顺利通过<color=red>拆卸课程</color> 加油!!");
|
|
MessageContainer.SendMessage("",this,MsgName.MainViewQuitFocuseMode);
|
|
yield return new WaitForSeconds(0.5f);
|
|
LzFramework.UI.TTUIPage.ShowPage<EndView>(tipStr);
|
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 完成安装模式
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
IEnumerator FinishLoadMode()
|
|
{
|
|
yield return new WaitForSeconds(2.50f);
|
|
string tipStr = string.Format("恭喜你顺利通过<color=red>安装课程</color> 加油!!");
|
|
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<EndView>(tipStr);
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// 当前拆卸完成
|
|
/// </summary>
|
|
void UnloadFinish()
|
|
{
|
|
|
|
MessageContainer.SendMessage("", this, MsgName.TipViewHideOperation);
|
|
HideTipSpare();
|
|
|
|
|
|
//显示零件展示 数据
|
|
SpareInfo info = GetCurSpareInfo();
|
|
if (info != null)
|
|
RendereSpareControl.Instance.ShowSpareRenderer(info);
|
|
|
|
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 当前组装完成
|
|
/// </summary>
|
|
void LoadFinish()
|
|
{
|
|
|
|
HideTipSpare();
|
|
string spareName = CommonTool.GetSpareName(curSpType);
|
|
string tip = string.Format("恭喜你完成了<color=red>{0}</color>的安装", spareName);
|
|
MessageContainer.SendMessage(tip, this, MsgName.TipViewShowPoint);
|
|
|
|
MessageContainer.SendMessage("temp", this, MsgName.MainViewGrowthBar,0.5f);
|
|
//准备安装下一个
|
|
ReadyLoadNextStep(1.5f);
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// 显示操作提示
|
|
/// </summary>
|
|
void ShowOperationTip()
|
|
{
|
|
string spareName = CommonTool.GetSpareName(curSpType);
|
|
string tipStr = "";
|
|
if (GameConfig.state == GameState.Load)
|
|
{
|
|
tipStr = string.Format("<size=30>{0}组装</size>\n按住鼠标左键可移动目标\n点击鼠标右键选择零件类型\n鼠标滚轮缩放视距,右键控制目标旋转", spareName);
|
|
}
|
|
else
|
|
{
|
|
tipStr = string.Format("<size=30>{0}拆装</size>\n请在左侧选择正确工具,进行操作\n鼠标滚轮缩放视距,右键控制目标旋转", spareName);
|
|
}
|
|
|
|
MessageContainer.SendMessage(tipStr, this, MsgName.TipViewShowOperation);
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 设置当前零件控制
|
|
/// </summary>
|
|
/// <param name="type"></param>
|
|
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();
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 返回当前零件信息
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
SpareInfo GetCurSpareInfo()
|
|
{
|
|
List<SpareInfo> 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;
|
|
}
|
|
}
|
|
|