11/*
22 * UniWindowControllerEditor.cs
3- *
4- * Author: Kirurobo http://twitter .com/kirurobo
3+ *
4+ * Author: Kirurobo http://x .com/kirurobo
55 * License: MIT
66 */
77
1313using UnityEngine ;
1414using UnityEditor ;
1515using System . Reflection ;
16+ using UnityEngine . Rendering ;
1617
1718namespace Kirurobo
1819{
@@ -22,24 +23,60 @@ namespace Kirurobo
2223 [ CustomEditor ( typeof ( UniWindowController ) ) ]
2324 public class UniWindowControllerEditor : Editor
2425 {
26+ /// <summary>
27+ /// カーソル下の色を表示するためのプロパティ
28+ /// </summary>
2529 SerializedProperty pickedColor ;
2630
31+ /// <summary>
32+ /// ゲームビューのウィンドウ
33+ /// </summary>
2734 private EditorWindow gameViewWindow ;
2835
36+ /// <summary>
37+ /// プロジェクト設定に関する警告を閉じておくか
2938 private bool isWarningDismissed = false ;
3039
40+ /// <summary>
41+ /// URP に関する警告を閉じておくか
42+ /// </summary>
43+ private bool isUrpWarningDismissed = true ;
44+
45+ /// <summary>
46+ /// URP が有効かどうか
47+ /// </summary>
48+ private bool hasUrp = false ;
49+
3150 void OnEnable ( )
3251 {
3352 LoadSettings ( ) ;
3453
3554 pickedColor = serializedObject . FindProperty ( "pickedColor" ) ;
55+
56+ // URP が有効か否かを判定
57+ hasUrp = GetUrpSettings ( ) ;
3658 }
3759
3860 void OnDisable ( )
3961 {
4062 SaveSettings ( ) ;
4163 }
4264
65+ /// <summary>
66+ /// URPが有効か否かを検出
67+ /// </summary>
68+ /// <returns></returns>
69+ private bool GetUrpSettings ( )
70+ {
71+ var renderPipelineAsset = GraphicsSettings . defaultRenderPipeline ;
72+ if ( renderPipelineAsset == null || renderPipelineAsset . GetType ( ) . Name != "UniversalRenderPipelineAsset" )
73+ {
74+ // URP が設定されていない
75+ return false ;
76+ }
77+ return true ;
78+ }
79+
4380 private void LoadSettings ( )
4481 {
4582 isWarningDismissed = EditorUserSettings . GetConfigValue ( "WindowController_IS_WARNING DISMISSED" ) == "1" ;
@@ -50,6 +87,12 @@ private void SaveSettings()
5087 EditorUserSettings . SetConfigValue ( "WindowController_IS_WARNING DISMISSED" , isWarningDismissed ? "1" : "0" ) ;
5188 }
5289
90+ /// <summary>
91+ /// インスペクタでの表示をカスタマイズ
92+ /// </summary>
93+ /// <description>
94+ /// 参考情報および、推奨設定の変更欄を表示します。
95+ /// </description>
5396 public override void OnInspectorGUI ( )
5497 {
5598 base . OnInspectorGUI ( ) ;
@@ -62,15 +105,26 @@ public override void OnInspectorGUI()
62105 EditorGUI . EndDisabledGroup ( ) ;
63106 }
64107
108+ // Project Settings の推奨設定を表示
109+ isWarningDismissed = ShowPlayerSettingsValidation ( isWarningDismissed ) ;
110+
111+ // URP 関連の推奨設定を表示
112+ isUrpWarningDismissed = ShowUrpSettingsValidation ( isUrpWarningDismissed ) ;
113+ }
114+
115+ /// <summary>
116+ /// Project Settings に関する推奨設定の自動設定欄を表示
117+ /// </summary>
118+ private bool ShowPlayerSettingsValidation ( bool dismissed ) {
65119 // 以下は Project Settings 関連
66120 EditorGUILayout . Space ( ) ;
67121
68- bool enableValidation = EditorGUILayout . Foldout ( ! isWarningDismissed , "Player Settings validation" ) ;
122+ bool enableValidation = EditorGUILayout . Foldout ( ! dismissed , "Player Settings validation" ) ;
69123
70124 // チェックするかどうかを記憶
71- if ( enableValidation == isWarningDismissed )
125+ if ( enableValidation == dismissed )
72126 {
73- isWarningDismissed = ! enableValidation ;
127+ dismissed = ! enableValidation ;
74128 }
75129
76130 // 推奨設定のチェック
@@ -92,11 +146,11 @@ public override void OnInspectorGUI()
92146 // Dismiss the validation
93147 GUI . backgroundColor = Color . yellow ;
94148 if ( GUILayout . Button (
95- "✘ Mute this validation" ,
149+ "✘ Dismiss this validation" ,
96150 GUILayout . MinHeight ( 25f )
97151 ) )
98152 {
99- isWarningDismissed = true ;
153+ dismissed = true ;
100154
101155 //SaveSettings(); // Uncomment this if save you want to save immediately
102156 }
@@ -126,8 +180,63 @@ public override void OnInspectorGUI()
126180
127181 EditorGUILayout . Space ( ) ;
128182 }
183+ return dismissed ;
129184 }
130185
186+ /// <summary>
187+ /// URP に関する推奨設定の自動設定欄を表示
188+ /// </summary>
189+ private bool ShowUrpSettingsValidation ( bool dismissed ) {
190+ // URP が無効ならば何もしない
191+ if ( ! hasUrp ) return dismissed ;
192+
193+ // 以下は URP 関連の自動設定
194+ EditorGUILayout . Space ( ) ;
195+
196+ bool enableValidation = EditorGUILayout . Foldout ( ! dismissed , "URP Settings validation" ) ;
197+ // チェックするかどうかを記憶
198+ if ( enableValidation == dismissed )
199+ {
200+ dismissed = ! enableValidation ;
201+ }
202+ // 推奨設定のチェック
203+ //if (!isWarningDismissed)
204+ if ( enableValidation )
205+ {
206+ if ( ValidateUrpSettings ( false ) )
207+ {
208+ // Apply all recommendation
209+ GUI . backgroundColor = Color . green ;
210+ if ( GUILayout . Button (
211+ "✔ Fix all settings to recommended values" ,
212+ GUILayout . MinHeight ( 25f )
213+ ) )
214+ {
215+ ValidateUrpSettings ( true ) ;
216+ }
217+
218+ // Dismiss the validation
219+ GUI . backgroundColor = Color . yellow ;
220+ if ( GUILayout . Button (
221+ "✘ Dismiss this validation" ,
222+ GUILayout . MinHeight ( 25f )
223+ ) )
224+ {
225+ dismissed = true ;
226+ }
227+
228+ EditorGUILayout . Space ( ) ;
229+ }
230+ else
231+ {
232+ GUI . color = Color . green ;
233+ GUILayout . Label ( "OK!" ) ;
234+ }
235+
236+ EditorGUILayout . Space ( ) ;
237+ }
238+ return dismissed ;
239+ }
131240
132241 private delegate void FixMethod ( ) ;
133242
@@ -161,6 +270,31 @@ private void FixSetting(string message, FixMethod fixAction, bool silentFix = fa
161270 EditorGUILayout . EndHorizontal ( ) ;
162271 }
163272 }
273+
274+ /// <summary>
275+ /// Show the recommendation only
276+ /// </summary>
277+ /// <param name="message">Warning message</param>
278+ private void ShowInfo ( string message , Object target = null )
279+
280+ {
281+ // Show the message and a fix button
282+ EditorGUILayout . BeginHorizontal ( ) ;
283+ EditorGUILayout . HelpBox ( message , MessageType . Info , true ) ;
284+ GUILayout . FlexibleSpace ( ) ;
285+
286+ // 自動設定できない対象は、プロジェクトウィンドウで示すのみ
287+ if ( target != null )
288+ {
289+ EditorGUILayout . BeginVertical ( ) ;
290+ EditorGUILayout . Space ( ) ;
291+ if ( GUILayout . Button ( "Ping" , GUILayout . Width ( 60f ) ) ) { EditorGUIUtility . PingObject ( target ) ; }
292+ //GUILayout.FlexibleSpace();
293+ EditorGUILayout . EndVertical ( ) ;
294+ }
295+
296+ EditorGUILayout . EndHorizontal ( ) ;
297+ }
164298
165299 /// <summary>
166300 /// Validate player settings
@@ -250,12 +384,87 @@ private bool ValidateSettings(bool silentFix = false)
250384 silentFix
251385 ) ;
252386 }
387+
388+ // Direct3D12 は透過ウィンドウに対応していないので、Graphics APIs for Windows から除外することを推奨
389+ if ( PlayerSettings . GetUseDefaultGraphicsAPIs ( BuildTarget . StandaloneWindows ) )
390+ {
391+ // 自動の場合も警告を出す
392+ ShowInfo (
393+ "Direct3D12 is not supported for transparent window. " +
394+ "Please consider using Direct3D11 instead of the 'Auto Graphics API for Windows' setting in Player Settings." ,
395+ null
396+ ) ;
397+ }
398+ else if ( PlayerSettings . GetGraphicsAPIs ( BuildTarget . StandaloneWindows ) . Contains ( GraphicsDeviceType . Direct3D12 ) )
399+ {
400+ // Graphhics APIs for Windows に Direct3D12 が含まれている場合は警告を出す
401+ ShowInfo (
402+ "Direct3D12 is not supported for transparent window. " +
403+ "Please remove Direct3D12 from 'Graphics APIs for Windows' in Player Settings." ,
404+ null
405+ ) ;
406+ }
253407#endif
254408
255409 return invalid ;
256410 }
411+
412+ /// <summary>
413+ /// Validate player settings
414+ /// </summary>
415+ /// <param name="silentFix">false: show warning and fix button, true: fix without showing</param>
416+ /// <returns>true if there are any invalid items</returns>
417+ private bool ValidateUrpSettings ( bool silentFix = false )
418+ {
419+ bool invalid = false ;
420+
421+ // Universal Render Pipelineが有効ならば、HDRの無効化を推奨
422+ foreach ( var cam in Camera . allCameras )
423+ {
424+ if ( cam . allowHDR ) {
425+ string name = cam . name ;
426+ invalid = true ;
427+ FixSetting (
428+ $ "{ name } : Disable 'HDR' in the camera to make the window transparent.",
429+ ( ) => cam . allowHDR = false ,
430+ silentFix
431+ ) ;
432+ }
433+ if ( cam . allowMSAA ) {
434+ string name = cam . name ;
435+ invalid = true ;
436+ FixSetting (
437+ $ "{ name } : Disable 'MSAA' in the camera to make the window transparent.",
438+ ( ) => cam . allowMSAA = false ,
439+ silentFix
440+ ) ;
441+ }
442+ }
443+
444+ var urpAsset = GraphicsSettings . defaultRenderPipeline ;
445+ if ( hasUrp && urpAsset != null )
446+ {
447+ // hasUrp == true の時点で urpAsset は UniversalRenderPipelineAsset であるはず。そのため allowPostProcessAlphaOutput があるはず
448+ var alphaProcessingProperty = urpAsset . GetType ( ) . GetProperty ( "allowPostProcessAlphaOutput" , BindingFlags . Public | BindingFlags . Instance ) ;
449+ if ( alphaProcessingProperty != null )
450+ {
451+ var alphaProcessing = alphaProcessingProperty . GetValue ( urpAsset ) ;
452+ if ( ! ( bool ) alphaProcessing )
453+ {
454+ invalid = true ;
455+ ShowInfo (
456+ "Turn on 'Alpha Processing' in the URP asset" ,
457+ urpAsset
458+ ) ;
459+ }
460+ }
461+ }
462+
463+ return invalid ;
464+ }
257465 }
258466
467+
259468 [ CustomPropertyDrawer ( typeof ( ReadOnlyAttribute ) ) ]
260469 public class UniWindowControllerReadOnlyDrawer : PropertyDrawer
261470 {
0 commit comments