| //-------------------------------------------------------- | 
| //    [Author]:           玩个游戏 | 
| //    [  Date ]:           Friday, September 29, 2017 | 
| //-------------------------------------------------------- | 
| using UnityEngine; | 
| using System.Collections; | 
| using UnityEngine.UI; | 
| using System; | 
| using UnityEngine.EventSystems; | 
|   | 
|     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; | 
|         } | 
|   | 
|         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); | 
|   | 
|             if (_funcOpenCfg == null) | 
|             { | 
|                 IsOpen = true; | 
|                 active = true; | 
|             } | 
|   | 
|             if (funcBtn != null) | 
|             { | 
|                 funcBtn.interactable = IsOpen; | 
|             } | 
|              | 
|             | 
|             if (LockImg != null) | 
|             { | 
|                 LockImg.SetActive(!IsOpen); | 
|             } | 
|   | 
|             if (_funcOpenCfg != null && _funcOpenCfg.open == 0) | 
|             { | 
|                 gameObject.SetActive(false); | 
|                 return; | 
|             } | 
|   | 
|             if (!active) | 
|             { | 
|                 gameObject.SetActive(IsOpen); | 
|             } | 
|             else | 
|             { | 
|                 if (!gameObject.activeSelf) | 
|                 { | 
|                     gameObject.SetActive(true); | 
|                 } | 
|             } | 
|         } | 
|     } |