示例#1
0
        private void _InitData(SceneLevelData levelData)
        {
            this.chunkWidth   = levelData.ChunkWidth;
            this.chunkHeight  = levelData.ChunkHeight;
            this.chunkColumns = levelData.ChunkColumns;
            this.chunkRows    = levelData.ChunkRows;
            this.chunks       = new SceneChunk[this.chunkColumns * this.chunkRows];

            for (var i = 0; i < levelData.Chunks.Count; ++i)
            {
                var chunkRefData = levelData.Chunks[i];
                var x            = chunkRefData.PositionX / this.chunkWidth;
                var z            = chunkRefData.PositionZ / this.chunkHeight;
                var index        = Mathf.FloorToInt(z * this.chunkColumns + x);
                var go           = new GameObject("_Chunk");
                go.transform.SetParent(this.levelRoot.transform);

                var chunk = new SceneChunk(index, chunkRefData, go, this.validateData);
                this.chunks[index] = chunk;
            }

            if (SceneLevel.IsInEdit())
            {
                var levelObject = SceneLevel.GetOrAddComponent <LevelObject>(this.levelRoot);
                levelObject.Path         = this.levelPath;
                levelObject.ChunkWidth   = this.chunkWidth;
                levelObject.ChunkHeight  = this.chunkHeight;
                levelObject.ChunkColumns = this.chunkColumns;
                levelObject.ChunkRows    = this.chunkRows;
            }
        }
示例#2
0
 public ScenePrefab(SceneObjectData objectData, GameObject objectRoot) : base(objectData, objectRoot)
 {
     if (SceneLevel.IsInEdit())
     {
         var prefabObject = SceneLevel.GetOrAddComponent <PrefabObject>(this.ObjectRoot);
         prefabObject.PrefabPath = (this.ObjectData as ScenePrefabData).Path;
     }
 }
示例#3
0
        /// <summary>
        ///
        /// </summary>
        public void Load()
        {
            Clear();

            var level = new SceneLevel(this.Path, this.gameObject, true);

            level.Load(Vector3.zero, Quaternion.identity);
        }
示例#4
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;
            }
        }
示例#5
0
 public override void Dispose()
 {
     if (!SceneLevel.IsInEdit())
     {
         for (var i = 0; i < this.chunks.Length; ++i)
         {
             if (null != this.chunks[i])
             {
                 this.chunks[i].Dispose();
             }
         }
         this.chunks = null;
     }
 }
示例#6
0
        public SceneLightModifier(SceneObjectData objectData, GameObject objectRoot) : base(objectData, objectRoot)
        {
            var modifierData = objectData as SceneLightModifierData;

            this.targetIntensity = modifierData.Intensity;
            this.targetColor     = new Color(modifierData.Red, modifierData.Green, modifierData.Blue);

            if (SceneLevel.IsInEdit())
            {
                var modifierObject = SceneLevel.GetOrAddComponent <LightModifierObject>(this.ObjectRoot);
                modifierObject.Intensity = this.targetIntensity;
                modifierObject.Color     = this.targetColor;
            }
        }