Esempio n. 1
0
    /// <summary>
    /// Writes a list of project-relative TextScene files to buildsettings. The
    /// corresponding binary unity scenes are stored in the Unity standard
    /// build-settings.
    /// </summary>
    private static void WriteBuildSettings(List <string> sceneList)
    {
        StreamWriter writer = File.CreateText(EditorHelper.GetProjectFolder() + buildSettingsFile);

        foreach (string scene in sceneList)
        {
            writer.Write("scene " + scene + '\n');
        }

        writer.Close();

        //Also update the editor build settings
        List <EditorBuildSettingsScene> binaryScenes = new List <EditorBuildSettingsScene>();

        foreach (string scene in sceneList)
        {
            EditorBuildSettingsScene ebss = new EditorBuildSettingsScene();

            ebss.path    = TextScene.TextSceneToTempBinaryFile(scene);
            ebss.enabled = true;

            binaryScenes.Add(ebss);
        }

        EditorBuildSettings.scenes = binaryScenes.ToArray();
    }
Esempio n. 2
0
    /// <summary>
    /// Adds the selected TextScene file to buildsettings. Also updates the standard Unity
    /// buildsettings.
    /// </summary>
    public static void AddSelectedSceneToBuild()
    {
        if (Selection.activeObject == null)
        {
            EditorUtility.DisplayDialog("Nothing selected", "You need to select a text scene asset to add to build", "OK");
            return;
        }

        TextAsset asset = Selection.activeObject as TextAsset;

        string assetPath = "";

        if (asset != null)
        {
            assetPath = AssetDatabase.GetAssetPath(asset);
        }

        if (!assetPath.EndsWith(".txt"))
        {
            EditorUtility.DisplayDialog("Not a text file", "Text scenes can be TextAssets (*.txt)", "OK");
        }
        else
        {
            TextScene.AddSceneToBuild(assetPath);
        }
    }
Esempio n. 3
0
        public GameObject[] Init(TextScene scene)
        {
            var gameObjects = new List <GameObject>();

            var i = 0;

            foreach (var button in SelectButtons)
            {
                var btn = new ButtonObject(new Text(button, Cache.GetFont("fonts/arial")), new Style());
                btn.Position         = new Vector2f(1920 / 2f - (btn.RectangleShape.Size.X / 2f), 1080 / 2f + (i * 40));
                btn.LeftClickHandler = () =>
                {
                    if (SelectScene.ContainsKey(button))
                    {
                        Game.Scene = Scene.Find(SelectScene[button]);
                    }
                    else
                    {
                        Game.Scene = Scene.Find(Game.DefaultScene);
                    }
                };

                gameObjects.Add(btn);
                i++;
            }

            return(gameObjects.ToArray());
        }
Esempio n. 4
0
    public TextSceneBuilder(string buildPath, BuildTarget buildTarget, List <string> sceneList)
    {
        if (sceneList == null)
        {
            sceneList = TextScene.ReadScenes();
        }

        if (sceneList.Count == 0)
        {
            EditorUtility.DisplayDialog("No scenes", "No scenes have been added to the build settings. Please add some, and try to build again.", "OK");
            return;
        }

        this.sceneQueue  = new Queue <string>(sceneList);
        this.sceneToLoad = TextSceneMonitor.Instance.GetCurrentScene();
        this.buildPath   = buildPath;
        this.buildTarget = buildTarget;

        if (EditorApplication.SaveCurrentSceneIfUserWantsTo())
        {
            TextSceneMonitor.Instance.SaveIfTempIsNewer();
        }
        else
        {
            Debug.Log("Cancelled build");
            return;
        }

        BuildNext();
    }
Esempio n. 5
0
    private static void MonitorStateChange()
    {
        if (EditorApplication.isPlayingOrWillChangePlaymode)
        {
            List <string> invalidScenes;

            if (!TextScene.ValidateBuildSettings(out invalidScenes))
            {
                EditorApplication.isPlaying = false;


                StringBuilder sb = new StringBuilder();

                sb.Append("Errors were found while validating Build Settings: \n");

                foreach (string scene in invalidScenes)
                {
                    sb.Append("   ");
                    sb.Append(scene);
                    sb.Append('\n');
                }

                sb.Append("Your levels may not switch correctly in play-mode! Do you want to fix up any outdated/missing temp file issues now?");

                if (EditorUtility.DisplayDialog("Build settings", sb.ToString(), "Yes", "No"))
                {
                    TextScene.BuildTempScenes(invalidScenes);
                }
            }
        }
    }
Esempio n. 6
0
        public void QuitToMenu()
        {
            TextScene confirm = new TextScene("Warning", "Are you sure you want to quit?");

            confirm.AddChoice("Yes", delegate() { Program.SceneManager.SetBaseScene(new TitleScene()); });
            confirm.AddChoice("No", delegate() { confirm.EndScene(); });
            AddSubscene(confirm);
        }
Esempio n. 7
0
 public GameObject[] Init(TextScene scene)
 {
     TextObject.Position = new Vector2f(15, 1080 - BoxObject.RectangleShape.Size.Y + 40);
     return new GameObject[]
     {
         BoxObject,
         TextObject
     };
 }
Esempio n. 8
0
        public void Update(TextScene scene)
        {
            if (scene.FocusedObject != InputObject && scene.FocusedObject != null)
            {
                return;
            }

            scene.FocusedObject = InputObject;
        }
Esempio n. 9
0
        public static void LoadGame()
        {
            TextScene     loadscreen = new TextScene("Choose your player", "", new Dictionary <string, Action>());
            List <Player> players    = Player.GetAllPlayers();

            foreach (Player p in players)
            {
                if (p.ID > 0)
                {
                    loadscreen.AddChoice(p.Name + " (" + p.Level + ")", delegate() { LoadPlayer(p.ID); });
                }
            }
            loadscreen.AddChoice("Cancel", delegate() { Program.SceneManager.EndSubscene(); });
            Program.SceneManager.AddSubscene(loadscreen);
        }
Esempio n. 10
0
        private void ShowNPCDetails()
        {
            NPC    npc    = Opponents[ChoiceIndex];
            Player player = Program.ActivePlayer;
            string text   =
                npc.Name + "\n" +
                npc.Description +
                "\nYour record against " + npc.Name +
                ":\nWins: " + player.GetWins(npc.ID) +
                " Losses: " + player.GetLosses(npc.ID) +
                " Ties: " + player.GetTies(npc.ID);
            TextScene confirm = new TextScene(text);

            confirm.AddChoice("Battle", delegate() { AddSubscene(new Battle(player, npc)); });
            confirm.AddChoice("Cancel", delegate() { EndSubscene(); });
            AddSubscene(confirm);
        }
Esempio n. 11
0
    private void showScene(string name)
    {
        DisplayObject newScene;

        switch (name)
        {
        case "Textures":
            newScene = new TextureScene();
            break;

        case "Multitouch":
            newScene = new TouchScene();
            break;

        case "TextFields":
            newScene = new TextScene();
            break;

        case "Animations":
            newScene = new AnimationScene();
            break;

        case "Movie Clip":
            newScene = new MovieScene();
            break;

        case "Blend Modes":
            newScene = new BlendModeScene();
            break;

        case "Clipping":
            newScene = new MaskScene();
            break;

        case "Benchmark":
            newScene = new BenchmarkScene();
            break;

        default:
            newScene = new Scene();
            break;
        }

        Game.viewManager.setView(newScene);
    }
Esempio n. 12
0
    /// <summary>
    /// Adds the currently open scene to the TextScene buildsettings, and updates
    /// the standard Unity buildsettings with the corresponding temp binary scene file.
    /// User will be notified if the current scene is not saved or is not a temp binary
    /// file.
    /// </summary>
    public static void AddCurrentSceneToBuild()
    {
        string currentScene = EditorApplication.currentScene;

        if (currentScene.Length == 0)
        {
            EditorUtility.DisplayDialog("Unsaved", "The currently open scene is not saved. Please save it using the TextScene menu option and try again.", "OK");
            return;
        }

        if (currentScene.StartsWith("Assets/"))
        {
            EditorUtility.DisplayDialog("Invalid scene", "The currently open scene is not a TextScene. Please re-save using the TextScene menu options and try again", "OK");
            return;
        }

        //Debug.Log("Text scene file to save in build settings: " + textSceneFile);

        TextScene.AddSceneToBuild(TextScene.TempToTextSceneFile(EditorApplication.currentScene));
    }
Esempio n. 13
0
    public static void SaveAs()
    {
        string currentScene = EditorApplication.currentScene;

        string startFolder = "";



        if (currentScene.Length == 0)
        {
            SaveCurrent();
            return;
        }
        else if (currentScene.StartsWith("Assets/"))
        {
            string needResaveAs = currentScene.Substring(currentScene.IndexOf('/'));

            needResaveAs = needResaveAs.Replace(".unity", ".txt");

            needResaveAs = Application.dataPath + needResaveAs;

            startFolder = needResaveAs.Substring(0, needResaveAs.LastIndexOf('/'));
        }
        else
        {
            //TODO: Verify that it starts with TempScenes?

            startFolder = EditorHelper.GetProjectFolder() + TextScene.TempToTextSceneFile(currentScene);

            startFolder = startFolder.Substring(0, startFolder.LastIndexOf('/'));
        }

        string fileName = EditorUtility.SaveFilePanel("Save TextScene as", startFolder, "textscene", "txt");

        if (fileName.Length > 0)
        {
            Save(fileName);
        }
    }
Esempio n. 14
0
        public bool HandleFrame(TextScene scene)
        {
            BoxObject.UpperText = Character.Id;

            if (Index < Text.Length)
            {
                if (Index != 0)
                {
                    TextObject.Text += " " + Text[Index];
                }
                else
                {
                    TextObject.Text = Text[Index];
                    TextObject.TextTyped.DisplayedString = "";
                }

                Index++;
                if (Index < Text.Length) return false;
            }

            return true;
        }
Esempio n. 15
0
    void OnInspectorUpdate()
    {
        //TODO FIXME HACK: I can't currently see how to make the instance survive a play/stop session,
        //                 so we just make sure it is constantly requested (and renewed if necessary).
        //UPDATE: Moved this to a possibly even worse hack, but at least it works without needing to have
        //        this editor window active.
        //TextSceneMonitor.MonitorUpdate();


        if (EditorApplication.timeSinceStartup > nextBuildSettingsCheck)
        {
            nextBuildSettingsCheck = EditorApplication.timeSinceStartup + 2.0f;

            DateTime buildSettingsTime = TextScene.BuildSettingsDate();

            if (buildSettingsTime > loadedBuildSettingsTime)
            {
                LoadSettings();
                loadedBuildSettingsTime = buildSettingsTime;
            }
        }
    }
Esempio n. 16
0
    //TODO: Finish up and make public!
    public static bool ValidateBuildSettings(out List <string> invalidScenes)
    {
        SyncBuildSettings();

        List <string> sceneList = ReadScenes();

        invalidScenes = new List <string>();

        foreach (string scene in sceneList)
        {
            string absoluteTextScene = EditorHelper.GetProjectFolder() + scene;

            //Make sure the scene exists at all in a TextScene format
            if (!File.Exists(absoluteTextScene))
            {
                Debug.LogWarning("Scene does not exist: " + scene);

                EditorApplication.isPlaying = false;

                if (EditorUtility.DisplayDialog("Invalid scene", "The scene '" + scene + "' is listed in your build settings but it does not exist. Do you want to remove it from build settings?", "Yes", "No"))
                {
                    TextScene.RemoveSceneFromBuild(scene);
                }
                else
                {
                    invalidScenes.Add(scene);
                    continue;
                }
            }
            else
            {
                //While the textscene might be present, we also need the binary temp file.
                //Make sure there is one up-to-date, if not, the user should be prompted
                //to generate one.
                string absoluteBinaryTempScene = EditorHelper.GetProjectFolder() + TextSceneToTempBinaryFile(scene);

                if (!File.Exists(absoluteBinaryTempScene))
                {
                    Debug.LogWarning("Temp scene does not exist: " + absoluteBinaryTempScene);

                    //EditorApplication.isPlaying = false;
                    //if (EditorUtility.DisplayDialog("Missing temp file", "Missing temp file for '" + scene + "' - do you want to generate it now?", "Yes", "No"))
                    //    TextSceneDeserializer.LoadSafe(absoluteTextScene);

                    invalidScenes.Add(scene);
                    continue;
                }
                else
                {
                    //Both files exist, but we also need to make sure the temp scene isn't outdated.
                    DateTime textSceneTime       = File.GetLastWriteTime(absoluteTextScene);
                    DateTime binaryTempSceneTime = File.GetLastWriteTime(absoluteBinaryTempScene);

                    if (textSceneTime > binaryTempSceneTime)
                    {
                        Debug.LogWarning("Temp scene for '" + scene + "' is outdated: " + binaryTempSceneTime + " is older than " + textSceneTime);

                        //EditorApplication.isPlaying = false;
                        //if (EditorUtility.DisplayDialog("Outdated temp file", "Outdated temp file for '" + scene + "' - do you want to update it now?", "Yes", "No"))
                        //    TextSceneDeserializer.LoadSafe(absoluteTextScene);

                        invalidScenes.Add(scene);
                        continue;
                    }
                }
            }
        }

        return(invalidScenes.Count == 0);
    }
Esempio n. 17
0
 public static void AddCurrentToBuild()
 {
     TextScene.AddCurrentSceneToBuild();
 }
Esempio n. 18
0
    private void showScene(string name)
    {
        DisplayObject newScene;

        switch(name)
        {
            case "Textures":
                newScene = new TextureScene();
                break;
            case "Multitouch":
                newScene = new TouchScene();
                break;
            case "TextFields":
                newScene = new TextScene();
                break;
            case "Animations":
                newScene = new AnimationScene();
                break;
            case "Movie Clip":
                newScene = new MovieScene();
                break;
            case "Blend Modes":
                newScene = new BlendModeScene();
                break;
            case "Clipping":
                newScene = new MaskScene();
                break;
            case "Benchmark":
                newScene = new BenchmarkScene();
                break;
            default :
                newScene = new Scene();
                break;
        }

        Game.viewManager.setView( newScene );
    }
Esempio n. 19
0
 public static void AddContext()
 {
     TextScene.AddSelectedSceneToBuild();
 }
Esempio n. 20
0
 public bool HandleFrame(TextScene scene)
 {
     return(false);
 }
Esempio n. 21
0
    public Status Update()
    {
        if (saveAndReload.Length == 0)
        {
            Debug.LogError("Invalid saveandreload name! Cancelling load/save process...");
            return(Status.Failed);
        }

        if (saveAndReloadTimer > 0)
        {
            EditorUtility.DisplayProgressBar("Creating temp...", "Creating binary temp file for TextScene: " + state.ToString(), 1.0f - saveAndReloadTimer / SAVE_AND_RELOAD_FRAMES);

            saveAndReloadTimer--;
            return(Status.Working);
        }
        else
        {
            if (state == State.SaveTemp)
            {
                Debug.Log("SaveAndReload: " + saveAndReload);

                ///FIXME: Unity sometimes puts a lock on the scenes we try to save, this is a CRUEL way to
                ///get around it.
                ///
                ///Repro-steps: *Comment out the try/catch
                ///             *Clean out tempscenes-folder.
                ///             *Open up a scene (LEVEL1) from build settings, hit play
                ///             *While playing, do something to make the game
                ///              change to another level (LEVEL2).
                ///             *Stop playing, you should now be back in the level where you
                ///              hit play from.
                ///             *Try to switch to the level you switched to in-game (LEVEL2).
                ///             *You should, after the progress bar has completed, be prompted
                ///              with an error saying Unity could not move file from Temp/Tempfile
                ///
                try
                {
                    FileStream f = File.OpenWrite(saveAndReload);
                    f.Close();
                }
                catch
                {
                    Debug.LogWarning("HACK: Getting around 'access denied' on temp files!");

                    //HACK: This seems to make Unity release the file so we can try to save it in a new go.
                    if (!EditorApplication.OpenScene(saveAndReload))
                    {
                        //Uh oh.
                        Debug.LogError("HACK failed! What to do next?");
                        EditorUtility.ClearProgressBar();
                        return(Status.Failed);
                    }

                    TextSceneDeserializer.Load(EditorHelper.GetProjectFolder() + TextScene.TempToTextSceneFile(EditorApplication.currentScene), saveAndReloadCallback);
                    return(Status.Working);
                }

                if (!EditorApplication.SaveScene(saveAndReload))
                {
                    Debug.LogError("Failed to save temp: " + saveAndReload);


                    if (EditorUtility.DisplayDialog("ERROR", "Failed to save temp (" + saveAndReload + ") - try again?", "Yes", "No"))
                    {
                        saveAndReloadTimer = Mathf.RoundToInt(SAVE_AND_RELOAD_FRAMES);
                    }
                    else
                    {
                        return(Status.Failed);
                    }


                    EditorUtility.ClearProgressBar();
                    return(Status.Working);
                }

                state = State.CreateNew;
                saveAndReloadTimer = Mathf.RoundToInt(SAVE_AND_RELOAD_FRAMES);
                return(Status.Working);
            }
            else if (state == State.CreateNew)
            {
                EditorApplication.NewScene();

                state = State.LoadTemp;
                saveAndReloadTimer = Mathf.RoundToInt(SAVE_AND_RELOAD_FRAMES);
                return(Status.Working);
            }
            else if (state == State.LoadTemp)
            {
                if (!EditorApplication.OpenScene(saveAndReload))
                {
                    Debug.LogError("Failed to load temp: " + saveAndReload);

                    if (EditorUtility.DisplayDialog("ERROR", "Failed to load temp (" + saveAndReload + ") - try again?", "Yes", "No"))
                    {
                        saveAndReloadTimer = Mathf.RoundToInt(SAVE_AND_RELOAD_FRAMES);
                    }
                    else
                    {
                        return(Status.Failed);
                    }

                    EditorUtility.ClearProgressBar();
                    return(Status.Working);
                }

                string writtenFile = EditorHelper.GetProjectFolder() + EditorApplication.currentScene;

                DateTime writtenTime = File.GetLastWriteTime(writtenFile);

                Debug.Log("Wrote temp file at " + writtenTime);

                TextSceneMonitor.Instance.SetCurrentScene(EditorHelper.GetProjectFolder() + TextScene.TempToTextSceneFile(EditorApplication.currentScene));

                saveAndReload = "";

                EditorUtility.ClearProgressBar();

                return(Status.Complete);
            }
        }

        Debug.LogError("Failing....");
        return(Status.Failed);
    }
Esempio n. 22
0
 public GameObject[] Init(TextScene scene)
 {
     return(Array.Empty <GameObject>());
 }
Esempio n. 23
0
 public bool HandleFrame(TextScene scene)
 {
     return(true);
 }
Esempio n. 24
0
    void OnGUI()
    {
        GUILayout.BeginVertical();

        scroll = GUILayout.BeginScrollView(scroll);

        GUILayout.Label("Scenes to build");

        foreach (string scene in scenes)
        {
            EditorGUILayout.BeginHorizontal();

            if (GUILayout.Button(scene))
            {
                TextSceneDeserializer.LoadSafe(EditorHelper.GetProjectFolder() + scene);
                GUIUtility.ExitGUI();
                return;
            }


            if (GUILayout.Button("Remove", GUILayout.MaxWidth(60)))
            {
                if (EditorUtility.DisplayDialog("Remove scene", "Are you sure you want to remove this scene from the build settings?", "Yes", "No"))
                {
                    TextScene.RemoveSceneFromBuild(scene);
                    LoadSettings();
                }
            }

            if (GUILayout.Button("+", GUILayout.MaxWidth(20)))
            {
                TextScene.MoveScenePosition(scene, 1);
                LoadSettings();
            }

            if (GUILayout.Button("-", GUILayout.MaxWidth(20)))
            {
                TextScene.MoveScenePosition(scene, -1);
                LoadSettings();
            }

            GUILayout.EndHorizontal();
        }

        if (scenes.Count > 0)
        {
            EditorGUILayout.Separator();
            EditorGUILayout.BeginVertical(GUILayout.MaxWidth(150));

            if (GUILayout.Button("Build Temp"))
            {
                TextScene.BuildTempScenes();
                GUIUtility.ExitGUI();
                return;
            }

            if (GUILayout.Button("Build Streamed Web"))
            {
                TextScene.Build(BuildTarget.WebPlayerStreamed);
                GUIUtility.ExitGUI();
                return;
            }

            if (GUILayout.Button("Build Web"))
            {
                TextScene.Build(BuildTarget.WebPlayer);
                GUIUtility.ExitGUI();
                return;
            }

            if (GUILayout.Button("Build OSX"))
            {
                TextScene.Build(BuildTarget.StandaloneOSXUniversal);
                GUIUtility.ExitGUI();
                return;
            }

            if (GUILayout.Button("Build Windows"))
            {
                TextScene.Build(BuildTarget.StandaloneWindows);
                GUIUtility.ExitGUI();
                return;
            }

            EditorGUILayout.EndVertical();
        }
        else
        {
            GUILayout.Label("Add scenes via the TextScene menu item to enable build");
        }

        EditorGUILayout.Separator();

        if (GUILayout.Button("Add current", GUILayout.MaxWidth(100)))
        {
            TextScene.AddCurrentSceneToBuild();
            LoadSettings();
        }

        EditorGUILayout.Separator();

        if (GUILayout.Button("Validate Settings", GUILayout.MaxWidth(100)))
        {
            List <string> invalidScenes;

            if (TextScene.ValidateBuildSettings(out invalidScenes))
            {
                EditorUtility.DisplayDialog("Valid settings", "The build settings seem valid enough", "OK");
            }
            else
            {
                StringBuilder sb = new StringBuilder();

                sb.Append("There were errors in validation: \n");

                foreach (string scene in invalidScenes)
                {
                    sb.Append("   ");
                    sb.Append(scene);
                    sb.Append('\n');
                }

                sb.Append("Try running 'Build Temp' to fix them up, or inspect the console for further hints.");

                EditorUtility.DisplayDialog("Validation failed", sb.ToString(), "OK");
            }
        }

        GUILayout.EndScrollView();

        GUILayout.EndVertical();
    }
Esempio n. 25
0
 public void Update(TextScene scene)
 {
 }
Esempio n. 26
0
    void LoadSettings()
    {
        scenes = TextScene.ReadScenes();

        loadedBuildSettingsTime = TextScene.BuildSettingsDate();
    }