Skip to content

Commit 82b8246

Browse files
authored
Merge pull request #88 from kirurobo/dev_win
Added settings verification when using URP
2 parents e305cbe + 032bf99 commit 82b8246

File tree

6 files changed

+239
-12
lines changed

6 files changed

+239
-12
lines changed

README-ja.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,16 @@ B. UnityPackage を利用する手順
5151
5. ビルドしたものを起動
5252

5353

54+
### URP 利用時の設定
55+
背景を透明にするためには、アルファチャンネルを維持する必要があります。
56+
そのためにいくつかの条件があります。
57+
- HDR は無効にする [参考](https://github.com/kirurobo/UniWindowController/issues/42#issuecomment-2507577260)
58+
- Main Camera (GameObject) > Camera (Component) > Output > HDR: Off
59+
- AlphaProcessing は有効にする [](https://github.com/kirurobo/UniWindowController/issues/42#issuecomment-250757726)
60+
61+
5462
## 制限事項
63+
- Direct3D12 では背景透過が有効となりません。Direct3D11 では `Use DXGI flip model swapchain for D3D11` を無効にすることで透過が可能です。
5564
- Unityエディタ上では透過はできません。ビルドをしてお試しください。
5665
- 常に最前面やウィンドウ移動等は動作しますが、実行中にゲームビューを閉じたりドッキングの配置を変えることはお勧めしません。一応、ゲームビューにフォーカスを移すとウィンドウを再取得はします。
5766
- マウスでは良いのですが、タッチ操作には適切な対応がまだ定まっていません。

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,16 @@ B. Using an UnityPackage
5050
5. Launch the build
5151

5252

53+
### Settings when using URP
54+
To make the background transparent, the alpha channel must be maintained.
55+
There are some conditions for this.
56+
- HDR must be disabled [Reference](https://github.com/kirurobo/UniWindowController/issues/42#issuecomment-2507577260)
57+
- Main Camera (GameObject) > Camera (Component) > Output > HDR: Off
58+
- AlphaProcessing must be enabled [Figure](https://github.com/kirurobo/UniWindowController/issues/42#issuecomment-250757726)
59+
60+
5361
## Limitations
62+
- Background transparency is not enabled in Direct3D12; in Direct3D11, transparency can be enabled by disabling `Use DXGI flip model swapchain for D3D11`.
5463
- Transparency is not available on the Unity Editor. Please build and try it.
5564
- It works for topmost, moving windows, etc., but I do not recommend closing the game view or changing the docking arrangement while it is running. In the meantime, the window will reacquire when the focus is shifted to the game view.
5665
- The proper support for touch operations has not yet been determined.

UniWinC/Assets/Kirurobo/UniWindowController/Editor/Scripts/UniWindowControllerEditor.cs

Lines changed: 216 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
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

@@ -13,6 +13,7 @@
1313
using UnityEngine;
1414
using UnityEditor;
1515
using System.Reflection;
16+
using UnityEngine.Rendering;
1617

1718
namespace 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
{

UniWinC/Assets/Kirurobo/UniWindowController/README-ja.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ https://twitter.com/i/status/1314440790945361920
2121

2222

2323
## デモ
24-
[Release のページ](https://github.com/kirurobo/UniWindowController/releases) にビルドしたサンプルを置いてあります
24+
[UniWinC_VRM](https://github.com/kirurobo/UniWinC_VRM) にはビルドしたVRMファイルビューアーのサンプルを置いてあります
2525

2626

2727
## インストール

UniWinC/Assets/Kirurobo/UniWindowController/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ https://twitter.com/i/status/1314440790945361920
2020

2121

2222
## Demo
23-
You can find some sample builts on the [Release page](https://github.com/kirurobo/UniWindowController/releases).
23+
You can find a sample VRM viewer via [UniWinC_VRM](https://github.com/kirurobo/UniWinC_VRM).
2424

2525

2626
## Installation

UniWinC/Assets/Kirurobo/UniWindowController/Samples/00_Menu/SampleMenu.unity

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ RenderSettings:
3838
m_ReflectionIntensity: 1
3939
m_CustomReflection: {fileID: 0}
4040
m_Sun: {fileID: 0}
41-
m_IndirectSpecularColor: {r: 0.44657844, g: 0.49641222, b: 0.57481676, a: 1}
41+
m_IndirectSpecularColor: {r: 0.44657815, g: 0.49641186, b: 0.57481647, a: 1}
4242
m_UseRadianceAmbientProbe: 0
4343
--- !u!157 &3
4444
LightmapSettings:
@@ -854,7 +854,7 @@ Canvas:
854854
m_RenderMode: 0
855855
m_Camera: {fileID: 0}
856856
m_PlaneDistance: 100
857-
m_PixelPerfect: 0
857+
m_PixelPerfect: 1
858858
m_ReceivesEvents: 1
859859
m_OverrideSorting: 0
860860
m_OverridePixelPerfect: 0
@@ -1670,7 +1670,7 @@ Transform:
16701670
m_GameObject: {fileID: 4973827625486595094}
16711671
serializedVersion: 2
16721672
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
1673-
m_LocalPosition: {x: 409, y: 261.5, z: 0}
1673+
m_LocalPosition: {x: 0, y: 0, z: 0}
16741674
m_LocalScale: {x: 1, y: 1, z: 1}
16751675
m_ConstrainProportionsScale: 0
16761676
m_Children:

0 commit comments

Comments
 (0)