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

76 行
2.4 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(InputAssetAction))]
public class InputAssetActionPropertyDrawer: 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("asset");
var path = property.FindPropertyRelative("path");
position.height = EditorGUIUtility.singleLineHeight;
EditorGUI.PropertyField(position, asset, new GUIContent("Input Action Asset"));
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();
}
}
public static class Extensions
{
public static int IndexOf(this string[] array, string value)
{
for (int i = 0; i < array.Length; i++)
{
if (array[i] == value)
return i;
}
return -1;
}
}
}
#endif