private IEnumerable <DependencyViewerOperation> FindReferencesOnUnityObject( DependencyViewerNode node, UnityEngine.Object obj, AssetDependencyResolverOperation op, GameObject prefabRoot = null) { SerializedObject objSO = new SerializedObject(obj); SerializedProperty sp = objSO.GetIterator(); while (sp.NextVisible(true)) { if (IsPropertyADependency(sp, node)) { // Reference found! DependencyViewerNode reference = new DependencyViewerNode(obj); DependencyViewerGraph.CreateNodeLink(reference, node); if (prefabRoot != null) { reference.SetAsPrefabContainerInfo(prefabRoot, (obj as Component).gameObject.name); } } ++op.numProcessedProperties; if (op.numProcessedProperties > NumAssetPropertiesReferencesResolvedPerFrame) { op.AssetBeingProcessed = obj; op.numProcessedProperties = 0; yield return(op); } } }
private void FindDependencies(DependencyViewerNode node, UnityEngine.Object obj, int depth = 1, GameObject prefabRoot = null) { SerializedObject targetObjectSO = new SerializedObject(obj); SerializedProperty sp = targetObjectSO.GetIterator(); while (sp.NextVisible(true)) { if (sp.propertyType == SerializedPropertyType.ObjectReference && sp.objectReferenceValue != null && IsObjectAllowedBySettings(sp.objectReferenceValue)) { // Dependency found! DependencyViewerNode dependencyNode = new DependencyViewerNode(sp.objectReferenceValue); DependencyViewerGraph.CreateNodeLink(node, dependencyNode); if (prefabRoot != null) { Component comp = obj as Component; dependencyNode.SetAsPrefabContainerInfo(prefabRoot, comp.gameObject.name); } if (depth > 1) { FindDependencies(dependencyNode, sp.objectReferenceValue, depth - 1); } } } }
private IEnumerable <DependencyViewerOperation> FindReferencesAmongGameObjects(DependencyViewerNode node, List <Scene> scenes) { AssetDependencyResolverOperation operationStatus = new AssetDependencyResolverOperation(); operationStatus.node = node; List <GameObject> allGameObjects = GetAllGameObjectsFromScenes(scenes); operationStatus.numTotalAssets = allGameObjects.Count; int numPropertiesCheck = 0; for (int i = 0; i < allGameObjects.Count; ++i) { GameObject currentGo = allGameObjects[i]; operationStatus.AssetBeingProcessed = currentGo; Component[] components = currentGo.GetComponents <Component>(); for (int componentIndex = 0; componentIndex < components.Length; ++componentIndex) { Component component = components[componentIndex]; if (component == null) { continue; } SerializedObject componentSO = new SerializedObject(component); SerializedProperty componentSP = componentSO.GetIterator(); while (componentSP.NextVisible(true)) { // Reference found! if (componentSP.propertyType == SerializedPropertyType.ObjectReference && componentSP.objectReferenceValue == node.TargetObject && IsObjectAllowedBySettings(component)) { DependencyViewerNode referenceNode = new DependencyViewerNode(component); DependencyViewerGraph.CreateNodeLink(referenceNode, node); } ++numPropertiesCheck; if (numPropertiesCheck > NumAssetPropertiesReferencesResolvedPerFrame) { numPropertiesCheck = 0; yield return(operationStatus); } } } ++operationStatus.numProcessedAssets; } }