VRCommandMenuDrawManager.cs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. using System;
  2. using UnityEngine;
  3. public class VRCommandMenuDrawManager : VRWfChangeCanvas
  4. {
  5. public override void ChangeDeviceMode(GameMain.VRDeviceType devideType)
  6. {
  7. this.isVisible = true;
  8. this.ChangeDrawMode(devideType != GameMain.VRDeviceType.NON);
  9. if (devideType == GameMain.VRDeviceType.RIFT_TOUCH || devideType == GameMain.VRDeviceType.VIVE)
  10. {
  11. this.updateWorldPosition = false;
  12. }
  13. else
  14. {
  15. this.updateWorldPosition = true;
  16. }
  17. }
  18. public override void ChangeDrawMode(bool worldMode)
  19. {
  20. if (worldMode)
  21. {
  22. base.renderMode = RenderMode.WorldSpace;
  23. this.rectTransform.localPosition = Vector3.zero;
  24. this.rectTransform.localScale = new Vector3(0.0006f, 0.0006f, 1f);
  25. this.rectTransform.localRotation = Quaternion.identity;
  26. this.commandImageTransform.anchorMin = new Vector2(0.5f, 0.5f);
  27. this.commandImageTransform.anchorMax = new Vector2(0.5f, 0.5f);
  28. this.commandImageTransform.pivot = new Vector2(0.5f, 0.5f);
  29. this.commandImageTransform.anchoredPosition = new Vector2(-123.7f, 149.9f);
  30. this.backupPosition = this.commandImageTransform.anchoredPosition;
  31. }
  32. else
  33. {
  34. base.renderMode = RenderMode.ScreenSpaceOverlay;
  35. this.rectTransform.localScale = Vector3.one;
  36. this.rectTransform.localRotation = Quaternion.identity;
  37. this.commandImageTransform.anchorMin = Vector2.zero;
  38. this.commandImageTransform.anchorMax = Vector2.zero;
  39. this.commandImageTransform.pivot = new Vector2(0.5f, 0.5f);
  40. this.commandImageTransform.anchoredPosition = new Vector2(233f, 101f);
  41. this.backupPosition = this.commandImageTransform.anchoredPosition;
  42. }
  43. }
  44. protected override void FixedUpdate()
  45. {
  46. base.FixedUpdate();
  47. if (!this.updateWorldPosition)
  48. {
  49. this.commandImageTransform.anchoredPosition = this.backupPosition + this.imagePositionOffset;
  50. this.rectTransform.localRotation = Quaternion.Euler(this.rotationOffset);
  51. }
  52. }
  53. [SerializeField]
  54. public RectTransform commandImageTransform;
  55. public Vector2 imagePositionOffset;
  56. public Vector3 rotationOffset;
  57. private Vector2 backupPosition;
  58. }