public void ClearSingleCache(int ID)
    {
        if (!isValid)
        {
            return;
        }
        RemovePreWarmEffectQueue(ID);
        if (m_behaviorCacheTable.ContainsKey(ID))
        {
            m_behaviorCacheTable.Remove(ID);
        }

        LinkedList <LightingEffectBehavior> list;

        if (m_allBehaviorTable.TryGetValue(ID, out list))
        {
            foreach (LightingEffectBehavior bev in list)
            {
                LightingEffectBehavior temp = bev;
                DestroyBehavior(ref temp);
            }

            m_allBehaviorTable.Remove(ID);
        }
    }
예제 #2
0
    public override bool Begin()
    {
        if (!cameraConfig || null == EffectParam)
        {
            return(false);
        }
        base.Begin();
        uint tick = GameLogicAPI.getTickCount();

        mStartTick = tick;
        mEndTick   = mStartTick + (uint)cameraConfig.effectLiveTick + (uint)cameraConfig.delayTick;
        if (cameraConfig.effectRad > 0.01f && EntityFactory.MainHero)
        {
            Vector3 deta = EffectParam.targetPos - EntityFactory.MainHero.transform.position;
            if (deta.magnitude > cameraConfig.effectRad)
            {
                //创建失败,要进行回收,要不然缓存无法更新
                LightingEffectBehavior temp = this;
                LightingEffectFactory.Instance.CacheEffectBehavior(ref temp);
                return(false);
            }
        }

        bStartEffect = true;
        return(true);
    }
    private void RemoveFromEntityEffectTable(LightingEffectBehavior instance)
    {
        if (!isValid)
        {
            return;
        }
        if (ClosedOptimiezed)
        {
            return;
        }
        if (null == instance)
        {
            return;
        }
        if (null == instance.EffectConfig || null == instance.EffectParam)
        {
            return;
        }

        int effectID = instance.getID();

        if (effectID <= 0)
        {
            return;
        }
        LightEffectParam param = instance.EffectParam;

        //是single类型的,梁成说必须要创建
        if (instance.EffectConfig.bSingle)
        {
            return;
        }
        //只对绑定光效作这个效果
        if (instance.EffectConfig.GetEffectType() != LightingEffectConfigType.Bind)
        {
            return;
        }

        int entityID = param.nSrcEntityID;
        Dictionary <int, List <LightingEffectBehavior> > tables = null;
        List <LightingEffectBehavior> list = null;

        //已经有这个ID了
        if (m_EntityBindEffectHostID.TryGetValue(entityID, out tables))
        {
            if (tables.TryGetValue(effectID, out list))
            {
                list.Remove(instance);
                if (list.Count <= 0)
                {
                    tables.Remove(effectID);
                }
            }

            if (tables.Count <= 0)
            {
                m_EntityBindEffectHostID.Remove(entityID);
            }
        }
    }
    /// <summary>
    /// 创建光效
    /// </summary>
    /// <param name="nID"></param>
    /// <param name="param"></param>
    /// <returns></returns>
    public LightingEffectBehavior CreateEffect(int nID, LightEffectParam param, bool isFromHero = false)
    {
        if (!isValid)
        {
            return(null);
        }
        if (nID <= 0)
        {
            return(null);
        }
        LightingEffectBehavior reslut = null;
        LightingEffect         config = ASpeedGame.Data.Scheme.SchemeLightingEffect.Instance.GetLightingEffect(nID);

        if (!config)
        {
            Trace.Warning("LightingEffect creates failed. Id " + nID.ToString() + "has not loaded.");
            return(reslut);
        }

        //if(!SceneManager.Instance.isMainCity())
        //{
        //    if (!FirstCachedEffectID.Contains(nID))
        //    {
        //        if (!currentCachedEffectID.Contains(nID))
        //        {
        //            FirstCachedEffectID.Add(nID);
        //            Debug.LogWarning("创建了没有缓存的光效,ID:" + nID);
        //        }
        //    }
        //}

        if (!isCanCreateEffect(config, param))
        {
            return(reslut);
        }
        RemovePreWarmEffectQueue(nID);
        Queue <LightingEffectBehavior> cacheList = null;

        if (!m_behaviorCacheTable.TryGetValue(nID, out cacheList))
        {
            cacheList = new Queue <LightingEffectBehavior>();
            m_behaviorCacheTable.Add(nID, new Queue <LightingEffectBehavior>());
        }

        if (cacheList.Count > 0)
        {
            reslut = cacheList.Dequeue();
            ResetBehavior(reslut);
        }
        else
        {
            reslut = CreateNewBehavior(nID, config.GetEffectType());
        }
        reslut.FillData(config, param, GetResourceHandleAsync(nID, reslut.OnResourcesLoadFinish), AllocBehaviorTransformAgent());
        reslut.SetValid();
        PushToEntityEffectTable(reslut);
        return(reslut);
    }
예제 #5
0
    public override bool Begin()
    {
        if (!speedConfig || null == EffectParam)
        {
            return(false);
        }
        base.Begin();
        //如果在有效距离范围外,则不触发
        Vector3 vec = EffectParam.srcObject.transform.position - EntityFactory.MainHero.transform.position;

        if (vec.magnitude > speedConfig.effectRad)
        {
            //创建失败,要进行回收,要不然缓存无法更新
            LightingEffectBehavior temp = this;
            LightingEffectFactory.Instance.CacheEffectBehavior(ref temp);
            return(false);
        }

        if (EffectParam.srcObject && Initialize.mainCam)
        {
            //距离超过创建距离,不创建光效了。
            //为了保证上帝视角和切换回英雄附近都能正确看到光效,这里同时考虑光效到英雄以及光效到摄像机的距离

            Vector3 p0 = EffectParam.srcObject.transform.position;
            Vector3 p1 = Initialize.mainCam.transform.position;
            Vector3 p2 = Vector3.zero;
            if (EntityFactory.MainHero)
            {
                p2 = EntityFactory.MainHero.transform.position;
            }


            //不要Y
            p0.y = 0;
            p1.y = 0;
            p2.y = 0;

            Vector3 dis1   = p1 - p0;
            Vector3 dis2   = p2 - p0;
            float   disSqr = LightingEffectFactory.CreateDistance * LightingEffectFactory.CreateDistance;

            if (EffectConfig.EnableDistanceOptimtized && (dis1.sqrMagnitude > disSqr) && (dis2.sqrMagnitude > disSqr))
            {
                //创建失败,要进行回收,要不然缓存无法更新
                LightingEffectBehavior temp = this;
                LightingEffectFactory.Instance.CacheEffectBehavior(ref temp);
                return(false);
            }
        }

        uint tick = GameLogicAPI.getTickCount();

        m_startTick = (uint)speedConfig.nStartTick + tick;
        m_endTick   = (uint)speedConfig.nEndTick + tick;
        //m_bStartedEffect = false;
        return(true);
    }
예제 #6
0
    public override bool Begin()
    {
        if (!BindConfig || null == EffectParam)
        {
            return(false);
        }
        base.Begin();

        Camera cam = SoldierCamera.MainInstance().CurrentCamera;

        if (EffectParam.srcObject && cam && Initialize.mainCam)
        {
            //距离超过创建距离,不创建光效了。
            //为了保证上帝视角和切换回英雄附近都能正确看到光效,这里同时考虑光效到英雄以及光效到摄像机的距离

            Vector3 p0 = EffectParam.srcObject.transform.position;
            Vector3 p1 = Initialize.mainCam.transform.position;
            Vector3 p2 = Vector3.zero;
            if (EntityFactory.MainHero)
            {
                p2 = EntityFactory.MainHero.transform.position;
            }


            //不要Y
            p0.y = 0;
            p1.y = 0;
            p2.y = 0;

            Vector3 dis1   = p1 - p0;
            Vector3 dis2   = p2 - p0;
            float   disSqr = LightingEffectFactory.CreateDistance * LightingEffectFactory.CreateDistance;

            if (EffectConfig.EnableDistanceOptimtized && (dis1.sqrMagnitude > disSqr) && (dis2.sqrMagnitude > disSqr))
            {
                //创建失败,要进行回收,要不然缓存无法更新
                LightingEffectBehavior temp = this;
                LightingEffectFactory.Instance.CacheEffectBehavior(ref temp);
                return(false);
            }
        }


        if (EffectParam.speed <= 0.0f)
        {
            EffectParam.speed = 1.0f;
        }
        uint tick = GameLogicAPI.getTickCount();

        mStartTick = tick + (uint)((float)BindConfig.effectStartTick / EffectParam.speed);
        mEndTick   = mStartTick + (uint)((float)BindConfig.effectLiveTick / EffectParam.speed);
        UnRegsiterSkinChangedEvent(EffectParam.nSrcEntityID, OnSkinChanged);
        RegsiterSkinChangedEvent(EffectParam.nSrcEntityID, OnSkinChanged);
        return(true);
    }
    private void PushToEntityEffectTable(LightingEffectBehavior instance)
    {
        if (!isValid)
        {
            return;
        }
        if (ClosedOptimiezed)
        {
            return;
        }
        if (null == instance)
        {
            return;
        }
        //是single类型的,梁成说必须要创建
        if (instance.EffectConfig.bSingle)
        {
            return;
        }
        //只对绑定光效作这个效果
        if (instance.EffectConfig.GetEffectType() != LightingEffectConfigType.Bind)
        {
            return;
        }

        int entityID = instance.EffectParam.nSrcEntityID;

        int effectID = instance.getID();

        if (effectID <= 0)
        {
            return;
        }
        Dictionary <int, List <LightingEffectBehavior> > tables = null;
        List <LightingEffectBehavior> list = null;

        //已经有这个ID了
        if (m_EntityBindEffectHostID.TryGetValue(entityID, out tables))
        {
            if (!tables.TryGetValue(effectID, out list))
            {
                list = new List <LightingEffectBehavior>();
                tables.Add(effectID, list);
            }
            list.Add(instance);
        }
        else
        {
            tables = new Dictionary <int, List <LightingEffectBehavior> >();
            list   = new List <LightingEffectBehavior>();
            list.Add(instance);
            tables.Add(effectID, list);
            m_EntityBindEffectHostID.Add(entityID, tables);
        }
    }
예제 #8
0
    //使用这个接口会返回LightingEffect,可以通过强制转换控制光效的属性
    public static LightingEffectBehavior PlayAndReturnEffect(ref U3D_Render.EntityView ev, int effectID, cmd_creature_skillview cmdInfo)
    {
        //光效开关
        if (!Initialize.Instance || !OptimitzedControlPlane.Instance.EnabledLightingEffect)
        {
            return(null);
        }

        LightEffectParam param = new LightEffectParam();

        param.nFeedbackID     = cmdInfo.nFeedBackID;
        param.bIsHero         = ev.IsHero;
        param.nSrcEntityID    = ev.ID;
        param.nTargetEntityID = cmdInfo.nTargetEntityID;
        param.srcObject       = ev.gameObject;
        if (cmdInfo.nSrcEntityID > 0)
        {
            param.nSrcEntityID = cmdInfo.nSrcEntityID;
            param.srcObject    = EntityFactory.getEntityGameObjectByID(cmdInfo.nSrcEntityID);
        }
        param.fDistance    = cmdInfo.fDistance;
        param.fAttackRange = cmdInfo.fAttackRange;
        param.speed        = cmdInfo.fPASD;
        if (cmdInfo.nTargetEntityID != 0)
        {
            param.targetObject = EntityFactory.getEntityGameObjectByID(cmdInfo.nTargetEntityID);
        }
        param.targetPos = new Vector3(cmdInfo.fTargetPos_x, cmdInfo.fTargetPos_y, cmdInfo.fTargetPos_z);
        param.sourcePos = new Vector3(cmdInfo.fSrcPos_x, cmdInfo.fSrcPos_y, cmdInfo.fSrcPos_z);
        if (cmdInfo.bFromSrcPos != 0)
        {
            param.nEffectFlag |= (int)LightEffectParam.EFFECT_FLAG.CustomSourcePos;
        }
        param.nCreatorSide = cmdInfo.nCreatorSide;

        LightingEffectManager manager = ev.LightingEffectManager;

        if (manager == null)
        {
            return(null);
        }

        // 开始光效
        LightingEffectBehavior eff = manager.AddLighting(effectID, param);

        // 输出光效信息
        if (manager.showLog)
        {
            Trace.Log("Add Lighting" + effectID + ". Entity Id=" + ev.ID + " SrcID=" + param.nSrcEntityID);
            Trace.Log("TargetID=" + cmdInfo.nTargetEntityID + ". TargetPos=(" + cmdInfo.fTargetPos_x + "," + cmdInfo.fTargetPos_y + "," + cmdInfo.fTargetPos_z + ").");
        }

        return(eff);
    }
예제 #9
0
    private void clearEffectImpl()
    {
        if (null == mEffectList)
        {
            return;
        }

        foreach (LightingEffectBehavior effect in mEffectList)
        {
            effect.Close();
            //创建失败,要进行回收,要不然缓存无法更新
            LightingEffectBehavior temp = effect;
            LightingEffectFactory.Instance.CacheEffectBehavior(ref temp);
        }
        mEffectList.Clear();
    }
    void DestroyBehavior(ref LightingEffectBehavior instance)
    {
        if (!isValid)
        {
            return;
        }
        RemoveFromEntityEffectTable(instance);

        LightingEffectResHandleInstance temp = instance.ResourceHandle;

        DeleteResourceHandleAsync(ref temp, instance.OnResourcesLoadFinish);
        DeleteBehaviorTransformAgent(instance.TransformAgent);
        instance.ClearData();
        instance.ResetAllMembers();
        instance.SetInvalid();
        instance = null;
    }
    public override bool Begin()
    {
        if (!aniRepConfig || null == EffectParam)
        {
            return(false);
        }
        base.Begin();
        uint tick = GameLogicAPI.getTickCount();

        m_startTick      = (uint)aniRepConfig.nStartTick + tick;
        m_endTick        = (uint)aniRepConfig.nEndTick + tick;
        m_bStartedEffect = false;
        if (!EffectParam.srcObject)
        {
            //创建失败,要进行回收,要不然缓存无法更新
            LightingEffectBehavior temp = this;
            LightingEffectFactory.Instance.CacheEffectBehavior(ref temp);
            return(false);
        }

        CreatureStateMachine state = GetStateMachine(EffectParam.nSrcEntityID) as CreatureStateMachine;

        if (state == null)
        {
            //创建失败,要进行回收,要不然缓存无法更新
            LightingEffectBehavior temp = this;
            LightingEffectFactory.Instance.CacheEffectBehavior(ref temp);
            return(false);
        }
        animatorCtrl = state.animatorCtrl;
        if (animatorCtrl == null)
        {
            //创建失败,要进行回收,要不然缓存无法更新
            LightingEffectBehavior temp = this;
            LightingEffectFactory.Instance.CacheEffectBehavior(ref temp);
            return(false);
        }
        return(true);
    }
    /// <summary>
    /// 缓存光效配置
    /// </summary>
    /// <param name="effect"></param>
    public void CacheEffectBehavior(ref LightingEffectBehavior behaviorInstance)
    {
        if (!isValid)
        {
            return;
        }
        if (behaviorInstance == null)
        {
            return;
        }

        int ID = behaviorInstance.getID();

        if (ID <= 0)
        {
            return;
        }
        //对于没有在缓存表配置的ID来说,全部采用删除处理,不缓存,因为缓存了之后,主城切换皮肤的时候是不会被删除的,这样会导致越来越多光效遗留
        if (GameLogicAPI.isMainMap(SceneManager.Instance.getCurrentMapId()))
        {
            if (!allCacheID.Contains(ID))
            {
                DestroyBehavior(ref behaviorInstance);
                return;
            }
        }

        Queue <LightingEffectBehavior> list = null;

        if (!m_behaviorCacheTable.TryGetValue(ID, out list))
        {
            list = new Queue <LightingEffectBehavior>();
            m_behaviorCacheTable.Add(ID, list);
        }
        RemoveFromEntityEffectTable(behaviorInstance);
        list.Enqueue(behaviorInstance);
        ResetBehavior(behaviorInstance);
    }
예제 #13
0
    public bool RemoveLightingImmediate(int nID, int nFeedbackID = 0)
    {
        //遍历光效列表,对光效进行更新或关闭操作
        for (int i = 0; i < mEffectList.Count;)
        {
            LightingEffectBehavior effect = mEffectList[i];
            bool bRemove = effect.getID() == nID;
            bRemove = bRemove && (nFeedbackID == 0 || effect.EffectParam.nFeedbackID == nFeedbackID);
            bRemove = bRemove || !effect.Valid;

            if (bRemove)
            {
                effect.Close();
                mEffectList.RemoveAt(i);
                LightingEffectFactory.Instance.CacheEffectBehavior(ref effect);
            }
            else
            {
                i++;
            }
        }
        return(true);
    }
예제 #14
0
    public override bool Begin()
    {
        if (!shadowConfig || null == EffectParam)
        {
            return(false);
        }
        base.Begin();
        if (!AssetBundleManager.EntityAlphaShader)
        {
            //创建失败,要进行回收,要不然缓存无法更新
            LightingEffectBehavior temp = this;
            LightingEffectFactory.Instance.CacheEffectBehavior(ref temp);
            Trace.LogWarning("AssetBundleManager.EntityAlphaShader---实体半透shader为null");
            return(false);
        }

        mStartTick          = GameLogicAPI.getTickCount() + (uint)shadowConfig.nStartTick;
        mEndTick            = mStartTick + (uint)shadowConfig.nEndTick + (uint)shadowConfig.nShadowMaintainTick + (uint)shadowConfig.nShadowFadeoutTick;
        shadowObjectIndex   = 0;
        shadowInstanceLists = new List <ShadowInstance>();
        shadowCount         = 0;
        if (!EffectParam.bIsHero)
        {
            maxShadowCount = 20; //非主角最多画20个

            //计算前进一步所偏移的像素
            Vector3 projectPos     = Initialize.mainCam.WorldToScreenPoint(EffectParam.srcObject.transform.position);
            Vector3 projectStepPos = Initialize.mainCam.WorldToScreenPoint(EffectParam.srcObject.transform.position + EffectParam.srcObject.transform.forward.normalized);
            Vector3 dis            = projectPos - projectStepPos;
            dis.z = 0;

            //间隔5像素画一个
            float drawDis = 5.0f / dis.magnitude;
            shadowConfig.minDistance = Mathf.Max(shadowConfig.minDistance, drawDis);
        }
        return(true);
    }
예제 #15
0
    private bool PreWarmEffect(int nID, int PreWarmCount)
    {
        if (m_allBehaviorTable.ContainsKey(nID))
        {
            //Debug.LogWarning("光效已经加载,不需要缓存,ID:" + nID);
            return(false);
        }
        LightingEffect config = ASpeedGame.Data.Scheme.SchemeLightingEffect.Instance.GetLightingEffect(nID);

        if (!config)
        {
            Debug.LogWarning("光效加载失败,找不到配置,ID:" + nID);
            return(false);
        }

        LightingEffectResHandle        handle = AllocResourcesHandle(nID);
        Queue <LightingEffectBehavior> list   = null;

        if (!m_behaviorCacheTable.TryGetValue(nID, out list))
        {
            list = new Queue <LightingEffectBehavior>();
            m_behaviorCacheTable.Add(nID, list);
        }

        for (int i = 0; i < PreWarmCount; i++)
        {
            LightingEffectBehavior          reslut   = CreateNewBehavior(nID, config.GetEffectType());
            LightingEffectResHandleInstance instance = GetResourceHandleAsync(nID, reslut.OnResourcesLoadFinish);
            handle.CacheInstance(instance, EffectCacheRoot.transform, CachePos);
            handle.Release();//缓存不需要保留引用
            reslut.FillData(config, null, instance, null);
            list.Enqueue(reslut);
        }

        return(true);
    }
예제 #16
0
    public void Update() //Update阶段更新,在人物动作计算之前,不支持失败删除光效
#endif
    {
        if (mEffectList == null)
        {
            return;
        }
        //dealWithStateEffect();

        //遍历光效列表,对光效进行更新
        for (int i = 0; i < mEffectList.Count; i++)
        {
            LightingEffectBehavior effect = mEffectList[i];

            if (!effect.Valid)
            {
                continue;
            }
            if (effect.needClose != true)
            {
                effect.Update();
            }
        }
    }
    public void ResetBehavior(LightingEffectBehavior instance)
    {
        if (!isValid)
        {
            return;
        }
        if (null == instance)
        {
            return;
        }
        int effectID = instance.getID();

        if (effectID > 0)
        {
            LightingEffectResHandle handle = AllocResourcesHandle(instance.getID());
            handle.CacheInstance(instance.ResourceHandle, EffectCacheRoot.transform, CachePos);
            handle.Release();
        }

        DeleteBehaviorTransformAgent(instance.TransformAgent);
        //CacheBehaviorDestroyTimer(instance.BehaviorDestroyTimer);
        instance.ResetAllMembers();
        instance.SetInvalid();
    }
예제 #18
0
    public void addMoneyEffect(U3D_Render.EntityView dieEv, ulong uMurderID)
    {
        if (dieEv == null || dieEv.CampFlag != SPELL.CampFlag.CampFlag_Enemy)
        {
            return;
        }

        U3D_Render.EntityView mainEv = EntityFactory.getMainPlayer();

        if (mainEv == null || mainEv.StateMachine.GetState() == GameLogic.EntityState.Dead)
        {
            return;
        }

        Vector3 deadLoc = dieEv.gameObject.transform.position;
        Vector3 heroLoc = mainEv.gameObject.transform.position;

        if ((ulong)mainEv.ID == uMurderID)
        {
            int effectCount = 0;
            //根据死亡对象类型控制光效数量
            //如果是怪物类型
            if (dieEv.Type == ENTITY_TYPE.TYPE_MONSTER)
            {
                //中立野怪
                //if ((int)MONSTER_SUB_TYPE.MONSTER_SUB_TYPE_WILD_MONSTER == dieEv.Flag)
                effectCount = 3;    //小兵和野怪都是3个
            }
            else if (dieEv.Type == ENTITY_TYPE.TYPE_PLAYER_ROLE)
            {
                effectCount = 6;    //英雄6个
            }


            LightingEffectBehavior eff = EffectHelper.PlayAndReturnEffect(ref mainEv, GameLogicConfigApi.MoneyEffect, mainEv.ID, mainEv.ID, deadLoc, 0, 2);
            if (eff != null)
            {
                LightingEffectBehavior_Area effect = (LightingEffectBehavior_Area)eff;
                effect.SetEffectCount(effectCount);
                return;
            }
        }

        //别人杀死就没金币掉落

        //int nMonsterDistance = GameLogicConfigApi.MonsterDistance;
        //int nTowerDistance = GameLogicConfigApi.TowerDistance;

        //if ((deadLoc - heroLoc).sqrMagnitude > (nMonsterDistance * nMonsterDistance))
        //    return;

        //IList<U3D_Render.EntityView> monster_Entities = MapFinderManager.Nearest(deadLoc, /*nTowerDistance*/nMonsterDistance, SPELL.CampFlag.CampFlag_Self);
        //if (monster_Entities == null)
        //    return;

        //int nMainID = 0;
        //float fMinDis = 0.0f;
        //foreach (U3D_Render.EntityView monsterEv in monster_Entities)
        //{
        //    if (HeroDistanceMgr.CheckDistance(dieEv, monsterEv, nMonsterDistance) == false || monsterEv == null)
        //        continue;

        //    if ((int)MONSTER_SUB_TYPE.MONSTER_SUB_TYPE_DEFENSIVE_TOWER == monsterEv.Flag)
        //    {

        //        //return;
        //    }
        //    else if (ENTITY_TYPE.TYPE_PLAYER_ROLE == monsterEv.Type)
        //    {
        //        float fEntityDistance = (deadLoc - monsterEv.gameObject.transform.position).sqrMagnitude;
        //        if (fMinDis == 0 || fEntityDistance < fMinDis)
        //        {
        //            fMinDis = fEntityDistance;
        //            nMainID = monsterEv.ID;
        //        }
        //    }
        //}

        //U3D_Render.EntityView view = EntityFactory.getEntityViewByID((int)uMurderID);

        //if (nMainID == mainEv.ID && (ulong)nMainID != uMurderID && (int)MONSTER_SUB_TYPE.MONSTER_SUB_TYPE_DEFENSIVE_TOWER != view.Flag)
        //{
        //    if ((view.InitMaskFlag & (int)ENTITY_MASKFLAG.MASKFLAG_DIE_NO_COMMONLIGHT) != (int)ENTITY_MASKFLAG.MASKFLAG_DIE_NO_COMMONLIGHT)
        //        EffectHelper.Play(ref mainEv, GameLogicConfigApi.MonsterEffect, mainEv.ID, mainEv.ID, monsterLoc);
        //}
    }
    private LightingEffectBehavior CreateNewBehavior(int effectID, LightingEffectConfigType t)
    {
        if (!isValid)
        {
            return(null);
        }

        LightingEffectBehavior reslut = null;

        switch (t)
        {
        case LightingEffectConfigType.AniReplace:
            reslut = new LightingEffectBehavior_AnimationReplace();
            break;

        case LightingEffectConfigType.Area:
            reslut = new LightingEffectBehavior_Area();
            break;

        case LightingEffectConfigType.Bind:
            reslut = new LightingEffectBehavior_Bind();
            break;

        case LightingEffectConfigType.Camera:
            reslut = new LightingEffectBehavior_Camera();
            break;

        case LightingEffectConfigType.Fly:
            reslut = new LightingEffectBehavior_Fly();
            break;

        case LightingEffectConfigType.Invalid:
            break;

        //case LightingEffectConfigType.MatReplace:
        //    reslut = new LightingEffectBehavior_MaterialReplace();
        //    break;
        case LightingEffectConfigType.Shadow:
            reslut = new LightingEffectBehavior_Shadow();
            break;

        case LightingEffectConfigType.Sound:
            reslut = new LightingEffectBehavior_Sound();
            break;

        case LightingEffectConfigType.Speed:
            reslut = new LightingEffectBehavior_Speed();
            break;

        case LightingEffectConfigType.Ward:
            reslut = new LightingEffectBehavior_Ward();
            break;
        }
        if (null == reslut)
        {
            Debug.LogError("CreateNewBehavior faild,找不到配置类型:" + t);
        }
        else
        {
            LinkedList <LightingEffectBehavior> list = null;
            if (!m_allBehaviorTable.TryGetValue(effectID, out list))
            {
                list = new LinkedList <LightingEffectBehavior>();
                m_allBehaviorTable.Add(effectID, list);
            }
            list.AddLast(reslut);
        }
        return(reslut);
    }
예제 #20
0
    public void LateUpdate() //光效更新改在了LateUpdate阶段,在人物动作计算之后,以便获得绑点准确的transoform信息
#endif
    {
        if (mEffectList == null)
        {
            return;
        }
        //dealWithStateEffect();

        //遍历光效列表,对光效进行更新或关闭操作
        for (int i = 0; i < mEffectList.Count;)
        {
            LightingEffectBehavior effect = mEffectList[i];
            int effectid = effect.getID();


            bool bRemove = false;
            if (!effect.Valid)
            {
                bRemove = true;
            }
            else
            {
                if (effect.needClose == true) //光效需要关闭并移除
                {
                    effect.Close();
                    if (effect.needClose)
                    {
                        //如果有类似原路返回的效果,则不能立刻删除光效,在Close()函数中会把needClose改回false,此时就不移除光效
                        bRemove = true;
                    }
                }
                else if (effect.LateUpdate() == false) //否则,对光效进行更新,更新失败的关闭并移除
                {
                    effect.needClose = true;
                    effect.Close();
                    if (effect.needClose)
                    {
                        //如果有类似原路返回的效果,则不能立刻删除光效,在Close()函数中会把needClose改回false,此时就不移除光效
                        bRemove = true;
                    }
                }


                effect.ApplyPlayDataToResHandler();
            }

            if (bRemove)
            {
                mEffectList.RemoveAt(i);
                DoCompleteCallBack(effectid);

                LightingEffectFactory.Instance.CacheEffectBehavior(ref effect);
            }
            else
            {
                DoStartCallBack(effectid);
                i++;
            }
        }
    }
예제 #21
0
    public void addMonsterEffect(U3D_Render.EntityView dieEv, ulong uMurderID)
    {
        if (dieEv == null || dieEv.CampFlag != SPELL.CampFlag.CampFlag_Enemy || !CheckMonsterType(dieEv))
        {
            return;
        }

        U3D_Render.EntityView mainEv = EntityFactory.getMainPlayer();

        if (mainEv == null || mainEv.StateMachine.GetState() == GameLogic.EntityState.Dead)
        {
            return;
        }

        Vector3 monsterLoc = dieEv.gameObject.transform.position;
        Vector3 heroLoc    = mainEv.gameObject.transform.position;

        int  effectCount         = 0;
        bool needPlayMoneyEffect = false;
        //根据死亡对象类型控制光效数量
        int    vocationID   = dieEv.createinfo.nHeroID;
        string dieEffectMsg = "";
        IntPtr strPtr       = GameLogicAPI.toCoinLighting(vocationID, (int)ENTITY_TYPE.TYPE_MONSTER);

        if (strPtr != null)
        {
            dieEffectMsg = IntPtrHelper.Ptr2Str(strPtr);
        }
        if (dieEffectMsg.Contains(GameLogicConfigApi.MoneyEffect.ToString()))
        {
            needPlayMoneyEffect = true;
        }

        if ((ulong)mainEv.ID == uMurderID && GameLogicAPI.isInWarScene() != 0)
        {
            //如果是怪物类型
            if (dieEv.Type == ENTITY_TYPE.TYPE_MONSTER)
            {
                //中立野怪
                //if ((int)MONSTER_SUB_TYPE.MONSTER_SUB_TYPE_WILD_MONSTER == dieEv.Flag)
                effectCount = 3;    //小兵和野怪都是3个
            }
            else if (dieEv.Type == ENTITY_TYPE.TYPE_PLAYER_ROLE)
            {
                effectCount = 6;    //英雄6个
            }

            if (effectCount > 0 && needPlayMoneyEffect)
            {
                LightingEffectBehavior moneyEff = EffectHelper.PlayAndReturnEffect(ref mainEv, GameLogicConfigApi.MoneyEffect, mainEv.ID, mainEv.ID, monsterLoc, 0, 2);
                if (moneyEff != null)
                {
                    LightingEffectBehavior_Area effect = (LightingEffectBehavior_Area)moneyEff;
                    effect.SetEffectCount(effectCount);
                }
            }
            LightingEffectBehavior deadEff = EffectHelper.PlayAndReturnEffect(ref dieEv, GameLogicConfigApi.MonsterDeadEffect, dieEv.ID, dieEv.ID, monsterLoc, 0, 2);
            return;
        }

        int nMonsterDistance = GameLogicConfigApi.MonsterDistance;
        int nTowerDistance   = GameLogicConfigApi.TowerDistance;

        if ((monsterLoc - heroLoc).sqrMagnitude > (nMonsterDistance * nMonsterDistance))
        {
            return;
        }

        IList <U3D_Render.EntityView> monster_Entities = MapFinderManager.Nearest(monsterLoc, /*nTowerDistance*/ nMonsterDistance, SPELL.CampFlag.CampFlag_Self);

        if (monster_Entities == null)
        {
            return;
        }

        int   nMainID = 0;
        float fMinDis = 0.0f;

        foreach (U3D_Render.EntityView monsterEv in monster_Entities)
        {
            if (HeroDistanceMgr.CheckDistance(dieEv, monsterEv, nMonsterDistance) == false || monsterEv == null)
            {
                continue;
            }

            if ((int)MONSTER_SUB_TYPE.MONSTER_SUB_TYPE_DEFENSIVE_TOWER == monsterEv.Flag)
            {
                //return;
            }
            else if (ENTITY_TYPE.TYPE_PLAYER_ROLE == monsterEv.Type)
            {
                float fEntityDistance = (monsterLoc - monsterEv.gameObject.transform.position).sqrMagnitude;
                if (fMinDis == 0 || fEntityDistance < fMinDis)
                {
                    fMinDis = fEntityDistance;
                    nMainID = monsterEv.ID;
                }
            }
        }

        U3D_Render.EntityView view = EntityFactory.getEntityViewByID((int)uMurderID);

        if (nMainID == mainEv.ID && (ulong)nMainID != uMurderID && (int)MONSTER_SUB_TYPE.MONSTER_SUB_TYPE_DEFENSIVE_TOWER != view.Flag)
        {
            if ((view.InitMaskFlag & (int)ENTITY_MASKFLAG.MASKFLAG_DIE_NO_COMMONLIGHT) != (int)ENTITY_MASKFLAG.MASKFLAG_DIE_NO_COMMONLIGHT)
            {
                EffectHelper.Play(ref dieEv, GameLogicConfigApi.MonsterDeadEffect, dieEv.ID, mainEv.ID, monsterLoc);
            }
        }
    }
예제 #22
0
    ////-----------------------------------------------------------------------------------------------------
    ////以下部分主要处理光效跟动作配合的时候,需要检查状态机切换再开始光效的功能
    ////-----------------------------------------------------------------------------------------------------
    //private List<LightingEffect> mDelayEffectList; //延迟挂接的光效,等到状态切换后再开始挂接
    //private int lastestStateNameHash = 0;
    //private void dealWithStateEffect()
    //{
    //    if (animator == null)
    //    {
    //        animator = transform.GetComponent<Animator>();
    //    }

    //    if (animator == null)
    //    {
    //        return;
    //    }
    //    if (animator.layerCount < 2)
    //    {
    //        return;
    //    }
    //    AnimatorStateInfo sta = animator.GetCurrentAnimatorStateInfo(1);
    //    int currentStateNameHash = sta.nameHash;
    //    if (currentStateNameHash == lastestStateNameHash)
    //    {
    //        return;
    //    }

    //    //切换动作了!这里nameHash只做切换时间点的判断,用nameHash和effect.waitState对比老是失败
    //    lastestStateNameHash=currentStateNameHash;
    //    foreach (LightingEffect effect in mDelayEffectList)
    //    {
    //        if (sta.IsName(effect.getWaitState()))
    //        {
    //            if (effect.Begin())
    //            {
    //                mEffectList.Add(effect);
    //            }
    //        }
    //    }

    //    //目前暂定切一次动作就清空一次延迟光效的记录,也就是说光效只能延迟一个动作挂接
    //    mDelayEffectList.Clear();
    //}



    // 添加一个光效
    // @param nID : 光效ID
    // @param nSrcEntityID : 光效源对象ID
    // @param targetObject : 目标对象,可以为空
    // @param targetPos : 目标位置,可以为空
    // @param isHero : 是否是游戏玩家控制的主角
    // @param nFeedbackID : 逻辑层传的ID标识,用于标记、删除和碰撞是返回标识。

    public LightingEffectBehavior AddLightingImpl(int nID, LightEffectParam param)
    {
        //远距离不创建分情况考虑,具体在LightingEffect实现
        //if (LightingEffectFactory.Instance.IsEnabledOptimize())
        //{
        //    //距离超过创建距离,不创建光效了。
        //    Vector3 dis = Initialize.mainCam.transform.position - param.srcObject.transform.position;
        //    if (dis.sqrMagnitude > LightingEffectFactory.CreateDistance * LightingEffectFactory.CreateDistance)
        //    {
        //        return null;
        //    }
        //}

        //处理单一实例的光效
        if (LightingEffectFactory.Instance.IsSingleEffect(nID))
        {
            foreach (LightingEffectBehavior effect in mEffectList)
            {
                if (effect.getID() == nID && effect.EffectConfig.bSingle)
                {
                    if (effect.EffectConfig.bRecoverSingleEffect)
                    {
                        effect.recoverEffectLift(param);
                        return(effect);
                    }
                    else if (effect.EffectParam.nTargetEntityID == param.nTargetEntityID)
                    {
                        effect.extendEffectLift();
                        return(effect);
                    }
                }
            }
        }

        if (LightingEffectFactory.Instance.CheckGolbalEffect(nID) && isGlobal == false)
        {
            LightingEffectManager leManager = EntityFactory.GloabaleManager;
            if (leManager != null && leManager.isGlobal == true)
            {
                leManager.AddLighting(nID, param);
            }
            return(null);
        }

        LightingEffectBehavior newEffect = LightingEffectFactory.Instance.CreateEffect(nID, param);

        if (newEffect == null)
        {
            return(null);
        }

        newEffect.showLog = showLog;
        //string needStateName = newEffect.getWaitState();

        //if (needStateName.Length != 0)
        //{
        //    AnimatorStateInfo sta = animator.GetCurrentAnimatorStateInfo(1);
        //    if (!sta.IsName(needStateName))
        //    {
        //        //等下一个切换状态时再检测
        //        mDelayEffectList.Add(newEffect);
        //        return newEffect;
        //    }
        //}

        //开始失败了,返回null
        if (newEffect.Begin())
        {
            mEffectList.Add(newEffect);

            return(newEffect);
        }
        return(null);
    }