Пример #1
0
        public override void Enter(StateMachine stateMachine)
        {
            this.completed = false;

            var chunk = stateMachine.Model as SceneChunk;

            chunk._Objects = new List <SceneObject>();
            ServiceCenter.GetService <IAssetManager>().LoadAsync(chunk._ChunkRefData.Path + ".bytes", AssetType.BYTES, asset =>
            {
                if (null != asset)
                {
                    var stream = new MemoryStream(asset.Cast <byte[]>());
                    SceneChunkData.DeserializeAsync(stream, chunk._ValidateData, chunkData =>
                    {
                        stream.Close();
                        stream.Dispose();
                        for (var i = 0; i < chunkData.Objects.Count; ++i)
                        {
                            var go = new GameObject();
                            go.transform.SetParent(chunk._ChunkRoot.transform);

                            var objectData  = chunkData.Objects[i];
                            SceneObject obj = null;
                            switch (objectData.Type)
                            {
                            case SceneObjectType.PREFAB:
                                obj     = new ScenePrefab(objectData, go);
                                go.name = "_Prefab";
                                break;

                            case SceneObjectType.LIGHTMODIFIER:
                                obj     = new SceneLightModifier(objectData, go);
                                go.name = "_LightModifier";
                                break;

                            default:
                                go.name = "_SceneObject";
                                break;
                            }
                            chunk._Objects.Add(obj);
                        }

                        this.completed = true;
                    });
                }
                asset.Dispose();
            });
        }
Пример #2
0
        public void Load()
        {
            using (var asset = ServiceCenter.GetService <IAssetManager>().Load(this.chunkRefData.Path + ".bytes", AssetType.BYTES)) {
                var bytes = asset.Cast <byte[]>();
                if (null != bytes)
                {
                    this.objects = new List <SceneObject>();
                    using (var stream = new MemoryStream(bytes)) {
                        var chunkData = SceneChunkData.Deserialize(stream, this.validateData);
                        for (var i = 0; i < chunkData.Objects.Count; ++i)
                        {
                            var go = new GameObject();
                            go.transform.SetParent(this.chunkRoot.transform);

                            var         objectData = chunkData.Objects[i];
                            SceneObject obj        = null;
                            switch (objectData.Type)
                            {
                            case SceneObjectType.PREFAB:
                                obj     = new ScenePrefab(objectData, go);
                                go.name = "_Prefab";
                                break;

                            case SceneObjectType.LIGHTMODIFIER:
                                obj     = new SceneLightModifier(objectData, go);
                                go.name = "_LightModifier";
                                break;

                            default:
                                go.name = "_SceneObject";
                                break;
                            }
                            this.objects.Add(obj);
                            obj.Load();
                        }
                    }
                }
            }
        }