Пример #1
0
    public void PlayAnimation(string actionName, bool isClearOldActionInfo = true, Action hitHandler = null, Action endHandler = null)
    {
        if (currentActionName == actionName)
        {
            return;
        }
        StopActionSound();
        if (isClearOldActionInfo)
        {
            StopOldActionEffect(currentActionName);
        }
        TimerManager.RemoveHandler(timerInfo);
        timerInfo          = null;
        OnActionEndHandler = null;
        if (Model != null && characterConfigInfo != null)
        {
            currentActionName = actionName;
            currentActionInfo = characterConfigInfo.GetActionInfo(currentActionName);
            if (currentActionInfo != null)
            {
                bool loop = AnimationType.IsLoopAction(currentActionName);
                if (currentActionInfo.SelfMoveTime > 0f && currentActionInfo.SelfMoveDistance > 0f && currentActionInfo.IsLoop)
                {
                    OnActionEndHandler = endHandler;
                    timerInfo          = TimerManager.AddDelayHandler(OnEndHandler, currentActionInfo.SelfMoveDelayTime + currentActionInfo.SelfMoveTime, 1);
                    Model.PlayAnimation(currentActionName, currentActionInfo.PlaySpeed, hitHandler, null);
                }
                else
                {
                    Model.PlayAnimation(currentActionName, currentActionInfo.PlaySpeed, hitHandler, endHandler);
                }
                PlayActionSound(currentActionInfo.SoundName, loop, (ulong)currentActionInfo.SoundPlayDelayTime);
                for (int i = 0; i < currentActionInfo.ActionEffectInfos.Count; ++i)
                {
                    EffectInfo effectInfo = currentActionInfo.ActionEffectInfos[i];
                    if (effectInfo.EffectType == EffectTypes.Bullet)
                    {
                        continue;
                    }
                    if (effectInfo.EffectType == EffectTypes.Normal && effectInfo.BindType == BindTypes.Bone && (effectInfo.BindName == BindTypes.NONE || string.IsNullOrEmpty(effectInfo.BindName)))
                    {
                        continue;
                    }

                    NEffect    nEffect = GetEffect(effectInfo);
                    GameObject effect  = nEffect.GetEffect();
                    if (effect == null)
                    {
                        continue;
                    }
                    if (effectInfo.BindType == BindTypes.OrginePoint)
                    {
                        //自身同坐标,且随自身一起移动
                        if (Container != null)
                        {
                            effect.transform.SetParent(Container.transform);
                            effect.transform.localPosition = Vector3.zero;
                            effect.transform.localScale    = Vector3.one;
                            effect.transform.localRotation = Quaternion.identity;
                        }
                    }
                    else if (effectInfo.BindType == BindTypes.Self_Point)
                    {
                        //自身同坐标,且不随自身一起移动
                        if (Container != null)
                        {
                            effect.transform.SetParent(null);
                            effect.transform.localPosition = Vector3.zero;
                            effect.transform.localScale    = Vector3.one;
                            effect.transform.localRotation = Quaternion.identity;
                            effect.transform.position      = GetPosition();
                            effect.transform.eulerAngles   = new Vector3(0f, Container.transform.eulerAngles.y, 0f);
                        }
                    }
                    else if (effectInfo.BindType == BindTypes.Bone)
                    {
                        //绑骨骼
                        Transform bone = Model.GetChild(effectInfo.BindName);
                        if (bone != null)
                        {
                            effect.transform.SetParent(bone);
                            effect.transform.localPosition = Vector3.zero;
                            effect.transform.localScale    = Vector3.one;
                            effect.transform.localRotation = Quaternion.identity;
                        }
                    }
                    nEffect.Play();
                }
            }
        }
    }