From eb84bb298d2b95aec7b2ae12cbf25ac64f25379a Mon Sep 17 00:00:00 2001 From: tylermurphy534 Date: Sun, 6 Nov 2022 15:12:42 -0500 Subject: move to self host --- .../GestureManager/Scripts/GestureManager.cs | 97 ++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 VRCSDK3AvatarsQuest/Assets/Resources/GestureManager/Scripts/GestureManager.cs (limited to 'VRCSDK3AvatarsQuest/Assets/Resources/GestureManager/Scripts/GestureManager.cs') 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 ControlledAvatars = new Dictionary(); + public static bool InWebClientRequest; + + private TransformData _managerTransform; + private Animator _customAnimator; + private Transform _beforeEmote; + private bool _drag; + + public List LastCheckedActiveModules = new List(); + 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 -- cgit v1.2.3-freya