示例#1
0
        [Test] public void RequestContent()
        {
            // Create a test resource and save it somewhere to be retrieved later
            Pixmap resource = new Pixmap();
            string path     = PathOp.Combine(DualityApp.DataDirectory, "Test" + Resource.GetFileExtByType <Pixmap>());

            resource.Save(path, false);
            resource.Dispose();
            resource = null;

            // Request the resource from its path and expect it to be valid
            Assert.IsNotNull(ContentProvider.RequestContent <Pixmap>(path).Res);
            Assert.IsNotNull(ContentProvider.RequestContent(path).Res);
            Assert.IsTrue(ContentProvider.HasContent(path));
            CollectionAssert.Contains(ContentProvider.GetLoadedContent <Pixmap>(), new ContentRef <Pixmap>(null, path));
            CollectionAssert.Contains(ContentProvider.GetAvailableContent <Pixmap>(), new ContentRef <Pixmap>(null, path));

            // Request the resource multiple times and expect the same instance to be returned
            ContentRef <Pixmap> requestA = ContentProvider.RequestContent <Pixmap>(path);
            ContentRef <Pixmap> requestB = ContentProvider.RequestContent <Pixmap>(path);

            Assert.AreEqual(requestA, requestB);
            Assert.AreSame(requestA.Res, requestB.Res);

            // Dispose the resource and expect an automatic reload on access
            Pixmap oldResource = requestA.Res;

            oldResource.Dispose();
            Assert.IsNotNull(requestA.Res);
            Assert.IsNotNull(requestB.Res);
            Assert.AreEqual(requestA, requestB);
            Assert.AreSame(requestA.Res, requestB.Res);
        }
示例#2
0
文件: Style.cs 项目: Seti-0/blue
 public static ContentRef <Style <T> > GetDefault <T>() where T : class
 {
     return(ContentProvider
            .GetAvailableContent <Style <T> >()
            .Where(x => x.Res != null && x.Res.Default)
            .FirstOrDefault());
 }
示例#3
0
        public static void OnGameStart()
        {
            SceneSelector selector = null;

            foreach (var scene in ContentProvider.GetAvailableContent <Scene>())
            {
                selector = scene.Res?.FindComponent <SceneSelector>() ?? selector;
            }

            if (selector == null)
            {
                Logs.Game.WriteWarning("Unable to set scenes, SceneSelector not found.");
            }
            else
            {
                _gameScene = selector.Game;
                _menuScene = selector.Menu;


                if (_gameScene.Res == null || _menuScene.Res == null)
                {
                    Logs.Game.WriteWarning("Scene Selector ContentRefs aren't available, unable to set scenes.");
                }
            }

            OldContext.ClearNotifications();
        }
示例#4
0
        private void VerifyStartScene()
        {
            if (DualityApp.AppData.StartScene != null)
            {
                return;
            }

            // If there is no StartScene defined, attempt to find one automatically.
            if (!Scene.Current.IsRuntimeResource)
            {
                DualityApp.AppData.StartScene = Scene.Current;
                DualityApp.SaveAppData();
            }
            else
            {
                ContentRef <Scene> existingScene = ContentProvider.GetAvailableContent <Scene>().FirstOrDefault();
                if (existingScene != null)
                {
                    DualityApp.AppData.StartScene = existingScene;
                    DualityApp.SaveAppData();
                }
                else if (!Scene.Current.IsEmpty)
                {
                    DualityEditorApp.SaveCurrentScene(false);
                    DualityApp.AppData.StartScene = Scene.Current;
                    DualityApp.SaveAppData();
                }
            }
        }
        public override void ShowObjectSelector()
        {
            var objectSelector = new ObjectSelector
            {
                StartPosition = FormStartPosition.CenterScreen,
                Text          = "Select " + editedResType.Name
            };

            objectSelector.SetTreeViewItems(ContentProvider.GetAvailableContent(editedResType)
                                            .Select(c => new Node(c.Name)
            {
                Tag = c
            })
                                            .OrderBy(n => n.Text));

            var result = objectSelector.ShowDialog();

            if (result == DialogResult.Cancel)
            {
                return;
            }

            var selectedObject = objectSelector.SelectedObject;

            UpdateContentPath(selectedObject != null ? selectedObject.Path : null);
        }
示例#6
0
        public void OnActivate()
        {
            if (DualityApp.ExecEnvironment == DualityApp.ExecutionEnvironment.Editor)
            {
                return;
            }

            this.gameBoardComponent = GameObj.Scene.FindComponent <GameBoardComponent>();
            this.transform          = GameObj.GetComponent <Transform>();

            //Preload the game assets
            this.playerOneMat = ContentProvider.GetAvailableContent <Material>().Where(c => c.Name == "alienPink").FirstOrDefault();
            this.playerOneMat.EnsureLoaded();
            this.playerTwoMat = ContentProvider.GetAvailableContent <Material>().Where(c => c.Name == "alienGreen").FirstOrDefault();
            this.playerTwoMat.EnsureLoaded();
            this.playerThreeMat = ContentProvider.GetAvailableContent <Material>().Where(c => c.Name == "alienBeige").FirstOrDefault();
            this.playerThreeMat.EnsureLoaded();
            this.playerFourMat = ContentProvider.GetAvailableContent <Material>().Where(c => c.Name == "alienYellow").FirstOrDefault();
            this.playerFourMat.EnsureLoaded();

            playerList = new List <GameObject>();

            //Create the players off screen
            for (int playerNumber = 1; playerNumber <= 4; playerNumber++)
            {
                GameObject player          = new GameObject("Player" + playerNumber);
                Transform  playerTransform = new Transform();
                playerTransform.Pos = new Vector3(-2000, -2000, 0); //Create the coin way off screen

                player.AddComponent(playerTransform);

                SpriteRenderer tempCoinSpriteRenderer = new SpriteRenderer();
                tempCoinSpriteRenderer.DepthOffset = -10;

                switch (playerNumber)
                {
                case 1:
                    tempCoinSpriteRenderer.SharedMaterial = playerOneMat;
                    break;

                case 2:
                    tempCoinSpriteRenderer.SharedMaterial = playerTwoMat;
                    break;

                case 3:
                    tempCoinSpriteRenderer.SharedMaterial = playerThreeMat;
                    break;

                case 4:
                    tempCoinSpriteRenderer.SharedMaterial = playerFourMat;
                    break;
                }

                tempCoinSpriteRenderer.Rect = new Rect(0, 0, 66, 92);

                player.AddComponent(tempCoinSpriteRenderer);
                playerList.Add(player);
                GameObj.Scene.AddObject(player);
            }
        }
示例#7
0
        public void OnActivate()
        {
            if (DualityApp.ExecEnvironment == DualityApp.ExecutionEnvironment.Editor)
            {
                return;
            }

            //Preload the game assets
            this.tileMat = ContentProvider.GetAvailableContent <Material>().Where(c => c.Name == "tile").FirstOrDefault();
            this.tileMat.EnsureLoaded();

            this.coinMat = ContentProvider.GetAvailableContent <Material>().Where(c => c.Name == "coinGold").FirstOrDefault();
            this.coinMat.EnsureLoaded();

            this.transform          = GameObj.GetComponent <Transform>();
            this.gameBoardComponent = GameObj.Scene.FindComponent <GameBoardComponent>();

            //Setup the game board
            for (int widthIndex = 0; widthIndex < this.gameBoardComponent.GameBoard.Width(); widthIndex++)
            {
                for (int heightIndex = 0; heightIndex < this.gameBoardComponent.GameBoard.Height(); heightIndex++)
                {
                    GameObject tempTileGameObject = new GameObject("Tile_" + widthIndex + "_" + heightIndex);
                    Transform  tempTileTransform  = new Transform();
                    //TODO: make this more flexible/configurable?
                    tempTileTransform.Pos = new Vector3(-225 + 150 * widthIndex, -225 + 150 * heightIndex, 0);

                    tempTileGameObject.AddComponent(tempTileTransform);

                    SpriteRenderer tempTileSpriteRenderer = new SpriteRenderer();
                    tempTileSpriteRenderer.DepthOffset    = 0;
                    tempTileSpriteRenderer.SharedMaterial = tileMat;
                    tempTileSpriteRenderer.Rect           = new Rect(0, 0, 128, 128);

                    tempTileGameObject.AddComponent(tempTileSpriteRenderer);
                    GameObj.Scene.AddObject(tempTileGameObject);
                    boardTileList.Add(tempTileGameObject);

                    //Create the coin pool - only have 5 non-player tiles currently.  Maybe make this more generic down the road.
                    for (int coinIndex = 0; coinIndex < this.gameBoardComponent.GameBoard.MaxCoinsPerTile(); coinIndex++)
                    {
                        GameObject tempCoinGameObject = new GameObject("Coin" + "_" + widthIndex + "_" + heightIndex + "_" + coinIndex);
                        Transform  tempCoinTransform  = new Transform();
                        tempCoinTransform.Pos = new Vector3(-2000, -2000, 0); //Create the coin way off screen

                        tempCoinGameObject.AddComponent(tempCoinTransform);

                        SpriteRenderer tempCoinSpriteRenderer = new SpriteRenderer();
                        tempCoinSpriteRenderer.DepthOffset    = -10;
                        tempCoinSpriteRenderer.SharedMaterial = coinMat;
                        tempCoinSpriteRenderer.Rect           = new Rect(0, 0, 64, 64);

                        tempCoinGameObject.AddComponent(tempCoinSpriteRenderer);
                        GameObj.Scene.AddObject(tempCoinGameObject);
                        coinPoolList.Add(tempCoinGameObject);
                    }
                }
            }
        }
示例#8
0
#pragma warning disable 1591
        protected override void OnGameStarting()
#pragma warning restore 1591
        {
            var logger = new LoggerAdapter(Logs.Game);
            IEnumerable <SingularityModules> moduleResources = ContentProvider.GetAvailableContent <SingularityModules>().Select(x => x.Res);

            _gameScope = new GameScope(logger, new SceneScopeFactory(), new SceneEventsProvider(), moduleResources);
        }
示例#9
0
 void ICmpInitializable.OnInit(Component.InitContext context)
 {
     if (context == InitContext.Activate && DualityApp.ExecContext == DualityApp.ExecutionContext.Game)
     {
         // Retrieve a list of all available scenes to cycle through.
         this.sampleScenes = ContentProvider.GetAvailableContent <Scene>();
     }
 }
示例#10
0
        public void EnterBenchmarkMode()
        {
            // Retrieve a list of all available scenes to cycle through.
            this.benchmarkScenes = ContentProvider.GetAvailableContent <Scene>();
            this.renderSetup     = ContentProvider.GetAvailableContent <BenchmarkRenderSetup>().FirstOrDefault();

            // Make sure the benchmark setup is used globally
            DualityApp.AppData.Instance.RenderingSetup = this.renderSetup.As <RenderSetup>();
        }
示例#11
0
        [Test] public void AddRemoveContent()
        {
            Pixmap resource = new Pixmap();
            string alias    = "Foo";


            // Register the new resource with the provider
            ContentProvider.AddContent(alias, resource);

            // Expect it to be registered and show up in all relevant API calls
            Assert.IsTrue(ContentProvider.HasContent(alias));
            Assert.AreSame(resource, ContentProvider.RequestContent <Pixmap>(alias).Res);
            Assert.AreSame(resource, ContentProvider.RequestContent(alias).Res);
            CollectionAssert.Contains(ContentProvider.GetLoadedContent <Pixmap>(), (ContentRef <Pixmap>)resource);

            // Expect it to not show up in specialized API calls that have nothing to do with the registered resource
            CollectionAssert.DoesNotContain(ContentProvider.GetDefaultContent <Pixmap>(), (ContentRef <Pixmap>)resource);
            CollectionAssert.DoesNotContain(ContentProvider.GetAvailableContent <Pixmap>(), (ContentRef <Pixmap>)resource);

            // Expect the resource itself to reference back to its new primary path
            Assert.AreEqual(alias, resource.Path);
            Assert.IsFalse(resource.IsRuntimeResource);


            // Un-register the new resource, but don't dispose it
            ContentProvider.RemoveContent(alias, false);

            // Expect the resource to still be valid
            Assert.IsFalse(resource.Disposed);

            // Expect it to no longer show up in any of the relevant API calls
            Assert.IsFalse(ContentProvider.HasContent(alias));
            Assert.IsNull(ContentProvider.RequestContent <Pixmap>(alias).Res);
            Assert.IsNull(ContentProvider.RequestContent(alias).Res);
            CollectionAssert.DoesNotContain(ContentProvider.GetLoadedContent <Pixmap>(), (ContentRef <Pixmap>)resource);

            // Expect the resource itself to no longer back-reference to its former path
            Assert.IsNull(resource.Path);
            Assert.IsTrue(resource.IsRuntimeResource);


            // Re-register the resource, and immediately unregister-dispose it afterwards
            ContentProvider.AddContent(alias, resource);
            ContentProvider.RemoveContent(alias, true);

            // Expect the resource to be disposed and no longer show up in API calls
            Assert.IsTrue(resource.Disposed);
            Assert.IsFalse(ContentProvider.HasContent(alias));
            Assert.IsNull(ContentProvider.RequestContent <Pixmap>(alias).Res);
            Assert.IsNull(ContentProvider.RequestContent(alias).Res);
            CollectionAssert.DoesNotContain(ContentProvider.GetLoadedContent <Pixmap>(), (ContentRef <Pixmap>)resource);

            // Expect the resource path to remain unchanged, in order to allow reload-recovery
            Assert.AreEqual(alias, resource.Path);
            Assert.IsFalse(resource.IsRuntimeResource);
        }
示例#12
0
        private static Scene BuildScene()
        {
            Scene splash = new Scene();

            GameObject camera = new GameObject();

            camera.AddComponent <Transform>();
            camera.GetComponent <Transform>().Pos = new Vector3(0, 0, -500);
            camera.AddComponent <Camera>();
            camera.GetComponent <Camera>().ClearColor = _background;
            splash.AddObject(camera);

            int i = 0;

            foreach (string s in _logos)
            {
                ContentRef <Material> logo = ContentProvider.GetAvailableContent <Material>().FirstOrDefault(l => l.Name == s);
                Texture tx = logo.Res?.MainTexture.Res;

                if (tx != null)
                {
                    BatchInfo bi = new BatchInfo(logo.Res);
                    bi.Technique = DrawTechnique.Alpha;

                    GameObject sprite = new GameObject();
                    sprite.AddComponent <Transform>();
                    sprite.AddComponent <SpriteRenderer>();
                    sprite.AddComponent <SpriteRenderer>().ColorTint      = Colors.TransparentWhite;
                    sprite.GetComponent <SpriteRenderer>().Rect           = new Rect(tx.Size).WithOffset(-tx.Size / 2);
                    sprite.GetComponent <SpriteRenderer>().CustomMaterial = bi;
                    sprite.AddComponent <SpriteOrder>();
                    sprite.GetComponent <SpriteOrder>().Order = i;

                    splash.AddObject(sprite);
                    i++;
                }
            }

            Texture   duality   = Material.DualityLogoBig.Res.MainTexture.Res;
            BatchInfo dualityBi = new BatchInfo(Material.DualityLogoBig.Res);

            dualityBi.Technique = DrawTechnique.Alpha;

            GameObject dualityLogo = new GameObject();

            dualityLogo.AddComponent <Transform>();
            dualityLogo.AddComponent <SpriteRenderer>();
            dualityLogo.AddComponent <SpriteRenderer>().ColorTint      = Colors.TransparentWhite;
            dualityLogo.GetComponent <SpriteRenderer>().Rect           = new Rect(duality.Size).WithOffset(-duality.Size / 2);
            dualityLogo.GetComponent <SpriteRenderer>().CustomMaterial = dualityBi;
            dualityLogo.AddComponent <SpriteOrder>();
            dualityLogo.GetComponent <SpriteOrder>().Order = i;
            splash.AddObject(dualityLogo);

            return(splash);
        }
示例#13
0
 public void OnInit(Component.InitContext context)
 {
     if (context == InitContext.Loaded)
     {
         foreach (ContentRef <Resource> res in ContentProvider.GetAvailableContent <Resource>())
         {
             res.MakeAvailable();
         }
     }
 }
示例#14
0
        void ICmpInitializable.OnActivate()
        {
            if (DualityApp.ExecContext != DualityApp.ExecutionContext.Game)
            {
                return;
            }

            // Retrieve a list of all available scenes to cycle through.
            this.sampleScenes = ContentProvider.GetAvailableContent <Scene>();
        }
示例#15
0
        private void LoadTabs()
        {
            spriteTabContainer.SelectedIndexChanged += (o, e) => LoadTabButtons(spriteTabContainer.SelectedIndex);
            _sprites = ContentProvider.GetAvailableContent <Sprite>();
            var tabItems = _sprites.GroupBy(s => s.Res.EditorCategory);

            foreach (var tabItem in tabItems)
            {
                var tab = new TabPage(tabItem.Key);
                spriteTabContainer.Controls.Add(tab);
                tab.Tag = tabItem.ToArray();
            }
            _tabLoadStatus = Enumerable.Repeat(false, spriteTabContainer.TabCount).ToArray();

            // load first tab
            LoadTabButtons(0);
        }
示例#16
0
        protected override void OnGameStarting()
        {
            base.OnGameStarting();

            // Load all available content so we don't need on-demand loading at runtime.
            // It's probably not a good idea for content-rich games, consider having a per-level
            // loading screen instead, or something similar.
            Log.Game.Write("Loading game content...");
            Log.Game.PushIndent();
            {
                List <ContentRef <Resource> > availableContent = ContentProvider.GetAvailableContent <Resource>();
                foreach (ContentRef <Resource> resourceReference in availableContent)
                {
                    resourceReference.MakeAvailable();
                }
            }
            Log.Game.PopIndent();
        }
示例#17
0
        private void LoadTabs()
        {
            tabControl1.SelectedIndexChanged += (o, e) => LoadTabButtons(tabControl1.SelectedIndex);
            _sprites = ContentProvider.GetAvailableContent <SpriteAtlas>();
            var tabItems = _sprites.SelectMany(s => s.Res.Sprites.Select(t => new TabItemInfo(s.Res.Pixmap, t.Key, t.Value)))
                           .Where(s => s.Pixmap != null && s.Pixmap.Res.Atlas != null && s.Pixmap.Res.Atlas.Count > 0)
                           .GroupBy(s => s.Key.Split('/')[0]);

            foreach (var item in tabItems)
            {
                var tab = new TabPage(item.Key);
                tabControl1.Controls.Add(tab);
                tab.Tag = item.ToArray();
            }
            _tabLoadStatus = Enumerable.Repeat(false, tabControl1.TabCount).ToArray();

            LoadTabButtons(0);
        }
示例#18
0
        protected override void OnBeforeUpdate()
        {
            base.OnBeforeUpdate();

            // Load all available content so we don't need on-demand loading during runtime.
            // It's probably not a good idea for content-rich games, consider having a per-level
            // loading screen instead, or something similar.
            if (!this.contentLoaded && DualityApp.ExecContext == DualityApp.ExecutionContext.Game)
            {
                Log.Game.Write("Loading game content...");
                Log.Game.PushIndent();
                {
                    List <ContentRef <Resource> > availableContent = ContentProvider.GetAvailableContent <Resource>();
                    foreach (ContentRef <Resource> resourceReference in availableContent)
                    {
                        resourceReference.MakeAvailable();
                    }
                }
                Log.Game.PopIndent();
                this.contentLoaded = true;
            }
        }
示例#19
0
		void ICmpUpdatable.OnUpdate()
		{
			if (DualityApp.Keyboard.KeyHit(Key.Escape))
			{
				DualityApp.Terminate();
			}
			if (DualityApp.Keyboard.KeyHit(Key.Space))
			{
				//preloading materials and sounds
				foreach (ContentRef<Material> m in ContentProvider.GetAvailableContent<Material>())
				{
					m.EnsureLoaded();
				}
				foreach (ContentRef<Sound> s in ContentProvider.GetAvailableContent<Sound>())
				{
					s.EnsureLoaded();
				}

				GameScene.Res.FindComponent<GameController>().Reset();

				Scene.SwitchTo(GameScene);
			}
		}
示例#20
0
        public static void NotifyFileRenamed(string filePathOld, string filePathNew)
        {
            if (string.IsNullOrEmpty(filePathOld))
            {
                return;
            }

            // Find an importer to handle the file rename
            IFileImporter importer = importers.FirstOrDefault(i => i.CanImportFile(filePathOld));

            if (importer == null)
            {
                return;
            }

            // Guess which Resources are affected and check them first
            string fileBaseName = Path.GetFileNameWithoutExtension(Path.GetFileNameWithoutExtension(filePathOld));
            List <ContentRef <Resource> > checkContent = ContentProvider.GetAvailableContent <Resource>();

            for (int i = 0; i < checkContent.Count; ++i)
            {
                ContentRef <Resource> resRef = checkContent[i];
                if (resRef.Name == fileBaseName)
                {
                    checkContent.RemoveAt(i);
                    checkContent.Insert(0, resRef);
                }
            }

            // Iterate over all existing Resources to find out which one to modify.
            List <Resource> touchedResources = null;

            foreach (ContentRef <Resource> resRef in checkContent)
            {
                if (resRef.IsDefaultContent)
                {
                    continue;
                }
                if (!importer.IsUsingSrcFile(resRef, filePathOld))
                {
                    continue;
                }
                try
                {
                    Resource res = resRef.Res;
                    if (res.SourcePath == filePathOld)
                    {
                        res.SourcePath = filePathNew;
                        if (touchedResources == null)
                        {
                            touchedResources = new List <Resource>();
                        }
                        touchedResources.Add(res);
                        // Multiple Resources referring to a single source file shouldn't happen
                        // in the current implementation of FileImport and Resource system.
                        // Might change later.
                        break;
                    }
                }
                catch (Exception)
                {
                    Log.Editor.WriteError("There was an error internally renaming a source file '{0}' to '{1}'", filePathOld, filePathNew);
                }
            }

            if (touchedResources != null)
            {
                DualityEditorApp.FlagResourceUnsaved(touchedResources);
            }
        }
示例#21
0
        public static void ReimportFile(string filePath)
        {
            // Find an importer to handle the file import
            IFileImporter importer = importers.FirstOrDefault(i => i.CanImportFile(filePath));

            if (importer == null)
            {
                return;
            }

            // Guess which Resources are affected and check them first
            string fileBaseName = Path.GetFileNameWithoutExtension(Path.GetFileNameWithoutExtension(filePath));
            List <ContentRef <Resource> > checkContent = ContentProvider.GetAvailableContent <Resource>();

            for (int i = 0; i < checkContent.Count; ++i)
            {
                ContentRef <Resource> resRef = checkContent[i];
                if (resRef.Name == fileBaseName)
                {
                    checkContent.RemoveAt(i);
                    checkContent.Insert(0, resRef);
                }
            }

            // Iterate over all existing Resources to find out which one to ReImport.
            List <Resource> touchedResources = null;

            foreach (ContentRef <Resource> resRef in checkContent)
            {
                if (resRef.IsDefaultContent)
                {
                    continue;
                }
                if (!importer.IsUsingSrcFile(resRef, filePath))
                {
                    continue;
                }
                try
                {
                    importer.ReimportFile(resRef, filePath);
                    if (resRef.IsLoaded)
                    {
                        if (touchedResources == null)
                        {
                            touchedResources = new List <Resource>();
                        }
                        touchedResources.Add(resRef.Res);
                    }
                    // Multiple Resources referring to a single source file shouldn't happen
                    // in the current implementation of FileImport and Resource system.
                    // Might change later.
                    break;
                }
                catch (Exception)
                {
                    Log.Editor.WriteError("Can't re-import file '{0}'", filePath);
                }
            }

            if (touchedResources != null)
            {
                DualityEditorApp.NotifyObjPropChanged(null, new ObjectSelection((IEnumerable <object>)touchedResources));
            }
        }
示例#22
0
        public static void ReimportFile(string filePath)
        {
            string fileExt = Path.GetExtension(filePath);

            // Find an importer to handle the file import
            IFileImporter importer = importers.FirstOrDefault(i => i.CanImportFile(filePath));

            if (importer == null)
            {
                return;
            }

            // Determine which Resources are affected
            ContentRef <Resource> affectedResource = null;

            // First, try to guess which Resource is affected using the file name
            {
                string guessedResourceName   = ContentProvider.GetNameFromPath(filePath);
                string resourceSearchPattern = "*" + guessedResourceName + "*" + Resource.FileExt;
                foreach (string resourcePath in Directory.EnumerateFiles(DualityApp.DataDirectory, resourceSearchPattern, SearchOption.AllDirectories))
                {
                    ContentRef <Resource> resourceRef = new ContentRef <Resource>(null, resourcePath);
                    string resourceName = ContentProvider.GetNameFromPath(resourcePath);

                    // If the name doesn't match, skip
                    if (!string.Equals(resourceName, guessedResourceName, StringComparison.InvariantCultureIgnoreCase))
                    {
                        continue;
                    }
                    // If there is no association between source fil and Resource, skip it
                    if (!IsUsingSourceFile(importer, resourceRef, filePath, fileExt) && importer.CanReImportFile(resourceRef, filePath))
                    {
                        continue;
                    }
                    // If the importer can't handle that Resource with that file, skip it
                    if (!importer.CanReImportFile(resourceRef, filePath))
                    {
                        continue;
                    }

                    affectedResource = resourceRef;
                    break;
                }
            }

            // No idea yet? Try brute force and check all the available Resources
            if (affectedResource == null)
            {
                foreach (ContentRef <Resource> resRef in ContentProvider.GetAvailableContent <Resource>())
                {
                    // If this is default content, skip it
                    if (resRef.IsDefaultContent)
                    {
                        continue;
                    }
                    // If there is no association between source fil and Resource, skip it
                    if (!IsUsingSourceFile(importer, resRef, filePath, fileExt) && importer.CanReImportFile(resRef, filePath))
                    {
                        continue;
                    }
                    // If the importer can't handle that Resource with that file, skip it
                    if (!importer.CanReImportFile(resRef, filePath))
                    {
                        continue;
                    }

                    affectedResource = resRef;
                    break;
                }
            }

            // Re-Import the affected Resources
            List <Resource> touchedResources = null;

            if (affectedResource != null)
            {
                try
                {
                    importer.ReImportFile(affectedResource, filePath);
                    if (affectedResource.IsLoaded)
                    {
                        if (touchedResources == null)
                        {
                            touchedResources = new List <Resource>();
                        }
                        touchedResources.Add(affectedResource.Res);
                    }
                }
                catch (Exception e)
                {
                    Log.Editor.WriteError("Can't re-import file '{0}': {1}", filePath, Log.Exception(e));
                }
            }

            // Notify the editor that we have modified some Resources
            if (touchedResources != null)
            {
                DualityEditorApp.NotifyObjPropChanged(null, new ObjectSelection((IEnumerable <object>)touchedResources));
            }
        }
示例#23
0
        protected override void OnShown(EventArgs e)
        {
            base.OnShown(e);

            this.objectReferenceListing.ClearSelection();
            this.objectReferenceListing.Model = this.Model;

            this.objectReferenceListing.BeginUpdate();
            this.Model.Nodes.Clear();

            if (typeof(GameObject).IsAssignableFrom(this.FilteredType))
            {
                this.Text = "Select a GameObject";

                foreach (GameObject currentObject in Scene.Current.AllObjects)
                {
                    this.Model.Nodes.Add(new ReferenceNode(currentObject));
                }
            }
            else if (typeof(Component).IsAssignableFrom(this.FilteredType))
            {
                this.Text = string.Format("Select a {0} Component", this.FilteredType.GetTypeCSCodeName());

                foreach (Component currentComponent in Scene.Current.FindComponents(this.FilteredType))
                {
                    this.Model.Nodes.Add(new ReferenceNode(currentComponent));
                }
            }
            else
            {
                Type filteredType = typeof(Resource);

                if (this.FilteredType.IsGenericType)
                {
                    filteredType = this.FilteredType.GetGenericArguments()[0];
                    this.Text    = string.Format("Select a {0} Resource", filteredType.GetTypeCSCodeName(true));
                }
                else
                {
                    this.Text = "Select a Resource";
                }

                foreach (IContentRef contentRef in ContentProvider.GetAvailableContent(filteredType))
                {
                    this.Model.Nodes.Add(new ReferenceNode(contentRef));
                }
            }

            foreach (var treeNodeAdv in this.objectReferenceListing.AllNodes)
            {
                ReferenceNode node = treeNodeAdv.Tag as ReferenceNode;

                treeNodeAdv.IsExpanded = true;

                if (node != null && node.Path == this.ResourcePath)
                {
                    this.objectReferenceListing.SelectedNode = treeNodeAdv;
                }
            }

            this.objectReferenceListing.EndUpdate();
            this.txtFilterInput.Focus();
        }