@@ -18,21 +18,21 @@ public class HybridCLRSettingsProvider : SettingsProvider
1818 private SerializedProperty _hotUpdateAssemblies ;
1919 private SerializedProperty _preserveHotUpdateAssemblies ;
2020 private SerializedProperty _hotUpdateDllCompileOutputRootDir ;
21- private SerializedProperty _externalHotUpdateAssembliyDirs ;
21+ private SerializedProperty _externalHotUpdateAssemblyDirs ;
2222 private SerializedProperty _strippedAOTDllOutputRootDir ;
2323 private SerializedProperty _patchAOTAssemblies ;
2424 private SerializedProperty _outputLinkFile ;
2525 private SerializedProperty _outputAOTGenericReferenceFile ;
2626 private SerializedProperty _maxGenericReferenceIteration ;
2727 private SerializedProperty _maxMethodBridgeGenericIteration ;
2828
29- private GUIStyle buttonStyle ;
3029 public HybridCLRSettingsProvider ( ) : base ( "Project/HybridCLR Settings" , SettingsScope . Project ) { }
30+
3131 public override void OnActivate ( string searchContext , VisualElement rootElement )
3232 {
33- EditorStatusWatcher . OnEditorFocused += OnEditorFocused ;
3433 InitGUI ( ) ;
3534 }
35+
3636 private void InitGUI ( )
3737 {
3838 var setting = HybridCLRSettings . LoadOrCreate ( ) ;
@@ -46,133 +46,61 @@ private void InitGUI()
4646 _hotUpdateAssemblies = _serializedObject . FindProperty ( "hotUpdateAssemblies" ) ;
4747 _preserveHotUpdateAssemblies = _serializedObject . FindProperty ( "preserveHotUpdateAssemblies" ) ;
4848 _hotUpdateDllCompileOutputRootDir = _serializedObject . FindProperty ( "hotUpdateDllCompileOutputRootDir" ) ;
49- _externalHotUpdateAssembliyDirs = _serializedObject . FindProperty ( "externalHotUpdateAssembliyDirs" ) ;
49+ _externalHotUpdateAssemblyDirs = _serializedObject . FindProperty ( "externalHotUpdateAssembliyDirs" ) ;
5050 _strippedAOTDllOutputRootDir = _serializedObject . FindProperty ( "strippedAOTDllOutputRootDir" ) ;
5151 _patchAOTAssemblies = _serializedObject . FindProperty ( "patchAOTAssemblies" ) ;
5252 _outputLinkFile = _serializedObject . FindProperty ( "outputLinkFile" ) ;
5353 _outputAOTGenericReferenceFile = _serializedObject . FindProperty ( "outputAOTGenericReferenceFile" ) ;
5454 _maxGenericReferenceIteration = _serializedObject . FindProperty ( "maxGenericReferenceIteration" ) ;
5555 _maxMethodBridgeGenericIteration = _serializedObject . FindProperty ( "maxMethodBridgeGenericIteration" ) ;
5656 }
57- private void OnEditorFocused ( )
58- {
59- InitGUI ( ) ;
60- Repaint ( ) ;
61- }
62- public override void OnTitleBarGUI ( )
63- {
64- base . OnTitleBarGUI ( ) ;
65- var rect = GUILayoutUtility . GetLastRect ( ) ;
66- buttonStyle = buttonStyle ?? GUI . skin . GetStyle ( "IconButton" ) ;
6757
68- #region 绘制官方网站跳转按钮
69- var w = rect . x + rect . width ;
70- rect . x = w - 57 ;
71- rect . y += 6 ;
72- rect . width = rect . height = 18 ;
73- var content = EditorGUIUtility . IconContent ( "_Help" ) ;
74- content . tooltip = "点击访问 HybridCLR 官方文档" ;
75- if ( GUI . Button ( rect , content , buttonStyle ) )
76- {
77- Application . OpenURL ( "https://hybridclr.doc.code-philosophy.com/" ) ;
78- }
79- #endregion
80- #region 绘制 Preset
81- rect . x += 19 ;
82- content = EditorGUIUtility . IconContent ( "Preset.Context" ) ;
83- content . tooltip = "点击存储或加载 Preset ." ;
84- if ( GUI . Button ( rect , content , buttonStyle ) )
85- {
86- var target = HybridCLRSettings . Instance ;
87- var receiver = ScriptableObject . CreateInstance < SettingsPresetReceiver > ( ) ;
88- receiver . Init ( target , this ) ;
89- PresetSelector . ShowSelector ( target , null , true , receiver ) ;
90- }
91- #endregion
92- #region 绘制 Reset
93- rect . x += 19 ;
94- content = EditorGUIUtility . IconContent (
95- #if UNITY_2021_3_OR_NEWER
96- "pane options"
97- #else
98- "_Popup"
99- #endif
100- ) ;
101- content . tooltip = "Reset" ;
102- if ( GUI . Button ( rect , content , buttonStyle ) )
103- {
104- GenericMenu menu = new GenericMenu ( ) ;
105- menu . AddItem ( new GUIContent ( "Reset" ) , false , ( ) =>
106- {
107- Undo . RecordObject ( HybridCLRSettings . Instance , "Capture Value for Reset" ) ;
108- var dv = ScriptableObject . CreateInstance < HybridCLRSettings > ( ) ;
109- var json = EditorJsonUtility . ToJson ( dv ) ;
110- UnityEngine . Object . DestroyImmediate ( dv ) ;
111- EditorJsonUtility . FromJsonOverwrite ( json , HybridCLRSettings . Instance ) ;
112- HybridCLRSettings . Save ( ) ;
113- } ) ;
114- menu . ShowAsContext ( ) ;
115- }
116- #endregion
117- }
11858 public override void OnGUI ( string searchContext )
11959 {
120- using ( CreateSettingsWindowGUIScope ( ) )
60+ if ( _serializedObject == null || ! _serializedObject . targetObject )
12161 {
122- if ( _serializedObject == null || ! _serializedObject . targetObject )
123- {
124- InitGUI ( ) ;
125- }
126- _serializedObject . Update ( ) ;
127- EditorGUI . BeginChangeCheck ( ) ;
128- EditorGUILayout . PropertyField ( _enable ) ;
129- EditorGUILayout . PropertyField ( _hybridclrRepoURL ) ;
130- EditorGUILayout . PropertyField ( _il2cppPlusRepoURL ) ;
131- EditorGUILayout . PropertyField ( _useGlobalIl2cpp ) ;
132- EditorGUILayout . PropertyField ( _hotUpdateAssemblyDefinitions ) ;
133- EditorGUILayout . PropertyField ( _hotUpdateAssemblies ) ;
134- EditorGUILayout . PropertyField ( _preserveHotUpdateAssemblies ) ;
135- EditorGUILayout . PropertyField ( _hotUpdateDllCompileOutputRootDir ) ;
136- EditorGUILayout . PropertyField ( _externalHotUpdateAssembliyDirs ) ;
137- EditorGUILayout . PropertyField ( _strippedAOTDllOutputRootDir ) ;
138- EditorGUILayout . PropertyField ( _patchAOTAssemblies ) ;
139- EditorGUILayout . PropertyField ( _outputLinkFile ) ;
140- EditorGUILayout . PropertyField ( _outputAOTGenericReferenceFile ) ;
141- EditorGUILayout . PropertyField ( _maxGenericReferenceIteration ) ;
142- EditorGUILayout . PropertyField ( _maxMethodBridgeGenericIteration ) ;
143- if ( EditorGUI . EndChangeCheck ( ) )
144- {
145- _serializedObject . ApplyModifiedProperties ( ) ;
146- HybridCLRSettings . Save ( ) ;
147- }
62+ InitGUI ( ) ;
63+ }
64+ _serializedObject . Update ( ) ;
65+ EditorGUI . BeginChangeCheck ( ) ;
66+ EditorGUILayout . PropertyField ( _enable ) ;
67+ EditorGUILayout . PropertyField ( _hybridclrRepoURL ) ;
68+ EditorGUILayout . PropertyField ( _il2cppPlusRepoURL ) ;
69+ EditorGUILayout . PropertyField ( _useGlobalIl2cpp ) ;
70+ EditorGUILayout . PropertyField ( _hotUpdateAssemblyDefinitions ) ;
71+ EditorGUILayout . PropertyField ( _hotUpdateAssemblies ) ;
72+ EditorGUILayout . PropertyField ( _preserveHotUpdateAssemblies ) ;
73+ EditorGUILayout . PropertyField ( _hotUpdateDllCompileOutputRootDir ) ;
74+ EditorGUILayout . PropertyField ( _externalHotUpdateAssemblyDirs ) ;
75+ EditorGUILayout . PropertyField ( _strippedAOTDllOutputRootDir ) ;
76+ EditorGUILayout . PropertyField ( _patchAOTAssemblies ) ;
77+ EditorGUILayout . PropertyField ( _outputLinkFile ) ;
78+ EditorGUILayout . PropertyField ( _outputAOTGenericReferenceFile ) ;
79+ EditorGUILayout . PropertyField ( _maxGenericReferenceIteration ) ;
80+ EditorGUILayout . PropertyField ( _maxMethodBridgeGenericIteration ) ;
81+ if ( EditorGUI . EndChangeCheck ( ) )
82+ {
83+ _serializedObject . ApplyModifiedProperties ( ) ;
84+ HybridCLRSettings . Save ( ) ;
14885 }
14986 }
150- private IDisposable CreateSettingsWindowGUIScope ( )
151- {
152- var unityEditorAssembly = Assembly . GetAssembly ( typeof ( EditorWindow ) ) ;
153- var type = unityEditorAssembly . GetType ( "UnityEditor.SettingsWindow+GUIScope" ) ;
154- return Activator . CreateInstance ( type ) as IDisposable ;
155- }
87+
15688 public override void OnDeactivate ( )
15789 {
15890 base . OnDeactivate ( ) ;
159- EditorStatusWatcher . OnEditorFocused -= OnEditorFocused ;
16091 HybridCLRSettings . Save ( ) ;
16192 }
16293
163- static HybridCLRSettingsProvider provider ;
94+ static HybridCLRSettingsProvider s_provider ;
95+
16496 [ SettingsProvider ]
16597 public static SettingsProvider CreateMyCustomSettingsProvider ( )
16698 {
167- if ( HybridCLRSettings . Instance && provider == null )
99+ if ( s_provider == null )
168100 {
169- provider = new HybridCLRSettingsProvider ( ) ;
170- using ( var so = new SerializedObject ( HybridCLRSettings . Instance ) )
171- {
172- provider . keywords = GetSearchKeywordsFromSerializedObject ( so ) ;
173- }
101+ s_provider = new HybridCLRSettingsProvider ( ) ;
174102 }
175- return provider ;
103+ return s_provider ;
176104 }
177105 }
178106}
0 commit comments