浏览代码

Action Mapping from Input System Manager

/feature-new-input-system
Thomas ICHÉ 4 年前
当前提交
3b17bc62
共有 10 个文件被更改,包括 124 次插入37 次删除
  1. 73
      Editor/PropertyDrawers/RegisteredInputActionsPropertyDrawer.cs
  2. 40
      Runtime/Input/InputSystemManager.cs
  3. 2
      Runtime/LevelScripting/Events/OnButtonDownEvent.cs
  4. 2
      Runtime/LevelScripting/Events/OnKeyDownEvent.cs
  5. 3
      Runtime/LevelScripting/Events/OnDirectInputEvent.cs
  6. 20
      Runtime/LevelScripting/Events/OnInputEvent.cs
  7. 21
      Runtime/LevelScripting/Events/OnInputSystemEvent.cs
  8. 0
      /Runtime/LevelScripting/Events/OnDirectInputEvent.cs.meta
  9. 0
      /Runtime/LevelScripting/Events/OnInputEvent.cs.meta
  10. 0
      /Runtime/LevelScripting/Events/OnDirectInputEvent.cs

73
Editor/PropertyDrawers/RegisteredInputActionsPropertyDrawer.cs


using GameplayIngredients.Managers;
using System.Collections.Generic;
using UnityEngine.InputSystem;
[CustomPropertyDrawer(typeof(RegisteredInputActionsAttribute))]
[CustomPropertyDrawer(typeof(InputSystemManager.RegisteredInputAction))]
public class RegisteredInputActionsPropertyDrawer : PropertyDrawer
{
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)

else
{
return (property.objectReferenceValue == null ? 2:1) * base.GetPropertyHeight(property, label);
return 2 * base.GetPropertyHeight(property, label);
#if ENABLE_INPUT_SYSTEM
InputSystemManager ism = GetDefaultInputSystemManager();
if(ism == null)
{

displayedOptions[i] = action? new GUIContent(action.name) : Contents.nullEntry ;
}
if(ism.inputActions.Any(o => o.inputActionAsset == property.objectReferenceValue))
if(ism.inputActions.Any(o => o.inputActionAsset == GetInputAsset(property) ))
if (ism.inputActions[i].inputActionAsset != null && ism.inputActions[i].inputActionAsset == property.objectReferenceValue)
if (ism.inputActions[i].inputActionAsset != null && ism.inputActions[i].inputActionAsset == property.FindPropertyRelative("asset").objectReferenceValue)
{
value = i;
break;

if(GUI.changed)
{
if (value == -1)
property.objectReferenceValue = null;
property.FindPropertyRelative("asset").objectReferenceValue = null;
property.objectReferenceValue = ism.inputActions[value].inputActionAsset;
property.FindPropertyRelative("asset").objectReferenceValue = ism.inputActions[value].inputActionAsset;
if (property.objectReferenceValue == null)
position.yMin += EditorGUIUtility.singleLineHeight;
position.height = EditorGUIUtility.singleLineHeight;
if (GetInputAsset(property) != null)
position.yMin += EditorGUIUtility.singleLineHeight;
position.height = EditorGUIUtility.singleLineHeight;
InputActionAsset ia = property.FindPropertyRelative("asset").objectReferenceValue as InputActionAsset;
List<string> items = new List<string>();
foreach(var actionMap in ia.actionMaps)
{
foreach(var action in actionMap.actions)
{
items.Add($"{actionMap.name}/{action.name}");
}
}
string val = property.FindPropertyRelative("actionPath").stringValue;
int selected = -1;
GUIContent[] names = new GUIContent[items.Count];
int[] indices = new int[items.Count];
for(int i = 0; i < items.Count; i++)
{
names[i] = new GUIContent(items[i]);
indices[i] = i;
EditorGUI.PropertyField(position, property);
if (val == items[i])
selected = i;
}
selected = EditorGUI.IntPopup(position, new GUIContent(" - Action"), selected, names, indices);
if(GUI.changed)
{
property.FindPropertyRelative("actionPath").stringValue = items[selected];
}
#else
EditorGUI.HelpBox(position, "New Input System package is not installed", MessageType.Warning);
#endif
}
static InputAction GetAction(SerializedProperty property)
{
var inputAsset = GetInputAsset(property);
string path = property.FindPropertyRelative("actionPath").stringValue;
return InputSystemManager.RegisteredInputAction.GetAtPath(inputAsset, path);
}
static InputActionAsset GetInputAsset(SerializedProperty property)
{
return property.FindPropertyRelative("asset").objectReferenceValue as InputActionAsset;
}
InputSystemManager GetDefaultInputSystemManager()

static class Contents
{
public static GUIContent preset = new GUIContent("Preset", "Preset as defined in your InputSystemManager");
public static GUIContent noPreset = new GUIContent("(No Preset : Specify Action)");
public static GUIContent noPreset = new GUIContent("(No Preset)");
public static GUIContent nullEntry = new GUIContent("Null Entry defined in InputSystemManager");
}
}

40
Runtime/Input/InputSystemManager.cs


throw new System.NotImplementedException();
}
}
[System.Serializable]
public struct RegisteredInputAction
{
public InputActionAsset asset;
public string actionPath;
public InputAction action => GetAtPath(this.asset, this.actionPath);
public static InputAction GetAtPath(InputActionAsset asset, string path)
{
if (asset == null)
return null;
if (string.IsNullOrEmpty(path))
return null;
string[] split = path.Split('/');
foreach(var map in asset.actionMaps)
{
if (!map.name.Equals(split[0]))
continue;
foreach(var action in map.actions)
{
if (action.name.Equals(split[1]))
return action;
}
}
return null;
}
}
public enum Device
{
Gamepad,

LeftThumbStick, RightThumbStick,
Start, Select,
}
}

2
Runtime/LevelScripting/Events/OnButtonDownEvent.cs


#if !ENABLE_LEGACY_INPUT_MANAGER
[WarnDisabledModule("Legacy Input Manager","Player Settings")]
#endif
[AddComponentMenu(ComponentMenu.eventsPath + "On Button Down Event (Legacy Input System)")]
[AddComponentMenu(ComponentMenu.eventsPath + "On Button Down Event (Legacy Input)")]
public class OnButtonDownEvent : EventBase
{
public string Button = "Fire1";

2
Runtime/LevelScripting/Events/OnKeyDownEvent.cs


#if !ENABLE_LEGACY_INPUT_MANAGER
[WarnDisabledModule("Legacy Input Manager","Player Settings")]
#endif
[AddComponentMenu(ComponentMenu.eventsPath + "On Key Down Event (Legacy Input System)")]
[AddComponentMenu(ComponentMenu.eventsPath + "On Key Down Event (Legacy Input)")]
public class OnKeyDownEvent : EventBase
{
public KeyCode Key = KeyCode.F5;

3
Runtime/LevelScripting/Events/OnDirectInputEvent.cs


#if !ENABLE_INPUT_SYSTEM
[WarnDisabledModule("New Input System")]
#endif
public class OnInputSystemDirectInputEvent : EventBase
[AddComponentMenu(ComponentMenu.eventsPath + "On Direct Input Event (New Input System)")]
public class OnDirectInputEvent : EventBase
{
[SerializeField]
Device device = Device.Keyboard;

20
Runtime/LevelScripting/Events/OnInputEvent.cs


using UnityEngine;
#if ENABLE_INPUT_SYSTEM
using GameplayIngredients.Managers;
#endif
namespace GameplayIngredients.Events
{
#if !ENABLE_INPUT_SYSTEM
[WarnDisabledModule("New Input System")]
#endif
[AddComponentMenu(ComponentMenu.eventsPath + "On Input Event (New Input System)")]
public class OnInputEvent : EventBase
{
#if ENABLE_INPUT_SYSTEM
public InputSystemManager.RegisteredInputAction inputAction;
#endif
}
}

21
Runtime/LevelScripting/Events/OnInputSystemEvent.cs


#if ENABLE_INPUT_SYSTEM
using UnityEngine.InputSystem;
#endif
namespace GameplayIngredients.Events
{
#if !ENABLE_INPUT_SYSTEM
[WarnDisabledModule("New Input System")]
#endif
public class OnInputSystemEvent : EventBase
{
#if ENABLE_INPUT_SYSTEM
[RegisteredInputActions]
public InputActionAsset inputAction;
#endif
}
}

/Runtime/LevelScripting/Events/OnInputSystemDirectInputEvent.cs.meta → /Runtime/LevelScripting/Events/OnDirectInputEvent.cs.meta

/Runtime/LevelScripting/Events/OnInputSystemEvent.cs.meta → /Runtime/LevelScripting/Events/OnInputEvent.cs.meta

/Runtime/LevelScripting/Events/OnInputSystemDirectInputEvent.cs → /Runtime/LevelScripting/Events/OnDirectInputEvent.cs

正在加载...
取消
保存