浏览代码

Property Drawer for InputPlayerAction

/feature-new-input-system
Thomas ICHÉ 3 年前
当前提交
ee89c7b9
共有 4 个文件被更改,包括 81 次插入3 次删除
  1. 7
      Editor/PropertyDrawers/InputAssetActionPropertyDrawer.cs
  2. 2
      Runtime/LevelScripting/Events/OnPlayerInputActionEvent.cs
  3. 64
      Editor/PropertyDrawers/InputPlayerActionPropertyDrawer.cs
  4. 11
      Editor/PropertyDrawers/InputPlayerActionPropertyDrawer.cs.meta

7
Editor/PropertyDrawers/InputAssetActionPropertyDrawer.cs


EditorGUI.PropertyField(position, asset, new GUIContent("Input Action Asset"));
EditorGUI.indentLevel++;
position.y += EditorGUIUtility.singleLineHeight + 2;
//EditorGUI.PropertyField(position, path);
path.stringValue = paths[selected];
if (selected >= 0)
path.stringValue = paths[selected];
else
path.stringValue = string.Empty;
}
EditorGUI.indentLevel--;
}

2
Runtime/LevelScripting/Events/OnPlayerInputActionEvent.cs


#if !ENABLE_INPUT_SYSTEM
[WarnDisabledModule("New Input System")]
#endif
[AddComponentMenu(ComponentMenu.eventsPath + "On Input Asset Action Event (New Input System)")]
[AddComponentMenu(ComponentMenu.eventsPath + "On Player Input Action Event (New Input System)")]
public class OnPlayerInputActionEvent : EventBase
{
#if ENABLE_INPUT_SYSTEM

64
Editor/PropertyDrawers/InputPlayerActionPropertyDrawer.cs


#if ENABLE_INPUT_SYSTEM
using UnityEngine;
using UnityEditor;
using UnityEngine.InputSystem;
using System.Linq;
using System.Collections.Generic;
using GameplayIngredients.Events;
namespace GameplayIngredients.Editor
{
[CustomPropertyDrawer(typeof(PlayerInputAction))]
public class InputPlayerActionPropertyDrawer: PropertyDrawer
{
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
{
return EditorGUIUtility.singleLineHeight * 2 + 8;
}
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
var asset = property.FindPropertyRelative("playerInput");
var path = property.FindPropertyRelative("path");
position.height = EditorGUIUtility.singleLineHeight;
EditorGUI.PropertyField(position, asset, new GUIContent("Player Input"));
EditorGUI.indentLevel++;
position.y += EditorGUIUtility.singleLineHeight + 2;
var paths = GetPaths(asset.objectReferenceValue as InputActionAsset);
int selected = paths.IndexOf(path.stringValue);
selected = EditorGUI.Popup(position, "Action", selected, paths);
if(GUI.changed)
{
if (selected >= 0)
path.stringValue = paths[selected];
else
path.stringValue = string.Empty;
}
EditorGUI.indentLevel--;
}
string[] GetPaths(InputActionAsset asset)
{
if (asset == null)
return new string[0];
List<string> paths = new List<string>();
foreach(var map in asset.actionMaps)
{
if (map == null) continue;
foreach(var action in map.actions)
{
if (action == null) continue;
paths.Add($"{map.name}{InputAssetAction.pathSeparator}{action.name}");
}
}
return paths.ToArray();
}
}
}
#endif

11
Editor/PropertyDrawers/InputPlayerActionPropertyDrawer.cs.meta


fileFormatVersion: 2
guid: d4b5368aae1726047bd77d96d0112350
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存