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);
            }
        }
    }
示例#2
0
    private void OnEnable()
    {
        _graph       = new DependencyViewerGraph();
        _graphDrawer = new DependencyViewerGraphDrawer(_graph);
        _settings    = DependencyViewerSettings.Create();
        _settings.Load();
        _settingsOverlay = new DependencyViewerSettingsOverlay(_settings);
        _resolver        = new DependencyResolver(_graph, _settings);
        _statusBar       = new DependencyViewerStatusBar();

        _settings.onSettingsChanged        += OnSettingsChanged;
        _graphDrawer.requestViewDependency += ViewDependencies;

        if (refTarget != null)
        {
            BuildGraph();
        }

        // If the active object is already a DependencyViewerSettings,
        // it probably means that some old settings are actually inspected.
        // Update the active object to now use the new settings object.
        if (Selection.activeObject is DependencyViewerSettings)
        {
            Selection.activeObject = _settings;
        }
    }
    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);
                }
            }
        }
    }
示例#4
0
 public DependencyResolver(DependencyViewerGraph graph, DependencyViewerSettings settings)
 {
     _graph                = graph;
     _settings             = settings;
     _referencesResolver   = new DependencyResolver_References(graph, settings);
     _dependenciesResolver = new DependencyResolver_Dependencies(settings);
 }
示例#5
0
 public DependencyViewerGraphDrawer(DependencyViewerGraph graph)
 {
     _graph           = graph;
     _titleLabelStyle = new GUIStyle()
     {
         alignment = TextAnchor.MiddleCenter
     };
 }
    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;
        }
    }
 public DependencyResolver_References(DependencyViewerGraph graph, DependencyViewerSettings settings)
 {
     _graph    = graph;
     _settings = settings;
 }