DNP_UIArea.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. using UnityEngine.EventSystems;
  6. namespace DamageNumbersPro.Demo
  7. {
  8. public class DNP_UIArea : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler
  9. {
  10. public static DNP_UIArea currentArea;
  11. public DNP_UIArea otherArea;
  12. public bool noSpawnArea = false;
  13. public bool breakCube = false;
  14. RectTransform rectTransform;
  15. void Start()
  16. {
  17. rectTransform = GetComponent<RectTransform>();
  18. }
  19. public void OnPointerEnter(PointerEventData eventData)
  20. {
  21. currentArea = this;
  22. }
  23. public void OnPointerExit(PointerEventData eventData)
  24. {
  25. if(currentArea == this)
  26. {
  27. currentArea = null;
  28. }
  29. }
  30. public static RectTransform GetRect()
  31. {
  32. return currentArea != null ? (currentArea.otherArea == null ? currentArea.rectTransform : currentArea.otherArea.rectTransform) : null;
  33. }
  34. public static bool CanSpawn()
  35. {
  36. return currentArea == null || currentArea.noSpawnArea == false;
  37. }
  38. public static void OnSpawn()
  39. {
  40. if(currentArea != null && currentArea.breakCube)
  41. {
  42. DNP_FallingCube cube = currentArea.GetComponent<DNP_FallingCube>();
  43. cube.Break();
  44. }
  45. }
  46. }
  47. }