Skip to content

Commit

Permalink
feat: StateTimeline inspector using UI Toolkit
Browse files Browse the repository at this point in the history
  • Loading branch information
christides11 committed Jul 19, 2023
1 parent bc090d3 commit 89c78a1
Show file tree
Hide file tree
Showing 9 changed files with 100 additions and 38 deletions.
28 changes: 26 additions & 2 deletions Assets/HnSF/Editor/StateTimelineEditor.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,38 @@
using UnityEditor;
using UnityEditor.UIElements;
using UnityEngine;
using UnityEngine.UIElements;

namespace HnSF
{
[CustomEditor(typeof(StateTimeline), true)]
public class StateTimelineEditor : Editor
{
public VisualTreeAsset inspectorXML;

[SerializeField] public StateTimelineEditorWindow currentTimeline;

public override void OnInspectorGUI()
public override VisualElement CreateInspectorGUI()
{
VisualElement inspector = new VisualElement();

inspectorXML.CloneTree(inspector);

// Default Inspector
VisualElement inspectorFoldout = inspector.Q("Default_Inspector");
InspectorElement.FillDefaultInspector(inspectorFoldout, serializedObject, this);

Button openEditor = inspector.Q<Button>(name: "OpenEditor");
openEditor.clicked += () =>
{
StateTimeline st = (StateTimeline)target;
st.BuildStateVariablesIDMap();
currentTimeline = StateTimelineEditorWindow.OpenWindow(st);
};

return inspector;
}
/*public override void OnInspectorGUI()
{
StateTimeline st = (StateTimeline)target;
base.OnInspectorGUI();
Expand All @@ -25,6 +49,6 @@ public override void OnInspectorGUI()
currentTimeline.RefreshFrameBars();
}
}
}
}*/
}
}
5 changes: 4 additions & 1 deletion Assets/HnSF/Editor/StateTimelineEditor.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Assets/HnSF/Editor/StateTimelineEditor.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" editor-extension-mode="True">
<ui:Button text="Open Editor" display-tooltip-when-elided="true" name="OpenEditor" />
<ui:Label text="General" display-tooltip-when-elided="true" name="Label-General" style="font-size: 24px; -unity-font-style: bold; -unity-text-align: upper-center;" />
<ui:TextField picking-mode="Ignore" label="State Name" value="filler text" text="filler text" binding-path="stateName" name="StateName" />
<ui:Toggle label="Use Base State?" binding-path="useBaseState" name="UseBaseState" />
<uie:ObjectField label="Base State" allow-scene-objects="false" name="BaseState" binding-path="baseState" />
<uie:IntegerField label="State Length" value="60" name="StateLength" binding-path="totalFrames" is-delayed="true" />
<ui:Label text="Auto" display-tooltip-when-elided="true" name="Label-Auto" style="font-size: 24px; -unity-font-style: bold; -unity-text-align: upper-center;" />
<ui:Toggle label="Auto Increment Frames" binding-path="autoIncrement" name="AutoIncrement" />
<ui:Toggle label="Auto Loop" binding-path="autoLoop" name="AutoLoop" />
<uie:IntegerField label="Auto Loop Frame" value="1" name="AutoLoopFrame" binding-path="autoLoopFrame" />
<ui:Foldout text="Default Inspector" name="Default_Inspector" value="false" />
</ui:UXML>

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 40f66a5b733e53543bcb2daa52776331, type: 3}
m_Name: ADV.State.Jump
m_EditorClassIdentifier:
stateName:
stateName: 0
useBaseState: 1
baseState: {fileID: 11400000, guid: 65f5e055426eb834a95aa16b8f725063, type: 2}
totalFrames: 24
Expand Down
1 change: 1 addition & 0 deletions HnSF.Editor.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
<None Include="Assets\HnSF\Editor\StateEditor\StateTimelineStyle.uss" />
<None Include="Assets\HnSF\Editor\HnSF.Editor.asmdef" />
<None Include="Assets\HnSF\Editor\StateEditor\sidebar-data-label.uxml" />
<None Include="Assets\HnSF\Editor\StateTimelineEditor\statetimeline_inspector_uxml.uxml" />
<None Include="Assets\HnSF\Editor\StateEditor\StateTimelineVisualTree.uxml" />
</ItemGroup>
<ItemGroup>
Expand Down
3 changes: 3 additions & 0 deletions UserSettings/EditorUserSettings.asset
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ EditorUserSettings:
RecentlyUsedScenePath-0:
value: 2242470311464673033d2a6d232252001a120b65180c07333920123dadd41019e1f33fe6e9742a323016f6
flags: 0
UIBuilder.EditorExtensionModeKey:
value: 37434103
flags: 0
vcSharedLogLevel:
value: 0d5e400f0650
flags: 0
Expand Down
68 changes: 34 additions & 34 deletions UserSettings/Layouts/default-2021.dwlt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ MonoBehaviour:
width: 2560
height: 1349
m_ShowMode: 4
m_Title: Hierarchy
m_Title: Project
m_RootView: {fileID: 6}
m_MinSize: {x: 875, y: 300}
m_MaxSize: {x: 10000, y: 10000}
Expand Down Expand Up @@ -48,7 +48,7 @@ MonoBehaviour:
m_MinSize: {x: 300, y: 200}
m_MaxSize: {x: 24288, y: 16192}
vertical: 0
controlID: 114
controlID: 75
--- !u!114 &3
MonoBehaviour:
m_ObjectHideFlags: 52
Expand Down Expand Up @@ -94,7 +94,7 @@ MonoBehaviour:
x: 0
y: 0
width: 495
height: 792
height: 761
m_MinSize: {x: 200, y: 200}
m_MaxSize: {x: 4000, y: 4000}
m_ActualView: {fileID: 16}
Expand All @@ -118,9 +118,9 @@ MonoBehaviour:
m_Position:
serializedVersion: 2
x: 0
y: 792
y: 761
width: 2041
height: 507
height: 538
m_MinSize: {x: 231, y: 271}
m_MaxSize: {x: 10001, y: 10021}
m_ActualView: {fileID: 14}
Expand Down Expand Up @@ -224,7 +224,7 @@ MonoBehaviour:
m_MinSize: {x: 200, y: 200}
m_MaxSize: {x: 16192, y: 16192}
vertical: 1
controlID: 115
controlID: 22
--- !u!114 &10
MonoBehaviour:
m_ObjectHideFlags: 52
Expand All @@ -245,11 +245,11 @@ MonoBehaviour:
x: 0
y: 0
width: 2041
height: 792
height: 761
m_MinSize: {x: 200, y: 100}
m_MaxSize: {x: 16192, y: 8096}
vertical: 0
controlID: 116
controlID: 23
--- !u!114 &11
MonoBehaviour:
m_ObjectHideFlags: 52
Expand All @@ -268,7 +268,7 @@ MonoBehaviour:
x: 495
y: 0
width: 1546
height: 792
height: 761
m_MinSize: {x: 200, y: 200}
m_MaxSize: {x: 4000, y: 4000}
m_ActualView: {fileID: 18}
Expand Down Expand Up @@ -365,9 +365,9 @@ MonoBehaviour:
m_Pos:
serializedVersion: 2
x: 0
y: 865
y: 834
width: 2040
height: 486
height: 517
m_ViewDataDictionary: {fileID: 0}
m_OverlayCanvas:
m_LastAppliedPresetName: Default
Expand All @@ -385,22 +385,22 @@ MonoBehaviour:
m_SkipHidden: 0
m_SearchArea: 1
m_Folders:
- Assets/HnSF/Samples/TDAction/Scripts/State
- Assets/HnSF/Editor
m_Globs: []
m_OriginalText:
m_ViewMode: 1
m_StartGridSize: 16
m_LastFolders:
- Assets/HnSF/Samples/TDAction/Scripts/State
- Assets/HnSF/Editor
m_LastFoldersGridSize: 16
m_LastProjectPath: C:\Projects\Unity\hack-and-slash-framework
m_LockTracker:
m_IsLocked: 0
m_FolderTreeState:
scrollPos: {x: 0, y: 62}
m_SelectedIDs: 5e660000
m_LastClickedID: 26206
m_ExpandedIDs: 00000000986400009a6400009c6400009e640000a0640000a2640000a4640000a6640000a8640000aa64000000ca9a3b
scrollPos: {x: 0, y: 19}
m_SelectedIDs: 48660000
m_LastClickedID: 26184
m_ExpandedIDs: 00000000986400009a6400009c6400009e640000a0640000a2640000a6640000a86400004866000000ca9a3bffffff7f
m_RenameOverlay:
m_UserAcceptedRename: 0
m_Name:
Expand Down Expand Up @@ -456,21 +456,21 @@ MonoBehaviour:
m_SelectedInstanceIDs:
m_LastClickedInstanceID: 0
m_HadKeyboardFocusLastEvent: 1
m_ExpandedInstanceIDs: c6230000
m_ExpandedInstanceIDs: c623000000000000
m_RenameOverlay:
m_UserAcceptedRename: 0
m_Name:
m_OriginalName:
m_Name: StateTimelineEditor
m_OriginalName: StateTimelineEditor
m_EditFieldRect:
serializedVersion: 2
x: 0
y: 0
width: 0
height: 0
m_UserData: 0
m_UserData: 4020
m_IsWaitingForDelay: 0
m_IsRenaming: 0
m_OriginalEventType: 11
m_OriginalEventType: 0
m_IsRenamingFilename: 1
m_ClientGUIView: {fileID: 5}
m_CreateAssetUtility:
Expand Down Expand Up @@ -550,15 +550,15 @@ MonoBehaviour:
x: 0
y: 73
width: 494
height: 771
height: 740
m_ViewDataDictionary: {fileID: 0}
m_OverlayCanvas:
m_LastAppliedPresetName: Default
m_SaveData: []
m_SceneHierarchy:
m_TreeViewState:
scrollPos: {x: 0, y: 0}
m_SelectedIDs:
m_SelectedIDs: b40f0000
m_LastClickedID: 0
m_ExpandedIDs: 24fbffff
m_RenameOverlay:
Expand Down Expand Up @@ -936,7 +936,7 @@ MonoBehaviour:
x: 495
y: 73
width: 1544
height: 771
height: 740
m_ViewDataDictionary: {fileID: 0}
m_OverlayCanvas:
m_LastAppliedPresetName: Default
Expand Down Expand Up @@ -984,22 +984,22 @@ MonoBehaviour:
x: 0
y: 21
width: 1544
height: 750
m_Scale: {x: 0.3472222, y: 0.3472222}
m_Translation: {x: 772, y: 375}
height: 719
m_Scale: {x: 0.33287036, y: 0.33287036}
m_Translation: {x: 772, y: 359.5}
m_MarginLeft: 0
m_MarginRight: 0
m_MarginTop: 0
m_MarginBottom: 0
m_LastShownAreaInsideMargins:
serializedVersion: 2
x: -2223.36
x: -2319.2212
y: -1080
width: 4446.72
width: 4638.4424
height: 2160
m_MinimalGUI: 1
m_defaultScale: 0.3472222
m_LastWindowPixelSize: {x: 1544, y: 771}
m_defaultScale: 0.33287036
m_LastWindowPixelSize: {x: 1544, y: 740}
m_ClearInEditMode: 1
m_NoCameraWarning: 1
m_LowResolutionForAspectRatios: 01000000000000000000
Expand Down Expand Up @@ -1027,9 +1027,9 @@ MonoBehaviour:
m_Pos:
serializedVersion: 2
x: 0
y: 865
y: 834
width: 2040
height: 486
height: 517
m_ViewDataDictionary: {fileID: 0}
m_OverlayCanvas:
m_LastAppliedPresetName: Default
Expand Down

0 comments on commit 89c78a1

Please sign in to comment.