Exemple #1
0
        public SceneChunk(int index, SceneChunkRefData chunkRefData, GameObject chunkRoot, bool validateData)
        {
            this.index        = index;
            this.chunkRefData = chunkRefData;
            this.chunkRoot    = chunkRoot;
            this.chunkRoot.transform.localPosition = new Vector3(chunkRefData.PositionX, chunkRefData.PositionY, chunkRefData.PositionZ);
            this.chunkRoot.transform.localRotation = new Quaternion(chunkRefData.OrientationX, chunkRefData.OrientationY, chunkRefData.OrientationZ, chunkRefData.OrientationW);
            this.chunkRoot.transform.localScale    = Vector3.one;
            this.validateData = validateData;

            this.dispatcher = new Dispatcher(this);

            this.stateSet = new StateSet <States>();

            // Data loading
            var dataLoadingState = new ChunkDataLoadingState(States.DATALOADING);

            dataLoadingState.UnloadStateId = States.UNLOADING;
            this.stateSet.AddState(dataLoadingState.StateId, dataLoadingState);

            // Object loading
            var objectLoadingState = new ChunkObjectLoadingState(States.OBJECTLOADING);

            objectLoadingState.UnloadStateId = States.UNLOADING;
            this.stateSet.AddState(objectLoadingState.StateId, objectLoadingState);

            // Loaded
            var loadedState = new ChunkLoadedState(States.LOADED);

            loadedState.LoadStateId   = States.LOADED;
            loadedState.UnloadStateId = States.UNLOADING;
            this.stateSet.AddState(loadedState.StateId, loadedState);

            // Unloading
            var unloadingState = new ChunkUnloadingState(States.UNLOADING);

            this.stateSet.AddState(unloadingState.StateId, unloadingState);

            // Unloaded
            var unloadedState = new ChunkUnloadedState(States.UNLOADED);

            unloadedState.LoadStateId   = States.DATALOADING;
            unloadedState.UnloadStateId = States.UNLOADED;
            this.stateSet.AddState(unloadedState.StateId, unloadedState);

            this.controller = new StateMachine(this);
            _ChangeState(States.UNLOADED);

            if (SceneLevel.IsInEdit())
            {
                var chunkObject = SceneLevel.GetOrAddComponent <ChunkObject>(this.chunkRoot);
                chunkObject.Path = chunkRefData.Path;
            }
        }
Exemple #2
0
        private void _Read(TableStreamReader reader)
        {
            reader.Blob("SceneLevelData", () =>
            {
                this.Name = reader.ReadKeyString("Name");

                this.ChunkWidth  = (float)reader.ReadKeyFloat("ChunkWidth");
                this.ChunkHeight = (float)reader.ReadKeyFloat("ChunkHeight");

                this.ChunkColumns = (int)reader.ReadKeyNumber("ChunkColumns");
                this.ChunkRows    = (int)reader.ReadKeyNumber("ChunkRows");

                this.Chunks = new List <SceneChunkRefData>();
                var count   = reader.ReadKeyNumber("Chunks");
                for (var i = 0; i < count; ++i)
                {
                    var chunkRefData = new SceneChunkRefData();
                    chunkRefData._Read(reader);
                    this.Chunks.Add(chunkRefData);
                }
            });
        }
Exemple #3
0
        private void _ReadAsync(TableStreamAsyncReader reader)
        {
            reader.Blob("SceneLevelData", () =>
            {
                reader.ReadKeyString("Name", name => { this.Name = name; });

                reader.ReadKeyFloat("ChunkWidth", chunkWidth => { this.ChunkWidth = (float)chunkWidth; });
                reader.ReadKeyFloat("ChunkHeight", chunkHeight => { this.ChunkHeight = (float)chunkHeight; });

                reader.ReadKeyNumber("ChunkColumns", chunkColumns => { this.ChunkColumns = (int)chunkColumns; });
                reader.ReadKeyNumber("ChunkRows", chunkRows => { this.ChunkRows = (int)chunkRows; });

                this.Chunks = new List <SceneChunkRefData>();
                reader.ReadKeyNumber("Chunks", count =>
                {
                    for (var i = 0; i < count; ++i)
                    {
                        var chunkRefData = new SceneChunkRefData();
                        chunkRefData._ReadAsync(reader);
                        this.Chunks.Add(chunkRefData);
                    }
                });
            });
        }