123456789101112131415161718192021222324252627282930313233343536 |
- using System;
- using UnityEngine;
- public static class GameObjectExpand
- {
- public static ClickButton OnClick(this GameObject obj, Action callBack)
- {
- if (obj == null) return null;
- ClickEvent clickEvent = GetClickEvent(obj);
- ClickButton button = clickEvent.OnRegister<ClickButton>(callBack);
- return button;
- }
- public static DoubleClickButton OnDoubleClick(this GameObject obj, Action callBack)
- {
- if (obj == null) return null;
- ClickEvent clickEvent = GetClickEvent(obj);
- DoubleClickButton button = clickEvent.OnRegister<DoubleClickButton>(callBack);
- return button;
- }
- public static PressButton OnPress(this GameObject obj, Action callBack)
- {
- if (obj == null) return null;
- ClickEvent clickEvent = GetClickEvent(obj);
- PressButton button = clickEvent.OnRegister<PressButton>(callBack);
- return button;
- }
- static ClickEvent GetClickEvent(GameObject obj)
- {
- ClickEvent clickEvent = obj.GetComponent<ClickEvent>();
- if (clickEvent == null) clickEvent = obj.AddComponent<ClickEvent>();
- return clickEvent;
- }
- }
|