AnalyzeRuleGUI.cs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. using System;
  2. using UnityEditor.IMGUI.Controls;
  3. using UnityEngine;
  4. namespace UnityEditor.AddressableAssets.GUI
  5. {
  6. [Serializable]
  7. class AnalyzeRuleGUI
  8. {
  9. [SerializeField]
  10. private TreeViewState m_TreeState;
  11. private AssetSettingsAnalyzeTreeView m_Tree;
  12. private const float k_ButtonHeight = 24f;
  13. internal void OnGUI(Rect rect)
  14. {
  15. if (m_Tree == null)
  16. {
  17. if (m_TreeState == null)
  18. m_TreeState = new TreeViewState();
  19. m_Tree = new AssetSettingsAnalyzeTreeView(m_TreeState);
  20. m_Tree.Reload();
  21. }
  22. var treeRect = new Rect(rect.xMin, rect.yMin + k_ButtonHeight, rect.width, rect.height - k_ButtonHeight);
  23. m_Tree.OnGUI(treeRect);
  24. var buttonRect = new Rect(rect.xMin, rect.yMin, rect.width, rect.height);
  25. GUILayout.BeginArea(buttonRect);
  26. GUILayout.BeginHorizontal();
  27. EditorGUI.BeginDisabledGroup(!m_Tree.SelectionContainsRuleContainer);
  28. if (GUILayout.Button("Analyze Selected Rules"))
  29. {
  30. EditorApplication.delayCall += () => m_Tree.RunAllSelectedRules();
  31. }
  32. if (GUILayout.Button("Clear Selected Rules"))
  33. {
  34. EditorApplication.delayCall += () => m_Tree.ClearAllSelectedRules();
  35. }
  36. EditorGUI.BeginDisabledGroup(!m_Tree.SelectionContainsFixableRule || !m_Tree.SelectionContainsErrors);
  37. if (GUILayout.Button("Fix Selected Rules"))
  38. {
  39. EditorApplication.delayCall += () => m_Tree.FixAllSelectedRules();
  40. }
  41. EditorGUI.EndDisabledGroup();
  42. GUILayout.EndHorizontal();
  43. GUILayout.EndArea();
  44. //TODO
  45. //if (GUILayout.Button("Revert Selected"))
  46. //{
  47. // m_Tree.RevertAllActiveRules();
  48. //}
  49. }
  50. }
  51. }