Advertisement
baroquedub

DoTween sequence query

Apr 28th, 2022
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.77 KB | None | 0 0
  1. using UnityEngine;
  2. using DG.Tweening;
  3. using RootMotion.FinalIK;
  4.  
  5. namespace jdp{
  6. public class LookAtIKTweenTest : MonoBehaviour
  7. {
  8.     [SerializeField] LookAtIK m_lookAtIK;
  9.    
  10.     [SerializeField] float defaultWeight = 0.68f;
  11.     [SerializeField] float defaultFadeTime = 1f;
  12.  
  13.     Sequence cacheStareSequence;
  14.  
  15.     void Start(){
  16.         cacheStareSequence = DOTween.Sequence();
  17.             cacheStareSequence.Pause();
  18.             cacheStareSequence.Append(DoFadeWeight(1f, defaultFadeTime))
  19.                                 .AppendInterval(1f)
  20.                                 .Append(DoFadeWeight(defaultWeight, defaultFadeTime));
  21.     }
  22.  
  23.     public void StareNotWorking(){
  24.         cacheStareSequence.Restart();
  25.     }
  26.  
  27.     public void StareNotWorkingEither(){
  28.        
  29.         Sequence stareSequence = DOTween.Sequence();
  30.         stareSequence.Pause();
  31.         stareSequence.Append(DoFadeWeight(1f, defaultFadeTime))
  32.                         .AppendInterval(1f)
  33.                         .Append(DoFadeWeight(defaultWeight, defaultFadeTime));
  34.         stareSequence.Play();
  35.  
  36.     }
  37.  
  38. //Working but hacky
  39.     public void StareWorking(){
  40.        
  41.         DoFadeWeight(1f, defaultFadeTime).OnComplete(() => {
  42.             Invoke("TurnOnLookIK", 0.75f);
  43.         });
  44.  
  45.     }
  46.  
  47.     public void TurnOnLookIK(){
  48.          DoFadeWeight(defaultWeight, defaultFadeTime);
  49.     }
  50.  
  51.  
  52.     private Tween DoFadeWeight(float finalValue, float duration) {
  53.         Tween tween = null;
  54.  
  55.             float val = m_lookAtIK.solver.GetIKPositionWeight(); // get initial value
  56.             Debug.Log("val: " + val);
  57.             tween = DOTween.To (() => val, x => val = x, finalValue, duration).OnUpdate (() => {
  58.                 m_lookAtIK.solver.SetLookAtWeight(val);
  59.             });
  60.  
  61.         return tween;
  62.     }
  63.     }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement