ZibraEffectsMessagePopup.cs 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. using UnityEngine;
  2. using UnityEditor;
  3. using UnityEngine.UIElements;
  4. using com.zibra.common.Editor.SDFObjects;
  5. namespace com.zibra.common.Editor
  6. {
  7. internal class ZibraEffectsMessagePopup : EditorWindow
  8. {
  9. public static GUIContent WindowTitle => new GUIContent("Zibra Effects License Message");
  10. private string Url = "";
  11. private static void ShowWindow()
  12. {
  13. ZibraEffectsMessagePopup window = (ZibraEffectsMessagePopup)GetWindow(typeof(ZibraEffectsMessagePopup));
  14. window.titleContent = WindowTitle;
  15. window.Show();
  16. }
  17. private void OnEnable()
  18. {
  19. var root = rootVisualElement;
  20. root.Clear();
  21. int width = 456;
  22. int height = 442;
  23. minSize = maxSize = new Vector2(width, height);
  24. var uxmlAssetPath = AssetDatabase.GUIDToAssetPath("7e8488b56556d8c48a38cd92f80fbd6a");
  25. var visualTree = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>(uxmlAssetPath);
  26. visualTree.CloneTree(root);
  27. root.Q<Button>("ButtonText").clicked += SubscribeClick;
  28. }
  29. private void SubscribeClick()
  30. {
  31. Application.OpenURL(Url);
  32. }
  33. [InitializeOnLoadMethod]
  34. static void SetupCallback()
  35. {
  36. // Don't automatically open any windows in batch mode
  37. if (Application.isBatchMode)
  38. {
  39. return;
  40. }
  41. ServerAuthManager.OnProLicenseWarning = OpenProOnbordengWindow;
  42. }
  43. static void OpenProOnbordengWindow(string headerText, string bodyText, string url, string buttonText)
  44. {
  45. ZibraEffectsMessagePopup popup = CreateInstance<ZibraEffectsMessagePopup>();
  46. popup.OpenProOnbordengWindowInternal(headerText, bodyText, url, buttonText);
  47. }
  48. private void OpenProOnbordengWindowInternal(string headerText, string bodyText, string url, string buttonText)
  49. {
  50. var root = rootVisualElement;
  51. root.Q<Label>("TextTitle").text = headerText;
  52. root.Q<Label>("TextMessage").text = bodyText;
  53. if (buttonText == "")
  54. {
  55. root.Q<Button>("ButtonText").style.display = DisplayStyle.None;
  56. }
  57. else
  58. {
  59. root.Q<Button>("ButtonText").text = buttonText;
  60. }
  61. Url = url;
  62. ShowWindow();
  63. }
  64. }
  65. }