Gameplay Ingredients是一组用于 Unity 游戏的运行时和编辑器工具:一组脚本的集合,可在制作游戏和原型时简化简单的任务。
您最多选择25个主题 主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

64 行
2.1 KiB

#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