少年修仙传客户端代码仓库
leonard Wu
2018-08-09 1875ff6edde61f76e0f0cbe247244b04318fcd80
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
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TableConfig;
namespace Snxxz.UI
{
    public class DungeonInspireBehaviour : MonoBehaviour
    {
        [SerializeField] Button m_InspireBtn;
        [SerializeField] RotationTween m_RotTween;
        [SerializeField] Text m_InspireProgress;
        [SerializeField, Header("晃动次数")]
        int m_WaggleCnt = 6;
        [SerializeField, Header("间隔时间")]
        float m_IntervalTime = 3.0f;
 
        float m_Time;
 
        DungeonModel m_Model;
        DungeonModel model { get { return m_Model ?? (m_Model = ModelCenter.Instance.GetModel<DungeonModel>()); } }
 
        bool m_Waggle = false;
 
        DungeonInspireConfig m_CoinConfig;
 
        private void Awake()
        {
            m_InspireBtn.onClick.AddListener(OnInspireBtn);
        }
 
        private void OnEnable()
        {
            ResetTween();
            model.dungeonInspireLvEvent += UpdateDugeonInspireLv;
            UpdateDugeonInspireLv();
            var _list = model.GetDungeonInspire(PlayerDatas.Instance.baseData.MapID);
            m_CoinConfig = null;
            if (_list == null)
            {
                return;
            }
            for (int i = 0; i < _list.Count; i++)
            {
                if (_list[i].InspireType == 1)
                {
                    m_CoinConfig = _list[i];
                    break;
                }
            }
        }
 
        private void UpdateDugeonInspireLv()
        {
            var mapId = model.GetDungeonDataIdByMapId(PlayerDatas.Instance.baseData.MapID);
            var lv = model.dungeonJadeInspireCount + model.dungeonCoinInspireCount;
            m_Waggle = m_CoinConfig != null && model.dungeonCoinInspireCount < m_CoinConfig.InspireCount
                && lv < model.GetDungeonInspireMaxCnt(mapId);
            if (m_InspireProgress != null)
            {
                m_InspireProgress.gameObject.SetActive(PlayerDatas.Instance.baseData.MapID == DemonJarModel.DEMONJAR_MAPID);
                m_InspireProgress.text = StringUtility.Contact(lv * 10, "%");
            }
            if (!m_Waggle)
            {
                ResetTween();
            }
        }
 
        private void LateUpdate()
        {
            if (m_Waggle)
            {
                m_Time += Time.deltaTime;
                if (m_RotTween.isActiveAndEnabled)
                {
                    if (m_Time > m_RotTween.duration * m_WaggleCnt)
                    {
                        ResetTween();
                    }
                }
                else
                {
                    if (m_Time > m_IntervalTime)
                    {
                        m_Time = 0;
                        m_RotTween.enabled = true;
                    }
                }
            }
        }
 
        private void ResetTween()
        {
            m_Time = 0;
            m_RotTween.enabled = false;
            m_InspireBtn.transform.localEulerAngles = Vector3.zero;
        }
 
        private void OnInspireBtn()
        {
            if ((model.dungeonCoinInspireCount + model.dungeonJadeInspireCount) >= model.GetDungeonInspireMaxCnt(PlayerDatas.Instance.baseData.MapID))
            {
                SysNotifyMgr.Instance.ShowTip("Xjmj_InspireMaxLevel");
                return;
            }
            WindowCenter.Instance.Open<DungeonInspireWin>();
        }
 
        private void OnDisable()
        {
            model.dungeonInspireLvEvent -= UpdateDugeonInspireLv;
        }
    }
}