You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

57 lines
1.2 KiB

  1. using System;
  2. using System.Diagnostics;
  3. using SUISS.Core;
  4. using SUISS.Scheduling;
  5. using UnityEngine;
  6. namespace SUISSEngine
  7. {
  8. public class Clickable : MonoBehaviour
  9. {
  10. public static Clickable Instance(GameObject target)
  11. {
  12. if (target == null)
  13. {
  14. string arg = string.Empty;
  15. try
  16. {
  17. arg = target.name;
  18. }
  19. catch (Exception)
  20. {
  21. }
  22. UnityEngine.Debug.LogError(string.Format("Clickable.Instance called on null GameObject ({0}).", arg));
  23. target = new GameObject();
  24. SingletonMonobehaviour<Scheduler>.Instance.ExecuteNextFrame(target, delegate()
  25. {
  26. UnityEngine.Object.Destroy(target);
  27. });
  28. }
  29. Clickable clickable = target.GetComponent<Clickable>();
  30. if (clickable == null)
  31. {
  32. clickable = target.AddComponent<Clickable>();
  33. }
  34. return clickable;
  35. }
  36. public static Clickable Instance(Component target)
  37. {
  38. return Clickable.Instance(target.gameObject);
  39. }
  40. //[DebuggerBrowsable(DebuggerBrowsableState.Never)]
  41. public event Clickable.ClickAction OnClickEvent;
  42. public void OnClick(GameObject target)
  43. {
  44. if (this.OnClickEvent != null)
  45. {
  46. this.OnClickEvent(target);
  47. }
  48. }
  49. public delegate void ClickAction(GameObject target);
  50. }
  51. }