using System; using UnityEngine; using UnityEditor; using jeanf.EventSystem; namespace jeanf.vrplayer { public class PlayerInputEventManager : MonoBehaviour { #region event scriptable objects private BoolEventChannelSO takeObject; private BoolEventChannelSO cursorStateChannel_ManualOverrideSO; private IntBoolEventChannelSO takeObjectInSpecificLocation; private VoidEventChannelSO grab_LeftHand_SetAttachTransformSO; private VoidEventChannelSO grab_RightHand_SetAttachTransformSO; private IntEventChannelSO grabCountEventChannelSO; private BoolEventChannelSO grabEvent_LeftHandStateSO; private BoolEventChannelSO grabEvent_RightHandStateSO; private VoidEventChannelSO noHandGrabbingSO; private VoidEventChannelSO actionDeniedSO; private IntEventChannelSO floorChangeSO; private IntEventChannelSO floorInaccessibleSO; private BoolEventChannelSO gloveStateEventChannelSO; private BoolEventChannelSO HMDStateEventChannelSO; private VoidEventChannelSO mouseLookCameraResentEventChannelSO; private BoolEventChannelSO mouseLookStateEventChannelSO; private BoolEventChannelSO primaryItemStateEventChannelSO; private BoolEventChannelSO primaryItemStateEventVR_ChannelSO; private XRBaseInteractorEventChannelSO xrDirectInteractorEvent_LeftChannelSO; private XRBaseInteractorEventChannelSO xrDirectInteractorEvent_RightChannelSO; #endregion #if UNITY_EDITOR // ReSharper disable Unity.PerformanceAnalysis public void CreateEventChannels() { const string pathGrabFolder = "Player/Channels/Grab"; const string pathChannelsFolder = "Player/Channels"; #region Events to go in Assets/Resources/Player/Channels folder var path = pathChannelsFolder; takeObject = CreateSO( nameof(takeObject),typeof(BoolEventChannelSO), path) as BoolEventChannelSO; cursorStateChannel_ManualOverrideSO = CreateSO( nameof(cursorStateChannel_ManualOverrideSO), typeof(BoolEventChannelSO), path) as BoolEventChannelSO; actionDeniedSO = CreateSO( nameof(actionDeniedSO),typeof(VoidEventChannelSO), path) as VoidEventChannelSO; takeObjectInSpecificLocation = CreateSO( nameof(takeObjectInSpecificLocation), typeof(IntBoolEventChannelSO), path) as IntBoolEventChannelSO; actionDeniedSO = CreateSO( nameof(actionDeniedSO), typeof(VoidEventChannelSO),path) as VoidEventChannelSO; cursorStateChannel_ManualOverrideSO = CreateSO( nameof(cursorStateChannel_ManualOverrideSO), typeof(BoolEventChannelSO),path) as BoolEventChannelSO; floorChangeSO = CreateSO( nameof(floorChangeSO), typeof(IntEventChannelSO),path) as IntEventChannelSO; floorInaccessibleSO = CreateSO( nameof(floorInaccessibleSO), typeof(IntEventChannelSO),path) as IntEventChannelSO; gloveStateEventChannelSO = CreateSO( nameof(gloveStateEventChannelSO),typeof(BoolEventChannelSO),path) as BoolEventChannelSO; HMDStateEventChannelSO = CreateSO( nameof(HMDStateEventChannelSO), typeof(BoolEventChannelSO),path) as BoolEventChannelSO; mouseLookCameraResentEventChannelSO = CreateSO( nameof(mouseLookCameraResentEventChannelSO), typeof(VoidEventChannelSO),path) as VoidEventChannelSO; mouseLookStateEventChannelSO = CreateSO( nameof(mouseLookStateEventChannelSO), typeof(BoolEventChannelSO),path) as BoolEventChannelSO; primaryItemStateEventChannelSO = CreateSO( nameof(primaryItemStateEventChannelSO), typeof(BoolEventChannelSO), path) as BoolEventChannelSO; primaryItemStateEventVR_ChannelSO = CreateSO( nameof(primaryItemStateEventVR_ChannelSO),typeof(BoolEventChannelSO), path) as BoolEventChannelSO; xrDirectInteractorEvent_LeftChannelSO = CreateSO( nameof(xrDirectInteractorEvent_LeftChannelSO), typeof(XRBaseInteractorEventChannelSO), path) as XRBaseInteractorEventChannelSO; xrDirectInteractorEvent_RightChannelSO = CreateSO(nameof(xrDirectInteractorEvent_RightChannelSO), typeof(XRBaseInteractorEventChannelSO), path) as XRBaseInteractorEventChannelSO; #endregion #region Events to go in Assets/Resources/Player/Channels/Grab folder path = pathGrabFolder; grab_LeftHand_SetAttachTransformSO = CreateSO( nameof(grab_LeftHand_SetAttachTransformSO), typeof(VoidEventChannelSO), path) as VoidEventChannelSO; grab_RightHand_SetAttachTransformSO = CreateSO( nameof(grab_RightHand_SetAttachTransformSO), typeof(VoidEventChannelSO), path) as VoidEventChannelSO; grabCountEventChannelSO = CreateSO( nameof(grabCountEventChannelSO), typeof(IntEventChannelSO), path) as IntEventChannelSO; grabEvent_LeftHandStateSO = CreateSO( nameof(grabEvent_LeftHandStateSO), typeof(BoolEventChannelSO), path) as BoolEventChannelSO; grabEvent_RightHandStateSO = CreateSO( nameof(grabEvent_RightHandStateSO), typeof(BoolEventChannelSO), path) as BoolEventChannelSO; noHandGrabbingSO = CreateSO( nameof(noHandGrabbingSO), typeof(VoidEventChannelSO), path) as VoidEventChannelSO; #endregion } private ScriptableObject CreateSO(string name, Type type, string folderPath) { ScriptableObject so; Debug.Log($"Attempting to create so {name}"); var path = $"Assets/Resources/{folderPath}/{name}.asset"; // first check if it exists var existingSO = Resources.Load(path); if (existingSO == null) { Debug.Log($"Did not found channel {name}, creating in folder {folderPath}"); so = ScriptableObject.CreateInstance(type); AssetDatabase.CreateAsset(so, path); } else { so = existingSO; Debug.Log($"The SO: {name} exists."); } return so; } #endif } }