Beispiel #1
0
        private static void IterateThroughObjectTree(ChangePrefab changePrefabAction, GameObject go)
        {
            var prefabType = PrefabUtility.GetPrefabType(go);

            //Is the selected gameobject a prefab?
            if (prefabType == PrefabType.PrefabInstance || prefabType == PrefabType.DisconnectedPrefabInstance)
            {
                var prefabRoot = PrefabUtility.FindRootGameObjectWithSameParentPrefab(go);
                if (prefabRoot != null)
                {
                    changePrefabAction(prefabRoot);
                    changedObjectsCount++;
                    return;
                }
            }
            // If not a prefab, go through all children
            var transform = go.transform;
            var children  = transform.childCount;

            for (int i = 0; i < children; i++)
            {
                var childGo = transform.GetChild(i).gameObject;
                IterateThroughObjectTree(changePrefabAction, childGo);
            }
        }
Beispiel #2
0
        //Look for connections
        private static void SearchPrefabConnections(ChangePrefab changePrefabAction)
        {
            GameObject[] selectedTransforms = Selection.gameObjects;
            int          numberOfTransforms = selectedTransforms.Length;

            showProgressBar     = numberOfTransforms >= SelectionThresholdForProgressBar;
            changedObjectsCount = 0;
            //Iterate through all the selected gameobjects
            try
            {
                for (int i = 0; i < numberOfTransforms; i++)
                {
                    var go = selectedTransforms[i];
                    if (showProgressBar)
                    {
                        EditorUtility.DisplayProgressBar("Update prefabs", "Updating prefab " + go.name + " (" + i + "/" + numberOfTransforms + ")",
                                                         (float)i / (float)numberOfTransforms);
                    }
                    IterateThroughObjectTree(changePrefabAction, go);
                }
            }
            finally
            {
                if (showProgressBar)
                {
                    EditorUtility.ClearProgressBar();
                }
                Debug.LogFormat("{0} Prefab(s) updated", changedObjectsCount);
            }
        }
Beispiel #3
0
 private void Start()
 {
     SpawnHighlightCube();
     changePrefab = FindObjectOfType <ChangePrefab>();
     if (changePrefab == null)
     {
         Destroy(this);
     }
 }
Beispiel #4
0
        private static void SearchPrefabConnections(ChangePrefab changePrefabAction)
        {
            GameObject[] selectedTransforms  = Selection.gameObjects;
            int          numberOfTransforms  = selectedTransforms.Length;
            bool         showProgressBar     = numberOfTransforms >= SelectionThresholdForProgressBar;
            int          changedObjectsCount = 0;

            //Iterate through all the selected gameobjects
            try {
                for (int i = 0; i < numberOfTransforms; i++)
                {
                    if (showProgressBar)
                    {
                        EditorUtility.DisplayProgressBar("Update prefabs",
                                                         "Updating prefabs (" + i + "/" + numberOfTransforms + ")",
                                                         (float)i / (float)numberOfTransforms);
                    }

                    var go         = selectedTransforms[i];
                    var prefabType = PrefabUtility.GetPrefabType(go);
                    //Is the selected gameobject a prefab?
                    if (prefabType == PrefabType.PrefabInstance ||
                        prefabType == PrefabType.DisconnectedPrefabInstance)
                    {
                        var prefabRoot = PrefabUtility.FindRootGameObjectWithSameParentPrefab(go);
                        if (prefabRoot == null)
                        {
                            continue;
                        }

                        changePrefabAction(prefabRoot);
                        changedObjectsCount++;
                    }
                }
            }
            finally {
                if (showProgressBar)
                {
                    EditorUtility.ClearProgressBar();
                }
                Debug.LogFormat("{0} Prefab(s) updated", changedObjectsCount);
            }
        }