Beispiel #1
0
    private NEffect GetEffect(EffectInfo effectInfo)
    {
        NEffect nEffect = null;

        effectLsit.TryGetValue(effectInfo.Index, out nEffect);
        if (nEffect == null)
        {
            nEffect = new NEffect();
            effectLsit.Add(effectInfo.Index, nEffect);
            nEffectCache.Add(nEffect);
        }
        nEffect.Init(effectInfo.EffectName, effectInfo.EffectName, effectInfo.SoundName, effectInfo.SoundPlayDelayTime, effectInfo.IsLoop);
        return(nEffect);
    }
Beispiel #2
0
    public void Play(Vector3 bPosition, Vector3 tPosition, float flySpeed, string effectABName, string effectName, string audioClipName = "", float delayTime = 0f)
    {
        targetPosition = tPosition;
        bullet         = new NEffect();
        bullet.Init(effectABName, effectName, audioClipName, delayTime, true);
        GameObject go = bullet.GetEffect();

        go.transform.SetParent(null);
        go.transform.position = bPosition;
        go.tag = GameObjectTags.Bullet;
        CapsuleCollider capsuleCollider = go.GetComponent <CapsuleCollider>();

        if (capsuleCollider == null)
        {
            capsuleCollider = go.AddComponent <CapsuleCollider>();
        }
        capsuleCollider.isTrigger = true;

        Rigidbody rigidbody = go.GetComponent <Rigidbody>();

        if (rigidbody == null)
        {
            rigidbody = go.AddComponent <Rigidbody>();
        }
        rigidbody.useGravity = false;


        coliderCheackHandler = go.GetComponent <ColiderCheackHandler>();
        if (coliderCheackHandler == null)
        {
            coliderCheackHandler = go.AddComponent <ColiderCheackHandler>();
        }
        coliderCheackHandler.ColliderCallBack = OnCollider;

        bullet.Play();
        float distance = Vector3.Distance(bPosition, tPosition);


        float duration = distance / flySpeed;

        tween = go.transform.DOMove(targetPosition, duration);

        //Vector3[] path = new Vector3[2];
        //path[0] = (bPosition + targetPosition) * 0.5f;
        //path[0].y += 3f;
        //path[1] = targetPosition;
        //tween = go.transform.DOPath(path, duration, PathType.Linear);
        tween.OnComplete(OnCompleteHandler);
    }
Beispiel #3
0
 public override void Destroy()
 {
     TimerManager.RemoveHandler(timerInfo);
     timerInfo = null;
     for (int i = 0; i < nEffectCache.Count; ++i)
     {
         NEffect nEffect = nEffectCache[i];
         nEffect.Stop();
     }
     nEffectCache.Clear();
     effectLsit.Clear();
     if (FSM != null)
     {
         FSM.Destroy();
         FSM = null;
     }
     base.Destroy();
 }
Beispiel #4
0
    //public Transform GetChild(string cn)
    //{
    //    if (Model == null)
    //    {
    //        return null;
    //    }
    //    if (Model.Container == null)
    //    {
    //        return null;
    //    }
    //    return Model.GetChild(cn);
    //}

    //public void AddChild(GameObject child, string bonen, bool destroyOldChild = false)
    //{
    //    if (Model != null)
    //    {
    //        Model.AddChild(child, bonen, destroyOldChild);
    //    }
    //}

    public void StopOldActionEffect(string actionName)
    {
        ActionInfo actionInfo = characterConfigInfo.GetActionInfo(actionName);

        if (actionInfo == null)
        {
            return;
        }
        for (int i = 0; i < actionInfo.ActionEffectInfos.Count; ++i)
        {
            EffectInfo effectInfo = actionInfo.ActionEffectInfos[i];
            NEffect    nEffect    = null;
            effectLsit.TryGetValue(effectInfo.Index, out nEffect);
            if (nEffect != null)
            {
                nEffect.Stop();
            }
        }
    }
Beispiel #5
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();
                }
            }
        }
    }