/// <summary> /// Animate the specified property value between 0 and 1 /// </summary> /// <param name="objref"></param> /// <param name="material"></param> /// <param name="property"></param> /// <param name="animType"></param> /// <param name="duration"></param> /// <param name="direction"></param> /// <param name="loop"></param> /// <returns></returns> public AnimationBeing CreateMaterialAnimation(GameObject objRef, Material material, string property, AnimationType animType, float duration, int direction = 1, bool loop = false) { AnimationBeingTargetField t = new AnimationBeingTargetField(); t.SetMaterial(material); System.Action <GameObject, AnimationBeingTargetField, float> func = null; func = (GameObject obj, AnimationBeingTargetField field, float alpha) => { //Vector3 res = t.GetAnimationVectorStruct().initial * (1 - alpha) + t.GetAnimationVectorStruct().target * alpha; material.SetFloat(property, alpha); //Debug.Log(res); }; //animation being creation AnimationBeing being = new AnimationBeing(objRef, func, duration, direction); being.SetLoop(loop); being.CreateAnimationBeingTargetAndInitializeDefaultValue(t.getMaterial()); switch (animType) { case AnimationType.Parallel: Debug.Log("Created"); animationBeingsParallel.Add(being); break; case AnimationType.Serial: animationBeingsSequence.Add(being); break; } return(being); }
public AnimationBeing CreateScaleAnim(GameObject objRef, Vector3 initial, Vector3 target, AnimationType animType, float duration, int direction, bool loop = false) { AnimationBeingTargetField t = new AnimationBeingTargetField(); t.SetAnimationVectorStruct(new AnimationVectorStuct(initial, target)); System.Action <GameObject, AnimationBeingTargetField, float> func = null; func = (GameObject obj, AnimationBeingTargetField field, float alpha) => { Vector3 res = field.GetAnimationVectorStruct().initial *(1 - alpha) + field.GetAnimationVectorStruct().target *alpha; //Debug.Log(res); obj.transform.localScale = res; }; //animation being creation AnimationBeing being = new AnimationBeing(objRef, func, duration, direction); being.SetLoop(loop); being.CreateAnimationBeingTargetAndInitializeDefaultValue(t.GetAnimationVectorStruct()); switch (animType) { case AnimationType.Parallel: Debug.Log("Created"); animationBeingsParallel.Add(being); break; case AnimationType.Serial: animationBeingsSequence.Add(being); break; } return(being); }
public AnimationBeing CreateRectTransformLocalPositionAnimation(RectTransform rectTransform, Vector3 initial, Vector3 target, AnimationType animType, float duration, int direction = 1, bool loop = false) { AnimationBeingTargetField t = new AnimationBeingTargetField(); t.SetAnimationVectorStruct(new AnimationVectorStuct(initial, target)); System.Action <GameObject, AnimationBeingTargetField, float> func = null; func = (GameObject obj, AnimationBeingTargetField field, float alpha) => { //Vector3 res = t.GetAnimationVectorStruct().initial * (1 - alpha) + t.GetAnimationVectorStruct().target * alpha; obj.GetComponent <RectTransform>().localPosition = field.GetAnimationVectorStruct().initial *(1 - alpha) + field.GetAnimationVectorStruct().target *alpha; //material.SetFloat(property, alpha); }; //animation being creation AnimationBeing being = new AnimationBeing(rectTransform.gameObject, func, duration, direction); being.SetLoop(loop); being.CreateAnimationBeingTargetAndInitializeDefaultValue(t.GetAnimationVectorStruct()); switch (animType) { case AnimationType.Parallel: Debug.Log("Created"); animationBeingsParallel.Add(being); break; case AnimationType.Serial: animationBeingsSequence.Add(being); break; } return(being); }