浏览代码

Added RegiteredInputActions Selector

/feature-new-input-system
Thomas ICHÉ 4 年前
当前提交
46b003c6
共有 14 个文件被更改,包括 262 次插入26 次删除
  1. 3
      Editor/GameplayIngredients-Editor.asmdef
  2. 15
      Resources/Default_InputSystemManager.prefab
  3. 3
      Runtime/GameplayIngredients.asmdef
  4. 21
      Runtime/Input/InputSystemManager.cs
  5. 120
      Editor/PropertyDrawers/RegisteredInputActionsPropertyDrawer.cs
  6. 11
      Editor/PropertyDrawers/RegisteredInputActionsPropertyDrawer.cs.meta
  7. 9
      Runtime/Attributes/RegisteredInputActionsAttribute.cs
  8. 11
      Runtime/Attributes/RegisteredInputActionsAttribute.cs.meta
  9. 21
      Runtime/LevelScripting/Events/OnInputSystemEvent.cs
  10. 11
      Runtime/LevelScripting/Events/OnInputSystemEvent.cs.meta
  11. 37
      Runtime/LevelScripting/Logic/InputSystemLogic.cs
  12. 11
      Runtime/LevelScripting/Logic/InputSystemLogic.cs.meta
  13. 1
      Resources/DefaultControls.inputactions
  14. 14
      Resources/DefaultControls.inputactions.meta

3
Editor/GameplayIngredients-Editor.asmdef


"GameplayIngredients",
"Unity.ugui",
"Unity.Timeline",
"Cinemachine"
"Cinemachine",
"Unity.InputSystem"
],
"includePlatforms": [
"Editor"

15
Resources/Default_InputSystemManager.prefab


%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &8406094827024957934
--- !u!1 &9173868411675018652
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}

m_Component:
- component: {fileID: 4168283503589276939}
- component: {fileID: -4413551057955569625}
- component: {fileID: 1529753585102584546}
- component: {fileID: -2206566852769537897}
m_Layer: 0
m_Name: Default_InputSystemManager
m_TagString: Untagged

m_IsActive: 1
--- !u!4 &4168283503589276939
--- !u!4 &1529753585102584546
m_GameObject: {fileID: 8406094827024957934}
m_GameObject: {fileID: 9173868411675018652}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}

m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &-4413551057955569625
--- !u!114 &-2206566852769537897
m_GameObject: {fileID: 8406094827024957934}
m_GameObject: {fileID: 9173868411675018652}
m_InputActions: []

3
Runtime/GameplayIngredients.asmdef


"NaughtyAttributes.Core",
"Cinemachine",
"Unity.Timeline",
"UnityEngine.UI"
"UnityEngine.UI",
"Unity.InputSystem"
],
"includePlatforms": [],
"excludePlatforms": [],

21
Runtime/Input/InputSystemManager.cs


using System;
#if ENABLE_INPUT_SYSTEM
using UnityEngine.InputSystem;
#endif
namespace GameplayIngredients.Managers
{

[ManagerDefaultPrefab("InputSystemManager")]
public class InputSystemManager : Manager
{
//public InputActionAsset
}
#if ENABLE_INPUT_SYSTEM
public InputActionDefinition[] inputActions { get => m_InputActions; }
[SerializeField]
InputActionDefinition[] m_InputActions;
[Serializable]
public struct InputActionDefinition
{
public InputActionAsset inputActionAsset;
public bool createUIActions;
}
#endif
}
}

120
Editor/PropertyDrawers/RegisteredInputActionsPropertyDrawer.cs


using GameplayIngredients.Managers;
using System.Linq;
using System.Reflection;
using UnityEditor;
using UnityEngine;
namespace GameplayIngredients.Editor
{
[CustomPropertyDrawer(typeof(RegisteredInputActionsAttribute))]
public class RegisteredInputActionsPropertyDrawer : PropertyDrawer
{
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
{
if (GameplayIngredientsSettings.currentSettings.excludedeManagers.Contains(nameof(InputSystemManager)))
return EditorGUIUtility.singleLineHeight * 2.5f;
else
{
return (property.objectReferenceValue == null ? 2:1) * base.GetPropertyHeight(property, label);
}
}
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
if (GameplayIngredientsSettings.currentSettings.excludedeManagers.Contains(typeof(InputSystemManager).Name))
{
EditorGUI.HelpBox(position, "Cannot check for Input Actions : \nInputSystemManager is excluded in your Assets/Resources/GameplayIngredientsSettings.asset", MessageType.Error);
return;
}
InputSystemManager ism = GetDefaultInputSystemManager();
if(ism == null)
{
GUI.color = Color.red;
EditorGUI.LabelField(position,"Error while getting the InputSystemManager prefab", EditorStyles.boldLabel);
GUI.color = Color.white;
return;
}
position.height = EditorGUIUtility.singleLineHeight;
int length = 1 + ism.inputActions.Length;
GUIContent[] displayedOptions = new GUIContent[length];
int[] optionValues = new int[length];
for(int i = 0; i<length; i++)
{
if (i == 0)
displayedOptions[i] = Contents.noPreset;
else
{
var action = ism.inputActions[i - 1].inputActionAsset;
displayedOptions[i] = action? new GUIContent(action.name) : Contents.nullEntry ;
}
optionValues[i] = i - 1;
}
int value = -1;
if(ism.inputActions.Any(o => o.inputActionAsset == property.objectReferenceValue))
{
for(int i = 0; i < ism.inputActions.Length; i++)
{
if (ism.inputActions[i].inputActionAsset != null && ism.inputActions[i].inputActionAsset == property.objectReferenceValue)
{
value = i;
break;
}
}
}
value = EditorGUI.IntPopup(position, Contents.preset, value, displayedOptions, optionValues);
if(GUI.changed)
{
if (value == -1)
property.objectReferenceValue = null;
else
property.objectReferenceValue = ism.inputActions[value].inputActionAsset;
}
if (property.objectReferenceValue == null)
{
position.yMin += EditorGUIUtility.singleLineHeight;
position.height = EditorGUIUtility.singleLineHeight;
EditorGUI.PropertyField(position, property);
}
}
InputSystemManager GetDefaultInputSystemManager()
{
string prefabName = typeof(InputSystemManager).GetCustomAttribute<ManagerDefaultPrefabAttribute>().prefab;
GameObject prefab = Resources.Load<GameObject>(prefabName);
if(prefab != null && prefab.TryGetComponent(out InputSystemManager ism))
{
return ism;
}
prefab = Resources.Load<GameObject>("Default_" + prefabName);
if (prefab != null && prefab.TryGetComponent(out InputSystemManager ism2))
{
return ism2;
}
return null;
}
static class Contents
{
public static GUIContent preset = new GUIContent("Preset", "Preset as defined in your InputSystemManager");
public static GUIContent noPreset = new GUIContent("(No Preset : Specify Action)");
public static GUIContent nullEntry = new GUIContent("Null Entry defined in InputSystemManager");
}
}
}

11
Editor/PropertyDrawers/RegisteredInputActionsPropertyDrawer.cs.meta


fileFormatVersion: 2
guid: c8ac85428885ec74f9a693cbb82c9f92
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

9
Runtime/Attributes/RegisteredInputActionsAttribute.cs


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

11
Runtime/Attributes/RegisteredInputActionsAttribute.cs.meta


fileFormatVersion: 2
guid: 732d939c46813224d85b61ac3a9ccf2b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

21
Runtime/LevelScripting/Events/OnInputSystemEvent.cs


#if ENABLE_INPUT_SYSTEM
using UnityEngine.InputSystem;
#endif
namespace GameplayIngredients.Events
{
#if !ENABLE_INPUT_SYSTEM
[WarnDisabledModule("New Input System")]
#endif
public class OnInputSystemEvent : EventBase
{
#if ENABLE_INPUT_SYSTEM
[RegisteredInputActions]
public InputActionAsset inputAction;
#endif
}
}

11
Runtime/LevelScripting/Events/OnInputSystemEvent.cs.meta


fileFormatVersion: 2
guid: 97ebdd020f382b24d91e934683a756de
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

37
Runtime/LevelScripting/Logic/InputSystemLogic.cs


using NaughtyAttributes;
using UnityEngine;
namespace GameplayIngredients.Logic
{
[AddComponentMenu(ComponentMenu.logicPath + "Input System Logic")]
[Callable("Application", "Logic/ic-generic-logic.png")]
public class InputSystemLogic : LogicBase
{
[ShowIf("checkForLegacyInput")]
public Callable[] OnLegacyInputPresent;
[ShowIf("checkForLegacyInput")]
public Callable[] OnLegacyInputNotPresent;
[ShowIf("checkForNewInput")]
public Callable[] OnNewInputPresent;
[ShowIf("checkForNewInput")]
public Callable[] OnNewInputNotPresent;
public override void Execute(GameObject instigator = null)
{
#if ENABLE_LEGACY_INPUT_MANAGER
Call(OnLegacyInputPresent, instigator);
#else
Call(OnLegacyInputNotPresent, instigator);
#endif
#if ENABLE_INPUT_SYSTEM
Call(OnNewInputPresent, instigator);
#else
Call(OnLegacyInputNotPresent, instigator);
#endif
}
}
}

11
Runtime/LevelScripting/Logic/InputSystemLogic.cs.meta


fileFormatVersion: 2
guid: a579c054a1017f84e9e093fad80ad6cb
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {fileID: 2800000, guid: 6d0a734cdedf48d478f3fcc7612af66f, type: 3}
userData:
assetBundleName:
assetBundleVariant:

1
Resources/DefaultControls.inputactions


{}

14
Resources/DefaultControls.inputactions.meta


fileFormatVersion: 2
guid: c0c261de82a1d5b4b82c2213150ca73e
ScriptedImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 2
userData:
assetBundleName:
assetBundleVariant:
script: {fileID: 11500000, guid: 8404be70184654265930450def6a9037, type: 3}
generateWrapperCode: 0
wrapperCodePath:
wrapperClassName:
wrapperCodeNamespace:
正在加载...
取消
保存