Esempio n. 1
0
        /// <summary>
        /// 根据给定信息获得委托
        /// </summary>
        /// <param name="animator"></param>
        /// <param name="clip"></param>
        /// <param name="frame"></param>
        /// <returns></returns>
        public Action <AnimationEvent> GetAction(Animator animator, AnimationClip clip, int frame)
        {
            Action <AnimationEvent> action      = default(Action <AnimationEvent>);
            A_EventInfo             a_EventInfo = eventContainer.Find((v) => { return(v.animator == animator && v.animationClip == clip); });

            if (null != a_EventInfo)
            {
                a_EventInfo.frameCallBackPairs.TryGetValue(frame, out action);
            }
            return(action);
        }
Esempio n. 2
0
        /// <summary>
        /// 获得指定的事件信息类
        /// </summary>
        /// <param name="animator">动画机</param>
        /// <param name="clip">动画片段</param>
        /// <returns>事件信息类</returns>
        private A_EventInfo GetEventInfo(Animator animator, AnimationClip clip)
        {
            A_EventInfo a_EventInfo = eventContainer.Find((v) => { return(v.animator == animator && v.animationClip == clip); });

            if (null == a_EventInfo)
            {
                a_EventInfo = new A_EventInfo(animator, clip);
                eventContainer.Add(a_EventInfo);
            }
            return(a_EventInfo);
        }
Esempio n. 3
0
        /// <summary>
        /// 为事件基础信息进行缓存
        /// </summary>
        /// <param name="animator">动画机</param>
        /// <param name="clipName">动画片段名称</param>
        /// <param name="frame">指定帧</param>
        public A_EventInfo GenerAnimationInfo(Animator animator, string clipName)
        {
            AnimationClip clip = GetAnimationClip(animator, clipName);

            if (null == clip)
            {
                return(null);
            }
            A_EventInfo a_EventInfo = GetEventInfo(animator, clip);  //获取指定事件信息类

            return(a_EventInfo);
        }
Esempio n. 4
0
        public static A_EventConfig_B SetTarget(this Animator animator, string clipName, int frame)
        {
            A_EventInfo a_EventInfo = A_EventHandler.Handler.GenerAnimationInfo(animator, clipName);

            if (null != a_EventInfo)
            {
                if (null == animator.GetComponent <CallbackListener>())
                {
                    animator.gameObject.AddComponent <CallbackListener>();
                }
            }
            //获得需要处理的动画片段
            return(new A_EventConfig_B(a_EventInfo, frame));
        }
Esempio n. 5
0
        /// <summary>
        /// 为指定动画机片段插入回调方法
        /// </summary>
        /// <param name="eventInfo">回调信息类</param>
        /// <param name="frame">指定帧</param>
        /// <param name="func">方法名</param>
        public void GenerAnimationEvent(A_EventInfo eventInfo, int frame)
        {
            if (frame < 0 || frame > eventInfo.totalFrames)
            {
                Debug.LogErrorFormat("AnimatorEventSystem[紧急]:【{0}】所在的动画机【{1}】片段帧数设置错误【{2}】!", eventInfo.animator.name, eventInfo.animationClip.name, frame);
                return;
            }
            float _time = frame / eventInfo.animationClip.frameRate;

            AnimationEvent[] events   = eventInfo.animationClip.events;
            AnimationEvent   varEvent = Array.Find(events, (v) => { return(v.time == _time); });

            if (null != varEvent)
            {
                if (varEvent.functionName == func)
                {
                    Debug.LogWarningFormat("AnimatorEventSystem[一般]:【{0}】所在的动画机【{1}】片段【{2}】帧已存在回调方法,无需重复添加!", eventInfo.animator.name, eventInfo.animationClip.name, frame);
                    if (!eventInfo.frameEventPairs.ContainsKey(frame))
                    {
                        eventInfo.frameEventPairs.Add(frame, varEvent);
                    }
                    return;
                }
                else
                {
                    Debug.LogWarningFormat("AnimatorEventSystem[一般]:【{0}】所在的动画机【{1}】片段【{2}】帧已存在回调方法【{3}】,将自动覆盖!", eventInfo.animator.name, eventInfo.animationClip.name, frame, varEvent.functionName);
                }
            }
            AnimationEvent a_event = new AnimationEvent                  //创建事件对象
            {
                functionName   = func,                                   //指定事件的函数名称
                time           = _time,                                  //对应动画指定帧处触发
                messageOptions = SendMessageOptions.DontRequireReceiver, //回调未找到不提示
            };

            eventInfo.animationClip.AddEvent(a_event); //绑定事件
            eventInfo.frameEventPairs.Add(frame, a_event);
            eventInfo.animator.Rebind();               //重新绑定动画器的所有动画的属性和网格数据。
        }
 public BaseEventConfig(A_EventInfo eventInfo, int frame)
 {
     _keyFrame = frame;
     a_Event   = eventInfo;
     _animator = eventInfo.animator;
 }
Esempio n. 7
0
 public A_EventConfig_B(A_EventInfo eventInfo, int frame) : base(eventInfo, frame)
 {
 }
Esempio n. 8
0
 public A_EventConfig_A(A_EventInfo eventInfo, int frame = -1) : base(eventInfo, frame)
 {
 }