Example #1
0
        ///// <summary>
        ///// 服务器二维坐标原点对应的unity坐标
        ///// </summary>
        //public Vector2 OriPos
        //{
        //    get
        //    {
        //        if(m_curMapLoader !=null)
        //        {
        //            return m_curMapLoader.OriPos;
        //        }
        //        return Vector2.zero;
        //    }
        //}

        public void Init()
        {
            string testSceneName     = "TestScene";
            string testSceneInfoFile = "TestScene/TestScene.json";
            int    mapAssetId        = 1;

            SceneUnit sceneUnit = new SceneUnit();

            sceneUnit.Init(mapDataDirPath + testSceneInfoFile);
            m_dicMapId.Add(mapAssetId, testSceneName);
            m_dicMapLoader.Add(testSceneName, sceneUnit);
        }
Example #2
0
        public void ExitCurMap()
        {
            if (m_curMapLoader != null)
            {
                m_curMapLoader.ExitScene();

                if (!m_listClosingMap.Contains(m_curMapLoader))
                {
                    m_listClosingMap.Add(m_curMapLoader);
                }
                m_curMapLoader = null;
            }
        }
Example #3
0
        //public bool StartReleaseMapData(string mapName)
        //{
        //    int mapID = GetMapID(mapName);
        //    return StartReleaseMapData(mapID);
        //}

        //开始回收指定地图资源
        private bool StartReleaseMapData(SceneUnit mapLoader)
        {
            if (m_listReleaseMap.Contains(mapLoader))
            {
#if DEBUG
                Debug.LogWarning("该地图已经在回收列表中");
#endif
                return(false);
            }
            mapLoader.ReleaseSceneObject();
            m_listReleaseMap.Add(mapLoader);
            //注册事件
            //m_eventModule.WatchUnityEvent(
            //    YuUnityEventType.FixedUpdate, ReleaseResourceFrame);
            return(true);
        }
Example #4
0
        public bool OpenMap(int mapID)//, Point2 coord,bool isPhase = false)
        {
            //if (CurMapId() == mapID)
            //{
            //    return true;
            //}

            if (m_dicMapId.ContainsKey(mapID) &&
                m_dicMapLoader.ContainsKey(m_dicMapId[mapID]))
            {
                ExitCurMap();                          //尝试关闭旧地图

                m_curMapLoader = m_dicMapLoader[m_dicMapId[mapID]];
                if (!m_curMapLoader.TryEnterScene())
                {
#if UNITY_EDITOR
                    Debug.LogError(string.Format("地图开启失败,ID:{0}", mapID));
#endif
                    //return false;
                }
                //---成功打开地图后---


                //---判断是否需要释放之前的地图资源---
                if (m_linkOpenOrder.Contains(m_curMapLoader))
                {
                    m_linkOpenOrder.Remove(m_curMapLoader);
                    m_linkOpenOrder.AddLast(m_curMapLoader);
                }
                else
                {
                    m_linkOpenOrder.AddLast(m_curMapLoader);
                }
                if (m_linkOpenOrder.Count > c_maxKeepResource)
                {
                    StartReleaseMapData(m_linkOpenOrder.First.Value);
                    m_linkOpenOrder.RemoveFirst();
                }
                return(true);
            }
#if UNITY_EDITOR
            Debug.LogError(string.Format("未找到对应的地图加载器,ID:{0}", mapID));
#endif
            return(false);
        }
Example #5
0
        public void Init(Dictionary <int, string> mapInfos)
        {
            foreach (var mapInfo in mapInfos)
            {
                //Todo 通过读表方式获取路径
                string mapAssetId = mapInfo.Value;

                if (m_dicMapId.ContainsKey(mapInfo.Key))
                {
#if DEBUG
                    Debug.LogError(string.Format("读取到重复的地图信息 ID:{0}    ,path:{1}", mapInfo.Key, mapAssetId));
#endif
                    continue;
                }
                //地图配置编号 映射 地图数据资源id
                m_dicMapId.Add(mapInfo.Key, mapInfo.Value);

                //如果资源id没有对应的地图加载器,则创建
                if (!m_dicMapLoader.ContainsKey(mapInfo.Value))
                {
                    SceneUnit mapLoader = new SceneUnit();
                    mapLoader.Init(mapAssetId);
                    //mapLoader.BlockMaterial = m_blockMaterial;
                    m_dicMapLoader.Add(mapInfo.Value, mapLoader);
                }
            }
            //注册事件
            //m_eventModule.WatchUnityEvent(
            //    YuUnityEventType.FixedUpdate, OnFixedUpdate);
            //m_eventModule.WatchEvent(
            //    YuUnityEventCode.NetDisconnect, CloseCurMap);

            //YuMapTools.SetMapIDMapping(m_dicMapId);

            //m_eventModule.WatchEvent(YuUnityEventCode.Scene_CameraTranslate, OnCameraTranslate);
        }