Skip to content

Commit 709176b

Browse files
authored
fix: Create input settings from wizard (#880)
* create input settings from wizard * add depend tester * fix typo
1 parent baad23f commit 709176b

File tree

2 files changed

+43
-8
lines changed

2 files changed

+43
-8
lines changed

com.unity.renderstreaming/Editor/ConfigInfoLine.cs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@ static class Style
1717
private readonly bool m_visibleStatus;
1818
private readonly bool m_skipErrorIcon;
1919
private Func<bool> m_tester;
20+
private Func<bool> m_dependTester;
2021
private bool m_haveFixer;
2122
private bool m_currentStatus;
23+
private bool m_dependStatus;
2224

2325
public ConfigInfoLine(
2426
string label,
@@ -27,6 +29,7 @@ public ConfigInfoLine(
2729
string resolverButtonLabel,
2830
Func<bool> tester,
2931
Action resolver,
32+
Func<bool> dependTester = null,
3033
bool visibleStatus = true,
3134
bool skipErrorIcon = false
3235
)
@@ -35,6 +38,7 @@ public ConfigInfoLine(
3538
m_skipErrorIcon = skipErrorIcon;
3639
m_tester = tester;
3740
m_haveFixer = resolver != null;
41+
m_dependTester = dependTester;
3842

3943
var testLabel = new Label(label) {name = "testLabel"};
4044
var fixer = new Button(resolver) {text = resolverButtonLabel, name = "resolver"};
@@ -71,20 +75,24 @@ public ConfigInfoLine(
7175

7276
Add(new HelpBox(error, kind));
7377

74-
UpdateDisplay(m_currentStatus, m_haveFixer);
78+
UpdateDisplay(m_currentStatus, m_haveFixer, m_dependStatus);
7579
}
7680

7781
public void CheckUpdate()
7882
{
7983
bool wellConfigured = m_tester();
80-
if (wellConfigured ^ m_currentStatus)
84+
bool wellDependConfigured = m_dependTester == null || m_dependTester();
85+
bool changeConfigured = wellConfigured ^ m_currentStatus;
86+
bool changeDependConfigured = wellDependConfigured ^ m_dependStatus;
87+
if (changeConfigured || changeDependConfigured)
8188
{
82-
UpdateDisplay(wellConfigured, m_haveFixer);
89+
UpdateDisplay(wellConfigured, m_haveFixer, wellDependConfigured);
8390
m_currentStatus = wellConfigured;
91+
m_dependStatus = wellDependConfigured;
8492
}
8593
}
8694

87-
private void UpdateDisplay(bool statusOK, bool haveFixer)
95+
private void UpdateDisplay(bool statusOK, bool haveFixer, bool dependStatusOK)
8896
{
8997
if (m_visibleStatus)
9098
{
@@ -94,7 +102,9 @@ private void UpdateDisplay(bool statusOK, bool haveFixer)
94102
: DisplayStyle.None;
95103
}
96104

97-
this.Q(name: "resolver").style.display = statusOK || !haveFixer ? DisplayStyle.None : DisplayStyle.Flex;
105+
var resolver = this.Q<Button>(name: "resolver");
106+
resolver.style.display = statusOK || !haveFixer ? DisplayStyle.None : DisplayStyle.Flex;
107+
resolver.SetEnabled(dependStatusOK);
98108
this.Q(className: HelpBox.ussClassName).style.display = statusOK ? DisplayStyle.None : DisplayStyle.Flex;
99109
}
100110
}

com.unity.renderstreaming/Editor/RenderStreamingWizard.cs

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ public ConfigStyle(string label, string error, string button = "Fix",
4848
label: "Run In Background",
4949
error: "Run In Background must be True for Render Streaming to work in Background.");
5050

51+
static readonly ConfigStyle inputSystemSettingsAssets = new ConfigStyle(
52+
label: "Input System Settings Assets",
53+
error: "Input System Settings asset must exist under the Assets folder for changes.");
54+
5155
static readonly ConfigStyle inputSystemBackgroundBehavior = new ConfigStyle(
5256
label: "InputSystem Background Behavior",
5357
error: "InputSystem Background Behavior must be Ignore Focus for Input System to work in Background.");
@@ -105,13 +109,14 @@ enum Scope
105109
struct Entry
106110
{
107111
public delegate bool Checker();
108-
109112
public delegate void Fixer();
113+
public delegate bool DependChecker();
110114

111115
public readonly Scope scope;
112116
public readonly ConfigStyle configStyle;
113117
public readonly Checker check;
114118
public readonly Fixer fix;
119+
public readonly DependChecker dependChecker;
115120
public readonly bool forceDisplayCheck;
116121
public readonly bool skipErrorIcon;
117122

@@ -120,6 +125,7 @@ public Entry(
120125
ConfigStyle configStyle,
121126
Checker check,
122127
Fixer fix,
128+
DependChecker dependChecker = null,
123129
bool forceDisplayCheck = false,
124130
bool skipErrorIcon = false
125131
)
@@ -128,6 +134,7 @@ public Entry(
128134
this.configStyle = configStyle;
129135
this.check = check;
130136
this.fix = fix;
137+
this.dependChecker = dependChecker;
131138
this.forceDisplayCheck = forceDisplayCheck;
132139
this.skipErrorIcon = skipErrorIcon;
133140
}
@@ -144,12 +151,15 @@ Entry[] Entries
144151
entries = new[]
145152
{
146153
new Entry(Scope.PlayMode, runInBackground, IsRunInBackgroundCorrect, FixRunInBackground),
154+
new Entry(Scope.PlayMode, inputSystemSettingsAssets, IsInputSettingsAssetsExists, FixInputSettingsAssets),
147155
new Entry(Scope.PlayMode, inputSystemBackgroundBehavior,
148156
IsInputSystemBackgroundBehaviorCorrect,
149-
FixInputSystemBackgroundBehavior),
157+
FixInputSystemBackgroundBehavior,
158+
IsInputSettingsAssetsExists),
150159
new Entry(Scope.PlayMode, inputSystemPlayModeInputBehavior,
151160
IsInputSystemPlayModeInputBehaviorCorrect,
152-
FixInputSystemPlayModeInputBehavior),
161+
FixInputSystemPlayModeInputBehavior,
162+
IsInputSettingsAssetsExists),
153163
new Entry(Scope.BuildSettings, currentBuildTarget, IsSupportedBuildTarget, FixSupportedBuildTarget),
154164
new Entry(Scope.BuildSettings, currentGraphicsApi, IsSupportedGraphics, FixSupportedGraphics),
155165
new Entry(Scope.BuildSettings, macCameraUsageDescription, IsMacCameraUsageCorrect, FixMacCameraUsage),
@@ -174,6 +184,19 @@ Entry[] Entries
174184
private static bool IsRunInBackgroundCorrect() => PlayerSettings.runInBackground;
175185
private static void FixRunInBackground() => PlayerSettings.runInBackground = true;
176186

187+
private static bool IsInputSettingsAssetsExists()
188+
{
189+
var path = AssetDatabase.GetAssetPath(UnityEngine.InputSystem.InputSystem.settings);
190+
return !string.IsNullOrEmpty(path) && path.StartsWith("Assets/");
191+
}
192+
193+
private static void FixInputSettingsAssets()
194+
{
195+
var inputSettings = CreateInstance<InputSettings>();
196+
AssetDatabase.CreateAsset(inputSettings, $"Assets/{PlayerSettings.productName}.inputsettings.asset");
197+
UnityEngine.InputSystem.InputSystem.settings = inputSettings;
198+
}
199+
177200
private static bool IsInputSystemBackgroundBehaviorCorrect() =>
178201
UnityEngine.InputSystem.InputSystem.settings.backgroundBehavior == InputSettings.BackgroundBehavior.IgnoreFocus;
179202

@@ -510,6 +533,7 @@ private void BindChecker()
510533
entry.configStyle.button,
511534
() => entry.check(),
512535
entry.fix == null ? (Action)null : () => entry.fix(),
536+
entry.dependChecker == null ? (Func<bool>)null : () => entry.dependChecker(),
513537
entry.configStyle.messageType == MessageType.Error || entry.forceDisplayCheck,
514538
entry.skipErrorIcon));
515539
}
@@ -523,6 +547,7 @@ private void BindChecker()
523547
entry.configStyle.button,
524548
() => entry.check(),
525549
entry.fix == null ? (Action)null : () => entry.fix(),
550+
entry.dependChecker == null ? (Func<bool>)null : () => entry.dependChecker(),
526551
entry.configStyle.messageType == MessageType.Error || entry.forceDisplayCheck,
527552
entry.skipErrorIcon));
528553
}

0 commit comments

Comments
 (0)