Ejemplo n.º 1
0
    void CreateEffect(int heroResId, string actionName, System.Action cb)
    {
        // 清除旧的特效
        CloseEmpty();
        ClearEffect();


        // 切换过程中都只认这个CID
        usingHeroCID = showingCID == null?CoreEntry.portalMgr.GetLastHeroCID() : showingCID;

        usingHeroResId     = heroResId;
        isShowingEmptyBase = false;

        // 创建特效
        float     costTime  = 0;
        Transform heroPoint = null;

        //ChardLi需求,进化后英雄第一次进入时,应播放进化之前对应的英雄动画
        if (evolutionCID != null && PortalMgr.CompareCID(usingHeroCID, evolutionCID))
        {
            var heroAttr = CoreEntry.gameDataMgr.heroAttr.GetRecord(heroResId);
            if (heroAttr != null)
            {
                heroResId = heroAttr.iInitialID;
            }
        }
        createHeroAction = () =>
        {
            //创建英雄
            if (CoreEntry.gameDataMgr.GetPlayerDataByResId(heroResId, out playerData))
            {
                if (heroObj != null)
                {
                    UnityEngine.Object.Destroy(heroObj);
                }
                heroObj = CoreEntry.resourceMgr.InstantiateObject(playerData.resPath + "_hd", Vector3.one, Quaternion.identity);
            }
            if (heroObj == null)
            {
                cb();
                return;
            }
            //加载翅膀
            CoreEntry.resourceMgr.LoadWing(heroObj, heroResId);
            // 关闭脚本
            var cs = heroObj.GetComponents <Creature>();
            for (int i = 0; i < cs.Length; ++i)
            {
                cs[i].enabled = false;
            }
            GlobalFunctions.ChangeLayer(heroObj, LayerMask.NameToLayer("ChangePlayer"), "Untagged");
            if (CoreEntry.sceneMgr.isPauseGame)
            {
                GlobalFunctions.AnimationIgnoreTime(heroObj);
            }
        };


        if (IsDeadType(changeType))
        {
            if (CoreEntry.toyMgr.GameMode == GameMode.VIRTUAL)
            {
                //如果是虚拟英雄的话走单独流程
                CoreEntry.globalObject.GetComponent <CoreEntry>().StartCoroutine(SceneMgr.DelayToInvoke(() =>
                {
                    // 关闭主摄像机,直接使用美术的
                    CoreEntry.cameraMgr.CloseMainCamera();
                    var panel = CoreEntry.uiMgr.GetPanelSimply(AIToyMgr.VIRTUAL_PANEL);
                    cb();
                }));
                return;
            }

            // 关闭主摄像机,直接使用美术的
            CoreEntry.cameraMgr.CloseMainCamera();
            //英雄死亡的逻辑走这里
            switchEffect = CoreEntry.resourceMgr.InstantiateObject("Prefabs/Effect/pet/p_pet_catch_lose", SceneMgr.FarAway, Quaternion.identity);
            costTime     = EFFECT_DIE_TIME;

            // 检查是否还有可以更换的英雄玩偶
            bool isAllDead = CoreEntry.virtualHeroMgr.ToyHeroAllDead();

            // 获取文字特效
            Transform goShowText1 = switchEffect.transform.Find("HeroPoint/p_pet_lose");
            if (null != goShowText1)
            {
                goShowText1.gameObject.SetActive(isAllDead);
            }
            Transform goShowText2 = switchEffect.transform.FindChild("HeroPoint/p_pet_lose02");
            if (null != goShowText2)
            {
                goShowText2.gameObject.SetActive(!isAllDead);
            }

            heroPoint = GlobalFunctions.GetTransform(switchEffect.transform, "HeroPoint");
            if (heroPoint != null)
            {
                //延后执行,不显示英雄生成时站立画面,直接显示失败动画
                Scheduler.Create(this, (sche, t, s) =>
                {
                    createHeroAction();
                    if (heroObj != null)
                    {
                        GlobalFunctions.MountTransform(heroObj.transform, heroPoint);
                    }
                    // 播放英雄死亡公共特效
                    CoreEntry.actionMgr.PlayAction("hero_dead", heroObj);
                    //执行回调函数
                    cb();
                }, 0, 0, costTime, ActionMgr.Priority.Normal, true);
            }
        }
        else
        {
            // 关闭主摄像机,直接使用美术的
            CoreEntry.cameraMgr.CloseMainCamera();
            //英雄正常进入走这里
            createHeroAction();
            switchEffect = CoreEntry.resourceMgr.InstantiateObject("Prefabs/Effect/scene/switchball/" + switchBg, SceneMgr.FarAway * 2, Quaternion.identity);
            costTime     = EFFECT_SHOW_TIME;

            // 使用美术坐标

            heroPoint = GlobalFunctions.GetTransform(switchEffect.transform, "NonHeroPoint");
#if true
            if (heroPoint != null && heroObj != null)
            {
                //播放切换英雄时音效
                //GlobalFunctions.ChangeLayer(heroPoint.gameObject, LayerMask.NameToLayer("ChangePlayer"));
                GlobalFunctions.MountTransform(heroObj.transform, heroPoint);
                var actor = heroObj.GetComponent <Actor>();
                if (actor != null)
                {
                    actor.ignoreTimeScale = true;
                }
                CoreEntry.actionMgr.PlayAction("switchFlyIn", heroObj);
            }
#endif

            // 创建名字特效
            Scheduler.Create(this, (sche, t, s) =>
            {
                // mount name
                if (switchEffect == null)
                {
                    cb();
                    return;
                }
                var namePoint = GlobalFunctions.GetTransform(switchEffect.transform, "NamePoint");
                if (playerData != null && namePoint != null && evolutionCID == null)                    //进化特效不展示英雄名字
                {
                    var name = CoreEntry.resourceMgr.InstantiateObject(playerData.namePath, SceneMgr.FarAway, Quaternion.identity);
                    if (name != null)
                    {
                        name.transform.parent        = namePoint;
                        name.transform.localPosition = Vector3.zero;
                        name.transform.localRotation = Quaternion.identity;
                    }
                }
                cb();
            }, 0, 0, costTime, ActionMgr.Priority.Normal, true);
        }

        // 设置场景对象,用于设置soundListener
        CoreEntry.sceneMgr.soundPlayerTransform = heroPoint.transform;
    }