From 81822823ba02a89c446dd1add3dc2ef65bb0249e Mon Sep 17 00:00:00 2001 From: Paul Tham Date: Tue, 15 Jun 2021 18:14:55 +0800 Subject: [PATCH 01/19] something is working --- .../Assets/LayerExplorer.meta | 8 ++ .../Assets/LayerExplorer/LayerBatch.uxml | 18 ++++ .../Assets/LayerExplorer/LayerBatch.uxml.meta | 10 ++ .../Assets/LayerExplorer/LayerExplorer.cs | 91 +++++++++++++++++++ .../LayerExplorer/LayerExplorer.cs.meta | 11 +++ .../Assets/LayerExplorer/LayerExplorer.uss | 34 +++++++ .../LayerExplorer/LayerExplorer.uss.meta | 11 +++ .../Assets/LayerExplorer/LayerExplorer.uxml | 13 +++ .../LayerExplorer/LayerExplorer.uxml.meta | 10 ++ 9 files changed, 206 insertions(+) create mode 100644 TestProjects/UniversalGraphicsTest_2D/Assets/LayerExplorer.meta create mode 100644 TestProjects/UniversalGraphicsTest_2D/Assets/LayerExplorer/LayerBatch.uxml create mode 100644 TestProjects/UniversalGraphicsTest_2D/Assets/LayerExplorer/LayerBatch.uxml.meta create mode 100644 TestProjects/UniversalGraphicsTest_2D/Assets/LayerExplorer/LayerExplorer.cs create mode 100644 TestProjects/UniversalGraphicsTest_2D/Assets/LayerExplorer/LayerExplorer.cs.meta create mode 100644 TestProjects/UniversalGraphicsTest_2D/Assets/LayerExplorer/LayerExplorer.uss create mode 100644 TestProjects/UniversalGraphicsTest_2D/Assets/LayerExplorer/LayerExplorer.uss.meta create mode 100644 TestProjects/UniversalGraphicsTest_2D/Assets/LayerExplorer/LayerExplorer.uxml create mode 100644 TestProjects/UniversalGraphicsTest_2D/Assets/LayerExplorer/LayerExplorer.uxml.meta diff --git a/TestProjects/UniversalGraphicsTest_2D/Assets/LayerExplorer.meta b/TestProjects/UniversalGraphicsTest_2D/Assets/LayerExplorer.meta new file mode 100644 index 00000000000..5e714c24ce5 --- /dev/null +++ b/TestProjects/UniversalGraphicsTest_2D/Assets/LayerExplorer.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 5329900f84e7b4d949d9e72ec7a12c90 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/TestProjects/UniversalGraphicsTest_2D/Assets/LayerExplorer/LayerBatch.uxml b/TestProjects/UniversalGraphicsTest_2D/Assets/LayerExplorer/LayerBatch.uxml new file mode 100644 index 00000000000..db79727ec9b --- /dev/null +++ b/TestProjects/UniversalGraphicsTest_2D/Assets/LayerExplorer/LayerBatch.uxml @@ -0,0 +1,18 @@ + + + + + + + + + + + diff --git a/TestProjects/UniversalGraphicsTest_2D/Assets/LayerExplorer/LayerBatch.uxml.meta b/TestProjects/UniversalGraphicsTest_2D/Assets/LayerExplorer/LayerBatch.uxml.meta new file mode 100644 index 00000000000..46f02345329 --- /dev/null +++ b/TestProjects/UniversalGraphicsTest_2D/Assets/LayerExplorer/LayerBatch.uxml.meta @@ -0,0 +1,10 @@ +fileFormatVersion: 2 +guid: 754a67c6d4788447895a4349508b2f37 +ScriptedImporter: + internalIDToNameTable: [] + externalObjects: {} + serializedVersion: 2 + userData: + assetBundleName: + assetBundleVariant: + script: {fileID: 13804, guid: 0000000000000000e000000000000000, type: 0} diff --git a/TestProjects/UniversalGraphicsTest_2D/Assets/LayerExplorer/LayerExplorer.cs b/TestProjects/UniversalGraphicsTest_2D/Assets/LayerExplorer/LayerExplorer.cs new file mode 100644 index 00000000000..b0a59772f90 --- /dev/null +++ b/TestProjects/UniversalGraphicsTest_2D/Assets/LayerExplorer/LayerExplorer.cs @@ -0,0 +1,91 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using Unity.Mathematics; +using UnityEditor; +using UnityEngine; +using UnityEngine.UIElements; +using Random = UnityEngine.Random; + + +internal class LayerExplorer : EditorWindow +{ + public class LayerBatch + { + public string[] LayerNames; + public int batchId; + public int color; + } + + + [MenuItem("Window/2D/LayerExplorer")] + public static void ShowExample() + { + LayerExplorer wnd = GetWindow(); + wnd.titleContent = new GUIContent("Layer Explorer"); + } + + public void CreateGUI() + { + // Each editor window contains a root VisualElement object + var root = rootVisualElement; + + // Import UXML + var styleSheet = AssetDatabase.LoadAssetAtPath("Assets/LayerExplorer/LayerExplorer.uss"); + var visualTree = AssetDatabase.LoadAssetAtPath("Assets/LayerExplorer/LayerExplorer.uxml"); + VisualElement templateRoot = visualTree.Instantiate(); + templateRoot.style.flexGrow = 1; + templateRoot.styleSheets.Add(styleSheet); + root.Add(templateRoot); + + const int itemCount = 10; + var colors = new[] + { + Color.black, Color.blue, Color.cyan, + Color.gray, Color.green, Color.magenta, + Color.red, Color.white, Color.yellow, + }; + var items = new List(itemCount); + for (var i = 0; i < itemCount; i++) + { + items.Add(new LayerBatch + { + batchId = i, + LayerNames = new [] + { + $"Layer {i}.A", $"Layer {i}.B", $"Layer {i}.C", + $"Layer {i}.D", $"Layer {i}.E", $"Layer {i}.F", + $"Layer {i}.G", $"Layer {i}.H", $"Layer {i}.J" + } + }); + } + + var batchElement = AssetDatabase.LoadAssetAtPath("Assets/LayerExplorer/LayerBatch.uxml"); + Func makeItem = () => batchElement.Instantiate(); + + Action bindItem = (e, i) => + { + // this line is required to make the child of the Listview vary in heights + e.style.height = new StyleLength(StyleKeyword.Auto); + var batchIndex = e.Query