wangguan
2020-12-10 d620049de0afa38688b7178d54b65e62ad2a61f0
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
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using DG.Tweening;
 
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;
 
    GameObject images;
    Transform btnImageTS;
 
    // Start is called before the first frame update
    void Awake()
    {
        bgBtn = transform.Find("BackGround").GetComponent<Button>();
        bgBtn.onClick.AddListener(OnClickBtn);
 
        images = transform.Find("Images").gameObject;
 
        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;
 
        btnImageTS = transform.Find("BtnImage");
 
        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()
    {
        images.SetActive(true);
        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()
    {
        images.SetActive(true);
 
        tmpPS = woodPS;
 
        tmpPS.SetActive(true);
 
        tmpObj = woodPanel;
 
        StartCoroutine(AfterPSPlay("单体攻击,狙击秒杀"));
 
    }
    private void Water()
    {
        images.SetActive(true);
 
        tmpPS = waterPS;
 
        tmpPS.SetActive(true);
 
        tmpObj = waterPanel;
        StartCoroutine(AfterPSPlay("群体减速,减速增伤"));
 
    }
 
 
    private void OnClickBtn()
    {
        if (callBack != null)
        {
            bgBtn.interactable=false;
            if (tmpPS != null) tmpPS.SetActive(false);
            //if (tmpObj != null) tmpObj.SetActive(false);
            images.SetActive(false);
            srImage.SetActive(false);
            infoImage.SetActive(false);
            PlayClosePs();
        }
    }
 
    Vector3 endScale = new Vector3(0.2f, 0.2f, 0.2f);
    private void PlayClosePs()
    {
        tmpObj.transform.Find("Images").gameObject.SetActive(false);
        tmpObj.transform.Find("Icon").GetComponent<Image>().enabled = true;
 
        //RectTransform ts = tmpObj.GetComponent<RectTransform>();
 
        tmpObj.transform.DOScale(endScale, 1.0f);
        // isRotate = true;
        // offect = 0;
        tmpObj.transform.DOMove(btnImageTS.transform.position, 1f).SetEase(Ease.OutQuad).OnComplete(Close);
        //ts.DOAnchorPos(btnImageRectTS.anchoredPosition, 1.0f).OnComplete(Close);
    }
 
    // bool isRotate = false;
    // float offect = 0;
    // /// <summary>
    // /// LateUpdate is called every frame, if the Behaviour is enabled.
    // /// It is called after all Update functions have been called.
    // /// </summary>
    // void LateUpdate()
    // {
    //     if (isRotate)
    //     {
    //         offect += Time.deltaTime;
    //         tmpObj.transform.localRotation = Quaternion.Euler(0, 0, offect * 1000);
    //     }
    // }
 
    private void Close()
    {
        //isRotate = false;
        tmpObj.gameObject.SetActive(false);
        gameObject.SetActive(false);
        callBack();
    }
}