mirror of
https://github.com/Alex-Rachel/TEngine.git
synced 2025-08-14 16:51:28 +00:00
更新demo
更新demo
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
#if UNITY_2020_3_OR_NEWER
|
||||
using System;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityEditor.UIElements;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
/// <summary>
|
||||
/// 分屏控件
|
||||
/// </summary>
|
||||
public class SplitView : TwoPaneSplitView
|
||||
{
|
||||
public new class UxmlFactory : UxmlFactory<SplitView, TwoPaneSplitView.UxmlTraits>
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 窗口分屏适配
|
||||
/// </summary>
|
||||
public static void Adjuster(VisualElement root)
|
||||
{
|
||||
var topGroup = root.Q<VisualElement>("TopGroup");
|
||||
var bottomGroup = root.Q<VisualElement>("BottomGroup");
|
||||
topGroup.style.minHeight = 100f;
|
||||
bottomGroup.style.minHeight = 100f;
|
||||
root.Remove(topGroup);
|
||||
root.Remove(bottomGroup);
|
||||
var spliteView = new SplitView();
|
||||
spliteView.fixedPaneInitialDimension = 300;
|
||||
spliteView.orientation = TwoPaneSplitViewOrientation.Vertical;
|
||||
spliteView.contentContainer.Add(topGroup);
|
||||
spliteView.contentContainer.Add(bottomGroup);
|
||||
root.Add(spliteView);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0c3f4136cf7142346ae33e8a82cbdb27
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,25 @@
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
|
||||
#if UNITY_2019
|
||||
public static partial class UnityEngine_UIElements_ListView_Extension
|
||||
{
|
||||
public static void ClearSelection(this UnityEngine.UIElements.ListView o)
|
||||
{
|
||||
o.selectedIndex = -1;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if UNITY_2019 || UNITY_2020
|
||||
public static partial class UnityEngine_UIElements_ListView_Extension
|
||||
{
|
||||
public static void Rebuild(this UnityEngine.UIElements.ListView o)
|
||||
{
|
||||
o.Refresh();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e8e4a86c3bd8c8947a947776891e14b1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,21 @@
|
||||
#if UNITY_2019_4_OR_NEWER
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityEditor.UIElements;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
public static class UIElementsTools
|
||||
{
|
||||
public static void SetElementVisible(VisualElement element, bool visible)
|
||||
{
|
||||
if (element == null)
|
||||
return;
|
||||
|
||||
element.style.display = visible ? DisplayStyle.Flex : DisplayStyle.None;
|
||||
element.style.visibility = visible ? Visibility.Visible : Visibility.Hidden;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cacb478021cc90b49a635aae388996fa
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,55 @@
|
||||
#if UNITY_2019_4_OR_NEWER
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityEditor.UIElements;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
public class UxmlLoader
|
||||
{
|
||||
private readonly static Dictionary<System.Type, string> _uxmlDic = new Dictionary<System.Type, string>();
|
||||
|
||||
/// <summary>
|
||||
/// 加载窗口的布局文件
|
||||
/// </summary>
|
||||
public static UnityEngine.UIElements.VisualTreeAsset LoadWindowUXML<TWindow>() where TWindow : class
|
||||
{
|
||||
var windowType = typeof(TWindow);
|
||||
|
||||
// 缓存里查询并加载
|
||||
if (_uxmlDic.TryGetValue(windowType, out string uxmlGUID))
|
||||
{
|
||||
string assetPath = AssetDatabase.GUIDToAssetPath(uxmlGUID);
|
||||
if (string.IsNullOrEmpty(assetPath))
|
||||
{
|
||||
_uxmlDic.Clear();
|
||||
throw new System.Exception($"Invalid UXML GUID : {uxmlGUID} ! Please close the window and open it again !");
|
||||
}
|
||||
var treeAsset = AssetDatabase.LoadAssetAtPath<UnityEngine.UIElements.VisualTreeAsset>(assetPath);
|
||||
return treeAsset;
|
||||
}
|
||||
|
||||
// 全局搜索并加载
|
||||
string[] guids = AssetDatabase.FindAssets(windowType.Name);
|
||||
if (guids.Length == 0)
|
||||
throw new System.Exception($"Not found any assets : {windowType.Name}");
|
||||
|
||||
foreach (string assetGUID in guids)
|
||||
{
|
||||
string assetPath = AssetDatabase.GUIDToAssetPath(assetGUID);
|
||||
var assetType = AssetDatabase.GetMainAssetTypeAtPath(assetPath);
|
||||
if (assetType == typeof(UnityEngine.UIElements.VisualTreeAsset))
|
||||
{
|
||||
_uxmlDic.Add(windowType, assetGUID);
|
||||
var treeAsset = AssetDatabase.LoadAssetAtPath<UnityEngine.UIElements.VisualTreeAsset>(assetPath);
|
||||
return treeAsset;
|
||||
}
|
||||
}
|
||||
throw new System.Exception($"Not found UXML file : {windowType.Name}");
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ed843f102c2467845b34fdce5d537e47
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in New Issue
Block a user