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.

362 lines
10 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

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<PcControl>
{
public List<SpareAnimationInfo> 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);
}
}
/// <summary>
/// 设置拆机步数
/// </summary>
/// <param name="step"></param>
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();
}
/// <summary>
/// 设置装机步数
/// </summary>
/// <param name="step"></param>
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();
}
/// <summary>
/// 注册零件控制事件
/// </summary>
public void RegistSpareControl()
{
curSpControl.spareAnimation.OnLoadFinishHandle.RemoveAllListeners();
curSpControl.spareAnimation.OnUnLoadFinishHandle.RemoveAllListeners();
curSpControl.spareAnimation.OnLoadFinishHandle.AddListener(LoadFinish);
curSpControl.spareAnimation.OnUnLoadFinishHandle.AddListener(UnloadFinish);
}
/// <summary>
/// 提示零件
/// </summary>
/// <param name="spareIndex">零件下标</param>
public void ProgressTipSpare(SpareType type)
{
SetSpareControl(type);
RegistSpareControl();
curSpControl.ShowOutline();
}
//当前数据是否已经准备
bool isReadyed = false;
/// <summary>
/// 准备拆卸下一个步骤数据
/// </summary>
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();
});
}
}
/// <summary>
/// 准备安装下一个步骤数据
/// </summary>
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();
});
}
}
/// <summary>
/// 隐藏高光
/// </summary>
public void HideTipSpare()
{
if (curSpControl)
{
curSpControl.DisableAllOutLine();
}
}
/// <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()
{
// Debug.LogFormat("当前{0}拆除成功",curSpType.ToString());
isReadyed = false;
MessageContainer.SendMessage("quit", this, MsgName.TipViewShowOperation);
HideTipSpare();
//显示零件展示
RendereSpareControl.Instance.ShowSpareRenderer(curSpType);
}
/// <summary>
/// 当前组装完成
/// </summary>
void LoadFinish()
{
isReadyed = false;
//Debug.LogFormat("当前{0}安装成功", curSpType.ToString());
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 SetNextSpareType()
{
SpareType[] types = Enum.GetValues(typeof(SpareType))as SpareType[];
curSpType = types[curSpIndex];
ShowOperationTip();
SetSpareControl(curSpType);
ProgressTipSpare(curSpType);
}
/// <summary>
/// 显示操作提示
/// </summary>
void ShowOperationTip()
{
string spareName = CommonTool.GetSpareName(curSpType);
string tipStr = "";
if (GameConfig.state == GameState.Load)
{
tipStr = string.Format("{0}<color=red>组装</color>\n请打开背包选择零件放置正确安装位置进行操作鼠标滚轮缩放鼠标右键旋转", spareName);
}
else
{
tipStr = string.Format("{0}<color=red>拆装</color>\n请在左侧选择正确工具进行操作鼠标滚轮缩放鼠标右键旋转", spareName);
}
MessageContainer.SendMessage(tipStr, this, MsgName.TipViewShowOperation);
}
/// <summary>
/// 设置当前零件控制
/// </summary>
/// <param name="type"></param>
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;
}
}