static bool CheckValidMeshWithMessageBox(Component_Mesh mesh) { if (!CommonFunctions.CheckValidMesh(mesh, out string error)) { EditorMessageBox.ShowWarning(error); return(false); } return(true); }
public static void SetCurrentLicense(string email, string password) { #if !DEPLOY try { var key = Registry.CurrentUser.CreateSubKey(registryPath); key.SetValue("LoginEmail", email); key.SetValue("LoginHash", EncryptDecrypt(password)); key.Close(); } catch (Exception e) { EditorMessageBox.ShowWarning(e.Message); return; } RequestFullLicenseInfo(); #endif }
public bool BuildArchive() //string writeToDirectory ) { var destFileName = Path.Combine(writeToDirectory, GetIdentifier() + "-" + GetVersion() + ".neoaxispackage"); //check file already exists if (File.Exists(destFileName)) { var text = $"The file with name \'{destFileName}\' is already exists. Overwrite?"; if (EditorMessageBox.ShowQuestion(text, EMessageBoxButtons.OKCancel) == EDialogResult.Cancel) { return(false); } } try { var sourceDirectory = Path.GetDirectoryName(VirtualPathUtility.GetRealPathByVirtual(ComponentUtility.GetOwnedFileNameOfComponent(this))); //make zip if (File.Exists(destFileName)) { File.Delete(destFileName); } //prepare Package.info var packageInfoTempFileName = Path.GetTempFileName(); { var block = new TextBlock(); block.SetAttribute("Identifier", GetIdentifier()); block.SetAttribute("Title", Title.Value); block.SetAttribute("Version", GetVersion()); //!!!! block.SetAttribute("Author", "Share CC Attribution"); block.SetAttribute("Description", ShortDescription); //"ShortDescription" block.SetAttribute("FullDescription", FullDescription.Value); string license = ""; switch (License.Value) { case LicenseEnum.MIT: license = "MIT"; break; case LicenseEnum.CCAttribution: license = "CC Attribution"; break; case LicenseEnum.FreeToUse: license = "Free To Use"; break; case LicenseEnum.PaidPerSeat: license = "Paid Per Seat"; break; } block.SetAttribute("License", license); if (License.Value == LicenseEnum.PaidPerSeat) { block.SetAttribute("Cost", Cost.Value.ToString()); } { var s = ""; foreach (CategoryEnum flag in GetFlags(Categories.Value)) { if (flag != 0) { if (s.Length != 0) { s += ", "; } s += TypeUtility.DisplayNameAddSpaces(flag.ToString()); } } block.SetAttribute("Categories", s); } block.SetAttribute("Tags", Tags.Value); //!!!! var openAfterInstall = sourceDirectory.Substring(VirtualFileSystem.Directories.Assets.Length + 1); block.SetAttribute("OpenAfterInstall", openAfterInstall); //MustRestart = True //AddCSharpFilesToProject = "Store\\Simple Level Generator" File.WriteAllText(packageInfoTempFileName, block.DumpToString()); } string[] files; using (var archive = ZipFile.Open(destFileName, ZipArchiveMode.Create)) { files = Directory.GetFiles(sourceDirectory, "*", SearchOption.AllDirectories); foreach (var file in files) { if (Path.GetExtension(file) == ".store") { continue; } var entryName = file.Substring(VirtualFileSystem.Directories.Project.Length + 1); //var entryName = file.Substring( sourceDirectory.Length + 1 ); archive.CreateEntryFromFile(file, entryName); } archive.CreateEntryFromFile(packageInfoTempFileName, "Package.info"); } if (File.Exists(packageInfoTempFileName)) { File.Delete(packageInfoTempFileName); } //write info json { var jsonFileName = destFileName + ".json"; var sw = new StringWriter(); using (JsonWriter writer = new JsonTextWriter(sw)) { writer.Formatting = Formatting.Indented; writer.WriteStartObject(); writer.WritePropertyName("Author"); //!!!! //writer.WriteValue( "3" ); writer.WriteValue("Share CC Attribution"); writer.WritePropertyName("Identifier"); writer.WriteValue(GetIdentifier()); writer.WritePropertyName("Title"); writer.WriteValue(Title.Value); writer.WritePropertyName("License"); switch (License.Value) { case LicenseEnum.MIT: writer.WriteValue("MIT"); break; case LicenseEnum.CCAttribution: writer.WriteValue("CC Attribution"); break; case LicenseEnum.FreeToUse: writer.WriteValue("Free To Use"); break; case LicenseEnum.PaidPerSeat: writer.WriteValue("Paid Per Seat"); break; } //writer.WriteValue( License.Value.ToString() ); writer.WritePropertyName("Cost"); writer.WriteValue(Cost.Value.ToString()); writer.WritePropertyName("ShortDescription"); writer.WriteValue(ShortDescription.Value); writer.WritePropertyName("FullDescription"); writer.WriteValue(FullDescription.Value); { writer.WritePropertyName("Categories"); var s = ""; foreach (CategoryEnum flag in GetFlags(Categories.Value)) { if (flag != 0) { if (s.Length != 0) { s += ", "; } s += TypeUtility.DisplayNameAddSpaces(flag.ToString()); } } writer.WriteValue(s); //writer.WriteValue( Categories.Value.ToString() ); } writer.WritePropertyName("Tags"); writer.WriteValue(Tags.Value); writer.WritePropertyName("Version"); writer.WriteValue(GetVersion()); //writer.WriteEnd(); writer.WriteEndObject(); } File.WriteAllText(jsonFileName, sw.ToString()); } //try to create screenshots if (CreateScreenshots) { //find in the folder one import file (FBX, etc). make screenshot of 'Mesh' object inside the import file. var resourceType = ResourceManager.GetTypeByName("Import 3D"); var importExtensions = new ESet <string>(); foreach (var e in resourceType.FileExtensions) { importExtensions.AddWithCheckAlreadyContained("." + e); } var importVirtualFileNames = new List <string>(); foreach (var file in files) { var ext = Path.GetExtension(file); if (!string.IsNullOrEmpty(ext) && importExtensions.Contains(ext)) { var virtualFileName = VirtualPathUtility.GetVirtualPathByReal(file); if (!string.IsNullOrEmpty(virtualFileName)) { importVirtualFileNames.Add(virtualFileName); } } } if (importVirtualFileNames.Count == 1) { var import3D = ResourceManager.LoadResource <Component_Import3D>(importVirtualFileNames[0]); if (import3D != null) { var mesh = import3D.GetComponent <Component_Mesh>("Mesh"); if (mesh != null) { var generator = new MeshImageGenerator(); generator.Generate(mesh, destFileName + ".logo.png"); } } } } } catch (Exception e) { EditorMessageBox.ShowWarning(e.Message); return(false); } return(true); }
public override bool Creation(NewObjectCell.ObjectCreationContext context) { if (Window.IsFileCreation()) { context.disableFileCreation = true; GetCreateCSharpClassInfo(out var csharpRealFileName, out var csharpClassName, out var csharpClassNameWithoutNamespace); try { //main file { string name = Template.Name + ".scene"; var sourceFile = VirtualPathUtility.GetRealPathByVirtual(@"Base\Tools\NewResourceTemplates\" + name); //copy scene file var text = File.ReadAllText(sourceFile); if (CreateCSharpClass) { text = text.Replace(".component NeoAxis.Component_Scene", ".component " + csharpClassName); } File.WriteAllText(context.fileCreationRealFileName, text); //copy additional folder if exist var sourceFolderPath = sourceFile + "_Files"; if (Directory.Exists(sourceFolderPath)) { var destFolderPath = context.fileCreationRealFileName + "_Files"; IOUtility.CopyDirectory(sourceFolderPath, destFolderPath); } } //cs file if (CreateCSharpClass) { string code = @"using System; using System.Collections.Generic; using System.Text; using System.ComponentModel; using NeoAxis; namespace Project { public class {Name} : {Base} { } }"; code = code.Replace("{Name}", csharpClassNameWithoutNamespace); code = code.Replace("{Base}", Window.SelectedType.Name); File.WriteAllText(csharpRealFileName, code); } } catch (Exception e) { EditorMessageBox.ShowWarning(e.Message); //Log.Warning( e.Message ); return(false); } if (CreateCSharpClass) { //add to Project.csproj { var toAdd = new List <string>(); var fileName = Path.Combine("Assets", VirtualPathUtility.GetVirtualPathByReal(csharpRealFileName)); toAdd.Add(fileName); if (CSharpProjectFileUtility.UpdateProjectFile(toAdd, null, out var error)) { if (toAdd.Count > 1) { Log.Info(EditorLocalization.Translate("General", "Items have been added to the Project.csproj.")); } else { Log.Info(EditorLocalization.Translate("General", "The item has been added to the Project.csproj.")); } } else { EditorMessageBox.ShowWarning(error); //Log.Warning( error ); return(false); } } Window.DisableUnableToCreateReason = true; //restart application var text = EditorLocalization.Translate("General", "To apply changes need restart the editor. Restart?\r\n\r\nThe editor must be restarted to compile and enable a new created C# class."); if (EditorMessageBox.ShowQuestion(text, EMessageBoxButtons.YesNo) == EDialogResult.Yes) { EditorAPI.BeginRestartApplication(); } Window.DisableUnableToCreateReason = false; } } return(true); }