PWBToolbar.cs 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483
  1. /*
  2. Copyright (c) 2020 Omar Duarte
  3. Unauthorized copying of this file, via any medium is strictly prohibited.
  4. Writen by Omar Duarte, 2020.
  5. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  6. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  7. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  8. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  9. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  10. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  11. THE SOFTWARE.
  12. */
  13. using UnityEngine;
  14. namespace PluginMaster
  15. {
  16. public class PWBToolbar : UnityEditor.EditorWindow
  17. {
  18. #region WINDOW
  19. private GUISkin _skin = null;
  20. private GUIStyle _btnStyle = null;
  21. private bool _wasDocked = false;
  22. private static PWBToolbar _instance = null;
  23. public static PWBToolbar instance => _instance;
  24. private Vector2 _mainScrollPosition = Vector2.zero;
  25. private const int MIN_SIZE = 32;
  26. private const int WIDTH = 556;
  27. private const int HEIGHT = 520;
  28. [UnityEditor.MenuItem("Tools/Plugin Master/Prefab World Builder/Toolbar...", false, 1100)]
  29. public static void ShowWindow()
  30. {
  31. #if UNITY_2021_2_OR_NEWER
  32. if (!UnityEditor.EditorUtility.DisplayDialog("Toolbar Overlays",
  33. "PWB tools are available as overlay panels in the scene view window (in Unity 2021.2 or higher). ",
  34. "Open toolbar anyway", "cancel")) return;
  35. #endif
  36. var isANewInstance = _instance == null;
  37. _instance = GetWindow<PWBToolbar>("Tools");
  38. if (isANewInstance) _instance.position = new Rect(_instance.position.x, _instance.position.y, WIDTH, MIN_SIZE);
  39. }
  40. public static void RepaintWindow()
  41. {
  42. if (_instance == null) return;
  43. _instance.Repaint();
  44. }
  45. public static void CloseWindow()
  46. {
  47. if (_instance != null) _instance.Close();
  48. }
  49. private void OnEnable()
  50. {
  51. _instance = this;
  52. _skin = Resources.Load<GUISkin>("PWBSkin");
  53. if (_skin == null) return;
  54. UnityEngine.Assertions.Assert.IsNotNull(_skin);
  55. _btnStyle = _skin.GetStyle("ToggleButton");
  56. _foldoutButtonStyle = new GUIStyle(_btnStyle);
  57. LoadToolIcons();
  58. LoadSnapIcons();
  59. LoadSelectionToolIcons();
  60. _axisButtonStyle = _skin.GetStyle("AxisButton");
  61. _radialAxisButtonStyle = new GUIStyle(_axisButtonStyle);
  62. _radialAxisButtonStyle.fixedWidth = 12;
  63. _buttonWithAxesStyle = new GUIStyle(_btnStyle);
  64. _buttonWithAxesStyle.margin.right = _buttonWithAxesStyle.margin.bottom = 0;
  65. _simpleBtnStyle = new GUIStyle(_btnStyle);
  66. _simpleBtnStyle.onNormal = _simpleBtnStyle.normal;
  67. minSize = new Vector2(MIN_SIZE, MIN_SIZE);
  68. _wasDocked = !isDocked;
  69. PWBIO.controlId = GUIUtility.GetControlID(GetHashCode(), FocusType.Passive);
  70. PWBIO.UpdateOctree();
  71. ToolManager.OnToolChange += OnToolChange;
  72. SnapManager.settings.OnDataChanged += Repaint;
  73. }
  74. private void OnDisable()
  75. {
  76. ToolManager.OnToolChange -= OnToolChange;
  77. SnapManager.settings.OnDataChanged -= Repaint;
  78. ToolManager.DeselectTool();
  79. }
  80. private void OnDestroy()
  81. {
  82. if (PWBCore.staticData.closeAllWindowsWhenClosingTheToolbar) PWBIO.CloseAllWindows(false);
  83. }
  84. private void OnGUI()
  85. {
  86. if (_skin == null)
  87. {
  88. Close();
  89. return;
  90. }
  91. #if UNITY_2019_1_OR_NEWER
  92. UpdateShortcutsTooltips();
  93. #endif
  94. bool widthGreaterThanHeight = position.width > position.height;
  95. UpdateFoldoutButtonStyle();
  96. using (var scrollView = new UnityEditor.EditorGUILayout.ScrollViewScope(_mainScrollPosition, false, false,
  97. widthGreaterThanHeight ? GUI.skin.horizontalScrollbar : GUIStyle.none,
  98. widthGreaterThanHeight ? GUIStyle.none : GUI.skin.verticalScrollbar, GUIStyle.none))
  99. {
  100. _mainScrollPosition = scrollView.scrollPosition;
  101. using (position.width > position.height
  102. ? (GUI.Scope)new GUILayout.HorizontalScope(_skin.box)
  103. : (GUI.Scope)new GUILayout.VerticalScope(_skin.box))
  104. {
  105. _axisButtonStyle.fixedHeight = widthGreaterThanHeight ? 24 : 12;
  106. _radialAxisButtonStyle.fixedHeight = _axisButtonStyle.fixedHeight;
  107. ToolsGUI();
  108. GUILayout.Space(5);
  109. SnapGUI();
  110. GUILayout.Space(5);
  111. if (GUILayout.Button(_helpIcon, _btnStyle)) PWBCore.OpenDocFile();
  112. GUILayout.FlexibleSpace();
  113. }
  114. }
  115. }
  116. private void Update()
  117. {
  118. if (_wasDocked && !isDocked)
  119. {
  120. var size = position.width >= position.height ? new Vector2(WIDTH, MIN_SIZE) : new Vector2(MIN_SIZE, HEIGHT);
  121. position = new Rect(position.position, size);
  122. _wasDocked = false;
  123. }
  124. else if (!_wasDocked && isDocked) _wasDocked = true;
  125. }
  126. private bool isDocked
  127. {
  128. get
  129. {
  130. var isDockedMethod = typeof(UnityEditor.EditorWindow).GetProperty("docked",
  131. System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic
  132. | System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Static).GetGetMethod(true);
  133. return (bool)isDockedMethod.Invoke(this, null);
  134. }
  135. }
  136. private void UpdateFoldoutButtonStyle()
  137. {
  138. if (position.width >= position.height)
  139. {
  140. _foldoutButtonStyle.fixedWidth = 16;
  141. _foldoutButtonStyle.fixedHeight = 24;
  142. }
  143. else
  144. {
  145. _foldoutButtonStyle.fixedWidth = 24;
  146. _foldoutButtonStyle.fixedHeight = 16;
  147. }
  148. }
  149. #if UNITY_2019_1_OR_NEWER
  150. private void UpdateShortcutsTooltips()
  151. {
  152. void UpdateTooltipShortcut(GUIContent button, string tooltip, string keyCombination)
  153. {
  154. if (keyCombination != string.Empty) button.tooltip = tooltip + " ... " + keyCombination;
  155. }
  156. UpdateTooltipShortcut(_floorIcon, "Floor", PWBSettings.shortcuts.toolbarFloorToggle.combination.ToString());
  157. UpdateTooltipShortcut(_wallIcon, "Wall", PWBSettings.shortcuts.toolbarWallToggle.combination.ToString());
  158. UpdateTooltipShortcut(_pinIcon, "Pin", PWBSettings.shortcuts.toolbarPinToggle.combination.ToString());
  159. UpdateTooltipShortcut(_brushIcon, "Brush", PWBSettings.shortcuts.toolbarBrushToggle.combination.ToString());
  160. UpdateTooltipShortcut(_eraserIcon, "Eraser", PWBSettings.shortcuts.toolbarEraserToggle.combination.ToString());
  161. UpdateTooltipShortcut(_physicsIcon, "Gravity Brush",
  162. PWBSettings.shortcuts.toolbarGravityToggle.combination.ToString());
  163. UpdateTooltipShortcut(_extrudeIcon, "Extrude", PWBSettings.shortcuts.toolbarExtrudeToggle.combination.ToString());
  164. UpdateTooltipShortcut(_lineIcon, "Line", PWBSettings.shortcuts.toolbarLineToggle.combination.ToString());
  165. UpdateTooltipShortcut(_shapeIcon, "Shape", PWBSettings.shortcuts.toolbarShapeToggle.combination.ToString());
  166. UpdateTooltipShortcut(_tilingIcon, "Tiling", PWBSettings.shortcuts.toolbarTilingToggle.combination.ToString());
  167. UpdateTooltipShortcut(_selectionIcon, "Selection",
  168. PWBSettings.shortcuts.toolbarSelectionToggle.combination.ToString());
  169. UpdateTooltipShortcut(_selectionIcon, "Circle Selection",
  170. PWBSettings.shortcuts.toolbarCircleSelectToggle.combination.ToString());
  171. UpdateTooltipShortcut(_mirrorIcon, "Mirror", PWBSettings.shortcuts.toolbarMirrorToggle.combination.ToString());
  172. UpdateTooltipShortcut(_lockGridIcon, "Lock the grid origin in place",
  173. PWBSettings.shortcuts.gridToggleLock.combination.ToString());
  174. UpdateTooltipShortcut(_unlockGridIcon, "Unlock the grid origin",
  175. PWBSettings.shortcuts.gridToggleLock.combination.ToString());
  176. }
  177. #endif
  178. #endregion
  179. #region TOOLS
  180. private GUIContent _floorIcon = null;
  181. private GUIContent _wallIcon = null;
  182. private GUIContent _pinIcon = null;
  183. private GUIContent _brushIcon = null;
  184. private GUIContent _eraserIcon = null;
  185. private GUIContent _physicsIcon = null;
  186. private GUIContent _extrudeIcon = null;
  187. private GUIContent _lineIcon = null;
  188. private GUIContent _shapeIcon = null;
  189. private GUIContent _tilingIcon = null;
  190. private GUIContent _selectionIcon = null;
  191. private GUIContent _circleSelectIcon = null;
  192. private GUIContent _mirrorIcon = null;
  193. private GUIContent _replaceIcon = null;
  194. private GUIContent _helpIcon = null;
  195. private GUIContent _propertiesIcon = null;
  196. private bool _toolChanged = false;
  197. private void OnToolChange(ToolManager.PaintTool prevTool)
  198. {
  199. _toolChanged = true;
  200. PWBIO.OnToolChange(prevTool);
  201. }
  202. private void LoadToolIcons()
  203. {
  204. _floorIcon = new GUIContent(Resources.Load<Texture2D>("Sprites/Floors"), "Floor");
  205. _wallIcon = new GUIContent(Resources.Load<Texture2D>("Sprites/Walls"), "Wall");
  206. _pinIcon = new GUIContent(Resources.Load<Texture2D>("Sprites/Pin"), "Pin");
  207. _brushIcon = new GUIContent(Resources.Load<Texture2D>("Sprites/Brush"), "Brush");
  208. _eraserIcon = new GUIContent(Resources.Load<Texture2D>("Sprites/Eraser"), "Eraser");
  209. _physicsIcon = new GUIContent(Resources.Load<Texture2D>("Sprites/GravityTool"), "Gravity Brush");
  210. _extrudeIcon = new GUIContent(Resources.Load<Texture2D>("Sprites/Extrude"), "Extrude");
  211. _lineIcon = new GUIContent(Resources.Load<Texture2D>("Sprites/Line"), "Line");
  212. _shapeIcon = new GUIContent(Resources.Load<Texture2D>("Sprites/Shape"), "Shape");
  213. _tilingIcon = new GUIContent(Resources.Load<Texture2D>("Sprites/Tiling"), "Tiling");
  214. _selectionIcon = new GUIContent(Resources.Load<Texture2D>("Sprites/Selection"), "Selection");
  215. _circleSelectIcon = new GUIContent(Resources.Load<Texture2D>("Sprites/CircleSelect"), "Circle Select");
  216. _mirrorIcon = new GUIContent(Resources.Load<Texture2D>("Sprites/Mirror"), "Mirror");
  217. _replaceIcon = new GUIContent(Resources.Load<Texture2D>("Sprites/Replace"), "Replacer");
  218. _helpIcon = new GUIContent(Resources.Load<Texture2D>("Sprites/Help"), "Documentation");
  219. _propertiesIcon = new GUIContent(Resources.Load<Texture2D>("Sprites/ToolProperties"), "Tool Properties");
  220. }
  221. private void ToolsGUI()
  222. {
  223. using (var check = new UnityEditor.EditorGUI.ChangeCheckScope())
  224. {
  225. var newtool = ToolManager.tool;
  226. var floorSelected = newtool == ToolManager.PaintTool.FLOOR;
  227. newtool = (GUILayout.Toggle(floorSelected, _floorIcon, _btnStyle)
  228. ? ToolManager.PaintTool.FLOOR : (floorSelected ? ToolManager.PaintTool.NONE : newtool));
  229. var wallSelected = newtool == ToolManager.PaintTool.WALL;
  230. newtool = (GUILayout.Toggle(wallSelected, _wallIcon, _btnStyle)
  231. ? ToolManager.PaintTool.WALL : (wallSelected ? ToolManager.PaintTool.NONE : newtool));
  232. GUILayout.Space(5);
  233. var pinSelected = newtool == ToolManager.PaintTool.PIN;
  234. newtool = (GUILayout.Toggle(pinSelected, _pinIcon, _btnStyle)
  235. ? ToolManager.PaintTool.PIN : (pinSelected ? ToolManager.PaintTool.NONE : newtool));
  236. var brushSelected = newtool == ToolManager.PaintTool.BRUSH;
  237. newtool = (GUILayout.Toggle(brushSelected, _brushIcon, _btnStyle)
  238. ? ToolManager.PaintTool.BRUSH : (brushSelected ? ToolManager.PaintTool.NONE : newtool));
  239. var gravitySelected = newtool == ToolManager.PaintTool.GRAVITY;
  240. newtool = (GUILayout.Toggle(gravitySelected, _physicsIcon, _btnStyle)
  241. ? ToolManager.PaintTool.GRAVITY : (gravitySelected ? ToolManager.PaintTool.NONE : newtool));
  242. var lineSelected = newtool == ToolManager.PaintTool.LINE;
  243. newtool = (GUILayout.Toggle(lineSelected, _lineIcon, _btnStyle)
  244. ? ToolManager.PaintTool.LINE : (lineSelected ? ToolManager.PaintTool.NONE : newtool));
  245. var shapeSelected = newtool == ToolManager.PaintTool.SHAPE;
  246. newtool = (GUILayout.Toggle(shapeSelected, _shapeIcon, _btnStyle)
  247. ? ToolManager.PaintTool.SHAPE : (shapeSelected ? ToolManager.PaintTool.NONE : newtool));
  248. var tilingSelected = newtool == ToolManager.PaintTool.TILING;
  249. newtool = (GUILayout.Toggle(tilingSelected, _tilingIcon, _btnStyle)
  250. ? ToolManager.PaintTool.TILING : (tilingSelected ? ToolManager.PaintTool.NONE : newtool));
  251. var replaceSelected = newtool == ToolManager.PaintTool.REPLACER;
  252. newtool = (GUILayout.Toggle(replaceSelected, _replaceIcon, _btnStyle)
  253. ? ToolManager.PaintTool.REPLACER : (replaceSelected ? ToolManager.PaintTool.NONE : newtool));
  254. var eraserSelected = newtool == ToolManager.PaintTool.ERASER;
  255. newtool = (GUILayout.Toggle(eraserSelected, _eraserIcon, _btnStyle)
  256. ? ToolManager.PaintTool.ERASER : (eraserSelected ? ToolManager.PaintTool.NONE : newtool));
  257. GUILayout.Space(5);
  258. if (GUILayout.Button(_propertiesIcon, _btnStyle)) ToolProperties.ShowWindow();
  259. GUILayout.Space(5);
  260. var selectionSelected = newtool == ToolManager.PaintTool.SELECTION;
  261. newtool = (GUILayout.Toggle(selectionSelected, _selectionIcon, _buttonWithAxesStyle)
  262. ? ToolManager.PaintTool.SELECTION : (selectionSelected ? ToolManager.PaintTool.NONE : newtool));
  263. GUILayout.Space(1);
  264. bool TRSChanged = false;
  265. using (new UnityEditor.EditorGUI.DisabledGroupScope(!selectionSelected))
  266. {
  267. using (new GUILayout.HorizontalScope())
  268. {
  269. using (var checkTRS = new UnityEditor.EditorGUI.ChangeCheckScope())
  270. {
  271. SelectionToolManager.settings.move = GUILayout.Toggle(SelectionToolManager.settings.move,
  272. _tIcon, _axisButtonStyle);
  273. SelectionToolManager.settings.rotate = GUILayout.Toggle(SelectionToolManager.settings.rotate,
  274. _rIcon, _axisButtonStyle);
  275. SelectionToolManager.settings.scale = GUILayout.Toggle(SelectionToolManager.settings.scale,
  276. _sIcon, _axisButtonStyle);
  277. if (checkTRS.changed)
  278. {
  279. TRSChanged = true;
  280. UnityEditor.SceneView.RepaintAll();
  281. ToolProperties.RepainWindow();
  282. }
  283. }
  284. }
  285. }
  286. var circleSelectSelected = newtool == ToolManager.PaintTool.CIRCLE_SELECT;
  287. newtool = (GUILayout.Toggle(circleSelectSelected, _circleSelectIcon, _btnStyle)
  288. ? ToolManager.PaintTool.CIRCLE_SELECT : (circleSelectSelected ? ToolManager.PaintTool.NONE : newtool));
  289. var extrudeSelected = newtool == ToolManager.PaintTool.EXTRUDE;
  290. newtool = (GUILayout.Toggle(extrudeSelected, _extrudeIcon, _btnStyle)
  291. ? ToolManager.PaintTool.EXTRUDE : (extrudeSelected ? ToolManager.PaintTool.NONE : newtool));
  292. var mirrorSelected = newtool == ToolManager.PaintTool.MIRROR;
  293. newtool = (GUILayout.Toggle(mirrorSelected, _mirrorIcon, _btnStyle)
  294. ? ToolManager.PaintTool.MIRROR : (mirrorSelected ? ToolManager.PaintTool.NONE : newtool));
  295. if ((check.changed || _toolChanged) && !TRSChanged)
  296. {
  297. _toolChanged = false;
  298. ToolManager.tool = newtool;
  299. }
  300. }
  301. }
  302. #endregion
  303. #region SELECTION TOOL
  304. private GUIContent _tIcon = null;
  305. private GUIContent _rIcon = null;
  306. private GUIContent _sIcon = null;
  307. private void LoadSelectionToolIcons()
  308. {
  309. _tIcon = new GUIContent(Resources.Load<Texture2D>("Sprites/T"));
  310. _rIcon = new GUIContent(Resources.Load<Texture2D>("Sprites/R"));
  311. _sIcon = new GUIContent(Resources.Load<Texture2D>("Sprites/S"));
  312. }
  313. #endregion
  314. #region SNAP
  315. private GUIContent _showGridIcon = null;
  316. private GUIContent _enableSnappingIcon = null;
  317. private GUIContent _lockGridIcon = null;
  318. private GUIContent _unlockGridIcon = null;
  319. private GUIContent _snapSettingsIcon = null;
  320. private GUIContent _gridIcon = null;
  321. private GUIContent _radialGridIcon = null;
  322. private GUIContent _xIcon = null;
  323. private GUIContent _yIcon = null;
  324. private GUIContent _zIcon = null;
  325. private GUIStyle _axisButtonStyle = null;
  326. private GUIStyle _buttonWithAxesStyle = null;
  327. private GUIStyle _simpleBtnStyle = null;
  328. private GUIStyle _radialAxisButtonStyle = null;
  329. private GUIContent _cIcon = null;
  330. private bool _showGridTools = true;
  331. private GUIContent _showGridToolsIcon = null;
  332. private GUIContent _hideGridToolsIcon = null;
  333. private GUIContent _showGridToolsHIcon = null;
  334. private GUIContent _hideGridToolsHIcon = null;
  335. private GUIStyle _foldoutButtonStyle = null;
  336. private void LoadSnapIcons()
  337. {
  338. _showGridIcon = new GUIContent(Resources.Load<Texture2D>("Sprites/ShowGrid"), "Show grid");
  339. _enableSnappingIcon = new GUIContent(Resources.Load<Texture2D>("Sprites/SnapOn"), "Enable snapping");
  340. _lockGridIcon = new GUIContent(Resources.Load<Texture2D>("Sprites/LockGrid"),
  341. "Lock the grid origin in place");
  342. _unlockGridIcon = new GUIContent(Resources.Load<Texture2D>("Sprites/UnlockGrid"),
  343. "Unlock the grid origin");
  344. _snapSettingsIcon = new GUIContent(Resources.Load<Texture2D>("Sprites/SnapSettings"),
  345. "Grid and Snapping Settings");
  346. _gridIcon = new GUIContent(Resources.Load<Texture2D>("Sprites/Grid"), "Grid");
  347. _radialGridIcon = new GUIContent(Resources.Load<Texture2D>("Sprites/RadialGrid"), "Radial Grid");
  348. _xIcon = new GUIContent(Resources.Load<Texture2D>("Sprites/X"));
  349. _yIcon = new GUIContent(Resources.Load<Texture2D>("Sprites/Y"));
  350. _zIcon = new GUIContent(Resources.Load<Texture2D>("Sprites/Z"));
  351. _cIcon = new GUIContent(Resources.Load<Texture2D>("Sprites/C"));
  352. _showGridToolsIcon = new GUIContent(Resources.Load<Texture2D>("Sprites/ShowGridTools"));
  353. _hideGridToolsIcon = new GUIContent(Resources.Load<Texture2D>("Sprites/HideGridTools"));
  354. _showGridToolsHIcon = new GUIContent(Resources.Load<Texture2D>("Sprites/ShowGridToolsH"));
  355. _hideGridToolsHIcon = new GUIContent(Resources.Load<Texture2D>("Sprites/HideGridToolsH"));
  356. }
  357. private void SnapGUI()
  358. {
  359. var foldoutIcon = position.width > position.height
  360. ? _showGridTools ? _hideGridToolsHIcon : _showGridToolsHIcon
  361. : _showGridTools ? _hideGridToolsIcon : _showGridToolsIcon;
  362. if (!_showGridTools) if (GUILayout.Button(foldoutIcon, _foldoutButtonStyle)) _showGridTools = true;
  363. if (!_showGridTools) return;
  364. var settings = SnapManager.settings;
  365. using (var check = new UnityEditor.EditorGUI.ChangeCheckScope())
  366. {
  367. settings.radialGridEnabled = GUILayout.Toggle(settings.radialGridEnabled,
  368. settings.radialGridEnabled ? _gridIcon : _radialGridIcon, _simpleBtnStyle);
  369. if (check.changed) SnapSettingsWindow.RepaintWindow();
  370. }
  371. settings.snappingEnabled = GUILayout.Toggle(settings.snappingEnabled,
  372. _enableSnappingIcon, _buttonWithAxesStyle);
  373. GUILayout.Space(1);
  374. using (new UnityEditor.EditorGUI.DisabledGroupScope(!settings.snappingEnabled))
  375. {
  376. using (new GUILayout.HorizontalScope())
  377. {
  378. if (settings.radialGridEnabled)
  379. {
  380. settings.snapToRadius = GUILayout.Toggle(settings.snapToRadius,
  381. _rIcon, position.width > position.height ? _axisButtonStyle : _radialAxisButtonStyle);
  382. settings.snapToCircunference = GUILayout.Toggle(settings.snapToCircunference,
  383. _cIcon, position.width > position.height ? _axisButtonStyle : _radialAxisButtonStyle);
  384. }
  385. else
  386. {
  387. settings.snappingOnX = GUILayout.Toggle(settings.snappingOnX,
  388. _xIcon, _axisButtonStyle);
  389. SnapManager.settings.snappingOnY = GUILayout.Toggle(settings.snappingOnY,
  390. _yIcon, _axisButtonStyle);
  391. settings.snappingOnZ = GUILayout.Toggle(settings.snappingOnZ,
  392. _zIcon, _axisButtonStyle);
  393. }
  394. }
  395. }
  396. settings.visibleGrid = GUILayout.Toggle(settings.visibleGrid,
  397. _showGridIcon, _buttonWithAxesStyle);
  398. GUILayout.Space(1);
  399. using (new UnityEditor.EditorGUI.DisabledGroupScope(!settings.visibleGrid))
  400. {
  401. using (new GUILayout.HorizontalScope())
  402. {
  403. using (var check = new UnityEditor.EditorGUI.ChangeCheckScope())
  404. {
  405. var showGridX = GUILayout.Toggle(settings.gridOnX, _xIcon, _axisButtonStyle);
  406. if (check.changed && showGridX) settings.gridOnX = showGridX;
  407. }
  408. using (var check = new UnityEditor.EditorGUI.ChangeCheckScope())
  409. {
  410. var showGridY = GUILayout.Toggle(settings.gridOnY, _yIcon, _axisButtonStyle);
  411. if (check.changed && showGridY) settings.gridOnY = showGridY;
  412. }
  413. using (var check = new UnityEditor.EditorGUI.ChangeCheckScope())
  414. {
  415. var showGridZ = GUILayout.Toggle(settings.gridOnZ, _zIcon, _axisButtonStyle);
  416. if (check.changed && showGridZ) settings.gridOnZ = showGridZ;
  417. }
  418. }
  419. }
  420. using (var check = new UnityEditor.EditorGUI.ChangeCheckScope())
  421. {
  422. settings.lockedGrid = GUILayout.Toggle(settings.lockedGrid,
  423. settings.lockedGrid ? _lockGridIcon : _unlockGridIcon, _btnStyle);
  424. if (check.changed) SnapSettingsWindow.RepaintWindow();
  425. }
  426. if (GUILayout.Button(_snapSettingsIcon, _btnStyle)) SnapSettingsWindow.ShowWindow();
  427. if (GUILayout.Button(foldoutIcon, _foldoutButtonStyle)) _showGridTools = false;
  428. }
  429. #endregion
  430. }
  431. }