Assignment for RMIT Mixed Reality in 2020
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.

45 lines
1.6 KiB

  1. // UI Drop Zone|UI|80040
  2. namespace VRTK
  3. {
  4. using UnityEngine;
  5. using UnityEngine.EventSystems;
  6. /// <summary>
  7. /// Specifies a Unity UI Element as being a valid drop zone location for a UI Draggable element.
  8. /// </summary>
  9. /// <remarks>
  10. /// > It's appropriate to use a Panel UI element as a drop zone with a layout group applied so new children dropped into the drop zone automatically align.
  11. ///
  12. /// **Script Usage:**
  13. /// * Place the `VRTK_UIDropZone` script on the Unity UI element that is to become the drop zone.
  14. /// </remarks>
  15. /// <example>
  16. /// `VRTK/Examples/034_Controls_InteractingWithUnityUI` demonstrates a collection of UI Drop Zones.
  17. /// </example>
  18. [AddComponentMenu("VRTK/Scripts/UI/VRTK_UIDropZone")]
  19. public class VRTK_UIDropZone : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler
  20. {
  21. protected VRTK_UIDraggableItem droppableItem;
  22. public virtual void OnPointerEnter(PointerEventData eventData)
  23. {
  24. if (eventData.pointerDrag != null)
  25. {
  26. VRTK_UIDraggableItem dragItem = eventData.pointerDrag.GetComponent<VRTK_UIDraggableItem>();
  27. if (dragItem != null && dragItem.restrictToDropZone)
  28. {
  29. dragItem.validDropZone = gameObject;
  30. droppableItem = dragItem;
  31. }
  32. }
  33. }
  34. public virtual void OnPointerExit(PointerEventData eventData)
  35. {
  36. if (droppableItem != null)
  37. {
  38. droppableItem.validDropZone = null;
  39. }
  40. droppableItem = null;
  41. }
  42. }
  43. }