少年修仙传客户端代码仓库
client_linchunjie
2019-04-17 11997ece0dc4980eba3dd8889d37adb8376e14cb
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
//--------------------------------------------------------
//    [Author]:           第二世界
//    [  Date ]:           Friday, September 29, 2017
//--------------------------------------------------------
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
 
using System;
using UnityEngine.EventSystems;
namespace Snxxz.UI
{
    public class UIFuncOpen : MonoBehaviour, IPointerClickHandler
    {
        [SerializeField] int funcOpenKey;
        [SerializeField] GameObject LockImg;
        [SerializeField] bool active = true;
        public int id { get { return funcOpenKey; } }
        private Button funcBtn;
        private void Awake()
        {
            funcBtn = GetComponent<Button>();
 
            FuncOpen.Instance.OnFuncStateChangeEvent += OnFuncStateChangeEvent;
#if UNITY_EDITOR
            FuncOpen.FuncOpenModeChangeEvent += FuncOpenModeChangeEvent;
#endif
        }
#if UNITY_EDITOR
        private void FuncOpenModeChangeEvent()
        {
            SetState();
        }
#endif
 
        public void OnPointerClick(PointerEventData eventData)
        {
            if (!FuncOpen.Instance.IsFuncOpen(funcOpenKey))
            {
                FuncOpen.Instance.ProcessorFuncErrorTip(funcOpenKey);
                return;
            }
        }
 
        private void OnEnable()
        {
            SetState();
        }
 
        private void OnFuncStateChangeEvent(int func)
        {
            if (funcOpenKey == func)
            {
                SetState();
            }
        }
 
        private void OnDestroy()
        {
            FuncOpen.Instance.OnFuncStateChangeEvent -= OnFuncStateChangeEvent;
        }
        private void SetState()
        {
            var IsOpen = FuncOpen.Instance.IsFuncOpen(funcOpenKey);
            var _funcOpenCfg = FuncOpenLVConfig.Get(funcOpenKey);
 
            funcBtn.interactable = IsOpen;
            if (LockImg != null)
            {
                LockImg.SetActive(!IsOpen);
            }
#if UNITY_EDITOR
            if (!FuncOpen.development)
            {
                if (_funcOpenCfg != null && _funcOpenCfg.open == 0)
                {
                    gameObject.SetActive(false);
                    return;
                }
            }
#else
            if (_funcOpenCfg != null && _funcOpenCfg.open == 0)
            {
                gameObject.SetActive(false);
                return;
            }
#endif
            if (!active)
            {
                gameObject.SetActive(IsOpen);
            }
            else
            {
                if (!gameObject.activeSelf)
                {
                    gameObject.SetActive(true);
                }
            }
        }
    }
}