mirror of
https://github.com/hanetzer/sdraw_mods_cvr.git
synced 2025-09-05 03:19:23 +00:00
Avatar as parameter of any animator type
This commit is contained in:
parent
adf7796f9e
commit
080c0a5876
3 changed files with 114 additions and 45 deletions
|
@ -1,43 +0,0 @@
|
||||||
using ABI_RC.Core.Util.AnimatorManager;
|
|
||||||
using System.Text.RegularExpressions;
|
|
||||||
using UnityEngine;
|
|
||||||
|
|
||||||
namespace ml_prm
|
|
||||||
{
|
|
||||||
class AvatarBoolParameter
|
|
||||||
{
|
|
||||||
public readonly string m_name;
|
|
||||||
public readonly int m_hash = 0;
|
|
||||||
public readonly bool m_sync;
|
|
||||||
readonly AvatarAnimatorManager m_manager = null;
|
|
||||||
|
|
||||||
public AvatarBoolParameter(string p_name, AvatarAnimatorManager p_manager)
|
|
||||||
{
|
|
||||||
m_name = p_name;
|
|
||||||
m_manager = p_manager;
|
|
||||||
|
|
||||||
Regex l_regex = new Regex("^#?" + p_name + '$');
|
|
||||||
foreach(var l_param in m_manager.Animator.parameters)
|
|
||||||
{
|
|
||||||
if(l_regex.IsMatch(l_param.name) && (l_param.type == AnimatorControllerParameterType.Bool))
|
|
||||||
{
|
|
||||||
m_name = l_param.name;
|
|
||||||
m_sync = !l_param.name.StartsWith('#');
|
|
||||||
m_hash = l_param.nameHash;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void SetValue(bool p_value)
|
|
||||||
{
|
|
||||||
if(m_hash != 0)
|
|
||||||
{
|
|
||||||
if(m_sync)
|
|
||||||
m_manager.SetParameter(m_name, p_value);
|
|
||||||
else
|
|
||||||
m_manager.Animator.SetBool(m_hash, p_value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
109
ml_prm/AvatarParameter.cs
Normal file
109
ml_prm/AvatarParameter.cs
Normal file
|
@ -0,0 +1,109 @@
|
||||||
|
using ABI_RC.Core.Util.AnimatorManager;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace ml_prm
|
||||||
|
{
|
||||||
|
class AvatarParameter
|
||||||
|
{
|
||||||
|
public readonly string m_name;
|
||||||
|
public readonly int m_hash = 0;
|
||||||
|
public readonly bool m_sync;
|
||||||
|
public readonly AnimatorControllerParameterType m_type;
|
||||||
|
readonly AvatarAnimatorManager m_manager = null;
|
||||||
|
|
||||||
|
public AvatarParameter(string p_name, AvatarAnimatorManager p_manager)
|
||||||
|
{
|
||||||
|
m_name = p_name;
|
||||||
|
m_manager = p_manager;
|
||||||
|
|
||||||
|
Regex l_regex = new Regex("^#?" + p_name + '$');
|
||||||
|
foreach(var l_param in m_manager.Animator.parameters)
|
||||||
|
{
|
||||||
|
if(l_regex.IsMatch(l_param.name))
|
||||||
|
{
|
||||||
|
m_name = l_param.name;
|
||||||
|
m_sync = !l_param.name.StartsWith('#');
|
||||||
|
m_hash = l_param.nameHash;
|
||||||
|
m_type = l_param.type;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetValue(bool p_value)
|
||||||
|
{
|
||||||
|
if(m_hash != 0)
|
||||||
|
{
|
||||||
|
if(m_sync)
|
||||||
|
m_manager.SetParameter(m_name, p_value);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
switch(m_type)
|
||||||
|
{
|
||||||
|
case AnimatorControllerParameterType.Bool:
|
||||||
|
case AnimatorControllerParameterType.Trigger:
|
||||||
|
m_manager.Animator.SetBool(m_hash, p_value);
|
||||||
|
break;
|
||||||
|
case AnimatorControllerParameterType.Int:
|
||||||
|
m_manager.Animator.SetInteger(m_hash, p_value ? 1 : 0);
|
||||||
|
break;
|
||||||
|
case AnimatorControllerParameterType.Float:
|
||||||
|
m_manager.Animator.SetFloat(m_hash, p_value ? 1f : 0f);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetValue(int p_value)
|
||||||
|
{
|
||||||
|
if(m_hash != 0)
|
||||||
|
{
|
||||||
|
if(m_sync)
|
||||||
|
m_manager.SetParameter(m_name, p_value);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
switch(m_type)
|
||||||
|
{
|
||||||
|
case AnimatorControllerParameterType.Bool:
|
||||||
|
case AnimatorControllerParameterType.Trigger:
|
||||||
|
m_manager.Animator.SetBool(m_hash, p_value > 0);
|
||||||
|
break;
|
||||||
|
case AnimatorControllerParameterType.Int:
|
||||||
|
m_manager.Animator.SetInteger(m_hash, p_value);
|
||||||
|
break;
|
||||||
|
case AnimatorControllerParameterType.Float:
|
||||||
|
m_manager.Animator.SetFloat(m_hash, p_value);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetValue(float p_value)
|
||||||
|
{
|
||||||
|
if(m_hash != 0)
|
||||||
|
{
|
||||||
|
if(m_sync)
|
||||||
|
m_manager.SetParameter(m_name, p_value);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
switch(m_type)
|
||||||
|
{
|
||||||
|
case AnimatorControllerParameterType.Bool:
|
||||||
|
case AnimatorControllerParameterType.Trigger:
|
||||||
|
m_manager.Animator.SetBool(m_hash, p_value > 0f);
|
||||||
|
break;
|
||||||
|
case AnimatorControllerParameterType.Int:
|
||||||
|
m_manager.Animator.SetInteger(m_hash, (int)p_value);
|
||||||
|
break;
|
||||||
|
case AnimatorControllerParameterType.Float:
|
||||||
|
m_manager.Animator.SetFloat(m_hash, p_value);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,4 +1,5 @@
|
||||||
using ABI.CCK.Components;
|
using ABI.CCK.Components;
|
||||||
|
using ABI_RC.Core;
|
||||||
using ABI_RC.Core.InteractionSystem;
|
using ABI_RC.Core.InteractionSystem;
|
||||||
using ABI_RC.Core.Player;
|
using ABI_RC.Core.Player;
|
||||||
using ABI_RC.Systems.IK;
|
using ABI_RC.Systems.IK;
|
||||||
|
@ -39,7 +40,7 @@ namespace ml_prm
|
||||||
readonly List<System.Tuple<CharacterJoint, Vector3>> m_jointAnchors = null;
|
readonly List<System.Tuple<CharacterJoint, Vector3>> m_jointAnchors = null;
|
||||||
|
|
||||||
RagdollToggle m_avatarRagdollToggle = null; // Custom component available for editor
|
RagdollToggle m_avatarRagdollToggle = null; // Custom component available for editor
|
||||||
AvatarBoolParameter m_ragdolledParameter = null;
|
AvatarParameter m_ragdolledParameter = null;
|
||||||
PhysicMaterial m_physicsMaterial = null;
|
PhysicMaterial m_physicsMaterial = null;
|
||||||
|
|
||||||
bool m_inAir = false;
|
bool m_inAir = false;
|
||||||
|
@ -299,6 +300,7 @@ namespace ml_prm
|
||||||
BipedRagdollReferences l_avatarReferences = BipedRagdollReferences.FromAvatar(PlayerSetup.Instance._animator);
|
BipedRagdollReferences l_avatarReferences = BipedRagdollReferences.FromAvatar(PlayerSetup.Instance._animator);
|
||||||
|
|
||||||
m_puppetRoot = new GameObject("Root").transform;
|
m_puppetRoot = new GameObject("Root").transform;
|
||||||
|
m_puppetRoot.gameObject.layer = CVRLayers.PlayerClone;
|
||||||
m_puppetRoot.parent = m_puppet;
|
m_puppetRoot.parent = m_puppet;
|
||||||
m_puppetRoot.position = m_avatarTransform.position;
|
m_puppetRoot.position = m_avatarTransform.position;
|
||||||
m_puppetRoot.rotation = m_avatarTransform.rotation;
|
m_puppetRoot.rotation = m_avatarTransform.rotation;
|
||||||
|
@ -370,7 +372,7 @@ namespace ml_prm
|
||||||
m_vrIK.onPostSolverUpdate.AddListener(this.OnIKPostSolverUpdate);
|
m_vrIK.onPostSolverUpdate.AddListener(this.OnIKPostSolverUpdate);
|
||||||
|
|
||||||
m_avatarRagdollToggle = PlayerSetup.Instance._avatar.GetComponentInChildren<RagdollToggle>(true);
|
m_avatarRagdollToggle = PlayerSetup.Instance._avatar.GetComponentInChildren<RagdollToggle>(true);
|
||||||
m_ragdolledParameter = new AvatarBoolParameter("Ragdolled", PlayerSetup.Instance.animatorManager);
|
m_ragdolledParameter = new AvatarParameter("Ragdolled", PlayerSetup.Instance.animatorManager);
|
||||||
|
|
||||||
m_initTask = StartCoroutine(WaitForBodyHandlers());
|
m_initTask = StartCoroutine(WaitForBodyHandlers());
|
||||||
}
|
}
|
||||||
|
@ -781,6 +783,7 @@ namespace ml_prm
|
||||||
static Transform CloneTransform(Transform p_source, Transform p_parent, string p_name)
|
static Transform CloneTransform(Transform p_source, Transform p_parent, string p_name)
|
||||||
{
|
{
|
||||||
Transform l_target = new GameObject(p_name).transform;
|
Transform l_target = new GameObject(p_name).transform;
|
||||||
|
l_target.gameObject.layer = CVRLayers.PlayerClone;
|
||||||
l_target.parent = p_parent;
|
l_target.parent = p_parent;
|
||||||
p_source.CopyGlobal(l_target);
|
p_source.CopyGlobal(l_target);
|
||||||
return l_target;
|
return l_target;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue