Example #1
0
        public void InitializeModuleImporting(string excludeModuleName)
        {
            excludeIndex     = -1;
            modulesInProject = AssetTools.FindAssetsByType <Module>(false, null);

            unityPackagePaths = ProjectTools.GetFilesInDirectory(ModuleWorkFlow.defaultTargetExportDirectory, ProjectTools.packageExtension, out unityPackageNames);


            int l = unityPackagePaths.Length;

            importWarnings = "";

            for (int i = 0; i < l; i++)
            {
                string unVersionedName;
                int    unimportedVersion = ModuleWorkFlow.VersionFromFilePath(unityPackageNames[i], out unVersionedName);

                if (unVersionedName != null)
                {
                    unityPackageNames[i] = unVersionedName;
                }

                if (unityPackageNames[i] == excludeModuleName)
                {
                    excludeIndex = i;
                }


                // check for modules alraedy imported...
                for (int j = 0; j < modulesInProject.Count; j++)
                {
                    Module importedModule = modulesInProject[j];

                    // if package in project already
                    if (unityPackageNames[i] == importedModule.moduleName)
                    {
                        // check if our package version is higher than our already imported version
                        if (unimportedVersion > importedModule.currentVersion)
                        {
                            importWarnings += "\n" + unityPackageNames[i] + " Upgrade available! Version: " + unimportedVersion + ", Current: " + importedModule.currentVersion;

                            // mark as already imported but updateable
                            unityPackageNames[i] = "[...] " + unityPackageNames[i];
                        }
                        else
                        {
                            // mark as already imported
                            unityPackageNames[i] = "[ X ] " + unityPackageNames[i];
                        }
                        break;
                    }
                }
                // add version to name as readable
                unityPackageNames[i] = unityPackageNames[i] + " [v" + unimportedVersion + "]";
            }
        }
Example #2
0
        public static void ExportModulePackage(Module module, string targetDirectory, bool isUpgrade)
        {
            // export base directory is the directory the module is in
            string exportDir = Path.GetDirectoryName(AssetDatabase.GetAssetPath(module));

            // if the directory name for the module isnt a match with the module name
            // raise a warning, it might mean we're exporting the wrong module by accident
            string [] sp      = exportDir.Split('/');
            string    dirName = sp[sp.Length - 1];

            if (dirName != module.moduleName)
            {
                string msg = "Trying to export module: " + module.moduleName + ", but root directory for module is named: " + dirName + "\n\nAre you sure everything is set up right?";
                if (!EditorUtility.DisplayDialog("Module Export:\n" + module.moduleName, msg, "Continue", "Abort"))
                {
                    return;
                }
            }

            // when upgrading, we increment the version number, so other projects that use this module
            // know they need an update
            if (isUpgrade)
            {
                if (!EditorUtility.DisplayDialog("Module Upgrade:\n" + module.moduleName, "Are you sure you want to upgrade from v" + module.currentVersion + " to v" + (module.currentVersion + 1), "Upgrade", "Abort"))
                {
                    return;
                }

                module.currentVersion++;

                // make sure this change gets saved before export
                // TODO: check if this is actually needed
                EditorUtility.SetDirty(module);
                AssetDatabase.Refresh();
                AssetDatabase.SaveAssets();

                string oldPath = targetDirectory + module.moduleName + versionPrefix + (module.currentVersion - 1) + ProjectTools.packageExtension;

                // Check if file exists with its full path
                if (File.Exists(oldPath))
                {
                    File.Delete(oldPath);
                    Debug.Log("Deleted: " + oldPath);
                }
            }


            // dont let the ModuleProjectSpecifier in the project be exported with the module
            Func <string, bool> whereNotProjectSpecifierAsset = (filePath) => {
                // if its not an asset
                if (!filePath.EndsWith(".asset"))
                {
                    return(true);
                }

                bool isProjectSpecifier = AssetDatabase.LoadAssetAtPath <ModuleProjectSpecifier>(filePath) != null;
                if (isProjectSpecifier)
                {
                    Debug.LogWarning("Found ModuleProjectSpecifier in export files, removing: " + filePath);
                }
                return(!isProjectSpecifier);
            };

            string [] files = ProjectTools.GetFilesInDirectory(exportDir).Where(whereNotProjectSpecifierAsset).ToArray();

            if (files.Length == 0)
            {
                Debug.LogWarning("No files to export at directory: " + exportDir);
                return;
            }

            // only one file... chances are it's just the module object.
            // in which case, dont export
            if (files.Length == 1)
            {
                bool isModule = AssetDatabase.LoadAssetAtPath <ModuleProjectSpecifier>(files[0]) != null;
                if (isModule)
                {
                    Debug.LogWarning("No files except module to export at directory: " + exportDir);
                    return;
                }
            }

            // print out files as debug
            // for (int i = 0; i < files.Length; i++) Debug.Log("Export File: " + files[i]);

            string exportPath = targetDirectory + module.moduleName + versionPrefix + module.currentVersion + ProjectTools.packageExtension;

            AssetDatabase.ExportPackage(files, exportPath);
            EditorUtility.DisplayDialog("Export Complete", "Module Exported To:\n" + exportPath, "Ok", "Ok");
        }