@@ -10,8 +10,12 @@ namespace Unity.Samples.LetterSpell
10
10
[ UxmlElement ]
11
11
public partial class StackView : VisualElement
12
12
{
13
+ private VisualElement m_ContentContainer ;
13
14
private VisualElement m_ActiveView ;
15
+ private VisualElement m_TransitionElement ;
14
16
17
+ public override VisualElement contentContainer => m_ContentContainer ;
18
+
15
19
[ UxmlAttribute ]
16
20
public int index
17
21
{
@@ -29,10 +33,17 @@ public VisualElement activeView
29
33
get => m_ActiveView ;
30
34
set
31
35
{
36
+ var oldView = m_ActiveView ;
37
+
32
38
if ( m_ActiveView == value )
33
39
return ;
34
40
m_ActiveView = value ;
35
- UpdateViews ( ) ;
41
+
42
+ if ( panel != null )
43
+ StartTransition ( oldView , m_ActiveView ) ;
44
+ else
45
+ UpdateViews ( ) ;
46
+
36
47
activeViewChanged ? . Invoke ( ) ;
37
48
}
38
49
}
@@ -41,9 +52,54 @@ public VisualElement activeView
41
52
42
53
public StackView ( )
43
54
{
55
+ AddToClassList ( "lsp-stack-view" ) ;
56
+
57
+ m_ContentContainer = new VisualElement ( ) ;
58
+ m_ContentContainer . AddToClassList ( "lsp-stack-view__content-container" ) ;
59
+ m_ContentContainer . style . flexGrow = 1 ;
60
+ hierarchy . Add ( m_ContentContainer ) ;
44
61
RegisterCallback < GeometryChangedEvent > ( ( e ) => UpdateViews ( ) ) ;
45
62
}
63
+
64
+ void StartTransition ( VisualElement from , VisualElement to )
65
+ {
66
+ if ( m_TransitionElement == null )
67
+ {
68
+ m_TransitionElement ??= new VisualElement ( ) ;
69
+ m_TransitionElement . AddToClassList ( "lsp-stack-view-Transition" ) ;
70
+ }
71
+ m_TransitionElement . style . opacity = 0 ;
72
+ hierarchy . Add ( m_TransitionElement ) ;
46
73
74
+ var fadeIn = m_TransitionElement . experimental . animation . Start (
75
+ ( element ) => element . style . opacity . value ,
76
+ 1f , 400 , ( element , value ) =>
77
+ {
78
+ element . style . opacity = value ;
79
+ Debug . Log ( "op = " + value ) ;
80
+ } ) ;
81
+ fadeIn . onAnimationCompleted += ( ) =>
82
+ {
83
+ // Hide the old view
84
+ if ( from != null )
85
+ from . style . display = DisplayStyle . None ;
86
+
87
+ // Show the new view
88
+ if ( to != null )
89
+ {
90
+ to . style . display = DisplayStyle . Flex ;
91
+ }
92
+
93
+ var fadeOut = m_TransitionElement . experimental . animation . Start (
94
+ ( element ) => element . style . opacity . value ,
95
+ 0 , 400 , ( element , value ) => element . style . opacity = value ) ;
96
+ fadeOut . onAnimationCompleted += ( ) =>
97
+ {
98
+ m_TransitionElement . RemoveFromHierarchy ( ) ;
99
+ } ;
100
+ } ;
101
+ }
102
+
47
103
public void UpdateViews ( )
48
104
{
49
105
foreach ( var view in Children ( ) )
0 commit comments