-
Notifications
You must be signed in to change notification settings - Fork 332
Input system/cache properties #2370
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,6 +15,23 @@ | |
| public void OnEnable() | ||
| { | ||
| InputUser.onChange += OnUserChange; | ||
| CacheProperties(); | ||
| } | ||
|
|
||
| private void CacheProperties() | ||
| { | ||
| m_NotificationBehaviorProperty = serializedObject.FindProperty(nameof(PlayerInputManager.m_NotificationBehavior)); | ||
| m_PlayerJoinedEventProperty = serializedObject.FindProperty(nameof(PlayerInputManager.m_PlayerJoinedEvent)); | ||
| m_PlayerLeftEventProperty = serializedObject.FindProperty(nameof(PlayerInputManager.m_PlayerLeftEvent)); | ||
| m_JoinBehaviorProperty = serializedObject.FindProperty(nameof(PlayerInputManager.m_JoinBehavior)); | ||
| m_JoinActionProperty = serializedObject.FindProperty(nameof(PlayerInputManager.m_JoinAction)); | ||
| m_PlayerPrefabProperty = serializedObject.FindProperty(nameof(PlayerInputManager.m_PlayerPrefab)); | ||
| m_AllowJoiningProperty = serializedObject.FindProperty(nameof(PlayerInputManager.m_AllowJoining)); | ||
| m_MaxPlayerCountProperty = serializedObject.FindProperty(nameof(PlayerInputManager.m_MaxPlayerCount)); | ||
| m_SplitScreenProperty = serializedObject.FindProperty(nameof(PlayerInputManager.m_SplitScreen)); | ||
| m_MaintainAspectRatioProperty = serializedObject.FindProperty(nameof(PlayerInputManager.m_MaintainAspectRatioInSplitScreen)); | ||
| m_FixedNumberOfSplitScreensProperty = serializedObject.FindProperty(nameof(PlayerInputManager.m_FixedNumberOfSplitScreens)); | ||
| m_SplitScreenRectProperty = serializedObject.FindProperty(nameof(PlayerInputManager.m_SplitScreenRect)); | ||
| } | ||
|
|
||
| public void OnDisable() | ||
|
|
@@ -35,8 +52,6 @@ | |
|
|
||
| public override void OnInspectorGUI() | ||
| { | ||
| ////TODO: cache properties | ||
|
|
||
| EditorGUI.BeginChangeCheck(); | ||
|
|
||
| DoNotificationSectionUI(); | ||
|
|
@@ -54,9 +69,8 @@ | |
|
|
||
| private void DoNotificationSectionUI() | ||
| { | ||
| var notificationBehaviorProperty = serializedObject.FindProperty(nameof(PlayerInputManager.m_NotificationBehavior)); | ||
| EditorGUILayout.PropertyField(notificationBehaviorProperty); | ||
| switch ((PlayerNotifications)notificationBehaviorProperty.intValue) | ||
| EditorGUILayout.PropertyField(m_NotificationBehaviorProperty); | ||
| switch ((PlayerNotifications)m_NotificationBehaviorProperty.intValue) | ||
|
Check warning on line 73 in Packages/com.unity.inputsystem/InputSystem/Plugins/PlayerInput/PlayerInputManagerEditor.cs
|
||
| { | ||
| case PlayerNotifications.SendMessages: | ||
| if (m_SendMessagesHelpText == null) | ||
|
|
@@ -76,11 +90,8 @@ | |
| m_EventsExpanded = EditorGUILayout.Foldout(m_EventsExpanded, m_EventsLabel, toggleOnLabelClick: true); | ||
| if (m_EventsExpanded) | ||
| { | ||
| var playerJoinedEventProperty = serializedObject.FindProperty(nameof(PlayerInputManager.m_PlayerJoinedEvent)); | ||
| var playerLeftEventProperty = serializedObject.FindProperty(nameof(PlayerInputManager.m_PlayerLeftEvent)); | ||
|
|
||
| EditorGUILayout.PropertyField(playerJoinedEventProperty); | ||
| EditorGUILayout.PropertyField(playerLeftEventProperty); | ||
| EditorGUILayout.PropertyField(m_PlayerJoinedEventProperty); | ||
| EditorGUILayout.PropertyField(m_PlayerLeftEventProperty); | ||
|
Check warning on line 94 in Packages/com.unity.inputsystem/InputSystem/Plugins/PlayerInput/PlayerInputManagerEditor.cs
|
||
| } | ||
| break; | ||
| } | ||
|
|
@@ -91,52 +102,47 @@ | |
| EditorGUILayout.LabelField(m_JoiningGroupLabel, EditorStyles.boldLabel); | ||
|
|
||
| // Join behavior | ||
| var joinBehaviorProperty = serializedObject.FindProperty(nameof(PlayerInputManager.m_JoinBehavior)); | ||
| EditorGUILayout.PropertyField(joinBehaviorProperty); | ||
| if ((PlayerJoinBehavior)joinBehaviorProperty.intValue != PlayerJoinBehavior.JoinPlayersManually) | ||
| EditorGUILayout.PropertyField(m_JoinBehaviorProperty); | ||
| if ((PlayerJoinBehavior)m_JoinBehaviorProperty.intValue != PlayerJoinBehavior.JoinPlayersManually) | ||
|
Check warning on line 106 in Packages/com.unity.inputsystem/InputSystem/Plugins/PlayerInput/PlayerInputManagerEditor.cs
|
||
| { | ||
| ++EditorGUI.indentLevel; | ||
|
|
||
| // Join action. | ||
| if ((PlayerJoinBehavior)joinBehaviorProperty.intValue == | ||
| if ((PlayerJoinBehavior)m_JoinBehaviorProperty.intValue == | ||
|
Check warning on line 111 in Packages/com.unity.inputsystem/InputSystem/Plugins/PlayerInput/PlayerInputManagerEditor.cs
|
||
| PlayerJoinBehavior.JoinPlayersWhenJoinActionIsTriggered) | ||
| { | ||
| var joinActionProperty = serializedObject.FindProperty(nameof(PlayerInputManager.m_JoinAction)); | ||
| EditorGUILayout.PropertyField(joinActionProperty); | ||
| EditorGUILayout.PropertyField(m_JoinActionProperty); | ||
|
Check warning on line 114 in Packages/com.unity.inputsystem/InputSystem/Plugins/PlayerInput/PlayerInputManagerEditor.cs
|
||
| } | ||
|
|
||
| // Player prefab. | ||
| var playerPrefabProperty = serializedObject.FindProperty(nameof(PlayerInputManager.m_PlayerPrefab)); | ||
| EditorGUILayout.PropertyField(playerPrefabProperty); | ||
| EditorGUILayout.PropertyField(m_PlayerPrefabProperty); | ||
|
Check warning on line 118 in Packages/com.unity.inputsystem/InputSystem/Plugins/PlayerInput/PlayerInputManagerEditor.cs
|
||
|
|
||
| ValidatePlayerPrefab(joinBehaviorProperty, playerPrefabProperty); | ||
| ValidatePlayerPrefab(m_JoinBehaviorProperty, m_PlayerPrefabProperty); | ||
|
Check warning on line 120 in Packages/com.unity.inputsystem/InputSystem/Plugins/PlayerInput/PlayerInputManagerEditor.cs
|
||
|
|
||
| --EditorGUI.indentLevel; | ||
| } | ||
|
|
||
| // Enabled-by-default. | ||
| var allowJoiningProperty = serializedObject.FindProperty(nameof(PlayerInputManager.m_AllowJoining)); | ||
| if (m_AllowingJoiningLabel == null) | ||
| m_AllowingJoiningLabel = new GUIContent("Joining Enabled By Default", allowJoiningProperty.GetTooltip()); | ||
| EditorGUILayout.PropertyField(allowJoiningProperty, m_AllowingJoiningLabel); | ||
| m_AllowingJoiningLabel = new GUIContent("Joining Enabled By Default", m_AllowJoiningProperty.GetTooltip()); | ||
| EditorGUILayout.PropertyField(m_AllowJoiningProperty, m_AllowingJoiningLabel); | ||
|
Check warning on line 128 in Packages/com.unity.inputsystem/InputSystem/Plugins/PlayerInput/PlayerInputManagerEditor.cs
|
||
|
|
||
| // Max player count. | ||
| var maxPlayerCountProperty = serializedObject.FindProperty(nameof(PlayerInputManager.m_MaxPlayerCount)); | ||
| if (m_EnableMaxPlayerCountLabel == null) | ||
| m_EnableMaxPlayerCountLabel = EditorGUIUtility.TrTextContent("Limit Number of Players", maxPlayerCountProperty.GetTooltip()); | ||
| if (maxPlayerCountProperty.intValue > 0) | ||
| m_EnableMaxPlayerCountLabel = EditorGUIUtility.TrTextContent("Limit Number of Players", m_MaxPlayerCountProperty.GetTooltip()); | ||
| if (m_MaxPlayerCountProperty.intValue > 0) | ||
|
Check warning on line 133 in Packages/com.unity.inputsystem/InputSystem/Plugins/PlayerInput/PlayerInputManagerEditor.cs
|
||
| m_MaxPlayerCountEnabled = true; | ||
| m_MaxPlayerCountEnabled = EditorGUILayout.Toggle(m_EnableMaxPlayerCountLabel, m_MaxPlayerCountEnabled); | ||
| if (m_MaxPlayerCountEnabled) | ||
| { | ||
| ++EditorGUI.indentLevel; | ||
| if (maxPlayerCountProperty.intValue < 0) | ||
| maxPlayerCountProperty.intValue = 1; | ||
| EditorGUILayout.PropertyField(maxPlayerCountProperty); | ||
| if (m_MaxPlayerCountProperty.intValue < 0) | ||
| m_MaxPlayerCountProperty.intValue = 1; | ||
| EditorGUILayout.PropertyField(m_MaxPlayerCountProperty); | ||
|
Check warning on line 141 in Packages/com.unity.inputsystem/InputSystem/Plugins/PlayerInput/PlayerInputManagerEditor.cs
|
||
| --EditorGUI.indentLevel; | ||
| } | ||
| else | ||
| maxPlayerCountProperty.intValue = -1; | ||
| m_MaxPlayerCountProperty.intValue = -1; | ||
|
Check warning on line 145 in Packages/com.unity.inputsystem/InputSystem/Plugins/PlayerInput/PlayerInputManagerEditor.cs
|
||
| } | ||
|
|
||
| private static void ValidatePlayerPrefab(SerializedProperty joinBehaviorProperty, | ||
|
|
@@ -174,51 +180,47 @@ | |
| EditorGUILayout.LabelField(m_SplitScreenGroupLabel, EditorStyles.boldLabel); | ||
|
|
||
| // Split-screen toggle. | ||
| var splitScreenProperty = serializedObject.FindProperty(nameof(PlayerInputManager.m_SplitScreen)); | ||
| if (m_SplitScreenLabel == null) | ||
| m_SplitScreenLabel = new GUIContent("Enable Split-Screen", splitScreenProperty.GetTooltip()); | ||
| EditorGUILayout.PropertyField(splitScreenProperty, m_SplitScreenLabel); | ||
| if (!splitScreenProperty.boolValue) | ||
| m_SplitScreenLabel = new GUIContent("Enable Split-Screen", m_SplitScreenProperty.GetTooltip()); | ||
| EditorGUILayout.PropertyField(m_SplitScreenProperty, m_SplitScreenLabel); | ||
| if (!m_SplitScreenProperty.boolValue) | ||
|
Check warning on line 186 in Packages/com.unity.inputsystem/InputSystem/Plugins/PlayerInput/PlayerInputManagerEditor.cs
|
||
| return; | ||
|
|
||
| ++EditorGUI.indentLevel; | ||
|
|
||
| // Maintain-aspect-ratio toggle. | ||
| var maintainAspectRatioProperty = serializedObject.FindProperty(nameof(PlayerInputManager.m_MaintainAspectRatioInSplitScreen)); | ||
| if (m_MaintainAspectRatioLabel == null) | ||
| m_MaintainAspectRatioLabel = | ||
| new GUIContent("Maintain Aspect Ratio", maintainAspectRatioProperty.GetTooltip()); | ||
| EditorGUILayout.PropertyField(maintainAspectRatioProperty, m_MaintainAspectRatioLabel); | ||
| new GUIContent("Maintain Aspect Ratio", m_MaintainAspectRatioProperty.GetTooltip()); | ||
| EditorGUILayout.PropertyField(m_MaintainAspectRatioProperty, m_MaintainAspectRatioLabel); | ||
|
Check warning on line 195 in Packages/com.unity.inputsystem/InputSystem/Plugins/PlayerInput/PlayerInputManagerEditor.cs
|
||
|
|
||
| // Fixed-number toggle. | ||
| var fixedNumberProperty = serializedObject.FindProperty(nameof(PlayerInputManager.m_FixedNumberOfSplitScreens)); | ||
| if (m_EnableFixedNumberOfSplitScreensLabel == null) | ||
| m_EnableFixedNumberOfSplitScreensLabel = EditorGUIUtility.TrTextContent("Set Fixed Number", fixedNumberProperty.GetTooltip()); | ||
| if (fixedNumberProperty.intValue > 0) | ||
| m_EnableFixedNumberOfSplitScreensLabel = EditorGUIUtility.TrTextContent("Set Fixed Number", m_FixedNumberOfSplitScreensProperty.GetTooltip()); | ||
| if (m_FixedNumberOfSplitScreensProperty.intValue > 0) | ||
|
Check warning on line 200 in Packages/com.unity.inputsystem/InputSystem/Plugins/PlayerInput/PlayerInputManagerEditor.cs
|
||
| m_FixedNumberOfSplitScreensEnabled = true; | ||
| m_FixedNumberOfSplitScreensEnabled = EditorGUILayout.Toggle(m_EnableFixedNumberOfSplitScreensLabel, | ||
| m_FixedNumberOfSplitScreensEnabled); | ||
| if (m_FixedNumberOfSplitScreensEnabled) | ||
| { | ||
| ++EditorGUI.indentLevel; | ||
| if (fixedNumberProperty.intValue < 0) | ||
| fixedNumberProperty.intValue = 4; | ||
| if (m_FixedNumberOfSplitScreensProperty.intValue < 0) | ||
| m_FixedNumberOfSplitScreensProperty.intValue = 4; | ||
|
Check warning on line 208 in Packages/com.unity.inputsystem/InputSystem/Plugins/PlayerInput/PlayerInputManagerEditor.cs
|
||
| if (m_FixedNumberOfSplitScreensLabel == null) | ||
| m_FixedNumberOfSplitScreensLabel = EditorGUIUtility.TrTextContent("Number of Screens", | ||
| fixedNumberProperty.tooltip); | ||
| EditorGUILayout.PropertyField(fixedNumberProperty, m_FixedNumberOfSplitScreensLabel); | ||
| m_FixedNumberOfSplitScreensProperty.tooltip); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is an inconsistency in how tooltips are accessed. On line 199, 🤖 Helpful? 👍/👎 |
||
| EditorGUILayout.PropertyField(m_FixedNumberOfSplitScreensProperty, m_FixedNumberOfSplitScreensLabel); | ||
|
Check warning on line 212 in Packages/com.unity.inputsystem/InputSystem/Plugins/PlayerInput/PlayerInputManagerEditor.cs
|
||
| --EditorGUI.indentLevel; | ||
| } | ||
| else | ||
| { | ||
| fixedNumberProperty.intValue = -1; | ||
| m_FixedNumberOfSplitScreensProperty.intValue = -1; | ||
|
Check warning on line 217 in Packages/com.unity.inputsystem/InputSystem/Plugins/PlayerInput/PlayerInputManagerEditor.cs
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar to the 🤖 Helpful? 👍/👎 |
||
| } | ||
|
|
||
| // Split-screen area. | ||
| var splitScreenAreaProperty = serializedObject.FindProperty(nameof(PlayerInputManager.m_SplitScreenRect)); | ||
| if (m_SplitScreenAreaLabel == null) | ||
| m_SplitScreenAreaLabel = new GUIContent("Screen Rectangle", splitScreenAreaProperty.GetTooltip()); | ||
| EditorGUILayout.PropertyField(splitScreenAreaProperty, m_SplitScreenAreaLabel); | ||
| m_SplitScreenAreaLabel = new GUIContent("Screen Rectangle", m_SplitScreenRectProperty.GetTooltip()); | ||
| EditorGUILayout.PropertyField(m_SplitScreenRectProperty, m_SplitScreenAreaLabel); | ||
|
Check warning on line 223 in Packages/com.unity.inputsystem/InputSystem/Plugins/PlayerInput/PlayerInputManagerEditor.cs
|
||
|
|
||
| --EditorGUI.indentLevel; | ||
| } | ||
|
|
@@ -251,6 +253,19 @@ | |
| [SerializeField] private bool m_MaxPlayerCountEnabled; | ||
| [SerializeField] private bool m_FixedNumberOfSplitScreensEnabled; | ||
|
|
||
| [NonSerialized] private SerializedProperty m_NotificationBehaviorProperty; | ||
| [NonSerialized] private SerializedProperty m_PlayerJoinedEventProperty; | ||
| [NonSerialized] private SerializedProperty m_PlayerLeftEventProperty; | ||
| [NonSerialized] private SerializedProperty m_JoinBehaviorProperty; | ||
| [NonSerialized] private SerializedProperty m_JoinActionProperty; | ||
| [NonSerialized] private SerializedProperty m_PlayerPrefabProperty; | ||
| [NonSerialized] private SerializedProperty m_AllowJoiningProperty; | ||
| [NonSerialized] private SerializedProperty m_MaxPlayerCountProperty; | ||
| [NonSerialized] private SerializedProperty m_SplitScreenProperty; | ||
| [NonSerialized] private SerializedProperty m_MaintainAspectRatioProperty; | ||
| [NonSerialized] private SerializedProperty m_FixedNumberOfSplitScreensProperty; | ||
| [NonSerialized] private SerializedProperty m_SplitScreenRectProperty; | ||
|
Comment on lines
+256
to
+267
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The 🤖 Helpful? 👍/👎 |
||
|
|
||
| [NonSerialized] private readonly GUIContent m_JoiningGroupLabel = EditorGUIUtility.TrTextContent("Joining"); | ||
| [NonSerialized] private readonly GUIContent m_SplitScreenGroupLabel = EditorGUIUtility.TrTextContent("Split-Screen"); | ||
| [NonSerialized] private readonly GUIContent m_EventsLabel = EditorGUIUtility.TrTextContent("Events"); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,21 +1,22 @@ | ||
| using UnityEngine.InputSystem; | ||
|
|
||
| ////FIXME: This should be UnityEngine.InputSystem.UI | ||
|
|
||
| #if UNITY_DISABLE_DEFAULT_INPUT_PLUGIN_INITIALIZATION | ||
| public | ||
| #else | ||
| internal | ||
| #endif | ||
| static class UISupport | ||
| namespace UnityEngine.InputSystem.UI | ||
| { | ||
| public static void Initialize() | ||
| #if UNITY_DISABLE_DEFAULT_INPUT_PLUGIN_INITIALIZATION | ||
| public | ||
| #else | ||
| internal | ||
| #endif | ||
| static class UISupport | ||
| { | ||
| InputSystem.RegisterLayout(@" | ||
| { | ||
| ""name"" : ""VirtualMouse"", | ||
| ""extend"" : ""Mouse"" | ||
| } | ||
| "); | ||
| public static void Initialize() | ||
| { | ||
| InputSystem.RegisterLayout(@" | ||
| { | ||
| ""name"" : ""VirtualMouse"", | ||
| ""extend"" : ""Mouse"" | ||
| } | ||
| "); | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Assigning a value to
m_MaxPlayerCountProperty.intValueinside theelseblock ofOnInspectorGUIwill result in an unconditional write to the serialized property on every GUI event (Layout, Repaint, etc.) whenever the toggle is disabled. This can cause theSerializedObjectto be marked dirty unnecessarily and may interfere with the Undo system or performance in large scenes. Consider wrapping this assignment in a check to see if the value is already-1, or perform the assignment only whenm_MaxPlayerCountEnabledchanges.🤖 Helpful? 👍/👎