private static bool LookForObjectsReferencesInHierarchy(Object[] objects, List <HierarchyReferenceItem> results) { var foundReferences = new Dictionary <int, Dictionary <ExactReferenceData, List <ExactReferenceData> > >(objects.Length); var objectInstanceIds = CSObjectTools.GetObjectsInstanceIDs(objects); var canceled = HierarchyEntryFinder.FillHierarchyReferenceEntries(objects, (lookAt, lookForInstanceId, settings) => { for (var i = 0; i < objectInstanceIds.Length; i++) { var instanceId = objectInstanceIds[i]; if (instanceId == lookForInstanceId) { ExactReferenceData referenced; if (!foundReferences.ContainsKey(instanceId)) { foundReferences.Add(instanceId, new Dictionary <ExactReferenceData, List <ExactReferenceData> >()); referenced = ObjectToReferencingEntry(objects[i]); foundReferences[instanceId].Add(referenced, new List <ExactReferenceData>()); } else { referenced = foundReferences[instanceId].Keys.First(); } var assetPath = CSObjectTools.TryGetObjectAssetPath(lookAt); var reference = EntryGenerator.CreateNewReferenceEntry(EntryFinder.currentLocation, lookAt, lookAt as GameObject, settings); var referenceData = new ExactReferenceData { assetPath = assetPath, reference = reference }; foundReferences[instanceId][referenced].Add(referenceData); } } }); if (!canceled && foundReferences.Count > 0) { BuildTree(foundReferences, results); } if (canceled) { HierarchyReferencesTab.AutoSelectHierarchyReference = null; } return(canceled); }
private static ExactReferenceData ObjectToReferencingEntry(Object target) { var referencedObjectAsComponent = target as Component; var referencedObjectGameObject = target as GameObject; if (referencedObjectAsComponent != null) { referencedObjectGameObject = referencedObjectAsComponent.gameObject; } if (referencedObjectGameObject == null) { Debug.LogError(Maintainer.ConstructError("Couldn't find referenced Game Object from object " + target)); return(new ExactReferenceData()); } var referencedSettings = new EntryAddSettings { componentName = referencedObjectAsComponent != null?CSComponentTools.GetComponentName(referencedObjectAsComponent) : null, componentIndex = referencedObjectAsComponent != null?CSComponentTools.GetComponentIndex(referencedObjectAsComponent) : -1, componentInstanceId = referencedObjectAsComponent != null?referencedObjectAsComponent.GetInstanceID() : -1, }; var reference = EntryGenerator.CreateNewReferenceEntry(EntryFinder.currentLocation, referencedObjectGameObject, referencedObjectGameObject, referencedSettings); var assetPath = CSObjectTools.TryGetObjectAssetPath(target); var result = new ExactReferenceData { reference = reference, assetPath = assetPath }; return(result); }