Thomas ICHÉ
4 年前
当前提交
46b003c6
共有 14 个文件被更改,包括 262 次插入 和 26 次删除
-
3Editor/GameplayIngredients-Editor.asmdef
-
15Resources/Default_InputSystemManager.prefab
-
3Runtime/GameplayIngredients.asmdef
-
21Runtime/Input/InputSystemManager.cs
-
120Editor/PropertyDrawers/RegisteredInputActionsPropertyDrawer.cs
-
11Editor/PropertyDrawers/RegisteredInputActionsPropertyDrawer.cs.meta
-
9Runtime/Attributes/RegisteredInputActionsAttribute.cs
-
11Runtime/Attributes/RegisteredInputActionsAttribute.cs.meta
-
21Runtime/LevelScripting/Events/OnInputSystemEvent.cs
-
11Runtime/LevelScripting/Events/OnInputSystemEvent.cs.meta
-
37Runtime/LevelScripting/Logic/InputSystemLogic.cs
-
11Runtime/LevelScripting/Logic/InputSystemLogic.cs.meta
-
1Resources/DefaultControls.inputactions
-
14Resources/DefaultControls.inputactions.meta
|
|||
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"); |
|||
} |
|||
} |
|||
} |
|||
|
|||
|
|||
|
|||
|
|
|||
fileFormatVersion: 2 |
|||
guid: c8ac85428885ec74f9a693cbb82c9f92 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using UnityEngine; |
|||
|
|||
namespace GameplayIngredients |
|||
{ |
|||
public class RegisteredInputActionsAttribute : PropertyAttribute { } |
|||
} |
|||
|
|||
|
|||
|
|
|||
fileFormatVersion: 2 |
|||
guid: 732d939c46813224d85b61ac3a9ccf2b |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
#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
|
|||
|
|||
|
|||
} |
|||
} |
|||
|
|||
|
|
|||
fileFormatVersion: 2 |
|||
guid: 97ebdd020f382b24d91e934683a756de |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
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
|
|||
} |
|||
} |
|||
} |
|||
|
|
|||
fileFormatVersion: 2 |
|||
guid: a579c054a1017f84e9e093fad80ad6cb |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {fileID: 2800000, guid: 6d0a734cdedf48d478f3fcc7612af66f, type: 3} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
{} |
|
|||
fileFormatVersion: 2 |
|||
guid: c0c261de82a1d5b4b82c2213150ca73e |
|||
ScriptedImporter: |
|||
internalIDToNameTable: [] |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|||
script: {fileID: 11500000, guid: 8404be70184654265930450def6a9037, type: 3} |
|||
generateWrapperCode: 0 |
|||
wrapperCodePath: |
|||
wrapperClassName: |
|||
wrapperCodeNamespace: |
撰写
预览
正在加载...
取消
保存
Reference in new issue