summaryrefslogtreecommitdiff
path: root/VRCSDK3Avatars/Assets/Resources/GestureManager/Scripts/GestureManager.cs
diff options
context:
space:
mode:
authorFreya Murphy <freya@freyacat.org>2024-12-27 00:56:58 -0500
committerFreya Murphy <freya@freyacat.org>2024-12-27 00:58:02 -0500
commit799e6680d40119dc9c2a9e0b320054a40324bebe (patch)
treedbcd308d59eb6e4f937a5547dd77d9f91d4fec20 /VRCSDK3Avatars/Assets/Resources/GestureManager/Scripts/GestureManager.cs
parentmove to self host (diff)
downloadunityprojects-799e6680d40119dc9c2a9e0b320054a40324bebe.tar.gz
unityprojects-799e6680d40119dc9c2a9e0b320054a40324bebe.tar.bz2
unityprojects-799e6680d40119dc9c2a9e0b320054a40324bebe.zip
VRCSDK3Avatars found!
Diffstat (limited to 'VRCSDK3Avatars/Assets/Resources/GestureManager/Scripts/GestureManager.cs')
-rw-r--r--VRCSDK3Avatars/Assets/Resources/GestureManager/Scripts/GestureManager.cs97
1 files changed, 97 insertions, 0 deletions
diff --git a/VRCSDK3Avatars/Assets/Resources/GestureManager/Scripts/GestureManager.cs b/VRCSDK3Avatars/Assets/Resources/GestureManager/Scripts/GestureManager.cs
new file mode 100644
index 00000000..a62ba95a
--- /dev/null
+++ b/VRCSDK3Avatars/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