123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- using UnityEngine;
- using System.Collections;
- namespace RootMotion.FinalIK {
-
-
-
- public abstract class OffsetModifierVRIK: MonoBehaviour {
- [Tooltip("The master weight")]
- public float weight = 1f;
- [Tooltip("Reference to the VRIK component")]
- public VRIK ik;
-
- protected float deltaTime { get { return Time.time - lastTime; }}
- protected abstract void OnModifyOffset();
- private float lastTime;
- protected virtual void Start() {
- StartCoroutine(Initiate());
- }
-
- private IEnumerator Initiate() {
- while (ik == null) yield return null;
-
- ik.solver.OnPreUpdate += ModifyOffset;
- lastTime = Time.time;
- }
-
- private void ModifyOffset() {
- if (!enabled) return;
- if (weight <= 0f) return;
- if (deltaTime <= 0f) return;
- if (ik == null) return;
- weight = Mathf.Clamp(weight, 0f, 1f);
- OnModifyOffset();
- lastTime = Time.time;
- }
-
- protected virtual void OnDestroy() {
- if (ik != null) ik.solver.OnPreUpdate -= ModifyOffset;
- }
- }
- }
|