static void CreateLevelTemplateAll() { ClearLevelTemplate(); GameObject[] allObjects = UnityEngine.SceneManagement.SceneManager.GetActiveScene().GetRootGameObjects(); //Store array of all root objects for (int x = 0; x < allObjects.Length; x++) //Loop through all objects { Object fileCheck = (Object)AssetDatabase.LoadAssetAtPath(levelPath + allObjects[x].name + ".prefab", typeof(Object)); //If the path already exists while (fileCheck) { allObjects[x].name = allObjects[x].name + "(clone)"; fileCheck = (Object)AssetDatabase.LoadAssetAtPath(levelPath + allObjects[x].name + ".prefab", typeof(Object)); } ObjectClipboard.MakePrefab(allObjects[x].transform.gameObject, levelPath); //Make prefab of individual object } }
static void CreateLevelTemplateSelected() { ClearLevelTemplate(); //SelectionHandler.DeselectChildren(); GameObject[] allObjects = Selection.gameObjects; for (int x = 0; x < allObjects.Length; x++) //Loop through all objects { Object fileCheck = (Object)AssetDatabase.LoadAssetAtPath(levelPath + allObjects[x].name + ".prefab", typeof(Object)); //If the path already exists while (fileCheck) { allObjects[x].name = allObjects[x].name + "(clone)"; fileCheck = (Object)AssetDatabase.LoadAssetAtPath(levelPath + allObjects[x].name + ".prefab", typeof(Object)); } ObjectClipboard.MakePrefab(allObjects[x].transform.gameObject, levelPath); //Make prefab of individual object } }