InspectorWindow.cs 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data.Common;
  4. using System.IO;
  5. using BansheeEngine;
  6. namespace BansheeEditor
  7. {
  8. /// <summary>
  9. /// Displays GUI for a <see cref="SceneObject"/> or for a <see cref="Resource"/>. Scene object's transform values
  10. /// are displayed, along with all their components and their fields.
  11. /// </summary>
  12. internal sealed class InspectorWindow : EditorWindow
  13. {
  14. /// <summary>
  15. /// Type of objects displayed in the window.
  16. /// </summary>
  17. private enum InspectorType
  18. {
  19. SceneObject,
  20. Resource,
  21. Multiple,
  22. None
  23. }
  24. /// <summary>
  25. /// Inspector GUI elements for a single <see cref="Component"/> in a <see cref="SceneObject"/>.
  26. /// </summary>
  27. private class InspectorComponent
  28. {
  29. public GUIToggle foldout;
  30. public GUIButton removeBtn;
  31. public GUIPanel panel;
  32. public Inspector inspector;
  33. public bool expanded = true;
  34. public UInt64 instanceId;
  35. }
  36. /// <summary>
  37. /// Inspector GUI elements for a <see cref="Resource"/>
  38. /// </summary>
  39. private class InspectorResource
  40. {
  41. public GUIPanel panel;
  42. public Inspector inspector;
  43. }
  44. private static readonly Color HIGHLIGHT_COLOR = new Color(1.0f, 1.0f, 1.0f, 0.5f);
  45. private List<InspectorComponent> inspectorComponents = new List<InspectorComponent>();
  46. private InspectorResource inspectorResource;
  47. private GUIScrollArea inspectorScrollArea;
  48. private GUILayout inspectorLayout;
  49. private GUILayoutY sceneObjectLayout;
  50. private GUIPanel highlightPanel;
  51. private GUITexture scrollAreaHighlight;
  52. private SceneObject activeSO;
  53. private GUITextBox soNameInput;
  54. private GUILayout soPrefabLayout;
  55. private bool soHasPrefab;
  56. private GUIFloatField soPosX;
  57. private GUIFloatField soPosY;
  58. private GUIFloatField soPosZ;
  59. private GUIFloatField soRotX;
  60. private GUIFloatField soRotY;
  61. private GUIFloatField soRotZ;
  62. private GUIFloatField soScaleX;
  63. private GUIFloatField soScaleY;
  64. private GUIFloatField soScaleZ;
  65. private Rect2I dropBounds;
  66. private InspectorType currentType = InspectorType.None;
  67. private Resource activeResource;
  68. /// <summary>
  69. /// Opens the inspector window from the menu bar.
  70. /// </summary>
  71. [MenuItem("Windows/Inspector", ButtonModifier.CtrlAlt, ButtonCode.I)]
  72. private static void OpenInspectorWindow()
  73. {
  74. OpenWindow<InspectorWindow>();
  75. }
  76. /// <summary>
  77. /// Name of the inspector window to display on the window title.
  78. /// </summary>
  79. /// <returns>Name of the inspector window to display on the window title.</returns>
  80. protected override LocString GetDisplayName()
  81. {
  82. return new LocEdString("Inspector");
  83. }
  84. /// <summary>
  85. /// Sets a resource whose GUI is to be displayed in the inspector. Clears any previous contents of the window.
  86. /// </summary>
  87. /// <param name="resourcePath">Resource path relative to the project of the resource to inspect.</param>
  88. private void SetObjectToInspect(String resourcePath)
  89. {
  90. activeResource = ProjectLibrary.Load<Resource>(resourcePath);
  91. if (activeResource == null)
  92. return;
  93. currentType = InspectorType.Resource;
  94. inspectorScrollArea = new GUIScrollArea();
  95. GUI.AddElement(inspectorScrollArea);
  96. inspectorLayout = inspectorScrollArea.Layout;
  97. inspectorResource = new InspectorResource();
  98. inspectorResource.panel = inspectorLayout.AddPanel();
  99. inspectorResource.inspector = InspectorUtility.GetInspector(activeResource.GetType());
  100. inspectorResource.inspector.Initialize(this, inspectorResource.panel, activeResource);
  101. inspectorResource.inspector.Refresh();
  102. inspectorLayout.AddFlexibleSpace();
  103. }
  104. /// <summary>
  105. /// Sets a scene object whose GUI is to be displayed in the inspector. Clears any previous contents of the window.
  106. /// </summary>
  107. /// <param name="so">Scene object to inspect.</param>
  108. private void SetObjectToInspect(SceneObject so)
  109. {
  110. if (so == null)
  111. return;
  112. currentType = InspectorType.SceneObject;
  113. activeSO = so;
  114. inspectorScrollArea = new GUIScrollArea();
  115. scrollAreaHighlight = new GUITexture(Builtin.WhiteTexture);
  116. scrollAreaHighlight.SetTint(HIGHLIGHT_COLOR);
  117. GUI.AddElement(inspectorScrollArea);
  118. highlightPanel = GUI.AddPanel(-1);
  119. highlightPanel.AddElement(scrollAreaHighlight);
  120. inspectorLayout = inspectorScrollArea.Layout;
  121. // SceneObject fields
  122. CreateSceneObjectFields();
  123. RefreshSceneObjectFields(true);
  124. // Components
  125. Component[] allComponents = so.GetComponents();
  126. for (int i = 0; i < allComponents.Length; i++)
  127. {
  128. InspectorComponent data = new InspectorComponent();
  129. data.instanceId = allComponents[i].InstanceId;
  130. data.foldout = new GUIToggle(allComponents[i].GetType().Name, EditorStyles.Foldout);
  131. data.removeBtn = new GUIButton(new GUIContent(EditorBuiltin.XBtnIcon), GUIOption.FixedWidth(30));
  132. GUILayoutX titleLayout = inspectorLayout.AddLayoutX();
  133. titleLayout.AddElement(data.foldout);
  134. titleLayout.AddElement(data.removeBtn);
  135. data.panel = inspectorLayout.AddPanel();
  136. data.inspector = InspectorUtility.GetInspector(allComponents[i].GetType());
  137. data.inspector.Initialize(this, data.panel, allComponents[i]);
  138. data.foldout.Value = true;
  139. Type curComponentType = allComponents[i].GetType();
  140. data.foldout.OnToggled += (bool expanded) => OnComponentFoldoutToggled(data, expanded);
  141. data.removeBtn.OnClick += () => OnComponentRemoveClicked(curComponentType);
  142. inspectorComponents.Add(data);
  143. inspectorComponents[i].inspector.Refresh();
  144. }
  145. inspectorLayout.AddFlexibleSpace();
  146. dropBounds = inspectorScrollArea.Bounds;
  147. scrollAreaHighlight.Bounds = dropBounds;
  148. }
  149. /// <summary>
  150. /// Creates GUI elements required for displaying <see cref="SceneObject"/> fields like name, prefab data and
  151. /// transform (position, rotation, scale). Assumes that necessary inspector scroll area layout has already been
  152. /// created.
  153. /// </summary>
  154. private void CreateSceneObjectFields()
  155. {
  156. GUIPanel sceneObjectPanel = inspectorLayout.AddPanel();
  157. sceneObjectPanel.SetHeight(GetTitleBounds().height);
  158. sceneObjectLayout = sceneObjectPanel.AddLayoutY();
  159. sceneObjectLayout.SetPosition(5, 5);
  160. GUIPanel sceneObjectBgPanel = sceneObjectPanel.AddPanel(1);
  161. GUILayoutX nameLayout = sceneObjectLayout.AddLayoutX();
  162. GUILabel nameLbl = new GUILabel(new LocEdString("Name"), GUIOption.FixedWidth(50));
  163. soNameInput = new GUITextBox(false, GUIOption.FlexibleWidth(180));
  164. soNameInput.Text = activeSO.Name;
  165. soNameInput.OnChanged += (x) => { if (activeSO != null) activeSO.Name = x; };
  166. nameLayout.AddElement(nameLbl);
  167. nameLayout.AddElement(soNameInput);
  168. nameLayout.AddFlexibleSpace();
  169. soPrefabLayout = sceneObjectLayout.AddLayoutX();
  170. GUILayoutX positionLayout = sceneObjectLayout.AddLayoutX();
  171. GUILabel positionLbl = new GUILabel(new LocEdString("Position"), GUIOption.FixedWidth(50));
  172. soPosX = new GUIFloatField(new LocEdString("X"), 10, "", GUIOption.FixedWidth(60));
  173. soPosY = new GUIFloatField(new LocEdString("Y"), 10, "", GUIOption.FixedWidth(60));
  174. soPosZ = new GUIFloatField(new LocEdString("Z"), 10, "", GUIOption.FixedWidth(60));
  175. soPosX.OnChanged += (x) => OnPositionChanged(0, x);
  176. soPosY.OnChanged += (y) => OnPositionChanged(1, y);
  177. soPosZ.OnChanged += (z) => OnPositionChanged(2, z);
  178. positionLayout.AddElement(positionLbl);
  179. positionLayout.AddElement(soPosX);
  180. positionLayout.AddSpace(10);
  181. positionLayout.AddFlexibleSpace();
  182. positionLayout.AddElement(soPosY);
  183. positionLayout.AddSpace(10);
  184. positionLayout.AddFlexibleSpace();
  185. positionLayout.AddElement(soPosZ);
  186. positionLayout.AddFlexibleSpace();
  187. GUILayoutX rotationLayout = sceneObjectLayout.AddLayoutX();
  188. GUILabel rotationLbl = new GUILabel(new LocEdString("Rotation"), GUIOption.FixedWidth(50));
  189. soRotX = new GUIFloatField(new LocEdString("X"), 10, "", GUIOption.FixedWidth(60));
  190. soRotY = new GUIFloatField(new LocEdString("Y"), 10, "", GUIOption.FixedWidth(60));
  191. soRotZ = new GUIFloatField(new LocEdString("Z"), 10, "", GUIOption.FixedWidth(60));
  192. soRotX.OnChanged += (x) => OnRotationChanged(0, x);
  193. soRotY.OnChanged += (y) => OnRotationChanged(1, y);
  194. soRotZ.OnChanged += (z) => OnRotationChanged(2, z);
  195. rotationLayout.AddElement(rotationLbl);
  196. rotationLayout.AddElement(soRotX);
  197. rotationLayout.AddSpace(10);
  198. rotationLayout.AddFlexibleSpace();
  199. rotationLayout.AddElement(soRotY);
  200. rotationLayout.AddSpace(10);
  201. rotationLayout.AddFlexibleSpace();
  202. rotationLayout.AddElement(soRotZ);
  203. rotationLayout.AddFlexibleSpace();
  204. GUILayoutX scaleLayout = sceneObjectLayout.AddLayoutX();
  205. GUILabel scaleLbl = new GUILabel(new LocEdString("Scale"), GUIOption.FixedWidth(50));
  206. soScaleX = new GUIFloatField(new LocEdString("X"), 10, "", GUIOption.FixedWidth(60));
  207. soScaleY = new GUIFloatField(new LocEdString("Y"), 10, "", GUIOption.FixedWidth(60));
  208. soScaleZ = new GUIFloatField(new LocEdString("Z"), 10, "", GUIOption.FixedWidth(60));
  209. soScaleX.OnChanged += (x) => OnScaleChanged(0, x);
  210. soScaleY.OnChanged += (y) => OnScaleChanged(1, y);
  211. soScaleX.OnChanged += (z) => OnScaleChanged(2, z);
  212. scaleLayout.AddElement(scaleLbl);
  213. scaleLayout.AddElement(soScaleX);
  214. scaleLayout.AddSpace(10);
  215. scaleLayout.AddFlexibleSpace();
  216. scaleLayout.AddElement(soScaleY);
  217. scaleLayout.AddSpace(10);
  218. scaleLayout.AddFlexibleSpace();
  219. scaleLayout.AddElement(soScaleZ);
  220. scaleLayout.AddFlexibleSpace();
  221. sceneObjectLayout.AddFlexibleSpace();
  222. inspectorLayout.AddSpace(5);
  223. GUITexture titleBg = new GUITexture(null, EditorStyles.InspectorTitleBg);
  224. sceneObjectBgPanel.AddElement(titleBg);
  225. }
  226. /// <summary>
  227. /// Updates contents of the scene object specific fields (name, position, rotation, etc.)
  228. /// </summary>
  229. /// <param name="forceUpdate">If true, the GUI elements will be updated regardless of whether a change was
  230. /// detected or not.</param>
  231. private void RefreshSceneObjectFields(bool forceUpdate)
  232. {
  233. if (activeSO == null)
  234. return;
  235. soNameInput.Text = activeSO.Name;
  236. bool hasPrefab = PrefabUtility.HasPrefabLink(activeSO);
  237. if (soHasPrefab != hasPrefab || forceUpdate)
  238. {
  239. int numChildren = soPrefabLayout.ChildCount;
  240. for (int i = 0; i < numChildren; i++)
  241. soPrefabLayout.GetChild(0).Destroy();
  242. GUILabel prefabLabel =new GUILabel(new LocEdString("Prefab"), GUIOption.FixedWidth(50));
  243. soPrefabLayout.AddElement(prefabLabel);
  244. if (hasPrefab)
  245. {
  246. GUIButton btnApplyPrefab = new GUIButton(new LocEdString("Apply"), GUIOption.FixedWidth(60));
  247. GUIButton btnRevertPrefab = new GUIButton(new LocEdString("Revert"), GUIOption.FixedWidth(60));
  248. GUIButton btnBreakPrefab = new GUIButton(new LocEdString("Break"), GUIOption.FixedWidth(60));
  249. btnApplyPrefab.OnClick += () => PrefabUtility.ApplyPrefab(activeSO);
  250. btnRevertPrefab.OnClick += () => PrefabUtility.RevertPrefab(activeSO);
  251. btnBreakPrefab.OnClick += () => PrefabUtility.BreakPrefab(activeSO);
  252. soPrefabLayout.AddElement(btnApplyPrefab);
  253. soPrefabLayout.AddElement(btnRevertPrefab);
  254. soPrefabLayout.AddElement(btnBreakPrefab);
  255. }
  256. else
  257. {
  258. GUILabel noPrefabLabel = new GUILabel("None");
  259. soPrefabLayout.AddElement(noPrefabLabel);
  260. }
  261. soHasPrefab = hasPrefab;
  262. }
  263. Vector3 position;
  264. Vector3 angles;
  265. if (EditorApplication.ActiveCoordinateMode == HandleCoordinateMode.World)
  266. {
  267. position = activeSO.Position;
  268. angles = activeSO.Rotation.ToEuler();
  269. }
  270. else
  271. {
  272. position = activeSO.LocalPosition;
  273. angles = activeSO.LocalRotation.ToEuler();
  274. }
  275. Vector3 scale = activeSO.LocalScale;
  276. soPosX.Value = position.x;
  277. soPosY.Value = position.y;
  278. soPosZ.Value = position.z;
  279. soRotX.Value = angles.x;
  280. soRotY.Value = angles.y;
  281. soRotZ.Value = angles.z;
  282. soScaleX.Value = scale.x;
  283. soScaleY.Value = scale.y;
  284. soScaleZ.Value = scale.z;
  285. }
  286. private void OnInitialize()
  287. {
  288. Selection.OnSelectionChanged += OnSelectionChanged;
  289. OnSelectionChanged(new SceneObject[0], new string[0]);
  290. }
  291. private void OnDestroy()
  292. {
  293. Selection.OnSelectionChanged -= OnSelectionChanged;
  294. }
  295. private void OnEditorUpdate()
  296. {
  297. if (currentType == InspectorType.SceneObject)
  298. {
  299. Component[] allComponents = activeSO.GetComponents();
  300. bool requiresRebuild = allComponents.Length != inspectorComponents.Count;
  301. if (!requiresRebuild)
  302. {
  303. for (int i = 0; i < inspectorComponents.Count; i++)
  304. {
  305. if (inspectorComponents[i].instanceId != allComponents[i].InstanceId)
  306. {
  307. requiresRebuild = true;
  308. break;
  309. }
  310. }
  311. }
  312. if (requiresRebuild)
  313. {
  314. SceneObject so = activeSO;
  315. Clear();
  316. SetObjectToInspect(so);
  317. }
  318. else
  319. {
  320. RefreshSceneObjectFields(false);
  321. for (int i = 0; i < inspectorComponents.Count; i++)
  322. {
  323. inspectorComponents[i].inspector.Refresh();
  324. }
  325. }
  326. }
  327. else if (currentType == InspectorType.Resource)
  328. {
  329. inspectorResource.inspector.Refresh();
  330. }
  331. // Detect drag and drop
  332. bool isDraggingOver = false;
  333. if (activeSO != null && inspectorScrollArea != null)
  334. {
  335. Vector2I windowPos = ScreenToWindowPos(Input.PointerPosition);
  336. ScriptCode droppedCodeFile = null;
  337. string droppedCodeFileName = "";
  338. if (DragDrop.DragInProgress && DragDrop.Type == DragDropType.Resource)
  339. {
  340. isDraggingOver = dropBounds.Contains(windowPos);
  341. }
  342. else if (DragDrop.DropInProgress && DragDrop.Type == DragDropType.Resource)
  343. {
  344. ResourceDragDropData dragData = DragDrop.Data as ResourceDragDropData;
  345. if (dragData != null)
  346. {
  347. foreach (var resPath in dragData.Paths)
  348. {
  349. LibraryEntry entry = ProjectLibrary.GetEntry(resPath);
  350. FileEntry fileEntry = entry as FileEntry;
  351. if (fileEntry != null)
  352. {
  353. if (fileEntry.ResType == ResourceType.ScriptCode)
  354. {
  355. droppedCodeFile = ProjectLibrary.Load<ScriptCode>(resPath);
  356. droppedCodeFileName = fileEntry.Name;
  357. break;
  358. }
  359. }
  360. }
  361. }
  362. }
  363. if (droppedCodeFile != null)
  364. {
  365. Type droppedComponentType = null;
  366. Type[] droppedTypes = droppedCodeFile.Types;
  367. foreach (var type in droppedTypes)
  368. {
  369. if (type.IsSubclassOf(typeof(Component)))
  370. {
  371. droppedComponentType = type;
  372. break;
  373. }
  374. }
  375. if (droppedComponentType != null)
  376. {
  377. UndoRedo.RecordSO(activeSO, "Added component " + droppedComponentType.Name);
  378. activeSO.AddComponent(droppedComponentType);
  379. }
  380. else
  381. Debug.LogWarning("Cannot find a Component in " + droppedCodeFileName);
  382. }
  383. }
  384. if (scrollAreaHighlight != null)
  385. scrollAreaHighlight.Visible = isDraggingOver;
  386. }
  387. /// <summary>
  388. /// Triggered when the user selects a new resource or a scene object, or deselects everything.
  389. /// </summary>
  390. /// <param name="objects">A set of new scene objects that were selected.</param>
  391. /// <param name="paths">A set of absolute resource paths that were selected.</param>
  392. private void OnSelectionChanged(SceneObject[] objects, string[] paths)
  393. {
  394. Clear();
  395. if (objects.Length == 0 && paths.Length == 0)
  396. {
  397. currentType = InspectorType.None;
  398. inspectorScrollArea = new GUIScrollArea();
  399. GUI.AddElement(inspectorScrollArea);
  400. inspectorLayout = inspectorScrollArea.Layout;
  401. inspectorLayout.AddFlexibleSpace();
  402. GUILayoutX layoutMsg = inspectorLayout.AddLayoutX();
  403. layoutMsg.AddFlexibleSpace();
  404. layoutMsg.AddElement(new GUILabel(new LocEdString("No object selected")));
  405. layoutMsg.AddFlexibleSpace();
  406. inspectorLayout.AddFlexibleSpace();
  407. }
  408. else if ((objects.Length + paths.Length) > 1)
  409. {
  410. currentType = InspectorType.None;
  411. inspectorScrollArea = new GUIScrollArea();
  412. GUI.AddElement(inspectorScrollArea);
  413. inspectorLayout = inspectorScrollArea.Layout;
  414. inspectorLayout.AddFlexibleSpace();
  415. GUILayoutX layoutMsg = inspectorLayout.AddLayoutX();
  416. layoutMsg.AddFlexibleSpace();
  417. layoutMsg.AddElement(new GUILabel(new LocEdString("Multiple objects selected")));
  418. layoutMsg.AddFlexibleSpace();
  419. inspectorLayout.AddFlexibleSpace();
  420. }
  421. else if (objects.Length == 1)
  422. {
  423. SetObjectToInspect(objects[0]);
  424. }
  425. else if (paths.Length == 1)
  426. {
  427. SetObjectToInspect(paths[0]);
  428. }
  429. }
  430. /// <summary>
  431. /// Triggered when the user closes or expands a component foldout, making the component fields visible or hidden.
  432. /// </summary>
  433. /// <param name="inspectorData">Contains GUI data for the component that was toggled.</param>
  434. /// <param name="expanded">Determines whether to display or hide component contents.</param>
  435. private void OnComponentFoldoutToggled(InspectorComponent inspectorData, bool expanded)
  436. {
  437. inspectorData.expanded = expanded;
  438. inspectorData.inspector.SetVisible(expanded);
  439. }
  440. /// <summary>
  441. /// Triggered when the user clicks the component remove button. Removes that component from the active scene object.
  442. /// </summary>
  443. /// <param name="componentType">Type of the component to remove.</param>
  444. private void OnComponentRemoveClicked(Type componentType)
  445. {
  446. if (activeSO != null)
  447. {
  448. UndoRedo.RecordSO(activeSO, "Removed component " + componentType.Name);
  449. activeSO.RemoveComponent(componentType);
  450. }
  451. }
  452. /// <summary>
  453. /// Destroys all inspector GUI elements.
  454. /// </summary>
  455. internal void Clear()
  456. {
  457. for (int i = 0; i < inspectorComponents.Count; i++)
  458. {
  459. inspectorComponents[i].foldout.Destroy();
  460. inspectorComponents[i].removeBtn.Destroy();
  461. inspectorComponents[i].inspector.Destroy();
  462. }
  463. inspectorComponents.Clear();
  464. if (inspectorResource != null)
  465. {
  466. inspectorResource.inspector.Destroy();
  467. inspectorResource = null;
  468. }
  469. if (inspectorScrollArea != null)
  470. {
  471. inspectorScrollArea.Destroy();
  472. inspectorScrollArea = null;
  473. }
  474. if (scrollAreaHighlight != null)
  475. {
  476. scrollAreaHighlight.Destroy();
  477. scrollAreaHighlight = null;
  478. }
  479. if (highlightPanel != null)
  480. {
  481. highlightPanel.Destroy();
  482. highlightPanel = null;
  483. }
  484. activeSO = null;
  485. soNameInput = null;
  486. soPrefabLayout = null;
  487. soHasPrefab = false;
  488. soPosX = null;
  489. soPosY = null;
  490. soPosZ = null;
  491. soRotX = null;
  492. soRotY = null;
  493. soRotZ = null;
  494. soScaleX = null;
  495. soScaleY = null;
  496. soScaleZ = null;
  497. dropBounds = new Rect2I();
  498. sceneObjectLayout = null;
  499. activeResource = null;
  500. currentType = InspectorType.None;
  501. }
  502. /// <summary>
  503. /// Returns the size of the title bar area that is displayed for <see cref="SceneObject"/> specific fields.
  504. /// </summary>
  505. /// <returns>Area of the title bar, relative to the window.</returns>
  506. private Rect2I GetTitleBounds()
  507. {
  508. return new Rect2I(0, 0, Width, 115);
  509. }
  510. /// <summary>
  511. /// Triggered when the position value in the currently active <see cref="SceneObject"/> changes. Updates the
  512. /// necessary GUI elements.
  513. /// </summary>
  514. /// <param name="idx">Index of the coordinate that was changed.</param>
  515. /// <param name="value">New value of the field.</param>
  516. private void OnPositionChanged(int idx, float value)
  517. {
  518. if (activeSO == null)
  519. return;
  520. if (EditorApplication.ActiveCoordinateMode == HandleCoordinateMode.World)
  521. {
  522. Vector3 position = activeSO.Position;
  523. position[idx] = value;
  524. activeSO.Position = position;
  525. }
  526. else
  527. {
  528. Vector3 position = activeSO.LocalPosition;
  529. position[idx] = value;
  530. activeSO.LocalPosition = position;
  531. }
  532. }
  533. /// <summary>
  534. /// Triggered when the rotation value in the currently active <see cref="SceneObject"/> changes. Updates the
  535. /// necessary GUI elements.
  536. /// </summary>
  537. /// <param name="idx">Index of the euler angle that was changed (0 - X, 1 - Y, 2 - Z).</param>
  538. /// <param name="value">New value of the field.</param>
  539. private void OnRotationChanged(int idx, float value)
  540. {
  541. if (activeSO == null)
  542. return;
  543. if (EditorApplication.ActiveCoordinateMode == HandleCoordinateMode.World)
  544. {
  545. Vector3 angles = activeSO.Rotation.ToEuler();
  546. angles[idx] = value;
  547. activeSO.Rotation = Quaternion.FromEuler(angles);
  548. }
  549. else
  550. {
  551. Vector3 angles = activeSO.LocalRotation.ToEuler();
  552. angles[idx] = value;
  553. activeSO.LocalRotation = Quaternion.FromEuler(angles);
  554. }
  555. }
  556. /// <summary>
  557. /// Triggered when the scale value in the currently active <see cref="SceneObject"/> changes. Updates the
  558. /// necessary GUI elements.
  559. /// </summary>
  560. /// <param name="idx">Index of the coordinate that was changed.</param>
  561. /// <param name="value">New value of the field.</param>
  562. private void OnScaleChanged(int idx, float value)
  563. {
  564. if (activeSO == null)
  565. return;
  566. Vector3 scale = activeSO.LocalScale;
  567. scale[idx] = value;
  568. activeSO.LocalScale = scale;
  569. }
  570. /// <inheritdoc/>
  571. protected override void WindowResized(int width, int height)
  572. {
  573. base.WindowResized(width, height);
  574. if(inspectorScrollArea != null)
  575. dropBounds = inspectorScrollArea.Bounds;
  576. if (scrollAreaHighlight != null)
  577. scrollAreaHighlight.Bounds = dropBounds;
  578. }
  579. }
  580. }