第一批重构,主要是物理迁移脚本和部分命名空间的调整
- 结构上迁移文件,将脚本分成 Base/Runtime/Presentation/Procedure/Editor 五大文件夹 - 调整 DataTable 和 Definition 下脚本的命名空间 - 依据 UI-5层架构设计规范 拆分原先的 UI 到 Runtime 和 Presentation 下
This commit is contained in:
@@ -0,0 +1,88 @@
|
||||
//------------------------------------------------------------
|
||||
// Game Framework
|
||||
// Copyright © 2013-2021 Jiang Yin. All rights reserved.
|
||||
// Homepage: https://gameframework.cn/
|
||||
// Feedback: mailto:ellan@gameframework.cn
|
||||
//------------------------------------------------------------
|
||||
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
namespace UI
|
||||
{
|
||||
public class CommonButton : MonoBehaviour, IPointerEnterHandler, IPointerDownHandler, IPointerExitHandler,
|
||||
IPointerUpHandler
|
||||
{
|
||||
private const float FadeTime = 0.3f;
|
||||
private const float OnHoverAlpha = 0.7f;
|
||||
private const float OnClickAlpha = 0.6f;
|
||||
|
||||
[SerializeField] private UnityEvent _onPointerEnterAction = new();
|
||||
|
||||
[SerializeField] private UnityEvent _onClickAction = new();
|
||||
|
||||
[SerializeField] private UnityEvent _onPointerExitAction = new();
|
||||
|
||||
[SerializeField] private bool _enableFade = true;
|
||||
|
||||
private CanvasGroup _canvasGroup = null;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
_canvasGroup = gameObject.GetOrAddComponent<CanvasGroup>();
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
_canvasGroup.alpha = 1f;
|
||||
}
|
||||
|
||||
public void OnPointerEnter(PointerEventData eventData)
|
||||
{
|
||||
if (eventData.button != PointerEventData.InputButton.Left)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
StopAllCoroutines();
|
||||
if (_enableFade)
|
||||
StartCoroutine(_canvasGroup.FadeToAlpha(OnHoverAlpha, FadeTime));
|
||||
_onPointerEnterAction.Invoke();
|
||||
}
|
||||
|
||||
public void OnPointerDown(PointerEventData eventData)
|
||||
{
|
||||
if (eventData.button != PointerEventData.InputButton.Left)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_canvasGroup.alpha = OnClickAlpha;
|
||||
_onClickAction.Invoke();
|
||||
}
|
||||
|
||||
public void OnPointerUp(PointerEventData eventData)
|
||||
{
|
||||
if (eventData.button != PointerEventData.InputButton.Left)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_canvasGroup.alpha = OnHoverAlpha;
|
||||
}
|
||||
|
||||
public void OnPointerExit(PointerEventData eventData)
|
||||
{
|
||||
if (eventData.button != PointerEventData.InputButton.Left)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
StopAllCoroutines();
|
||||
if (_enableFade)
|
||||
StartCoroutine(_canvasGroup.FadeToAlpha(1.0f, FadeTime));
|
||||
_onPointerExitAction.Invoke();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user