Example #1
0
        static public void AddScenesPackageInBuild(ScenesPackage package)
        {
            List <string> scenesPath = new List <string>(GetScenesBuildPath());

            SceneField[] scenesToAdd = package.GetScenes(includeDependencies: false);

            for (int i = 0; i < scenesToAdd.Length; ++i)
            {
                if (scenesToAdd[i].Empty || scenesPath.Contains(scenesToAdd[i].ScenePath))
                {
                    continue;
                }

                if (package._master && i == 0)
                {
                    scenesPath.Insert(0, scenesToAdd[i].ScenePath);
                }
                else
                {
                    scenesPath.Add(scenesToAdd[i].ScenePath);
                }
            }

            SetScenesBuildPath(scenesPath.ToArray());

            Debug.Log(string.Format("{0} : Les scenes ont été ajoutées à la build", package.name), package);
        }
Example #2
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);
        }
Example #3
0
        // -- //

        void OnEnable()
        {
            if (target != null)
            {
                scenesProp       = serializedObject.FindProperty("_scenes");
                dependenciesProp = serializedObject.FindProperty("_dependencies");
                masterProp       = serializedObject.FindProperty("_master");
                lastPackage      = target as ScenesPackage;
            }
        }
Example #4
0
        static public void SaveAllScenes(ScenesPackage package)
        {
            SceneField[] scenes = package.GetScenes(includeDependencies: true);

            for (int i = 0; i < scenes.Length; ++i)
            {
                Scene scene = EditorSceneManager.GetSceneByPath(scenes[i].ScenePath);
                EditorSceneManager.SaveScene(scene);
            }
        }
Example #5
0
        static public void DeletePackage(ScenesPackage package)
        {
            SceneField[] scenes = package.GetScenes(includeDependencies: false);

            for (int i = 0; i < scenes.Length; ++i)
            {
                AssetDatabase.MoveAssetToTrash(scenes[i].ScenePath);
            }

            AssetDatabase.MoveAssetToTrash(AssetDatabase.GetAssetPath(package));
        }
        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 AddInCategory(string category, ScenesPackage package)
        {
            List <ScenesPackage> packInCat;

            if (!packages.TryGetValue(category, out packInCat))
            {
                packInCat = new List <ScenesPackage>();
                packages.Add(category, packInCat);
            }

            packInCat.Add(package);
        }
        void AssetGUI(ScenesPackage asset, Color backgroundColor)
        {
            GUI.backgroundColor = backgroundColor;

            try {
                EditorGUILayout.BeginHorizontal("Box");
                EditorGUILayout.LabelField(asset.name, EditorStyles.boldLabel);

                if (GUILayout.Button("Sélectionner"))
                {
                    Selection.activeObject = asset;
                }
                EditorGUILayout.EndHorizontal();
            } catch (MissingReferenceException) {
                Refresh();
                Repaint();
                return;
            }
        }
Example #9
0
        static public void RemoveScenesPackageFromBuild(ScenesPackage package)
        {
            List <string> scenesPath = new List <string>(GetScenesBuildPath());

            SceneField[] scenesToRemove = package.GetScenes(includeDependencies: false);

            for (int i = 0; i < scenesToRemove.Length; ++i)
            {
                if (scenesToRemove[i].Empty || !scenesPath.Contains(scenesToRemove[i].ScenePath))
                {
                    continue;
                }

                scenesPath.Remove(scenesToRemove[i].ScenePath);
            }

            SetScenesBuildPath(scenesPath.ToArray());

            Debug.Log(string.Format("{0} : Les scenes ont été retirées à la build", package.name), package);
        }
        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();
        }
        void FindAllAssets()
        {
            ClearAssets();

            string[] assetsGUID = AssetDatabase.FindAssets("t:" + typeof(ScenesPackage).Name);
            string[] assetsPath = new string[assetsGUID.Length];

            // Sort by name
            for (int i = 0; i < assetsGUID.Length; ++i)
            {
                assetsPath[i] = AssetDatabase.GUIDToAssetPath(assetsGUID[i]);
            }

            System.Array.Sort(assetsPath, (a, b) => string.Compare(a, b));

            // Sort in categories
            for (int i = 0; i < assetsPath.Length; ++i)
            {
                ScenesPackage package    = AssetDatabase.LoadAssetAtPath <ScenesPackage>(assetsPath[i]);
                string        sceneName  = System.IO.Path.GetFileNameWithoutExtension(assetsPath[i]);
                bool          inCategory = false;

                foreach (string category in categories.Keys)
                {
                    if (sceneName.StartsWith(category))
                    {
                        AddInCategory(category, package);
                        inCategory = true;
                        break;
                    }
                }

                if (!inCategory)
                {
                    AddInCategory(NO_CATEGORY, package);
                }
            }
        }
Example #12
0
        static public void LoadScenesPackage(ScenesPackage package)
        {
            SceneField[] scenes    = package.GetScenes(includeDependencies: true);
            bool         activeSet = false;

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

                Scene opened = EditorSceneManager.OpenScene(scenes[i].ScenePath, OpenSceneMode.Additive);

                if (!activeSet)
                {
                    EditorSceneManager.SetActiveScene(opened);
                    CloseAllScenesButActive();

                    activeSet = true;
                }
            }
        }