add project files
This commit is contained in:
@@ -0,0 +1,127 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
|
||||
namespace OHM.UnityToolkit.UI
|
||||
{
|
||||
public class UIMenuBase : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
protected Animator animator;
|
||||
|
||||
[SerializeField]
|
||||
protected GameObject toEnableOnShow;
|
||||
|
||||
[SerializeField]
|
||||
protected bool hideOnBack;
|
||||
|
||||
public UIMenuEvent onShow = new UIMenuEvent();
|
||||
public UIMenuEvent onHide = new UIMenuEvent();
|
||||
public UIMenuInteractionEvent onInteraction = new UIMenuInteractionEvent();
|
||||
protected UIMenusController menuController;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
}
|
||||
|
||||
internal void SetMenuController(UIMenusController menuController)
|
||||
{
|
||||
this.menuController = menuController;
|
||||
}
|
||||
|
||||
public virtual void Show()
|
||||
{
|
||||
base.gameObject.SetActive(value: true);
|
||||
if (toEnableOnShow != null)
|
||||
{
|
||||
toEnableOnShow.SetActive(value: true);
|
||||
}
|
||||
ResetTrigger("Hide");
|
||||
int? trigger = GetAnimParameter("Show");
|
||||
if (trigger.HasValue)
|
||||
{
|
||||
animator.SetTrigger(trigger.Value);
|
||||
}
|
||||
onShow.Invoke(base.name);
|
||||
if (menuController != null)
|
||||
{
|
||||
menuController.PushPopup(this);
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void Hide()
|
||||
{
|
||||
onHide.Invoke(base.name);
|
||||
if (menuController != null)
|
||||
{
|
||||
menuController.PopPopup(this);
|
||||
}
|
||||
ResetTrigger("Show");
|
||||
int? trigger = GetAnimParameter("Hide");
|
||||
if (trigger.HasValue)
|
||||
{
|
||||
animator.SetTrigger(trigger.Value);
|
||||
}
|
||||
else
|
||||
{
|
||||
base.gameObject.SetActive(value: false);
|
||||
}
|
||||
}
|
||||
|
||||
public void DisableNow()
|
||||
{
|
||||
base.gameObject.SetActive(value: false);
|
||||
}
|
||||
|
||||
protected void ResetTrigger(string id)
|
||||
{
|
||||
int? trigger = GetAnimParameter(id);
|
||||
if (trigger.HasValue)
|
||||
{
|
||||
animator.ResetTrigger(trigger.Value);
|
||||
}
|
||||
}
|
||||
|
||||
protected Nullable<int> GetAnimParameter(string name)
|
||||
{
|
||||
if (animator != null && animator.gameObject.activeSelf)
|
||||
{
|
||||
AnimatorControllerParameter[] parameters = animator.parameters;
|
||||
for (int i = 0; i < parameters.Length; i++)
|
||||
{
|
||||
if (parameters[i].name == name)
|
||||
{
|
||||
return parameters[i].nameHash;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
protected void OnInteraction(string interactionId)
|
||||
{
|
||||
onInteraction.Invoke(base.name, interactionId);
|
||||
}
|
||||
|
||||
public virtual bool OnBack()
|
||||
{
|
||||
if (!hideOnBack)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
Hide();
|
||||
return true;
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class UIMenuEvent : UnityEvent<string>
|
||||
{
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class UIMenuInteractionEvent : UnityEvent<string, string>
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user