public static void CreateUnityPackage(string aboslutePath, PackageBuildInformation package) { package.CheckThatAssemblyAreDefined(); Directory.CreateDirectory(aboslutePath); string packageJson = GetPackageAsJson(package); File.WriteAllText(aboslutePath + "/" + "package.json", packageJson); string path = ""; string absFile, absFolder; GetAssemblyFilepath(aboslutePath, package.m_assemblyRuntime, out absFolder, out absFile); Directory.CreateDirectory(absFolder); File.Delete(absFile); File.WriteAllText(absFile, GetAssemblyAsJson(package.m_assemblyRuntime)); File.WriteAllText(absFolder + "/" + UnityPaths.AlphaNumeric(package.GetProjectNamespaceId(false)) + ".cs", "//Empty Script"); GetAssemblyFilepath(aboslutePath, package.m_assemblyEditor, out absFolder, out absFile); Directory.CreateDirectory(absFolder); File.Delete(absFile); File.WriteAllText(absFile, GetAssemblyAsJson(package.m_assemblyEditor)); File.WriteAllText(absFolder + "/" + UnityPaths.AlphaNumeric(package.GetProjectNamespaceId(false)) + ".cs", "//Empty Script"); #if UNITY_EDITOR AssetDatabase.Refresh(); #endif }
public static void DrawPackageEditor(ref string relativePathOfProject, PackageBuildInformation package) { GUILayout.BeginHorizontal(); //if (GUILayout.Button("Create Folder")) //{ // PackageBuilder.CreateFolder(relativePathOfProject); // AssetDatabase.Refresh(); //} if (string.IsNullOrEmpty(package.m_projectName)) { package.m_projectName = AlphaNumeric(Application.productName); } package.m_projectName = (GUILayout.TextField("" + package.m_projectName)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); //if (GUILayout.Button("Create Folder")) //{ // PackageBuilder.CreateFolder(relativePathOfProject); // AssetDatabase.Refresh(); //} if (string.IsNullOrEmpty(package.m_projectAlphNumId)) { package.m_projectAlphNumId = AlphaNumeric(Application.productName); } if (string.IsNullOrEmpty(package.m_company)) { package.m_company = AlphaNumeric(Application.companyName); } package.m_country = AlphaNumeric(GUILayout.TextField("" + package.m_country)); GUILayout.Label(".", GUILayout.Width(5)); package.m_company = AlphaNumeric(GUILayout.TextField("" + package.m_company)); GUILayout.Label(".", GUILayout.Width(5)); package.m_projectAlphNumId = AlphaNumeric(GUILayout.TextField("" + package.m_projectAlphNumId)); GUILayout.EndHorizontal(); GUILayout.Label("Namespace ID: " + package.GetProjectNamespaceId()); GUILayout.BeginHorizontal(); if (GUILayout.Button("Create " + package.m_projectName)) { PackageBuilder.CreateUnityPackage(relativePathOfProject, package); AssetDatabase.Refresh(); } GUILayout.EndHorizontal(); }
public static string GetPackageAsJson(PackageBuildInformation packageInfo, string fileName = "package.json") { string packageJson = ""; string[] dependenciesModificatedForJson = CompressDependenciesToString(packageInfo.m_otherPackageDependency); string[] dependenciesRelationModificatedForJson = CompressDependenciesToString(packageInfo.m_otherPackageRelation); string[] keywordForJson = new string[packageInfo.m_keywords.Length]; for (int i = 0; i < packageInfo.m_keywords.Length; i++) { keywordForJson[i] = "\"" + packageInfo.m_keywords[i] + "\""; } packageJson += "\n{ "; packageJson += "\n \"name\": \"" + packageInfo.GetProjectNamespaceId(true) + "\", "; packageJson += "\n \"displayName\": \"" + packageInfo.m_projectName + "\", "; packageJson += "\n \"version\": \"" + packageInfo.m_packageVersion + "\", "; packageJson += "\n \"unity\": \"" + packageInfo.m_unityVersion + "\", "; packageJson += "\n \"unityRelease\": \"" + packageInfo.m_unityVersionRelease + "\", "; packageJson += "\n \"description\": \"" + packageInfo.m_description + "\", "; packageJson += "\n \"keywords\": [" + string.Join(",", keywordForJson) + "], "; packageJson += "\n \"dependencies\":{" + string.Join(",", dependenciesModificatedForJson) + "}, "; packageJson += "\n \"relatedPackages\":{" + string.Join(",", dependenciesRelationModificatedForJson) + "}, "; packageJson += "\n \"samples\" : [" + GetSamplesCompress(packageInfo.m_samples.m_samples.ToArray()) + "], "; packageJson += "\n \"author\" : {" + "\n\"name\":\"" + packageInfo.m_author.m_name + "\"," + "\n\"mail\":\"" + packageInfo.m_author.m_mail + "\"," + "\n\"url\":\"" + packageInfo.m_author.m_url + "\"" + "}, "; packageJson += "\n \"repository\":{" + "\n\"type\":\"" + packageInfo.m_repositoryLink.m_type + "\"," + "\n\"url\":\"" + packageInfo.m_repositoryLink.m_url + "\"," + "\n\"footprint\":\"" + packageInfo.m_repositoryLink.m_footprint + "\"," + "\n\"revision\":\"" + packageInfo.m_repositoryLink.m_revision + "\"" + "}, "; packageJson += "\n \"category\": \"" + packageInfo.m_category.ToString().Replace("_", " ") + "\" "; packageJson += "\n} "; return(packageJson); }
public static void DrawPackageEditor(UnityPathSelectionInfo selection, PackageJsonFileStream packageTarget, PackageBuildInformation package) { string path = packageTarget.GetAbsolutePath(); GitLinkOnDisk gitLinked = packageTarget.GetLinkedGit(); GUILayout.BeginHorizontal(); if (GUILayout.Button("Create package.json")) { LoadSamplesFromDirectoryToPackage(selection, ref package); string json = PackageBuilder.GetPackageAsJson(package); packageTarget.Set(json, true); AssetDatabase.Refresh(); } if (GUILayout.Button("Create Files & Folders")) { PackageBuilder.CreateUnityPackage(packageTarget.GetPackageProjectRoot(), package); AssetDatabase.Refresh(); } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); if (string.IsNullOrEmpty(package.m_projectName)) { package.m_projectName = UnityPaths.AlphaNumeric(Application.productName); } package.m_projectName = (GUILayout.TextField("" + package.m_projectName)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); if (string.IsNullOrEmpty(package.m_projectAlphNumId)) { // package.m_projectAlphNumId = UnityPaths.AlphaNumeric(Application.productName, true); package.m_projectAlphNumId = selection.GetSelectName(true); } if (string.IsNullOrEmpty(package.m_company)) { package.m_company = UnityPaths.AlphaNumeric(Application.companyName); } package.m_country = UnityPaths.AlphaNumeric(GUILayout.TextField("" + package.m_country)); GUILayout.Label(".", GUILayout.Width(5)); package.m_company = UnityPaths.AlphaNumeric(GUILayout.TextField("" + package.m_company)); GUILayout.Label(".", GUILayout.Width(5)); package.m_projectAlphNumId = UnityPaths.AlphaNumeric(GUILayout.TextField("" + package.m_projectAlphNumId)); GUILayout.EndHorizontal(); GUILayout.Label("Namespace ID: " + package.GetProjectNamespaceId()); GUILayout.Label("Description"); package.m_description = GUILayout.TextArea(package.m_description, GUILayout.MinHeight(100)); GUILayout.BeginHorizontal(); GUILayout.Label("Tags:", GUILayout.MaxWidth(60)); package.m_keywords = GUILayout.TextField(string.Join(",", package.m_keywords)).Split(','); GUILayout.EndHorizontal(); GUILayout.Label("Author"); GUILayout.BeginHorizontal(); GUILayout.Label("Name: ", GUILayout.MaxWidth(60)); package.m_author.m_name = GUILayout.TextField(package.m_author.m_name); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Mail: ", GUILayout.MaxWidth(60)); package.m_author.m_mail = GUILayout.TextField(package.m_author.m_mail); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Url: ", GUILayout.MaxWidth(60)); package.m_author.m_url = GUILayout.TextField(package.m_author.m_url); GUILayout.EndHorizontal(); GUILayout.Label("Repository Info"); GUILayout.BeginHorizontal(); GUILayout.Label("Git Url: ", GUILayout.MaxWidth(60)); package.m_repositoryLink.m_url = GUILayout.TextField(gitLinked.GetUrl()); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Revision: ", GUILayout.MaxWidth(60)); package.m_repositoryLink.m_revision = GUILayout.TextField(gitLinked.GetLastRevision()); GUILayout.EndHorizontal(); GUILayout.Space(10); GUILayout.Label("Direct dependence"); DrawEditableDependency(ref package.m_otherPackageDependency); GUILayout.Space(10); GUILayout.Label("Relative dependence"); DrawEditableDependency(ref package.m_otherPackageRelation); SampleDirectoryStream sample = SampleUtility.GetSampleFolder(selection); SampleEditor.DrawInfoAboutInterface(sample); DocumentationDirectoryStream documentation = DocumentationUtility.GetDocumentFolder(selection); DocumentationEditor.DrawInfoAboutInterface(documentation); }