Skip to content

Commit

Permalink
* SearchReferencesFast: Mutli-threading fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
NibbleByte committed Oct 9, 2023
1 parent 10792b6 commit 175f676
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions Editor/SearchReferencesFast.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ static SearchReferencesFast()
var implementingTypes = TypeCache.GetTypesDerivedFrom<IResultProcessor>().ToList();

ResultProcessors = new List<IResultProcessor>();

foreach (var implType in implementingTypes) {
var resultProcessor = (IResultProcessor) Activator.CreateInstance(implType);
ResultProcessors.Add(resultProcessor);
ResultProcessors.Add(resultProcessor);
}
}

[MenuItem("Tools/Asset Management/Search References (FAST)", false, 61)]
static void Init()
{
Expand Down Expand Up @@ -347,8 +347,9 @@ private void PerformSearchWork(List<SearchEntryData> targetEntries)
task.Start();
}

while (tasks.Any(a => a.Status == TaskStatus.Running)) {
while (tasks.Any(a => !a.IsCompleted)) {
ShowTasksProgress(progressHandles, searchPaths.Length, tasks.Count);
System.Threading.Thread.Sleep(200);
}

foreach (var task in tasks) {
Expand Down Expand Up @@ -486,10 +487,10 @@ private static bool ContentMatchesSearch(SearchEntryData searchData, string cont

if (matchGuidOnly || string.IsNullOrEmpty(searchData.LocalId))
return content.Contains(searchData.Guid);

int guidIndex = 0;
while (true) {

guidIndex = content.IndexOf(searchData.Guid, guidIndex + 1, StringComparison.Ordinal);

if (guidIndex < 0)
Expand Down Expand Up @@ -572,7 +573,7 @@ private static List<T[]> Split<T>(T[] targets, int chunkSize)
}
return output;
}

private void DrawResults()
{
GUILayout.Label("Results:", EditorStyles.boldLabel);
Expand Down Expand Up @@ -621,7 +622,7 @@ private void DrawResults()
_selectedResultProcessor,
processorNames,
GUILayout.Width(150));

if (GUILayout.Button(EditorGUIUtility.IconContent("PlayButton"), GUILayout.ExpandWidth(false))) {
IEnumerable<UnityEngine.Object> results = _results.Data
.Where(
Expand All @@ -639,7 +640,7 @@ private void DrawResults()
}
}
}

EditorGUILayout.EndHorizontal();

EditorGUILayout.BeginVertical();
Expand Down Expand Up @@ -1075,8 +1076,8 @@ private void TryGetGUIDAndLocalFileIdentifier(Object target)
long localId;
AssetDatabase.TryGetGUIDAndLocalFileIdentifier(target, out guid, out localId);
Guid = guid;



// LocalId is 102900000 for folders, scenes and unknown asset types. Probably marks this as invalid id.
// For unknown asset types, which actually have some localIds inside them (custom made), this will be invalid when linked in places.
Expand Down

0 comments on commit 175f676

Please sign in to comment.