コード例 #1
0
    void CreateAndAddNewSceneReference(SceneAsset newSceneReferenceLevel)
    {
        if (newSceneReferenceLevel == null)
        {
            return;
        }

        SceneReference newSceneReference = CreateInstance <SceneReference> ();

        newSceneReference.levelScene = newSceneReferenceLevel;
        newSceneReference.menuScene  = AssetDatabase.LoadAssetAtPath <SceneAsset> (((SceneMenu)target).gameObject.scene.path);

        string newSceneReferencePath = AssetDatabase.GenerateUniqueAssetPath(k_NewSceneReferencePath);

        AssetDatabase.CreateAsset(newSceneReference, newSceneReferencePath);

        string newLevelPath  = AssetDatabase.GetAssetOrScenePath(newSceneReferenceLevel);
        Scene  newLevelScene = EditorSceneManager.OpenScene(newLevelPath, OpenSceneMode.Additive);

        SceneCompletion sceneCompletion = FindObjectOfType <SceneCompletion> ();

        sceneCompletion.sceneReference = newSceneReference;

        EditorUtility.SetDirty(sceneCompletion);
        EditorSceneManager.SaveScene(newLevelScene);
        EditorSceneManager.CloseScene(newLevelScene, true);

        m_LevelsProp.arraySize++;
        m_LevelsProp.GetArrayElementAtIndex(m_LevelsProp.arraySize - 1).FindPropertyRelative("level").objectReferenceValue = newSceneReference;
    }
コード例 #2
0
    static List <string> GetSceneReferencesFromActiveScene(out List <SceneReference> sceneReferences)
    {
        // Look for a SceneMenu in the scene.
        SceneMenu sceneMenu = Object.FindObjectOfType <SceneMenu>();

        if (sceneMenu != null)
        {
            // If there is one, just use the method which takes a reference to the SceneMenu.
            return(GetSceneReferencesFromSceneMenu(out sceneReferences, sceneMenu));
        }

        // Otherwise initialise the variables to be returned.
        List <string> uniqueScenePaths = new List <string>();

        sceneReferences = new List <SceneReference>();

        // Look for the SceneCompletion component.
        SceneCompletion sceneCompletion = Object.FindObjectOfType <SceneCompletion>();

        if (sceneCompletion == null)
        {
            throw new UnityException("Neither a SceneMenu or a SceneCompletion component were found in this Scene. No Scene setup can be done.");
        }

        // Find the menu for this level.
        SceneAsset menuScene = sceneCompletion.sceneReference.menuScene;

        if (menuScene == null)
        {
            throw new UnityException("No reference to the menu scene for this level was found. No Scene setup can be done.");
        }

        // Add a path to the menu first so it can be added to the build settings and will be the first opened for a build.
        uniqueScenePaths.Add(AssetDatabase.GetAssetOrScenePath(menuScene));

        // Get all SceneReference assets so they can be checked.
        List <SceneReference> allSceneReferences = SceneReferenceEditor.GetAllSceneReferences();

        for (int i = 0; i < allSceneReferences.Count; i++)
        {
            // Find all the SceneReference assets which use this menu scene.
            if (allSceneReferences[i].menuScene == menuScene)
            {
                // Add those SceneReferences to the list and get paths to them so they can be added to the build settings.
                sceneReferences.Add(allSceneReferences[i]);
                uniqueScenePaths.Add(AssetDatabase.GetAssetOrScenePath(allSceneReferences[i].levelScene));
            }
        }

        return(uniqueScenePaths);
    }