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(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(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(callBack); return button; } static ClickEvent GetClickEvent(GameObject obj) { ClickEvent clickEvent = obj.GetComponent(); if (clickEvent == null) clickEvent = obj.AddComponent(); return clickEvent; } }