private void ActivateLicenseGUI() { GUILayout.Label(GUI.MakeLabel("Activate license", true), InspectorEditor.Skin.Label); var selectLicenseRect = GUILayoutUtility.GetLastRect(); selectLicenseRect.x += selectLicenseRect.width; selectLicenseRect.width = 28; selectLicenseRect.x -= selectLicenseRect.width; selectLicenseRect.y -= EditorGUIUtility.standardVerticalSpacing; var selectLicensePressed = InspectorGUI.Button(selectLicenseRect, MiscIcon.Locate, UnityEngine.GUI.enabled, "Select license file on this computer", 1.25f); if (selectLicensePressed) { var sourceLicense = EditorUtility.OpenFilePanel("Copy AGX Dynamics license file", ".", $"{AGXUnity.LicenseManager.GetLicenseExtension( AGXUnity.LicenseInfo.LicenseType.Service ).Remove( 0, 1 )}," + $"{AGXUnity.LicenseManager.GetLicenseExtension( AGXUnity.LicenseInfo.LicenseType.Legacy ).Remove( 0, 1 )}"); if (!string.IsNullOrEmpty(sourceLicense)) { var targetLicense = AGXUnity.IO.Environment.FindUniqueFilename($"{LicenseDirectory}/{Path.GetFileName( sourceLicense )}").PrettyPath(); if (EditorUtility.DisplayDialog("Copy AGX Dynamics license", $"Copy \"{sourceLicense}\" to \"{targetLicense}\"?", "Yes", "Cancel")) { try { File.Copy(sourceLicense, targetLicense, false); StartUpdateLicenseInformation(); GUIUtility.ExitGUI(); } catch (ExitGUIException) { throw; } catch (System.Exception e) { Debug.LogException(e); } } } } using (InspectorGUI.IndentScope.Single) { m_licenseActivateData.Id = EditorGUILayout.TextField(GUI.MakeLabel("License Id"), m_licenseActivateData.Id, InspectorEditor.Skin.TextField); if (m_licenseActivateData.Id.Any(c => !char.IsDigit(c))) { m_licenseActivateData.Id = new string( m_licenseActivateData.Id.Where(c => char.IsDigit(c)).ToArray()); } m_licenseActivateData.Password = EditorGUILayout.PasswordField(GUI.MakeLabel("Activation Code"), m_licenseActivateData.Password); InspectorGUI.SelectFolder(GUI.MakeLabel("License File Directory"), LicenseDirectory, "License file directory", newDirectory => { newDirectory = newDirectory.PrettyPath(); if (string.IsNullOrEmpty(newDirectory)) { newDirectory = "Assets"; } if (!Directory.Exists(newDirectory)) { Debug.LogWarning($"Invalid license directory: {newDirectory} - directory doesn't exist."); return; } else if (!IO.Utils.IsValidProjectFolder(newDirectory)) { Debug.LogWarning($"Invalid license directory: {newDirectory} - directory has to be in the project."); return; } LicenseDirectory = newDirectory; }); using (new GUI.EnabledBlock(UnityEngine.GUI.enabled && m_licenseActivateData.Id.Length > 0 && m_licenseActivateData.Password.Length > 0)) { // It isn't possible to press this button during activation. if (UnityEngine.GUI.Button(EditorGUI.IndentedRect(EditorGUILayout.GetControlRect()), GUI.MakeLabel(AGXUnity.LicenseManager.IsBusy ? "Activating..." : "Activate"), InspectorEditor.Skin.Button)) { AGXUnity.LicenseManager.ActivateAsync(System.Convert.ToInt32(m_licenseActivateData.Id), m_licenseActivateData.Password, LicenseDirectory, success => { if (success) { m_licenseActivateData = IdPassword.Empty(); } else { Debug.LogError("License Error: ".Color(Color.red) + AGXUnity.LicenseManager.LicenseInfo.Status); } StartUpdateLicenseInformation(); UnityEngine.GUI.FocusControl(""); }); } } } }
private void OnGUI() { using (GUI.AlignBlock.Center) GUILayout.Box(IconManager.GetAGXUnityLogo(), GUI.Skin.customStyles[3], GUILayout.Width(400), GUILayout.Height(100)); EditorGUILayout.LabelField("© " + System.DateTime.Now.Year + " Algoryx Simulation AB", InspectorEditor.Skin.LabelMiddleCenter); InspectorGUI.BrandSeparator(1, 6); var agxLfxColor = Color.Lerp(Color.green, Color.black, 0.35f); var encryptedFilename = $"agx{AGXUnity.LicenseManager.GetRuntimeActivationExtension()}".Color(agxLfxColor); var serviceFilename = $"agx{AGXUnity.LicenseManager.GetLicenseExtension( AGXUnity.LicenseInfo.LicenseType.Service )}".Color(agxLfxColor); InspectorGUI.ToolDescription("Generate an AGX Dynamics for Unity runtime activation file containing " + "encrypted License Id and Activation Code bound to the application. The " + "generated runtime activation file (" + encryptedFilename + ") will be replaced " + "with a hardware locked " + serviceFilename + " if the activation is successful.\n\n" + "<b>Internet access is required during the activation on the target hardware.</b>"); InspectorGUI.Separator(1, 6); InspectorGUI.SelectFolder(GUI.MakeLabel("Build directory"), BuildDirectory, "Build directory", newBuildDirectory => { if (!Directory.Exists(newBuildDirectory)) { Debug.LogWarning($"Ignoring given build path {newBuildDirectory} doesn't exist."); return; } BuildDirectory = newBuildDirectory; // Reset reference file if it doesn't exist in the new build directory hierarchy. if (!File.Exists(ReferenceFileInBuildFull)) { m_referenceFileInBuild = string.Empty; } }); InspectorGUI.SelectFile(GUI.MakeLabel("Reference file"), ReferenceFileInBuild, "Select reference file in build", BuildDirectory, newFilename => { ReferenceFileInBuild = newFilename; }); m_idPassword.Id = EditorGUILayout.TextField(GUI.MakeLabel("Runtime License Id"), m_idPassword.Id, InspectorEditor.Skin.TextField); if (m_idPassword.Id.Any(c => !char.IsDigit(c))) { m_idPassword.Id = new string( m_idPassword.Id.Where(c => char.IsDigit(c)).ToArray()); } m_idPassword.Password = EditorGUILayout.PasswordField(GUI.MakeLabel("Runtime Activation Code"), m_idPassword.Password); var generateToolTip = string.Empty; using (new GUI.EnabledBlock(ValidateGenerate(ref generateToolTip))) { GUILayout.Space(3); if (GUILayout.Button(GUI.MakeLabel("Generate", false, generateToolTip))) { var generatedFilename = string.Empty; if (AGXUnity.LicenseManager.GenerateEncryptedRuntime(System.Convert.ToInt32(m_idPassword.Id), m_idPassword.Password, BuildDirectory, ReferenceFileInBuild, filename => generatedFilename = filename)) { EditorUtility.DisplayDialog("Encrypted Runtime License", $"Encrypted runtime successfully written to: {generatedFilename}", "Ok"); Close(); } } } }