56 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			C#
		
	
	
	
		
		
			
		
	
	
			56 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			C#
		
	
	
	
|  | using UnityEngine; | |||
|  | using System; | |||
|  | 
 | |||
|  | public enum EasingType{ | |||
|  |     Linear, | |||
|  |     Smooth, | |||
|  | } | |||
|  | 
 | |||
|  | public abstract class SomethingTo : MonoBehaviour { | |||
|  | 
 | |||
|  | 
 | |||
|  |     private float lerp = 1.0f; | |||
|  |     private float speed = 1.0f; | |||
|  |     protected Action<float> update = ActionExtensions.EmptyActionFloat; | |||
|  |     protected Action callback = ActionExtensions.EmptyAction; | |||
|  | 
 | |||
|  |     protected void Begin(Action<float>update, float interval, Action callback, EasingType easingType = EasingType.Linear){ | |||
|  |         SetUpdate(update, easingType); | |||
|  |         this.callback = callback; | |||
|  |         speed = 1.0f / interval; | |||
|  |         lerp = 0.0f; | |||
|  |     } | |||
|  |      | |||
|  |     private void SetUpdate(Action<float>update, EasingType easingType){ | |||
|  |         switch(easingType){ | |||
|  |         case EasingType.Smooth: | |||
|  |             this.update = lerp => { | |||
|  |                 update(AnimationCurveExtensions.Smooth01.Evaluate(lerp)); | |||
|  |             }; | |||
|  |             break; | |||
|  |         default: | |||
|  |             this.update = update; | |||
|  |             break; | |||
|  |         } | |||
|  |     } | |||
|  |      | |||
|  |     public void Stop(){ | |||
|  |         lerp = 1.0f; | |||
|  | //        update(lerp); | |||
|  | //        callback(); | |||
|  |     } | |||
|  | 
 | |||
|  |     void Update(){ | |||
|  |         if(lerp < 1.0f){ | |||
|  |             lerp += Time.deltaTime * speed; | |||
|  |             if(lerp >= 1.0f){ | |||
|  |                 lerp = 1.0f; | |||
|  |                 update(lerp); | |||
|  |                 callback(); | |||
|  |             }else{ | |||
|  |                 update(lerp); | |||
|  |             } | |||
|  |         } | |||
|  |     } | |||
|  | } |