FR2_WindowBase.cs 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEditor;
  4. using UnityEngine;
  5. namespace vietlabs.fr2
  6. {
  7. public interface IWindow
  8. {
  9. bool WillRepaint { get; set; }
  10. void Repaint();
  11. void OnSelectionChange();
  12. }
  13. internal interface IRefDraw
  14. {
  15. IWindow window { get; }
  16. int ElementCount();
  17. bool DrawLayout();
  18. bool Draw(Rect rect);
  19. }
  20. public abstract class FR2_WindowBase : EditorWindow, IWindow
  21. {
  22. public bool WillRepaint { get; set; }
  23. protected bool showFilter, showIgnore;
  24. //[NonSerialized] protected bool lockSelection;
  25. //[NonSerialized] internal List<FR2_Asset> Selected;
  26. public static bool isNoticeIgnore;
  27. public void AddItemsToMenu(GenericMenu menu)
  28. {
  29. FR2_Cache api = FR2_Cache.Api;
  30. if (api == null)
  31. {
  32. return;
  33. }
  34. menu.AddDisabledItem(new GUIContent("FR2 - v2.5.1"));
  35. menu.AddSeparator(string.Empty);
  36. menu.AddItem(new GUIContent("Enable"), !api.disabled, () => { api.disabled = !api.disabled; });
  37. menu.AddItem(new GUIContent("Refresh"), false, () =>
  38. {
  39. //FR2_Asset.lastRefreshTS = Time.realtimeSinceStartup;
  40. FR2_Cache.Api.Check4Changes(true);
  41. FR2_SceneCache.Api.SetDirty();
  42. });
  43. #if FR2_DEV
  44. menu.AddItem(new GUIContent("Refresh Usage"), false, () => FR2_Cache.Api.Check4Usage());
  45. menu.AddItem(new GUIContent("Refresh Selected"), false, ()=> FR2_Cache.Api.RefreshSelection());
  46. menu.AddItem(new GUIContent("Clear Cache"), false, () => FR2_Cache.Api.Clear());
  47. #endif
  48. }
  49. public abstract void OnSelectionChange();
  50. protected abstract void OnGUI();
  51. #if UNITY_2018_OR_NEWER
  52. protected void OnSceneChanged(Scene arg0, Scene arg1)
  53. {
  54. if (IsFocusingFindInScene || IsFocusingSceneToAsset || IsFocusingSceneInScene)
  55. {
  56. OnSelectionChange();
  57. }
  58. }
  59. #endif
  60. protected bool DrawEnable()
  61. {
  62. FR2_Cache api = FR2_Cache.Api;
  63. if (api == null)
  64. {
  65. return false;
  66. }
  67. bool v = api.disabled;
  68. if (v)
  69. {
  70. EditorGUILayout.HelpBox("Find References 2 is disabled!", MessageType.Warning);
  71. if (GUILayout.Button("Enable"))
  72. {
  73. api.disabled = !api.disabled;
  74. Repaint();
  75. }
  76. return !api.disabled;
  77. }
  78. return !api.disabled;
  79. }
  80. }
  81. }