コード例 #1
0
        public void LoadAsync(Vector3 position, Quaternion orientation, LevelLoadPolicy policy, Action handler)
        {
            this.policy = policy;

            ServiceCenter.GetService <IAssetManager>().LoadAsync(levelPath + ".bytes", AssetType.BYTES, asset =>
            {
                if (null != asset)
                {
                    var stream = new MemoryStream(asset.Cast <byte[]>());
                    SceneLevelData.DeserializeAsync(stream, this.validateData, levelData =>
                    {
                        stream.Close();
                        stream.Dispose();

                        _InitData(levelData);

                        switch (this.policy)
                        {
                        case LevelLoadPolicy.ALL:
                            _LoadAllChunksAsync(() =>
                            {
                                this.currentChunk = _FindChunk(position.x, position.z);
                                this.currentChunk.OnEnter();
                                _NotifyCompleted(handler);
                            });
                            break;

                        case LevelLoadPolicy.SURROUNDING:
                            // Start to load related chunks
                            this.currentChunk = _FindChunk(position.x, position.z);
                            if (null != this.currentChunk)
                            {
                                this.currentChunk.LoadAsync((target, message) =>
                                {
                                    this.currentChunk.OnEnter();
                                    _NotifyCompleted(handler);
                                });
                            }

                            _LoadNearChunksAsync(this.currentChunk.Index);
                            break;
                        }
                    });
                }
                asset.Dispose();
            });
        }
コード例 #2
0
ファイル: LevelSystem.cs プロジェクト: Hengle/Unity3D-1
 public void LoadLevelAsync(ISceneCharacter character, string levelPath, LevelLoadPolicy policy, GameObject levelRoot, Action handler)
 {
     this.character = character;
     this.level     = new SceneLevel(levelPath, null != levelRoot ? levelRoot : new GameObject("_Level"), this.validateData);
     this.level.LoadAsync(this.character.Position, this.character.Orientation, policy, handler);
 }