浏览代码
TransitionTableEditorWindow (#191)
TransitionTableEditorWindow (#191)
* Added TransitionTableEditorWindow. * [Bot] Automated dotnet-format update Co-authored-by: Ciro Continisio <ciro@unity3d.com>/main
GitHub
4 年前
当前提交
534e7d86
共有 9 个文件被更改,包括 398 次插入 和 71 次删除
-
83UOP1_Project/Assets/Scripts/StateMachine/Editor/AddTransitionHelper.cs
-
72UOP1_Project/Assets/Scripts/StateMachine/Editor/TransitionDisplayHelper.cs
-
48UOP1_Project/Assets/Scripts/StateMachine/Editor/TransitionTableEditor.cs
-
132UOP1_Project/Assets/Scripts/StateMachine/Editor/TransitionTableEditorWindow.cs
-
11UOP1_Project/Assets/Scripts/StateMachine/Editor/TransitionTableEditorWindow.cs.meta
-
81UOP1_Project/Assets/Scripts/StateMachine/Editor/TransitionTableEditorWindow.uss
-
11UOP1_Project/Assets/Scripts/StateMachine/Editor/TransitionTableEditorWindow.uss.meta
-
21UOP1_Project/Assets/Scripts/StateMachine/Editor/TransitionTableEditorWindow.uxml
-
10UOP1_Project/Assets/Scripts/StateMachine/Editor/TransitionTableEditorWindow.uxml.meta
|
|||
using UnityEditor; |
|||
using UnityEngine; |
|||
using UnityEngine.UIElements; |
|||
using UOP1.StateMachine.ScriptableObjects; |
|||
|
|||
namespace UOP1.StateMachine.Editor |
|||
{ |
|||
internal class TransitionTableEditorWindow : EditorWindow |
|||
{ |
|||
private static TransitionTableEditorWindow _window; |
|||
private static readonly string _uxmlPath = "Assets/Scripts/StateMachine/Editor/TransitionTableEditorWindow.uxml"; |
|||
private static readonly string _ussPath = "Assets/Scripts/StateMachine/Editor/TransitionTableEditorWindow.uss"; |
|||
private bool _doRefresh; |
|||
|
|||
private UnityEditor.Editor _transitionTableEditor; |
|||
|
|||
[MenuItem("Transition Table Editor", menuItem = "ChopChop/State Machine/Transition Table Editor")] |
|||
internal static void Display() |
|||
{ |
|||
if (_window == null) |
|||
_window = GetWindow<TransitionTableEditorWindow>("Transition Table Editor"); |
|||
|
|||
_window.Show(); |
|||
} |
|||
|
|||
private void OnEnable() |
|||
{ |
|||
var visualTree = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>(_uxmlPath); |
|||
var styleSheet = AssetDatabase.LoadAssetAtPath<StyleSheet>(_ussPath); |
|||
|
|||
rootVisualElement.Add(visualTree.CloneTree()); |
|||
|
|||
string labelClass = $"label-{(EditorGUIUtility.isProSkin ? "pro" : "personal")}"; |
|||
rootVisualElement.Query<Label>().Build().ForEach(label => label.AddToClassList(labelClass)); |
|||
|
|||
rootVisualElement.styleSheets.Add(styleSheet); |
|||
|
|||
minSize = new Vector2(480, 360); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Update list every time we gain focus
|
|||
/// </summary>
|
|||
private void OnFocus() |
|||
{ |
|||
// Calling CreateListView() from here when the window is docked
|
|||
// throws a NullReferenceException in UnityEditor.DockArea:OnEnable().
|
|||
if (_doRefresh == false) |
|||
_doRefresh = true; |
|||
} |
|||
|
|||
private void Update() |
|||
{ |
|||
if (!_doRefresh) |
|||
return; |
|||
|
|||
CreateListView(); |
|||
_doRefresh = false; |
|||
} |
|||
|
|||
private void CreateListView() |
|||
{ |
|||
var assets = FindAssets(); |
|||
ListView listView = rootVisualElement.Q<ListView>(className: "table-list"); |
|||
|
|||
listView.makeItem = null; |
|||
listView.bindItem = null; |
|||
|
|||
listView.itemsSource = assets; |
|||
listView.itemHeight = 16; |
|||
string labelClass = $"label-{(EditorGUIUtility.isProSkin ? "pro" : "personal")}"; |
|||
listView.makeItem = () => |
|||
{ |
|||
var label = new Label(); |
|||
label.AddToClassList(labelClass); |
|||
return label; |
|||
}; |
|||
listView.bindItem = (element, i) => ((Label)element).text = assets[i].name; |
|||
listView.selectionType = SelectionType.Single; |
|||
|
|||
listView.onSelectionChanged += enumerable => |
|||
{ |
|||
IMGUIContainer editor = rootVisualElement.Q<IMGUIContainer>(className: "table-editor"); |
|||
editor.onGUIHandler = null; |
|||
|
|||
if (enumerable.Count == 0) |
|||
return; |
|||
|
|||
var table = (TransitionTableSO)enumerable[0]; |
|||
if (table == null) |
|||
return; |
|||
|
|||
if (_transitionTableEditor == null) |
|||
_transitionTableEditor = UnityEditor.Editor.CreateEditor(table, typeof(TransitionTableEditor)); |
|||
else |
|||
UnityEditor.Editor.CreateCachedEditor(table, typeof(TransitionTableEditor), ref _transitionTableEditor); |
|||
|
|||
editor.onGUIHandler = () => |
|||
{ |
|||
if (!_transitionTableEditor.target) |
|||
{ |
|||
editor.onGUIHandler = null; |
|||
return; |
|||
} |
|||
|
|||
if ((Object)listView.selectedItem != _transitionTableEditor.target) |
|||
{ |
|||
var i = listView.itemsSource.IndexOf(_transitionTableEditor.target); |
|||
listView.selectedIndex = i; |
|||
if (i < 0) |
|||
{ |
|||
editor.onGUIHandler = null; |
|||
return; |
|||
} |
|||
} |
|||
|
|||
_transitionTableEditor.OnInspectorGUI(); |
|||
}; |
|||
}; |
|||
} |
|||
|
|||
private TransitionTableSO[] FindAssets() |
|||
{ |
|||
var guids = AssetDatabase.FindAssets($"t:{nameof(TransitionTableSO)}"); |
|||
var assets = new TransitionTableSO[guids.Length]; |
|||
for (int i = 0; i < guids.Length; i++) |
|||
assets[i] = AssetDatabase.LoadAssetAtPath<TransitionTableSO>(AssetDatabase.GUIDToAssetPath(guids[i])); |
|||
|
|||
return assets; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 1206c79203d3312419e6043c944a8f14 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
.root-container { |
|||
flex-direction: row; |
|||
flex-wrap: nowrap; |
|||
flex-basis: auto; |
|||
padding: 5px; |
|||
width: auto; |
|||
height: auto; |
|||
min-height: 250px; |
|||
flex-grow: 1; |
|||
flex-shrink: 1; |
|||
} |
|||
|
|||
.table-list-container { |
|||
flex-direction: column; |
|||
flex-wrap: nowrap; |
|||
flex-grow: 1; |
|||
justify-content: flex-start; |
|||
align-items: stretch; |
|||
align-content: stretch; |
|||
align-self: stretch; |
|||
width: 40%; |
|||
height: auto; |
|||
-unity-text-align: upper-center; |
|||
} |
|||
|
|||
.table-list-title { |
|||
color: gray; |
|||
flex-grow: 0; |
|||
width: auto; |
|||
height: auto; |
|||
-unity-font-style: bold; |
|||
font-size: 16px; |
|||
padding: 5px; |
|||
} |
|||
|
|||
.table-list { |
|||
flex-direction: column; |
|||
flex-wrap: nowrap; |
|||
flex-grow: 1; |
|||
width: auto; |
|||
height: auto; |
|||
padding: 2px; |
|||
} |
|||
|
|||
.label-personal { |
|||
color: #565656; |
|||
} |
|||
|
|||
.label-pro { |
|||
color: #d9d9d9; |
|||
} |
|||
|
|||
.table-list-refresh { |
|||
width: 20px; |
|||
height: 20px; |
|||
padding: 1px; |
|||
margin: 5px; |
|||
align-self: stretch; |
|||
justify-content: center; |
|||
align-content: center; |
|||
} |
|||
|
|||
.table-editor-container { |
|||
flex-direction: column; |
|||
padding: 5px; |
|||
width: 60%; |
|||
border-color: rgb(150, 150, 150); |
|||
border-left-width: 1px; |
|||
} |
|||
|
|||
.table-editor { |
|||
padding: 5px; |
|||
width: auto; |
|||
} |
|||
|
|||
.table-name { |
|||
width: auto; |
|||
flex-grow: 1; |
|||
padding: 10px; |
|||
font-size: 20px; |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 9e86a94cec7a6f549b603658cb974b8e |
|||
ScriptedImporter: |
|||
internalIDToNameTable: [] |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|||
script: {fileID: 12385, guid: 0000000000000000e000000000000000, type: 0} |
|||
disableValidation: 0 |
|
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<engine:UXML |
|||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
|||
xmlns:engine="UnityEngine.UIElements" |
|||
xmlns:editor="UnityEditor.UIElements" |
|||
xsi:noNamespaceSchemaLocation="../../../../UIElementsSchema/UIElements.xsd"> |
|||
|
|||
<engine:VisualElement class="root-container"> |
|||
|
|||
<engine:VisualElement class="table-list-container"> |
|||
<engine:Label class="table-list-title" text="Transition Tables" /> |
|||
<engine:ListView class="table-list" /> |
|||
</engine:VisualElement> |
|||
|
|||
<engine:ScrollView class="table-editor-container"> |
|||
<engine:IMGUIContainer class="table-editor" /> |
|||
</engine:ScrollView> |
|||
|
|||
</engine:VisualElement> |
|||
|
|||
</engine:UXML> |
|
|||
fileFormatVersion: 2 |
|||
guid: 32d0e869d54306c4a94a0cc1d8176a87 |
|||
ScriptedImporter: |
|||
internalIDToNameTable: [] |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|||
script: {fileID: 13804, guid: 0000000000000000e000000000000000, type: 0} |
撰写
预览
正在加载...
取消
保存
Reference in new issue