Beispiel #1
0
        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("");
                        });
                    }
                }
            }
        }