123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158 |
- using System;
- using Excel2Json;
- using Fort23.Core;
- using Fort23.Mono;
- using Fort23.UTool;
- using UnityEngine;
- using UnityEngine.EventSystems;
- using UnityEngine.UI;
- public class ULockWidget : MonoBehaviour, IPointerClickHandler
- {
- private int uLockId;
- public int uLockFunction;
- public Action ulockCallBack;
- private UnlockConfig _config;
- private bool _currULock;
- private Button mUIButton;
- private bool mIsUnlock;
- private void Awake()
- {
- if (uLockFunction == 0)
- return;
- StartULock();
- if (mUIButton == null) return;
- }
- public void SetuLockFunction(int id)
- {
- uLockFunction = id;
- if (uLockFunction == 0)
- {
- mIsUnlock = true;
- UnlockShow(mIsUnlock);
- return;
- }
- StartULock();
- if (mUIButton == null) return;
- }
- public void StartULock()
- {
- if (uLockId <= 0)
- {
- _config = ULockManager.Instance.GetULockConfig(uLockFunction);
- }
- else
- {
- _config = ULockManager.Instance.GetULockConfig(uLockId, false);
- }
- mUIButton = transform.GetComponentInChildren<Button>();
- EventManager.Instance.RemoveEventListener(CustomEventType.RefreshULock, RefreshULock);
- EventManager.Instance.AddEventListener(CustomEventType.RefreshULock, RefreshULock);
- ULock();
- }
- public void UnlockCallBack()
- {
- ulockCallBack?.Invoke();
- }
- private void OnDestroy()
- {
- EventManager.Instance.RemoveEventListener(CustomEventType.RefreshULock, RefreshULock);
- ulockCallBack = null;
- }
- private void RefreshULock(IEventData e)
- {
- ULock();
- }
- private void ULock()
- {
- if (_config.ID == 0)
- {
- mIsUnlock = true;
- return;
- }
- mIsUnlock = ULockManager.Instance.IsULock(_config);
- UnlockShow(mIsUnlock);
- }
- /// <summary>
- /// 解锁的表现逻辑
- /// </summary>
- /// <param name="isUnlock">是否解锁</param>
- private void UnlockShow(bool isUnlock)
- {
- mIsUnlock = isUnlock;
- if (gameObject == null) return;
- Text[] texts = gameObject.GetComponentsInChildren<Text>();
- if (!isUnlock)
- {
- if (_config.lockType == 1)
- {
- gameObject.SetActive(false);
- }
- else if (_config.lockType == 2)
- {
- if (mUIButton != null)
- {
- mUIButton.enabled = false;
- }
- else
- {
- LogTool.Log("没有碰撞区域" + gameObject.name);
- }
- gameObject.transform.Gray(true);
- }
- _currULock = true;
- }
- else
- {
- if (_config.lockType == 1)
- {
- gameObject.SetActive(true);
- }
- else if (_config.lockType == 2)
- {
- if (mUIButton != null)
- {
- mUIButton.enabled = true;
- }
- //TODO 恢复正常颜色
- gameObject.transform.RecoverColor();
- }
- UnlockCallBack();
- EventManager.Instance.RemoveEventListener(CustomEventType.RefreshULock, RefreshULock);
- }
- }
- public void OnPointerClick(PointerEventData eventData)
- {
- LogTool.Log("点击~");
- if (!mIsUnlock)
- {
- TipMessagePanel.OpenTipMessagePanel(ULockManager.Instance.ShowUnlockTips(_config.ID), Vector2.zero);
- }
- }
- }
|