Advertisement
CassataGames

Untitled

Jun 13th, 2022
663
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.91 KB | None | 0 0
  1. using UnityEditor;
  2. using UnityEngine;
  3. using UnityEngine.UIElements;
  4.  
  5.  
  6. public class customEditor : EditorWindow
  7. {
  8.     private VisualElement _root;
  9.     private VisualTreeAsset _treeAsset;
  10.    
  11.     [MenuItem("Window/UI Toolkit/customEditor")]
  12.     public static void ShowExample()
  13.     {
  14.         customEditor wnd = GetWindow<customEditor>();
  15.         wnd.titleContent = new GUIContent("customEditor");
  16.     }
  17.  
  18.     public void CreateGUI()
  19.     {
  20.         _root = rootVisualElement;
  21.         _treeAsset = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>("Assets/Editor/customEditor.uxml");
  22.  
  23.         Button button = _root.Query<Button>("button-Test");
  24.  
  25.         button.clickable.clicked += ButtonClicked;
  26.        
  27.         VisualElement labelFromUXML = _treeAsset.Instantiate();
  28.         _root.Add(labelFromUXML);
  29.        
  30.        
  31.     }
  32.  
  33.     private void ButtonClicked()
  34.     {
  35.         Debug.Log("Test");
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement