diff --git a/Assets/Samples/CustomComposite/CustomComposite.cs b/Assets/Samples/CustomComposite/CustomComposite.cs index 0cbd54c3e0..273a54f4cd 100644 --- a/Assets/Samples/CustomComposite/CustomComposite.cs +++ b/Assets/Samples/CustomComposite/CustomComposite.cs @@ -136,6 +136,13 @@ public class CustomCompositeEditor : InputParameterEditor { public override void OnGUI() { + // Using the 'target' property, we can access an instance of our composite. + var currentValue = target.scaleFactor; + + // The easiest way to lay out our UI is to simply use EditorGUILayout. + // We simply assign the changed value back to the 'target' object. The input + // system will automatically detect a change in value. + target.scaleFactor = EditorGUILayout.Slider(m_ScaleFactorLabel, currentValue, 0, 2); } public override void OnDrawVisualElements(VisualElement root, Action onChangedCallback) diff --git a/Packages/com.unity.inputsystem/InputSystem/Actions/Composites/AxisComposite.cs b/Packages/com.unity.inputsystem/InputSystem/Actions/Composites/AxisComposite.cs index 297ecb0c36..da72a70b8a 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Actions/Composites/AxisComposite.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Actions/Composites/AxisComposite.cs @@ -5,6 +5,7 @@ #if UNITY_EDITOR using System; +using UnityEditor; using UnityEngine.InputSystem.Editor; using UnityEngine.UIElements; #endif @@ -211,20 +212,24 @@ public enum WhichSideWins #if UNITY_EDITOR internal class AxisCompositeEditor : InputParameterEditor { - private const string label = "Which Side Wins"; - private const string tooltipText = "Determine which axis 'wins' if both are actuated at the same time. " + private GUIContent m_WhichAxisWinsLabel = new GUIContent("Which Side Wins", + "Determine which axis 'wins' if both are actuated at the same time. " + "If 'Neither' is selected, the result is 0 (or, more precisely, " - + "the midpoint between minValue and maxValue)."; + + "the midpoint between minValue and maxValue)."); public override void OnGUI() { + if (!InputSystem.settings.useIMGUIEditorForAssets) + return; + + target.whichSideWins = (AxisComposite.WhichSideWins)EditorGUILayout.EnumPopup(m_WhichAxisWinsLabel, target.whichSideWins); } public override void OnDrawVisualElements(VisualElement root, Action onChangedCallback) { - var modeField = new EnumField(label, target.whichSideWins) + var modeField = new EnumField(m_WhichAxisWinsLabel.text, target.whichSideWins) { - tooltip = tooltipText + tooltip = m_WhichAxisWinsLabel.tooltip }; modeField.RegisterValueChangedCallback(evt => diff --git a/Packages/com.unity.inputsystem/InputSystem/Actions/Composites/Vector2Composite.cs b/Packages/com.unity.inputsystem/InputSystem/Actions/Composites/Vector2Composite.cs index a8568f8013..730588db0c 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Actions/Composites/Vector2Composite.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Actions/Composites/Vector2Composite.cs @@ -5,6 +5,7 @@ using UnityEngine.InputSystem.Utilities; #if UNITY_EDITOR +using UnityEditor; using UnityEngine.InputSystem.Editor; using UnityEngine.UIElements; #endif @@ -191,20 +192,24 @@ public enum Mode #if UNITY_EDITOR internal class Vector2CompositeEditor : InputParameterEditor { - private const string label = "Mode"; - private const string tooltipText = "How to synthesize a Vector2 from the inputs. Digital " + private GUIContent m_ModeLabel = new GUIContent("Mode", + "How to synthesize a Vector2 from the inputs. Digital " + "treats part bindings as buttons (on/off) whereas Analog preserves " - + "floating-point magnitudes as read from controls."; + + "floating-point magnitudes as read from controls."); public override void OnGUI() { + if (!InputSystem.settings.useIMGUIEditorForAssets) + return; + + target.mode = (Vector2Composite.Mode)EditorGUILayout.EnumPopup(m_ModeLabel, target.mode); } public override void OnDrawVisualElements(VisualElement root, Action onChangedCallback) { - var modeField = new EnumField(label, target.mode) + var modeField = new EnumField(m_ModeLabel.text, target.mode) { - tooltip = tooltipText + tooltip = m_ModeLabel.tooltip }; modeField.RegisterValueChangedCallback(evt => diff --git a/Packages/com.unity.inputsystem/InputSystem/Actions/Composites/Vector3Composite.cs b/Packages/com.unity.inputsystem/InputSystem/Actions/Composites/Vector3Composite.cs index 72371f81b3..21383c700b 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Actions/Composites/Vector3Composite.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Actions/Composites/Vector3Composite.cs @@ -4,6 +4,7 @@ using UnityEngine.InputSystem.Utilities; #if UNITY_EDITOR +using UnityEditor; using UnityEngine.InputSystem.Editor; using UnityEngine.UIElements; #endif @@ -171,20 +172,24 @@ public enum Mode #if UNITY_EDITOR internal class Vector3CompositeEditor : InputParameterEditor { - private const string label = "Mode"; - private const string tooltip = "How to synthesize a Vector3 from the inputs. Digital " + private GUIContent m_ModeLabel = new GUIContent("Mode", + "How to synthesize a Vector3 from the inputs. Digital " + "treats part bindings as buttons (on/off) whereas Analog preserves " - + "floating-point magnitudes as read from controls."; + + "floating-point magnitudes as read from controls."); public override void OnGUI() { + if (!InputSystem.settings.useIMGUIEditorForAssets) + return; + + target.mode = (Vector3Composite.Mode)EditorGUILayout.EnumPopup(m_ModeLabel, target.mode); } public override void OnDrawVisualElements(VisualElement root, Action onChangedCallback) { - var modeField = new EnumField(label, target.mode) + var modeField = new EnumField(m_ModeLabel.text, target.mode) { - tooltip = tooltip + tooltip = m_ModeLabel.tooltip }; modeField.RegisterValueChangedCallback(evt => diff --git a/Packages/com.unity.inputsystem/InputSystem/Actions/Interactions/HoldInteraction.cs b/Packages/com.unity.inputsystem/InputSystem/Actions/Interactions/HoldInteraction.cs index 45f08e261f..9345d5f9b0 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Actions/Interactions/HoldInteraction.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Actions/Interactions/HoldInteraction.cs @@ -1,7 +1,7 @@ using System; using System.ComponentModel; using UnityEngine.InputSystem.Controls; - +using UnityEngine.Scripting; #if UNITY_EDITOR using UnityEngine.InputSystem.Editor; using UnityEngine.UIElements; @@ -124,6 +124,11 @@ protected override void OnEnable() public override void OnGUI() { + if (!InputSystem.settings.useIMGUIEditorForAssets) + return; + + m_PressPointSetting.OnGUI(); + m_DurationSetting.OnGUI(); } public override void OnDrawVisualElements(VisualElement root, Action onChangedCallback) diff --git a/Packages/com.unity.inputsystem/InputSystem/Actions/Interactions/MultiTapInteraction.cs b/Packages/com.unity.inputsystem/InputSystem/Actions/Interactions/MultiTapInteraction.cs index d068639dae..41610ced29 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Actions/Interactions/MultiTapInteraction.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Actions/Interactions/MultiTapInteraction.cs @@ -1,9 +1,11 @@ using System; using UnityEngine.InputSystem.Controls; - +using UnityEngine.Scripting; #if UNITY_EDITOR +using UnityEditor; using UnityEngine.InputSystem.Editor; using UnityEngine.UIElements; +using UnityEditor.UIElements; #endif ////TODO: add ability to respond to any of the taps in the sequence (e.g. one response for single tap, another for double tap) @@ -194,14 +196,21 @@ protected override void OnEnable() public override void OnGUI() { + if (!InputSystem.settings.useIMGUIEditorForAssets) + return; + + target.tapCount = EditorGUILayout.IntField(m_TapCountLabel, target.tapCount); + m_TapDelaySetting.OnGUI(); + m_TapTimeSetting.OnGUI(); + m_PressPointSetting.OnGUI(); } public override void OnDrawVisualElements(VisualElement root, Action onChangedCallback) { - var tapCountField = new IntegerField(tapLabel) + var tapCountField = new IntegerField(m_TapCountLabel.text) { value = target.tapCount, - tooltip = tapTooltip + tooltip = m_TapCountLabel.tooltip }; tapCountField.RegisterValueChangedCallback(evt => { @@ -215,8 +224,7 @@ public override void OnDrawVisualElements(VisualElement root, Action onChangedCa m_PressPointSetting.OnDrawVisualElements(root, onChangedCallback); } - private const string tapLabel = "Tap Count"; - private const string tapTooltip = "How many taps need to be performed in succession. Two means double-tap, three means triple-tap, and so on."; + private readonly GUIContent m_TapCountLabel = new GUIContent("Tap Count", "How many taps need to be performed in succession. Two means double-tap, three means triple-tap, and so on."); private CustomOrDefaultSetting m_PressPointSetting; private CustomOrDefaultSetting m_TapTimeSetting; diff --git a/Packages/com.unity.inputsystem/InputSystem/Actions/Interactions/PressInteraction.cs b/Packages/com.unity.inputsystem/InputSystem/Actions/Interactions/PressInteraction.cs index 3b7c7a20b0..f5361ae56b 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Actions/Interactions/PressInteraction.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Actions/Interactions/PressInteraction.cs @@ -1,9 +1,12 @@ using System; using System.ComponentModel; using UnityEngine.InputSystem.Controls; +using UnityEngine.Scripting; #if UNITY_EDITOR +using UnityEditor; using UnityEngine.InputSystem.Editor; using UnityEngine.UIElements; +using UnityEditor.UIElements; #endif ////TODO: protect against the control *hovering* around the press point; this should not fire the press repeatedly; probably need a zone around the press point @@ -210,15 +213,21 @@ protected override void OnEnable() public override void OnGUI() { + if (!InputSystem.settings.useIMGUIEditorForAssets) + return; + + EditorGUILayout.HelpBox(s_HelpBoxText); + target.behavior = (PressBehavior)EditorGUILayout.EnumPopup(s_PressBehaviorLabel, target.behavior); + m_PressPointSetting.OnGUI(); } public override void OnDrawVisualElements(VisualElement root, Action onChangedCallback) { - root.Add(new HelpBox(helpLabel, HelpBoxMessageType.None)); + root.Add(new HelpBox(s_HelpBoxText.text, HelpBoxMessageType.None)); - var behaviourDropdown = new EnumField(triggerLabel, target.behavior) + var behaviourDropdown = new EnumField(s_PressBehaviorLabel.text, target.behavior) { - tooltip = triggerTooltip + tooltip = s_PressBehaviorLabel.tooltip }; behaviourDropdown.RegisterValueChangedCallback(evt => { @@ -232,13 +241,14 @@ public override void OnDrawVisualElements(VisualElement root, Action onChangedCa private CustomOrDefaultSetting m_PressPointSetting; - private const string helpLabel = "Note that the 'Press' interaction is only " + private static readonly GUIContent s_HelpBoxText = EditorGUIUtility.TrTextContent("Note that the 'Press' interaction is only " + "necessary when wanting to customize button press behavior. For default press behavior, simply set the action type to 'Button' " - + "and use the action without interactions added to it."; - private const string triggerLabel = "Trigger Behavior"; - private const string triggerTooltip = "Determines how button presses trigger the action. By default (PressOnly), the action is performed on press. " + + "and use the action without interactions added to it."); + + private static readonly GUIContent s_PressBehaviorLabel = EditorGUIUtility.TrTextContent("Trigger Behavior", + "Determines how button presses trigger the action. By default (PressOnly), the action is performed on press. " + "With ReleaseOnly, the action is performed on release. With PressAndRelease, the action is performed on press and " - + "canceled on release."; + + "canceled on release."); } #endif } diff --git a/Packages/com.unity.inputsystem/InputSystem/Actions/Interactions/SlowTapInteraction.cs b/Packages/com.unity.inputsystem/InputSystem/Actions/Interactions/SlowTapInteraction.cs index 6d663989b5..cb79393e00 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Actions/Interactions/SlowTapInteraction.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Actions/Interactions/SlowTapInteraction.cs @@ -1,6 +1,7 @@ using System; using System.ComponentModel; using UnityEngine.InputSystem.Controls; +using UnityEngine.Scripting; #if UNITY_EDITOR using UnityEngine.InputSystem.Editor; using UnityEngine.UIElements; @@ -87,6 +88,11 @@ protected override void OnEnable() public override void OnGUI() { + if (!InputSystem.settings.useIMGUIEditorForAssets) + return; + + m_DurationSetting.OnGUI(); + m_PressPointSetting.OnGUI(); } public override void OnDrawVisualElements(VisualElement root, Action onChangedCallback) diff --git a/Packages/com.unity.inputsystem/InputSystem/Actions/Interactions/TapInteraction.cs b/Packages/com.unity.inputsystem/InputSystem/Actions/Interactions/TapInteraction.cs index 9fea108006..cd3fe54b95 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Actions/Interactions/TapInteraction.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Actions/Interactions/TapInteraction.cs @@ -1,6 +1,7 @@ using System; using System.ComponentModel; using UnityEngine.InputSystem.Controls; +using UnityEngine.Scripting; #if UNITY_EDITOR using UnityEngine.InputSystem.Editor; using UnityEngine.UIElements; @@ -113,6 +114,11 @@ protected override void OnEnable() public override void OnGUI() { + if (!InputSystem.settings.useIMGUIEditorForAssets) + return; + + m_DurationSetting.OnGUI(); + m_PressPointSetting.OnGUI(); } public override void OnDrawVisualElements(VisualElement root, Action onChangedCallback) diff --git a/Packages/com.unity.inputsystem/InputSystem/Controls/Processors/AxisDeadzoneProcessor.cs b/Packages/com.unity.inputsystem/InputSystem/Controls/Processors/AxisDeadzoneProcessor.cs index 066eb2aaf4..f86bb17c18 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Controls/Processors/AxisDeadzoneProcessor.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Controls/Processors/AxisDeadzoneProcessor.cs @@ -1,4 +1,5 @@ using System; +using UnityEngine.Scripting; #if UNITY_EDITOR using UnityEngine.InputSystem.Editor; @@ -92,6 +93,11 @@ protected override void OnEnable() public override void OnGUI() { + if (!InputSystem.settings.useIMGUIEditorForAssets) + return; + + m_MinSetting.OnGUI(); + m_MaxSetting.OnGUI(); } public override void OnDrawVisualElements(VisualElement root, Action onChangedCallback) diff --git a/Packages/com.unity.inputsystem/InputSystem/Controls/Processors/StickDeadzoneProcessor.cs b/Packages/com.unity.inputsystem/InputSystem/Controls/Processors/StickDeadzoneProcessor.cs index 1dec047010..631f7b51d5 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Controls/Processors/StickDeadzoneProcessor.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Controls/Processors/StickDeadzoneProcessor.cs @@ -1,4 +1,5 @@ using System; +using UnityEngine.Scripting; #if UNITY_EDITOR using UnityEngine.InputSystem.Editor; @@ -81,6 +82,11 @@ protected override void OnEnable() public override void OnGUI() { + if (!InputSystem.settings.useIMGUIEditorForAssets) + return; + + m_MinSetting.OnGUI(); + m_MaxSetting.OnGUI(); } public override void OnDrawVisualElements(VisualElement root, Action onChangedCallback) diff --git a/Packages/com.unity.inputsystem/InputSystem/Editor/Analytics/InputBuildAnalytic.cs b/Packages/com.unity.inputsystem/InputSystem/Editor/Analytics/InputBuildAnalytic.cs index dd719aa8f3..78666fd1dd 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Editor/Analytics/InputBuildAnalytic.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Editor/Analytics/InputBuildAnalytic.cs @@ -381,4 +381,4 @@ public void OnPostprocessBuild(BuildReport report) } } } -#endif +#endif \ No newline at end of file diff --git a/Packages/com.unity.inputsystem/InputSystem/Editor/AssetEditor/ParameterListView.cs b/Packages/com.unity.inputsystem/InputSystem/Editor/AssetEditor/ParameterListView.cs index 9b38064796..25bd44764c 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Editor/AssetEditor/ParameterListView.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Editor/AssetEditor/ParameterListView.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Reflection; using UnityEditor; +using UnityEditor.UIElements; using UnityEngine.InputSystem.Layouts; using UnityEngine.InputSystem.Utilities; using UnityEngine.UIElements; @@ -134,7 +135,7 @@ public void Initialize(Type registeredType, ReadOnlyArray existingPa parameter.value = parameter.value.ConvertTo(underlyingTypeCode); // Read enum names and values. - parameter.enumNames = Enum.GetNames(fieldType); + parameter.enumNames = Enum.GetNames(fieldType).Select(x => new GUIContent(x)).ToArray(); ////REVIEW: this probably falls apart if multiple members have the same value var list = new List(); foreach (var value in Enum.GetValues(fieldType)) @@ -223,7 +224,7 @@ public void Initialize(Type registeredType, ReadOnlyArray existingPa m_ParameterEditor = null; // Create parameter labels. - m_ParameterLabels = new(string text, string tooltip)[m_Parameters.Length]; + m_ParameterLabels = new GUIContent[m_Parameters.Length]; for (var i = 0; i < m_Parameters.Length; ++i) { // Look up tooltip from field. @@ -235,7 +236,7 @@ public void Initialize(Type registeredType, ReadOnlyArray existingPa // Create label. var niceName = ObjectNames.NicifyVariableName(m_Parameters[i].value.name); - m_ParameterLabels[i] = (niceName, tooltip); + m_ParameterLabels[i] = new GUIContent(niceName, tooltip); } } } @@ -276,7 +277,7 @@ void OnEditEnd() if (parameter.isEnum) { - var names = parameter.enumNames.ToList(); + var names = parameter.enumNames.Select(c => c.text).ToList(); var rawValue = parameter.value.value.ToInt32(); var selectedIndex = parameter.enumValues.IndexOf(rawValue); if (selectedIndex < 0 || selectedIndex >= names.Count) @@ -349,6 +350,72 @@ private void OnValuesChanged() public void OnGUI() { + // If we have a dedicated parameter editor, let it do all the work. + if (m_ParameterEditor != null) + { + EditorGUI.BeginChangeCheck(); + m_ParameterEditor.OnGUI(); + if (EditorGUI.EndChangeCheck()) + { + ReadParameterValuesFrom(m_ParameterEditor.target); + onChange?.Invoke(); + } + return; + } + + // handled by OnDrawVisualElements with UI Toolkit + if (!InputSystem.settings.useIMGUIEditorForAssets) + return; + + // Otherwise, fall back to our default logic. + if (m_Parameters == null) + return; + for (var i = 0; i < m_Parameters.Length; i++) + { + var parameter = m_Parameters[i]; + var label = m_ParameterLabels[i]; + + EditorGUI.BeginChangeCheck(); + + object result = null; + if (parameter.isEnum) + { + var intValue = parameter.value.value.ToInt32(); + result = EditorGUILayout.IntPopup(label, intValue, parameter.enumNames, parameter.enumValues); + } + else if (parameter.value.type == TypeCode.Int64 || parameter.value.type == TypeCode.UInt64) + { + var longValue = parameter.value.value.ToInt64(); + result = EditorGUILayout.LongField(label, longValue); + } + else if (parameter.value.type.IsInt()) + { + var intValue = parameter.value.value.ToInt32(); + result = EditorGUILayout.IntField(label, intValue); + } + else if (parameter.value.type == TypeCode.Single) + { + var floatValue = parameter.value.value.ToSingle(); + result = EditorGUILayout.FloatField(label, floatValue); + } + else if (parameter.value.type == TypeCode.Double) + { + var floatValue = parameter.value.value.ToDouble(); + result = EditorGUILayout.DoubleField(label, floatValue); + } + else if (parameter.value.type == TypeCode.Boolean) + { + var boolValue = parameter.value.value.ToBoolean(); + result = EditorGUILayout.Toggle(label, boolValue); + } + + if (EditorGUI.EndChangeCheck()) + { + parameter.value.value = PrimitiveValue.FromObject(result).ConvertTo(parameter.value.type); + m_Parameters[i] = parameter; + onChange?.Invoke(); + } + } } ////REVIEW: check whether parameters have *actually* changed? @@ -381,15 +448,14 @@ private void ReadParameterValuesFrom(object target) private InputParameterEditor m_ParameterEditor; private EditableParameterValue[] m_Parameters; - - private (string text, string tooltip)[] m_ParameterLabels; + private GUIContent[] m_ParameterLabels; private struct EditableParameterValue { public NamedValue value; public NamedValue? defaultValue; public int[] enumValues; - public string[] enumNames; + public GUIContent[] enumNames; public FieldInfo field; public bool isEnum => enumValues != null; diff --git a/Packages/com.unity.inputsystem/InputSystem/Editor/InputParameterEditor.cs b/Packages/com.unity.inputsystem/InputSystem/Editor/InputParameterEditor.cs index 6313b4343c..c2b8d0dc1c 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Editor/InputParameterEditor.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Editor/InputParameterEditor.cs @@ -210,19 +210,12 @@ public void Initialize(string label, string tooltip, string defaultName, Func> Project Settings... >> Input (NEW)." - : "If enabled, the default value is used."); + m_ToggleLabel = EditorGUIUtility.TrTextContent( + "Default", $"If enabled, the default {label.ToLowerInvariant()} configured globally in the input settings is used. See Edit >> Project Settings... >> Input (NEW)."); m_ValueLabel = EditorGUIUtility.TrTextContent(label, tooltip); - if (defaultComesFromInputSettings) - m_OpenInputSettingsLabel = EditorGUIUtility.TrTextContent("Open Input Settings"); m_DefaultInitializedValue = defaultInitializedValue; m_UseDefaultValue = Mathf.Approximately(getValue(), defaultInitializedValue); m_DefaultComesFromInputSettings = defaultComesFromInputSettings; - m_HelpBoxText = - EditorGUIUtility.TrTextContent( - $"Uses \"{defaultName}\" set in project-wide input settings."); } public void OnDrawVisualElements(VisualElement root, Action onChangedCallback) @@ -249,12 +242,10 @@ public void OnDrawVisualElements(VisualElement root, Action onChangedCallback) m_FloatField.RegisterValueChangedCallback(ChangeSettingValue); m_FloatField.RegisterCallback(_ => OnEditEnd(onChangedCallback)); m_FloatField.SetEnabled(!m_UseDefaultValue); - - m_HelpBox = new HelpBox(m_HelpBoxText.text, HelpBoxMessageType.None); - m_DefaultToggle = new Toggle("Default") { value = m_UseDefaultValue, + tooltip = m_ToggleLabel.tooltip, style = { flexDirection = FlexDirection.RowReverse @@ -263,28 +254,10 @@ public void OnDrawVisualElements(VisualElement root, Action onChangedCallback) m_DefaultToggle.RegisterValueChangedCallback(evt => ToggleUseDefaultValue(evt, onChangedCallback)); m_DefaultToggle.Q