using System.Collections;
|
using System.Diagnostics;
|
using System.Collections.Generic;
|
using UnityEngine;
|
using KTGMGemClient;
|
|
/// <summary>
|
/// 新手引导控制脚本
|
/// </summary>
|
public class GuideCtrl : MonoBehaviour
|
{
|
private static GuideCtrl ins;
|
public static GuideCtrl Ins { get { return ins; } }
|
|
GuidePanel panel;//UI
|
Dictionary<GuideEnum, string[]> allGuideDic;
|
GuideEnum currentStep;//当前引导到了第几步
|
int currentIndex;//分解步骤
|
int needIndex;//当前步骤中需要多少分步
|
|
/// <summary>
|
/// Awake is called when the script instance is being loaded.
|
/// </summary>
|
void Awake()
|
{
|
ins = this;
|
AddDic();
|
currentStep = GuideEnum.None;
|
currentIndex = -1;
|
panel = gameObject.AddComponent<GuidePanel>();
|
}
|
|
private void Start()
|
{
|
//int step = PlayerPrefs.GetInt("GemBattleGuide");
|
|
Init(0);
|
EventCenter.Ins.Add((int)KTGMGemClient.EventType.AddCard, AddCard);
|
EventCenter.Ins.Add((int)KTGMGemClient.EventType.CreateFireLv2, CreateFireLv2);
|
EventCenter.Ins.Add((int)KTGMGemClient.EventType.ChargingEnd, ChargingEnd);
|
EventCenter.Ins.Add((int)KTGMGemClient.EventType.KillDone, KillDone);
|
EventCenter.Ins.Add((int)KTGMGemClient.EventType.GetOneTowerPos, GetOneTowerPos);
|
EventCenter.Ins.Add((int)KTGMGemClient.EventType.CreateWaterLv1, CreateWaterLv1);
|
//EventCenter.Ins.Add((int)KTGMGemClient.EventType.SkillStep, SkillStep);
|
EventCenter.Ins.Add((int)KTGMGemClient.EventType.DragStep, DragStep);
|
EventCenter.Ins.Add((int)KTGMGemClient.EventType.ShowWarningTips, ShowWarningTips);//开始第三关,弹一大波敌人
|
EventCenter.Ins.Add((int)KTGMGemClient.EventType.CreateThirdWaveDone, CreateThirdWaveDone);
|
|
//EventCenter.Ins.Add((int)KTGMGemClient.EventType.SkillRelease, SkillRelease);
|
//EventCenter.Ins.Add((int)KTGMGemClient.EventType.SkillReleaseDone, SkillReleaseDone);
|
|
}
|
|
private void OnDestroy()
|
{
|
EventCenter.Ins.Remove((int)KTGMGemClient.EventType.AddCard, AddCard);
|
EventCenter.Ins.Remove((int)KTGMGemClient.EventType.CreateFireLv2, CreateFireLv2);
|
EventCenter.Ins.Remove((int)KTGMGemClient.EventType.ChargingEnd, ChargingEnd);
|
EventCenter.Ins.Remove((int)KTGMGemClient.EventType.KillDone, KillDone);
|
EventCenter.Ins.Remove((int)KTGMGemClient.EventType.GetOneTowerPos, GetOneTowerPos);
|
EventCenter.Ins.Remove((int)KTGMGemClient.EventType.CreateWaterLv1, CreateWaterLv1);
|
//EventCenter.Ins.Remove((int)KTGMGemClient.EventType.SkillStep, SkillStep);
|
EventCenter.Ins.Remove((int)KTGMGemClient.EventType.DragStep, DragStep);
|
EventCenter.Ins.Remove((int)KTGMGemClient.EventType.CreateThirdWaveDone, CreateThirdWaveDone);
|
|
//EventCenter.Ins.Remove((int)KTGMGemClient.EventType.SkillRelease, SkillRelease);
|
//EventCenter.Ins.Remove((int)KTGMGemClient.EventType.SkillReleaseDone, SkillReleaseDone);
|
|
|
}
|
public void Init(int step)
|
{
|
ChangeStep(GuideEnum.Step0);
|
GameConfig.CanOpenNewTower = false;
|
|
}
|
|
/// <summary>
|
/// 初始化字典
|
/// </summary>
|
void AddDic()
|
{
|
allGuideDic = new Dictionary<GuideEnum, string[]>();
|
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[] { });
|
allGuideDic.Add(GuideEnum.Step4, new string[] { GuideConfig.showWords[6] });
|
allGuideDic.Add(GuideEnum.Step5, new string[] { GuideConfig.showWords[7], GuideConfig.showWords[8] });
|
allGuideDic.Add(GuideEnum.Step6, new string[] { });
|
allGuideDic.Add(GuideEnum.Step7, new string[] { });
|
allGuideDic.Add(GuideEnum.Step8, new string[] { GuideConfig.showWords[9] });
|
allGuideDic.Add(GuideEnum.Step9, new string[] { });
|
allGuideDic.Add(GuideEnum.Step10, new string[] { GuideConfig.showWords[10], GuideConfig.showWords[11] });
|
allGuideDic.Add(GuideEnum.Step11, new string[] { });
|
allGuideDic.Add(GuideEnum.Step12, new string[] { GuideConfig.showWords[12], GuideConfig.showWords[13] });
|
allGuideDic.Add(GuideEnum.Step13, new string[] { });
|
allGuideDic.Add(GuideEnum.Step14, new string[] { GuideConfig.showWords[14], GuideConfig.showWords[15] });
|
|
}
|
|
|
/// <summary>
|
/// 引导步骤
|
/// </summary>
|
/// <param name="step"></param>
|
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;
|
case GuideEnum.Step13:
|
Step13();
|
break;
|
case GuideEnum.Step14:
|
Step14();
|
break;
|
case GuideEnum.Finish:
|
Finish();
|
break;
|
|
}
|
|
}
|
}
|
|
|
#region 步骤分解
|
|
private void Step0()
|
{
|
isShowing = true;
|
if (currentIndex == -1)//初始化本步
|
{
|
CommonDebugHelper.DebugError("第1步开始, 对话");
|
TDAA_SDKManager.Ins.Statistics(5);//埋点
|
|
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)
|
{
|
CommonDebugHelper.DebugError("第2步开始,购买火元素");
|
TDAA_SDKManager.Ins.Statistics(6);//埋点
|
TDAA_SDKManager.Ins.GuideStep(1);//埋点
|
|
currentIndex = 0;
|
needIndex = 2;
|
panel.SetGuideUI(false);
|
panel.Step1(allGuideDic[currentStep][currentIndex], currentIndex, Step1_1);
|
}
|
else if (currentIndex == 1)
|
{
|
panel.Step1(allGuideDic[currentStep][currentIndex], currentIndex, Step1_2);
|
|
currentIndex++;
|
}
|
|
}
|
|
/// <summary>
|
/// 分步1,购买1排1列的火元素
|
/// </summary>
|
private void Step1_1()
|
{
|
panel.Step1_1();
|
OnFinishOneStep();
|
}
|
/// <summary>
|
/// 分步2,购买2排3列的火元素
|
/// </summary>
|
private void Step1_2()
|
{
|
panel.Step1_2();
|
StartCoroutine(AfterCreateFire());
|
|
}
|
|
IEnumerator AfterCreateFire()
|
{
|
yield return new WaitForSeconds(1f);
|
OnFinishOneStep();
|
}
|
//对话
|
private void Step2()
|
{
|
isShowing = true;
|
if (currentIndex == -1)
|
{
|
CommonDebugHelper.DebugError("第3步开始,介绍火元素");
|
TDAA_SDKManager.Ins.GuideStep(2);//埋点
|
|
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)
|
{
|
CommonDebugHelper.DebugError("第4步开始,引导合成火元素");
|
TDAA_SDKManager.Ins.GuideStep(3);//埋点
|
|
currentIndex = 0;
|
needIndex = 2;
|
panel.Step3(currentIndex, "");
|
}
|
}
|
|
//开始拖拽
|
public void BeginDrag()
|
{
|
panel.Step3_2("");
|
}
|
|
//结束推拽 没有合成,回到上一步
|
public void EndDrag()
|
{
|
panel.Step3(0, "");
|
}
|
|
//合成了卡牌,开始下一步
|
private void AddCard()
|
{
|
currentIndex = -1;
|
panel.StopShowDragPath(false);
|
ChangeStep(GuideEnum.Step4);
|
}
|
|
private void Step4()
|
{
|
if (currentIndex == -1)
|
{
|
CommonDebugHelper.DebugError("第5步开始,上阵火元素 ");
|
TDAA_SDKManager.Ins.GuideStep(4);//埋点
|
|
currentIndex = 0;
|
panel.StopShowDragPath(true);
|
panel.Step4(currentIndex, allGuideDic[currentStep][currentIndex]);
|
}
|
}
|
|
//建造了塔,开始下一步
|
private void CreateFireLv2()
|
{
|
currentIndex = -1;
|
panel.StopShowDragPath(true);
|
ChangeStep(GuideEnum.Step5);
|
}
|
|
|
private void Step5()
|
{
|
if (currentIndex == -1)
|
{
|
CommonDebugHelper.DebugError("第6步开始,开打第一波");
|
TDAA_SDKManager.Ins.GuideStep(5);//埋点
|
|
EventCenter.Ins.BroadCast((int)KTGMGemClient.EventType.CreateFirstWave);
|
panel.Step5(currentIndex, "");
|
}
|
else if (currentIndex == 1)
|
{
|
isShowing = true;
|
|
panel.StartShowWord(allGuideDic[currentStep][currentIndex], ShowWordCallBack);
|
}
|
}
|
|
private void ChargingEnd()
|
{
|
currentIndex = 0;
|
needIndex = 2;
|
panel.SetGuideUI(true);
|
isShowing = true;
|
panel.StartShowWord(allGuideDic[currentStep][currentIndex], ShowWordCallBack);
|
|
}
|
|
private void Step6()
|
{
|
if (currentIndex == -1)
|
{
|
CommonDebugHelper.DebugError("第7步开始,出怪");
|
TDAA_SDKManager.Ins.GuideStep(6);//埋点
|
|
panel.SetGuideUI(false);
|
//恢复出怪
|
EventCenter.Ins.BroadCast((int)KTGMGemClient.EventType.RestartWave);
|
}
|
else if (currentIndex == 1)
|
{
|
isShowing = true;
|
|
panel.StartShowWord(allGuideDic[currentStep][currentIndex], ShowWordCallBack);
|
|
//增加200金币
|
EventCenter.Ins.BroadCast<int>((int)KTGMGemClient.EventType.AddGold, 200);
|
}
|
}
|
|
private void KillDone()
|
{
|
currentIndex = -1;
|
|
ChangeStep(GuideEnum.Step7);
|
|
// currentIndex = 0;
|
// needIndex = 2;
|
// panel.SetGuideUI(true);
|
// isShowing = true;
|
// panel.StartShowWord(allGuideDic[currentStep][currentIndex], ShowWordCallBack);
|
}
|
|
|
private void Step7()
|
{
|
if (currentIndex == -1)
|
{
|
CommonDebugHelper.DebugError("第8步开始,跳过了");
|
TDAA_SDKManager.Ins.GuideStep(7);//埋点
|
|
currentIndex = 0;
|
needIndex = 1;
|
panel.SetGuideUI(false);
|
|
//GameConfig.CanOpenNewTower = true;
|
|
//等待解锁塔
|
//panel.Step7(currentIndex, allGuideDic[currentStep][currentIndex]);
|
|
//第一排直接开过塔了,引导买水元素
|
GetOneTowerPos();
|
}
|
}
|
|
|
private void GetOneTowerPos()
|
{
|
currentIndex = -1;
|
ChangeStep(GuideEnum.Step8);
|
}
|
|
|
|
private void Step8()
|
{
|
isShowing = true;
|
if (currentIndex == -1)//初始化本步
|
{
|
CommonDebugHelper.DebugError("第9步开始,介绍水元素");
|
TDAA_SDKManager.Ins.GuideStep(8);//埋点
|
GameConfig.CanOpenNewTower = false;
|
|
currentIndex = 0;
|
needIndex = 1;
|
panel.Step8();
|
panel.StartShowWord(allGuideDic[currentStep][currentIndex], ShowWordCallBack);
|
}
|
|
}
|
|
|
|
private void Step9()
|
{
|
if (currentIndex == -1)
|
{
|
CommonDebugHelper.DebugError("第10步开始,购买水元素,第二步上阵");
|
TDAA_SDKManager.Ins.GuideStep(9);//埋点
|
|
currentIndex = 0;
|
needIndex = 2;
|
panel.SetGuideUI(false);
|
panel.Step9("", currentIndex, Step9_1);
|
}
|
else if (currentIndex == 1)
|
{
|
panel.Step9("", currentIndex, null);
|
}
|
}
|
|
/// <summary>
|
/// 分步9,购买1排5列的水元素
|
/// </summary>
|
private void Step9_1()
|
{
|
panel.Step9_1();
|
OnFinishOneStep();
|
}
|
|
private void CreateWaterLv1()
|
{
|
panel.CleanMask();
|
panel.StopShowDragPath(true);
|
EventCenter.Ins.BroadCast((int)KTGMGemClient.EventType.CreateSecondWave);//生成第二波小怪
|
}
|
|
private void SkillStep()
|
{
|
currentIndex = -1;
|
ChangeStep(GuideEnum.Step10);
|
}
|
|
private void DragStep()
|
{
|
currentIndex = -1;
|
ChangeStep(GuideEnum.Step10);
|
}
|
|
private void Step10()
|
{
|
isShowing = true;
|
if (currentIndex == -1)//初始化本步
|
{
|
CommonDebugHelper.DebugError("第11步开始,自己编的,需要修改,反正就是引导换位置");
|
TDAA_SDKManager.Ins.GuideStep(10);//埋点
|
|
currentIndex = 0;
|
needIndex = 2;
|
panel.SetGuideUI(true);
|
panel.StartShowWord(allGuideDic[currentStep][currentIndex], ShowWordCallBack);
|
|
}
|
else if (currentIndex == 1)
|
{
|
panel.StartShowWord(allGuideDic[currentStep][currentIndex], ShowWordCallBack);
|
//panel.Step10();
|
}
|
}
|
|
private void Step11()
|
{
|
if (currentIndex == -1)
|
{
|
CommonDebugHelper.DebugError("第12步开始,已经换了位置");
|
TDAA_SDKManager.Ins.GuideStep(11);//埋点
|
|
currentIndex = 0;
|
needIndex = 1;
|
|
panel.Step11Drag(currentIndex);
|
|
}
|
}
|
|
//开始拖拽
|
public void BeginDrag11_1()
|
{
|
panel.Step11Drag(1);
|
}
|
|
//结束推拽 没有合成,回到上一步
|
public void EndDrag11_1()
|
{
|
panel.Step11Drag(0);
|
}
|
|
public void DragDone()
|
{
|
GameConfig.CanDragTower = false;
|
CommonDebugHelper.Debug("结束拖拽");
|
panel.Step11Drag(2);
|
EventCenter.Ins.BroadCast((int)KTGMGemClient.EventType.RestartWave);
|
}
|
|
/// <summary>
|
/// 大波敌人来袭
|
/// </summary>
|
private void ShowWarningTips()
|
{
|
CommonDebugHelper.Debug("这里需要显示大波敌人来袭");
|
panel.Step11_End();
|
//结束后需要
|
//EventCenter.Ins.BroadCast((int)KTGMGemClient.EventType.CreateThirdWave);
|
}
|
|
private void CreateThirdWaveDone()
|
{
|
currentIndex = -1;
|
ChangeStep(GuideEnum.Step12);
|
}
|
|
// private void SkillRelease()
|
// {
|
// panel.SkillRelease();
|
// }
|
|
|
// private void SkillReleaseDone()
|
// {
|
// currentIndex = -1;
|
// ChangeStep(GuideEnum.Step12);
|
// }
|
|
private void Step12()
|
{
|
isShowing = true;
|
if (currentIndex == -1)//初始化本步
|
{
|
CommonDebugHelper.DebugError("第13步开始,对话框说明技能");
|
TDAA_SDKManager.Ins.GuideStep(12);//埋点
|
|
currentIndex = 0;
|
needIndex = 2;
|
panel.Step12();
|
|
panel.StartShowWord(allGuideDic[currentStep][currentIndex], ShowWordCallBack);
|
}
|
else
|
{
|
panel.StartShowWord(allGuideDic[currentStep][currentIndex], ShowWordCallBack);
|
}
|
}
|
|
private void Step13()
|
{
|
isShowing = true;
|
if (currentIndex == -1)//初始化本步
|
{
|
CommonDebugHelper.DebugError("第14步开始,引导释放技能");
|
TDAA_SDKManager.Ins.GuideStep(13);//埋点
|
|
currentIndex = 0;
|
needIndex = 2;
|
panel.Step13("释放技能", AfterSkillDone);
|
|
}
|
}
|
|
private void AfterSkillDone()
|
{
|
panel.CleanMask();
|
StartCoroutine(ChangeState());
|
}
|
|
IEnumerator ChangeState()
|
{
|
CommonDebugHelper.Debug("释放技能结束,这里等了1秒钟");
|
yield return new WaitForSeconds(1.0f);
|
currentIndex = -1;
|
ChangeStep(GuideEnum.Step14);
|
}
|
|
private void Step14()
|
{
|
isShowing = true;
|
if (currentIndex == -1)//初始化本步
|
{
|
CommonDebugHelper.DebugError("第15步开始,引导释放技能");
|
TDAA_SDKManager.Ins.GuideStep(14);//埋点
|
|
currentIndex = 0;
|
needIndex = 2;
|
panel.Step14();
|
panel.StartShowWord(allGuideDic[currentStep][currentIndex], ShowWordCallBack);
|
}
|
else
|
{
|
panel.StartShowWord(allGuideDic[currentStep][currentIndex], ShowWordCallBack);
|
}
|
}
|
|
private void Finish()
|
{
|
UnityEngine.Debug.Log("新手指导已经完成了");
|
TDAA_SDKManager.Ins.GuideStep(13);//埋点
|
|
GameConfig.CanOpenNewTower = true;
|
GameConfig.CanBuyNewTower = true;
|
panel.FinishGuide();
|
|
EventCenter.Ins.BroadCast((int)KTGMGemClient.EventType.GuideFinish);
|
PlayerPrefs.SetInt("GemBattleGuide", 1);
|
Destroy(gameObject);
|
}
|
|
#endregion
|
|
#region 点击事件
|
|
bool isShowing;//是否正在显示文字
|
|
/// <summary>
|
/// 文字显示结束
|
/// </summary>
|
public void ShowWordCallBack()
|
{
|
isShowing = false;
|
if (needIndex - currentIndex == 1)
|
{
|
currentIndex = needIndex;
|
}
|
//currentIndex++;
|
}
|
|
|
/// <summary>
|
/// 完成了当前步骤中的一个分步骤
|
/// </summary>
|
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
|
|
}
|