コード例 #1
0
    /// <summary>
    /// Checks the .gitignore and if the default file is not added to the
    /// .gitignore, it will be added.
    /// </summary>
    public static void CheckAndUpdateGitIgnore()
    {
        // initialize variable to read file
        string line;

        // create path to gitignore
        string path = Path.Combine(Directory.GetCurrentDirectory(), gitignore);

        // check if the file exists
        if (File.Exists(path) == true)
        {
            // open file and read line by line
            StreamReader file = new System.IO.StreamReader(path);
            while ((line = file.ReadLine()) != null)
            {
                // if the scene is in the file then we should ignore it
                if (line == fileName)
                {
                    return;
                }
            }

            // close the file
            file.Close();

            // if here then the .gitignore isn't updated and the file should be added
            CreateSceneMenus.AddToGitIgnore(path);
        }
    }
コード例 #2
0
    /// <summary>
    /// Each available scene is added to the navigation menu by creating the file
    /// defined by filePath and then adding the functions to the file for unity to
    /// parse.
    /// </summary>
    public static void CreateScenes()
    {
        // Start string
        string completeFile = CreateSceneMenus.openingString;

        // get all paths
        string[] paths = AssetDatabase.GetAllAssetPaths();

        // loop through each path
        for (int i = 0; i < paths.Length; ++i)
        {
            // check if this is a scene
            if (paths[i].Contains(".unity"))
            {
                // strip beginning Assets/ foldr from string
                paths[i] = paths[i].Replace(CreateSceneMenus.assetFolder, "");

                // add function to file
                completeFile += CreateSceneMenus.CreateSceneString(paths[i], i);
            }
        }

        // add ending
        completeFile += CreateSceneMenus.endingString;

        // print file to file
        System.IO.StreamWriter writer = System.IO.File.CreateText(CreateSceneMenus.filePath);
        writer.Write(completeFile);
        writer.Flush();
        writer.Close();

        // Re build unity
        AssetDatabase.Refresh();
    }
コード例 #3
0
    /// <summary>
    /// Initializes the <see cref="CreateSceneMenus"/> class and immediatley
    /// sets up menu. It will overwrite on start to ensure files are not
    /// missed.
    /// </summary>
    static CreateSceneMenus()
    {
        // Create scenes
        CreateSceneMenus.CheckAndUpdateGitIgnore();
        CreateSceneMenus.CreateScenes();

        // subscribe to event when new scene is created
//		EditorSceneManager.NewSceneCreatedCallback += NewSceneCreated;
        EditorSceneManager.sceneSaved += CreateSceneMenus.NewSceneCreated;
    }
コード例 #4
0
 /// <summary>
 /// Called when a scene is being saved. This is useful for when this scene
 /// does not already exist.
 /// </summary>
 /// <param name="scene">Scene.</param>
 public static void NewSceneCreated(UnityEngine.SceneManagement.Scene scene)
 {
     CreateSceneMenus.CreateScenes();
 }