Пример #1
0
    //--------------------------------------------------------------------------
    public void TransitionToChunk(WorldDirection chunkDir, string sceneName)
    {
        WorldChunkIndex newChunkIndex = _currentIndx + WorldDirectionUtils.GetWorldChunkOffset(chunkDir);

        // make sure we have the chunk cached (else, we should be warping)
        WorldChunk newChunk = _chunkCache[newChunkIndex];

        DebugUtils.Assert(newChunk != null, "WorldManager::Transition() - '{0}' was not cached at ({1},{2}), try calling WarpToChunk() instead.",
                          sceneName, newChunkIndex.x, newChunkIndex.y);

        // switch focus to the new chunk
        newChunk.AddLoadCompleteDelegate(delegate(string loadedSceneName) {
            DebugUtils.Assert(loadedSceneName == sceneName, "WorldManager::Transition() - '{0}' was not the chunk we found at ({1},{2}), '{3}' was",
                              sceneName, newChunkIndex.x, newChunkIndex.y, loadedSceneName);

            SetFocusedChunk(sceneName, newChunkIndex);
        });
    }
Пример #2
0
    //--------------------------------------------------------------------------
    private void SetFocusedChunk(string chunkName, WorldChunkIndex atIndex)
    {
        //--------------------------------------
        // deactivate old chunk block
        //--------------------------------------

        WorldChunk oldChunk = _chunkCache[_currentIndx];

        if (oldChunk != null)
        {
            oldChunk.AddLoadCompleteDelegate(delegate(string sceneName) {
                oldChunk.focused = false;
            });
        }
        _chunkCache.SetChunkBlockActive(_currentIndx, false, chunkBlockSize, chunkBlockSize);

        //--------------------------------------
        // load new chunk block
        //--------------------------------------

        int leftOffset   = ((int)chunkBlockSize - 1) / 2;
        int rightOffset  = (int)Math.Ceiling((chunkBlockSize - 1) / 2.0f);
        int topOffset    = leftOffset;
        int bottomOffset = rightOffset;

        WorldChunk focusedChunk = LoadChunkBlock(atIndex.x, atIndex.y, chunkName, leftOffset, rightOffset, topOffset, bottomOffset);

        //--------------------------------------
        // shift camera & chunk index
        //--------------------------------------

        focusedChunk.AddLoadCompleteDelegate(delegate(string sceneName) {
            focusedChunk.focused = true;

            Vector3 newCamPos = focusedChunk.root.transform.position;
            newCamPos.z       = WorldZLayers.kCameraZLayer;
            Camera.mainCamera.transform.position = newCamPos;

            _currentIndx = atIndex;
        });
        _chunkCache.SetChunkBlockActive(atIndex, true, chunkBlockSize, chunkBlockSize);
    }