From c3eb662df8c91f84209a6c77cc81eec69673545d Mon Sep 17 00:00:00 2001 From: lilisha-unity Date: Tue, 11 Oct 2022 15:56:36 +0000 Subject: [PATCH 01/53] Added create a popup window code example --- .../Editor/PopupContentExample.cs | 30 +++++++++++++++++++ create-a-popup-window/Editor/PopupExample.cs | 23 ++++++++++++++ create-a-popup-window/Editor/PopupExample.uss | 3 ++ .../Editor/PopupExample.uxml | 4 +++ .../Editor/PopupWindowContent.uxml | 6 ++++ 5 files changed, 66 insertions(+) create mode 100644 create-a-popup-window/Editor/PopupContentExample.cs create mode 100644 create-a-popup-window/Editor/PopupExample.cs create mode 100644 create-a-popup-window/Editor/PopupExample.uss create mode 100644 create-a-popup-window/Editor/PopupExample.uxml create mode 100644 create-a-popup-window/Editor/PopupWindowContent.uxml diff --git a/create-a-popup-window/Editor/PopupContentExample.cs b/create-a-popup-window/Editor/PopupContentExample.cs new file mode 100644 index 0000000..e291803 --- /dev/null +++ b/create-a-popup-window/Editor/PopupContentExample.cs @@ -0,0 +1,30 @@ +using UnityEditor; +using UnityEngine; +using UnityEngine.UIElements; + +public class PopupContentExample : PopupWindowContent +{ + //Set the window size + public override Vector2 GetWindowSize() + { + return new Vector2(200, 100); + } + + public override void OnGUI(Rect rect) + { + // Intentionally left empty + } + + public override void OnOpen() + { + Debug.Log("Popup opened: " + this); + + var visualTreeAsset = AssetDatabase.LoadAssetAtPath("Assets/Editor/PopupWindowContent.uxml"); + visualTreeAsset.CloneTree(editorWindow.rootVisualElement); + } + + public override void OnClose() + { + Debug.Log("Popup closed: " + this); + } +} \ No newline at end of file diff --git a/create-a-popup-window/Editor/PopupExample.cs b/create-a-popup-window/Editor/PopupExample.cs new file mode 100644 index 0000000..ae0cea2 --- /dev/null +++ b/create-a-popup-window/Editor/PopupExample.cs @@ -0,0 +1,23 @@ +using UnityEditor; +using UnityEngine.UIElements; +using PopupWindow = UnityEditor.PopupWindow; + +public class PopupExample : EditorWindow +{ + // Add menu item + [MenuItem("Example/Popup Example")] + static void Init() + { + EditorWindow window = EditorWindow.CreateInstance(); + window.Show(); + } + + private void CreateGUI() + { + var visualTreeAsset = AssetDatabase.LoadAssetAtPath("Assets/Editor/PopupExample.uxml"); + visualTreeAsset.CloneTree(rootVisualElement); + + var button = rootVisualElement.Q