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.

57 lines
2.2 KiB

  1. namespace VRTK.Examples
  2. {
  3. using UnityEngine;
  4. public class SnapDropZoneGroup_Switcher : MonoBehaviour
  5. {
  6. private VRTK_SnapDropZone cubeZone;
  7. private VRTK_SnapDropZone sphereZone;
  8. private void Start()
  9. {
  10. cubeZone = transform.Find("Cube_SnapDropZone").gameObject.GetComponent<VRTK_SnapDropZone>();
  11. sphereZone = transform.Find("Sphere_SnapDropZone").GetComponent<VRTK_SnapDropZone>();
  12. cubeZone.ObjectEnteredSnapDropZone += new SnapDropZoneEventHandler(DoCubeZoneSnapped);
  13. cubeZone.ObjectSnappedToDropZone += new SnapDropZoneEventHandler(DoCubeZoneSnapped);
  14. cubeZone.ObjectExitedSnapDropZone += new SnapDropZoneEventHandler(DoCubeZoneUnsnapped);
  15. cubeZone.ObjectUnsnappedFromDropZone += new SnapDropZoneEventHandler(DoCubeZoneUnsnapped);
  16. sphereZone.ObjectEnteredSnapDropZone += new SnapDropZoneEventHandler(DoSphereZoneSnapped);
  17. sphereZone.ObjectSnappedToDropZone += new SnapDropZoneEventHandler(DoSphereZoneSnapped);
  18. sphereZone.ObjectExitedSnapDropZone += new SnapDropZoneEventHandler(DoSphereZoneUnsnapped);
  19. sphereZone.ObjectUnsnappedFromDropZone += new SnapDropZoneEventHandler(DoSphereZoneUnsnapped);
  20. }
  21. private void DoCubeZoneSnapped(object sender, SnapDropZoneEventArgs e)
  22. {
  23. if (sphereZone.GetCurrentSnappedObject() == null)
  24. {
  25. sphereZone.gameObject.SetActive(false);
  26. }
  27. }
  28. private void DoCubeZoneUnsnapped(object sender, SnapDropZoneEventArgs e)
  29. {
  30. if (cubeZone.GetCurrentSnappedObject() == null)
  31. {
  32. sphereZone.gameObject.SetActive(true);
  33. }
  34. }
  35. private void DoSphereZoneSnapped(object sender, SnapDropZoneEventArgs e)
  36. {
  37. if (cubeZone.GetCurrentSnappedObject() == null)
  38. {
  39. cubeZone.gameObject.SetActive(false);
  40. }
  41. }
  42. private void DoSphereZoneUnsnapped(object sender, SnapDropZoneEventArgs e)
  43. {
  44. if (sphereZone.GetCurrentSnappedObject() == null)
  45. {
  46. cubeZone.gameObject.SetActive(true);
  47. }
  48. }
  49. }
  50. }