wangguan
2020-12-02 6bc45c691891dac88bece3483fb6f3cf2d7a00a4
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
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
 
public enum GuideBoxType
{
    None,
    //Box,
    Fire,
    Wood,
    Water
}
public class GuideBox : MonoBehaviour
{
    Button bgBtn;//背景按钮
    private GuideBoxType myType;
 
    GameObject srImage;
    GameObject infoImage;
 
    GameObject firePS;
    GameObject woodPS;
    GameObject waterPS;
 
    GameObject firePanel;
    GameObject woodPanel;
    GameObject waterPanel;
 
 
    GameObject tmpPS = null;
    GameObject tmpObj = null;
 
    Text infoTxt;
 
    Action callBack;
 
    // Start is called before the first frame update
    void Awake()
    {
        bgBtn = transform.Find("BackGround").GetComponent<Button>();
        bgBtn.onClick.AddListener(OnClickBtn);
 
        srImage = transform.Find("SRImage").gameObject;
 
        firePS = transform.Find("Effect_UI_ChouKa_Huo").gameObject;
        woodPS = transform.Find("Effect_UI_ChouKa_Mu").gameObject;
        waterPS = transform.Find("Effect_UI_ChouKa_Shui").gameObject;
 
        firePanel = transform.Find("Fire").gameObject;
        woodPanel = transform.Find("Wood").gameObject;
        waterPanel = transform.Find("Water").gameObject;
 
 
        infoImage = transform.Find("InfoTxt").gameObject;
        infoTxt = transform.Find("InfoTxt/Text").GetComponent<Text>();
 
        myType = GuideBoxType.None;
 
        gameObject.SetActive(false);
    }
 
    public void ChangeType(GuideBoxType type, Action ac)
    {
        if (!gameObject.activeSelf)
        {
            gameObject.SetActive(true);
        }
 
        callBack = ac;
        srImage.SetActive(false);
        infoImage.SetActive(false);
        if (type != myType)
        {
            myType = type;
 
            bgBtn.interactable = false;
            if (myType == GuideBoxType.Fire)
            {
                Fire();
            }
            else if (myType == GuideBoxType.Wood)
            {
                Wood();
            }
            else if (myType == GuideBoxType.Water)
            {
                Water();
            }
        }
    }
 
    private void Fire()
    {
        tmpPS = firePS;
        tmpPS.SetActive(true);
        //tmpPS.Play();
        tmpObj = firePanel;
        StartCoroutine(AfterPSPlay("群体攻击,充能爆发"));
    }
 
    IEnumerator AfterPSPlay(string info)
    {
        yield return new WaitForSeconds(1.2f);
        bgBtn.interactable = true;
        srImage.SetActive(true);
        infoImage.SetActive(true);
        infoTxt.text = info;
        tmpObj.SetActive(true);
    }
    private void Wood()
    {
        tmpPS = woodPS;
 
        tmpPS.SetActive(true);
 
        tmpObj = woodPanel;
 
        StartCoroutine(AfterPSPlay("单体攻击,狙击秒杀"));
 
    }
    private void Water()
    {
        tmpPS = waterPS;
 
        tmpPS.SetActive(true);
 
        tmpObj = waterPanel;
        StartCoroutine(AfterPSPlay("群体减速,减速增伤"));
 
    }
 
 
    private void OnClickBtn()
    {
        if (callBack != null)
        {
            if (tmpPS != null) tmpPS.SetActive(false);
            if (tmpObj != null) tmpObj.SetActive(false);
            gameObject.SetActive(false);
            callBack();
        }
    }
}