chenxin
2020-10-27 49f88e6493466a1723dd6b3967ff4c70f723db5d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
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.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.SkillReleaseDone, SkillReleaseDone);
 
 
    }
    public void Init(int step)
    {
        //Time.timeScale = 0;//游戏暂停,这样会导致协程停止了
        ChangeStep(GuideEnum.Step0);
        GameConfig.CanOpenNewTower = false;
        // switch (step)
        // {
        //     case 2:
        //     case 3:
        //         //生成两个火元素
        //         break;
        //     case 4:
        //         //生成1个2级火元素,标记上阵位置
 
        //         break;
        //     case 5:
        //         //生成2级火元素塔,第一关小怪出木元素小怪
 
        //         break;
 
        // }
        // ChangeStep((GuideEnum)(step + 1));
 
    }
 
    /// <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[] { 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] });
 
    }
 
 
    /// <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.Finish:
                    Finish();
                    break;
 
            }
 
        }
    }
 
 
    #region 步骤分解
 
    private void Step0()
    {
        isShowing = true;
        if (currentIndex == -1)//初始化本步
        {
            CommonDebugHelper.DebugError("第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)
        {
            CommonDebugHelper.DebugError("第2步开始");
 
            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步开始");
            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步开始");
 
            currentIndex = 0;
            needIndex = 2;
            panel.Step3(currentIndex, allGuideDic[currentStep][currentIndex]);
        }
    }
 
    //开始拖拽
    public void BeginDrag()
    {
        panel.Step3_2(allGuideDic[currentStep][1]);
    }
 
    //结束推拽 没有合成,回到上一步
    public void EndDrag()
    {
        panel.Step3(0, allGuideDic[currentStep][0]);
    }
 
    //合成了卡牌,开始下一步
    private void AddCard()
    {
        currentIndex = -1;
        ChangeStep(GuideEnum.Step4);
    }
 
    private void Step4()
    {
        if (currentIndex == -1)
        {
            CommonDebugHelper.DebugError("第5步开始");
 
            currentIndex = 0;
            panel.Step4(currentIndex, allGuideDic[currentStep][currentIndex]);
        }
    }
 
    //建造了塔,开始下一步
    private void CreateFireLv2()
    {
        currentIndex = -1;
        ChangeStep(GuideEnum.Step5);
    }
 
 
    private void Step5()
    {
        if (currentIndex == -1)
        {
            CommonDebugHelper.DebugError("第6步开始");
 
            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步开始");
 
            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 = 0;
        needIndex = 2;
        panel.SetGuideUI(true);
        isShowing = true;
        panel.StartShowWord(allGuideDic[currentStep][currentIndex], ShowWordCallBack);
    }
 
 
    private void Step7()
    {
        if (currentIndex == -1)
        {
            CommonDebugHelper.DebugError("第8步开始");
 
            currentIndex = 0;
            needIndex = 1;
            panel.SetGuideUI(false);
            GameConfig.CanOpenNewTower = true;
 
            //等待解锁塔
            panel.Step7(currentIndex, allGuideDic[currentStep][currentIndex]);
        }
    }
 
 
    private void GetOneTowerPos()
    {
        currentIndex = -1;
        ChangeStep(GuideEnum.Step8);
    }
 
 
 
    private void Step8()
    {
        isShowing = true;
        if (currentIndex == -1)//初始化本步
        {
            CommonDebugHelper.DebugError("第9步开始");
            GameConfig.CanOpenNewTower = false;
 
            currentIndex = 0;
            needIndex = 2;
            panel.Step8();
 
            panel.StartShowWord(allGuideDic[currentStep][currentIndex], ShowWordCallBack);
        }
        else if (currentIndex == 1)
        {
            panel.StartShowWord(allGuideDic[currentStep][currentIndex], ShowWordCallBack);
        }
 
    }
 
    private void Step9()
    {
        if (currentIndex == -1)
        {
            CommonDebugHelper.DebugError("第10步开始");
 
            currentIndex = 0;
            needIndex = 2;
            panel.SetGuideUI(false);
            panel.Step9(allGuideDic[currentStep][currentIndex], currentIndex, Step9_1);
        }
        else if (currentIndex == 1)
        {
            panel.Step9(allGuideDic[currentStep][currentIndex], currentIndex, null);
        }
    }
 
    /// <summary>
    /// 分步9,购买1排5列的水元素
    /// </summary>
    private void Step9_1()
    {
        panel.Step9_1();
        OnFinishOneStep();
    }
 
    private void CreateWaterLv1()
    {
        panel.CleanMask();
        EventCenter.Ins.BroadCast((int)KTGMGemClient.EventType.CreateSecondWave);//生成第二波小怪
    }
 
    private void SkillStep()
    {
        currentIndex = -1;
        ChangeStep(GuideEnum.Step10);
    }
 
    private void Step10()
    {
        isShowing = true;
        if (currentIndex == -1)//初始化本步
        {
            CommonDebugHelper.DebugError("第11步开始");
 
            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步开始");
 
            currentIndex = 0;
            needIndex = 1;
 
            panel.Step11(currentIndex, allGuideDic[currentStep][currentIndex]);
 
        }
    }
 
    //开始拖拽
    public void BeginDrag11_1()
    {
 
        panel.Step11(1, allGuideDic[currentStep][1]);
    }
 
    //结束推拽 没有合成,回到上一步
    public void EndDrag11_1()
    {
        panel.Step11(0, allGuideDic[currentStep][0]);
    }
 
 
    private void SkillReleaseDone()
    {
        currentIndex = -1;
        ChangeStep(GuideEnum.Step12);
    }
 
    private void Step12()
    {
        isShowing = true;
        if (currentIndex == -1)//初始化本步
        {
            CommonDebugHelper.DebugError("第13步开始");
 
            currentIndex = 0;
            needIndex = 3;
            panel.Step12();
 
            panel.StartShowWord(allGuideDic[currentStep][currentIndex], ShowWordCallBack);
 
        }
        else
        {
            panel.StartShowWord(allGuideDic[currentStep][currentIndex], ShowWordCallBack);
        }
    }
 
    private void Finish()
    {
        UnityEngine.Debug.Log("新手指导已经完成了");
        GameConfig.CanOpenNewTower = true;
        GameConfig.CanBuyNewTower = true;
 
        EventCenter.Ins.BroadCast((int)KTGMGemClient.EventType.GuideFinish);
        Destroy(gameObject);
        //gameObject.SetActive(false);
    }
 
    #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
 
}