EnhancedHierarchy.cs 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using UnityEditor;
  6. using UnityEngine;
  7. using Object = UnityEngine.Object;
  8. namespace EnhancedHierarchy
  9. {
  10. /// <summary>
  11. /// Main class, draws hierarchy items.
  12. /// </summary>
  13. [InitializeOnLoad]
  14. public static partial class EnhancedHierarchy
  15. {
  16. private static MiniLabelProvider[] MiniLabelProviders
  17. {
  18. get { return Preferences.miniLabelProviders; }
  19. }
  20. static EnhancedHierarchy()
  21. {
  22. if (Preferences.DebugEnabled || Preferences.ProfilingEnabled)
  23. {
  24. Utility.EnableFPSCounter();
  25. Utility.ForceUpdateHierarchyEveryFrame();
  26. }
  27. EditorApplication.hierarchyWindowItemOnGUI += SetItemInformation;
  28. EditorApplication.hierarchyWindowItemOnGUI += OnItemGUI;
  29. EditorApplication.RepaintHierarchyWindow();
  30. }
  31. private static void OnItemGUI(int id, Rect rect)
  32. {
  33. if (!Preferences.Enabled)
  34. return;
  35. bool isActivie = EditorPrefs.GetBool("isActiveObjectTool", false);
  36. if (!isActivie)
  37. {
  38. return;
  39. }
  40. using (ProfilerSample.Get("Enhanced Hierarchy"))
  41. try
  42. {
  43. if (IsGameObject)
  44. {
  45. for (var i = 0; i < Preferences.RightIcons.Value.Count; i++)
  46. Preferences.RightIcons.Value[i].SafeInit();
  47. for (var i = 0; i < Preferences.LeftIcons.Value.Count; i++)
  48. Preferences.LeftIcons.Value[i].SafeInit();
  49. Preferences.LeftSideButton.SafeInit();
  50. for (var i = 0; i < MiniLabelProviders.Length; i++)
  51. {
  52. MiniLabelProviders[i].Init();
  53. }
  54. }
  55. if (IsFirstVisible && Reflected.HierarchyArea.Supported)
  56. {
  57. Reflected.HierarchyArea.IndentWidth = Preferences.Indent;
  58. Reflected.HierarchyArea.BaseIndent = Preferences.LeftMargin;
  59. }
  60. //SetTitle("EH 2.0");
  61. CalculateIconsWidth();
  62. DoSelection(RawRect);
  63. IgnoreLockedSelection();
  64. DrawTree(RawRect);
  65. ChildToggle();
  66. var trailingWidth = DoTrailing();
  67. DrawHover();
  68. ColorSort(RawRect);
  69. DrawLeftSideIcons(RawRect);
  70. DrawTooltip(RawRect, trailingWidth);
  71. if (Reflected.IconWidthSupported)
  72. Reflected.IconWidth = Preferences.DisableNativeIcon ? 0 : 16;
  73. if (IsGameObject)
  74. {
  75. rect.xMax -= Preferences.RightMargin;
  76. rect.xMin = rect.xMax;
  77. rect.y++;
  78. for (var i = 0; i < Preferences.RightIcons.Value.Count; i++)
  79. using (new GUIBackgroundColor(Styles.backgroundColorEnabled))
  80. {
  81. var icon = Preferences.RightIcons.Value[i];
  82. rect.xMin -= icon.SafeGetWidth();
  83. icon.SafeDoGUI(rect);
  84. rect.xMax -= icon.SafeGetWidth();
  85. }
  86. var leftSideRect = RawRect;
  87. if (Preferences.LeftmostButton)
  88. leftSideRect.xMin = 0f;
  89. else
  90. leftSideRect.xMin -= 2f + CurrentGameObject.transform.childCount > 0 || Preferences.TreeOpacity > ALPHA_THRESHOLD ? 30f : 18f;
  91. leftSideRect.xMax = leftSideRect.xMin + Preferences.LeftSideButton.SafeGetWidth();
  92. using (new GUIBackgroundColor(Styles.backgroundColorEnabled))
  93. Preferences.LeftSideButton.SafeDoGUI(leftSideRect);
  94. }
  95. DrawMiniLabel(ref rect);
  96. DrawHorizontalSeparator(RawRect);
  97. }
  98. catch (Exception e)
  99. {
  100. Utility.LogException(e);
  101. }
  102. }
  103. private static void DrawHover()
  104. {
  105. if (Reflected.NativeHierarchyHoverTintSupported)
  106. {
  107. if (IsFirstVisible && IsRepaintEvent)
  108. Reflected.NativeHierarchyHoverTint = Preferences.HoverTintColor;
  109. return;
  110. }
  111. var tint = Preferences.HoverTintColor.Value;
  112. if (IsFirstVisible && Reflected.NativeHierarchyHoverTintSupported)
  113. Reflected.HierarchyWindowInstance.wantsMouseMove = tint.a >= ALPHA_THRESHOLD;
  114. if (tint.a < ALPHA_THRESHOLD)
  115. return;
  116. if (!Utility.ShouldCalculateTooltipAt(FullSizeRect))
  117. return;
  118. if (IsRepaintEvent)
  119. EditorGUI.DrawRect(FullSizeRect, tint);
  120. switch (Event.current.type)
  121. {
  122. case EventType.MouseMove:
  123. Event.current.Use();
  124. break;
  125. }
  126. }
  127. private static void IgnoreLockedSelection()
  128. {
  129. if (Preferences.AllowSelectingLockedObjects || !IsFirstVisible || !IsRepaintEvent)
  130. return;
  131. using (ProfilerSample.Get())
  132. {
  133. var selection = Selection.objects;
  134. var changed = false;
  135. for (var i = 0; i < selection.Length; i++)
  136. if (selection[i] is GameObject && (selection[i].hideFlags & HideFlags.NotEditable) != 0 && !EditorUtility.IsPersistent(selection[i]))
  137. {
  138. selection[i] = null;
  139. changed = true;
  140. }
  141. if (changed)
  142. {
  143. Selection.objects = selection;
  144. Reflected.SetHierarchySelectionNeedSync();
  145. EditorApplication.RepaintHierarchyWindow();
  146. }
  147. }
  148. }
  149. private static void ChildToggle()
  150. {
  151. using (ProfilerSample.Get())
  152. {
  153. if (!Preferences.NumericChildExpand || !IsRepaintEvent || !IsGameObject || CurrentGameObject.transform.childCount <= 0)
  154. return;
  155. var rect = RawRect;
  156. var childString = CurrentGameObject.transform.childCount.ToString("00");
  157. var expanded = Reflected.GetTransformIsExpanded(CurrentGameObject);
  158. rect.xMax = rect.xMin - 1f;
  159. rect.xMin -= 15f;
  160. if (childString.Length > 2)
  161. rect.xMin -= 4f;
  162. using (new GUIBackgroundColor(Styles.childToggleColor))
  163. Styles.newToggleStyle.Draw(rect, Utility.GetTempGUIContent(childString), false, false, expanded, false);
  164. }
  165. }
  166. private static void DrawHorizontalSeparator(Rect rect)
  167. {
  168. if (Preferences.LineSize < 1 || Preferences.LineColor.Value.a <= ALPHA_THRESHOLD || !IsRepaintEvent)
  169. return;
  170. using (ProfilerSample.Get())
  171. {
  172. rect.xMin = 0f;
  173. rect.xMax = rect.xMax + 50f;
  174. rect.yMin -= Preferences.LineSize / 2;
  175. rect.yMax = rect.yMin + Preferences.LineSize;
  176. EditorGUI.DrawRect(rect, Preferences.LineColor);
  177. if (!IsFirstVisible)
  178. return;
  179. rect.y = FinalRect.y - Preferences.LineSize / 2;
  180. var height = Reflected.HierarchyWindowInstance.position.height;
  181. var count = (height - FinalRect.y) / FinalRect.height;
  182. if (FinalRect.height <= 0f)
  183. count = 100f;
  184. for (var i = 0; i < count; i++)
  185. {
  186. rect.y += RawRect.height;
  187. EditorGUI.DrawRect(rect, Preferences.LineColor);
  188. }
  189. }
  190. }
  191. private static void ColorSort(Rect rect)
  192. {
  193. if (!IsRepaintEvent)
  194. return;
  195. using (ProfilerSample.Get())
  196. {
  197. rect.xMin = 0f;
  198. rect.xMax = rect.xMax + 50f;
  199. var rowTint = GetRowTint();
  200. var rowCustomTint = GetRowCustomTint();
  201. if (rowCustomTint.color.a > ALPHA_THRESHOLD)
  202. using (new GUIColor(rowCustomTint.color))
  203. {
  204. switch (rowCustomTint.mode)
  205. {
  206. case TintMode.Flat:
  207. EditorGUI.DrawRect(rect, Color.white);
  208. break;
  209. case TintMode.GradientLeftToRight:
  210. GUI.DrawTexture(Utility.FlipRectHorizontally(rect), Styles.fadeTexture, ScaleMode.StretchToFill);
  211. break;
  212. case TintMode.GradientRightToLeft:
  213. GUI.DrawTexture(rect, Styles.fadeTexture, ScaleMode.StretchToFill);
  214. break;
  215. }
  216. }
  217. if (rowTint.a > ALPHA_THRESHOLD)
  218. EditorGUI.DrawRect(rect, rowTint);
  219. if (!IsFirstVisible)
  220. return;
  221. rect.y = FinalRect.y;
  222. var height = Reflected.HierarchyWindowInstance.position.height;
  223. var count = (height - FinalRect.y) / FinalRect.height;
  224. if (FinalRect.height <= 0f)
  225. count = 100f;
  226. for (var i = 0; i < count; i++)
  227. {
  228. rect.y += RawRect.height;
  229. rowTint = GetRowTint(rect);
  230. if (rowTint.a > ALPHA_THRESHOLD)
  231. EditorGUI.DrawRect(rect, rowTint);
  232. }
  233. }
  234. }
  235. private static void DrawTree(Rect rect)
  236. {
  237. if (Preferences.TreeOpacity <= ALPHA_THRESHOLD || !IsGameObject)
  238. return;
  239. if (!IsRepaintEvent && !Preferences.SelectOnTree)
  240. return;
  241. using (ProfilerSample.Get())
  242. using (new GUIColor(Utility.GetHierarchyColor(CurrentGameObject.transform.parent), Preferences.TreeOpacity))
  243. {
  244. var indent = Reflected.HierarchyArea.Supported ? Reflected.HierarchyArea.IndentWidth : 16f;
  245. // #42 - Jules: pull back indent one level and neatly align tree lines with expansion arrow tips
  246. rect.x -= indent + 2f;
  247. rect.xMin -= 14f;
  248. rect.xMax = rect.xMin + 14f;
  249. // #42 - Jules: allow showing of stems for container objects
  250. if (CurrentGameObject.transform.parent)
  251. {
  252. var lastInHierarchy = Utility.TransformIsLastChild(CurrentGameObject.transform);
  253. GUI.DrawTexture(rect, lastInHierarchy ? Styles.treeElbowTexture : Styles.treeTeeTexture);
  254. /*
  255. #42 - Jules: add short horizontal line to extend stem if there's no expansion triangle.
  256. NOTE: Please make this value into a slider in the preferences, since it's arguably a bad thing to have it.
  257. It looks "nicer" with extended stems but is less clear since it throws off the stem alignments.
  258. At a value of 1 this can make things look an entire level off of where they truly are relative to other things!!!
  259. I think 0.5 is an okay compromise, but 0 is the most consistent, which means no extra stem line at all.
  260. So it's the sort of thing where people might have different ideas of what's best for them...
  261. */
  262. var extendStemProportion = CurrentGameObject.transform.childCount == 0 ? Preferences.TreeStemProportion.Value * indent : indent - 14f;
  263. if (extendStemProportion > 0.01f)
  264. {
  265. var extendedStemRect = new Rect(rect.x + rect.size.x, rect.y + (lastInHierarchy ? 9f : 8f), extendStemProportion, 1f);
  266. EditorGUI.DrawRect(extendedStemRect, Color.white);
  267. }
  268. if (Preferences.SelectOnTree && GUI.Button(rect, GUIContent.none, Styles.labelNormal))
  269. Selection.activeTransform = CurrentGameObject.transform.parent;
  270. }
  271. var currentTransform = CurrentGameObject.transform.parent;
  272. for (rect.x -= indent; rect.xMin > 0f && currentTransform && currentTransform.parent; rect.x -= indent)
  273. {
  274. if (!Utility.TransformIsLastChild(currentTransform))
  275. using (new GUIColor(Utility.GetHierarchyColor(currentTransform.parent), Preferences.TreeOpacity))
  276. {
  277. GUI.DrawTexture(rect, Styles.treeLineTexture);
  278. if (Preferences.SelectOnTree && GUI.Button(rect, GUIContent.none, Styles.labelNormal))
  279. Selection.activeTransform = currentTransform.parent;
  280. }
  281. currentTransform = currentTransform.parent;
  282. }
  283. }
  284. }
  285. private static void CalculateIconsWidth()
  286. {
  287. using (ProfilerSample.Get())
  288. {
  289. LeftIconsWidth = 0f;
  290. RightIconsWidth = 0f;
  291. if (!IsGameObject)
  292. return;
  293. for (var i = 0; i < Preferences.RightIcons.Value.Count; i++)
  294. RightIconsWidth += Preferences.RightIcons.Value[i].SafeGetWidth();
  295. for (var i = 0; i < Preferences.LeftIcons.Value.Count; i++)
  296. LeftIconsWidth += Preferences.LeftIcons.Value[i].SafeGetWidth();
  297. }
  298. }
  299. private static void DrawLeftSideIcons(Rect rect)
  300. {
  301. if (!IsGameObject)
  302. return;
  303. using (ProfilerSample.Get())
  304. {
  305. rect.xMin += LabelSize;
  306. rect.xMin = Math.Min(rect.xMax - RightIconsWidth - LeftIconsWidth - CalcMiniLabelSize() - 5f - Preferences.RightMargin, rect.xMin);
  307. for (var i = 0; i < Preferences.LeftIcons.Value.Count; i++)
  308. using (new GUIBackgroundColor(Styles.backgroundColorEnabled))
  309. {
  310. var icon = Preferences.LeftIcons.Value[i];
  311. rect.xMax = rect.xMin + icon.SafeGetWidth();
  312. icon.SafeDoGUI(rect);
  313. rect.xMin = rect.xMax;
  314. }
  315. }
  316. }
  317. private static float DoTrailing()
  318. {
  319. if (!IsRepaintEvent || !Preferences.Trailing || !IsGameObject)
  320. return RawRect.xMax;
  321. using (ProfilerSample.Get())
  322. {
  323. var size = LabelSize; // CurrentStyle.CalcSize(Utility.GetTempGUIContent(GameObjectName)).x;
  324. var iconsWidth = RightIconsWidth + LeftIconsWidth + CalcMiniLabelSize() + Preferences.RightMargin;
  325. var iconsMin = FullSizeRect.xMax - iconsWidth;
  326. var labelMax = LabelOnlyRect.xMax;
  327. var overlapping = iconsMin <= labelMax;
  328. if (!overlapping)
  329. return labelMax;
  330. var rect = FullSizeRect;
  331. rect.xMin = iconsMin - 18;
  332. rect.xMax = labelMax;
  333. if (Selection.gameObjects.Contains(CurrentGameObject))
  334. EditorGUI.DrawRect(rect, Reflected.HierarchyFocused ? Styles.selectedFocusedColor : Styles.selectedUnfocusedColor);
  335. else
  336. EditorGUI.DrawRect(rect, Styles.normalColor);
  337. rect.y++;
  338. using (new GUIColor(CurrentColor))
  339. EditorStyles.boldLabel.Draw(rect, trailingContent, 0);
  340. return iconsMin;
  341. }
  342. }
  343. private static void DrawMiniLabel(ref Rect rect)
  344. {
  345. if (!IsGameObject)
  346. return;
  347. rect.x -= 3f;
  348. using (ProfilerSample.Get())
  349. switch (MiniLabelProviders.Length)
  350. {
  351. case 0:
  352. return;
  353. case 1:
  354. if (MiniLabelProviders[0].HasValue())
  355. MiniLabelProviders[0].Draw(ref rect);
  356. break;
  357. default:
  358. var ml0 = MiniLabelProviders[0];
  359. var ml1 = MiniLabelProviders[1];
  360. var ml0HasValue = ml0.HasValue();
  361. var ml1HasValue = ml1.HasValue();
  362. if (ml0HasValue && ml1HasValue || !Preferences.CentralizeMiniLabelWhenPossible)
  363. {
  364. var topRect = rect;
  365. var bottomRect = rect;
  366. topRect.yMax = RawRect.yMax - RawRect.height / 2f;
  367. bottomRect.yMin = RawRect.yMin + RawRect.height / 2f;
  368. if (ml0HasValue)
  369. ml0.Draw(ref topRect);
  370. if (ml1HasValue)
  371. ml1.Draw(ref bottomRect);
  372. rect.xMin = Mathf.Min(topRect.xMin, bottomRect.xMin);
  373. }
  374. else if (ml1HasValue)
  375. ml1.Draw(ref rect);
  376. else if (ml0HasValue)
  377. ml0.Draw(ref rect);
  378. break;
  379. }
  380. }
  381. private static float CalcMiniLabelSize()
  382. {
  383. Styles.miniLabelStyle.fontSize = Preferences.SmallerMiniLabel ? 8 : 9;
  384. using (ProfilerSample.Get())
  385. {
  386. switch (MiniLabelProviders.Length)
  387. {
  388. case 0:
  389. return 0f;
  390. case 1:
  391. return MiniLabelProviders[0].Measure();
  392. default:
  393. return Math.Max(
  394. MiniLabelProviders[0].Measure(),
  395. MiniLabelProviders[1].Measure()
  396. );
  397. }
  398. }
  399. }
  400. private static void DrawTooltip(Rect rect, float fullTrailingWidth)
  401. {
  402. if (!Preferences.Tooltips || !IsGameObject || !IsRepaintEvent)
  403. return;
  404. using (ProfilerSample.Get())
  405. {
  406. if (DragSelection != null)
  407. return;
  408. rect.xMax = Mathf.Min(fullTrailingWidth, rect.xMin + LabelSize);
  409. rect.xMin = 0f;
  410. if (!Utility.ShouldCalculateTooltipAt(rect))
  411. return;
  412. var tooltip = new StringBuilder(100);
  413. tooltip.AppendLine(GameObjectName);
  414. tooltip.AppendFormat("\nTag: {0}", GameObjectTag);
  415. tooltip.AppendFormat("\nLayer: {0}", LayerMask.LayerToName(CurrentGameObject.layer));
  416. if (GameObjectUtility.GetStaticEditorFlags(CurrentGameObject) != 0)
  417. tooltip.AppendFormat("\nStatic: {0}", Utility.EnumFlagsToString(GameObjectUtility.GetStaticEditorFlags(CurrentGameObject)));
  418. tooltip.AppendLine();
  419. tooltip.AppendLine();
  420. foreach (var component in Components)
  421. if (component is Transform)
  422. continue;
  423. else if (component)
  424. tooltip.AppendLine(ObjectNames.GetInspectorTitle(component));
  425. else
  426. tooltip.AppendLine("Missing Component");
  427. EditorGUI.LabelField(rect, Utility.GetTempGUIContent(null, tooltip.ToString().TrimEnd('\n', '\r')));
  428. }
  429. }
  430. private static void DoSelection(Rect rect)
  431. {
  432. if (!Preferences.EnhancedSelectionSupported || !Preferences.EnhancedSelection || Event.current.button != 1)
  433. {
  434. DragSelection = null;
  435. return;
  436. }
  437. using (ProfilerSample.Get())
  438. {
  439. rect.xMin = 0f;
  440. switch (Event.current.type)
  441. {
  442. case EventType.MouseDrag:
  443. if (!IsFirstVisible)
  444. return;
  445. if (DragSelection == null)
  446. {
  447. DragSelection = new List<Object>();
  448. SelectionStart = Event.current.mousePosition;
  449. SelectionRect = new Rect();
  450. }
  451. SelectionRect = new Rect()
  452. {
  453. xMin = Mathf.Min(Event.current.mousePosition.x, SelectionStart.x),
  454. yMin = Mathf.Min(Event.current.mousePosition.y, SelectionStart.y),
  455. xMax = Mathf.Max(Event.current.mousePosition.x, SelectionStart.x),
  456. yMax = Mathf.Max(Event.current.mousePosition.y, SelectionStart.y)
  457. };
  458. if (Event.current.control || Event.current.command)
  459. DragSelection.AddRange(Selection.objects);
  460. Selection.objects = DragSelection.ToArray();
  461. Event.current.Use();
  462. break;
  463. case EventType.MouseUp:
  464. if (DragSelection != null)
  465. Event.current.Use();
  466. DragSelection = null;
  467. break;
  468. case EventType.Repaint:
  469. if (DragSelection == null || !IsFirstVisible)
  470. break;
  471. Rect scrollRect;
  472. if (Event.current.mousePosition.y > FinalRect.y)
  473. {
  474. scrollRect = FinalRect;
  475. scrollRect.y += scrollRect.height;
  476. }
  477. else if (Event.current.mousePosition.y < RawRect.y)
  478. {
  479. scrollRect = RawRect;
  480. scrollRect.y -= scrollRect.height;
  481. }
  482. else
  483. break;
  484. SelectionRect = new Rect()
  485. {
  486. xMin = Mathf.Min(scrollRect.xMax, SelectionStart.x),
  487. yMin = Mathf.Min(scrollRect.yMax, SelectionStart.y),
  488. xMax = Mathf.Max(scrollRect.xMax, SelectionStart.x),
  489. yMax = Mathf.Max(scrollRect.yMax, SelectionStart.y)
  490. };
  491. if (Event.current.control || Event.current.command)
  492. DragSelection.AddRange(Selection.objects);
  493. Selection.objects = DragSelection.ToArray();
  494. GUI.ScrollTowards(scrollRect, 9f);
  495. EditorApplication.RepaintHierarchyWindow();
  496. break;
  497. case EventType.Layout:
  498. if (DragSelection != null && IsGameObject)
  499. if (!SelectionRect.Overlaps(rect) && DragSelection.Contains(CurrentGameObject))
  500. DragSelection.Remove(CurrentGameObject);
  501. else if (SelectionRect.Overlaps(rect) && !DragSelection.Contains(CurrentGameObject))
  502. DragSelection.Add(CurrentGameObject);
  503. break;
  504. }
  505. }
  506. }
  507. public static Color GetRowTint()
  508. {
  509. return GetRowTint(RawRect);
  510. }
  511. public static Color GetRowTint(Rect rect)
  512. {
  513. using (ProfilerSample.Get())
  514. if (rect.y / RawRect.height % 2 >= 0.5f)
  515. return Preferences.OddRowColor;
  516. else
  517. return Preferences.EvenRowColor;
  518. }
  519. public static LayerColor GetRowCustomTint()
  520. {
  521. return GetRowCustomTint(CurrentGameObject);
  522. }
  523. public static LayerColor GetRowCustomTint(GameObject go)
  524. {
  525. using (ProfilerSample.Get())
  526. {
  527. if (!go)
  528. return new LayerColor();
  529. var layerColors = Preferences.PerLayerRowColors.Value;
  530. if (layerColors == null)
  531. return new LayerColor();
  532. var goLayer = go.layer;
  533. for (var i = 0; i < layerColors.Count; i++)
  534. if (layerColors[i] == goLayer)
  535. return layerColors[i];
  536. return new LayerColor();
  537. }
  538. }
  539. public static List<GameObject> GetSelectedObjectsAndCurrent()
  540. {
  541. if (!Preferences.ChangeAllSelected || Selection.gameObjects.Length <= 1)
  542. return new List<GameObject> {CurrentGameObject};
  543. var selection = new List<GameObject>(Selection.gameObjects);
  544. for (var i = 0; i < selection.Count; i++)
  545. if (EditorUtility.IsPersistent(selection[i]))
  546. selection.RemoveAt(i);
  547. if (!selection.Contains(CurrentGameObject))
  548. selection.Add(CurrentGameObject);
  549. selection.Remove(null);
  550. return selection;
  551. }
  552. }
  553. }