Beispiel #1
0
        static public ScenesPackage CreatePackage(string folder, string packageName, string[] scenesToCreate)
        {
            if (scenesToCreate == null || scenesToCreate.Length == 0)
            {
                Debug.LogWarning("ScenesPackage Creator : Indiquez au moins une scène à créer");
                return(null);
            }
            else if (!AssetDatabase.IsValidFolder(folder))
            {
                Debug.LogWarning("ScenesPackage Creator : Le dossier spécifié n'est pas valide");
                return(null);
            }

            ScenesPackage package     = ScriptableObject.CreateInstance <ScenesPackage>();
            string        assetFolder = AssetDatabase.GenerateUniqueAssetPath(folder + "/" + packageName);
            string        assetPath;

            // Create the base folder and the scene package
            AssetDatabase.CreateFolder(folder, packageName);
            assetPath = AssetDatabase.GenerateUniqueAssetPath(assetFolder + "/" + packageName);
            AssetDatabase.CreateAsset(package, assetPath + ".asset");

            // Create the scenes
            SerializedObject   packageObject = new SerializedObject(package);
            SerializedProperty scenesProp    = packageObject.FindProperty("_scenes");
            int scenesCreated = 0;

            packageObject.Update();

            for (int i = 0; i < scenesToCreate.Length; ++i)
            {
                if (scenesToCreate[i] == "")
                {
                    continue;
                }

                // New scene
                Scene newScene = EditorSceneManager.NewScene(NewSceneSetup.EmptyScene, NewSceneMode.Single);
                EditorSceneManager.SaveScene(newScene, assetPath + "_" + scenesToCreate[i] + ".unity");

                // Get the asset of the scene and add it on the package
                SceneAsset newSceneAsset = AssetDatabase.LoadAssetAtPath <SceneAsset>(newScene.path);

                scenesProp.arraySize++;
                scenesProp.GetArrayElementAtIndex(i).FindPropertyRelative("sceneAsset").objectReferenceValue = newSceneAsset;

                scenesCreated++;
            }

            packageObject.ApplyModifiedProperties();

            ScenesPackageHelper.LoadScenesPackage(packageObject.targetObject as ScenesPackage);

            Debug.Log(string.Format("ScenesPackage Creator : \"{0}\" créé, incluant {1} scènes", packageName, scenesCreated));

            return(packageObject.targetObject as ScenesPackage);
        }
Beispiel #2
0
        void CloseDelayed()
        {
            if (saveScenes)
            {
                ScenesPackageHelper.SaveAllScenes(serializedObject.targetObject as ScenesPackage);
            }

            ScenesPackageHelper.CloseAllScenes();
            Selection.activeObject = target;
        }
        static public AssetDeleteResult OnWillDeleteAsset(string asset, RemoveAssetOptions options)
        {
            ScenesPackage scenePackage = AssetDatabase.LoadAssetAtPath <ScenesPackage>(asset);

            if (scenePackage != null)
            {
                // Delete the scene from the build settings
                ScenesPackageHelper.RemoveScenesPackageFromBuild(scenePackage);
            }

            return(AssetDeleteResult.DidNotDelete);
        }
        void OnGUI()
        {
            EditorGUILayout.LabelField("ScenesPackage Creator", EditorStyles.largeLabel);
            EditorGUILayout.Separator();

            windowObject.Update();

            scroll = EditorGUILayout.BeginScrollView(scroll);

            EditorGUI.BeginChangeCheck();
            EditorGUILayout.PropertyField(templateProp);

            if (EditorGUI.EndChangeCheck())
            {
                SetTemplate();
            }

            EditorGUILayout.PropertyField(folderProp, folderLabel);
            EditorGUILayout.PropertyField(packageNameProp, packageNameLabel);

            EditorGUILayout.Separator();

            ScenesPackageGUIUtils.ArrayGUI(scenesToCreateProp, "Scenes à créer", "Indiquez le nom des scènes à créer. Elles seront préfixées avec le nom du package.");

            EditorGUILayout.Separator();

            if (GUILayout.Button("Créer le package", GUILayout.Height(30)))
            {
                ScenesPackage newPackage = ScenesPackageHelper.CreatePackage(folder, packageName, scenesToCreate);

                if (newPackage != null)
                {
                    Selection.activeObject = newPackage;
                }
            }

            EditorGUILayout.EndScrollView();

            windowObject.ApplyModifiedProperties();
        }
Beispiel #5
0
        override public void OnInspectorGUI()
        {
            serializedObject.Update();

            ScenesPackageGUIUtils.ArrayGUI(dependenciesProp, "Dépendances", "Package de scènes qui sera chargé avant celles de celui-ci.");
            ScenesPackageGUIUtils.ArrayGUI(scenesProp, "Scènes", "Scènes à charger, dans l'ordre.");

            EditorGUILayout.Separator();

            if (GUILayout.Button("Charger le package", GUILayout.Height(30)))
            {
                ScenesPackageHelper.LoadScenesPackage(serializedObject.targetObject as ScenesPackage);
            }

            if (GUILayout.Button("Sauvegarder toutes les scènes"))
            {
                ScenesPackageHelper.SaveAllScenes(serializedObject.targetObject as ScenesPackage);
            }

            EditorGUILayout.BeginHorizontal();
            if (GUILayout.Button("Sauvegarder et fermer"))
            {
                if (EditorUtility.DisplayDialog("Fermer", "Fermer le package ? Seules les scènes du package seront sauvegardées.", "Oui", "Non"))
                {
                    saveScenes = true;
                    EditorApplication.delayCall += CloseDelayed;
                }
            }

            if (GUILayout.Button("Fermer"))
            {
                if (EditorUtility.DisplayDialog("Fermer", "Fermer le package ? Toutes les modifications non sauvegardées seront perdues.", "Oui", "Non"))
                {
                    EditorApplication.delayCall += CloseDelayed;
                }
            }
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.Separator();

            if (GUILayout.Button("Ajouter les scenes dans la build"))
            {
                ScenesPackageHelper.AddScenesPackageInBuild(serializedObject.targetObject as ScenesPackage);
            }

            if (GUILayout.Button("Retirer les scenes de la build"))
            {
                ScenesPackageHelper.RemoveScenesPackageFromBuild(serializedObject.targetObject as ScenesPackage);
            }

            if (GUILayout.Button("Ouvrir les Build Settings"))
            {
                EditorApplication.ExecuteMenuItem("File/Build Settings...");
            }

            EditorGUILayout.Separator();

            EditorGUILayout.BeginVertical("Box");
            EditorGUI.indentLevel++;
            masterFoldout = EditorGUILayout.Foldout(masterFoldout, "Master package");
            EditorGUI.indentLevel--;

            if (masterFoldout)
            {
                EditorGUILayout.HelpBox("Master Package : La 1ère scène de ce package sera la 1ère scène chargée en jeu.", MessageType.Info);

                if (GUILayout.Button(masterProp.boolValue ? "Désactiver master" : "Activer master"))
                {
                    saveScenes           = false;
                    masterProp.boolValue = !masterProp.boolValue;
                }
            }
            EditorGUILayout.EndVertical();

            serializedObject.ApplyModifiedProperties();

            GUI.backgroundColor = Color.red;
            EditorGUILayout.Separator();
            EditorGUILayout.Separator();
            EditorGUILayout.Separator();
            EditorGUILayout.Separator();
            EditorGUILayout.BeginVertical("Box");
            EditorGUI.indentLevel++;

            dangerZoneFoldout = EditorGUILayout.Foldout(dangerZoneFoldout, "Danger zone");

            if (dangerZoneFoldout)
            {
                EditorGUILayout.HelpBox("Faites attentions à ce que vous faites !", MessageType.Warning);

                if (GUILayout.Button("Supprimer le package"))
                {
                    if (EditorUtility.DisplayDialog("Supprimer", "Êtes-vous sûr de vouloir supprimer le package. Toutes les scènes seront supprimées.", "Oui", "Non"))
                    {
                        ScenesPackageHelper.DeletePackage(serializedObject.targetObject as ScenesPackage);
                        EditorApplication.delayCall += CloseDelayed;
                    }
                }
            }

            EditorGUI.indentLevel--;
            EditorGUILayout.EndVertical();
            GUI.backgroundColor = Color.white;
        }