Exemplo n.º 1
0
        /// <summary>
        /// 注册时间轴事件
        /// </summary>
        /// <param name="name">Name.</param>
        /// <param name="time">Time.</param>
        /// <param name="handler">Handler.</param>
        public void RegisterAnimationEventCallback(string name, float time, AnimationTimeLineDelegate handler)
        {
            Animator animator = this.GetComponent <Animator> ();

            if (animator == null)
            {
                return;
            }

            RuntimeAnimatorController controller = animator.runtimeAnimatorController;

            for (int i = 0; i < controller.animationClips.Length; i++)
            {
                AnimationClip clip = controller.animationClips [i];
                if (clip.name != name)
                {
                    continue;
                }

                TimeLineCallBack callback = new TimeLineCallBack();
                callback.Handler      = handler;
                callback.Name         = name;
                callback.Time         = time;
                callback.EndAnimation = false;

                AnimationEvent animationEvent = new AnimationEvent();
                animationEvent.time                     = time;
                animationEvent.functionName             = "OnTimeLineEvent";
                animationEvent.objectReferenceParameter = callback as Object;
                clip.AddEvent(animationEvent);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 时间轴回调事件
        /// </summary>
        /// <param name="obj">Object.</param>
        void OnTimeLineEvent(Object obj)
        {
            if (obj == null)
            {
                return;
            }
            TimeLineCallBack callback = obj as TimeLineCallBack;

            if (callback != null && callback.Handler != null)
            {
                callback.Handler(callback.Name, callback.Time, callback.EndAnimation);
            }
        }