Skip to content

Commit 6d1bd88

Browse files
authored
Merge branch 'develop' into fix/ISXB-1319/input-recorder-game-view-focus
2 parents 820619d + 2255883 commit 6d1bd88

8 files changed

Lines changed: 173 additions & 16 deletions

File tree

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: Check Editor references in Runtime code
2+
3+
on:
4+
pull_request:
5+
types:
6+
- opened
7+
- synchronize
8+
- reopened
9+
branches: [ "develop" ]
10+
11+
workflow_dispatch:
12+
13+
jobs:
14+
check-runtime-editor-refs:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- uses: actions/checkout@v4
18+
19+
- name: Check Runtime code has no Editor namespace references
20+
run: bash check-runtime-editor-refs.sh

Packages/com.unity.inputsystem/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
3030
- Removed 32-bit compilation check for HID on Windows players, which had no impact anymore. (ISX-2543)
3131
- Migrated sample scenes to use Universal Render Pipeline (URP) with Built-in Render Pipeline fallback shaders. The URP package is now required to run the samples. (ISX-2343)
3232
- Changed the UI for `Actions.inputactions` asset to use UI Toolkit framework.
33+
- Changed the UI for `InputSystem.inputsettings` asset to use UI Toolkit framework.
3334

3435
### Added
3536

Packages/com.unity.inputsystem/InputSystem/Editor/InputAssetEditorUtils.cs

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System;
44
using System.IO;
55
using UnityEditor;
6+
using UnityEngine.UIElements;
67

78
namespace UnityEngine.InputSystem.Editor
89
{
@@ -82,12 +83,32 @@ internal static T CreateAsset<T>(T asset, string relativePath) where T : Scripta
8283
return asset;
8384
}
8485

85-
public static void DrawMakeActiveGui<T>(T current, T target, string targetName, string entity, Action<T> apply, bool allowAssignActive = true)
86+
public static VisualElement CreateMakeActiveGui<T>(Func<T> getCurrent, T target, string targetName, string entity,
87+
Action<T> apply, Action<Action> subscribeToChanges, Action<Action> unsubscribeFromChanges,
88+
bool allowAssignActive = true)
8689
where T : ScriptableObject
8790
{
91+
var container = new VisualElement();
92+
93+
void Refresh() => PopulateMakeActiveGui(container, getCurrent(), target, entity, apply, allowAssignActive);
94+
95+
Refresh();
96+
97+
// Subscribe for as long as the element is part of a panel, matching the pattern used in InputParameterEditor.
98+
container.RegisterCallback<AttachToPanelEvent>(_ => subscribeToChanges(Refresh));
99+
container.RegisterCallback<DetachFromPanelEvent>(_ => unsubscribeFromChanges(Refresh));
100+
101+
return container;
102+
}
103+
104+
private static void PopulateMakeActiveGui<T>(VisualElement container, T current, T target, string entity, Action<T> apply, bool allowAssignActive)
105+
where T : ScriptableObject
106+
{
107+
container.Clear();
108+
88109
if (current == target)
89110
{
90-
EditorGUILayout.HelpBox($"These actions are assigned as the {entity}.", MessageType.Info);
111+
container.Add(new HelpBox($"These actions are assigned as the {entity}.", HelpBoxMessageType.Info));
91112
return;
92113
}
93114

@@ -96,11 +117,26 @@ public static void DrawMakeActiveGui<T>(T current, T target, string targetName,
96117
currentlyActiveAssetsPath = AssetDatabase.GetAssetPath(current);
97118
if (!string.IsNullOrEmpty(currentlyActiveAssetsPath))
98119
currentlyActiveAssetsPath = $" The actions currently assigned as the {entity} are: {currentlyActiveAssetsPath}. ";
99-
EditorGUILayout.HelpBox($"These actions are not assigned as the {entity} for the Input System. {currentlyActiveAssetsPath??""}", MessageType.Warning);
100-
GUI.enabled = allowAssignActive;
101-
if (GUILayout.Button($"Assign as the {entity}", EditorStyles.miniButton))
120+
121+
container.Add(new HelpBox(
122+
$"These actions are not assigned as the {entity} for the Input System. {currentlyActiveAssetsPath ?? ""}",
123+
HelpBoxMessageType.Warning));
124+
125+
var assignButton = new Button(() =>
126+
{
102127
apply(target);
103-
GUI.enabled = true;
128+
PopulateMakeActiveGui(container, target, target, entity, apply, allowAssignActive);
129+
})
130+
{
131+
text = $"Assign as the {entity}",
132+
style =
133+
{
134+
minHeight = 30,
135+
whiteSpace = WhiteSpace.Normal
136+
}
137+
};
138+
assignButton.SetEnabled(allowAssignActive);
139+
container.Add(assignButton);
104140
}
105141

106142
public static bool IsValidFileExtension(string path)

Packages/com.unity.inputsystem/InputSystem/Editor/InputSystemEditorInitializer.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,8 @@ private static void RegisterAssetDatabaseHooks()
277277
InputManager.s_GetProjectWideActions = () => ProjectWideActionsBuildProvider.actionsToIncludeInPlayerBuild;
278278

279279
InputActionReference.s_CheckImmutableReference = CheckImmutableInputActionReference;
280+
281+
InputSettings.s_GetIsInspectorIndented = () => EditorGUI.indentLevel > 0;
280282
}
281283

282284
/// <summary>

Packages/com.unity.inputsystem/InputSystem/Editor/Settings/InputSettingsProvider.cs

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -489,17 +489,36 @@ internal static void ForceReload()
489489
[CustomEditor(typeof(InputSettings))]
490490
internal class InputSettingsEditor : UnityEditor.Editor
491491
{
492-
public override void OnInspectorGUI()
492+
public override VisualElement CreateInspectorGUI()
493493
{
494-
EditorGUILayout.Space();
494+
var root = new VisualElement();
495495

496-
if (GUILayout.Button("Open Input Settings Window", GUILayout.Height(30)))
497-
InputSettingsProvider.Open();
498-
499-
EditorGUILayout.Space();
496+
var openButton = new Button(() => InputSettingsProvider.Open())
497+
{
498+
text = "Open Input Settings Window",
499+
style = { minHeight = 30, whiteSpace = WhiteSpace.Normal }
500+
};
501+
root.Add(openButton);
502+
503+
// UndoRedoCallback is void(), not Action, so an adapter is required.
504+
// The variable is shared between the two lambdas so the same instance is removed on unsubscribe.
505+
Undo.UndoRedoCallback undoRedoAdapter = null;
506+
root.Add(InputAssetEditorUtils.CreateMakeActiveGui(
507+
() => InputSystem.settings, target as InputSettings,
508+
target.name, "settings", (value) => InputSystem.settings = value,
509+
handler =>
510+
{
511+
InputSystem.onSettingsChange += handler;
512+
undoRedoAdapter = () => handler();
513+
Undo.undoRedoPerformed += undoRedoAdapter;
514+
},
515+
handler =>
516+
{
517+
InputSystem.onSettingsChange -= handler;
518+
Undo.undoRedoPerformed -= undoRedoAdapter;
519+
}));
500520

501-
InputAssetEditorUtils.DrawMakeActiveGui(InputSystem.settings, target as InputSettings,
502-
target.name, "settings", (value) => InputSystem.settings = value);
521+
return root;
503522
}
504523

505524
protected override bool ShouldHideOpenButton()

Packages/com.unity.inputsystem/InputSystem/Runtime/InputManager.LegacyFocusHandling.cs.meta

Lines changed: 10 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Packages/com.unity.inputsystem/InputSystem/Runtime/InputSettings.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -988,7 +988,10 @@ public enum InputActionPropertyDrawerMode
988988
/// * support inspector view which only work in IMGUI for now.
989989
/// * prevent the UI to be rendered in IMGUI and UI Toolkit in the Input Actions Editor window.
990990
/// </summary>
991-
public bool useIMGUIEditorForAssets => UnityEditor.EditorGUI.indentLevel > 0 || IsFeatureEnabled(InputFeatureNames.kUseIMGUIEditorForAssets);
991+
public bool useIMGUIEditorForAssets =>
992+
(s_GetIsInspectorIndented?.Invoke() == true) || IsFeatureEnabled(InputFeatureNames.kUseIMGUIEditorForAssets);
993+
994+
internal static Func<bool> s_GetIsInspectorIndented;
992995
#endif
993996

994997
private static bool CompareFloats(float a, float b)

check-runtime-editor-refs.sh

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#!/bin/bash
2+
[ -n "$BASH_VERSION" ] || { echo "ERROR: This script requires bash. Run with: bash $0" >&2; exit 1; }
3+
set -euo pipefail
4+
5+
RUNTIME_DIR="Packages/com.unity.inputsystem/InputSystem/Runtime"
6+
7+
# POSIX ERE patterns for grep -E, compatible with macOS (BSD grep) and Ubuntu (GNU grep).
8+
# No \b word boundaries — not portable across both. False positive risk is negligible
9+
# since no real identifiers contain these namespace roots as substrings.
10+
# (\.[A-Za-z0-9_]+)* covers sub-namespaces (UnityEditor.UI, …Editor.Tools, …).
11+
# Add more lines as needed, e.g. 'UnityEditorInternal(\.[A-Za-z0-9_]+)*'
12+
FORBIDDEN_REGEX=(
13+
'UnityEditor(\.[A-Za-z0-9_]+)*'
14+
'UnityEngine\.InputSystem\.Editor(\.[A-Za-z0-9_]+)*'
15+
)
16+
17+
RED=$'\033[0;31m'
18+
GREEN=$'\033[0;32m'
19+
NC=$'\033[0m'
20+
21+
INCLUDE_COMMENTS=false
22+
for arg in "$@"; do
23+
case "$arg" in
24+
--include-comments) INCLUDE_COMMENTS=true ;;
25+
--help)
26+
cat <<EOF
27+
Usage: $(basename "$0") [OPTIONS]
28+
29+
Check that Runtime code has no Editor namespace dependencies.
30+
Edit FORBIDDEN_REGEX in this script to add patterns.
31+
32+
Options:
33+
--include-comments Also flag references inside XML doc and // comments
34+
--help Show this help
35+
EOF
36+
exit 0 ;;
37+
*) echo "Unknown option: $arg"; exit 1 ;;
38+
esac
39+
done
40+
41+
[ -d "$RUNTIME_DIR" ] || { echo "${RED}ERROR: Runtime directory not found: $RUNTIME_DIR${NC}" >&2; exit 1; }
42+
43+
COMBINED=$(IFS='|'; echo "${FORBIDDEN_REGEX[*]}")
44+
45+
GREP_OUTPUT=$(grep -rnw --include='*.cs' --color=never -E "$COMBINED" "$RUNTIME_DIR" || true)
46+
47+
if [ "$INCLUDE_COMMENTS" = false ]; then
48+
VIOLATIONS=$(echo "$GREP_OUTPUT" | grep -Ev ':[0-9]+:[[:space:]]*//' || true)
49+
else
50+
VIOLATIONS="$GREP_OUTPUT"
51+
fi
52+
53+
if [ -z "$VIOLATIONS" ]; then
54+
echo "${GREEN}PASS: No Editor namespace references found in Runtime code.${NC}"
55+
exit 0
56+
fi
57+
58+
VIOLATION_COUNT=$(echo "$VIOLATIONS" | wc -l | tr -d ' ')
59+
echo "${RED}FAIL: Found $VIOLATION_COUNT Editor namespace reference(s) in Runtime code:${NC}"
60+
echo ""
61+
echo "$VIOLATIONS"
62+
echo ""
63+
echo "${RED}Active patterns:${NC}"
64+
for re in "${FORBIDDEN_REGEX[@]}"; do
65+
printf ' \033[0;31m%s\033[0m\n' "$re"
66+
done
67+
exit 1

0 commit comments

Comments
 (0)