Skip to content

动画系统

高凯 edited this page Jan 19, 2018 · 1 revision

简介

一行代码即可使用的动画系统,内置多种动画。

常用参数

animObject 动画对象  
time 动画时间  
isChild 是否影响子节点  
interp 插值类型  
IsIgnoreTimeScale 是否忽略时间缩放  
repeatType 重复类型  
repeatCount 重复次数  
callBack 动画完成回调函数  
parameter 动画完成回调函数传参  

动画类型

LocalPosition,
Position,
LocalScale,
LocalRotate,
Rotate,

Color,
Alpha,

UGUI_Color,
UGUI_Alpha,
UGUI_AnchoredPosition,
UGUI_SizeDetal,

Custom_Vector4,
Custom_Vector3,
Custom_Vector2,
Custom_Float,

Blink,

插值类型

Default,
Linear,
InBack,
OutBack,
InOutBack,
OutInBack,
InQuad,
OutQuad,
InoutQuad,
InCubic,
OutCubic,
InoutCubic,
OutInCubic,
InQuart,
OutQuart,
InOutQuart,
OutInQuart,
InQuint,
OutQuint,
InOutQuint,
OutInQuint,
InSine,
OutSine,
InOutSine,
OutInSine,

InExpo,
OutExpo,
InOutExpo,
OutInExpo,

OutBounce,
InBounce,
InOutBounce,
OutInBounce,

API

AnimSystem

public static AnimData UguiColor(GameObject animObject, Color? from, Color to,  
        float time = 0.5f,  
        float delayTime = 0,  
        InterpType interp = InterpType.Default,  
        bool isChild = true,  
        bool IsIgnoreTimeScale = false,  
        RepeatType repeatType = RepeatType.Once,  
        int repeatCount = -1,  
        AnimCallBack callBack = null, object[] parameter = null)  

动画过度到目标颜色

public static AnimData CustomMethodToFloat(AnimCustomMethodFloat method, float from, float to,  
        float time = 0.5f,  
        float delayTime = 0,  
        InterpType interp = InterpType.Default,  
        bool IsIgnoreTimeScale = false,  
        RepeatType repeatType = RepeatType.Once,  
        int repeatCount = -1,  
        AnimCallBack callBack = null, object[] parameter = null)  

传入一个接受float的函数,以指定的插值变化对该函数进行调用

public static AnimData BezierMove(GameObject animObject, Vector3? from, Vector3 to,  
        Vector3[] bezier_contral,  
        float time = 0.5f,  
        float delayTime = 0,  
        RepeatType repeatType = RepeatType.Once,  
        int repeatCount = -1,  
        InterpType interp = InterpType.Default,  
        bool isLocal = true,  
        PathType bezierMoveType = PathType.Bezier2,  
        AnimCallBack callBack = null, object[] parameter = null)  

传入贝塞尔控制点,对目标对象进行曲线移动

public static AnimData BezierMove(GameObject animObject, Vector3? from, Vector3 to, float time,
        float[] bezierContralRadius,  
        RepeatType repeatType,  
        int repeatCount = -1,  
        float delayTime = 0,  
        InterpType interp = InterpType.Default,  
        bool isLocal = true,  
        PathType bezierMoveType = PathType.Bezier2,  
        AnimCallBack callBack = null, object[] parameter = null)

传入贝塞尔控制点随机半径,对目标对象进行随机曲线移动

public static void ClearAllAnim(bool isCallBack = false) 停止所有动画,可选择是否触发回调
public static void StopAnim(AnimData animData, bool isCallBack = false) 停止一个动画,可选择是否触发回调
public static void StopAnim(GameObject animGameObject, bool isCallBack = false) 停止一个物体上的所有动画,可选择是否触发回调

示例

AnimSystem.UguiMove(m_uiRoot, new Vector3(-2000, 0, 0), Vector3.zero, interp: InterpType.OutExpo);

AnimSystem.UguiAlpha(gameObject, 0, 1, callBack:(object[] obj)=>
{
    StartCoroutine(base.EnterAnim(l_animComplete, l_callBack, objs));
});    
   
public void SetCharacterColor(Vector3 value)
{
    for (int i = 0; i < oldMaterials.Count; i++)
    {
       for (int j = 0; j < oldMaterials[i].Length; j++)
       {
           oldMaterials[i][j].color = new Color(value.x, value.y, value.z, 1);
       }
    }
}

public void SetRevort()
{
     AnimSystem.StopAnim(gameObject);

     AnimSystem.CustomMethodToVector3(SetCharacterColor, new Vector3(1, 0.2f, 0.2f), new Vector3(0.5f, 0.5f, 0.5f), time: 0.2f);
}
Clone this wiki locally