diff --git a/CVRLua/DestructionDetector.cs b/CVRLua/DestructionDetector.cs deleted file mode 100644 index 2991608..0000000 --- a/CVRLua/DestructionDetector.cs +++ /dev/null @@ -1,14 +0,0 @@ -using UnityEngine; - -namespace CVRLua -{ - class DestructionDetector : MonoBehaviour - { - public System.Action Detection; - - void OnDestroy() - { - Detection?.Invoke(this.gameObject); - } - } -} diff --git a/CVRLua/Lua/LuaDefs/PlayerDefs.cs b/CVRLua/Lua/LuaDefs/PlayerDefs.cs index 6bd002e..bbc77c8 100644 --- a/CVRLua/Lua/LuaDefs/PlayerDefs.cs +++ b/CVRLua/Lua/LuaDefs/PlayerDefs.cs @@ -33,8 +33,8 @@ internal static void Init() ms_instanceProperties.Add(("avatarScale", (GetAvatarScale, null))); ms_instanceProperties.Add(("playerHeight", (GetPlayerHeight, null))); ms_instanceProperties.Add(("playerScale", (GetPlayerScale, null))); - ms_instanceProperties.Add(("cameraPosition", (GetCameraPosition, null))); - ms_instanceProperties.Add(("cameraRotation", (GetCameraRotation, null))); + ms_instanceProperties.Add(("viewPosition", (GetViewPosition, null))); + ms_instanceProperties.Add(("viewRotation", (GetViewRotation, null))); ms_instanceProperties.Add(("inVR", (GetInVR, null))); ms_instanceProperties.Add(("inFBT", (GetFBT, null))); ms_instanceProperties.Add(("hasAvatar", (GetAvatar, null))); @@ -59,6 +59,7 @@ internal static void Init() ms_instanceProperties.Add(("lookVector", (GetLookVector, null))); ms_instanceProperties.Add(("individualFingerTracking", (GetIndividualFingerTracking, null))); ms_instanceProperties.Add(("fingerCurls", (GetFingerCurls, null))); + ms_instanceProperties.Add(("fingerSpreads", (GetFingerSpreads, null))); ms_instanceMethods.Add((nameof(Teleport), Teleport)); ms_instanceMethods.Add((nameof(SetImmobilized), SetImmobilized)); @@ -232,8 +233,8 @@ static int GetName(IntPtr p_state) var l_argReader = new LuaArgReader(p_state); Players.Player l_player = null; l_argReader.ReadObject(ref l_player); - if(!l_argReader.HasErrors() && l_player.GetName(out string l_name)) - l_argReader.PushString(l_name); + if(!l_argReader.HasErrors()) + l_argReader.PushString(l_player.GetName()); else l_argReader.PushBoolean(false); @@ -245,8 +246,8 @@ static int GetUuid(IntPtr p_state) var l_argReader = new LuaArgReader(p_state); Players.Player l_player = null; l_argReader.ReadObject(ref l_player); - if(!l_argReader.HasErrors() && l_player.GetId(out string l_id)) - l_argReader.PushString(l_id); + if(!l_argReader.HasErrors()) + l_argReader.PushString(l_player.GetId()); else l_argReader.PushBoolean(false); @@ -259,8 +260,8 @@ static int GetPosition(IntPtr p_state) var l_argReader = new LuaArgReader(p_state); Players.Player l_player = null; l_argReader.ReadObject(ref l_player); - if(!l_argReader.HasErrors() && l_player.GetPosition(out UnityEngine.Vector3 l_pos)) - l_argReader.PushObject(new Wrappers.Vector3(l_pos)); + if(!l_argReader.HasErrors()) + l_argReader.PushObject(new Wrappers.Vector3(l_player.GetPosition())); else l_argReader.PushBoolean(false); @@ -273,8 +274,8 @@ static int GetRotation(IntPtr p_state) var l_argReader = new LuaArgReader(p_state); Players.Player l_player = null; l_argReader.ReadObject(ref l_player); - if(!l_argReader.HasErrors() && l_player.GetRotation(out UnityEngine.Quaternion l_rot)) - l_argReader.PushObject(new Wrappers.Quaternion(l_rot)); + if(!l_argReader.HasErrors()) + l_argReader.PushObject(new Wrappers.Quaternion(l_player.GetRotation())); else l_argReader.PushBoolean(false); @@ -287,8 +288,8 @@ static int GetAvatarHeight(IntPtr p_state) var l_argReader = new LuaArgReader(p_state); Players.Player l_player = null; l_argReader.ReadObject(ref l_player); - if(!l_argReader.HasErrors() && l_player.GetAvatarHeight(out float l_height)) - l_argReader.PushNumber(l_height); + if(!l_argReader.HasErrors()) + l_argReader.PushNumber(l_player.GetAvatarHeight()); else l_argReader.PushBoolean(false); @@ -301,8 +302,8 @@ static int GetAvatarScale(IntPtr p_state) var l_argReader = new LuaArgReader(p_state); Players.Player l_player = null; l_argReader.ReadObject(ref l_player); - if(!l_argReader.HasErrors() && l_player.GetAvatarScale(out float l_scale)) - l_argReader.PushNumber(l_scale); + if(!l_argReader.HasErrors()) + l_argReader.PushNumber(l_player.GetAvatarScale()); else l_argReader.PushBoolean(false); @@ -315,8 +316,8 @@ static int GetPlayerHeight(IntPtr p_state) var l_argReader = new LuaArgReader(p_state); Players.Player l_player = null; l_argReader.ReadObject(ref l_player); - if(!l_argReader.HasErrors() && l_player.GetPlayerHeight(out float l_height)) - l_argReader.PushNumber(l_height); + if(!l_argReader.HasErrors()) + l_argReader.PushNumber(l_player.GetPlayerHeight()); else l_argReader.PushBoolean(false); @@ -329,8 +330,8 @@ static int GetPlayerScale(IntPtr p_state) var l_argReader = new LuaArgReader(p_state); Players.Player l_player = null; l_argReader.ReadObject(ref l_player); - if(!l_argReader.HasErrors() && l_player.GetPlayerScale(out float l_scale)) - l_argReader.PushNumber(l_scale); + if(!l_argReader.HasErrors()) + l_argReader.PushNumber(l_player.GetPlayerScale()); else l_argReader.PushBoolean(false); @@ -338,13 +339,13 @@ static int GetPlayerScale(IntPtr p_state) return 1; } - static int GetCameraPosition(IntPtr p_state) + static int GetViewPosition(IntPtr p_state) { var l_argReader = new LuaArgReader(p_state); Players.Player l_player = null; l_argReader.ReadObject(ref l_player); - if(!l_argReader.HasErrors() && l_player.GetCameraPosition(out var l_pos)) - l_argReader.PushObject(new Wrappers.Vector3(l_pos)); + if(!l_argReader.HasErrors()) + l_argReader.PushObject(new Wrappers.Vector3(l_player.GetViewPosition())); else l_argReader.PushBoolean(false); @@ -352,13 +353,13 @@ static int GetCameraPosition(IntPtr p_state) return 1; } - static int GetCameraRotation(IntPtr p_state) + static int GetViewRotation(IntPtr p_state) { var l_argReader = new LuaArgReader(p_state); Players.Player l_player = null; l_argReader.ReadObject(ref l_player); - if(!l_argReader.HasErrors() && l_player.GetCameraRotation(out var l_rot)) - l_argReader.PushObject(new Wrappers.Quaternion(l_rot)); + if(!l_argReader.HasErrors()) + l_argReader.PushObject(new Wrappers.Quaternion(l_player.GetViewRotation())); else l_argReader.PushBoolean(false); @@ -539,8 +540,8 @@ static int GetLeftHandPosition(IntPtr p_state) var l_argReader = new LuaArgReader(p_state); Players.Player l_player = null; l_argReader.ReadObject(ref l_player); - if(!l_argReader.HasErrors() && l_player.GetLeftHandPosition(out var l_pos)) - l_argReader.PushObject(new Wrappers.Vector3(l_pos)); + if(!l_argReader.HasErrors()) + l_argReader.PushObject(new Wrappers.Vector3(l_player.GetLeftHandPosition())); else l_argReader.PushBoolean(false); @@ -553,8 +554,8 @@ static int GetLeftHandRotation(IntPtr p_state) var l_argReader = new LuaArgReader(p_state); Players.Player l_player = null; l_argReader.ReadObject(ref l_player); - if(!l_argReader.HasErrors() && l_player.GetLeftHandRotation(out var l_rot)) - l_argReader.PushObject(new Wrappers.Quaternion(l_rot)); + if(!l_argReader.HasErrors()) + l_argReader.PushObject(new Wrappers.Quaternion(l_player.GetLeftHandRotation())); else l_argReader.PushBoolean(false); @@ -567,8 +568,8 @@ static int GetRightHandPosition(IntPtr p_state) var l_argReader = new LuaArgReader(p_state); Players.Player l_player = null; l_argReader.ReadObject(ref l_player); - if(!l_argReader.HasErrors() && l_player.GetRightHandPosition(out var l_pos)) - l_argReader.PushObject(new Wrappers.Vector3(l_pos)); + if(!l_argReader.HasErrors()) + l_argReader.PushObject(new Wrappers.Vector3(l_player.GetRightHandPosition())); else l_argReader.PushBoolean(false); @@ -581,8 +582,8 @@ static int GetRightHandRotation(IntPtr p_state) var l_argReader = new LuaArgReader(p_state); Players.Player l_player = null; l_argReader.ReadObject(ref l_player); - if(!l_argReader.HasErrors() && l_player.GetRightHandRotation(out var l_rot)) - l_argReader.PushObject(new Wrappers.Quaternion(l_rot)); + if(!l_argReader.HasErrors()) + l_argReader.PushObject(new Wrappers.Quaternion(l_player.GetRightHandRotation())); else l_argReader.PushBoolean(false); @@ -595,8 +596,8 @@ static int GetLeftHandGesture(IntPtr p_state) var l_argReader = new LuaArgReader(p_state); Players.Player l_player = null; l_argReader.ReadObject(ref l_player); - if(!l_argReader.HasErrors() && l_player.GetLeftHandGetsture(out float l_gesture)) - l_argReader.PushNumber(l_gesture); + if(!l_argReader.HasErrors()) + l_argReader.PushNumber(l_player.GetLeftHandGetsture()); else l_argReader.PushBoolean(false); @@ -609,8 +610,8 @@ static int GetRightHandGesture(IntPtr p_state) var l_argReader = new LuaArgReader(p_state); Players.Player l_player = null; l_argReader.ReadObject(ref l_player); - if(!l_argReader.HasErrors() && l_player.GetRightHandGetsture(out float l_gesture)) - l_argReader.PushNumber(l_gesture); + if(!l_argReader.HasErrors()) + l_argReader.PushNumber(l_player.GetRightHandGetsture()); else l_argReader.PushBoolean(false); @@ -637,8 +638,8 @@ static int GetZoomFactor(IntPtr p_state) var l_argReader = new LuaArgReader(p_state); Players.Player l_player = null; l_argReader.ReadObject(ref l_player); - if(!l_argReader.HasErrors() && l_player.GetZoomFactor(out float l_factor)) - l_argReader.PushNumber(l_factor); + if(!l_argReader.HasErrors()) + l_argReader.PushNumber(l_player.GetZoomFactor()); else l_argReader.PushBoolean(false); @@ -651,8 +652,8 @@ static int GetMovementVector(IntPtr p_state) var l_argReader = new LuaArgReader(p_state); Players.Player l_player = null; l_argReader.ReadObject(ref l_player); - if(!l_argReader.HasErrors() && l_player.GetMovementVector(out var l_move)) - l_argReader.PushObject(new Wrappers.Vector2(l_move)); + if(!l_argReader.HasErrors()) + l_argReader.PushObject(new Wrappers.Vector2(l_player.GetMovementVector())); else l_argReader.PushBoolean(false); @@ -665,8 +666,8 @@ static int GetLookVector(IntPtr p_state) var l_argReader = new LuaArgReader(p_state); Players.Player l_player = null; l_argReader.ReadObject(ref l_player); - if(!l_argReader.HasErrors() && l_player.GetLookVector(out var l_look)) - l_argReader.PushObject(new Wrappers.Vector2(l_look)); + if(!l_argReader.HasErrors()) + l_argReader.PushObject(new Wrappers.Vector2(l_player.GetLookVector())); else l_argReader.PushBoolean(false); @@ -693,8 +694,22 @@ static int GetFingerCurls(IntPtr p_state) var l_argReader = new LuaArgReader(p_state); Players.Player l_player = null; l_argReader.ReadObject(ref l_player); - if(!l_argReader.HasErrors() && l_player.GetFingerCurls(out var l_curls)) - l_argReader.PushTable(l_curls); + if(!l_argReader.HasErrors()) + l_argReader.PushTable(l_player.GetFingerCurls()); + else + l_argReader.PushBoolean(false); + + l_argReader.LogError(); + return 1; + } + + static int GetFingerSpreads(IntPtr p_state) + { + var l_argReader = new LuaArgReader(p_state); + Players.Player l_player = null; + l_argReader.ReadObject(ref l_player); + if(!l_argReader.HasErrors()) + l_argReader.PushTable(l_player.GetFingerSpreads()); else l_argReader.PushBoolean(false); @@ -770,8 +785,8 @@ static int GetBonePosition(IntPtr p_state) UnityEngine.HumanBodyBones l_bone = UnityEngine.HumanBodyBones.LastBone; l_argReader.ReadObject(ref l_player); l_argReader.ReadEnum(ref l_bone); - if(!l_argReader.HasErrors() && l_player.GetBonePosition(l_bone, out var l_pos)) - l_argReader.PushObject(new Wrappers.Vector3(l_pos)); + if(!l_argReader.HasErrors()) + l_argReader.PushObject(new Wrappers.Vector3(l_player.GetBonePosition(l_bone))); else l_argReader.PushBoolean(false); @@ -786,8 +801,8 @@ static int GetBoneRotation(IntPtr p_state) UnityEngine.HumanBodyBones l_bone = UnityEngine.HumanBodyBones.LastBone; l_argReader.ReadObject(ref l_player); l_argReader.ReadEnum(ref l_bone); - if(!l_argReader.HasErrors() && l_player.GetBoneRotation(l_bone, out var l_rot)) - l_argReader.PushObject(new Wrappers.Quaternion(l_rot)); + if(!l_argReader.HasErrors()) + l_argReader.PushObject(new Wrappers.Quaternion(l_player.GetBoneRotation(l_bone))); else l_argReader.PushBoolean(false); diff --git a/CVRLua/LuaHandler.cs b/CVRLua/LuaHandler.cs index 7a2b078..e83d1de 100644 --- a/CVRLua/LuaHandler.cs +++ b/CVRLua/LuaHandler.cs @@ -14,7 +14,6 @@ public enum ScriptEvent OnEnable, OnDisable, OnDestroy, - OnGUI, OnCollisionEnter, OnCollisionExit, OnCollisionStay, @@ -22,17 +21,24 @@ public enum ScriptEvent OnTriggerExit, OnTriggerStay, OnAnimatorIK, + OnMessage, + + OnPlayerJoin, + OnPlayerLeft, + OnInteractableGrab, OnInteractableDrop, OnInteractableUp, OnInteractableDown, OnInteractableGazeEnter, OnInteractableGazeExit, - OnPlayerJoin, - OnPlayerLeft, + OnEnterSeat, + OnExitSeat, + OnAttachmentAttach, OnAttachmentDeattach, + OnButtonClick, OnToggleChange, OnSliderChange diff --git a/CVRLua/LuaScript.cs b/CVRLua/LuaScript.cs index 145c221..8da4781 100644 --- a/CVRLua/LuaScript.cs +++ b/CVRLua/LuaScript.cs @@ -27,6 +27,11 @@ void Awake() if(m_luaHandler == null) { m_interactable = this.GetComponent(); + if(m_interactable != null) + { + m_interactable.onEnterSeat.AddListener(this.OnEnterSeat); + m_interactable.onExitSeat.AddListener(this.OnExitSeat); + } m_attachment = this.GetComponent(); if(m_attachment != null) @@ -73,6 +78,9 @@ void Awake() } m_luaHandler.ParseEvents(); + + Players.PlayersManager.PlayerJoin += this.OnPlayerJoin; + Players.PlayersManager.PlayerLeft += this.OnPlayerLeft; } } @@ -92,6 +100,9 @@ void OnDestroy() { m_luaHandler?.CallEvent(LuaHandler.ScriptEvent.OnDestroy); Core.Instance?.UnregisterScript(this); + + Players.PlayersManager.PlayerJoin -= this.OnPlayerJoin; + Players.PlayersManager.PlayerLeft -= this.OnPlayerLeft; } void Update() @@ -119,11 +130,6 @@ void OnDisable() m_luaHandler?.CallEvent(LuaHandler.ScriptEvent.OnDisable); } - void OnGUI() - { - m_luaHandler?.CallEvent(LuaHandler.ScriptEvent.OnGUI); - } - void OnCollisionEnter(Collision p_col) { // Add later @@ -215,6 +221,16 @@ internal void OnInteractableGazeExit(CVRInteractable p_instance) m_luaHandler?.CallEvent(LuaHandler.ScriptEvent.OnInteractableGazeExit); } + void OnEnterSeat() + { + m_luaHandler?.CallEvent(LuaHandler.ScriptEvent.OnEnterSeat); + } + + void OnExitSeat() + { + m_luaHandler?.CallEvent(LuaHandler.ScriptEvent.OnExitSeat); + } + void OnAttachmentAttach() { m_luaHandler?.CallEvent(LuaHandler.ScriptEvent.OnAttachmentAttach); @@ -226,11 +242,11 @@ void OnAttachmentDeattach() } // Players events - internal void OnPlayerJoin(Players.Player p_player) + void OnPlayerJoin(Players.Player p_player) { m_luaHandler?.CallEvent(LuaHandler.ScriptEvent.OnPlayerJoin, p_player); } - internal void OnPlayerLeft(Players.Player p_player) + void OnPlayerLeft(Players.Player p_player) { m_luaHandler?.CallEvent(LuaHandler.ScriptEvent.OnPlayerLeft, p_player); } diff --git a/CVRLua/Main.cs b/CVRLua/Main.cs index 5ba5f5d..b4d15e7 100644 --- a/CVRLua/Main.cs +++ b/CVRLua/Main.cs @@ -1,16 +1,14 @@ using ABI.CCK.Components; using ABI_RC.Core.InteractionSystem; -using ABI_RC.Core.Player; using System; using System.Collections.Generic; using System.Reflection; -using UnityEngine; namespace CVRLua { public class Core : MelonLoader.MelonMod { - public const int c_modRelease = 30; + public const int c_modRelease = 31; static public Core Instance { get; private set; } = null; @@ -56,12 +54,7 @@ public override void OnInitializeMelon() new HarmonyLib.HarmonyMethod(typeof(Core).GetMethod(nameof(OnInteractableGazeExit_Postfix), BindingFlags.NonPublic | BindingFlags.Static)) ); - // PuppetMaster - HarmonyInstance.Patch( - typeof(PuppetMaster).GetMethod("Start", BindingFlags.NonPublic | BindingFlags.Instance), - null, - new HarmonyLib.HarmonyMethod(typeof(Core).GetMethod(nameof(OnPuppetMasterStart_Postfix), BindingFlags.NonPublic | BindingFlags.Static)) - ); + Players.PlayersManager.Init(); } public override void OnDeinitializeMelon() @@ -182,41 +175,5 @@ void OnInteractableGazeExit(CVRInteractable p_interact) MelonLoader.MelonLogger.Error(e); } } - - // Players managment - static void OnPuppetMasterStart_Postfix(ref PuppetMaster __instance) => Instance?.OnPuppetMasterStart(__instance.gameObject); - void OnPuppetMasterStart(GameObject p_obj) - { - try - { - p_obj.AddComponent().Detection += this.OnPuppetMasterDestroy; - Players.Player l_player = Players.PlayersManager.AddPlayer(p_obj); - foreach(var l_script in m_scripts) - l_script.OnPlayerJoin(l_player); - } - catch(Exception e) - { - MelonLoader.MelonLogger.Error(e); - } - } - - internal void OnPuppetMasterDestroy(GameObject p_obj) - { - try - { - Players.Player l_player = Players.PlayersManager.GetFromGameObject(p_obj); - if(l_player != null) - { - foreach(var l_script in m_scripts) - l_script.OnPlayerLeft(l_player); - - Players.PlayersManager.RemovePlayerByGameObject(p_obj); - } - } - catch(Exception e) - { - MelonLoader.MelonLogger.Error(e); - } - } } } diff --git a/CVRLua/Players/Player.cs b/CVRLua/Players/Player.cs index cd7b49c..800a105 100644 --- a/CVRLua/Players/Player.cs +++ b/CVRLua/Players/Player.cs @@ -13,637 +13,694 @@ namespace CVRLua.Players { class Player { - bool m_local = false; - bool m_remote = false; + enum PlayerType + { + Local = 0, + Remote + }; + + PlayerType m_type; readonly GameObject m_gameObject = null; // Remote only readonly PlayerDescriptor m_descriptor = null; // Remote only readonly PuppetMaster m_puppetMaster = null; // Remote only public Player() { - m_local = true; + m_type = PlayerType.Local; } - public Player(GameObject p_obj) + public Player(PlayerDescriptor p_descriptor) { - m_gameObject = p_obj; - m_descriptor = p_obj.GetComponent(); - m_puppetMaster = p_obj.GetComponent(); - m_remote = true; + m_type = PlayerType.Remote; + m_descriptor = p_descriptor; + m_gameObject = p_descriptor.gameObject; + m_puppetMaster = m_gameObject.GetComponent(); } - public bool IsLocal() => m_local; - public bool IsRemote() => m_remote; - public bool IsConnected() => (m_local || (m_remote && (m_puppetMaster != null))); + public bool IsLocal() => (m_type == PlayerType.Local); + public bool IsRemote() => (m_type == PlayerType.Remote); + public bool IsConnected() => ((m_type == PlayerType.Local) || (m_descriptor != null)); - public bool GetName(out string p_name) + public string GetName() { - if(m_local) + string l_result = ""; + switch(m_type) { - p_name = CVR_MenuManager.Instance.coreData.core.username; - return true; + case PlayerType.Local: + l_result = CVR_MenuManager.Instance.coreData.core.username; + break; + case PlayerType.Remote: + l_result = m_descriptor.name; + break; } - if(m_remote && (m_descriptor != null)) - { - p_name = m_descriptor.userName; - return true; - } - p_name = ""; - return false; + return l_result; } - public bool GetId(out string p_id) + public string GetId() { - if(m_local) - { - p_id = MetaPort.Instance.ownerId; - return true; - } - if(m_remote && (m_puppetMaster != null)) + string l_result = ""; + switch(m_type) { - var l_player = CVRPlayerManager.Instance.NetworkPlayers.Find(p => p.PuppetMaster == m_puppetMaster); - if(l_player != null) - { - p_id = l_player.Uuid; - return true; - } + case PlayerType.Local: + l_result = MetaPort.Instance.ownerId; + break; + case PlayerType.Remote: + l_result = m_descriptor.ownerId; + break; } - p_id = ""; - return false; + return l_result; } - public bool GetPosition(out Vector3 p_pos) + public Vector3 GetPosition() { - if(m_local) - { - p_pos = PlayerSetup.Instance.transform.position; - return true; - } - if(m_remote && (m_gameObject != null)) + Vector3 l_result = Vector3.zero; + switch(m_type) { - p_pos = m_gameObject.transform.position; - return true; + case PlayerType.Local: + l_result = PlayerSetup.Instance.transform.position; + break; + + case PlayerType.Remote: + { + if(m_gameObject != null) + l_result = m_gameObject.transform.position; + } + break; } - p_pos = Vector3.zero; - return false; + return l_result; } - public bool GetRotation(out Quaternion p_rot) + public Quaternion GetRotation() { - if(m_local) - { - p_rot = PlayerSetup.Instance.transform.rotation; - return true; - } - if(m_remote && (m_gameObject != null)) + Quaternion l_result = Quaternion.identity; + switch(m_type) { - p_rot = m_gameObject.transform.rotation; - return true; + case PlayerType.Local: + l_result = PlayerSetup.Instance.transform.rotation; + break; + + case PlayerType.Remote: + { + if(m_gameObject != null) + l_result = m_gameObject.transform.rotation; + } + break; } - p_rot = Quaternion.identity; - return false; + return l_result; } - public bool GetAvatarHeight(out float p_height) + public float GetAvatarHeight() { - if(m_local) - { - p_height = PlayerSetup.Instance.GetAvatarHeight(); - return true; - } - if(m_remote && (m_puppetMaster != null)) + float l_result = 0f; + switch(m_type) { - p_height = m_puppetMaster.GetAvatarHeight(); - return true; + case PlayerType.Local: + l_result = PlayerSetup.Instance.GetAvatarHeight(); + break; + case PlayerType.Remote: + l_result = m_puppetMaster.GetAvatarHeight(); + break; } - p_height = 0f; - return false; + return l_result; } - public bool GetAvatarScale(out float p_scale) + public float GetAvatarScale() { - if(m_local) - { - p_scale = PlayerSetup.Instance.GetAvatarScale().y; - return true; - } - if(m_remote && (m_puppetMaster != null)) + float l_result = 0f; + switch(m_type) { - p_scale = m_puppetMaster.GetAvatarScale().y; - return true; + case PlayerType.Local: + l_result = PlayerSetup.Instance.GetAvatarScale().y; + break; + case PlayerType.Remote: + l_result = m_puppetMaster.GetAvatarScale().y; + break; } - p_scale = 0f; - return false; + return l_result; } - public bool GetPlayerHeight(out float p_height) + public float GetPlayerHeight() { - if(m_local) - { - p_height = PlayerSetup.Instance.playerHeight; - return true; - } - if(m_remote && (m_puppetMaster != null)) + float l_result = 0f; + switch(m_type) { - p_height = m_puppetMaster.GetAvatarHeight(); - return true; + case PlayerType.Local: + l_result = PlayerSetup.Instance.playerHeight; + break; + case PlayerType.Remote: + l_result = m_puppetMaster.GetAvatarHeight(); + break; } - p_height = 0f; - return false; + return l_result; } - public bool GetPlayerScale(out float p_scale) + public float GetPlayerScale() { - if(m_local) + float l_result = 0f; + switch(m_type) { - p_scale = PlayerSetup.Instance.GetPlayerScale(); - return true; + case PlayerType.Local: + l_result = PlayerSetup.Instance.GetPlayerScale(); + break; + case PlayerType.Remote: + l_result = m_puppetMaster.GetAvatarScale().y; + break; } - if(m_remote && (m_puppetMaster != null)) - { - p_scale = m_puppetMaster.GetAvatarScale().y; - return true; - } - p_scale = 0f; - return false; + return l_result; } - public bool GetCameraPosition(out Vector3 p_pos) + public Vector3 GetViewPosition() { - if(m_local) + Vector3 l_result = Vector3.zero; + switch(m_type) { - p_pos = PlayerSetup.Instance.GetActiveCamera().transform.position; - return true; - } - if(m_remote && (m_puppetMaster != null)) - { - var l_point = m_puppetMaster.GetHeadPoint(); - if(l_point != null) + case PlayerType.Local: + l_result = PlayerSetup.Instance.GetActiveCamera().transform.position; + break; + case PlayerType.Remote: { - p_pos = l_point.transform.position; - return true; + var l_point = m_puppetMaster.GetHeadPoint(); + if(l_point != null) + l_result = l_point.transform.position; } + break; } - p_pos = Vector3.zero; - return false; + return l_result; } - public bool GetCameraRotation(out Quaternion p_rot) + public Quaternion GetViewRotation() { - if(m_local) + Quaternion l_result = Quaternion.identity; + switch(m_type) { - p_rot = PlayerSetup.Instance.GetActiveCamera().transform.rotation; - return true; - } - if(m_remote && (m_puppetMaster != null)) - { - var l_point = m_puppetMaster.GetHeadPoint(); - if(l_point != null) + case PlayerType.Local: + l_result = PlayerSetup.Instance.GetActiveCamera().transform.rotation; + break; + case PlayerType.Remote: { - p_rot = l_point.transform.rotation; - return true; + var l_point = m_puppetMaster.GetHeadPoint(); + if(l_point != null) + l_result = l_point.transform.rotation; } + break; } - p_rot = Quaternion.identity; - return false; + return l_result; } public bool IsInVR() { - if(m_local) - return CheckVR.Instance.hasVrDeviceLoaded; - if(m_remote && (m_puppetMaster != null)) - return (m_puppetMaster.PlayerAvatarMovementDataInput.DeviceType == PlayerAvatarMovementData.UsingDeviceType.PCVR); - return false; + bool l_result = false; + switch(m_type) + { + case PlayerType.Local: + l_result = CheckVR.Instance.hasVrDeviceLoaded; + break; + case PlayerType.Remote: + l_result = (m_puppetMaster.PlayerAvatarMovementDataInput.DeviceType != PlayerAvatarMovementData.UsingDeviceType.PCStanalone); + break; + } + return l_result; } - public bool IsInFullbody() - { - if(m_local) - return BodySystem.isCalibratedAsFullBody; - return false; - } + public bool IsInFullbody() => ((m_type == PlayerType.Local) && BodySystem.isCalibratedAsFullBody); public bool HasAvatar() { - if(m_local) - return (PlayerSetup.Instance._avatar != null); - if(m_remote && (m_puppetMaster != null)) + bool l_result = false; + switch(m_type) { - CVRAvatar l_avatar = m_puppetMaster.GetAvatar(); - return (l_avatar != null); + case PlayerType.Local: + l_result = (PlayerSetup.Instance._avatar != null); + break; + case PlayerType.Remote: + l_result = (m_puppetMaster.GetAvatar() != null); + break; } - return false; + return l_result; } - public bool IsAvatarLoading() - { - if(m_local) - return PlayerSetup.Instance.avatarIsLoading; - return false; - } + public bool IsAvatarLoading() => ((m_type == PlayerType.Local) && PlayerSetup.Instance.avatarIsLoading); public bool IsAvatarHumanoid() { - if(m_local) - return ((PlayerSetup.Instance._animator != null) && PlayerSetup.Instance._animator.isHuman); - if(m_remote && (m_puppetMaster != null)) + bool l_result = false; + switch(m_type) { - Animator l_animator = m_puppetMaster.GetAnimator(); - return ((l_animator != null) && l_animator.isHuman); + case PlayerType.Local: + l_result = ((PlayerSetup.Instance._animator != null) && PlayerSetup.Instance._animator.isHuman); + break; + case PlayerType.Remote: + { + Animator l_animator = m_puppetMaster.GetAnimator(); + l_result = ((l_animator != null) && l_animator.isHuman); + } + break; } - return false; + return l_result; } public bool IsFlying() { - if(m_local) - return MovementSystem.Instance.flying; - if(m_remote && (m_puppetMaster != null)) - return m_puppetMaster.PlayerAvatarMovementDataInput.AnimatorFlying; - return false; + bool l_result = false; + switch(m_type) + { + case PlayerType.Local: + l_result = MovementSystem.Instance.flying; + break; + case PlayerType.Remote: + l_result = m_puppetMaster.PlayerAvatarMovementDataInput.AnimatorFlying; + break; + } + return l_result; } public bool IsCrouching() { - if(m_local) - return MovementSystem.Instance.crouching; - if(m_remote && (m_puppetMaster != null)) - return m_puppetMaster.PlayerAvatarMovementDataInput.AnimatorCrouching; - return false; + bool l_result = false; + switch(m_type) + { + case PlayerType.Local: + l_result = MovementSystem.Instance.crouching; + break; + case PlayerType.Remote: + l_result = m_puppetMaster.PlayerAvatarMovementDataInput.AnimatorCrouching; + break; + } + return l_result; } public bool IsProning() { - if(m_local) - return MovementSystem.Instance.prone; - if(m_remote && (m_puppetMaster != null)) - return m_puppetMaster.PlayerAvatarMovementDataInput.AnimatorProne; - return false; + bool l_result = false; + switch(m_type) + { + case PlayerType.Local: + l_result = MovementSystem.Instance.prone; + break; + case PlayerType.Remote: + l_result = m_puppetMaster.PlayerAvatarMovementDataInput.AnimatorProne; + break; + } + return l_result; } public bool IsSitting() { - if(m_local) - return MovementSystem.Instance.sitting; - if(m_remote && (m_puppetMaster != null)) - return m_puppetMaster.PlayerAvatarMovementDataInput.AnimatorSitting; - return false; + bool l_result = false; + switch(m_type) + { + case PlayerType.Local: + l_result = MovementSystem.Instance.sitting; + break; + case PlayerType.Remote: + l_result = m_puppetMaster.PlayerAvatarMovementDataInput.AnimatorSitting; + break; + } + return l_result; } public bool IsSprinting() { - if(m_local) - return CVRInputManager.Instance.sprint; - return false; + bool l_result = false; + switch(m_type) + { + case PlayerType.Local: + l_result = CVRInputManager.Instance.sprint; + break; + case PlayerType.Remote: + { + Vector2 l_move = new Vector2(m_puppetMaster.PlayerAvatarMovementDataInput.AnimatorMovementX, m_puppetMaster.PlayerAvatarMovementDataInput.AnimatorMovementY); + l_result = (l_move.magnitude >= 0.5f); + } + break; + } + return l_result; } - public bool IsJumping() - { - if(m_local) - return CVRInputManager.Instance.jump; - return false; - } + public bool IsJumping() => ((m_type == PlayerType.Local) && CVRInputManager.Instance.jump); public bool IsGrounded() { - if(m_local) - return MovementSystem.Instance.IsGrounded(); - if(m_remote && (m_puppetMaster != null)) - return m_puppetMaster.PlayerAvatarMovementDataInput.AnimatorGrounded; - return false; - } - - public bool IsZooming() - { - if(m_local) - return CVRInputManager.Instance.zoom; - return false; - } - - public bool GetZoomFactor(out float p_factor) - { - if(m_local) + bool l_result = false; + switch(m_type) { - p_factor = CVR_DesktopCameraController.currentZoomProgress; - return true; + case PlayerType.Local: + l_result = MovementSystem.Instance.IsGrounded(); + break; + case PlayerType.Remote: + l_result = m_puppetMaster.PlayerAvatarMovementDataInput.AnimatorGrounded; + break; } - p_factor = 0f; return false; } - public bool GetMovementVector(out Vector2 p_vec) + public bool IsZooming() => ((m_type == PlayerType.Local) && CVRInputManager.Instance.zoom); + + public float GetZoomFactor() => ((m_type == PlayerType.Local) ? CVR_DesktopCameraController.currentZoomProgress : 0f); + + public Vector2 GetMovementVector() { - if(m_local) - { - p_vec = new Vector2(MovementSystem.Instance.movementVector.x, MovementSystem.Instance.movementVector.z); - return true; - } - if(m_remote && (m_puppetMaster != null)) + Vector2 l_result = Vector2.zero; + switch(m_type) { - p_vec = new Vector2(m_puppetMaster.PlayerAvatarMovementDataInput.AnimatorMovementX, m_puppetMaster.PlayerAvatarMovementDataInput.AnimatorMovementY); - return true; + case PlayerType.Local: + { + l_result.x = MovementSystem.Instance.movementVector.x; + l_result.y = MovementSystem.Instance.movementVector.y; + } + break; + case PlayerType.Remote: + { + l_result.x = m_puppetMaster.PlayerAvatarMovementDataInput.AnimatorMovementX; + l_result.y = m_puppetMaster.PlayerAvatarMovementDataInput.AnimatorMovementY; + } + break; } - p_vec = Vector2.zero; - return false; + return l_result; } - public bool GetLeftHandPosition(out Vector3 p_pos) + public Vector3 GetLeftHandPosition() { - if(m_local) + Vector3 l_result = Vector3.zero; + switch(m_type) { - p_pos = IKSystem.Instance.leftHandOffset.position; - return true; - } - if(m_remote && (m_puppetMaster != null)) - { - Animator l_animator = m_puppetMaster.GetAnimator(); - if((l_animator != null) && l_animator.isHuman) + case PlayerType.Local: + l_result = IKSystem.Instance.leftHandOffset.position; + break; + case PlayerType.Remote: { - Transform l_hand = l_animator.GetBoneTransform(HumanBodyBones.LeftHand); - if(l_hand != null) + Animator l_animator = m_puppetMaster.GetAnimator(); + if((l_animator != null) && l_animator.isHuman) { - p_pos = l_hand.position; - return true; + Transform l_hand = l_animator.GetBoneTransform(HumanBodyBones.LeftHand); + if(l_hand != null) + l_result = l_hand.position; } } + break; } - p_pos = Vector3.zero; - return false; + return l_result; } - public bool GetLeftHandRotation(out Quaternion p_rot) + public Quaternion GetLeftHandRotation() { - if(m_local) - { - p_rot = IKSystem.Instance.leftHandOffset.rotation; - return true; - } - if(m_remote && (m_puppetMaster != null)) + Quaternion l_result = Quaternion.identity; + switch(m_type) { - Animator l_animator = m_puppetMaster.GetAnimator(); - if((l_animator != null) && l_animator.isHuman) + case PlayerType.Local: + l_result = IKSystem.Instance.leftHandOffset.rotation; + break; + case PlayerType.Remote: { - Transform l_hand = l_animator.GetBoneTransform(HumanBodyBones.LeftHand); - if(l_hand != null) + Animator l_animator = m_puppetMaster.GetAnimator(); + if((l_animator != null) && l_animator.isHuman) { - p_rot = l_hand.rotation; - return true; + Transform l_hand = l_animator.GetBoneTransform(HumanBodyBones.LeftHand); + if(l_hand != null) + l_result = l_hand.rotation; } } + break; } - p_rot = Quaternion.identity; - return false; + return l_result; } - public bool GetRightHandPosition(out Vector3 p_pos) + public Vector3 GetRightHandPosition() { - if(m_local) - { - p_pos = IKSystem.Instance.rightHandOffset.position; - return true; - } - if(m_remote && (m_puppetMaster != null)) + Vector3 l_result = Vector3.zero; + switch(m_type) { - Animator l_animator = m_puppetMaster.GetAnimator(); - if((l_animator != null) && l_animator.isHuman) + case PlayerType.Local: + l_result = IKSystem.Instance.rightHandOffset.position; + break; + case PlayerType.Remote: { - Transform l_hand = l_animator.GetBoneTransform(HumanBodyBones.RightHand); - if(l_hand != null) + Animator l_animator = m_puppetMaster.GetAnimator(); + if((l_animator != null) && l_animator.isHuman) { - p_pos = l_hand.position; - return true; + Transform l_hand = l_animator.GetBoneTransform(HumanBodyBones.RightHand); + if(l_hand != null) + l_result = l_hand.position; } } + break; } - p_pos = Vector3.zero; - return false; + return l_result; } - public bool GetRightHandRotation(out Quaternion p_rot) + public Quaternion GetRightHandRotation() { - if(m_local) - { - p_rot = IKSystem.Instance.rightHandOffset.rotation; - return true; - } - if(m_remote && (m_puppetMaster != null)) + Quaternion l_result = Quaternion.identity; + switch(m_type) { - Animator l_animator = m_puppetMaster.GetAnimator(); - if((l_animator != null) && l_animator.isHuman) + case PlayerType.Local: + l_result = IKSystem.Instance.rightHandOffset.rotation; + break; + case PlayerType.Remote: { - Transform l_hand = l_animator.GetBoneTransform(HumanBodyBones.RightHand); - if(l_hand != null) + Animator l_animator = m_puppetMaster.GetAnimator(); + if((l_animator != null) && l_animator.isHuman) { - p_rot = l_hand.rotation; - return true; + Transform l_hand = l_animator.GetBoneTransform(HumanBodyBones.RightHand); + if(l_hand != null) + l_result = l_hand.rotation; } } + break; } - p_rot = Quaternion.identity; - return false; + return l_result; } - public bool GetLeftHandGetsture(out float p_gesture) + public float GetLeftHandGetsture() { - if(m_local) + float l_result = 0f; + switch(m_type) { - p_gesture = CVRInputManager.Instance.gestureLeft; - return true; - } - if(m_remote && (m_puppetMaster != null)) - { - p_gesture = m_puppetMaster.PlayerAvatarMovementDataInput.AnimatorGestureLeft; - return true; + case PlayerType.Local: + l_result = CVRInputManager.Instance.gestureLeft; + break; + case PlayerType.Remote: + l_result = m_puppetMaster.PlayerAvatarMovementDataInput.AnimatorGestureLeft; + break; } - p_gesture = 0f; - return false; + return l_result; } - public bool GetRightHandGetsture(out float p_gesture) + public float GetRightHandGetsture() { - if(m_local) + float l_result = 0f; + switch(m_type) { - p_gesture = CVRInputManager.Instance.gestureRight; - return true; + case PlayerType.Local: + l_result = CVRInputManager.Instance.gestureRight; + break; + case PlayerType.Remote: + l_result = m_puppetMaster.PlayerAvatarMovementDataInput.AnimatorGestureRight; + break; } - if(m_remote && (m_puppetMaster != null)) - { - p_gesture = m_puppetMaster.PlayerAvatarMovementDataInput.AnimatorGestureRight; - return true; - } - p_gesture = 0f; - return false; + return l_result; } public void Teleport(Vector3 p_position) { - if(m_local) + if(m_type == PlayerType.Local) MovementSystem.Instance.TeleportTo(p_position); } public void Teleport(Vector3 p_position, Quaternion p_rotation) { - if(m_local) + if(m_type == PlayerType.Local) MovementSystem.Instance.TeleportTo(p_position, p_rotation.eulerAngles); } public void SetImmobilized(bool p_state) { - if(m_local) + if(m_type == PlayerType.Local) MovementSystem.Instance.SetImmobilized(p_state); } public void Respawn() { - if(m_local) + if(m_type == PlayerType.Local) RootLogic.Instance.Respawn(); } - public bool GetBonePosition(HumanBodyBones p_bone, out Vector3 p_vec) + public Vector3 GetBonePosition(HumanBodyBones p_bone) { - if(m_local) + Vector3 l_result = Vector3.zero; + switch(m_type) { - Vector3 l_result = Vector3.zero; - if((PlayerSetup.Instance._animator != null) && PlayerSetup.Instance._animator.isHuman) + case PlayerType.Local: { - Transform l_bone = PlayerSetup.Instance._animator.GetBoneTransform(p_bone); - if(l_bone != null) + if((PlayerSetup.Instance._animator != null) && PlayerSetup.Instance._animator.isHuman) { - p_vec = l_bone.position; - return true; + Transform l_bone = PlayerSetup.Instance._animator.GetBoneTransform(p_bone); + if(l_bone != null) + l_result = l_bone.position; } } - } - if(m_remote && (m_puppetMaster != null)) - { - Animator l_animator = m_puppetMaster.GetAnimator(); - if((l_animator != null) && l_animator.isHuman) + break; + case PlayerType.Remote: { - Transform l_bone = l_animator.GetBoneTransform(p_bone); - if(l_bone != null) + Animator l_animator = m_puppetMaster.GetAnimator(); + if((l_animator != null) && l_animator.isHuman) { - p_vec = l_bone.position; - return true; + Transform l_bone = l_animator.GetBoneTransform(p_bone); + if(l_bone != null) + l_result = l_bone.position; } } + break; } - p_vec = Vector3.zero; - return false; + return l_result; } - public bool GetBoneRotation(HumanBodyBones p_bone, out Quaternion p_rot) + public Quaternion GetBoneRotation(HumanBodyBones p_bone) { - if(m_local) + Quaternion l_result = Quaternion.identity; + switch(m_type) { - Vector3 l_result = Vector3.zero; - if((PlayerSetup.Instance._animator != null) && PlayerSetup.Instance._animator.isHuman) + case PlayerType.Local: { - Transform l_bone = PlayerSetup.Instance._animator.GetBoneTransform(p_bone); - if(l_bone != null) + if((PlayerSetup.Instance._animator != null) && PlayerSetup.Instance._animator.isHuman) { - p_rot = l_bone.rotation; - return true; + Transform l_bone = PlayerSetup.Instance._animator.GetBoneTransform(p_bone); + if(l_bone != null) + l_result = l_bone.rotation; } } - } - if(m_remote && (m_puppetMaster != null)) - { - Animator l_animator = m_puppetMaster.GetAnimator(); - if((l_animator != null) && l_animator.isHuman) + break; + case PlayerType.Remote: { - Transform l_bone = l_animator.GetBoneTransform(p_bone); - if(l_bone != null) + Animator l_animator = m_puppetMaster.GetAnimator(); + if((l_animator != null) && l_animator.isHuman) { - p_rot = l_bone.rotation; - return true; + Transform l_bone = l_animator.GetBoneTransform(p_bone); + if(l_bone != null) + l_result = l_bone.rotation; } } + break; } - p_rot = Quaternion.identity; - return false; + return l_result; } - public bool GetLookVector(out Vector2 p_vec) + public Vector2 GetLookVector() => ((m_type == PlayerType.Local) ? CVRInputManager.Instance.lookVector : Vector2.zero); + + public bool GetIndividualFingerTracking() { - if(m_local) + bool l_result = false; + switch(m_type) { - p_vec = CVRInputManager.Instance.lookVector; - return true; + case PlayerType.Local: + l_result = CVRInputManager.Instance.individualFingerTracking; + break; + case PlayerType.Remote: + l_result = m_puppetMaster.PlayerAvatarMovementDataInput.IndexUseIndividualFingers; + break; } - p_vec = Vector2.zero; - return false; + return l_result; } - public bool GetIndividualFingerTracking() + public float[] GetFingerCurls() { - if(m_local) - return CVRInputManager.Instance.individualFingerTracking; - if(m_remote && (m_puppetMaster != null)) - return m_puppetMaster.PlayerAvatarMovementDataInput.IndexUseIndividualFingers; - return false; + float[] l_result = null; + switch(m_type) + { + case PlayerType.Local: + { + l_result = new float[10] + { + CVRInputManager.Instance.fingerCurlLeftThumb, + CVRInputManager.Instance.fingerCurlLeftIndex, + CVRInputManager.Instance.fingerCurlLeftMiddle, + CVRInputManager.Instance.fingerCurlLeftThumb, + CVRInputManager.Instance.fingerCurlLeftPinky, + CVRInputManager.Instance.fingerCurlRightThumb, + CVRInputManager.Instance.fingerCurlRightIndex, + CVRInputManager.Instance.fingerCurlRightMiddle, + CVRInputManager.Instance.fingerCurlRightThumb, + CVRInputManager.Instance.fingerCurlRightPinky + }; + } + break; + case PlayerType.Remote: + { + l_result = new float[10] + { + m_puppetMaster.PlayerAvatarMovementDataInput.LeftThumbCurl, + m_puppetMaster.PlayerAvatarMovementDataInput.LeftIndexCurl, + m_puppetMaster.PlayerAvatarMovementDataInput.LeftMiddleCurl, + m_puppetMaster.PlayerAvatarMovementDataInput.LeftRingCurl, + m_puppetMaster.PlayerAvatarMovementDataInput.LeftPinkyCurl, + m_puppetMaster.PlayerAvatarMovementDataInput.RightThumbCurl, + m_puppetMaster.PlayerAvatarMovementDataInput.RightIndexCurl, + m_puppetMaster.PlayerAvatarMovementDataInput.RightMiddleCurl, + m_puppetMaster.PlayerAvatarMovementDataInput.RightRingCurl, + m_puppetMaster.PlayerAvatarMovementDataInput.RightPinkyCurl + }; + } + break; + } + return l_result; } - public bool GetFingerCurls(out float[] p_curls) + public float[] GetFingerSpreads() { - if(m_local) + float[] l_result = null; + switch(m_type) { - p_curls = new float[10] + case PlayerType.Local: { - CVRInputManager.Instance.fingerCurlLeftThumb, - CVRInputManager.Instance.fingerCurlLeftIndex, - CVRInputManager.Instance.fingerCurlLeftMiddle, - CVRInputManager.Instance.fingerCurlLeftThumb, - CVRInputManager.Instance.fingerCurlLeftPinky, - CVRInputManager.Instance.fingerCurlRightThumb, - CVRInputManager.Instance.fingerCurlRightIndex, - CVRInputManager.Instance.fingerCurlRightMiddle, - CVRInputManager.Instance.fingerCurlRightThumb, - CVRInputManager.Instance.fingerCurlRightPinky - }; - return true; - } - if(m_remote && (m_puppetMaster != null)) - { - p_curls = new float[10] + l_result = new float[10] + { + CVRInputManager.Instance.fingerSpreadLeftThumb, + CVRInputManager.Instance.fingerSpreadLeftIndex, + CVRInputManager.Instance.fingerSpreadLeftMiddle, + CVRInputManager.Instance.fingerSpreadLeftThumb, + CVRInputManager.Instance.fingerSpreadLeftPinky, + CVRInputManager.Instance.fingerSpreadRightThumb, + CVRInputManager.Instance.fingerSpreadRightIndex, + CVRInputManager.Instance.fingerSpreadRightMiddle, + CVRInputManager.Instance.fingerSpreadRightThumb, + CVRInputManager.Instance.fingerSpreadRightPinky + }; + } + break; + case PlayerType.Remote: { - m_puppetMaster.PlayerAvatarMovementDataInput.LeftThumbCurl, - m_puppetMaster.PlayerAvatarMovementDataInput.LeftIndexCurl, - m_puppetMaster.PlayerAvatarMovementDataInput.LeftMiddleCurl, - m_puppetMaster.PlayerAvatarMovementDataInput.LeftRingCurl, - m_puppetMaster.PlayerAvatarMovementDataInput.LeftPinkyCurl, - m_puppetMaster.PlayerAvatarMovementDataInput.RightThumbCurl, - m_puppetMaster.PlayerAvatarMovementDataInput.RightIndexCurl, - m_puppetMaster.PlayerAvatarMovementDataInput.RightMiddleCurl, - m_puppetMaster.PlayerAvatarMovementDataInput.RightRingCurl, - m_puppetMaster.PlayerAvatarMovementDataInput.RightPinkyCurl - }; - return true; + l_result = new float[10] + { + m_puppetMaster.PlayerAvatarMovementDataInput.LeftThumbSpread, + m_puppetMaster.PlayerAvatarMovementDataInput.LeftIndexSpread, + m_puppetMaster.PlayerAvatarMovementDataInput.LeftMiddleSpread, + m_puppetMaster.PlayerAvatarMovementDataInput.LeftRingSpread, + m_puppetMaster.PlayerAvatarMovementDataInput.LeftPinkySpread, + m_puppetMaster.PlayerAvatarMovementDataInput.RightThumbSpread, + m_puppetMaster.PlayerAvatarMovementDataInput.RightIndexSpread, + m_puppetMaster.PlayerAvatarMovementDataInput.RightMiddleSpread, + m_puppetMaster.PlayerAvatarMovementDataInput.RightRingSpread, + m_puppetMaster.PlayerAvatarMovementDataInput.RightPinkySpread + }; + } + break; } - p_curls = null; - return false; + return l_result; } public static bool Compare(Player p_playerA, Player p_playerB) { - if(p_playerA.m_local && p_playerB.m_local) + if(p_playerA.IsLocal() && p_playerB.IsLocal()) return true; - if(p_playerA.m_local && p_playerB.m_remote) + if(p_playerA.IsLocal() && p_playerB.IsRemote()) return false; - if(p_playerA.m_remote && p_playerB.m_local) + if(p_playerA.IsRemote() && p_playerB.IsLocal()) return false; - if(p_playerA.m_remote && p_playerB.m_remote) + if(p_playerA.IsRemote() && p_playerB.IsRemote()) return (p_playerA.m_gameObject == p_playerB.m_gameObject); return false; } - public override string ToString() - { - string l_result = "Player("; - if(GetName(out string l_name)) - l_result += l_name; - l_result += ')'; - return l_result; - } + public override string ToString() => string.Format("Player({0})", GetName()); } } diff --git a/CVRLua/Players/PlayersManager.cs b/CVRLua/Players/PlayersManager.cs index 96627f8..6f6f9f4 100644 --- a/CVRLua/Players/PlayersManager.cs +++ b/CVRLua/Players/PlayersManager.cs @@ -1,22 +1,65 @@ using ABI_RC.Core.Player; using ABI_RC.Core.Savior; using System.Collections.Generic; -using System.Linq; using UnityEngine; +using ABI_RC.Systems.GameEventSystem; +using System; namespace CVRLua.Players { static class PlayersManager { - static readonly Dictionary ms_players = new Dictionary(); + static readonly Dictionary ms_remotePlayers = new Dictionary(); static readonly Player ms_localPlayer = new Player(); + static internal Action PlayerJoin; + static internal Action PlayerLeft; + + internal static void Init() + { + CVRGameEventSystem.Player.OnJoin.AddListener(OnPlayerJoin); + CVRGameEventSystem.Player.OnLeave.AddListener(OnPlayerLeave); + } + + static void OnPlayerJoin(PlayerDescriptor p_descriptor) + { + try + { + if(!ms_remotePlayers.ContainsKey(p_descriptor)) + { + Player l_remotePlayer = new Player(p_descriptor); + ms_remotePlayers.Add(p_descriptor, l_remotePlayer); + PlayerJoin?.Invoke(l_remotePlayer); + } + } + catch(Exception e) + { + MelonLoader.MelonLogger.Warning(e); + } + } + + static void OnPlayerLeave(PlayerDescriptor p_descriptor) + { + try + { + if(ms_remotePlayers.TryGetValue(p_descriptor, out Player l_remotePlayer)) + { + PlayerLeft?.Invoke(l_remotePlayer); + ms_remotePlayers.Remove(p_descriptor); + } + } + catch(Exception e) + { + MelonLoader.MelonLogger.Warning(e); + } + } + public static Player GetLocalPlayer() => ms_localPlayer; public static List GetRemotePlayers() { var l_list = new List(); - foreach(var l_pair in ms_players) + foreach(var l_pair in ms_remotePlayers) l_list.Add(l_pair.Value); return l_list; } @@ -25,7 +68,7 @@ public static List GetAllPlayers() { var l_list = new List(); l_list.Add(ms_localPlayer); - foreach(var l_pair in ms_players) + foreach(var l_pair in ms_remotePlayers) l_list.Add(l_pair.Value); return l_list; } @@ -35,11 +78,10 @@ public static Player GetFromId(string p_id) if(MetaPort.Instance.ownerId == p_id) return ms_localPlayer; - if(CVRPlayerManager.Instance.GetPlayerPuppetMaster(p_id, out var l_puppet)) + foreach(var l_remotePlayer in ms_remotePlayers) { - var l_searchPair = ms_players.FirstOrDefault(p => (p.Key == l_puppet.gameObject)); - if(l_searchPair.Key != null) - return l_searchPair.Value; + if(l_remotePlayer.Key.ownerId == p_id) + return l_remotePlayer.Value; } return null; } @@ -47,28 +89,16 @@ public static Player GetFromId(string p_id) public static Player GetFromGameObject(GameObject p_obj) { Player l_result = null; - if(!ms_players.TryGetValue(p_obj, out l_result) && (p_obj == PlayerSetup.Instance.gameObject)) + Transform l_root = p_obj.transform.root; + if(l_root == PlayerSetup.Instance.transform) l_result = ms_localPlayer; - return l_result; - } - - // Core call only - internal static Player AddPlayer(GameObject p_obj) - { - Player l_result = null; - if(!ms_players.TryGetValue(p_obj, out l_result)) + else { - l_result = new Player(p_obj); - ms_players.Add(p_obj, l_result); + PlayerDescriptor l_descriptor = l_root.GetComponent(); + if(l_descriptor != null) + ms_remotePlayers.TryGetValue(l_descriptor, out l_result); } return l_result; } - - // Core call only - internal static void RemovePlayerByGameObject(GameObject p_obj) - { - if(ms_players.ContainsKey(p_obj)) - ms_players.Remove(p_obj); - } } }