Ejemplo n.º 1
0
        private void OnGUI()
        {
            GUILayout.BeginHorizontal(GUILayout.Width(570));
            GUILayout.Box(IconManager.GetAGXUnityLogo(),
                          GUI.Skin.customStyles[3],
                          GUILayout.Width(400),
                          GUILayout.Height(100));
            GUILayout.EndHorizontal();

            InspectorGUI.Separator(1, 4);

            EditorGUILayout.LabelField(GUI.MakeLabel("Current version"),
                                       GUI.MakeLabel(m_currentVersion.IsValid ?
                                                     m_currentVersion.VersionStringShort :
                                                     "git checkout",
                                                     Color.white));
            using (new EditorGUILayout.HorizontalScope()) {
                var newVersionAvailable = m_serverVersion.IsValid && m_serverVersion > m_currentVersion;
                EditorGUILayout.LabelField(GUI.MakeLabel("Latest version"),
                                           GUI.MakeLabel(m_serverVersion.IsValid ?
                                                         m_serverVersion.VersionStringShort :
                                                         "...",
                                                         newVersionAvailable ?
                                                         Color.Lerp(Color.green, Color.black, 0.35f) :
                                                         Color.white),
                                           InspectorEditor.Skin.Label);
                GUILayout.FlexibleSpace();
                if (newVersionAvailable && InspectorGUI.Link(GUI.MakeLabel("Changelog")))
                {
                    Application.OpenURL(TopMenu.AGXUnityChangelogURL);
                }
                else if (!newVersionAvailable)
                {
                    GUILayout.Label("", InspectorEditor.Skin.Label);
                }
            }

            InspectorGUI.Separator(1, 4);

            var isUpToDate = m_currentVersion.IsValid &&
                             m_serverVersion.IsValid &&
                             m_currentVersion >= m_serverVersion;

            if (isUpToDate)
            {
                EditorGUILayout.LabelField(GUI.MakeLabel("The version of AGX Dynamics for Unity is up to date.",
                                                         Color.Lerp(Color.green, Color.black, 0.35f)),
                                           InspectorEditor.Skin.TextAreaMiddleCenter);
            }
            else if (m_status == Status.Passive)
            {
                if (Web.RequestHandler.Get(@"https://us.download.algoryx.se/AGXUnity/latest.php",
                                           OnPackageNameRequest))
                {
                    m_status = Status.CheckingForUpdate;
                }
            }
            else if (m_status == Status.CheckingForUpdate)
            {
                Repaint();
            }
            else
            {
                if (m_serverVersion.IsValid)
                {
                    HandleDownloadInstall();
                    if (m_status == Status.Downloading)
                    {
                        Repaint();
                    }
                }
            }

            var manualPackageButtonSize = new Vector2(110, EditorGUIUtility.singleLineHeight);
            var manualPackageRect       = new Rect(maxSize - manualPackageButtonSize - new Vector2(2.0f * EditorGUIUtility.standardVerticalSpacing,
                                                                                                   2.0f * EditorGUIUtility.standardVerticalSpacing),
                                                   manualPackageButtonSize);
            var manualSelectPressed = false;

            using (new GUI.EnabledBlock(m_status != Status.Installing && m_status != Status.Downloading))
                manualSelectPressed = UnityEngine.GUI.Button(manualPackageRect,
                                                             GUI.MakeLabel("Manual select..."),
                                                             InspectorEditor.Skin.Button);
            if (manualSelectPressed)
            {
                if (!Directory.Exists(GetManualPackageDirectoryData().String))
                {
                    GetManualPackageDirectoryData().String = "Assets";
                }
                var manualPackageFilename = EditorUtility.OpenFilePanelWithFilters("AGX Dynamics for Unity package",
                                                                                   GetManualPackageDirectoryData().String,
                                                                                   new string[]
                {
                    "AGXUnity package",
                    "*.*.*unitypackage"
                });
                if (!string.IsNullOrEmpty(manualPackageFilename))
                {
                    var manualTargetFileInfo = new FileInfo(manualPackageFilename);
                    GetManualPackageDirectoryData().String = manualTargetFileInfo.Directory.FullName;

                    if (!manualTargetFileInfo.Exists)
                    {
                        Debug.LogWarning($"The target package \"{manualTargetFileInfo.FullName}\" doesn't exist. Aborting.");
                    }
                    else if (!VersionInfo.Parse(manualTargetFileInfo.Name).IsValid)
                    {
                        Debug.LogWarning($"Unable to parse version from package name \"{manualTargetFileInfo.Name}\". Aborting.");
                    }
                    else if (!manualTargetFileInfo.Name.StartsWith("AGXDynamicsForUnity-"))
                    {
                        Debug.LogWarning($"Package name \"{manualTargetFileInfo.Name}\" doesn't seems to be an AGX Dynamics for Unity package. Aborting.");
                    }
                    else if (EditorUtility.DisplayDialog("AGX Dynamics for Unity update",
                                                         "AGX Dynamics for Unity is about to be updated/downgraded " +
                                                         "to version " +
                                                         VersionInfo.Parse(manualTargetFileInfo.Name).VersionString +
                                                         ".\n\nDo you want to continue with the update/downgrade?",
                                                         "Continue",
                                                         "Cancel"))
                    {
                        Target   = manualTargetFileInfo.FullName;
                        m_status = Status.AwaitInstall;
                        InstallTarget();
                    }
                }
            }
        }
        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();
                    }
                }
            }
        }
Ejemplo n.º 3
0
        private void OnGUI()
        {
            GUILayout.BeginHorizontal(GUILayout.Width(570));
            GUILayout.Box(IconManager.GetAGXUnityLogo(),
                          GUI.Skin.customStyles[3],
                          GUILayout.Width(400),
                          GUILayout.Height(100));
            GUILayout.EndHorizontal();

            EditorGUILayout.LabelField("© " + System.DateTime.Now.Year + " Algoryx Simulation AB",
                                       InspectorEditor.Skin.LabelMiddleCenter);

            InspectorGUI.BrandSeparator(1, 6);

            EditorGUILayout.LabelField(GUI.MakeLabel("Thank you for using AGX Dynamics for Unity!", true),
                                       InspectorEditor.Skin.LabelMiddleCenter);

            GUILayout.Space(6);

            var fieldColor = EditorGUIUtility.isProSkin ?
                             Color.white :
                             Color.black;
            var fieldErrorColor = Color.Lerp(Color.red,
                                             Color.black,
                                             0.25f);
            var fieldOkColor = Color.Lerp(Color.green,
                                          Color.black,
                                          0.35f);
            var fieldWarningColor = Color.Lerp(Color.yellow,
                                               Color.black,
                                               0.45f);

            var versionInfo = PackageUpdateHandler.FindCurrentVersion();

            EditorGUILayout.LabelField(GUI.MakeLabel("Version"),
                                       GUI.MakeLabel(versionInfo.IsValid ? versionInfo.VersionString : "git checkout", fieldColor),
                                       InspectorEditor.Skin.Label);

            string agxDynamicsVersion = s_agxInfo.Version;

            if (string.IsNullOrEmpty(agxDynamicsVersion))
            {
                agxDynamicsVersion = GUI.AddColorTag("Unknown",
                                                     fieldErrorColor);
            }
            else
            {
                agxDynamicsVersion = GUI.AddColorTag(agxDynamicsVersion,
                                                     fieldColor);
            }
            EditorGUILayout.LabelField(GUI.MakeLabel("AGX Dynamics version"),
                                       GUI.MakeLabel(agxDynamicsVersion),
                                       InspectorEditor.Skin.Label);

            EditorGUILayout.LabelField(GUI.MakeLabel(s_agxInfo.LicenseExpired ?
                                                     "License expired" :
                                                     "License expires"),
                                       s_agxInfo.ValidEndDate ?
                                       GUI.MakeLabel(s_agxInfo.EndDate.ToString("yyyy-MM-dd") +
                                                     GUI.AddColorTag($" ({s_agxInfo.DiffString} {(s_agxInfo.LicenseExpired ? "ago" : "remaining")})",
                                                                     s_agxInfo.LicenseExpired ?
                                                                     fieldErrorColor :
                                                                     s_agxInfo.IsLicenseAboutToBeExpired(10) ?
                                                                     fieldWarningColor :
                                                                     fieldOkColor),
                                                     fieldColor) :
                                       GUI.MakeLabel("License not found", fieldErrorColor),
                                       InspectorEditor.Skin.Label);

            InspectorGUI.BrandSeparator(1, 8);

            GUILayout.Label(GUI.MakeLabel("Online Documentation", true), InspectorEditor.Skin.Label);

            using (new EditorGUILayout.HorizontalScope(GUILayout.Width(200))) {
                if (InspectorGUI.Link(GUI.MakeLabel("AGX Dynamics for Unity")))
                {
                    Application.OpenURL(TopMenu.AGXDynamicsForUnityManualURL);
                }
                GUILayout.Label(" - ", InspectorEditor.Skin.Label);
                if (InspectorGUI.Link(GUI.MakeLabel("Examples")))
                {
                    Application.OpenURL(TopMenu.AGXDynamicsForUnityExamplesURL);
                }
            }

            using (new EditorGUILayout.HorizontalScope(GUILayout.Width(200))) {
                if (InspectorGUI.Link(GUI.MakeLabel("AGX Dynamics user manual")))
                {
                    Application.OpenURL(TopMenu.AGXUserManualURL);
                }
                GUILayout.Label(" - ", InspectorEditor.Skin.Label);
                if (InspectorGUI.Link(GUI.MakeLabel("AGX Dynamics API Reference")))
                {
                    Application.OpenURL(TopMenu.AGXAPIReferenceURL);
                }
            }

            InspectorGUI.BrandSeparator(1, 8);

            GUILayout.Label("Support", EditorStyles.boldLabel);
            EditorGUILayout.SelectableLabel("Please refer to the information received when purchasing your license for support contact information.",
                                            InspectorEditor.Skin.LabelWordWrap);
        }