コード例 #1
0
        public AssetManagerWorld(
            IAssetManagerProvider assetManagerProvider,
            I2DRenderUtilities renderUtilities,
            ISkin skin,
            IAssetLoader[] loaders)
        {
            this.Entities = new List <IEntity>();
            this.m_Skin   = skin;
            this.m_Start  = DateTime.Now;

            // Add the asset manager layout.
            var entity = new CanvasEntity(this.m_Skin);

            this.m_Layout = new AssetManagerLayout(assetManagerProvider, renderUtilities, loaders, entity);
            entity.Canvas = this.m_Layout;
            this.Entities.Add(entity);

            this.m_Layout.MarkDirty.Click += (sender, e) =>
            {
                foreach (var asset in this.AssetManager.GetAll())
                {
                    this.AssetManager.Dirty(asset.Name);
                }
            };

            this.m_Layout.Bake.Click += (sender, e) =>
            {
                if (this.m_CurrentEditor != null)
                {
                    this.m_CurrentEditor.Bake(this.AssetManager);
                }
                var item = this.m_Layout.AssetTree.SelectedItem as AssetTreeItem;
                if (item == null)
                {
                    return;
                }
                this.AssetManager.Bake(item.Asset);
            };

            this.m_Layout.AssetTree.SelectedItemChanged += (sender, e) =>
            {
                if (this.m_CurrentEditor != null)
                {
                    this.m_CurrentEditor.FinishLayout(this.m_Layout.EditorContainer, this.AssetManager);
                }
                var item = this.m_Layout.AssetTree.SelectedItem as AssetTreeItem;
                if (item != null && m_Editors.ContainsKey(item.Asset.GetType()))
                {
                    this.m_CurrentEditor = m_Editors[item.Asset.GetType()];
                    this.m_CurrentEditor.SetAsset(item.Asset);
                    this.m_CurrentEditor.BuildLayout(this.m_Layout.EditorContainer, this.AssetManager);
                }
                else
                {
                    this.m_CurrentEditor = null;
                    this.m_Layout.EditorContainer.SetChild(
                        new Label {
                        Text = "No editor for " + (item == null ? "folders" : item.Asset.GetType().Name)
                    });
                }
            };

            this.m_Layout.ExitClick += (sender, e) =>
            {
                Environment.Exit(0);
            };

            this.m_Layout.BakeAllClick += (sender, e) =>
            {
                foreach (var asset in this.AssetManager.GetAll())
                {
                    this.AssetManager.Bake(asset);
                }
            };

            this.m_Layout.CreateNameEntered += (sender, e) =>
            {
                var asset = e.Loader.GetNew(this.AssetManager, this.m_Layout.PromptName.Text);
                assetManagerProvider.GetAssetManager(false).Bake(asset);
                this.m_Layout.AssetTree.AddChild(new AssetTreeItem
                {
                    Text  = this.m_Layout.PromptName.Text,
                    Asset = asset
                });
            };
        }
コード例 #2
0
        public AssetManagerWorld(
            IAssetManagerProvider assetManagerProvider,
            I2DRenderUtilities renderUtilities,
            ISkin skin,
            IAssetLoader[] loaders)
        {
            this.Entities = new List<IEntity>();
            this.m_Skin = skin;
            this.m_Start = DateTime.Now;

            // Add the asset manager layout.
            var entity = new CanvasEntity(this.m_Skin);
            this.m_Layout = new AssetManagerLayout(assetManagerProvider, renderUtilities, loaders, entity);
            entity.Canvas = this.m_Layout;
            this.Entities.Add(entity);

            this.m_Layout.MarkDirty.Click += (sender, e) =>
            {
                foreach (var asset in this.AssetManager.GetAll())
                    this.AssetManager.Dirty(asset.Name);
            };

            this.m_Layout.Bake.Click += (sender, e) =>
            {
                if (this.m_CurrentEditor != null)
                    this.m_CurrentEditor.Bake(this.AssetManager);
                var item = this.m_Layout.AssetTree.SelectedItem as AssetTreeItem;
                if (item == null)
                    return;
                this.AssetManager.Bake(item.Asset);
            };

            this.m_Layout.AssetTree.SelectedItemChanged += (sender, e) =>
            {
                if (this.m_CurrentEditor != null)
                    this.m_CurrentEditor.FinishLayout(this.m_Layout.EditorContainer, this.AssetManager);
                var item = this.m_Layout.AssetTree.SelectedItem as AssetTreeItem;
                if (item != null && m_Editors.ContainsKey(item.Asset.GetType()))
                {
                    this.m_CurrentEditor = m_Editors[item.Asset.GetType()];
                    this.m_CurrentEditor.SetAsset(item.Asset);
                    this.m_CurrentEditor.BuildLayout(this.m_Layout.EditorContainer, this.AssetManager);
                }
                else
                {
                    this.m_CurrentEditor = null;
                    this.m_Layout.EditorContainer.SetChild(
                        new Label { Text = "No editor for " + (item == null ? "folders" : item.Asset.GetType().Name) });
                }
            };

            this.m_Layout.ExitClick += (sender, e) =>
            {
                Environment.Exit(0);
            };

            this.m_Layout.BakeAllClick += (sender, e) =>
            {
                foreach (var asset in this.AssetManager.GetAll())
                    this.AssetManager.Bake(asset);
            };

            this.m_Layout.CreateNameEntered += (sender, e) =>
            {
                var asset = e.Loader.GetNew(this.AssetManager, this.m_Layout.PromptName.Text);
                assetManagerProvider.GetAssetManager(false).Bake(asset);
                this.m_Layout.AssetTree.AddChild(new AssetTreeItem
                {
                    Text = this.m_Layout.PromptName.Text,
                    Asset = asset
                });
            };
        }