1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.Events;
- namespace WS
- {
-
- public enum PointerEventType
- {
-
- OnDown,
-
- OnUp,
-
- OnEnter,
-
- OnExit
- }
-
- public class PointerEventComponent : WSComponent
- {
-
- private Dictionary<GameObject, PointerEventMono> AllPointerEvent = new Dictionary<GameObject, PointerEventMono>();
-
-
-
-
- public void AddPointerEvent(GameObject ui, PointerEventType type, UnityAction callback)
- {
- if (!AllPointerEvent.ContainsKey(ui))
- {
- PointerEventMono component = ui.AddComponent<PointerEventMono>();
- AllPointerEvent.Add(ui, component);
- }
- PointerEventMono pointer = AllPointerEvent[ui];
- switch (type)
- {
- case PointerEventType.OnDown:
- pointer.OnDown = callback;
- break;
- case PointerEventType.OnUp:
- pointer.OnUp = callback;
- break;
- case PointerEventType.OnEnter:
- pointer.OnEnter = callback;
- break;
- case PointerEventType.OnExit:
- pointer.OnExit = callback;
- break;
- }
- }
- public override void Dispose()
- {
- base.Dispose();
- foreach (var item in AllPointerEvent)
- {
- UnityEngine.Object.Destroy(item.Value);
- }
- AllPointerEvent.Clear();
- }
- }
- }
|