using System.Collections;
using System.Collections.Generic;
using UnityEngine;
///
/// 新手引导控制脚本
///
public class GuideCtrl : MonoBehaviour
{
GuidePanel panel;//UI
Dictionary allGuideDic;
GuideEnum currentStep;//当前引导到了第几步
int currentIndex;//分解步骤
int needIndex;//当前步骤中需要多少分步
///
/// Awake is called when the script instance is being loaded.
///
void Awake()
{
AddDic();
currentStep = GuideEnum.None;
currentIndex = -1;
panel = gameObject.AddComponent();
}
private void Start()
{
Init();
}
public void Init()
{
//Time.timeScale = 0;//游戏暂停,这样会导致协程停止了
ChangeStep(GuideEnum.Step0);
}
///
/// 初始化字典
///
void AddDic()
{
allGuideDic = new Dictionary();
allGuideDic.Add(GuideEnum.Step0, new string[] { GuideConfig.showWords[0], GuideConfig.showWords[1] });
allGuideDic.Add(GuideEnum.Step1, new string[] { GuideConfig.showWords[2], GuideConfig.showWords[3] });
allGuideDic.Add(GuideEnum.Step2, new string[] { GuideConfig.showWords[4], GuideConfig.showWords[5] });
allGuideDic.Add(GuideEnum.Step3, new string[] { GuideConfig.showWords[6], GuideConfig.showWords[7] });
allGuideDic.Add(GuideEnum.Step4, new string[] { GuideConfig.showWords[8] });
allGuideDic.Add(GuideEnum.Step5, new string[] { GuideConfig.showWords[9], GuideConfig.showWords[10] });
allGuideDic.Add(GuideEnum.Step6, new string[] { GuideConfig.showWords[11], GuideConfig.showWords[12] });
allGuideDic.Add(GuideEnum.Step7, new string[] { GuideConfig.showWords[13] });
allGuideDic.Add(GuideEnum.Step8, new string[] { GuideConfig.showWords[14], GuideConfig.showWords[15] });
allGuideDic.Add(GuideEnum.Step9, new string[] { GuideConfig.showWords[16], GuideConfig.showWords[17] });
allGuideDic.Add(GuideEnum.Step10, new string[] { GuideConfig.showWords[18], GuideConfig.showWords[19] });
allGuideDic.Add(GuideEnum.Step11, new string[] { GuideConfig.showWords[20], GuideConfig.showWords[21] });
allGuideDic.Add(GuideEnum.Step12, new string[] { GuideConfig.showWords[22], GuideConfig.showWords[23], GuideConfig.showWords[24] });
}
///
/// 引导步骤
///
///
public void ChangeStep(GuideEnum step)
{
//if (currentStep != step)
{
currentStep = step;
switch (currentStep)
{
case GuideEnum.Step0:
Step0();
break;
case GuideEnum.Step1:
Step1();
break;
case GuideEnum.Step2:
Step2();
break;
case GuideEnum.Step3:
Step3();
break;
case GuideEnum.Step4:
Step4();
break;
case GuideEnum.Step5:
Step5();
break;
case GuideEnum.Step6:
Step6();
break;
case GuideEnum.Step7:
Step7();
break;
case GuideEnum.Step8:
Step8();
break;
case GuideEnum.Step9:
Step9();
break;
case GuideEnum.Step10:
Step10();
break;
case GuideEnum.Step11:
Step11();
break;
case GuideEnum.Step12:
Step12();
break;
}
}
}
#region 步骤分解
private void Step0()
{
isShowing = true;
if (currentIndex == -1)//初始化本步
{
currentIndex = 0;
needIndex = 2;
panel.SetGuideUI(true);
panel.StartShowWord(allGuideDic[currentStep][currentIndex], ShowWordCallBack);
}
else if (currentIndex == 1)
{
panel.StartShowWord(allGuideDic[currentStep][currentIndex], ShowWordCallBack);
}
}
private void Step1()
{
if (currentIndex == -1)
{
panel.SetGuideUI(false);
currentIndex = 0;
needIndex = 2;
panel.Step1(allGuideDic[currentStep][currentIndex], currentIndex, OnFinishOneStep);
}
else if (currentIndex == 1)
{
panel.Step1(allGuideDic[currentStep][currentIndex], currentIndex, OnFinishOneStep);
currentIndex++;
}
}
private void Step2()
{
isShowing = true;
if (currentIndex == -1)
{
currentIndex = 0;
needIndex = 2;
panel.Step2(currentIndex);
panel.SetGuideUI(true);
panel.StartShowWord(allGuideDic[currentStep][currentIndex], ShowWordCallBack);
//隐藏
}
else if (currentIndex == 1)
{
panel.StartShowWord(allGuideDic[currentStep][currentIndex], ShowWordCallBack);
//currentIndex++;
}
}
private void Step3()
{
if (currentIndex == -1)
{
}
}
private void Step4()
{
if (currentIndex == -1)
{
}
}
private void Step5()
{
if (currentIndex == -1)
{
}
}
private void Step6()
{
if (currentIndex == -1)
{
}
}
private void Step7()
{
if (currentIndex == -1)
{
}
}
private void Step8()
{
if (currentIndex == -1)
{
}
}
private void Step9()
{
if (currentIndex == -1)
{
}
}
private void Step10()
{
if (currentIndex == -1)
{
}
}
private void Step11()
{
if (currentIndex == -1)
{
}
}
private void Step12()
{
if (currentIndex == -1)
{
}
}
#endregion
#region 点击事件
bool isShowing;//是否正在显示文字
///
/// 文字显示结束
///
public void ShowWordCallBack()
{
isShowing = false;
if (needIndex - currentIndex == 1)
{
currentIndex = needIndex;
}
//currentIndex++;
}
///
/// 完成了当前步骤中的一个分步骤
///
public void OnFinishOneStep()
{
if (isShowing)
{
//正在显示文字,第一次点击,显示全部
panel.ShowWordImmediately();
}
else if (needIndex - currentIndex > 0)
{
//说明当前步骤没完成,进行下一个分步
currentIndex++;
ChangeStep(currentStep);
}
else
{
//开始新的步骤
currentIndex = -1;
ChangeStep(currentStep + 1);
}
//Debug.LogError($"当前引导:{currentStep} 当前步数:{currentIndex} 总共有:{needIndex}步");
}
#endregion
}