Scale To Snap ActionClip

Slate Forums Custom Clips Scale To Snap ActionClip

This topic contains 0 replies, has 1 voice, and was last updated by  itsallgoodgames 1 year ago.

Viewing 1 post (of 1 total)
  • Author
    Posts
  • #1366

    itsallgoodgames
    Participant
    using UnityEngine;
    using Slate;
    using Slate.ActionClips;
    
    [Category("Transform")]
    [Description("IMPORTANT stepRate <= length \n RECOMMENDED length/stepRate = whole number \n 5sec/1rate = 5 steps + 1 = 6")]
    public class ScaleToSnap : ActorActionClip {
    
    	[SerializeField] [HideInInspector]
    	private float _length = 1;
    
    	public Vector3 targetScale;
    	[Min(0)]
    	public float stepRate = 1f;
    
    	private Vector3 originalPos;
    
    	public override string info{
    		get {return string.Format("Scale To\n{0}", targetScale);}
    	}
    
    	public override float length{
    		get {return _length;}
    		set {_length = value;}
    	}
    
    	public override float blendIn{
    		get {return length;}
    	}
    
    	protected override void OnEnter(){
    		originalPos = actor.transform.localScale;
    	}
    
    	protected override void OnUpdate(float deltaTime){
    		int steps = (int)(length / stepRate);
    		Vector3 stepLength = (targetScale - originalPos) / (steps+1);
    		int currentStep = (int)((deltaTime * (steps)) / (length));
    		Vector3 pos = originalPos + (stepLength * (currentStep+1));
    		if (length == 0){
    			actor.transform.localScale = targetScale;
    			return;
    		}
    		actor.transform.localScale = pos;
    	}
    
    	protected override void OnReverse(){
    		actor.transform.localScale = originalPos;
    	}
    }
    
Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.