void ConfigureFinder() { //This is an example of a 'scene graph' query you can use in finder //Add some objects to the scene graph... _gameObjects.Add(new PlayerGameObject { Name = "Player 1", Health = 100 }); for (var i = 1; i <= 5; i++) { _gameObjects.Add(new EnemyGameObject { Name = "Enemy " + i, Damage = i * 10 }); } //Set the Finder function to query the _gameObjects collection GS.GearsetComponent.Console.SetFinderSearchFunction(queryString => { var result = new FinderResult(); var searchParams = queryString.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); // Split the query if (searchParams.Length == 0) { searchParams = new[] { String.Empty }; } else { // Ignore case. for (var i = 0; i < searchParams.Length; i++) { searchParams[i] = searchParams[i].ToUpper(); } } foreach (var component in _gameObjects) { var matches = true; var type = component.GetType().ToString(); // Check if it matches all search params. foreach (var t in searchParams) { if (component.ToString().ToUpper().Contains(t) || type.ToUpper().Contains(t)) { continue; } matches = false; break; } if (matches) { result.Add(new ObjectDescription(component, type)); } } return(result); }); }
/// <summary> /// The default search function. It will search through the GameComponentCollection of the Game. /// </summary> static FinderResult DefaultSearchFunction(String queryString) { var result = new FinderResult(); var searchParams = queryString.Split(new [] { ' ' }, StringSplitOptions.RemoveEmptyEntries); // Split the query if (searchParams.Length == 0) { searchParams = new [] { String.Empty }; } else { // Ignore case. for (var i = 0; i < searchParams.Length; i++) { searchParams[i] = searchParams[i].ToUpper(); } } foreach (var component in GearsetResources.Game.Components) { var matches = true; var type = component.GetType().ToString(); if (component is GearsetComponentBase) { continue; } // Check if it matches all search params. foreach (var t in searchParams) { if (component.ToString().ToUpper().Contains(t) || type.ToUpper().Contains(t)) { continue; } matches = false; break; } if (matches) { result.Add(new ObjectDescription(component, type)); } } return(result); }
/// <summary> /// The default search function. It will search through the GameComponentCollection /// of the Game. /// </summary> private FinderResult DefaultSearchFunction(String queryString) { FinderResult result = new FinderResult(); String[] searchParams = queryString.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); // Split the query if (searchParams.Length == 0) { searchParams = new String[] { String.Empty }; } else { // Ignore case. for (int i = 0; i < searchParams.Length; i++) searchParams[i] = searchParams[i].ToUpper(); } foreach (IGameComponent component in GearsetResources.Game.Components) { bool matches = true; String type = component.GetType().ToString(); if (component is GearsetComponentBase) continue; // Check if it matches all search params. for (int i = 0; i < searchParams.Length; i++) { if (!(component.ToString().ToUpper().Contains(searchParams[i]) || type.ToUpper().Contains(searchParams[i]))) { matches = false; break; } } if (matches) result.Add(new ObjectDescription(component, type)); } return result; }