Ejemplo n.º 1
0
 static void OnSceneOpenCallback(Scene scene, OpenSceneMode sceneMode)
 {
     if (EditorSceneManager.GetSceneByBuildIndex((int)SceneIndex.MANAGER).isLoaded == false)
     {
         EditorSceneManager.OpenScene("Assets/Scenes/Persistent_Scene.unity", OpenSceneMode.Additive);
     }
 }
        public override VisualElement CreatePropertyGUI(SerializedProperty property)
        {
            if (property.propertyType == SerializedPropertyType.String)
            {
                var comboBox = new ComboBoxField();

                void options()
                {
                    var scenes = new List <string>();

                    for (var i = 0; i < EditorSceneManager.sceneCountInBuildSettings; i++)
                    {
                        var scene = EditorSceneManager.GetSceneByBuildIndex(i);
                        scenes.Add(scene.name);
                    }

                    comboBox.Options = scenes;
                }

                var action = new Action(options);

                action.Invoke();
                comboBox.schedule.Execute(action).Every(100);

                return(comboBox.ConfigureProperty(property));
            }
            else
            {
                Debug.LogErrorFormat(_invalidTypeError, property.propertyPath);
                return(new FieldContainer(property.displayName));
            }
        }
Ejemplo n.º 3
0
        public static void LoadFirstScene()
        {
            ToolsDebug.Log("LoadFirstScene " + cursor + " " + sceneHistoryList.Count);
            userLoadedScene = true;
#if UNITY_5_0_OR_NEWER || UNITY_2017_1_OR_NEWER
            EditorSceneManager.SaveCurrentModifiedScenesIfUserWantsTo();
            if (sceneHistoryList.Count >= maxLength)
            {
                sceneHistoryList.RemoveAt(0);
                sceneHistoryList.Add(new SceneRef(EditorSceneManager.GetActiveScene().path));
            }
            else
            {
                sceneHistoryList.Add(new SceneRef(EditorSceneManager.GetActiveScene().path));
            }
#else
            EditorApplication.SaveCurrentSceneIfUserWantsTo();
            if (sceneHistoryList.Count >= maxLength)
            {
                sceneHistoryList.RemoveAt(0);
                sceneHistoryList.Add(EditorApplication.currentScene);
            }
            else
            {
                sceneHistoryList.Add(EditorApplication.currentScene);
            }
#endif

#if UNITY_5_0_OR_NEWER || UNITY_2017_1_OR_NEWER
            if (EditorSceneManager.sceneCountInBuildSettings != 0)
            {
                if (EditorSceneManager.GetSceneByBuildIndex(0) != null)
                {
                    EditorSceneManager.OpenScene(EditorBuildSettings.scenes[0].path, OpenSceneMode.Single);
                }
                else
                {
                    ToolsDebug.Log("Not exist scenes in builds settings. ");
                }
            }
            else
            {
                ToolsDebug.Log("Not exist scenes in builds settings. ");
            }
#else
            if (EditorBuildSettings.scenes.Length != 0)
            {
                EditorApplication.OpenScene(EditorBuildSettings.scenes[0].path);
            }
            else
            {
                ToolsDebug.Log("Not exist scenes in builds settings. ");
            }
#endif
        }
Ejemplo n.º 4
0
    public virtual void OnGUI()
    {
        GUIContent guiContent;

        for (int i = 0; i < EditorSceneManager.sceneCountInBuildSettings; i++)
        {
            guiContent      = new GUIContent();
            guiContent.text = EditorSceneManager.GetSceneByBuildIndex(i).name;
            EditorGUILayout.DropdownButton(guiContent, FocusType.Passive);
        }
    }
Ejemplo n.º 5
0
 static bool allLevelScenesLoaded()
 {
     for (int i = FIRST_LEVEL_INDEX; i < EditorBuildSettings.scenes.Length; i++)
     {
         Scene scene = EditorSceneManager.GetSceneByBuildIndex(i);
         if (!scene.isLoaded)
         {
             return(false);
         }
     }
     return(true);
 }
Ejemplo n.º 6
0
        public static void DrawButton(int i)
        {
            bool isPlaymode = Application.isPlaying;
            var  scenePath  = SceneUtility.GetScenePathByBuildIndex(i);
            var  scene      = EditorSceneManager.GetSceneByBuildIndex(i);
            var  filename   = Path.GetFileName(scenePath);


            Color defualtColor = GUI.backgroundColor;


            GUILayout.BeginHorizontal();
            if (scene.isLoaded)
            {
                GUI.enabled         = !isPlaymode && EditorSceneManager.loadedSceneCount > 1;
                GUI.backgroundColor = GUI.enabled ? minusButtonColor : Color.gray;
                if (GUILayout.Button("-", GUILayout.Width(ControlButtonWidth)))
                {
                    if (!scene.isDirty || EditorSceneManager.SaveCurrentModifiedScenesIfUserWantsTo())
                    {
                        EditorSceneManager.CloseScene(scene, true);
                    }
                }
                GUI.enabled = true;
            }
            else
            {
                GUI.enabled         = !isPlaymode;
                GUI.backgroundColor = plusButtonColor;
                if (GUILayout.Button("+", GUILayout.Width(ControlButtonWidth)))
                {
                    EditorSceneManager.OpenScene(scenePath, OpenSceneMode.Additive);
                }
                GUI.enabled = true;
            }

            GUI.enabled         = !isPlaymode;
            GUI.backgroundColor = scene.isLoaded ? SceneButtonColor : ButtonColor;
            if (GUILayout.Button(filename.Substring(0, filename.IndexOf(".unity"))))
            {
                if (EditorSceneManager.SaveCurrentModifiedScenesIfUserWantsTo())
                {
                    EditorSceneManager.OpenScene(scenePath, OpenSceneMode.Single);
                }
            }
            GUILayout.EndHorizontal();
            GUI.enabled         = true;
            GUI.backgroundColor = defualtColor;
        }
Ejemplo n.º 7
0
    public static void loadOrUnloadLevelScenes()
    {
        //Find out if all of the scenes are loaded
        bool allLoaded = true;

        for (int i = FIRST_LEVEL_INDEX; i < EditorBuildSettings.scenes.Length; i++)
        {
            if (!EditorSceneManager.GetSceneByBuildIndex(i).isLoaded)
            {
                allLoaded = false;
                break;
            }
        }
        //If any are loaded, unload them all.
        //Else, load them all.
        loadAllLevelScenes(!allLoaded);
    }
Ejemplo n.º 8
0
 public static void loadAllLevelScenes(bool load)
 {
     //Load or unload all the level scenes
     for (int i = FIRST_LEVEL_INDEX; i < EditorBuildSettings.scenes.Length; i++)
     {
         Scene scene = EditorSceneManager.GetSceneByBuildIndex(i);
         if (!load)
         {
             //Unload
             EditorSceneManager.CloseScene(scene, false);
         }
         else
         {
             //Load
             EditorSceneManager.OpenScene(
                 "Assets/Scenes/Levels/" + scene.name + ".unity",
                 OpenSceneMode.Additive
                 );
             SetExpanded(scene, false);
         }
     }
 }
    public static void SummarizeScenes()
    {
        string output = "";

        if (EditorSceneManager.sceneCountInBuildSettings > 0)
        {
            for (int n = 0; n < EditorSceneManager.sceneCountInBuildSettings; ++n)
            {
                Scene scene = EditorSceneManager.GetSceneByBuildIndex(n);
                if (scene.IsValid())
                {
                    output += scene.name;
                    output += scene.isLoaded ? " (Opened, " : " (Not Opened, ";
                    output += scene.isDirty ? "Dirty, " : "Clean, ";
                    output += scene.buildIndex >= 0 ? " in build)\n" : " NOT in build)\n";
                }
            }
        }
        else
        {
            output = "No open scenes.";
        }
        EditorUtility.DisplayDialog("Scene Summary", output, "Ok");
    }
Ejemplo n.º 10
0
    public static void ExportBundle(string source)
    {
        string dest = Path.Combine(ModManager.GetModsfolderPath(), $"modfile_{Path.GetFileName(source)}");

        Debug.Log($"Exporting Mod: Source: \"{source}\", Target: \"{dest}\"");

        // Get Files and convert absolute paths to relative paths (required by the buildmap)
        string[] absolute_files = Directory.GetFiles(source).Where(name => !name.EndsWith(".meta") && !name.EndsWith(".cs")).ToArray();
        string[] files          = new string[absolute_files.Length];

        if (files.Length > 0)
        {
            int index = absolute_files[0].IndexOf("Assets");
            for (int i = 0; i < files.Length; i++)
            {
                files[i] = absolute_files[i].Substring(index);
            }
        }

        if (!CheckHasHolder(files))
        {
            throw new System.Exception($"Failed to export \"{Path.GetDirectoryName(source)}\". Make sure you have an appropriate holder included!");
        }

        // Prepare Bundle
        AssetBundleBuild[] build_map = new AssetBundleBuild[1];
        build_map[0].assetNames = files;

        // Build Folder / Bundle
        Directory.CreateDirectory(dest);
        foreach (var target in new Dictionary <OperatingSystemFamily, BuildTarget> {
            { OperatingSystemFamily.Windows, BuildTarget.StandaloneWindows64 }, { OperatingSystemFamily.Linux, BuildTarget.StandaloneLinux64 }, { OperatingSystemFamily.MacOSX, BuildTarget.StandaloneOSX }
        })
        {
            build_map[0].assetBundleName = $"{Path.GetFileName(source)}_{target.Key}";
            BuildPipeline.BuildAssetBundles(dest, build_map, BuildAssetBundleOptions.None, target.Value);
        }

        // Clean out manifest files and bundle holder
        try {
            if (Directory.GetFiles(dest).Count() > 10)  // FAILSAFE
            {
                throw new System.ArgumentException($"failsafe triggered: too many files found in mod folder! Skipping deletion of unneeded files!");
            }

            File.Delete(Path.Combine(dest, Path.GetFileName(dest)));
            foreach (var manifest in Directory.GetFiles(dest, "*.manifest", SearchOption.TopDirectoryOnly))
            {
                File.Delete(Path.Combine(dest, manifest));
            }
        } catch (System.UnauthorizedAccessException) {
            Debug.LogWarning("Unauthorized to delete obsolete files in the exported mod. These files are not needed and don't need to be removed manually.");
        } catch (System.ArgumentException e) {
            Debug.LogError(e);
        }

        // Make Thumbnail
        GameObject thumbnailMakerPrefab = UnityEditor.AssetDatabase.LoadAssetAtPath <GameObject>("Assets/ThumbnailMaker.prefab");

        if (thumbnailMakerPrefab)
        {
            Mod mod = ModImporter.ImportModNow(dest, true);

            string lastScene      = EditorSceneManager.GetActiveScene().path;
            int    lastBuildIndex = EditorSceneManager.GetActiveScene().buildIndex;

            // Create scene
            Scene          thumbnailScene = EditorSceneManager.NewScene(NewSceneSetup.EmptyScene, NewSceneMode.Single);
            ThumbnailMaker thumbnailMaker = Instantiate(thumbnailMakerPrefab).GetComponent <ThumbnailMaker>();

            File.WriteAllBytes(mod.GetThumbnailPath(), thumbnailMaker.CreateThumbnail(mod).EncodeToJPG(90));
            // Cleanup
            if (lastBuildIndex >= 0)
            {
                EditorSceneManager.OpenScene(lastScene, OpenSceneMode.Single);
            }
            else
            {
                EditorSceneManager.OpenScene(EditorSceneManager.GetSceneByBuildIndex(0).path);
            }
        }

        Debug.Log($"Export Completed. Name: \"{Path.GetFileName(source)}\" with {files.Length} files");
    }