├── ProjectSettings ├── ProjectVersion.txt ├── TagManager.asset ├── TimeManager.asset ├── AudioManager.asset ├── InputManager.asset ├── NavMeshAreas.asset ├── DynamicsManager.asset ├── EditorSettings.asset ├── GraphicsSettings.asset ├── NetworkManager.asset ├── ProjectSettings.asset ├── QualitySettings.asset ├── Physics2DSettings.asset ├── ClusterInputManager.asset ├── EditorBuildSettings.asset └── UnityConnectSettings.asset ├── Assets ├── Main.unity ├── SuperFind │ ├── Nodes.meta │ ├── Empty.unity │ ├── Selectors.meta │ ├── Visitors.meta │ ├── SceneDescender.cs.meta │ ├── Selectors │ │ ├── Flairs.meta │ │ ├── Flairs │ │ │ ├── Flair.cs.meta │ │ │ ├── WordFlair.cs.meta │ │ │ ├── IndexFlair.cs.meta │ │ │ ├── ComponentFlair.cs.meta │ │ │ ├── ComponentFlair.cs │ │ │ ├── Flair.cs │ │ │ ├── IndexFlair.cs │ │ │ └── WordFlair.cs │ │ ├── Selector.cs.meta │ │ ├── SelectorChain.cs.meta │ │ ├── Selector.cs │ │ └── SelectorChain.cs │ ├── TestScene.unity │ ├── VERSION.txt │ ├── Visitors │ │ ├── FindVisitor.cs.meta │ │ ├── IVisitor.cs │ │ ├── IVisitor.cs.meta │ │ ├── FindAllVisitor.cs.meta │ │ ├── FindVisitor.cs │ │ └── FindAllVisitor.cs │ ├── Editor │ │ ├── SuperFindBenchmarks.cs.meta │ │ ├── SuperFindInspector.cs.meta │ │ ├── SuperFindTestHelpers.cs.meta │ │ ├── SuperFindTests.cs.meta │ │ ├── SuperFindInspector.cs │ │ ├── SuperFindBenchmarks.cs │ │ ├── SuperFindTestHelpers.cs │ │ └── SuperFindTests.cs │ ├── Nodes │ │ ├── INode.cs │ │ ├── INode.cs.meta │ │ ├── TransformNode.cs.meta │ │ └── TransformNode.cs │ ├── Constants.cs │ ├── Empty.unity.meta │ ├── TestScene.unity.meta │ ├── Editor.meta │ ├── Constants.cs.meta │ ├── SuperFind.cs.meta │ ├── LICENSE │ ├── SceneDescender.cs │ └── SuperFind.cs ├── Main.unity.meta └── SuperFind.meta ├── VERSION.txt ├── .gitignore ├── LICENSE └── README.md /ProjectSettings/ProjectVersion.txt: -------------------------------------------------------------------------------- 1 | m_EditorVersion: 5.6.4p2 2 | -------------------------------------------------------------------------------- /Assets/Main.unity: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/haydenjameslee/unity-super-find/HEAD/Assets/Main.unity -------------------------------------------------------------------------------- /Assets/SuperFind/Nodes.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 022101c5f1034d719cf00aaa3530f987 3 | timeCreated: 1525488891 -------------------------------------------------------------------------------- /Assets/SuperFind/Empty.unity: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/haydenjameslee/unity-super-find/HEAD/Assets/SuperFind/Empty.unity -------------------------------------------------------------------------------- /Assets/SuperFind/Selectors.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 66c3d3d08c904369a9e9ae1bd54f93e5 3 | timeCreated: 1525489884 -------------------------------------------------------------------------------- /Assets/SuperFind/Visitors.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5db8fd7879ab4b47aec87fbdc7999a4f 3 | timeCreated: 1525488928 -------------------------------------------------------------------------------- /VERSION.txt: -------------------------------------------------------------------------------- 1 | SuperFind Version 1.2.0 2 | 3 | https://github.com/haydenjameslee/unity-super-find 4 | 5 | MIT License 6 | -------------------------------------------------------------------------------- /Assets/SuperFind/SceneDescender.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a0bb04a6405b4b8bbc7a90c306fc5c13 3 | timeCreated: 1525488065 -------------------------------------------------------------------------------- /Assets/SuperFind/Selectors/Flairs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 1fa0a24afc3444b29d8ca62914fd3bb9 3 | timeCreated: 1525489888 -------------------------------------------------------------------------------- /Assets/SuperFind/TestScene.unity: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/haydenjameslee/unity-super-find/HEAD/Assets/SuperFind/TestScene.unity -------------------------------------------------------------------------------- /ProjectSettings/TagManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/haydenjameslee/unity-super-find/HEAD/ProjectSettings/TagManager.asset -------------------------------------------------------------------------------- /ProjectSettings/TimeManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/haydenjameslee/unity-super-find/HEAD/ProjectSettings/TimeManager.asset -------------------------------------------------------------------------------- /Assets/SuperFind/Selectors/Flairs/Flair.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 81333e36986e4edea59f84af5c1294b0 3 | timeCreated: 1525263658 -------------------------------------------------------------------------------- /Assets/SuperFind/VERSION.txt: -------------------------------------------------------------------------------- 1 | SuperFind Version 1.2.0 2 | 3 | https://github.com/haydenjameslee/unity-super-find 4 | 5 | MIT License 6 | -------------------------------------------------------------------------------- /Assets/SuperFind/Visitors/FindVisitor.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 7c4ce5b3e206462a9333d54f465fdca7 3 | timeCreated: 1525943677 -------------------------------------------------------------------------------- /ProjectSettings/AudioManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/haydenjameslee/unity-super-find/HEAD/ProjectSettings/AudioManager.asset -------------------------------------------------------------------------------- /ProjectSettings/InputManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/haydenjameslee/unity-super-find/HEAD/ProjectSettings/InputManager.asset -------------------------------------------------------------------------------- /ProjectSettings/NavMeshAreas.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/haydenjameslee/unity-super-find/HEAD/ProjectSettings/NavMeshAreas.asset -------------------------------------------------------------------------------- /Assets/SuperFind/Editor/SuperFindBenchmarks.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ec48f8f6fb40416b944fda7c3ae4421f 3 | timeCreated: 1509536884 -------------------------------------------------------------------------------- /Assets/SuperFind/Editor/SuperFindInspector.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: aec41ee3f9e240b9b1c84297bf859d9e 3 | timeCreated: 1525437604 -------------------------------------------------------------------------------- /Assets/SuperFind/Editor/SuperFindTestHelpers.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 67a65096a42546e9b1734a5c73aed50f 3 | timeCreated: 1509537079 -------------------------------------------------------------------------------- /Assets/SuperFind/Selectors/Flairs/WordFlair.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3dd3ab7b683743baa01a29955e2aacd6 3 | timeCreated: 1525489942 -------------------------------------------------------------------------------- /ProjectSettings/DynamicsManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/haydenjameslee/unity-super-find/HEAD/ProjectSettings/DynamicsManager.asset -------------------------------------------------------------------------------- /ProjectSettings/EditorSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/haydenjameslee/unity-super-find/HEAD/ProjectSettings/EditorSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/GraphicsSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/haydenjameslee/unity-super-find/HEAD/ProjectSettings/GraphicsSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/NetworkManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/haydenjameslee/unity-super-find/HEAD/ProjectSettings/NetworkManager.asset -------------------------------------------------------------------------------- /ProjectSettings/ProjectSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/haydenjameslee/unity-super-find/HEAD/ProjectSettings/ProjectSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/QualitySettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/haydenjameslee/unity-super-find/HEAD/ProjectSettings/QualitySettings.asset -------------------------------------------------------------------------------- /ProjectSettings/Physics2DSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/haydenjameslee/unity-super-find/HEAD/ProjectSettings/Physics2DSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/ClusterInputManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/haydenjameslee/unity-super-find/HEAD/ProjectSettings/ClusterInputManager.asset -------------------------------------------------------------------------------- /ProjectSettings/EditorBuildSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/haydenjameslee/unity-super-find/HEAD/ProjectSettings/EditorBuildSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/UnityConnectSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/haydenjameslee/unity-super-find/HEAD/ProjectSettings/UnityConnectSettings.asset -------------------------------------------------------------------------------- /Assets/SuperFind/Nodes/INode.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | 3 | namespace SuperFindPlugin 4 | { 5 | public interface INode : IEnumerable 6 | { 7 | } 8 | } -------------------------------------------------------------------------------- /Assets/SuperFind/Constants.cs: -------------------------------------------------------------------------------- 1 | namespace SuperFindPlugin 2 | { 3 | public static class Constants 4 | { 5 | public const string Wildcard = "*"; 6 | } 7 | } -------------------------------------------------------------------------------- /Assets/SuperFind/Visitors/IVisitor.cs: -------------------------------------------------------------------------------- 1 | namespace SuperFindPlugin 2 | { 3 | public interface IVisitor 4 | { 5 | void Visit(INode node); 6 | bool ShortCircuit(); 7 | } 8 | } -------------------------------------------------------------------------------- /Assets/Main.unity.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5f05a24a02a533d4cad48ce3faba8d6c 3 | timeCreated: 1509291202 4 | licenseType: Pro 5 | DefaultImporter: 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/SuperFind/Empty.unity.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 70187eb0711a1b742be7a1729b1a89d7 3 | timeCreated: 1509292736 4 | licenseType: Pro 5 | DefaultImporter: 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/SuperFind/TestScene.unity.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e1bdd587a8b7ce945a57e197fcbc5ebf 3 | timeCreated: 1525438632 4 | licenseType: Pro 5 | DefaultImporter: 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/SuperFind.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d4a01d778d7a8904baa69fd9dddd4b8c 3 | folderAsset: yes 4 | timeCreated: 1509290446 5 | licenseType: Pro 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/SuperFind/Editor.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 38428e163dd2cf94982aa4784a1629cb 3 | folderAsset: yes 4 | timeCreated: 1509290268 5 | licenseType: Pro 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/SuperFind/Constants.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 1fc8da5afaaf2e743bc22169f445bb23 3 | timeCreated: 1528876289 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/SuperFind/SuperFind.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b4f8baafa84e41341bd8f21cca84b2f6 3 | timeCreated: 1509290454 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/SuperFind/Nodes/INode.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 42784e596d8191143be0ad5e8091ea8a 3 | timeCreated: 1525489161 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/SuperFind/Nodes/TransformNode.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 93df38e3055de36468a7def666a04005 3 | timeCreated: 1525489161 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/SuperFind/Selectors/Selector.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 80ab836f5b38d2d4e9d2d744c945750c 3 | timeCreated: 1525491886 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/SuperFind/Visitors/IVisitor.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 0da4ed0d5277bf344a1467599dd1634b 3 | timeCreated: 1525489161 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/SuperFind/Editor/SuperFindTests.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b02e2629ece6b1648979005393c06281 3 | timeCreated: 1509290273 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/SuperFind/Selectors/SelectorChain.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 96e0168b1a58a594888a90f6825454de 3 | timeCreated: 1525491886 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/SuperFind/Visitors/FindAllVisitor.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d2647c7a41e3e634a9f755183a33af10 3 | timeCreated: 1525489161 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/SuperFind/Selectors/Flairs/IndexFlair.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4ac334da3e8c4d34e9ed9d28d5ee1ed3 3 | timeCreated: 1525491886 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/SuperFind/Selectors/Flairs/ComponentFlair.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 8c32d396e669cda4093ebd78f3f48f6c 3 | timeCreated: 1528879563 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/SuperFind/Selectors/Flairs/ComponentFlair.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | 3 | namespace SuperFindPlugin 4 | { 5 | public class ComponentFlair : Flair 6 | { 7 | private string componentName; 8 | 9 | public ComponentFlair(string componentName) { 10 | this.componentName = componentName; 11 | } 12 | 13 | public override bool Match(Transform toMatch, string name) { 14 | return toMatch.GetComponent(componentName); 15 | } 16 | } 17 | } -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /[Ll]ibrary/ 2 | /[Tt]emp/ 3 | /[Oo]bj/ 4 | /[Bb]uild/ 5 | /[Bb]uilds/ 6 | /Assets/AssetStoreTools* 7 | 8 | # Visual Studio 2015 cache directory 9 | /.vs/ 10 | 11 | # Autogenerated VS/MD/Consulo solution and project files 12 | ExportedObj/ 13 | .consulo/ 14 | *.csproj 15 | *.unityproj 16 | *.sln 17 | *.suo 18 | *.tmp 19 | *.user 20 | *.userprefs 21 | *.pidb 22 | *.booproj 23 | *.svd 24 | *.pdb 25 | 26 | # Unity3D generated meta files 27 | *.pidb.meta 28 | 29 | # Unity3D Generated File On Crash Reports 30 | sysinfo.txt 31 | 32 | # Builds 33 | *.apk 34 | *.unitypackage 35 | -------------------------------------------------------------------------------- /Assets/SuperFind/Nodes/TransformNode.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | namespace SuperFindPlugin 6 | { 7 | public class TransformNode : INode 8 | { 9 | private readonly Transform _transform; 10 | private List _children = new List(); 11 | 12 | public TransformNode(Transform transform) { 13 | _transform = transform; 14 | 15 | foreach (Transform child in transform) { 16 | _children.Add(new TransformNode(child)); 17 | } 18 | } 19 | 20 | public IEnumerator GetEnumerator() { 21 | return _children.GetEnumerator(); 22 | } 23 | 24 | public Transform GetTransform() { 25 | return _transform; 26 | } 27 | } 28 | } -------------------------------------------------------------------------------- /Assets/SuperFind/Editor/SuperFindInspector.cs: -------------------------------------------------------------------------------- 1 | using SuperFindPlugin; 2 | using UnityEditor; 3 | using UnityEngine; 4 | 5 | public class SuperFindInspector : EditorWindow 6 | { 7 | private static string _input = ""; 8 | 9 | [MenuItem("Window/SuperFindInspector")] 10 | public static void ShowWindow() { 11 | GetWindow(typeof(SuperFindInspector)); 12 | } 13 | 14 | private void OnGUI() { 15 | _input = GUILayout.TextField(_input); 16 | 17 | if (GUILayout.Button("SuperFind.Find")) { 18 | GameObject found = SuperFind.Find(_input); 19 | if (found != null) { 20 | Selection.SetActiveObjectWithContext(found, null); 21 | } 22 | } 23 | 24 | if (GUILayout.Button("SuperFind.FindAll")) { 25 | GameObject[] found = SuperFind.FindAll(_input); 26 | if (found.Length != 0) { 27 | Selection.objects = found; 28 | } 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Assets/SuperFind/Selectors/Flairs/Flair.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using UnityEngine; 3 | 4 | namespace SuperFindPlugin 5 | { 6 | public abstract class Flair 7 | { 8 | public static string[] ValidWords = { 9 | "first", 10 | "last", 11 | }; 12 | 13 | public static Flair FromString(string flairStr) { 14 | int parsed; 15 | bool isNumeric = int.TryParse(flairStr, out parsed); 16 | if (isNumeric) { 17 | return new IndexFlair(parsed); 18 | } else if (IsValidWord(flairStr)) { 19 | return new WordFlair(flairStr); 20 | } else { 21 | return new ComponentFlair(flairStr); 22 | //throw new Exception("Flair " + flairStr + " is not a valid flair."); 23 | } 24 | } 25 | 26 | public static bool IsValidWord(string word) { 27 | return Array.Exists(ValidWords, element => element == word); 28 | } 29 | 30 | public abstract bool Match(Transform transform, string name); 31 | } 32 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Hayden Lee 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Assets/SuperFind/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Hayden Lee 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Assets/SuperFind/Visitors/FindVisitor.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using UnityEngine; 3 | 4 | namespace SuperFindPlugin 5 | { 6 | public class FindVisitor : IVisitor 7 | { 8 | private Transform _result; 9 | private SelectorChain _selectors; 10 | 11 | public FindVisitor(SelectorChain selectors) { 12 | _selectors = selectors; 13 | } 14 | 15 | public void Visit(INode node) { 16 | var transformNode = node as TransformNode; 17 | if (transformNode == null) { 18 | throw new InvalidCastException("TransformNode to INode"); 19 | } 20 | Visit(transformNode); 21 | } 22 | 23 | public bool ShortCircuit() { 24 | return _result != null; 25 | } 26 | 27 | public void Visit(TransformNode node) { 28 | Transform transform = node.GetTransform(); 29 | if (MatchesSelectors(transform)) { 30 | _result = transform; 31 | } 32 | } 33 | 34 | private bool MatchesSelectors(Transform transform) { 35 | return _selectors.Match(transform); 36 | } 37 | 38 | public Transform GetTransform() { 39 | return _result; 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /Assets/SuperFind/Visitors/FindAllVisitor.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | namespace SuperFindPlugin 6 | { 7 | public class FindAllVisitor : IVisitor 8 | { 9 | private List _foundTransforms = new List(); 10 | private SelectorChain _selectors; 11 | 12 | public FindAllVisitor(SelectorChain selectors) { 13 | _selectors = selectors; 14 | } 15 | 16 | public void Visit(INode node) { 17 | var transformNode = node as TransformNode; 18 | if (transformNode == null) { 19 | throw new InvalidCastException("TransformNode to INode"); 20 | } 21 | Visit(transformNode); 22 | } 23 | 24 | public bool ShortCircuit() { 25 | return false; 26 | } 27 | 28 | public void Visit(TransformNode node) { 29 | Transform transform = node.GetTransform(); 30 | 31 | if (MatchesSelectors(transform)) { 32 | _foundTransforms.Add(transform); 33 | } 34 | } 35 | 36 | private bool MatchesSelectors(Transform transform) { 37 | return _selectors.Match(transform); 38 | } 39 | 40 | public Transform[] GetTransforms() { 41 | return _foundTransforms.ToArray(); 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /Assets/SuperFind/SceneDescender.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using UnityEngine; 3 | using UnityEngine.SceneManagement; 4 | 5 | namespace SuperFindPlugin 6 | { 7 | public interface IDescender 8 | { 9 | void Descend(IVisitor visitor); 10 | } 11 | 12 | public class SceneDescender : IDescender 13 | { 14 | private Scene _scene; 15 | private IVisitor _visitor; 16 | 17 | public SceneDescender(Scene scene) { 18 | _scene = scene; 19 | } 20 | 21 | public void Descend(IVisitor visitor) { 22 | _visitor = visitor; 23 | 24 | GameObject[] roots = _scene.GetRootGameObjects(); 25 | for (int i = 0; i < roots.Length; i++) { 26 | INode node = new TransformNode(roots[i].transform); 27 | Descend(node); 28 | if (_visitor.ShortCircuit()) { 29 | return; 30 | } 31 | } 32 | } 33 | 34 | private void Descend(INode node) { 35 | _visitor.Visit(node); 36 | if (_visitor.ShortCircuit()) { 37 | return; 38 | } 39 | 40 | foreach (object child in node) { 41 | INode childNode = child as TransformNode; 42 | if (childNode == null) { 43 | throw new InvalidCastException("TransformNode to INode"); 44 | } 45 | Descend(childNode); 46 | if (_visitor.ShortCircuit()) { 47 | return; 48 | } 49 | } 50 | } 51 | } 52 | } -------------------------------------------------------------------------------- /Assets/SuperFind/Selectors/Flairs/IndexFlair.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using UnityEngine.SceneManagement; 3 | 4 | namespace SuperFindPlugin 5 | { 6 | public class IndexFlair : Flair 7 | { 8 | private int index; 9 | 10 | public IndexFlair(int index) { 11 | this.index = index; 12 | } 13 | 14 | public override bool Match(Transform toMatch, string name) { 15 | var parent = toMatch.parent; 16 | if (parent == null) { 17 | GameObject[] roots = SceneManager.GetActiveScene().GetRootGameObjects(); 18 | int i = 0; 19 | foreach (GameObject childGo in roots) { 20 | Transform child = childGo.transform; 21 | if (name == Constants.Wildcard || child.name == name) { 22 | if (i == index && child == toMatch) { 23 | return true; 24 | } else if (i == index) { 25 | return false; 26 | } 27 | i++; 28 | } 29 | } 30 | return false; 31 | } else { 32 | int i = 0; 33 | foreach (Transform child in parent) { 34 | if (name == Constants.Wildcard || child.name == name) { 35 | if (i == index && child == toMatch) { 36 | return true; 37 | } else if (i == index) { 38 | return false; 39 | } 40 | i++; 41 | } 42 | } 43 | return false; 44 | } 45 | } 46 | } 47 | } -------------------------------------------------------------------------------- /Assets/SuperFind/Selectors/Selector.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | 3 | namespace SuperFindPlugin 4 | { 5 | public class Selector 6 | { 7 | private string _name; 8 | private Flair[] _flairs; 9 | 10 | public Selector(string name) { 11 | _name = name; 12 | } 13 | 14 | public Selector(string name, Flair[] flairs) { 15 | _name = name; 16 | _flairs = flairs; 17 | } 18 | 19 | public static Selector FromString(string selectorStr) { 20 | string[] splitSelector = selectorStr.Split(':'); 21 | if (splitSelector.Length == 1) { 22 | return new Selector(selectorStr); 23 | } else { 24 | string name = splitSelector[0]; 25 | Flair[] flairs = new Flair[splitSelector.Length - 1]; 26 | for (int i = 1; i < splitSelector.Length; i++) { 27 | string flairStr = splitSelector[i]; 28 | Flair flair = Flair.FromString(flairStr); 29 | flairs[i - 1] = flair; 30 | } 31 | return new Selector(name, flairs); 32 | } 33 | } 34 | 35 | public bool Match(Transform transform) { 36 | if (_flairs != null) { 37 | return MatchName(transform.name) && MatchFlairs(transform); 38 | } else { 39 | return MatchName(transform.name); 40 | } 41 | } 42 | 43 | private bool MatchName(string nodeName) { 44 | return _name == Constants.Wildcard || nodeName == _name; 45 | } 46 | 47 | private bool MatchFlairs(Transform transform) { 48 | foreach (Flair flair in _flairs) { 49 | if (!flair.Match(transform, _name)) { 50 | return false; 51 | } 52 | } 53 | return true; 54 | } 55 | } 56 | } -------------------------------------------------------------------------------- /Assets/SuperFind/SuperFind.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using UnityEngine.SceneManagement; 3 | 4 | namespace SuperFindPlugin 5 | { 6 | public static class SuperFind { 7 | 8 | public static GameObject Find(string selector) { 9 | SelectorChain selectors = new SelectorChain(selector); 10 | FindVisitor visitor = new FindVisitor(selectors); 11 | SceneDescender descender = new SceneDescender(SceneManager.GetActiveScene()); 12 | 13 | descender.Descend(visitor); 14 | 15 | Transform result = visitor.GetTransform(); 16 | return result != null ? result.gameObject : null; 17 | } 18 | 19 | public static GameObject[] FindAll(string selector) { 20 | SelectorChain selectors = new SelectorChain(selector); 21 | FindAllVisitor visitor = new FindAllVisitor(selectors); 22 | SceneDescender descender = new SceneDescender(SceneManager.GetActiveScene()); 23 | 24 | descender.Descend(visitor); 25 | 26 | Transform[] results = visitor.GetTransforms(); 27 | GameObject[] output = GetGameObjectsFromTransforms(results); 28 | return output; 29 | } 30 | 31 | private static GameObject[] GetGameObjectsFromTransforms(Transform[] transforms) { 32 | GameObject[] gos = new GameObject[transforms.Length]; 33 | for (int i = 0; i < transforms.Length; i++) { 34 | gos[i] = transforms[i].gameObject; 35 | } 36 | return gos; 37 | } 38 | 39 | public static string NamesOfTransforms(Transform[] transforms, bool ids = false) { 40 | if (transforms == null) { 41 | return ""; 42 | } 43 | string output = ""; 44 | foreach (var t in transforms) { 45 | if (ids) { 46 | output += t.name + ":" + t.gameObject.GetInstanceID() + ", "; 47 | } else { 48 | output += t.name + ", "; 49 | } 50 | } 51 | if (output.Length > 0) { 52 | output = output.Remove(output.Length - 2); 53 | } 54 | return output; 55 | } 56 | } 57 | } -------------------------------------------------------------------------------- /Assets/SuperFind/Selectors/SelectorChain.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using UnityEngine; 3 | 4 | namespace SuperFindPlugin 5 | { 6 | public class SelectorChain 7 | { 8 | private List _chain = new List(); 9 | 10 | public SelectorChain(string fullSelector) { 11 | var regex = new System.Text.RegularExpressions.Regex("((?\")(?[^\"]*)(?<-Open>\"))|(?\\S+)"); 12 | var matches = regex.Matches(fullSelector); 13 | for (int i = 0; i < matches.Count; i++) { 14 | var selectorStr = matches[i].Groups["Name"].Value; 15 | var selector = Selector.FromString(selectorStr); 16 | _chain.Add(selector); 17 | } 18 | } 19 | 20 | /** 21 | * Match conditions: 22 | * - Leaf selector matches this transform 23 | * - All selectors match a transform in the parent list, in order 24 | */ 25 | public bool Match(Transform transform) { 26 | int currentSelectorIndex = _chain.Count - 1; 27 | Transform next = transform; 28 | 29 | // Check first node 30 | Selector leafSelector = _chain[currentSelectorIndex]; 31 | if (!leafSelector.Match(transform)) { 32 | // Leaf does not match, therefore this node cannot match selector 33 | return false; 34 | } 35 | currentSelectorIndex--; 36 | 37 | if (next.parent == null && _chain.Count == 1) { 38 | // No parents and leaf matched, so this node is valid 39 | return true; 40 | } 41 | 42 | // Set next to parent and walk up through parents 43 | next = transform.parent; 44 | while (next != null && currentSelectorIndex >= 0) { 45 | Selector selector = _chain[currentSelectorIndex]; 46 | if (selector.Match(next)) { 47 | currentSelectorIndex--; 48 | } 49 | next = next.parent; 50 | } 51 | 52 | // If index is below 0 then all selectors in the chain have been matched 53 | return currentSelectorIndex < 0; 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /Assets/SuperFind/Selectors/Flairs/WordFlair.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using UnityEngine; 3 | using UnityEngine.SceneManagement; 4 | 5 | namespace SuperFindPlugin 6 | { 7 | public class WordFlair : Flair 8 | { 9 | private string word; 10 | 11 | public WordFlair(string word) { 12 | this.word = word; 13 | } 14 | 15 | public override bool Match(Transform toMatch, string name) { 16 | var parent = toMatch.parent; 17 | if (word == "first") { 18 | if (parent == null) { 19 | GameObject[] roots = SceneManager.GetActiveScene().GetRootGameObjects(); 20 | foreach (GameObject go in roots) { 21 | if (name == Constants.Wildcard || go.name == name) { 22 | return go.transform == toMatch; 23 | } 24 | } 25 | } else { 26 | foreach (Transform child in parent) { 27 | if (name == Constants.Wildcard || child.name == name) { 28 | return child == toMatch; 29 | } 30 | } 31 | } 32 | return false; 33 | } else if (word == "last") { 34 | if (parent == null) { 35 | GameObject[] roots = SceneManager.GetActiveScene().GetRootGameObjects(); 36 | Transform lastFound = null; 37 | foreach (GameObject go in roots) { 38 | if (name == Constants.Wildcard || go.name == name) { 39 | lastFound = go.transform; 40 | } 41 | } 42 | return lastFound == toMatch; 43 | } else { 44 | Transform lastFound = null; 45 | foreach (Transform child in parent) { 46 | if (name == Constants.Wildcard || child.name == name) { 47 | lastFound = child; 48 | } 49 | } 50 | return lastFound == toMatch; 51 | } 52 | } 53 | throw new Exception(); 54 | } 55 | } 56 | } -------------------------------------------------------------------------------- /Assets/SuperFind/Editor/SuperFindBenchmarks.cs: -------------------------------------------------------------------------------- 1 | using System.Diagnostics; 2 | using NUnit.Framework; 3 | using SuperFindPlugin; 4 | using UnityEngine; 5 | using Debug = UnityEngine.Debug; 6 | 7 | [TestFixture] 8 | public class SuperFindBenchmarks { 9 | 10 | private const int REPS = 10000; 11 | 12 | [Test] 13 | public void Benchmark_RootScene() { 14 | SuperFindTestHelpers.CreateSceneWithRoot(); 15 | 16 | var watch = new Stopwatch(); 17 | 18 | watch.Reset(); 19 | watch.Start(); 20 | for (int i = 0; i < REPS; i++) { 21 | SuperFind.Find("Root"); 22 | } 23 | watch.Stop(); 24 | var superFindTime = watch.Elapsed; 25 | 26 | watch.Reset(); 27 | watch.Start(); 28 | for (int i = 0; i < REPS; i++) { 29 | GameObject.Find("Root"); 30 | } 31 | watch.Stop(); 32 | var nativeTime = watch.Elapsed; 33 | 34 | Debug.Log("Benchmark_RootScene: Time for GameObject.Find = " + nativeTime.TotalMilliseconds + "ms. Time for SuperFind.Find = " + 35 | superFindTime.TotalMilliseconds + "ms for " + REPS + " reps."); 36 | } 37 | 38 | [Test] 39 | public void Benchmark_ChildNotation_DeepScene() { 40 | SuperFindTestHelpers.CreateDeepScene(); 41 | 42 | var watch = new Stopwatch(); 43 | 44 | watch.Reset(); 45 | watch.Start(); 46 | for (int i = 0; i < REPS; i++) { 47 | SuperFind.Find("Root Child"); 48 | } 49 | watch.Stop(); 50 | var superFindTime = watch.Elapsed; 51 | 52 | watch.Reset(); 53 | watch.Start(); 54 | for (int i = 0; i < REPS; i++) { 55 | GameObject.Find("Root/Middle/Child"); 56 | } 57 | watch.Stop(); 58 | var nativeTime = watch.Elapsed; 59 | 60 | Debug.Log("Benchmark_ChildNotation_DeepScene: Time for GameObject.Find = " + nativeTime.TotalMilliseconds + "ms. Time for SuperFind.Find = " + 61 | superFindTime.TotalMilliseconds + "ms for " + REPS + " reps."); 62 | } 63 | 64 | [Test] 65 | public void Benchmark_ChildNotation_TrickyDeepScene() { 66 | SuperFindTestHelpers.CreateTrickyDeepScene(); 67 | 68 | var watch = new Stopwatch(); 69 | 70 | watch.Reset(); 71 | watch.Start(); 72 | for (int i = 0; i < REPS; i++) { 73 | SuperFind.Find("Root Child"); 74 | } 75 | watch.Stop(); 76 | var superFindTime = watch.Elapsed; 77 | 78 | watch.Reset(); 79 | watch.Start(); 80 | for (int i = 0; i < REPS; i++) { 81 | GameObject.Find("Root/Middle/Child"); 82 | } 83 | watch.Stop(); 84 | var nativeTime = watch.Elapsed; 85 | 86 | Debug.Log("Benchmark_ChildNotation_TrickyDeepScene: Time for GameObject.Find = " + nativeTime.TotalMilliseconds + "ms. Time for SuperFind.Find = " + 87 | superFindTime.TotalMilliseconds + "ms for " + REPS + " reps."); 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /Assets/SuperFind/Editor/SuperFindTestHelpers.cs: -------------------------------------------------------------------------------- 1 | #pragma warning disable 0219 2 | 3 | using UnityEditor.SceneManagement; 4 | using UnityEngine; 5 | 6 | public static class SuperFindTestHelpers { 7 | 8 | public static void CreateSceneWithRoot() { 9 | EditorSceneManager.OpenScene("Assets/SuperFind/Empty.unity"); 10 | var root = new GameObject("Root"); 11 | } 12 | 13 | public static void CreateDeepScene() { 14 | EditorSceneManager.OpenScene("Assets/SuperFind/Empty.unity"); 15 | var root = new GameObject("Root"); 16 | var middle = new GameObject("Middle"); 17 | middle.transform.SetParent(root.transform); 18 | var child = new GameObject("Child"); 19 | child.transform.SetParent(middle.transform); 20 | } 21 | 22 | public static void CreateTrickyDeepScene() { 23 | EditorSceneManager.OpenScene("Assets/SuperFind/Empty.unity"); 24 | var root1 = new GameObject("Root"); 25 | 26 | var root2 = new GameObject("Root"); 27 | var middle = new GameObject("Middle"); 28 | middle.transform.SetParent(root2.transform); 29 | var child = new GameObject("Child"); 30 | child.transform.SetParent(middle.transform); 31 | } 32 | 33 | public static GameObject CreateSiblingScene(int numSiblings, int returnIndex) { 34 | EditorSceneManager.OpenScene("Assets/SuperFind/Empty.unity"); 35 | var root1 = new GameObject("Root"); 36 | var root2 = new GameObject("Root"); 37 | var middle = new GameObject("Middle"); 38 | middle.transform.SetParent(root2.transform); 39 | 40 | GameObject[] children = new GameObject[numSiblings]; 41 | for (int i = 0; i < numSiblings; i++) { 42 | var child = new GameObject("Child(Clone)"); 43 | child.transform.SetParent(middle.transform); 44 | children[i] = child; 45 | child.transform.SetAsLastSibling(); 46 | } 47 | return children[returnIndex]; 48 | } 49 | 50 | public static GameObject CreateMultipleSetsofSiblingsScene(int numFirstSiblings, int numSecondSiblings, int returnIndex) { 51 | EditorSceneManager.OpenScene("Assets/SuperFind/Empty.unity"); 52 | var root1 = new GameObject("Root"); 53 | 54 | GameObject[] siblings1 = new GameObject[numFirstSiblings]; 55 | for (int i = 0; i < numFirstSiblings; i++) { 56 | var child = new GameObject("Child(Clone)"); 57 | child.transform.SetParent(root1.transform); 58 | siblings1[i] = child; 59 | child.transform.SetAsLastSibling(); 60 | } 61 | 62 | var root2 = new GameObject("Root"); 63 | var middle = new GameObject("Middle"); 64 | middle.transform.SetParent(root2.transform); 65 | 66 | GameObject[] sublings2 = new GameObject[numSecondSiblings]; 67 | for (int i = 0; i < numSecondSiblings; i++) { 68 | var child = new GameObject("Child(Clone)"); 69 | child.transform.SetParent(middle.transform); 70 | sublings2[i] = child; 71 | child.transform.SetAsLastSibling(); 72 | } 73 | return sublings2[returnIndex]; 74 | } 75 | 76 | public static void CreateSceneWithSpacesInName() { 77 | EditorSceneManager.OpenScene("Assets/SuperFind/Empty.unity"); 78 | var root = new GameObject("Root With Spaces"); 79 | var middle = new GameObject("Middle With Spaces"); 80 | middle.transform.SetParent(root.transform); 81 | var child = new GameObject("Child With Spaces"); 82 | child.transform.SetParent(middle.transform); 83 | } 84 | } -------------------------------------------------------------------------------- /Assets/SuperFind/Editor/SuperFindTests.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using NUnit.Framework; 3 | using SuperFindPlugin; 4 | 5 | [TestFixture] 6 | public class SuperFindTests { 7 | 8 | [Test] 9 | public void CannotFind() { 10 | SuperFindTestHelpers.CreateSceneWithRoot(); 11 | 12 | var result = SuperFind.Find("Wrong"); 13 | 14 | Assert.IsNull(result); 15 | } 16 | 17 | [Test] 18 | public void FindsByExactName_Root() { 19 | SuperFindTestHelpers.CreateSceneWithRoot(); 20 | 21 | var result = SuperFind.Find("Root"); 22 | 23 | Assert.AreEqual("Root", result.name); 24 | } 25 | 26 | [Test] 27 | public void FindsByName_WithSpaces() { 28 | SuperFindTestHelpers.CreateSceneWithSpacesInName(); 29 | 30 | var result = SuperFind.Find("\"Child With Spaces\""); 31 | 32 | Assert.AreEqual("Child With Spaces", result.name); 33 | } 34 | 35 | [Test] 36 | public void FindsByExactName_DeepScene() { 37 | SuperFindTestHelpers.CreateDeepScene(); 38 | 39 | var result = SuperFind.Find("Child"); 40 | 41 | Assert.AreEqual("Child", result.name); 42 | } 43 | 44 | [Test] 45 | public void FindsByExactName_Root_Inactive() { 46 | SuperFindTestHelpers.CreateSceneWithRoot(); 47 | GameObject.Find("Root").SetActive(false); 48 | 49 | var result = SuperFind.Find("Root"); 50 | 51 | Assert.AreEqual("Root", result.name); 52 | } 53 | 54 | [Test] 55 | public void FindsByChildNotaton_DeepScene() { 56 | SuperFindTestHelpers.CreateDeepScene(); 57 | 58 | var result = SuperFind.Find("Root Child"); 59 | 60 | Assert.AreEqual("Child", result.name); 61 | } 62 | 63 | [Test] 64 | public void FindsByChildNotaton_TrickyDeepScene() { 65 | SuperFindTestHelpers.CreateTrickyDeepScene(); 66 | 67 | var result = SuperFind.Find("Root Child"); 68 | 69 | Assert.AreEqual("Child", result.name); 70 | } 71 | 72 | [Test] 73 | public void FindsByChildNotaton_DeepScene_Inactive() { 74 | SuperFindTestHelpers.CreateDeepScene(); 75 | GameObject.Find("Child").SetActive(false); 76 | GameObject.Find("Root").SetActive(false); 77 | 78 | var result = SuperFind.Find("Root Child"); 79 | 80 | Assert.AreEqual("Child", result.name); 81 | } 82 | 83 | [Test] 84 | public void FindsBySiblingNotation_SiblingScene_first() { 85 | var target = SuperFindTestHelpers.CreateSiblingScene(6, 0); 86 | 87 | var result = SuperFind.Find("Child(Clone):first"); 88 | 89 | Assert.AreSame(target, result); 90 | } 91 | 92 | [Test] 93 | public void FindsBySiblingNotation_SiblingScene_last() { 94 | var target = SuperFindTestHelpers.CreateSiblingScene(6, 5); 95 | 96 | var result = SuperFind.Find("Child(Clone):last"); 97 | 98 | Assert.AreEqual(target, result); 99 | } 100 | 101 | [Test] 102 | public void FindsBySiblingNotation_SiblingScene_Index0() { 103 | var target = SuperFindTestHelpers.CreateSiblingScene(6, 0); 104 | 105 | var result = SuperFind.Find("Child(Clone):0"); 106 | 107 | Assert.AreEqual(target, result); 108 | } 109 | 110 | [Test] 111 | public void FindsBySiblingNotation_SiblingScene_Index3() { 112 | var target = SuperFindTestHelpers.CreateSiblingScene(6, 3); 113 | 114 | var result = SuperFind.Find("Child(Clone):3"); 115 | 116 | Assert.AreEqual(target, result); 117 | } 118 | 119 | [Test] 120 | public void FindsBySiblingNotation_SiblingScene_Index5() { 121 | var target = SuperFindTestHelpers.CreateSiblingScene(6, 5); 122 | 123 | var result = SuperFind.Find("Child(Clone):5"); 124 | 125 | Assert.AreEqual(target, result); 126 | } 127 | 128 | [Test] 129 | public void FindsBySiblingNotation_MultipleSiblingsScene_3() { 130 | var target = SuperFindTestHelpers.CreateMultipleSetsofSiblingsScene(3, 6, 3); 131 | 132 | var result = SuperFind.Find("Child(Clone):3"); 133 | 134 | Assert.AreSame(target, result); 135 | } 136 | 137 | [Test] 138 | public void FindsBySiblingNotation_MultipleSiblingsScene_5() { 139 | var target = SuperFindTestHelpers.CreateMultipleSetsofSiblingsScene(3, 6, 5); 140 | 141 | var result = SuperFind.Find("Child(Clone):5"); 142 | 143 | Assert.AreSame(target, result); 144 | } 145 | } 146 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # SuperFind 2 | 3 | A replacement for Unity's GameObject.Find that supports CSS-like selectors and inactive GameObjects. 4 | 5 | SuperFind allows you to find inactive GameObjects, use powerful selectors which make finding a GameObject much simpler and easy to maintain, and gives you a FindAll method to find all GameObjects that match your query. 6 | 7 | **Warning**: SuperFind is approximately 10x slower than Unity's (already slow) GameObject.Find method. As with GameObject.Find, you should not use SuperFind in an update loop or any other performance sensitive code path. 8 | 9 | ## Installation 10 | 11 | 1. Download the latest .unitypackage in the [releases archive](https://github.com/haydenjameslee/unity-super-find/releases) 12 | 2. Open your Unity project 13 | 3. Double click on the downloaded package from step 1 14 | 4. Import all the files into your project 15 | 16 | ## Documentation 17 | 18 | ### Methods 19 | 20 | #### SuperFind.Find 21 | 22 | `GameObject found = SuperFind.Find(string selector);` 23 | 24 | Returns the GameObject that first matches the given selector string in the active scene, including inactive GameObjects. If no GameObjects match the selector string, `null` is returned. 25 | 26 | #### SuperFind.FindAll 27 | 28 | `GameObject[] found = SuperFind.FindAll(string selector);` 29 | 30 | Returns all the GameObjects that match the given selector string in the active scene, including inactive GameObjects. If no GameObjects match the selector string, the returned list will be empty. 31 | 32 | ### Selectors 33 | 34 | Each SuperFind method takes a selector string to target the GameObject(s) you're trying to find. Selector strings can combine any of the following features. Please note that GameObject's with spaces in their name are not currently supported. 35 | 36 | * **By name** 37 | 38 | Similarly to `GameObject.Find`, pass the exact name of the GameObject. 39 | 40 | Eg. `SuperFind.Find("Child");` 41 | 42 | * **By wildcard** 43 | 44 | Use `*` instead of the GameObject's name to select a GameObject of any name. 45 | 46 | Eg. `SuperFind.FindAll("Parent *"); // Returns all the GameObjects under "Parent"` 47 | 48 | * **By ascendant** 49 | 50 | Pass any number of ascendant's names (in order from furthest to closest) each followed by a space and finish with the name of the GameObject (plus a sibling index if wanted). 51 | 52 | Eg. `SuperFind.Find("Grandparent Child"); // Returns a Child with a GameObject named Grandparent as an ascendant` 53 | 54 | * **By sibling index** 55 | 56 | Add a colon and the sibling index of the GameObject you want to find after the name of the GameObject. 57 | 58 | Eg. `SuperFind.Find("Enemy(Clone):3"); // Returns the 4th Enemy in a list of Enemy's` 59 | 60 | * **By first sibling** 61 | 62 | Add `:first` after the GameObject's name to find the first GameObject of that name in a list of GameObjects with that name. 63 | 64 | Eg. `SuperFind.Find("Enemy(Clone):first"); // Returns the first Enemy in a list of Enemy's` 65 | 66 | * **By last sibling** 67 | 68 | Add `:last` after the GameObject's name to find the last GameObject of that name in a list of GameObjects with that name. 69 | 70 | Eg. `SuperFind.Find("Enemy(Clone):last"); // Returns the last Enemy in a list of Enemy's` 71 | 72 | * **By component** 73 | 74 | Add `:` + the component's name after the GameObject's name to find a GameObject with this Component (or MonoBehaviour) 75 | 76 | Eg. `SuperFind.FindAll("Tree:BoxCollider"); // Returns all Tree's with a BoxCollider` 77 | 78 | * **By multiple flairs** 79 | 80 | Add a component selector and a sibling selector to combine selectors. 81 | 82 | Eg. `SuperFind.Find("Tree:BoxCollider:first"); // Returns the first Tree with a BoxCollider` 83 | 84 | 85 | ## Tests 86 | 87 | See the `SuperFind/Editor/` directory for a suite of unit tests. Run them in Unity by opening the Unity Test Runner (Window -> Test Runner) and clicking `Run All`. 88 | 89 | ## Inspector 90 | 91 | Find the SuperFind Inspector in Unity by going to `Window -> SuperFindInspector`. This inspector can be used to test selectors in realtime. 92 | 93 | 94 | ## Examples 95 | 96 | * Exact name 97 | 98 | `SuperFind.Find("One");` 99 | 100 | ![SuperFind.Find("One");](https://i.imgur.com/7WPWqJT.png) 101 | 102 | * Exact name (with space) 103 | 104 | `SuperFind.Find("\"Colliders 2\"");` 105 | 106 | ![SuperFind.Find("\"Colliders 2\"");](https://i.imgur.com/BhdNV6g.png) 107 | 108 | * Ascendant 109 | 110 | `SuperFind.FindAll("Three Child");` 111 | 112 | ![SuperFind.FindAll("Three Child");](https://i.imgur.com/zvYC9zf.png) 113 | 114 | * Multiple ascendants 115 | 116 | `SuperFind.FindAll("Three Mid Child");` 117 | 118 | ![SuperFind.FindAll("Three Mid Child");](https://i.imgur.com/zvYC9zf.png) 119 | 120 | * Sibling index 121 | 122 | `SuperFind.Find("Child:3");` 123 | 124 | ![SuperFind.FindAll("Child:3");](https://i.imgur.com/bdsNUbM.png) 125 | 126 | * First sibling 127 | 128 | `SuperFind.Find("Child:first");` 129 | 130 | ![SuperFind.Find("Child:first");](https://i.imgur.com/grZO7vK.png) 131 | 132 | * Last sibling 133 | 134 | `SuperFind.Find("Child:last");` 135 | 136 | ![SuperFind.Find("Child:last");](https://i.imgur.com/hudTbOK.png) 137 | 138 | * Acendants and sibling index 139 | 140 | `SuperFind.FindAll("Three Mid:first Child:3");` 141 | 142 | ![SuperFind.FindAll("Three Mid:first Child:3");](https://i.imgur.com/bdsNUbM.png) 143 | 144 | * Ancestor & Wildcard 145 | 146 | `SuperFind.FindAll("Mid *");` 147 | 148 | ![SuperFind.FindAll("Mid *");](https://i.imgur.com/N8Ehmij.png) 149 | 150 | * Ancestor & Wildcard 151 | 152 | `SuperFind.FindAll("Three *");` 153 | 154 | ![SuperFind.FindAll("Three *");](https://i.imgur.com/RaXOSEF.png) 155 | 156 | * Component 157 | 158 | `SuperFind.Find("Child:BoxCollider");` 159 | 160 | ![SuperFind.Find("Child:BoxCollider");](https://i.imgur.com/w2N3k2b.png) 161 | 162 | * Wildcard & Component 163 | 164 | `SuperFind.FindAll("*:BoxCollider");` 165 | 166 | ![SuperFind.FindAll("*:BoxCollider");](https://i.imgur.com/K1A3Gg1.png) 167 | 168 | * Ancestor, Wildcard & Component 169 | 170 | `SuperFind.FindAll("Colliders *:BoxCollider");` 171 | 172 | ![SuperFind.FindAll("Colliders *:BoxCollider");](https://i.imgur.com/GBCAnwe.png) 173 | 174 | * Find Ancestor, Wildcard, Component & Last Sibling 175 | 176 | `SuperFind.Find("Four *:BoxCollider:last");` 177 | 178 | ![SuperFind.Find("Four *:BoxCollider:last");](https://i.imgur.com/6Nd1uzW.png) 179 | 180 | * FindAll Ancestor, Wildcard, Component & Last Sibling 181 | 182 | `SuperFind.FindAll("Four *:BoxCollider:last");` 183 | 184 | ![SuperFind.FindAll("Four *:BoxCollider:last");](https://i.imgur.com/VxqjIUz.png) 185 | 186 | --------------------------------------------------------------------------------