Ejemplo n.º 1
0
        private void InvokeReadyToPlayCallback()
        {
            DebugUtility.Log(Constants.LOG_TAG, string.Format("Map({0}) Ready To Play", m_MapUid));
            //Debug.LogError("InvokeReadyToPlayCallback");
            try
            {
                DebugUtility.Log(Constants.LOG_TAG, "Begin Invoke OnReadyToPlayCallback");
                m_ForReadyToPlayCallback.OnReadyToPlayCallback?.Invoke();
                DebugUtility.Log(Constants.LOG_TAG, "End Invoke OnReadyToPlayCallback");
            }
            catch (System.Exception e)
            {
                DebugUtility.LogError(Constants.LOG_TAG, string.Format("Invoke OnReadyToPlayCallback Exception:\n{0}", e.ToString()));
            }
            finally
            {
                m_ForReadyToPlayCallback = null;
            }

            try
            {
                DebugUtility.Log(Constants.LOG_TAG, "Begin Invoke _OnChangedMap");
                MapManager.GetInstance()._OnChangedMap?.Invoke(m_MapUid);
                DebugUtility.Log(Constants.LOG_TAG, "End Invoke _OnChangedMap");
            }
            catch (System.Exception e)
            {
                DebugUtility.LogError(Constants.LOG_TAG, string.Format("Invoke _OnChangedMap Exception:\n{0}", e.ToString()));
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 检测是否需要切换区域
        ///		true:切换区域
        ///		false:更新当前区域
        /// </summary>
        /// <param name="firstUpdate">true: 加载Map后第一次更新Area</param>
        private void DoUpdate_Area(bool firstUpdate = false)
        {
            // 玩家当前所在区域
            int areaIndex = m_MapInfo.CaculateAreaIndex(MapManager.GetInstance()._PlayerInfo.RealWorldPosition);

            // 玩家切换区域了
            if (m_CurrentAreaController == null ||
                m_CurrentAreaController.GetAreaIndex() != areaIndex)
            {
                // UNDOEN 切换Voxel需要加个延迟,以防玩家在Voxel的边界来回摩擦时频繁切换Voxel
                TryChangeArea(areaIndex);
            }
            else
            {
                m_CurrentAreaController.DoUpdate();
            }

            if (firstUpdate)
            {
                if (m_CurrentAreaController != null)
                {
                    m_ForReadyToPlayCallback.StartArea = m_CurrentAreaController;
                }
                else
                {
                    InvokeReadyToPlayCallback();
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 检查玩家位置
        /// </summary>
        private void DoCheckPlayerPos(bool forceCheck = false)
        {
            if (m_AreaLayerControllers == null || m_AreaLayerControllers.Count <= 0)
            {
                return;
            }
            DoUpdate_AreaRoot(false);
            bool canCheckPos = false;

            if (Time.time - m_LastCheckTime >= m_PositionCheckTime)
            {
                canCheckPos     = true;
                m_LastCheckTime = Time.time;
            }
            Vector3 playerGameWorldPosition = MapManager.GetInstance()._PlayerInfo.GameWorldPosition;

            for (int iLayer = 0; iLayer < m_AreaLayerControllers.Count; iLayer++)
            {
                AreaLayerController areaLayerController = m_AreaLayerControllers[iLayer];
                if (canCheckPos)
                {
                    areaLayerController.DoUpdate(playerGameWorldPosition, forceCheck);
                }
                areaLayerController.DoUnitUpdate();
            }
        }
Ejemplo n.º 4
0
        protected void Start()
        {
            ms_Instance = this;

            Application.targetFrameRate           = 60;
            Application.backgroundLoadingPriority = ThreadPriority.Low;
            MapManager.GetInstance();
        }
Ejemplo n.º 5
0
 protected void LateUpdate()
 {
     if (Mathf.Abs(transform.position.x) > PositionLimit ||
         Mathf.Abs(transform.position.y) > PositionLimit ||
         Mathf.Abs(transform.position.z) > PositionLimit)
     {
         m_Offset          -= transform.position;
         transform.position = Vector3.zero;
     }
     MapManager.GetInstance().SetPlayerPosition(transform.position - m_Offset, transform.position);
 }
Ejemplo n.º 6
0
 private void DoUpdate_AreaRoot(bool force)
 {
     if (force ||
         MapManager.GetInstance()._PlayerInfo.IsRealWorld2GameWorldChange)
     {
         if (m_AreaInfo != null)
         {
             Vector3 areaPosition = m_AreaInfo.Position + MapManager.GetInstance()._PlayerInfo.RealWorld2GameWorld;
             DebugUtility.Log(Constants.LOG_TAG, $"Map({m_Owner.GetMapUid()}) Area({m_AreaInfo.Uid}) Update AreaRoot({StringUtility.ConvertToDisplay(areaPosition)})");
             m_AreaRoot.position = areaPosition;
         }
     }
 }
Ejemplo n.º 7
0
        /// <summary>
        /// 切换Area
        /// </summary>
        private void TryChangeArea(int areaIndex)
        {
            if (m_CurrentAreaController != null)
            {
                ulong lastAreaUid = GetCurrentAreaUid();
                ulong newAreaUid  = areaIndex != Constants.NOTSET_AREA_INDEX
                    ? m_MapInfo.AreaInfos[areaIndex].Uid
                    : Constants.NOTSET_AREA_UID;
                if (lastAreaUid != newAreaUid)
                {
                    DebugUtility.Log(Constants.LOG_TAG, $"Begin change area from {lastAreaUid} to {newAreaUid}, {MapManager.GetInstance()._PlayerInfo}");
                }
            }

            if (m_CurrentAreaController != null)
            {
                m_CurrentAreaController.RequestRelease();
                m_ExpiredAreaControllers.Add(m_CurrentAreaController);
                m_CurrentAreaController = null;
            }

            if (areaIndex != Constants.NOTSET_AREA_INDEX)
            {
                AreaInfo targetAraeInfo = m_MapInfo.AreaInfos[areaIndex];
                if (m_LimitChangeToAreaUid == Constants.NOT_LIMIT_AREA_UID ||
                    m_LimitChangeToAreaUid == targetAraeInfo.Uid)
                {
                    m_State = State.ChangingArea;

                    m_CurrentAreaController = new AreaController();
                    m_CurrentAreaController.RequestInitialize(this, m_MapInfo.AreaInfos[areaIndex]);

                    DebugUtility.Log(Constants.LOG_TAG, "Begin invoke on changed area");
                    try
                    {
                        MapManager.GetInstance()._OnChangedArea?.Invoke(m_MapInfo.AreaInfos[areaIndex].Uid);
                        DebugUtility.Log(Constants.LOG_TAG, "End invoke on changed area");
                    }
                    catch (Exception e)
                    {
                        DebugUtility.LogError(Constants.LOG_TAG, string.Format("Invoke on changed area failed, Exception:\n{0}", e.ToString()));
                    }
                }
                else
                {
                    DebugUtility.LogVerbose(Constants.LOG_TAG, $"Cant change to area({targetAraeInfo.Uid}), because limit change to uid({m_LimitChangeToAreaUid})");
                }
            }
        }
Ejemplo n.º 8
0
        private void DoUpdate_ForcedLockingDistanceToPlayer(bool force = false)
        {
            if (m_NeedForcedLockingDistanceToPlayers == null)
            {
                return;
            }

            if (force ||
                MapManager.GetInstance()._PlayerInfo.IsGameWorldChange)
            {
                DebugUtility.LogVerbose(Constants.LOG_TAG, $"Map({m_MapUid}) Update ForcedLockingDistanceToPlayer");
                Vector3 playerGameWorldPosition = MapManager.GetInstance()._PlayerInfo.GameWorldPosition;
                for (int iGameObject = 0; iGameObject < m_NeedForcedLockingDistanceToPlayers.Count; iGameObject++)
                {
                    m_NeedForcedLockingDistanceToPlayers[iGameObject].transform.localPosition = playerGameWorldPosition
                                                                                                + m_NeedForcedLockingDistanceToPlayers[iGameObject]._DistanceToPlayer;
                }
            }
        }
Ejemplo n.º 9
0
        private void DoUpdate_NeedOriginPointOffset(bool force = false)
        {
            if (m_NeedOriginPointOffsets == null)
            {
                return;
            }

            if (force ||
                MapManager.GetInstance()._PlayerInfo.IsRealWorld2GameWorldChange)
            {
                DebugUtility.LogVerbose(Constants.LOG_TAG, $"Map({m_MapUid}) Update NeedOriginPointOffset");

                Vector3 realWorld2GameWorld = MapManager.GetInstance()._PlayerInfo.RealWorld2GameWorld;

                for (int iGameObject = 0; iGameObject < m_NeedOriginPointOffsets.Count; iGameObject++)
                {
                    Vector3 newPosition = m_NeedOriginPointOffsets[iGameObject]._RealWorldPostion
                                          + realWorld2GameWorld;

                    m_NeedOriginPointOffsets[iGameObject].transform.localPosition = newPosition;
                }
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// 更新已经过期的Area,流程
        ///		等待已经实例化过程中的Unit实例化完
        ///		这些Area内的Unit会每帧销毁一些
        ///		等到所有Unit销毁完成后,<see cref="AreaController"/>的引用会被释放
        /// </summary>
        private void DoUpdate_ExpiredArea()
        {
            for (int iArea = m_ExpiredAreaControllers.Count - 1; iArea >= 0; iArea--)
            {
                AreaController iterAreaController = m_ExpiredAreaControllers[iArea];
                iterAreaController.DoUpdate();
                if (iterAreaController.IsReleased())
                {
                    try
                    {
                        DebugUtility.Log(Constants.LOG_TAG, $"Begin Invoke OnReleasedArea({iterAreaController.GetAreaUid()})");
                        MapManager.GetInstance()._OnReleasedArea?.Invoke(iterAreaController.GetAreaUid());
                        DebugUtility.Log(Constants.LOG_TAG, $"End Invoke OnReleasedArea({iterAreaController.GetAreaUid()})");
                    }
                    catch (Exception e)
                    {
                        DebugUtility.LogError(Constants.LOG_TAG, string.Format("Invoke OnReleasedArea Exception:\n{0}", e.ToString()));
                    }

                    m_ExpiredAreaControllers.RemoveAt(iArea);
                }
            }
        }
Ejemplo n.º 11
0
        /// <summary>
        /// 加载MapInfo成功
        /// </summary>
        private void OnLoadMapInfoCompleted(string pathOrAddress, UnityEngine.Object obj, object userData)
        {
            DebugUtility.Assert(obj != null, Constants.LOG_TAG, "Load Map Info");

            DebugUtility.Log(Constants.LOG_TAG, string.Format("Map({0}) Loaded Map Info", m_MapUid));
            //m_MapInfo = obj as MapInfo;
            TextAsset text = obj as TextAsset;

            m_MapInfo = new MapInfo();
            m_MapInfo.Deserialize(text.bytes);
            m_MapInfo.Initialize();

            if (GameFacade.Instance != null)
            {
                GameplayProxy gameplayProxy = GameFacade.Instance.RetrieveProxy(ProxyName.GameplayProxy) as GameplayProxy;
                if (gameplayProxy != null)
                {
                    Vector3 realWorldPos = MapManager.GetInstance()._PlayerInfo.RealWorldPosition;
                    Vector3 gameWorldPos = gameplayProxy.WorldPositionToServerAreaOffsetPosition(realWorldPos);
                    MapManager.GetInstance().SetPlayerPosition(realWorldPos, gameWorldPos);
                }
            }
            AssetUtil.LoadSceneAsync(m_MapInfo.SceneAddressableKey, OnLoadMapSceneCompleted, null, LoadSceneMode.Additive);
        }