Class responsible for writing Unity scene hierarchies to a textual, humanly readable format.
Exemplo n.º 1
0
    private bool CheckForChangedTemp()
    {
        //Also check for temp binary file changes, so we can give the user some options.
        if (File.Exists(currentTempBinaryScene))
        {
            DateTime lastTempWrite = File.GetLastWriteTime(currentTempBinaryScene);

            if (lastTempWrite > currentSceneLoaded)
            {
                if (EditorUtility.DisplayDialog("Temp scene changed", "The temp scene changed (" + lastTempWrite + "), this probably means that either you or Unity saved using the standard menu items - you should re-save using the TextScene menu if you want these changes to be kept!", "Re-save now", "I'll do it later"))
                {
                    if (EditorApplication.currentScene != alarmingEditorScene)
                    {
                        EditorApplication.OpenScene(alarmingEditorScene);
                    }


                    TextSceneSerializer.SaveCurrent();
                    return(true);
                }
                else
                {
                    SetCurrentScene(currentScene);//Reset the timers so we don't get this popping up more than once per save.
                }
            }
        }

        return(false);
    }
Exemplo n.º 2
0
 public void SaveIfTempIsNewer()
 {
     if (File.Exists(currentTempBinaryScene))
     {
         if (File.GetLastWriteTime(currentTempBinaryScene) > currentSceneLoaded)
         {
             TextSceneSerializer.SaveCurrent();
             Debug.Log("Temp file updated: " + currentTempBinaryScene);
         }
         else
         {
             Debug.Log("Temp file already up to date: " + currentTempBinaryScene);
         }
     }
     else
     {
         Debug.LogWarning("Temp file does not exist!");
     }
 }
Exemplo n.º 3
0
 public static void SaveCurrent()
 {
     TextSceneSerializer.SaveCurrent();
 }
Exemplo n.º 4
0
 public static void SaveAs()
 {
     TextSceneSerializer.SaveAs();
 }
Exemplo n.º 5
0
    /// <summary>
    /// Regularly checks if something worthy of notifying the user happens. This includes
    /// unexpected scene changes (double-clicking .unity files), creating new scenes and
    /// source TextScene files having been changed between now and the time it was loaded.
    /// </summary>
    private void Update()
    {
        //HACK: To get around bug (TOOD: Insert case #) where Save immediately
        //      after instantiating prefabs results in weird behaviour.
        if (process != null)
        {
            TextSceneTempCreator.Status status = process.Update();

            switch (status)
            {
            case TextSceneTempCreator.Status.Failed:
                Debug.LogError("Creating temp files failed!");
                process = null;
                break;

            case TextSceneTempCreator.Status.Complete:
                Debug.Log("Creating temp files succeeded!");

                //FIXME: Either do this, or get a reference to the delegate and call
                //       if after clearing tempCreator. The callback might
                //       end up setting the tempCreator again, typically in a build-cycle,
                //       for example.
                TextSceneTempCreator tempCreatorRef = process;

                process = null;

                tempCreatorRef.InvokeCallback();

                break;

            default:
                break;
            }

            return;
        }

        //Did the user create a new scene?
        if (currentScene.Length > 0 &&
            EditorApplication.currentScene.Length == 0)
        {
            if (CheckForChangedTemp())
            {
                EditorApplication.NewScene();
            }

            currentScene        = "";
            alarmingEditorScene = "";

            TextSceneSerializer.SaveCurrent();

            //Warn the user if the save scene dialog was cancelled.
            if (currentScene.Length == 0)
            {
                EditorUtility.DisplayDialog("New Scene", "You have started a new scene after using the TextScene system. Please use the TextScene menu to save it if you want to continue using the TextScene system", "OK");
            }
        }

        //Try to detect when we go from a TextScene to a regular unit scene.
        if ((currentScene.Length > 0 &&
             EditorApplication.currentScene.Length > 0) ||
            (currentScene.Length == 0 &&
             alarmingEditorScene.Length == 0))
        {
            if (alarmingEditorScene != EditorApplication.currentScene)
            {
                string current = EditorApplication.currentScene;

                if (CheckForChangedTemp())
                {
                    EditorApplication.OpenScene(current);
                }

                if (EditorUtility.DisplayDialog("TextScene/built-in mixed usage", "It is not recommended to mix TextScene usage with built-in Unity scenes. This may cause the TextScene system to miss updates or simply behave totally weird! If you plan on using the TextScene system, you should save the current scene via the TextScene menu item and  - if successfully saved (please inspect the log for errors and warnings) - remove the original from the Assets folder. Please note that not all components/Unity objects can be saved into the TextScene format, so don't delete the original until you are 100% sure you saved what you need!", "Save to TextScene now!", "I know what I'm doing"))
                {
                    TextSceneSerializer.SaveCurrent();
                }
                else
                {
                    alarmingEditorScene = EditorApplication.currentScene;
                    currentScene        = "";
                }
            }
        }

        //Regular checks to see if the scene file was edited since our last load.
        if (currentScene.Length > 0 &&
            EditorApplication.timeSinceStartup > nextCheckForChangedFile)
        {
            if (File.Exists(currentScene))
            {
                DateTime lastWriteTime = File.GetLastWriteTime(currentScene);

                if (lastWriteTime > currentSceneLoaded)
                {
                    int result = EditorUtility.DisplayDialogComplex("Scene changed", "The TextScene you currently have open changed (" + lastWriteTime + "). Do you want to reload it?", "Yes", "Backup mine first", "No");

                    if (result == 0)                    //Yes
                    {
                        TextSceneDeserializer.Load(currentScene);
                    }
                    else if (result == 1)//Backup first
                    {
                        string filename = EditorUtility.SaveFilePanel("Backup TextScene", currentScene.Substring(0, currentScene.LastIndexOf('/')), "backup", "txt");

                        if (filename.Length != 0)
                        {
                            //This is overwritten during the save.
                            string toLoad = currentScene;

                            TextSceneSerializer.Save(filename);
                            TextSceneDeserializer.Load(toLoad);
                        }
                        else
                        {
                            EditorUtility.DisplayDialog("Unsaved", "You chose to cancel the backup of your own scene file. It is recommended that you manually save a copy, and merge with the updated file from disk (" + currentScene + ")", "OK");
                        }
                    }
                    else//No
                    {
                        //HACK: Shut this message up. We don't want to get asked this again until the
                        //      file changes again.
                        currentSceneLoaded = DateTime.Now;
                    }
                }
            }
            else
            {
                if (EditorUtility.DisplayDialog("TextScene file gone!", "It seems like the TextScene representation of your open file has been deleted. Do you want to re-save it (" + currentScene + ")?", "Yes", "No"))
                {
                    TextSceneSerializer.Save(currentScene);
                }
                else
                {
                    currentScene = "";
                }
            }

            //Also check for changed temp files (.unity in TempScenes). This happens if
            //the user uses the built-in save functionality.
            CheckForChangedTemp();

            nextCheckForChangedFile = EditorApplication.timeSinceStartup + 1.0f;
        }
    }