PlaneDetectionDemo.cs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. using System.Collections.Generic;
  2. using UnityEngine;
  3. using UnityEngine.UI;
  4. using UnityEngine.SceneManagement;
  5. using EZXR.Glass.SixDof;
  6. using EZXR.Glass.Plane;
  7. public class PlaneDetectionDemo : BaseGlassSDKDemo
  8. {
  9. Dictionary<ulong, GameObject> m_allPlanes = new Dictionary<ulong, GameObject>();
  10. // Update is called once per frame
  11. new void Update()
  12. {
  13. Dictionary<ulong, PlaneDetectionManager.PlaneInfo> planes = PlaneDetectionManager.Instance.GetPlanes();
  14. foreach (KeyValuePair<ulong, PlaneDetectionManager.PlaneInfo> kvp in planes)
  15. {
  16. ulong key = kvp.Key;
  17. PlaneDetectionManager.PlaneInfo value = kvp.Value;
  18. if (m_allPlanes.ContainsKey(key))
  19. {
  20. GameObject planeObj = m_allPlanes[key];
  21. planeObj.transform.position = value.position;
  22. planeObj.transform.rotation = value.rotation;
  23. planeObj.transform.localScale = value.scale * 0.1f;
  24. }
  25. else
  26. {
  27. CreatePlane(key, value);
  28. }
  29. }
  30. base.Update();
  31. }
  32. void CreatePlane(ulong key, PlaneDetectionManager.PlaneInfo planeObj)
  33. {
  34. GameObject plane = GameObject.CreatePrimitive(PrimitiveType.Plane);
  35. plane.transform.position = planeObj.position;
  36. plane.transform.rotation = planeObj.rotation;
  37. plane.transform.localScale = planeObj.scale * 0.1f;
  38. Material material = Resources.Load<Material>("Shader/Wireframe/Examples/Materials/Wireframe-Transparent");
  39. plane.GetComponent<MeshRenderer>().material = material;
  40. m_allPlanes.Add(key, plane);
  41. }
  42. }