Thomas ICHÉ
4 年前
当前提交
56bf0966
共有 7 个文件被更改,包括 178 次插入 和 1 次删除
-
19Runtime/LevelScripting/Events/OnInputActionEvent.cs
-
73Editor/PropertyDrawers/PlayerInputActionPropertyDrawer.cs
-
11Editor/PropertyDrawers/PlayerInputActionPropertyDrawer.cs.meta
-
14Runtime/Attributes/PlayerInputActionAttribute.cs
-
11Runtime/Attributes/PlayerInputActionAttribute.cs.meta
-
40Runtime/LevelScripting/Events/OnPlayerInputActionEvent.cs
-
11Runtime/LevelScripting/Events/OnPlayerInputActionEvent.cs.meta
|
|||
#if ENABLE_INPUT_SYSTEM
|
|||
using UnityEngine; |
|||
using UnityEditor; |
|||
using UnityEngine.InputSystem; |
|||
using System; |
|||
using System.Reflection; |
|||
|
|||
namespace GameplayIngredients.Editor |
|||
{ |
|||
[CustomPropertyDrawer(typeof(PlayerInputActionAttribute))] |
|||
public class PlayerInputActionPropertyDrawer : PropertyDrawer |
|||
{ |
|||
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) |
|||
{ |
|||
PlayerInputActionAttribute pia = attribute as PlayerInputActionAttribute; |
|||
|
|||
var obj = property.serializedObject.targetObject; |
|||
|
|||
var fi = obj.GetType().GetField(pia.name, BindingFlags.NonPublic |
|||
| BindingFlags.Public |
|||
| BindingFlags.Instance); |
|||
|
|||
if(fi != null) |
|||
{ |
|||
var playerInput = fi.GetValue(obj) as PlayerInput; |
|||
|
|||
if(playerInput != null) |
|||
{ |
|||
if (playerInput.actions != null) |
|||
{ |
|||
var field = obj.GetType().GetField(property.name, BindingFlags.NonPublic |
|||
| BindingFlags.Public |
|||
| BindingFlags.Instance); |
|||
var fieldValue = field.GetValue(property.serializedObject.targetObject); |
|||
|
|||
var actionMap = playerInput.actions.FindActionMap(playerInput.defaultActionMap); |
|||
int selected = -1; |
|||
string[] names = new string[actionMap.actions.Count]; |
|||
for(int i = 0; i < actionMap.actions.Count; i ++) |
|||
{ |
|||
if (fieldValue == actionMap.actions[i]) |
|||
selected = i; |
|||
|
|||
names[i] = actionMap.actions[i].name; |
|||
} |
|||
selected = EditorGUI.Popup(position, ObjectNames.NicifyVariableName(property.name), selected, names); |
|||
if(GUI.changed) |
|||
{ |
|||
Undo.RecordObject(property.serializedObject.targetObject, "Set Action Map"); |
|||
property.serializedObject.Update(); |
|||
field.SetValue(property.serializedObject.targetObject, actionMap.actions[selected]); |
|||
EditorUtility.SetDirty(property.serializedObject.targetObject); |
|||
property.serializedObject.ApplyModifiedProperties(); |
|||
|
|||
|
|||
} |
|||
} |
|||
else |
|||
EditorGUI.HelpBox(position, $"Target Player Input had no actions configured", MessageType.Warning); |
|||
|
|||
|
|||
|
|||
} |
|||
else |
|||
EditorGUI.HelpBox(position, $"Property {pia.name} is null or not of PlayerInput type", MessageType.Error); |
|||
|
|||
} |
|||
else |
|||
EditorGUI.HelpBox(position, $"Could not find field {pia.name}", MessageType.Error); |
|||
} |
|||
} |
|||
} |
|||
#endif
|
|
|||
fileFormatVersion: 2 |
|||
guid: 857cf4d1897170945a9897f28a323452 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using UnityEngine; |
|||
|
|||
namespace GameplayIngredients |
|||
{ |
|||
public class PlayerInputActionAttribute : PropertyAttribute |
|||
{ |
|||
public readonly string name; |
|||
|
|||
public PlayerInputActionAttribute(string propertyName) |
|||
{ |
|||
this.name = propertyName; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: c57940c734ebd694eaf5a668fd2b344a |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using UnityEngine; |
|||
#if ENABLE_INPUT_SYSTEM
|
|||
using UnityEngine.InputSystem; |
|||
#endif
|
|||
|
|||
namespace GameplayIngredients.Events |
|||
{ |
|||
#if !ENABLE_INPUT_SYSTEM
|
|||
[WarnDisabledModule("New Input System")] |
|||
#endif
|
|||
[AddComponentMenu(ComponentMenu.eventsPath + "On Player Input Action Event (New Input System)")] |
|||
public class OnPlayerInputActionEvent : EventBase |
|||
{ |
|||
#if ENABLE_INPUT_SYSTEM
|
|||
[SerializeField] |
|||
public PlayerInput playerInput; |
|||
|
|||
[SerializeField, PlayerInputAction("playerInput")] |
|||
InputAction inputAction; |
|||
|
|||
public Callable[] onButtonDown; |
|||
|
|||
private void OnEnable() |
|||
{ |
|||
inputAction.performed += InputAction_performed; |
|||
} |
|||
private void OnDisable() |
|||
{ |
|||
inputAction.performed -= InputAction_performed; |
|||
} |
|||
|
|||
private void InputAction_performed(InputAction.CallbackContext obj) |
|||
{ |
|||
Callable.Call(onButtonDown, gameObject); |
|||
} |
|||
#endif
|
|||
} |
|||
} |
|||
|
|||
|
|
|||
fileFormatVersion: 2 |
|||
guid: 8e4443e2a5662e440999cb1f3de312a8 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
撰写
预览
正在加载...
取消
保存
Reference in new issue