breakpoint
before update unity version
This commit is contained in:
@@ -2,10 +2,12 @@ using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using Object = UnityEngine.Object;
|
||||
#if UNITY_EDITOR
|
||||
using UnityEngine.UIElements;
|
||||
using UnityEditor;
|
||||
using UnityEditor.UIElements;
|
||||
using UnityEngine.InputSystem;
|
||||
#endif
|
||||
namespace BITKit
|
||||
{
|
||||
@@ -21,9 +23,15 @@ namespace BITKit
|
||||
#if UNITY_EDITOR
|
||||
public class BITInputSystemEditor : EditorWindow
|
||||
{
|
||||
Toggle allowInput;
|
||||
private Toggle allowInput;
|
||||
private Toggle allowInputLog;
|
||||
private InputAction _inputAction;
|
||||
private ObjectField inputActionField;
|
||||
|
||||
private Label nameLabel;
|
||||
private Label valueLabel;
|
||||
[MenuItem("Tools/InputSystemEditor")]
|
||||
static void Entry()
|
||||
private static void Open()
|
||||
{
|
||||
GetWindow<BITInputSystemEditor>().Show();
|
||||
}
|
||||
@@ -36,10 +44,87 @@ namespace BITKit
|
||||
rootVisualElement.style.paddingBottom = 16;
|
||||
rootVisualElement.Add(allowInput =new Toggle());
|
||||
allowInput.text = "Enable Input";
|
||||
allowInput.SetEnabled(false);
|
||||
allowInput.style.opacity = 1;
|
||||
|
||||
allowInputLog = rootVisualElement.Create<Toggle>();
|
||||
allowInputLog.text = "Enable Input Log";
|
||||
|
||||
inputActionField = rootVisualElement.Create<ObjectField>();
|
||||
inputActionField.label = "Debug InputAction";
|
||||
|
||||
inputActionField.RegisterValueChangedCallback(NewValue);
|
||||
inputActionField.objectType = typeof(InputActionReference);
|
||||
|
||||
var hContainer = rootVisualElement.Create<VisualElement>();
|
||||
hContainer.style.flexDirection = FlexDirection.Row;
|
||||
nameLabel = hContainer.Create<Label>();
|
||||
|
||||
valueLabel = hContainer.Create<Label>();
|
||||
|
||||
valueLabel.style.paddingLeft = 8;
|
||||
|
||||
nameLabel.text = "Wait";
|
||||
valueLabel.text ="Input";
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
_inputAction?.Dispose();
|
||||
}
|
||||
|
||||
private void NewValue(ChangeEvent<Object> evt)
|
||||
{
|
||||
_inputAction?.Dispose();
|
||||
_inputAction = null;
|
||||
|
||||
if (evt.newValue is not InputActionReference inputActionReference) return;
|
||||
|
||||
_inputAction = inputActionReference.action.Clone();
|
||||
|
||||
_inputAction.Enable();
|
||||
|
||||
_inputAction.RegisterCallback(x =>
|
||||
{
|
||||
if (allowInputLog.value)
|
||||
{
|
||||
Debug.Log(x);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
allowInput.value = BITInputSystem.AllowInput;
|
||||
if (_inputAction is null)
|
||||
{
|
||||
nameLabel.text = "Wait";
|
||||
valueLabel.text = "Input";
|
||||
return;
|
||||
}
|
||||
var nameBuilder = new System.Text.StringBuilder();
|
||||
var valueBuilder = new System.Text.StringBuilder();
|
||||
|
||||
nameBuilder.AppendLine(nameof(InputAction.enabled));
|
||||
valueBuilder.AppendLine(_inputAction.enabled.ToString());
|
||||
|
||||
nameBuilder.AppendLine(nameof(InputAction.IsPressed));
|
||||
valueBuilder.AppendLine(_inputAction.IsPressed().ToString());
|
||||
|
||||
nameBuilder.AppendLine(nameof(InputAction.ReadValue));
|
||||
valueBuilder.AppendLine(_inputAction.ReadValue<float>().ToString());
|
||||
|
||||
nameBuilder.AppendLine(nameof(InputAction.ReadValueAsObject));
|
||||
valueBuilder.AppendLine(_inputAction.ReadValueAsObject()?.ToString());
|
||||
|
||||
nameBuilder.AppendLine(nameof(InputAction.triggered));
|
||||
valueBuilder.AppendLine(_inputAction.triggered.ToString());
|
||||
|
||||
nameBuilder.AppendLine(nameof(InputAction.phase));
|
||||
valueBuilder.AppendLine(_inputAction.phase.ToString());
|
||||
|
||||
nameLabel.text = nameBuilder.ToString();
|
||||
valueLabel.text = valueBuilder.ToString();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
@@ -23,13 +23,26 @@ namespace BITKit
|
||||
public readonly ValidHandle allowInput = new();
|
||||
private readonly ConcurrentDictionary<string,InputAction> actions = new();
|
||||
|
||||
/// <summary>
|
||||
/// 注册所有(started,performed,canceled)回调
|
||||
/// </summary>
|
||||
/// <param name="reference"></param>
|
||||
/// <param name="callback"></param>
|
||||
/// <returns></returns>
|
||||
public InputActionGroup RegisterCallback(InputActionReference reference,
|
||||
Action<InputAction.CallbackContext> callback)
|
||||
{
|
||||
var action = EnsureCreated(reference);
|
||||
action.RegisterCallback(callback);
|
||||
return this;
|
||||
}
|
||||
|
||||
public InputAction EnsureCreated(InputActionReference reference)
|
||||
{
|
||||
if (reference is null)
|
||||
{
|
||||
Debug.LogWarning($"未知的引用");
|
||||
return this;
|
||||
return null;
|
||||
}
|
||||
|
||||
EnsureConfiguration();
|
||||
@@ -39,12 +52,12 @@ namespace BITKit
|
||||
newAction.Rename(reference.name);
|
||||
return newAction;
|
||||
});
|
||||
action.RegisterCallback(callback);
|
||||
|
||||
allowInput.Invoke();
|
||||
|
||||
|
||||
return this;
|
||||
return action;
|
||||
}
|
||||
|
||||
public void Inherit(InputActionGroup other)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
|
Reference in New Issue
Block a user