Ejemplo n.º 1
0
    //返回值:是否回退了时间(若下一帧需要停留在事件上,则需要回退一段时间。)
    static bool TriggerEvent(PlayInfo playInfo, IM.Number deltaTime, PlayerActionEventHandler handler)
    {
        System.Type          type   = handler.GetType();
        List <AnimEventData> events = GetAnimEvent(playInfo.animData.eventDatas,
                                                   playInfo.realTime - deltaTime * playInfo.speed, playInfo.realTime);

        foreach (AnimEventData evt in events)
        {
            MethodInfo method = type.GetMethod(evt.funcName);
            if (method != null)
            {
                IM.Number prevSpeed = playInfo.speed;   //处理事件前,动画速度
                //组织事件参数
                ParameterInfo[] parameters = method.GetParameters();
                if (parameters.Length == 0)
                {
                    method.Invoke(handler, null);
                }
                else
                {
                    object[] objs = new object[parameters.Length];
                    for (int i = 0; i < parameters.Length; ++i)
                    {
                        ParameterInfo info = parameters[i];
                        if (info.ParameterType == typeof(string))
                        {
                            objs[i] = evt.stringParameter;
                        }
                        else if (info.ParameterType == typeof(int))
                        {
                            objs[i] = evt.intParameter;
                        }
                        else if (info.ParameterType == typeof(IM.Number))
                        {
                            objs[i] = evt.floatParameter;
                        }
                    }
                    method.Invoke(handler, objs);
                }
                IM.Number curSpeed = playInfo.speed; //处理事件后,动画速度

                if (curSpeed != prevSpeed)           // 事件处理中改变了播放速度
                {
                    IM.Number prevSign = (prevSpeed == IM.Number.zero ? IM.Number.zero : IM.Math.Sign(prevSpeed));
                    IM.Number curSign  = (curSpeed == IM.Number.zero ? IM.Number.zero : IM.Math.Sign(curSpeed));
                    if (prevSign != curSign)    // 动画播放被停止或反向,下一帧停在该事件上,且不再处理后续事件
                    {
                        //计算回退时间
                        //TODO 考虑Wrap的情况
                        IM.Number reverseTime = playInfo.realTime - evt.time;
                        playInfo.time -= reverseTime;
                        return(true);
                    }
                }
            }
        }
        return(false);
    }
Ejemplo n.º 2
0
 public AnimationManager(Animation animation, PlayerActionEventHandler eventHandler)
 {
     _eventHandler = eventHandler;
     _animation    = animation;
 }
Ejemplo n.º 3
0
 public AnimationManager(Player player)
 {
     _player       = player;
     _eventHandler = player.eventHandler;
     _animation    = player.gameObject.GetComponent <Animation>();
 }