diff --git a/Assets/Editor/E07_Data.cs b/Assets/Editor/E07_Data.cs new file mode 100644 index 0000000..3f91e18 --- /dev/null +++ b/Assets/Editor/E07_Data.cs @@ -0,0 +1,151 @@ +using UnityEditor; +using UnityEngine; +using UnityEngine.SceneManagement; +using UnityEngine.Experimental.UIElements; +using UnityEditor.SceneManagement; +using UnityEditor.Experimental.UIElements; +using System.Collections.Generic; +using System.Linq; + +namespace UIElementsExamples +{ + public class E07_Data : EditorWindow + { + [MenuItem("UIElementsExamples/07_Data")] + public static void ShowExample() + { + E07_Data window = GetWindow(); + window.minSize = new Vector2(450, 200); + window.titleContent = new GUIContent("Example 7"); + } + + static VisualTreeAsset s_Asset; + static VisualTreeAsset asset + { + get + { + if (s_Asset == null) + { + s_Asset = Resources.Load("TreeView"); + Debug.Assert(s_Asset != null); + } + return s_Asset; + } + } + + List m_ExpandedGOs; + + public void OnEnable() + { + if (m_ExpandedGOs == null) + m_ExpandedGOs = new List(); + + Scene scene = SceneManager.GetSceneAt(0); + + var scrollView = new ScrollView(); + scrollView.StretchToParentSize(); + + if (scene.IsValid()) + { + GameObject[] gameObjects = scene.GetRootGameObjects(); + RecursiveSetUp(gameObjects, scrollView.contentView); + } + + this.GetRootVisualContainer().AddChild(scrollView); + this.GetRootVisualContainer().AddStyleSheetPath("TreeView"); + } + + static void UpdateName(VisualElement treeViewItem, Object data) + { + if (data == null) + return; + + treeViewItem.Q