diff options
author | tylermurphy534 <tylermurphy534@gmail.com> | 2022-11-06 15:12:42 -0500 |
---|---|---|
committer | tylermurphy534 <tylermurphy534@gmail.com> | 2022-11-06 15:12:42 -0500 |
commit | eb84bb298d2b95aec7b2ae12cbf25ac64f25379a (patch) | |
tree | efd616a157df06ab661c6d56651853431ac6b08b /VRCSDK3AvatarsQuest/Assets/Resources/GestureManager/Scripts/GestureManager.cs | |
download | unityprojects-eb84bb298d2b95aec7b2ae12cbf25ac64f25379a.tar.gz unityprojects-eb84bb298d2b95aec7b2ae12cbf25ac64f25379a.tar.bz2 unityprojects-eb84bb298d2b95aec7b2ae12cbf25ac64f25379a.zip |
move to self host
Diffstat (limited to '')
-rw-r--r-- | VRCSDK3AvatarsQuest/Assets/Resources/GestureManager/Scripts/GestureManager.cs | 97 | ||||
-rw-r--r-- | VRCSDK3AvatarsQuest/Assets/Resources/GestureManager/Scripts/GestureManager.cs.meta | 11 |
2 files changed, 108 insertions, 0 deletions
diff --git a/VRCSDK3AvatarsQuest/Assets/Resources/GestureManager/Scripts/GestureManager.cs b/VRCSDK3AvatarsQuest/Assets/Resources/GestureManager/Scripts/GestureManager.cs new file mode 100644 index 00000000..a62ba95a --- /dev/null +++ b/VRCSDK3AvatarsQuest/Assets/Resources/GestureManager/Scripts/GestureManager.cs @@ -0,0 +1,97 @@ +using System.Collections.Generic; +using GestureManager.Scripts.Extra; +using UnityEngine; + +namespace GestureManager.Scripts +{ + public class GestureManager : MonoBehaviour + { + public static readonly Dictionary<GameObject, ModuleBase> ControlledAvatars = new Dictionary<GameObject, ModuleBase>(); + public static bool InWebClientRequest; + + private TransformData _managerTransform; + private Animator _customAnimator; + private Transform _beforeEmote; + private bool _drag; + + public List<ModuleBase> LastCheckedActiveModules = new List<ModuleBase>(); + public ModuleBase Module; + + public bool OnCustomAnimation { get; private set; } + public AnimationClip customAnim; + + private void OnDisable() => UnlinkModule(); + + private void Update() + { + if (Module == null) return; + if (Module.IsInvalid()) UnlinkModule(); + else ModuleUpdate(); + } + + private void ModuleUpdate() + { + if (_drag) _managerTransform.Difference(transform).AddTo(Module.Avatar.transform); + _managerTransform = new TransformData(transform); + Module.Update(); + } + + private void LateUpdate() + { + _managerTransform = new TransformData(transform); + Module?.LateUpdate(); + } + + public void SetDrag(bool drag) => _drag = drag; + + public void UnlinkModule() => SetModule(null); + + public void SetModule(ModuleBase module) + { + Module?.Unlink(); + if (Module != null) ControlledAvatars.Remove(Module.Avatar); + + Module = module; + Module?.Avatar.transform.ApplyTo(transform); + if (Module == null) return; + + Module.InitForAvatar(); + ControlledAvatars[module.Avatar] = module; + } + + private void SaveCurrentStartEmotePosition() => _beforeEmote = _customAnimator.gameObject.transform; + + private void RevertToEmotePosition() => _beforeEmote.ApplyTo(_customAnimator.gameObject.transform); + + public void SetCustomAnimation(AnimationClip clip) + { + if (!OnCustomAnimation) customAnim = clip; + else if (!clip) StopCustomAnimation(); + else PlayCustomAnimation(clip); + } + + /* + * Events + */ + + public void PlayCustomAnimation(AnimationClip clip) + { + if (OnCustomAnimation) RevertToEmotePosition(); + customAnim = clip; + OnCustomAnimation = true; + _customAnimator = Module.OnCustomAnimationPlay(customAnim); + SaveCurrentStartEmotePosition(); + _customAnimator.applyRootMotion = true; + } + + public void StopCustomAnimation() + { + OnCustomAnimation = false; + SetCustomAnimation(null); + _customAnimator = Module.OnCustomAnimationPlay(null); + if (!_customAnimator) return; + RevertToEmotePosition(); + _customAnimator.applyRootMotion = false; + } + } +}
\ No newline at end of file diff --git a/VRCSDK3AvatarsQuest/Assets/Resources/GestureManager/Scripts/GestureManager.cs.meta b/VRCSDK3AvatarsQuest/Assets/Resources/GestureManager/Scripts/GestureManager.cs.meta new file mode 100644 index 00000000..cb0933c9 --- /dev/null +++ b/VRCSDK3AvatarsQuest/Assets/Resources/GestureManager/Scripts/GestureManager.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 2398979b1d0d84349abc5ee9f0571350 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: |