public static void FindAllReferences(SymbolDefinition symbol, string localAssetPath) { if (symbol.kind == SymbolKind.Accessor || symbol.kind == SymbolKind.Constructor || symbol.kind == SymbolKind.Destructor) { symbol = symbol.parentSymbol; } if (symbol == null) { return; } symbol = symbol.GetGenericSymbol(); var candidates = FindReferenceCandidates(symbol, localAssetPath); var searchOptions = new FindResultsWindow.SearchOptions { text = symbol.name, matchWord = true, matchCase = true, }; var candidateGuids = new string[candidates.Count]; for (int i = 0; i < candidates.Count; i++) { candidateGuids[i] = AssetDatabase.AssetPathToGUID(candidates[i]); } var searchForVarRefs = symbol is TypeDefinitionBase && symbol.kind != SymbolKind.Delegate; if (searchForVarRefs) { searchOptions.altText1 = "var"; var builtInTypesEnumerator = SymbolDefinition.builtInTypes.GetEnumerator(); for (var i = 0; i < 16; i++) { builtInTypesEnumerator.MoveNext(); var type = builtInTypesEnumerator.Current.Value; if (type == symbol) { searchOptions.altText2 = builtInTypesEnumerator.Current.Key; break; } } } FindResultsWindow resultsWindow = FindResultsWindow.Create( "References to " + symbol.FullName, FindAllInSingleFile, candidateGuids, searchOptions, "References"); resultsWindow.SetFilesValidator(ValidateFileForReferences); resultsWindow.SetResultsValidator(ValidateResultAsReference, symbol); }
public FindResultsWindow ListAllResults() { string[] allTextAssetGuids; var lookInOption = this.lookInOption; if (lookForOption == FindReplace_LookFor.AllAssets || lookForOption == FindReplace_LookFor.Shaders || lookForOption == FindReplace_LookFor.TextAssets) { if (lookInOption > FindReplace_LookIn.CurrentTabOnly) { lookInOption = FindReplace_LookIn.WholeProject; } } if (lookInOption == FindReplace_LookIn.OpenTabsOnly) { allTextAssetGuids = (from w in FGCodeWindow.CodeWindows select w.TargetAssetGuid).Distinct().ToArray(); } else if (lookInOption == FindReplace_LookIn.CurrentTabOnly) { allTextAssetGuids = new [] { editor != null ? editor.targetGuid : FGCodeWindow.GetGuidHistory().FirstOrDefault() }; } else if (lookInOption != FindReplace_LookIn.WholeProject && lookForOption != FindReplace_LookFor.AllAssets && lookForOption != FindReplace_LookFor.Shaders && lookForOption != FindReplace_LookFor.TextAssets) { if (FGFindInFiles.assets != null) { FGFindInFiles.assets.Clear(); } if (lookInOption == FindReplace_LookIn.FirstPassGameAssemblies || lookInOption == FindReplace_LookIn.AllGameAssemblies) { if (lookForOption == FindReplace_LookFor.CSharpScripts || lookForOption == FindReplace_LookFor.AllScriptTypes) { FGFindInFiles.FindAllAssemblyScripts(AssemblyDefinition.UnityAssembly.CSharpFirstPass); } if (lookForOption == FindReplace_LookFor.JSScripts || lookForOption == FindReplace_LookFor.AllScriptTypes) { FGFindInFiles.FindAllAssemblyScripts(AssemblyDefinition.UnityAssembly.UnityScriptFirstPass); } if (lookForOption == FindReplace_LookFor.BooScripts || lookForOption == FindReplace_LookFor.AllScriptTypes) { FGFindInFiles.FindAllAssemblyScripts(AssemblyDefinition.UnityAssembly.BooFirstPass); } } if (lookInOption == FindReplace_LookIn.GameAssemblies || lookInOption == FindReplace_LookIn.AllGameAssemblies) { if (lookForOption == FindReplace_LookFor.CSharpScripts || lookForOption == FindReplace_LookFor.AllScriptTypes) { FGFindInFiles.FindAllAssemblyScripts(AssemblyDefinition.UnityAssembly.CSharp); } if (lookForOption == FindReplace_LookFor.JSScripts || lookForOption == FindReplace_LookFor.AllScriptTypes) { FGFindInFiles.FindAllAssemblyScripts(AssemblyDefinition.UnityAssembly.UnityScript); } if (lookForOption == FindReplace_LookFor.BooScripts || lookForOption == FindReplace_LookFor.AllScriptTypes) { FGFindInFiles.FindAllAssemblyScripts(AssemblyDefinition.UnityAssembly.Boo); } } if (lookInOption == FindReplace_LookIn.FirstPassEditorAssemblies || lookInOption == FindReplace_LookIn.AllEditorAssemblies) { if (lookForOption == FindReplace_LookFor.CSharpScripts || lookForOption == FindReplace_LookFor.AllScriptTypes) { FGFindInFiles.FindAllAssemblyScripts(AssemblyDefinition.UnityAssembly.CSharpEditorFirstPass); } if (lookForOption == FindReplace_LookFor.JSScripts || lookForOption == FindReplace_LookFor.AllScriptTypes) { FGFindInFiles.FindAllAssemblyScripts(AssemblyDefinition.UnityAssembly.UnityScriptEditorFirstPass); } if (lookForOption == FindReplace_LookFor.BooScripts || lookForOption == FindReplace_LookFor.AllScriptTypes) { FGFindInFiles.FindAllAssemblyScripts(AssemblyDefinition.UnityAssembly.BooEditorFirstPass); } } if (lookInOption == FindReplace_LookIn.EditorAssemblies || lookInOption == FindReplace_LookIn.AllEditorAssemblies) { if (lookForOption == FindReplace_LookFor.CSharpScripts || lookForOption == FindReplace_LookFor.AllScriptTypes) { FGFindInFiles.FindAllAssemblyScripts(AssemblyDefinition.UnityAssembly.CSharpEditor); } if (lookForOption == FindReplace_LookFor.JSScripts || lookForOption == FindReplace_LookFor.AllScriptTypes) { FGFindInFiles.FindAllAssemblyScripts(AssemblyDefinition.UnityAssembly.UnityScriptEditor); } if (lookForOption == FindReplace_LookFor.BooScripts || lookForOption == FindReplace_LookFor.AllScriptTypes) { FGFindInFiles.FindAllAssemblyScripts(AssemblyDefinition.UnityAssembly.BooEditor); } } allTextAssetGuids = FGFindInFiles.assets.ToArray(); } else { allTextAssetGuids = FGFindInFiles.FindAllTextAssets().ToArray(); IEnumerable <string> realTextAssets = null; switch (lookForOption) { case FindReplace_LookFor.AllAssets: realTextAssets = from guid in allTextAssetGuids where !ignoreFileTypes.Contains(Path.GetExtension(AssetDatabase.GUIDToAssetPath(guid).ToLowerInvariant())) select guid; break; case FindReplace_LookFor.AllScriptTypes: realTextAssets = from guid in allTextAssetGuids where scriptFileTypes.Contains(Path.GetExtension(AssetDatabase.GUIDToAssetPath(guid).ToLowerInvariant())) select guid; break; case FindReplace_LookFor.CSharpScripts: realTextAssets = from guid in allTextAssetGuids where Path.GetExtension(AssetDatabase.GUIDToAssetPath(guid).ToLowerInvariant()) == ".cs" select guid; break; case FindReplace_LookFor.JSScripts: realTextAssets = from guid in allTextAssetGuids where Path.GetExtension(AssetDatabase.GUIDToAssetPath(guid).ToLowerInvariant()) == ".js" select guid; break; case FindReplace_LookFor.BooScripts: realTextAssets = from guid in allTextAssetGuids where Path.GetExtension(AssetDatabase.GUIDToAssetPath(guid).ToLowerInvariant()) == ".boo" select guid; break; case FindReplace_LookFor.Shaders: realTextAssets = from guid in allTextAssetGuids where shaderFileTypes.Contains(Path.GetExtension(AssetDatabase.GUIDToAssetPath(guid).ToLowerInvariant())) select guid; break; case FindReplace_LookFor.TextAssets: realTextAssets = from guid in allTextAssetGuids where !nonTextFileTypes.Contains(Path.GetExtension(AssetDatabase.GUIDToAssetPath(guid).ToLowerInvariant())) select guid; break; } allTextAssetGuids = realTextAssets.ToArray(); } if (allTextAssetGuids.Length == 0 || allTextAssetGuids.Length == 1 && allTextAssetGuids[0] == null) { Debug.LogWarning("No asset matches selected searching scope!"); return(null); } var searchOptions = new FindResultsWindow.SearchOptions { text = findText, matchCase = matchCase, matchWord = matchWholeWord, }; FindResultsWindow resultsWindow = FindResultsWindow.Create( "Searching for '" + findText + "'...", FGFindInFiles.FindAllInSingleFile, allTextAssetGuids, searchOptions, isReplace ? "<b>Replace</b>" : listResultsInNewWindow ? "" : "Find Results"); return(resultsWindow); }
private void Execute() { if (findText.Trim() != "") { var historyIndex = System.Array.IndexOf(searchHistory, findText); if (historyIndex < 0) { historyIndex = searchHistory.Length - 1; } for (var i = historyIndex; i-- > 0;) { searchHistory[i + 1] = searchHistory[i]; } searchHistory[0] = findText; } for (var i = 0; i < searchHistory.Length; i++) { if (searchHistory[i] != null) { EditorPrefs.SetString("FlipbookGames.ScriptInspector.SearchHistory_" + i.ToString(), searchHistory[i]); } } Close(); if (editor != null && editor.OwnerWindow) { editor.OwnerWindow.Focus(); } string[] allTextAssetGuids; if (lookInOption != FindReplace_LookIn.AllAssemblies && lookForOption != FindReplace_LookFor.AllAssets && lookForOption != FindReplace_LookFor.Shaders && lookForOption != FindReplace_LookFor.TextAssets) { if (FGFindInFiles.assets != null) { FGFindInFiles.assets.Clear(); } if (lookInOption == FindReplace_LookIn.FirstPassGameAssemblies || lookInOption == FindReplace_LookIn.AllGameAssemblies) { if (lookForOption == FindReplace_LookFor.CSharpScripts || lookForOption == FindReplace_LookFor.AllScripts) { FGFindInFiles.FindAllAssemblyScripts(AssemblyDefinition.UnityAssembly.CSharpFirstPass); } if (lookForOption == FindReplace_LookFor.JSScripts || lookForOption == FindReplace_LookFor.AllScripts) { FGFindInFiles.FindAllAssemblyScripts(AssemblyDefinition.UnityAssembly.UnityScriptFirstPass); } if (lookForOption == FindReplace_LookFor.BooScripts || lookForOption == FindReplace_LookFor.AllScripts) { FGFindInFiles.FindAllAssemblyScripts(AssemblyDefinition.UnityAssembly.BooFirstPass); } } if (lookInOption == FindReplace_LookIn.GameAssemblies || lookInOption == FindReplace_LookIn.AllGameAssemblies) { if (lookForOption == FindReplace_LookFor.CSharpScripts || lookForOption == FindReplace_LookFor.AllScripts) { FGFindInFiles.FindAllAssemblyScripts(AssemblyDefinition.UnityAssembly.CSharp); } if (lookForOption == FindReplace_LookFor.JSScripts || lookForOption == FindReplace_LookFor.AllScripts) { FGFindInFiles.FindAllAssemblyScripts(AssemblyDefinition.UnityAssembly.UnityScript); } if (lookForOption == FindReplace_LookFor.BooScripts || lookForOption == FindReplace_LookFor.AllScripts) { FGFindInFiles.FindAllAssemblyScripts(AssemblyDefinition.UnityAssembly.Boo); } } if (lookInOption == FindReplace_LookIn.FirstPassEditorAssemblies || lookInOption == FindReplace_LookIn.AllEditorAssemblies) { if (lookForOption == FindReplace_LookFor.CSharpScripts || lookForOption == FindReplace_LookFor.AllScripts) { FGFindInFiles.FindAllAssemblyScripts(AssemblyDefinition.UnityAssembly.CSharpEditorFirstPass); } if (lookForOption == FindReplace_LookFor.JSScripts || lookForOption == FindReplace_LookFor.AllScripts) { FGFindInFiles.FindAllAssemblyScripts(AssemblyDefinition.UnityAssembly.UnityScriptEditorFirstPass); } if (lookForOption == FindReplace_LookFor.BooScripts || lookForOption == FindReplace_LookFor.AllScripts) { FGFindInFiles.FindAllAssemblyScripts(AssemblyDefinition.UnityAssembly.BooEditorFirstPass); } } if (lookInOption == FindReplace_LookIn.EditorAssemblies || lookInOption == FindReplace_LookIn.AllEditorAssemblies) { if (lookForOption == FindReplace_LookFor.CSharpScripts || lookForOption == FindReplace_LookFor.AllScripts) { FGFindInFiles.FindAllAssemblyScripts(AssemblyDefinition.UnityAssembly.CSharpEditor); } if (lookForOption == FindReplace_LookFor.JSScripts || lookForOption == FindReplace_LookFor.AllScripts) { FGFindInFiles.FindAllAssemblyScripts(AssemblyDefinition.UnityAssembly.UnityScriptEditor); } if (lookForOption == FindReplace_LookFor.BooScripts || lookForOption == FindReplace_LookFor.AllScripts) { FGFindInFiles.FindAllAssemblyScripts(AssemblyDefinition.UnityAssembly.BooEditor); } } allTextAssetGuids = FGFindInFiles.assets.ToArray(); } else { allTextAssetGuids = FindAllTextAssets().ToArray(); IEnumerable <string> realTextAssets = null; switch (lookForOption) { case FindReplace_LookFor.AllAssets: realTextAssets = from guid in allTextAssetGuids where !ignoreFileTypes.Contains(Path.GetExtension(AssetDatabase.GUIDToAssetPath(guid).ToLowerInvariant())) select guid; break; case FindReplace_LookFor.AllScripts: realTextAssets = from guid in allTextAssetGuids where scriptFileTypes.Contains(Path.GetExtension(AssetDatabase.GUIDToAssetPath(guid).ToLowerInvariant())) select guid; break; case FindReplace_LookFor.CSharpScripts: realTextAssets = from guid in allTextAssetGuids where Path.GetExtension(AssetDatabase.GUIDToAssetPath(guid).ToLowerInvariant()) == ".cs" select guid; break; case FindReplace_LookFor.JSScripts: realTextAssets = from guid in allTextAssetGuids where Path.GetExtension(AssetDatabase.GUIDToAssetPath(guid).ToLowerInvariant()) == ".js" select guid; break; case FindReplace_LookFor.BooScripts: realTextAssets = from guid in allTextAssetGuids where Path.GetExtension(AssetDatabase.GUIDToAssetPath(guid).ToLowerInvariant()) == ".boo" select guid; break; case FindReplace_LookFor.Shaders: realTextAssets = from guid in allTextAssetGuids where shaderFileTypes.Contains(Path.GetExtension(AssetDatabase.GUIDToAssetPath(guid).ToLowerInvariant())) select guid; break; case FindReplace_LookFor.TextAssets: realTextAssets = from guid in allTextAssetGuids where !nonTextFileTypes.Contains(Path.GetExtension(AssetDatabase.GUIDToAssetPath(guid).ToLowerInvariant())) select guid; break; } allTextAssetGuids = realTextAssets.ToArray(); } var searchOptions = new SearchOptions { text = findText, matchCase = matchCase, matchWord = matchWholeWord, }; FindResultsWindow.Create( "Searching for '" + findText + "'...", FindInFile, allTextAssetGuids, searchOptions, listResultsInNewWindow); }