When setting up scenes for test cases, you often need to make preparations like adding a few prefabs, changing light settings and so on. With a script like this, you can map a recipe for a scene setup to a keyboard shortcut.
Created
September 20, 2016 12:05
-
-
Save mandarinx/289c01257e3d463a2f6b595b83859421 to your computer and use it in GitHub Desktop.
Create a custom scene in Unity3D
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEditor; | |
using UnityEditor.SceneManagement; | |
using UnityEngine; | |
using UnityEngine.SceneManagement; | |
static public class NewScene { | |
[MenuItem("File/New Custom Scene %&n")] | |
static public void CreateNewScene() { | |
if (!EditorSceneManager.SaveCurrentModifiedScenesIfUserWantsTo()) { | |
return; | |
} | |
Scene scene = EditorSceneManager.NewScene(NewSceneSetup.EmptyScene, | |
NewSceneMode.Single); | |
Instantiate("Prefabs/Main", scene); | |
Instantiate("Prefabs/CameraRig", scene); | |
RenderSettings.ambientIntensity = 1f; | |
RenderSettings.ambientLight = Color.white; | |
EditorSceneManager.MarkSceneDirty(scene); | |
} | |
static private void Instantiate(string asset, Scene scene) { | |
GameObject prefab = AssetDatabase.LoadAssetAtPath<GameObject>("Assets/"+asset+".prefab"); | |
PrefabUtility.InstantiatePrefab(prefab, scene); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment