示例#1
0
    IEnumerator LoadDropIcon(uint iconId, Sprite3DEx sprite3D, uint loadId)
    {
        sprite3D.RenderEnable = false;

        SGameEngine.AssetResource ar = new SGameEngine.AssetResource();
        IconInfo info     = GoodsHelper.GetIconInfo(iconId);
        var      iconPath = info.MainTexturePath;

        yield return(xc.MainGame.GetGlobalMono().StartCoroutine(SGameEngine.ResourceLoader.Instance.load_asset(iconPath, typeof(Texture), ar)));

        // 检查资源
        var tex = ar.asset_ as Texture;

        if (tex == null)
        {
            GameDebug.LogError("LoadDropIcon is failed");
            yield break;
        }

        // 检查loadId是否变化/sprite3D组件
        if (loadId != mCurLoadIconID || sprite3D == null)
        {
            ar.destroy();
            yield break;
        }

        mDropIconRes = ar;

        sprite3D.SetTexture(tex, iconPath);
        sprite3D.UVOffset     = info.IconRect;
        sprite3D.RenderEnable = true;
    }
示例#2
0
    public void Destroy()
    {
        if (mIsBossChip && CanPick)
        {
            OnTouchExit();
        }

        mDropInfo        = null;
        mDropType        = EDropType.None;
        mCanPick         = false;
        CanNotPickReason = 0;
        mPickSqrRadius   = 0f;
        mIsTouching      = false;

        if (mTimer != null)
        {
            mTimer.Destroy();
            mTimer = null;
        }

        if (mDisappearTimer != null)
        {
            mDisappearTimer.Destroy();
            mDisappearTimer = null;
        }

        ClearCD();

        InstanceDropManager.GetInstance().RemoveDrop(this);

        if (mDropIconRes != null)
        {
            mDropIconRes.destroy();
            mDropIconRes = null;
        }

        if (mAutoPickCoroutine != null)
        {
            mAutoPickCoroutine.Stop();
            mAutoPickCoroutine = null;
        }

        mDropGoodsSubType = 0;
        mIsBossChip       = false;
        if (mBossChipEffectGameObject != null)
        {
            GameObject.DestroyImmediate(mBossChipEffectGameObject);
            mBossChipEffectGameObject = null;
        }

        mCurLoadEffectID = 0;
        mCurLoadIconID   = 0;

        m_IsDestory = true;
    }
示例#3
0
        /// <summary>
        /// 协程加载关卡配置
        /// </summary>
        /// <param name="path"></param>
        /// <returns></returns>\
        private IEnumerator CoLoadLevelFile(string path)
        {
            SGameEngine.AssetResource result = new SGameEngine.AssetResource();

            yield return(MainGame.HeartBehavior.StartCoroutine(SGameEngine.ResourceLoader.Instance.load_asset(path, typeof(TextAsset), result)));

            if (result.asset_ == null)
            {
                yield break;
            }

            TextAsset textAsset = result.asset_ as TextAsset;

            if (textAsset == null || textAsset.text == null)
            {
                result.destroy();
                Debug.LogError("LevelManager::CoLoadLevelFile, can not read level file:" + path);
                yield break;
            }

            Neptune.Data          data   = new Neptune.Data();
            FullSerializer.fsData fsdata = FullSerializer.fsJsonParser.Parse(textAsset.text);
            var serializer = new FullSerializer.fsSerializer();
            var processor  = new Neptune.FileSerializerProcessor();

            serializer.AddProcessor(processor);
            serializer.TryDeserialize <Neptune.Data>(fsdata, ref data);

            if (data == null)
            {
                result.destroy();
                yield break;
            }

            OnLevelLoadFinished(data);
            ObjCachePoolMgr.Instance.RecycleCSharpObject(data, ObjCachePoolType.JSON, path);

            result.destroy();
        }
示例#4
0
    /// <summary>
    /// 加载ai对应的文件
    /// </summary>
    /// <param name="aiFile"></param>
    /// <returns></returns>
    private IEnumerator LoadAIFile(string aiFile)
    {
        SGameEngine.AssetResource result = new SGameEngine.AssetResource();

        string path = string.Format(AI_PATH_PREFIX + "/{0}", aiFile);

        yield return(MainGame.HeartBehavior.StartCoroutine(SGameEngine.ResourceLoader.Instance.load_asset(path, typeof(TextAsset), result)));

        if (result.asset_ == null)
        {
            GameDebug.LogError("BehaviourAI::LoadAIFile, read ai file error 1:" + aiFile);

            yield break;
        }

        TextAsset textAsset = result.asset_ as TextAsset;

        if (textAsset == null)
        {
            Debug.LogError("BehaviourAI::LoadAIFile,can not read ai file:" + aiFile);
            yield break;
        }

        var options = MiniJSON.JsonDecode(textAsset.text) as Hashtable;

        if (options == null)
        {
            result.destroy();
            yield break;
        }

        var behaviourTree = new BehaviourTree.BehaviourTree(aiFile, options, this);

        ObjCachePoolMgr.Instance.RecycleCSharpObject(options, ObjCachePoolType.AIJSON, aiFile);

        SetBehaviourTree(behaviourTree);

        result.destroy();
    }
示例#5
0
        private IEnumerator CoLoadNavmeshFile(string path)
        {
            SGameEngine.AssetResource result = new SGameEngine.AssetResource();

            yield return(MainGame.HeartBehavior.StartCoroutine(SGameEngine.ResourceLoader.Instance.load_asset(path, typeof(TextAsset), result)));

            // 加载好的数据是否是当前场景的数据
            uint   stage_id     = SceneHelp.GetFirstStageId(SceneHelp.Instance.CurSceneID);
            uint   map_id       = SceneHelp.GetMapIdByStageId(stage_id);
            string navmesh_file = "Assets/Res/NavMesh/" + map_id.ToString() + ".txt";

            if (navmesh_file.Equals(path) == false)
            {
                yield break;
            }

            if (result.asset_ == null)
            {
                IsLoadingNavmeshFile = false;
                yield break;
            }

            TextAsset textAsset = result.asset_ as TextAsset;

            if (textAsset == null || textAsset.text == null)
            {
                IsLoadingNavmeshFile = false;
                Debug.LogError("LevelManager::CoLoadNavmeshFile, can not read navmesh file:" + path);
                yield break;
            }

            bool ret = XNavMesh.LoadBuffer(textAsset.bytes);

            if (!ret)
            {
                mCurNavmeshFile = string.Empty;
                GameDebug.LogError("navmesh LoadBuffer error : " + path);
            }
            else
            {
                mCurNavmeshFile = path;
            }

            result.destroy();

            IsLoadingNavmeshFile = false;
        }
示例#6
0
        //************************************
        // Method:  preload an asset, and keep in the cache for some seconds, sothat you can load it quickly without loading from bundle next time
        //Return IEnumerator : when the iemurrator ends, the asset loaded
        //Paramater string _asset_path: the asset path. eg. "Assets/Art/a.mat"
        //Paramater int _life_time: the time(in seconds) this asset keep in cache, it will be asured during this time, the asset will not destroyed from cache. a negitive (< 0 ) value implies infinite.
        //************************************
        public IEnumerator preload(string _asset_path, int _life_time = 30)
        {
            if (is_destroyed_)
            {
                yield break;
            }
            AssetResource ar = new AssetResource();

            yield return(StartCoroutine(load_asset(_asset_path, typeof(UnityEngine.Object), ar)));

            if (_life_time > 0)
            {
                yield return(new WaitForSeconds(_life_time));

                ar.destroy();
            }
            // <0 = forever !
        }
示例#7
0
    private IEnumerator ReloadRoutine()
    {
        var assetRes = new SGameEngine.AssetResource();

        yield return(StartCoroutine(SGameEngine.ResourceLoader.Instance.load_asset("Assets/" + xc.ResPath.path3,
                                                                                   typeof(TextAsset), assetRes, true, false, string.Empty)));

        var asset = assetRes.asset_ as TextAsset;

        if (asset == null)
        {
            GameDebug.LogError("ReloadRoutine load_asset failed.");
            yield break;
        }

        var mgr = LuaScriptMgr.Instance;

        mgr.ReloadBytes(asset.bytes);
        assetRes.destroy();
    }
示例#8
0
        /// <summary>
        /// <para>加载prefab并进行实例化,实例化后的GameObject会添加到dic_gameobj_asset_中</para>
        /// <para>调用gc时如果GameObject实例已经销毁,则会自动减少对应AssetObject的引用计数</para>
        /// <para>创建后返回的GameObject最好不要再进行Clone,因为GameObject被销毁后,Clone的实例资源也可能丢失</para>
        /// </summary>
        public IEnumerator load_prefab(string _asset_path, PrefabResource _result, bool _dont_destroy_on_load = false, bool _cache_global_bundle = false, Transform parent = null)
        {
            if (Const.Language != LanguageType.SIMPLE_CHINESE)
            {
                LocalizeManager.Instance.LocalizePath(ref _asset_path);
            }

            if (is_destroyed_)
            {
                yield break;
            }
            string lower_case = _asset_path.ToLower();

            if (!lower_case.EndsWith(CACHE_STR_PREFAB))
            {
                Debug.LogError(string.Format("{0} is not a prefab!", lower_case));
                yield break;
            }

            //1. lock the asset
            //do nothing

            //2. load asset and instantiate prefab
            AssetResource ar = new AssetResource();

            yield return(StartCoroutine(load_asset(_asset_path, type_game_object_, ar)));

            if (ar.asset_ != null)
            {
                /*if(_asset_path.Contains("/Res/UI/") && !_asset_path.Contains("/Res/UI/Atlas/") && _asset_path.EndsWith(".prefab"))
                 *              {
                 *                      yield return StartCoroutine(load_atlas(ar));
                 *              }*/

                _result.obj_ = instantiate_prefab_from_asset_object(ar, parent);
                if (_dont_destroy_on_load)
                {
                    GameObject.DontDestroyOnLoad(_result.obj_);
                }
                //adjust the gameobject postion to not be seen directly
                (_result.obj_ as GameObject).transform.position = new Vector3(-100, -1000, -100);
            }
            //3.已经在instantiate_prefab_from_asset_object进行了实例化,可以释放AssetResource对AssetObject的引用
            if (!_cache_global_bundle)
            {
                ar.destroy();
            }
            else
            {
                if (mGlobalCache.ContainsKey(_asset_path))
                {
                    ar.destroy();
                }
                else
                {
                    mGlobalCache[_asset_path] = true;
                }
            }

            //4.unlock asset
            //do nothing
        }
示例#9
0
        /// <summary>
        /// 停止播放剧情
        /// </summary>
        /// <param name="timelineInfo"></param>
        void StopImpl(TimelineInfo timelineInfo)
        {
            //GameDebug.LogError("TimelineManager.StopImpl: " + timelineInfo.Id);

            Actor localPlayer = Game.Instance.GetLocalPlayer();

            if (localPlayer != null)
            {
                if (Game.Instance.CameraControl != null)
                {
                    Game.Instance.CameraControl.Target = localPlayer.Trans;
                    Game.Instance.CameraControl.NeedFollowInterpolation = timelineInfo.NeedCameraFollowInterpolationWhenFinished;
                }
                else
                {
                    GameDebug.LogError("Stop timeline error, CameraControl is null!!!");
                }
            }
            else
            {
                // 播放动画的时候有可能还没登录游戏,所以LocalPlayer有可能不存在,这里的报错屏蔽掉
                //GameDebug.LogError("Stop timeline error, can not get local player!!!");
            }
            if (Game.Instance.MainCamera != null)
            {
                Cinemachine.CinemachineBrain cinemachineBrain = Game.Instance.MainCamera.GetComponent <Cinemachine.CinemachineBrain>();
                if (cinemachineBrain != null)
                {
                    cinemachineBrain.enabled = false;
                }
                Game.Instance.MainCamera.transform.rotation = mCameraRotationBeforePlay;
                Game.Instance.MainCamera.fieldOfView        = mCameraFOVBeforePlay;
            }
            else
            {
                GameDebug.LogError("Stop timeline error, can not get main camera!!!");
            }

            if (timelineInfo.PlayableDirector != null)
            {
                timelineInfo.PlayableDirector.time = timelineInfo.PlayableDirector.duration;
                GameObject.DestroyImmediate(timelineInfo.PlayableDirector.gameObject);
            }
            else
            {
                GameDebug.LogError("Stop timeline error, PlayableDirector is null!!!");
            }
            if (timelineInfo.RelatedGameObject != null)
            {
                GameObject.DestroyImmediate(timelineInfo.RelatedGameObject);
            }
            mPlayingTimeline = null;

            SetAllActorsVisible(true, timelineInfo.ShowLocalPlayer);

            // 恢复主角的自动战斗
            if (InstanceManager.Instance.IsAutoFighting != mIsAutoFightingWhenPlaying)
            {
                InstanceManager.Instance.IsAutoFighting = mIsAutoFightingWhenPlaying;
            }
            mIsAutoFightingWhenPlaying = false;

            GameInput.Instance.EnableInput(true, true);

            // 恢复CullManager的Update
            CullManager.Instance.IsEnabled = true;

            // 显示UI
            if (timelineInfo.ShowUI == false)
            {
                xc.ui.ugui.UIManager.Instance.ShowAllWindow();
            }

            // 恢复新手引导
            //GuideManager.Instance.Resume();

            // 恢复任务寻路
            if (mNavigatingTaskIdBeforePlay > 0)
            {
                Task task = TaskManager.Instance.GetTask(mNavigatingTaskIdBeforePlay);
                if (task != null)
                {
                    TaskHelper.TaskGuide(task);
                }
                mNavigatingTaskIdBeforePlay = 0;
            }

            // 恢复背景音乐
            if (!GlobalSettings.Instance.MusicMute && timelineInfo.PauseMusic)
            {
                AudioManager.Instance.PauseMusic(false);
            }

            ClientEventMgr.Instance.FireEvent((int)ClientEvent.CE_TIMELINE_FINISH, new CEventBaseArgs(timelineInfo.Id));

            if (timelineInfo.FinishCallback != null)
            {
                timelineInfo.FinishCallback();
            }

            // 释放预加载的资源
            SGameEngine.AssetResource ar = null;
            if (mPreloadedTimelineReses.TryGetValue(timelineInfo.Id, out ar) == true)
            {
                if (ar != null)
                {
                    ar.destroy();
                }

                mPreloadedTimelineReses.Remove(timelineInfo.Id);
            }

            // 如果有待播放的系统开放动画,则重新开放
            if (SysConfigManager.Instance.IsWaiting() == true)
            {
                if (SceneHelp.Instance.IsInWildInstance())
                {
                    TargetPathManager.Instance.StopPlayerAndReset();//有系统开启停止寻路
                    ClientEventMgr.GetInstance().FireEvent((int)ClientEvent.CE_NEW_WAITING_SYS, new CEventBaseArgs());
                }
                else
                {
                    ClientEventMgr.GetInstance().PostEvent((int)ClientEvent.CE_NEW_WAITING_SYS, new CEventBaseArgs());
                }
            }

            // 短时间内播放同一个模型的动画两次,第二个剧情会播放不出来,调用一下ResourceLoader的gc就好了,通过表格配置
            if (timelineInfo.NeedGC == true)
            {
                ResourceLoader.Instance.gc();
            }
        }