Skip to content

CHANGE: Exploring uielements dependency #2177

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

Draft
wants to merge 6 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,7 @@
using UnityEngine.InputSystem.Processors;
using UnityEngine.InputSystem.Utilities;

#if UNITY_EDITOR
using System;
using UnityEditor;
using UnityEngine.InputSystem.Editor;
using UnityEngine.UIElements;
#endif


namespace UnityEngine.InputSystem.Composites
{
Expand Down Expand Up @@ -209,40 +204,5 @@ public enum WhichSideWins
}
}

#if UNITY_EDITOR
internal class AxisCompositeEditor : InputParameterEditor<AxisComposite>
{
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).");

public override void OnGUI()
{
#if UNITY_INPUT_SYSTEM_PROJECT_WIDE_ACTIONS
if (!InputSystem.settings.useIMGUIEditorForAssets) return;
#endif
target.whichSideWins = (AxisComposite.WhichSideWins)EditorGUILayout.EnumPopup(m_WhichAxisWinsLabel, target.whichSideWins);
}

#if UNITY_INPUT_SYSTEM_PROJECT_WIDE_ACTIONS
public override void OnDrawVisualElements(VisualElement root, Action onChangedCallback)
{
var modeField = new EnumField(m_WhichAxisWinsLabel.text, target.whichSideWins)
{
tooltip = m_WhichAxisWinsLabel.tooltip
};

modeField.RegisterValueChangedCallback(evt =>
{
target.whichSideWins = (AxisComposite.WhichSideWins)evt.newValue;
onChangedCallback();
});

root.Add(modeField);
}

#endif
}
#endif

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@
using UnityEngine.InputSystem.Layouts;
using UnityEngine.InputSystem.Utilities;

#if UNITY_EDITOR
using UnityEditor;
using UnityEngine.InputSystem.Editor;
using UnityEngine.UIElements;
#endif

////TODO: add support for ramp up/down

Expand Down Expand Up @@ -189,40 +184,4 @@ public enum Mode
}
}

#if UNITY_EDITOR
internal class Vector2CompositeEditor : InputParameterEditor<Vector2Composite>
{
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.");

public override void OnGUI()
{
#if UNITY_INPUT_SYSTEM_PROJECT_WIDE_ACTIONS
if (!InputSystem.settings.useIMGUIEditorForAssets) return;
#endif
target.mode = (Vector2Composite.Mode)EditorGUILayout.EnumPopup(m_ModeLabel, target.mode);
}

#if UNITY_INPUT_SYSTEM_PROJECT_WIDE_ACTIONS
public override void OnDrawVisualElements(VisualElement root, Action onChangedCallback)
{
var modeField = new EnumField(m_ModeLabel.text, target.mode)
{
tooltip = m_ModeLabel.tooltip
};

modeField.RegisterValueChangedCallback(evt =>
{
target.mode = (Vector2Composite.Mode)evt.newValue;
onChangedCallback();
});

root.Add(modeField);
}

#endif
}
#endif
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@
using UnityEngine.InputSystem.Layouts;
using UnityEngine.InputSystem.Utilities;

#if UNITY_EDITOR
using UnityEditor;
using UnityEngine.InputSystem.Editor;
using UnityEngine.UIElements;
#endif

namespace UnityEngine.InputSystem.Composites
{
Expand Down Expand Up @@ -169,40 +164,4 @@ public enum Mode
}
}

#if UNITY_EDITOR
internal class Vector3CompositeEditor : InputParameterEditor<Vector3Composite>
{
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.");

public override void OnGUI()
{
#if UNITY_INPUT_SYSTEM_PROJECT_WIDE_ACTIONS
if (!InputSystem.settings.useIMGUIEditorForAssets) return;
#endif
target.mode = (Vector3Composite.Mode)EditorGUILayout.EnumPopup(m_ModeLabel, target.mode);
}

#if UNITY_INPUT_SYSTEM_PROJECT_WIDE_ACTIONS
public override void OnDrawVisualElements(VisualElement root, Action onChangedCallback)
{
var modeField = new EnumField(m_ModeLabel.text, target.mode)
{
tooltip = m_ModeLabel.tooltip
};

modeField.RegisterValueChangedCallback(evt =>
{
target.mode = (Vector3Composite.Mode)evt.newValue;
onChangedCallback();
});

root.Add(modeField);
}

#endif
}
#endif
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@
using System.ComponentModel;
using UnityEngine.InputSystem.Controls;
using UnityEngine.Scripting;
#if UNITY_EDITOR
using UnityEngine.InputSystem.Editor;
using UnityEngine.UIElements;
#endif


namespace UnityEngine.InputSystem.Interactions
{
Expand Down Expand Up @@ -104,44 +101,4 @@ public void Reset()
}
}

#if UNITY_EDITOR
/// <summary>
/// UI that is displayed when editing <see cref="HoldInteraction"/> in the editor.
/// </summary>
internal class HoldInteractionEditor : InputParameterEditor<HoldInteraction>
{
protected override void OnEnable()
{
m_PressPointSetting.Initialize("Press Point",
"Float value that an axis control has to cross for it to be considered pressed.",
"Default Button Press Point",
() => target.pressPoint, v => target.pressPoint = v, () => ButtonControl.s_GlobalDefaultButtonPressPoint);
m_DurationSetting.Initialize("Hold Time",
"Time (in seconds) that a control has to be held in order for it to register as a hold.",
"Default Hold Time",
() => target.duration, x => target.duration = x, () => InputSystem.settings.defaultHoldTime);
}

public override void OnGUI()
{
#if UNITY_INPUT_SYSTEM_PROJECT_WIDE_ACTIONS
if (!InputSystem.settings.useIMGUIEditorForAssets) return;
#endif
m_PressPointSetting.OnGUI();
m_DurationSetting.OnGUI();
}

#if UNITY_INPUT_SYSTEM_PROJECT_WIDE_ACTIONS
public override void OnDrawVisualElements(VisualElement root, Action onChangedCallback)
{
m_PressPointSetting.OnDrawVisualElements(root, onChangedCallback);
m_DurationSetting.OnDrawVisualElements(root, onChangedCallback);
}

#endif

private CustomOrDefaultSetting m_PressPointSetting;
private CustomOrDefaultSetting m_DurationSetting;
}
#endif
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
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)

Expand Down Expand Up @@ -169,69 +164,4 @@ private enum TapPhase
}
}

#if UNITY_EDITOR
/// <summary>
/// UI that is displayed when editing <see cref="HoldInteraction"/> in the editor.
/// </summary>
internal class MultiTapInteractionEditor : InputParameterEditor<MultiTapInteraction>
{
protected override void OnEnable()
{
m_TapTimeSetting.Initialize("Max Tap Duration",
"Time (in seconds) within with a control has to be released again for it to register as a tap. If the control is held "
+ "for longer than this time, the tap is canceled.",
"Default Tap Time",
() => target.tapTime, x => target.tapTime = x, () => InputSystem.settings.defaultTapTime);
m_TapDelaySetting.Initialize("Max Tap Spacing",
"The maximum delay (in seconds) allowed between each tap. If this time is exceeded, the multi-tap is canceled.",
"Default Tap Spacing",
() => target.tapDelay, x => target.tapDelay = x, () => InputSystem.settings.multiTapDelayTime);
m_PressPointSetting.Initialize("Press Point",
"The amount of actuation a control requires before being considered pressed. If not set, default to "
+ "'Default Button Press Point' in the global input settings.",
"Default Button Press Point",
() => target.pressPoint, v => target.pressPoint = v,
() => InputSystem.settings.defaultButtonPressPoint);
}

public override void OnGUI()
{
#if UNITY_INPUT_SYSTEM_PROJECT_WIDE_ACTIONS
if (!InputSystem.settings.useIMGUIEditorForAssets) return;
#endif
target.tapCount = EditorGUILayout.IntField(m_TapCountLabel, target.tapCount);
m_TapDelaySetting.OnGUI();
m_TapTimeSetting.OnGUI();
m_PressPointSetting.OnGUI();
}

#if UNITY_INPUT_SYSTEM_PROJECT_WIDE_ACTIONS
public override void OnDrawVisualElements(VisualElement root, Action onChangedCallback)
{
var tapCountField = new IntegerField(m_TapCountLabel.text)
{
value = target.tapCount,
tooltip = m_TapCountLabel.tooltip
};
tapCountField.RegisterValueChangedCallback(evt =>
{
target.tapCount = evt.newValue;
onChangedCallback?.Invoke();
});
root.Add(tapCountField);

m_TapDelaySetting.OnDrawVisualElements(root, onChangedCallback);
m_TapTimeSetting.OnDrawVisualElements(root, onChangedCallback);
m_PressPointSetting.OnDrawVisualElements(root, onChangedCallback);
}

#endif

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;
private CustomOrDefaultSetting m_TapDelaySetting;
}
#endif
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,7 @@
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
////TODO: also, for analog controls, we probably want a deadzone that gives just a tiny little buffer at the low end before the action starts
Expand Down Expand Up @@ -194,64 +189,4 @@ public enum PressBehavior
PressAndRelease = 2,
}

#if UNITY_EDITOR
/// <summary>
/// UI that is displayed when editing <see cref="PressInteraction"/> in the editor.
/// </summary>
// ReSharper disable once UnusedMember.Global
internal class PressInteractionEditor : InputParameterEditor<PressInteraction>
{
protected override void OnEnable()
{
m_PressPointSetting.Initialize("Press Point",
"The amount of actuation a control requires before being considered pressed. If not set, default to "
+ "'Default Button Press Point' in the global input settings.",
"Default Button Press Point",
() => target.pressPoint, v => target.pressPoint = v,
() => InputSystem.settings.defaultButtonPressPoint);
}

public override void OnGUI()
{
#if UNITY_INPUT_SYSTEM_PROJECT_WIDE_ACTIONS
if (!InputSystem.settings.useIMGUIEditorForAssets) return;
#endif
EditorGUILayout.HelpBox(s_HelpBoxText);
target.behavior = (PressBehavior)EditorGUILayout.EnumPopup(s_PressBehaviorLabel, target.behavior);
m_PressPointSetting.OnGUI();
}

#if UNITY_INPUT_SYSTEM_PROJECT_WIDE_ACTIONS
public override void OnDrawVisualElements(VisualElement root, Action onChangedCallback)
{
root.Add(new HelpBox(s_HelpBoxText.text, HelpBoxMessageType.None));

var behaviourDropdown = new EnumField(s_PressBehaviorLabel.text, target.behavior)
{
tooltip = s_PressBehaviorLabel.tooltip
};
behaviourDropdown.RegisterValueChangedCallback(evt =>
{
target.behavior = (PressBehavior)evt.newValue;
onChangedCallback?.Invoke();
});
root.Add(behaviourDropdown);

m_PressPointSetting.OnDrawVisualElements(root, onChangedCallback);
}

#endif

private CustomOrDefaultSetting m_PressPointSetting;

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 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.");
}
#endif
}
Loading