示例#1
0
        private void MyAnimatorEvent(string other)
        {
            FAnimatorData dat = null;

            if (mAnimatorEvent.TryGetValue(other, out dat))
            {
                if (mCallEvent != null)
                {
                    mCallEvent(dat);
                }
                dat._SendMsg();
            }
        }
示例#2
0
        //同一帧里添加动画事件,然后播放此动画,会有播放不了动画的bug,解决方案,延迟一帧播放
        private void _AddAnimationEvent(string anmation, float pre, string key, System.Action <FAnimatorData> callBack = null)
        {
            string anmationKey = anmation + "_@_" + key;

            if (!mAnimatorEvent.ContainsKey(anmationKey))
            {
                AnimationClip[] acs = mAni.runtimeAnimatorController.animationClips;
                if (acs != null)
                {
                    for (int i = 0; i < acs.Length; i++)
                    {
                        AnimationClip clip  = acs[i];
                        string        aName = clip.name;

                        anmationKey = anmation == "" ? aName + "_@_" + key : anmationKey;
                        if (anmation == aName || (anmation == "" && !mAnimatorEvent.ContainsKey(anmationKey)))
                        {
                            //if (!mCloneClips.ContainsKey(aName))
                            {
                                AnimationClip  cloneClip = UnityEngine.Object.Instantiate <AnimationClip>(clip);
                                AnimationEvent ae        = new AnimationEvent();
                                ae.time            = pre * cloneClip.length;
                                ae.functionName    = FAniEvent.EVENTNAME;
                                ae.stringParameter = anmationKey;
                                cloneClip.AddEvent(ae);
                                cloneClip.name = aName;
                                AnimatorOverrideController overrideController = new AnimatorOverrideController();
                                overrideController.runtimeAnimatorController = GetEffectiveController(mAni);
                                overrideController[aName]      = cloneClip;
                                mAni.runtimeAnimatorController = overrideController;
                                //mCloneClips[aName] = cloneClip;
                                clip = cloneClip;
                            }

                            FAnimatorData fd = new FAnimatorData(key, aName, pre, callBack);
                            mAnimatorEvent[anmationKey] = fd;
                            if (anmation != "")
                            {
                                break;
                            }
                        }
                    }
                }
            }
        }