DisplayWindow.cs 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594
  1. using System;
  2. using UnityEditor.UIElements;
  3. using UnityEngine;
  4. using UnityEngine.UIElements;
  5. namespace UnityEditor.Rendering.LookDev
  6. {
  7. /// <summary>Interface that must implement the viewer to communicate with the compositor and data management</summary>
  8. public interface IViewDisplayer
  9. {
  10. /// <summary>Get the displayed rect to use</summary>
  11. /// <param name="index">Index of this view</param>
  12. /// <returns>The Rect to draw</returns>
  13. Rect GetRect(ViewCompositionIndex index);
  14. /// <summary>Set the computed texture in the view</summary>
  15. /// <param name="index">Index of this view</param>
  16. /// <param name="texture">The texture used</param>
  17. void SetTexture(ViewCompositionIndex index, Texture texture);
  18. /// <summary>Repaint the UI</summary>
  19. void Repaint();
  20. /// <summary>Callback on layout changed</summary>
  21. event Action<Layout, SidePanel> OnLayoutChanged;
  22. /// <summary>Callback on RenderDoc acquisition is triggered</summary>
  23. event Action OnRenderDocAcquisitionTriggered;
  24. /// <summary>Callback on ;ouse events in the view</summary>
  25. event Action<IMouseEvent> OnMouseEventInView;
  26. /// <summary>Callback on object changed in the view</summary>
  27. event Action<GameObject, ViewCompositionIndex, Vector2> OnChangingObjectInView;
  28. /// <summary>Callback on environment changed in the view</summary>
  29. event Action<UnityEngine.Object, ViewCompositionIndex, Vector2> OnChangingEnvironmentInView;
  30. /// <summary>Callback on closed</summary>
  31. event Action OnClosed;
  32. /// <summary>Callback on update requested</summary>
  33. event Action OnUpdateRequested;
  34. }
  35. partial class DisplayWindow : EditorWindow, IViewDisplayer
  36. {
  37. static partial class Style
  38. {
  39. internal const string k_IconFolder = @"Packages/com.unity.render-pipelines.core/Editor/LookDev/Icons/";
  40. internal const string k_uss = @"Packages/com.unity.render-pipelines.core/Editor/LookDev/DisplayWindow.uss";
  41. internal const string k_uss_personal_overload = @"Packages/com.unity.render-pipelines.core/Editor/LookDev/DisplayWindow-PersonalSkin.uss";
  42. internal static readonly GUIContent k_WindowTitleAndIcon = EditorGUIUtility.TrTextContentWithIcon("Look Dev", CoreEditorUtils.LoadIcon(k_IconFolder, "LookDev", forceLowRes: true));
  43. internal static readonly Texture2D k_Layout1Icon = CoreEditorUtils.LoadIcon(Style.k_IconFolder, "Layout1", forceLowRes: true);
  44. internal static readonly Texture2D k_Layout2Icon = CoreEditorUtils.LoadIcon(Style.k_IconFolder, "Layout2", forceLowRes: true);
  45. internal static readonly Texture2D k_LayoutVerticalIcon = CoreEditorUtils.LoadIcon(Style.k_IconFolder, "LayoutVertical", forceLowRes: true);
  46. internal static readonly Texture2D k_LayoutHorizontalIcon = CoreEditorUtils.LoadIcon(Style.k_IconFolder, "LayoutHorizontal", forceLowRes: true);
  47. internal static readonly Texture2D k_LayoutStackIcon = CoreEditorUtils.LoadIcon(Style.k_IconFolder, "LayoutCustom", forceLowRes: true);
  48. internal static readonly Texture2D k_Camera1Icon = CoreEditorUtils.LoadIcon(Style.k_IconFolder, "Camera1", forceLowRes: true);
  49. internal static readonly Texture2D k_Camera2Icon = CoreEditorUtils.LoadIcon(Style.k_IconFolder, "Camera2", forceLowRes: true);
  50. internal static readonly Texture2D k_LinkIcon = CoreEditorUtils.LoadIcon(Style.k_IconFolder, "Link", forceLowRes: true);
  51. internal static readonly Texture2D k_RightIcon = CoreEditorUtils.LoadIcon(Style.k_IconFolder, "RightArrow", forceLowRes: true);
  52. internal static readonly Texture2D k_LeftIcon = CoreEditorUtils.LoadIcon(Style.k_IconFolder, "LeftArrow", forceLowRes: true);
  53. internal static readonly Texture2D k_RenderdocIcon = CoreEditorUtils.LoadIcon(Style.k_IconFolder, "RenderDoc", forceLowRes: true);
  54. internal const string k_RenderDocLabel = " Content";
  55. internal const string k_CameraMenuSync1On2 = "Align Camera 1 with Camera 2";
  56. internal const string k_CameraMenuSync2On1 = "Align Camera 2 with Camera 1";
  57. internal const string k_CameraMenuReset = "Reset Cameras";
  58. internal const string k_EnvironmentSidePanelName = "Environment";
  59. internal const string k_DebugSidePanelName = "Debug";
  60. internal const string k_DragAndDropObject = "Drag and drop object here";
  61. internal const string k_DragAndDropEnvironment = "Drag and drop environment from side panel here";
  62. // /!\ WARNING:
  63. //The following const are used in the uss.
  64. //If you change them, update the uss file too.
  65. internal const string k_MainContainerName = "mainContainer";
  66. internal const string k_ViewContainerName = "viewContainer";
  67. internal const string k_FirstViewName = "firstView";
  68. internal const string k_SecondViewName = "secondView";
  69. internal const string k_ToolbarName = "toolbar";
  70. internal const string k_ToolbarRadioName = "toolbarRadio";
  71. internal const string k_TabsRadioName = "tabsRadio";
  72. internal const string k_SideToolbarName = "sideToolbar";
  73. internal const string k_SharedContainerClass = "container";
  74. internal const string k_FirstViewClass = "firstView";
  75. internal const string k_SecondViewsClass = "secondView";
  76. internal const string k_VerticalViewsClass = "verticalSplit";
  77. internal const string k_DebugContainerName = "debugContainer";
  78. internal const string k_ShowDebugPanelClass = "showDebugPanel";
  79. internal const string k_EnvironmentContainerName = "environmentContainer";
  80. internal const string k_ShowEnvironmentPanelClass = "showEnvironmentPanel";
  81. internal const string k_CameraMenuName = "cameraMenu";
  82. internal const string k_CameraButtonName = "cameraButton";
  83. internal const string k_CameraSeparatorName = "cameraSeparator";
  84. internal const string k_RenderDocContentName = "renderdoc-content";
  85. }
  86. VisualElement m_MainContainer;
  87. VisualElement m_ViewContainer;
  88. VisualElement m_DebugContainer;
  89. Label m_NoEnvironmentList;
  90. Label m_NoObject1;
  91. Label m_NoEnvironment1;
  92. Label m_NoObject2;
  93. Label m_NoEnvironment2;
  94. Image[] m_Views = new Image[2];
  95. LayoutContext layout
  96. => LookDev.currentContext.layout;
  97. Layout viewLayout
  98. {
  99. get => layout.viewLayout;
  100. set
  101. {
  102. if (layout.viewLayout != value)
  103. {
  104. OnLayoutChangedInternal?.Invoke(value, sidePanel);
  105. ApplyLayout(value);
  106. }
  107. }
  108. }
  109. SidePanel sidePanel
  110. {
  111. get => layout.showedSidePanel;
  112. set
  113. {
  114. if (layout.showedSidePanel != value)
  115. {
  116. OnLayoutChangedInternal?.Invoke(viewLayout, value);
  117. ApplySidePanelChange(layout.showedSidePanel);
  118. }
  119. }
  120. }
  121. event Action<Layout, SidePanel> OnLayoutChangedInternal;
  122. event Action<Layout, SidePanel> IViewDisplayer.OnLayoutChanged
  123. {
  124. add => OnLayoutChangedInternal += value;
  125. remove => OnLayoutChangedInternal -= value;
  126. }
  127. event Action OnRenderDocAcquisitionTriggeredInternal;
  128. event Action IViewDisplayer.OnRenderDocAcquisitionTriggered
  129. {
  130. add => OnRenderDocAcquisitionTriggeredInternal += value;
  131. remove => OnRenderDocAcquisitionTriggeredInternal -= value;
  132. }
  133. event Action<IMouseEvent> OnMouseEventInViewPortInternal;
  134. event Action<IMouseEvent> IViewDisplayer.OnMouseEventInView
  135. {
  136. add => OnMouseEventInViewPortInternal += value;
  137. remove => OnMouseEventInViewPortInternal -= value;
  138. }
  139. event Action<GameObject, ViewCompositionIndex, Vector2> OnChangingObjectInViewInternal;
  140. event Action<GameObject, ViewCompositionIndex, Vector2> IViewDisplayer.OnChangingObjectInView
  141. {
  142. add => OnChangingObjectInViewInternal += value;
  143. remove => OnChangingObjectInViewInternal -= value;
  144. }
  145. //event Action<Material, ViewCompositionIndex, Vector2> OnChangingMaterialInViewInternal;
  146. //event Action<Material, ViewCompositionIndex, Vector2> IViewDisplayer.OnChangingMaterialInView
  147. //{
  148. // add => OnChangingMaterialInViewInternal += value;
  149. // remove => OnChangingMaterialInViewInternal -= value;
  150. //}
  151. event Action<UnityEngine.Object, ViewCompositionIndex, Vector2> OnChangingEnvironmentInViewInternal;
  152. event Action<UnityEngine.Object, ViewCompositionIndex, Vector2> IViewDisplayer.OnChangingEnvironmentInView
  153. {
  154. add => OnChangingEnvironmentInViewInternal += value;
  155. remove => OnChangingEnvironmentInViewInternal -= value;
  156. }
  157. event Action OnClosedInternal;
  158. event Action IViewDisplayer.OnClosed
  159. {
  160. add => OnClosedInternal += value;
  161. remove => OnClosedInternal -= value;
  162. }
  163. event Action OnUpdateRequestedInternal;
  164. event Action IViewDisplayer.OnUpdateRequested
  165. {
  166. add => OnUpdateRequestedInternal += value;
  167. remove => OnUpdateRequestedInternal -= value;
  168. }
  169. void OnEnable()
  170. {
  171. //Call the open function to configure LookDev
  172. // in case the window where open when last editor session finished.
  173. // (Else it will open at start and has nothing to display).
  174. if (!LookDev.open)
  175. LookDev.Open();
  176. titleContent = Style.k_WindowTitleAndIcon;
  177. // /!\ be sure to have a minSize that will allow a non negative sized viewport even with side panel open
  178. this.minSize = new Vector2(600, 400);
  179. rootVisualElement.styleSheets.Add(
  180. AssetDatabase.LoadAssetAtPath<StyleSheet>(Style.k_uss));
  181. if (!EditorGUIUtility.isProSkin)
  182. {
  183. rootVisualElement.styleSheets.Add(
  184. AssetDatabase.LoadAssetAtPath<StyleSheet>(Style.k_uss_personal_overload));
  185. }
  186. CreateToolbar();
  187. m_MainContainer = new VisualElement() { name = Style.k_MainContainerName };
  188. m_MainContainer.AddToClassList(Style.k_SharedContainerClass);
  189. rootVisualElement.Add(m_MainContainer);
  190. CreateViews();
  191. CreateEnvironment();
  192. CreateDebug();
  193. CreateDropAreas();
  194. ApplyLayout(viewLayout);
  195. ApplySidePanelChange(layout.showedSidePanel);
  196. }
  197. void OnDisable() => OnClosedInternal?.Invoke();
  198. void CreateToolbar()
  199. {
  200. // Layout swapper part
  201. var layoutRadio = new ToolbarRadio() { name = Style.k_ToolbarRadioName };
  202. layoutRadio.AddRadios(new[] {
  203. Style.k_Layout1Icon,
  204. Style.k_Layout2Icon,
  205. Style.k_LayoutVerticalIcon,
  206. Style.k_LayoutHorizontalIcon,
  207. Style.k_LayoutStackIcon,
  208. });
  209. layoutRadio.RegisterCallback((ChangeEvent<int> evt)
  210. => viewLayout = (Layout)evt.newValue);
  211. layoutRadio.SetValueWithoutNotify((int)viewLayout);
  212. var cameraMenu = new ToolbarMenu() { name = Style.k_CameraMenuName };
  213. cameraMenu.variant = ToolbarMenu.Variant.Popup;
  214. var cameraToggle = new ToolbarToggle() { name = Style.k_CameraButtonName };
  215. cameraToggle.value = LookDev.currentContext.cameraSynced;
  216. //Note: when having Image on top of the Toggle nested in the Menu, RegisterValueChangedCallback is not called
  217. //cameraToggle.RegisterValueChangedCallback(evt => LookDev.currentContext.cameraSynced = evt.newValue);
  218. cameraToggle.RegisterCallback<MouseUpEvent>(evt =>
  219. {
  220. LookDev.currentContext.cameraSynced ^= true;
  221. cameraToggle.SetValueWithoutNotify(LookDev.currentContext.cameraSynced);
  222. });
  223. var cameraSeparator = new ToolbarToggle() { name = Style.k_CameraSeparatorName };
  224. cameraToggle.Add(new Image() { image = Style.k_Camera1Icon });
  225. cameraToggle.Add(new Image() { image = Style.k_LinkIcon });
  226. cameraToggle.Add(new Image() { image = Style.k_Camera2Icon });
  227. cameraMenu.Add(cameraToggle);
  228. cameraMenu.Add(cameraSeparator);
  229. cameraMenu.menu.AppendAction(Style.k_CameraMenuSync1On2,
  230. (DropdownMenuAction a) => LookDev.currentContext.SynchronizeCameraStates(ViewIndex.Second),
  231. DropdownMenuAction.AlwaysEnabled);
  232. cameraMenu.menu.AppendAction(Style.k_CameraMenuSync2On1,
  233. (DropdownMenuAction a) => LookDev.currentContext.SynchronizeCameraStates(ViewIndex.First),
  234. DropdownMenuAction.AlwaysEnabled);
  235. cameraMenu.menu.AppendAction(Style.k_CameraMenuReset,
  236. (DropdownMenuAction a) =>
  237. {
  238. LookDev.currentContext.GetViewContent(ViewIndex.First).ResetCameraState();
  239. LookDev.currentContext.GetViewContent(ViewIndex.Second).ResetCameraState();
  240. },
  241. DropdownMenuAction.AlwaysEnabled);
  242. // Side part
  243. var sideRadio = new ToolbarRadio(canDeselectAll: true)
  244. {
  245. name = Style.k_TabsRadioName
  246. };
  247. sideRadio.AddRadios(new[] {
  248. Style.k_EnvironmentSidePanelName,
  249. Style.k_DebugSidePanelName,
  250. });
  251. sideRadio.SetValueWithoutNotify((int)sidePanel);
  252. sideRadio.RegisterCallback((ChangeEvent<int> evt)
  253. => sidePanel = (SidePanel)evt.newValue);
  254. // Aggregate parts
  255. var toolbar = new UIElements.Toolbar() { name = Style.k_ToolbarName };
  256. toolbar.Add(layoutRadio);
  257. toolbar.Add(new ToolbarSpacer());
  258. toolbar.Add(cameraMenu);
  259. toolbar.Add(new ToolbarSpacer() { flex = true });
  260. if (UnityEditorInternal.RenderDoc.IsInstalled() && UnityEditorInternal.RenderDoc.IsLoaded())
  261. {
  262. var renderDocButton = new ToolbarButton(() => OnRenderDocAcquisitionTriggeredInternal?.Invoke())
  263. {
  264. name = Style.k_RenderDocContentName
  265. };
  266. renderDocButton.Add(new Image() { image = Style.k_RenderdocIcon });
  267. renderDocButton.Add(new Label() { text = Style.k_RenderDocLabel });
  268. toolbar.Add(renderDocButton);
  269. toolbar.Add(new ToolbarSpacer());
  270. }
  271. toolbar.Add(sideRadio);
  272. rootVisualElement.Add(toolbar);
  273. }
  274. void CreateViews()
  275. {
  276. if (m_MainContainer == null || m_MainContainer.Equals(null))
  277. throw new System.MemberAccessException("m_MainContainer should be assigned prior CreateViews()");
  278. m_ViewContainer = new VisualElement() { name = Style.k_ViewContainerName };
  279. m_ViewContainer.AddToClassList(LookDev.currentContext.layout.isMultiView ? Style.k_SecondViewsClass : Style.k_FirstViewClass);
  280. m_ViewContainer.AddToClassList(Style.k_SharedContainerClass);
  281. m_MainContainer.Add(m_ViewContainer);
  282. m_ViewContainer.RegisterCallback<MouseDownEvent>(evt => OnMouseEventInViewPortInternal?.Invoke(evt));
  283. m_ViewContainer.RegisterCallback<MouseUpEvent>(evt => OnMouseEventInViewPortInternal?.Invoke(evt));
  284. m_ViewContainer.RegisterCallback<MouseMoveEvent>(evt => OnMouseEventInViewPortInternal?.Invoke(evt));
  285. m_Views[(int)ViewIndex.First] = new Image() { name = Style.k_FirstViewName, image = Texture2D.blackTexture };
  286. m_ViewContainer.Add(m_Views[(int)ViewIndex.First]);
  287. m_Views[(int)ViewIndex.Second] = new Image() { name = Style.k_SecondViewName, image = Texture2D.blackTexture };
  288. m_ViewContainer.Add(m_Views[(int)ViewIndex.Second]);
  289. var firstOrCompositeManipulator = new SwitchableCameraController(
  290. LookDev.currentContext.GetViewContent(ViewIndex.First).camera,
  291. LookDev.currentContext.GetViewContent(ViewIndex.Second).camera,
  292. this,
  293. index =>
  294. {
  295. LookDev.currentContext.SetFocusedCamera(index);
  296. var environment = LookDev.currentContext.GetViewContent(index).environment;
  297. if (sidePanel == SidePanel.Environment && environment != null && LookDev.currentContext.environmentLibrary != null)
  298. m_EnvironmentList.selectedIndex = LookDev.currentContext.environmentLibrary.IndexOf(environment);
  299. });
  300. var secondManipulator = new CameraController(
  301. LookDev.currentContext.GetViewContent(ViewIndex.Second).camera,
  302. this,
  303. () =>
  304. {
  305. LookDev.currentContext.SetFocusedCamera(ViewIndex.Second);
  306. var environment = LookDev.currentContext.GetViewContent(ViewIndex.Second).environment;
  307. if (sidePanel == SidePanel.Environment && environment != null && LookDev.currentContext.environmentLibrary != null)
  308. m_EnvironmentList.selectedIndex = LookDev.currentContext.environmentLibrary.IndexOf(environment);
  309. });
  310. var gizmoManipulator = new ComparisonGizmoController(LookDev.currentContext.layout.gizmoState, firstOrCompositeManipulator);
  311. m_Views[(int)ViewIndex.First].AddManipulator(gizmoManipulator); //must take event first to switch the firstOrCompositeManipulator
  312. m_Views[(int)ViewIndex.First].AddManipulator(firstOrCompositeManipulator);
  313. m_Views[(int)ViewIndex.Second].AddManipulator(secondManipulator);
  314. m_NoObject1 = new Label(Style.k_DragAndDropObject);
  315. m_NoObject1.style.flexGrow = 1;
  316. m_NoObject1.style.unityTextAlign = TextAnchor.MiddleCenter;
  317. m_NoObject2 = new Label(Style.k_DragAndDropObject);
  318. m_NoObject2.style.flexGrow = 1;
  319. m_NoObject2.style.unityTextAlign = TextAnchor.MiddleCenter;
  320. m_NoEnvironment1 = new Label(Style.k_DragAndDropEnvironment);
  321. m_NoEnvironment1.style.flexGrow = 1;
  322. m_NoEnvironment1.style.unityTextAlign = TextAnchor.MiddleCenter;
  323. m_NoEnvironment2 = new Label(Style.k_DragAndDropEnvironment);
  324. m_NoEnvironment2.style.flexGrow = 1;
  325. m_NoEnvironment2.style.unityTextAlign = TextAnchor.MiddleCenter;
  326. m_Views[(int)ViewIndex.First].Add(m_NoObject1);
  327. m_Views[(int)ViewIndex.First].Add(m_NoEnvironment1);
  328. m_Views[(int)ViewIndex.Second].Add(m_NoObject2);
  329. m_Views[(int)ViewIndex.Second].Add(m_NoEnvironment2);
  330. }
  331. void CreateDropAreas()
  332. {
  333. // GameObject or Prefab in view
  334. new DropArea(new[] { typeof(GameObject) }, m_Views[(int)ViewIndex.First], (obj, localPos) =>
  335. {
  336. if (viewLayout == Layout.CustomSplit)
  337. OnChangingObjectInViewInternal?.Invoke(obj as GameObject, ViewCompositionIndex.Composite, localPos);
  338. else
  339. OnChangingObjectInViewInternal?.Invoke(obj as GameObject, ViewCompositionIndex.First, localPos);
  340. m_NoObject1.style.visibility = obj == null || obj.Equals(null) ? Visibility.Visible : Visibility.Hidden;
  341. });
  342. new DropArea(new[] { typeof(GameObject) }, m_Views[(int)ViewIndex.Second], (obj, localPos) =>
  343. {
  344. OnChangingObjectInViewInternal?.Invoke(obj as GameObject, ViewCompositionIndex.Second, localPos);
  345. m_NoObject2.style.visibility = obj == null || obj.Equals(null) ? Visibility.Visible : Visibility.Hidden;
  346. });
  347. // Material in view
  348. //new DropArea(new[] { typeof(GameObject) }, m_Views[(int)ViewIndex.First], (obj, localPos) =>
  349. //{
  350. // if (layout == Layout.CustomSplit || layout == Layout.CustomCircular)
  351. // OnChangingMaterialInViewInternal?.Invoke(obj as Material, ViewCompositionIndex.Composite, localPos);
  352. // else
  353. // OnChangingMaterialInViewInternal?.Invoke(obj as Material, ViewCompositionIndex.First, localPos);
  354. //});
  355. //new DropArea(new[] { typeof(Material) }, m_Views[(int)ViewIndex.Second], (obj, localPos)
  356. // => OnChangingMaterialInViewInternal?.Invoke(obj as Material, ViewCompositionIndex.Second, localPos));
  357. // Environment in view
  358. new DropArea(new[] { typeof(Environment), typeof(Cubemap) }, m_Views[(int)ViewIndex.First], (obj, localPos) =>
  359. {
  360. if (viewLayout == Layout.CustomSplit)
  361. OnChangingEnvironmentInViewInternal?.Invoke(obj, ViewCompositionIndex.Composite, localPos);
  362. else
  363. OnChangingEnvironmentInViewInternal?.Invoke(obj, ViewCompositionIndex.First, localPos);
  364. m_NoEnvironment1.style.visibility = obj == null || obj.Equals(null) ? Visibility.Visible : Visibility.Hidden;
  365. });
  366. new DropArea(new[] { typeof(Environment), typeof(Cubemap) }, m_Views[(int)ViewIndex.Second], (obj, localPos) =>
  367. {
  368. OnChangingEnvironmentInViewInternal?.Invoke(obj, ViewCompositionIndex.Second, localPos);
  369. m_NoEnvironment2.style.visibility = obj == null || obj.Equals(null) ? Visibility.Visible : Visibility.Hidden;
  370. });
  371. // Environment in library
  372. //new DropArea(new[] { typeof(Environment), typeof(Cubemap) }, m_EnvironmentContainer, (obj, localPos) =>
  373. //{
  374. // //[TODO: check if this come from outside of library]
  375. // OnAddingEnvironmentInternal?.Invoke(obj);
  376. //});
  377. new DropArea(new[] { typeof(EnvironmentLibrary) }, m_EnvironmentContainer, (obj, localPos) =>
  378. {
  379. OnChangingEnvironmentLibraryInternal?.Invoke(obj as EnvironmentLibrary);
  380. RefreshLibraryDisplay();
  381. });
  382. }
  383. Rect IViewDisplayer.GetRect(ViewCompositionIndex index)
  384. {
  385. switch (index)
  386. {
  387. case ViewCompositionIndex.First:
  388. case ViewCompositionIndex.Composite: //display composition on first rect
  389. return m_Views[(int)ViewIndex.First].contentRect;
  390. case ViewCompositionIndex.Second:
  391. return m_Views[(int)ViewIndex.Second].contentRect;
  392. default:
  393. throw new ArgumentException("Unknown ViewCompositionIndex: " + index);
  394. }
  395. }
  396. Vector2 m_LastFirstViewSize = new Vector2();
  397. Vector2 m_LastSecondViewSize = new Vector2();
  398. void IViewDisplayer.SetTexture(ViewCompositionIndex index, Texture texture)
  399. {
  400. bool updated = false;
  401. switch (index)
  402. {
  403. case ViewCompositionIndex.First:
  404. case ViewCompositionIndex.Composite: //display composition on first rect
  405. if (updated |= m_Views[(int)ViewIndex.First].image != texture)
  406. m_Views[(int)ViewIndex.First].image = texture;
  407. else if (updated |= (m_LastFirstViewSize.x != texture.width
  408. || m_LastFirstViewSize.y != texture.height))
  409. {
  410. m_Views[(int)ViewIndex.First].image = null; //force refresh else it will appear zoomed
  411. m_Views[(int)ViewIndex.First].image = texture;
  412. }
  413. if (updated)
  414. {
  415. m_LastFirstViewSize.x = texture?.width ?? 0;
  416. m_LastFirstViewSize.y = texture?.height ?? 0;
  417. }
  418. break;
  419. case ViewCompositionIndex.Second:
  420. if (m_Views[(int)ViewIndex.Second].image != texture)
  421. m_Views[(int)ViewIndex.Second].image = texture;
  422. else if (updated |= (m_LastSecondViewSize.x != texture.width
  423. || m_LastSecondViewSize.y != texture.height))
  424. {
  425. m_Views[(int)ViewIndex.Second].image = null; //force refresh else it will appear zoomed
  426. m_Views[(int)ViewIndex.Second].image = texture;
  427. }
  428. if (updated)
  429. {
  430. m_LastSecondViewSize.x = texture?.width ?? 0;
  431. m_LastSecondViewSize.y = texture?.height ?? 0;
  432. }
  433. break;
  434. default:
  435. throw new ArgumentException("Unknown ViewCompositionIndex: " + index);
  436. }
  437. }
  438. void IViewDisplayer.Repaint() => Repaint();
  439. void ApplyLayout(Layout value)
  440. {
  441. m_NoObject1.style.visibility = LookDev.currentContext.GetViewContent(ViewIndex.First).hasViewedObject ? Visibility.Hidden : Visibility.Visible;
  442. m_NoObject2.style.visibility = LookDev.currentContext.GetViewContent(ViewIndex.Second).hasViewedObject ? Visibility.Hidden : Visibility.Visible;
  443. m_NoEnvironment1.style.visibility = LookDev.currentContext.GetViewContent(ViewIndex.First).hasEnvironment ? Visibility.Hidden : Visibility.Visible;
  444. m_NoEnvironment2.style.visibility = LookDev.currentContext.GetViewContent(ViewIndex.Second).hasEnvironment ? Visibility.Hidden : Visibility.Visible;
  445. switch (value)
  446. {
  447. case Layout.HorizontalSplit:
  448. case Layout.VerticalSplit:
  449. if (!m_ViewContainer.ClassListContains(Style.k_FirstViewClass))
  450. m_ViewContainer.AddToClassList(Style.k_FirstViewClass);
  451. if (!m_ViewContainer.ClassListContains(Style.k_SecondViewsClass))
  452. m_ViewContainer.AddToClassList(Style.k_SecondViewsClass);
  453. if (value == Layout.VerticalSplit)
  454. {
  455. m_ViewContainer.AddToClassList(Style.k_VerticalViewsClass);
  456. if (!m_ViewContainer.ClassListContains(Style.k_VerticalViewsClass))
  457. m_ViewContainer.AddToClassList(Style.k_FirstViewClass);
  458. }
  459. for (int i = 0; i < 2; ++i)
  460. m_Views[i].style.display = DisplayStyle.Flex;
  461. break;
  462. case Layout.FullFirstView:
  463. case Layout.CustomSplit: //display composition on first rect
  464. if (!m_ViewContainer.ClassListContains(Style.k_FirstViewClass))
  465. m_ViewContainer.AddToClassList(Style.k_FirstViewClass);
  466. if (m_ViewContainer.ClassListContains(Style.k_SecondViewsClass))
  467. m_ViewContainer.RemoveFromClassList(Style.k_SecondViewsClass);
  468. m_Views[0].style.display = DisplayStyle.Flex;
  469. m_Views[1].style.display = DisplayStyle.None;
  470. break;
  471. case Layout.FullSecondView:
  472. if (m_ViewContainer.ClassListContains(Style.k_FirstViewClass))
  473. m_ViewContainer.RemoveFromClassList(Style.k_FirstViewClass);
  474. if (!m_ViewContainer.ClassListContains(Style.k_SecondViewsClass))
  475. m_ViewContainer.AddToClassList(Style.k_SecondViewsClass);
  476. m_Views[0].style.display = DisplayStyle.None;
  477. m_Views[1].style.display = DisplayStyle.Flex;
  478. break;
  479. default:
  480. throw new ArgumentException("Unknown Layout");
  481. }
  482. //Add flex direction here
  483. if (value == Layout.VerticalSplit)
  484. m_ViewContainer.AddToClassList(Style.k_VerticalViewsClass);
  485. else if (m_ViewContainer.ClassListContains(Style.k_VerticalViewsClass))
  486. m_ViewContainer.RemoveFromClassList(Style.k_VerticalViewsClass);
  487. }
  488. void ApplySidePanelChange(SidePanel sidePanel)
  489. {
  490. IStyle GetEnvironmentContenairDraggerStyle()
  491. => m_EnvironmentContainer.Q(className: "unity-base-slider--vertical").Q("unity-dragger").style;
  492. if (sidePanel == SidePanel.Environment)
  493. {
  494. if (!m_MainContainer.ClassListContains(Style.k_ShowEnvironmentPanelClass))
  495. m_MainContainer.AddToClassList(Style.k_ShowEnvironmentPanelClass);
  496. if (m_EnvironmentList.selectedIndex != -1)
  497. m_EnvironmentContainer.Q<EnvironmentElement>().style.visibility = Visibility.Visible;
  498. GetEnvironmentContenairDraggerStyle().display = DisplayStyle.Flex;
  499. m_EnvironmentContainer.style.display = DisplayStyle.Flex;
  500. }
  501. else
  502. {
  503. if (m_MainContainer.ClassListContains(Style.k_ShowEnvironmentPanelClass))
  504. m_MainContainer.RemoveFromClassList(Style.k_ShowEnvironmentPanelClass);
  505. m_EnvironmentContainer.Q<EnvironmentElement>().style.visibility = Visibility.Hidden;
  506. GetEnvironmentContenairDraggerStyle().display = DisplayStyle.None;
  507. m_EnvironmentContainer.style.display = DisplayStyle.None;
  508. }
  509. if (sidePanel == SidePanel.Debug)
  510. {
  511. if (!m_MainContainer.ClassListContains(Style.k_ShowDebugPanelClass))
  512. m_MainContainer.AddToClassList(Style.k_ShowDebugPanelClass);
  513. UpdateSideDebugPanelProperties();
  514. }
  515. else
  516. {
  517. if (m_MainContainer.ClassListContains(Style.k_ShowDebugPanelClass))
  518. m_MainContainer.RemoveFromClassList(Style.k_ShowDebugPanelClass);
  519. }
  520. }
  521. void OnGUI() => OnUpdateRequestedInternal?.Invoke();
  522. }
  523. }