PICOCompositeLayerEditor.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. /*******************************************************************************
  2. Copyright © 2015-2022 PICO Technology Co., Ltd.All rights reserved.
  3. NOTICE:All information contained herein is, and remains the property of
  4. PICO Technology Co., Ltd. The intellectual and technical concepts
  5. contained hererin are proprietary to PICO Technology Co., Ltd. and may be
  6. covered by patents, patents in process, and are protected by trade secret or
  7. copyright law. Dissemination of this information or reproduction of this
  8. material is strictly forbidden unless prior written permission is obtained from
  9. PICO Technology Co., Ltd.
  10. *******************************************************************************/
  11. using UnityEditor;
  12. using UnityEngine;
  13. namespace Unity.XR.OpenXR.Features.PICOSupport
  14. {
  15. [CanEditMultipleObjects]
  16. [CustomEditor(typeof(CompositeLayerFeature))]
  17. public class PICOCompositeLayerEditor : UnityEditor.Editor
  18. {
  19. public override void OnInspectorGUI()
  20. {
  21. var guiContent = new GUIContent();
  22. foreach (CompositeLayerFeature overlayTarget in targets)
  23. {
  24. EditorGUILayout.LabelField("Overlay Settings", EditorStyles.boldLabel);
  25. EditorGUILayout.BeginVertical("frameBox");
  26. guiContent.text = "Type";
  27. overlayTarget.overlayType = (CompositeLayerFeature.OverlayType)EditorGUILayout.EnumPopup(guiContent, overlayTarget.overlayType);
  28. guiContent.text = "Shape";
  29. overlayTarget.overlayShape = (CompositeLayerFeature.OverlayShape)EditorGUILayout.EnumPopup(guiContent, overlayTarget.overlayShape);
  30. guiContent.text = "Depth";
  31. overlayTarget.layerDepth = EditorGUILayout.IntField(guiContent, overlayTarget.layerDepth);
  32. EditorGUILayout.EndVertical();
  33. EditorGUILayout.Separator();
  34. EditorGUILayout.LabelField("Overlay Textures", EditorStyles.boldLabel);
  35. guiContent.text = "Texture Type";
  36. overlayTarget.textureType = (CompositeLayerFeature.TextureType)EditorGUILayout.EnumPopup(guiContent, overlayTarget.textureType);
  37. EditorGUILayout.Separator();
  38. if (overlayTarget.textureType == CompositeLayerFeature.TextureType.StaticTexture)
  39. {
  40. overlayTarget.isDynamic = false;
  41. }
  42. else if (overlayTarget.textureType == CompositeLayerFeature.TextureType.DynamicTexture)
  43. {
  44. overlayTarget.isDynamic = true;
  45. }
  46. else
  47. {
  48. overlayTarget.isDynamic = false;
  49. }
  50. EditorGUILayout.LabelField("Texture");
  51. EditorGUILayout.BeginVertical("frameBox");
  52. var labelControlRect = EditorGUILayout.GetControlRect();
  53. EditorGUI.LabelField(new Rect(labelControlRect.x, labelControlRect.y, labelControlRect.width / 2, labelControlRect.height), new GUIContent("Left", "Texture used for the left eye"));
  54. EditorGUI.LabelField(new Rect(labelControlRect.x + labelControlRect.width / 2, labelControlRect.y, labelControlRect.width / 2, labelControlRect.height), new GUIContent("Right", "Texture used for the right eye"));
  55. var textureControlRect = EditorGUILayout.GetControlRect(GUILayout.Height(64));
  56. overlayTarget.layerTextures[0] = (Texture)EditorGUI.ObjectField(new Rect(textureControlRect.x, textureControlRect.y, 64, textureControlRect.height), overlayTarget.layerTextures[0], typeof(Texture), false);
  57. overlayTarget.layerTextures[1] = (Texture)EditorGUI.ObjectField(new Rect(textureControlRect.x + textureControlRect.width / 2, textureControlRect.y, 64, textureControlRect.height), overlayTarget.layerTextures[1] != null ? overlayTarget.layerTextures[1] : overlayTarget.layerTextures[0], typeof(Texture), false);
  58. EditorGUILayout.EndVertical();
  59. EditorGUILayout.Separator();
  60. if (overlayTarget.overlayShape == CompositeLayerFeature.OverlayShape.Equirect)
  61. {
  62. guiContent.text = "Radius";
  63. overlayTarget.radius = EditorGUILayout.FloatField(guiContent, Mathf.Abs(overlayTarget.radius));
  64. }
  65. if (overlayTarget.overlayShape == CompositeLayerFeature.OverlayShape.Quad || overlayTarget.overlayShape == CompositeLayerFeature.OverlayShape.Cylinder || overlayTarget.overlayShape == CompositeLayerFeature.OverlayShape.Equirect)
  66. {
  67. guiContent.text = "Texture Rects";
  68. overlayTarget.useImageRect = EditorGUILayout.Toggle(guiContent, overlayTarget.useImageRect);
  69. if (overlayTarget.useImageRect)
  70. {
  71. guiContent.text = "Source Rects";
  72. overlayTarget.textureRect = (CompositeLayerFeature.TextureRect)EditorGUILayout.EnumPopup(guiContent, overlayTarget.textureRect);
  73. if (overlayTarget.textureRect == CompositeLayerFeature.TextureRect.Custom)
  74. {
  75. EditorGUILayout.BeginVertical("frameBox");
  76. EditorGUILayout.BeginHorizontal();
  77. EditorGUILayout.LabelField("Left Rect");
  78. EditorGUILayout.LabelField("Right Rect");
  79. EditorGUILayout.EndHorizontal();
  80. EditorGUILayout.BeginHorizontal();
  81. overlayTarget.srcRectLeft = ClampRect(EditorGUILayout.RectField(overlayTarget.srcRectLeft));
  82. EditorGUILayout.Space(15);
  83. guiContent.text = "Right";
  84. overlayTarget.srcRectRight = ClampRect(EditorGUILayout.RectField(overlayTarget.srcRectRight));
  85. EditorGUILayout.EndHorizontal();
  86. EditorGUILayout.EndVertical();
  87. EditorGUILayout.Space();
  88. }
  89. else if (overlayTarget.textureRect == CompositeLayerFeature.TextureRect.MonoScopic)
  90. {
  91. overlayTarget.srcRectLeft = new Rect(0, 0, 1, 1);
  92. overlayTarget.srcRectRight = new Rect(0, 0, 1, 1);
  93. }
  94. else if (overlayTarget.textureRect == CompositeLayerFeature.TextureRect.StereoScopic)
  95. {
  96. overlayTarget.srcRectLeft = new Rect(0, 0, 0.5f, 1);
  97. overlayTarget.srcRectRight = new Rect(0.5f, 0, 0.5f, 1);
  98. }
  99. if (overlayTarget.overlayShape == CompositeLayerFeature.OverlayShape.Quad || overlayTarget.overlayShape == CompositeLayerFeature.OverlayShape.Equirect)
  100. {
  101. guiContent.text = "Destination Rects";
  102. overlayTarget.destinationRect = (CompositeLayerFeature.DestinationRect)EditorGUILayout.EnumPopup(guiContent, overlayTarget.destinationRect);
  103. if (overlayTarget.destinationRect == CompositeLayerFeature.DestinationRect.Custom)
  104. {
  105. EditorGUILayout.BeginVertical("frameBox");
  106. EditorGUILayout.BeginHorizontal();
  107. EditorGUILayout.LabelField("Left Rect");
  108. EditorGUILayout.LabelField("Right Rect");
  109. EditorGUILayout.EndHorizontal();
  110. EditorGUILayout.BeginHorizontal();
  111. overlayTarget.dstRectLeft = ClampRect(EditorGUILayout.RectField(overlayTarget.dstRectLeft));
  112. EditorGUILayout.Space(15);
  113. guiContent.text = "Right";
  114. overlayTarget.dstRectRight = ClampRect(EditorGUILayout.RectField(overlayTarget.dstRectRight));
  115. EditorGUILayout.EndHorizontal();
  116. EditorGUILayout.EndVertical();
  117. EditorGUILayout.Space();
  118. }
  119. else
  120. {
  121. overlayTarget.dstRectLeft = new Rect(0, 0, 1, 1);
  122. overlayTarget.dstRectRight = new Rect(0, 0, 1, 1);
  123. }
  124. }
  125. }
  126. }
  127. guiContent.text = "Layer Blend";
  128. overlayTarget.useLayerBlend = EditorGUILayout.Toggle(guiContent, overlayTarget.useLayerBlend);
  129. if (overlayTarget.useLayerBlend)
  130. {
  131. EditorGUILayout.BeginVertical("frameBox");
  132. guiContent.text = "Src Color";
  133. overlayTarget.srcColor = (PxrBlendFactor)EditorGUILayout.EnumPopup(guiContent, overlayTarget.srcColor);
  134. guiContent.text = "Dst Color";
  135. overlayTarget.dstColor = (PxrBlendFactor)EditorGUILayout.EnumPopup(guiContent, overlayTarget.dstColor);
  136. guiContent.text = "Src Alpha";
  137. overlayTarget.srcAlpha = (PxrBlendFactor)EditorGUILayout.EnumPopup(guiContent, overlayTarget.srcAlpha);
  138. guiContent.text = "Dst Alpha";
  139. overlayTarget.dstAlpha = (PxrBlendFactor)EditorGUILayout.EnumPopup(guiContent, overlayTarget.dstAlpha);
  140. EditorGUILayout.EndVertical();
  141. }
  142. guiContent.text = "Override Color Scale";
  143. overlayTarget.overrideColorScaleAndOffset = EditorGUILayout.Toggle(guiContent, overlayTarget.overrideColorScaleAndOffset);
  144. if (overlayTarget.overrideColorScaleAndOffset)
  145. {
  146. EditorGUILayout.BeginVertical("frameBox");
  147. guiContent.text = "Scale";
  148. Vector4 colorScale = EditorGUILayout.Vector4Field(guiContent, overlayTarget.colorScale);
  149. guiContent.text = "Offset";
  150. Vector4 colorOffset = EditorGUILayout.Vector4Field(guiContent, overlayTarget.colorOffset);
  151. overlayTarget.SetLayerColorScaleAndOffset(colorScale, colorOffset);
  152. EditorGUILayout.EndVertical();
  153. }
  154. }
  155. if (GUI.changed)
  156. {
  157. UnityEditor.SceneManagement.EditorSceneManager.MarkSceneDirty(UnityEngine.SceneManagement.SceneManager.GetActiveScene());
  158. }
  159. }
  160. private Rect ClampRect(Rect rect)
  161. {
  162. rect.x = Mathf.Clamp01(rect.x);
  163. rect.y = Mathf.Clamp01(rect.y);
  164. rect.width = Mathf.Clamp01(rect.width);
  165. rect.height = Mathf.Clamp01(rect.height);
  166. return rect;
  167. }
  168. }
  169. }