浏览代码

Removed InputActionReference PropertyAttribute / Added OnPlayerInputActionEvent

/feature-new-input-system
Thomas ICHÉ 3 年前
当前提交
7c4ccbfe
共有 6 个文件被更改,包括 94 次插入9 次删除
  1. 2
      Editor/PropertyDrawers/InputActionReferencePropertyDrawer.cs
  2. 2
      Runtime/LevelScripting/Events/OnInputAssetActionEvent.cs
  3. 2
      Runtime/LevelScripting/Events/OnPlayerInputActionEvent.cs.meta
  4. 91
      Runtime/LevelScripting/Events/OnPlayerInputActionEvent.cs
  5. 6
      Runtime/Attributes/InputAssetActionAttribute.cs
  6. 0
      /Runtime/LevelScripting/Events/OnPlayerInputActionEvent.cs.meta

2
Editor/PropertyDrawers/InputActionReferencePropertyDrawer.cs


namespace GameplayIngredients.Editor
{
[CustomPropertyDrawer(typeof(InputAssetActionAttribute))]
[CustomPropertyDrawer(typeof(InputAssetAction))]
public class InputActionReferencePropertyDrawer : PropertyDrawer
{
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)

2
Runtime/LevelScripting/Events/OnInputAssetActionEvent.cs


public class OnInputAssetActionEvent : EventBase
{
#if ENABLE_INPUT_SYSTEM
[SerializeField, InputAssetAction]
[SerializeField]
InputAssetAction inputAction;
[Header("Action")]

2
Runtime/LevelScripting/Events/OnPlayerInputActionEvent.cs.meta


fileFormatVersion: 2
guid: c57940c734ebd694eaf5a668fd2b344a
guid: 537b04352cb86e447aa922e8d6b2561e
MonoImporter:
externalObjects: {}
serializedVersion: 2

91
Runtime/LevelScripting/Events/OnPlayerInputActionEvent.cs


using System;
using UnityEngine;
#if ENABLE_INPUT_SYSTEM
using UnityEngine.InputSystem;
#endif
namespace GameplayIngredients.Events
{
#if ENABLE_INPUT_SYSTEM
[Serializable]
public struct PlayerInputAction
{
public PlayerInput playerInput;
public string path;
public InputAction action
{
get
{
if (playerInput == null)
return null;
else
{
if(m_CachedPath != path || m_CachedInputAction == null)
{
string[] split = path.Split(pathSeparator);
if(split.Length != 2)
{
Debug.LogWarning($"Invalid Path '{path}'", playerInput);
return null;
}
int mapIdx = playerInput.actions.actionMaps.IndexOf(o => o.name == split[0]);
if(mapIdx == -1) // not found
{
Debug.LogWarning($"Could not find action map '{split[0]}' in asset {playerInput.name}", playerInput);
return null;
}
var map = playerInput.actions.actionMaps[mapIdx];
int actionIdx = map.actions.IndexOf(o => o.name == split[1]);
if(actionIdx == -1) // not found
{
Debug.LogWarning($"Could not find action '{split[1]}' of map '{map.name}' in asset {playerInput.name}", playerInput);
return null;
}
m_CachedInputAction = map.actions[actionIdx];
m_CachedPath = path;
}
return m_CachedInputAction;
}
}
}
public const char pathSeparator = '/';
string m_CachedPath;
InputAction m_CachedInputAction;
}
#endif
#if !ENABLE_INPUT_SYSTEM
[WarnDisabledModule("New Input System")]
#endif
[AddComponentMenu(ComponentMenu.eventsPath + "On Input Asset Action Event (New Input System)")]
public class OnPlayerInputActionEvent : EventBase
{
#if ENABLE_INPUT_SYSTEM
[SerializeField]
PlayerInputAction inputAction;
[Header("Action")]
public Callable[] onButtonDown;
private void OnEnable()
{
InputActionManager.Request(inputAction.action, InputAction_performed);
}
private void OnDisable()
{
InputActionManager.Release(inputAction.action, InputAction_performed);
}
private void InputAction_performed(InputAction.CallbackContext obj)
{
Callable.Call(onButtonDown, gameObject);
}
#endif
}
}

6
Runtime/Attributes/InputAssetActionAttribute.cs


using UnityEngine;
namespace GameplayIngredients
{
public class InputAssetActionAttribute : PropertyAttribute { }
}

/Runtime/Attributes/InputAssetActionAttribute.cs.meta → /Runtime/LevelScripting/Events/OnPlayerInputActionEvent.cs.meta

正在加载...
取消
保存