NxrDragableItem.cs 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. using UnityEngine;
  2. namespace Nxr.Internal
  3. {
  4. /// <summary>
  5. ///
  6. /// </summary>
  7. public class NxrDragableItem : MonoBehaviour
  8. {
  9. public bool IsDraging { set; get; }
  10. Transform mTransform;
  11. Collider mCollider;
  12. // Start is called before the first frame update
  13. void Start()
  14. {
  15. mCollider = GetComponent<Collider>();
  16. mTransform = transform;
  17. IsDraging = false;
  18. }
  19. /// <summary>
  20. /// On begin drag game object
  21. /// </summary>
  22. /// <param name="parent"></param>
  23. public void OnBeginDrag(Transform parent)
  24. {
  25. mTransform.SetParent(parent);
  26. mCollider.enabled = false;
  27. IsDraging = true;
  28. }
  29. /// <summary>
  30. /// On end drag game object
  31. /// </summary>
  32. /// <param name="parent"></param>
  33. public void OnEndDrag(Transform parent)
  34. {
  35. mTransform.SetParent(parent);
  36. mCollider.enabled = true;
  37. IsDraging = false;
  38. }
  39. }
  40. }