public override IEnumerable <ObjectNode> Init(object target)
        {
            var targetObj = target as Object;

            var targets = new[] { targetObj }.ToHashSet();

            //var sceneGraphs = sceneFilePaths.Select( path => ObjectDependencyUtil.GetReferenceGraph( path, targets ) );

            var sceneGraphs = new[] { ObjectDependencyUtil.GetActiveSceneReferenceGraph(targets) };

            // when all sceneGraphs are empty, add a dummy node to represent the target
            if (sceneGraphs.All(x => !x.Keys.Any()))
            {
                string targetNodeName = targetObj.name + "\n(unreferenced)";
                var    dummyNode      = new ObjectNode(targetNodeName, targetNodeName, new[] { targetObj }, false);
                var    dummyGraph     = new ObjNodeGraph();
                dummyGraph[dummyNode] = new HashSet <ObjectNode>();
                sceneGraphs           = new[] { dummyGraph };
            }

            foreach (var g in sceneGraphs)
            {
                ObjectDependencyUtil.AddGraph(referenceGraph, g);
            }

            System.GC.Collect();
            return(ObjectGraphUtil.GetRoots(referenceGraph));
        }
 public override void OnDestroy()
 {
     if (graph != null)
     {
         // destroy all cycleReps
         var cycleReps = ObjectGraphUtil.GetAllNodes(graph).OfType <CycleRep>().ToArray();
         foreach (var cycleRep in cycleReps)
         {
             Object.DestroyImmediate(cycleRep);
         }
     }
 }
        public override IEnumerable <Object> Init(object target)
        {
            var targetObj = target as Object;
            // generate the dependency graph for this target
            var rootGOgraph = ObjectGraphUtil.GetDependencyGraph(targetObj, new Object[0]);

            // merge it with the existing graphs (of other targets)
            graph = ObjectGraphUtil.MergeGraphs(graph, rootGOgraph);

            System.GC.Collect();

            // targets have probably been substituted by cycleReps in the graph, so just use all parent-less nodes as seeds
            return(ObjectGraphUtil.GetRoots(rootGOgraph));
        }
        public static ObjNodeGraph GetActiveSceneReferenceGraph(HashSet <Object> targets)
        {
            var rootGameObjects = ActiveSceneRootGameObjects();

            // build the Object graph
            var objGraph    = new ObjMap();
            var targetArray = targets.ToArray();

            foreach (var rootGO in rootGameObjects)
            {
                var rootGOgraph = ObjectGraphUtil.GetDependencyGraph(rootGO, targetArray);
                objGraph = ObjectGraphUtil.MergeGraphs(objGraph, rootGOgraph);
            }

            // convert it to a SceneObjectNode graph, so we can destroy the objects
            return(ObjectGraphToObjectNodeGraph(objGraph, obj => GetActiveSceneObjectNode(obj, targets)));
        }
        public static ObjNodeGraph GetReferenceGraph(string sceneFilePath, HashSet <Object> targets)
        {
            // get the scene's objects
            var sceneObjects = UnityEditorInternal
                               .InternalEditorUtility
                               .LoadSerializedFileAndForget(sceneFilePath)
                               .ToHashSet();

            // get the root gameObjects
            var rootGOs = sceneObjects
                          .OfType <GameObject>()
                          .Where(go => go.transform.parent == null);

            // build the Object graph
            var objGraph    = new ObjMap();
            var targetArray = targets.ToArray();

            foreach (var rootGO in rootGOs)
            {
                var rootGOgraph = ObjectGraphUtil.GetDependencyGraph(rootGO, targetArray);
                objGraph = ObjectGraphUtil.MergeGraphs(objGraph, rootGOgraph);
            }

            // convert it to a SceneObjectNode graph, so we can destroy the objects
            var nodeGraph = ObjectGraphToObjectNodeGraph(objGraph, obj => GetSceneObjectNode(obj, targets, sceneObjects, sceneFilePath));

            // destroy the scene Objects
            var sceneObjArray = sceneObjects.ToArray();

            for (int i = 0; i < sceneObjArray.Length; i++)
            {
                Object.DestroyImmediate(sceneObjArray[i]);
            }
            System.GC.Collect();

            return(nodeGraph);
        }