Skip to content

Commit 31864a3

Browse files
committed
Added fade in/out transition for the new "navigate back" button (#22).
1 parent a3116dc commit 31864a3

File tree

5 files changed

+52
-20
lines changed

5 files changed

+52
-20
lines changed

Core/Solution/Hover.Cast/Display/Standard/UiItemSelectRenderer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ public void UpdateHoverPoints(IBaseItemPointsState pPointsState, Vector3 pCursor
124124
/*--------------------------------------------------------------------------------------------*/
125125
public static float GetArcAlpha(MenuState pMenuState) {
126126
float alpha = 1-(float)Math.Pow(1-pMenuState.DisplayStrength, 2);
127-
alpha -= (float)Math.Pow(pMenuState.NavBackStrength, 2);
127+
alpha -= (float)Math.Pow(pMenuState.NavBackStrength, 2)*0.5f;
128128
return Math.Max(0, alpha);
129129
}
130130

Core/Solution/Hover.Cast/Display/Standard/UiPalmNavBackRenderer.cs

Lines changed: 42 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Diagnostics;
23
using Hover.Cast.Custom.Standard;
34
using Hover.Cast.State;
45
using Hover.Common.Custom;
@@ -18,10 +19,13 @@ public class UiPalmNavBackRenderer : MonoBehaviour, IUiItemRenderer {
1819

1920
protected MenuState vMenuState;
2021
protected IBaseItemState vItemState;
22+
protected ISelectableItem vSelItem;
2123
protected ItemVisualSettingsStandard vSettings;
2224

2325
protected UiHoverMeshSlice vHoverSlice;
2426
protected GameObject vIcon;
27+
protected Stopwatch vEnabledAnim;
28+
protected bool vPrevEnabled;
2529

2630

2731
////////////////////////////////////////////////////////////////////////////////////////////////
@@ -30,6 +34,7 @@ public virtual void Build(MenuState pMenuState, IBaseItemState pItemState,
3034
float pArcAngle, IItemVisualSettings pSettings) {
3135
vMenuState = pMenuState;
3236
vItemState = pItemState;
37+
vSelItem = (vItemState.Item as ISelectableItem);
3338
vSettings = (ItemVisualSettingsStandard)pSettings;
3439

3540
////
@@ -52,31 +57,32 @@ public virtual void Build(MenuState pMenuState, IBaseItemState pItemState,
5257

5358
/*--------------------------------------------------------------------------------------------*/
5459
public virtual void Update() {
55-
ISelectableItem selItem = (vItemState.Item as ISelectableItem);
56-
5760
float high = vItemState.MaxHighlightProgress;
5861
bool showEdge = (vItemState.IsNearestHighlight && !vItemState.IsSelectionPrevented &&
59-
selItem != null && selItem.AllowSelection);
62+
vSelItem.AllowSelection);
6063
float edge = (showEdge ? high : 0);
61-
float select = 1-(float)Math.Pow(1-vItemState.SelectionProgress, 1.5f);
64+
float select = vItemState.SelectionProgress;
6265
float alpha = Math.Max(0, 1-(float)Math.Pow(1-vMenuState.DisplayStrength, 2));
66+
float enabledAnimProg = GetEnabledAnimProgress();
6367

64-
if ( vMenuState.NavBackStrength > select ) {
68+
if ( vSelItem.IsEnabled && vMenuState.NavBackStrength > select ) {
6569
select = vMenuState.NavBackStrength;
70+
edge = select;
6671
}
6772

73+
select = 1-(float)Math.Pow(1-select, 1.5f);
74+
6875
Color colBg = vSettings.BackgroundColor;
6976
Color colEdge = vSettings.EdgeColor;
7077
Color colHigh = vSettings.HighlightColor;
7178
Color colSel = vSettings.SelectionColor;
7279
Color colIcon = vSettings.ArrowIconColor;
7380

74-
colBg.a *= alpha*(vItemState.Item.IsEnabled ? 1 : 0.333f);
81+
colBg.a *= alpha*Mathf.Lerp(0.333f, 1, enabledAnimProg);
7582
colEdge.a *= edge*alpha;
7683
colHigh.a *= high*alpha;
7784
colSel.a *= select*alpha;
78-
colIcon.a *= (vItemState.MaxHighlightProgress*0.75f + 0.25f)*alpha*
79-
(vItemState.Item.IsEnabled ? 1 : 0);
85+
colIcon.a *= (vItemState.MaxHighlightProgress*0.75f + 0.25f)*alpha*enabledAnimProg;
8086

8187
vHoverSlice.UpdateBackground(colBg);
8288
vHoverSlice.UpdateEdge(colEdge);
@@ -98,6 +104,34 @@ public void UpdateHoverPoints(IBaseItemPointsState pPointsState, Vector3 pCursor
98104
vHoverSlice.UpdateHoverPoints(pPointsState);
99105
}
100106

107+
108+
////////////////////////////////////////////////////////////////////////////////////////////////
109+
/*--------------------------------------------------------------------------------------------*/
110+
private float GetEnabledAnimProgress() {
111+
if ( vSelItem.IsEnabled != vPrevEnabled ) {
112+
vEnabledAnim = Stopwatch.StartNew();
113+
vPrevEnabled = vSelItem.IsEnabled;
114+
}
115+
116+
float prog = (vSelItem.IsEnabled ? 1 : 0);
117+
118+
if ( vEnabledAnim != null ) {
119+
float ms = (float)vEnabledAnim.Elapsed.TotalMilliseconds;
120+
prog = Math.Min(1, ms/UiArc.LevelChangeMilliseconds);
121+
prog = 1-(float)Math.Pow(1-prog, 3);
122+
123+
if ( prog >= 1 ) {
124+
vEnabledAnim = null;
125+
}
126+
127+
if ( !vSelItem.IsEnabled ) {
128+
prog = 1-prog;
129+
}
130+
}
131+
132+
return prog;
133+
}
134+
101135
}
102136

103137
}

Core/Solution/Hover.Cast/Display/UiArc.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Diagnostics;
23
using Hover.Cast.State;
34
using Hover.Common.Custom;
45
using UnityEngine;
@@ -8,15 +9,15 @@ namespace Hover.Cast.Display {
89
/*================================================================================================*/
910
public class UiArc : MonoBehaviour {
1011

11-
private const float LevelChangeMilliseconds = 1000;
12+
public const float LevelChangeMilliseconds = 1000;
1213
private const float LevelChangeDistance = 0.5f;
1314

1415
private MenuState vMenuState;
1516
private IItemVisualSettingsProvider vVisualSettingsProv;
1617

1718
private GameObject vPrevLevelObj;
1819
private GameObject vCurrLevelObj;
19-
private DateTime? vChangeTime;
20+
private Stopwatch vChangeAnim;
2021
private int vChangeDir;
2122

2223

@@ -71,7 +72,7 @@ private void HandleLevelChange(int pDirection) {
7172

7273
////
7374

74-
vChangeTime = DateTime.UtcNow;
75+
vChangeAnim = Stopwatch.StartNew();
7576
vChangeDir = pDirection;
7677
UpdateItemChangeAnim();
7778
}
@@ -89,11 +90,11 @@ private void DestroyPrevLevel() {
8990

9091
/*--------------------------------------------------------------------------------------------*/
9192
private void UpdateItemChangeAnim() {
92-
if ( vChangeTime == null ) {
93+
if ( vChangeAnim == null ) {
9394
return;
9495
}
9596

96-
float ms = (float)(DateTime.UtcNow-(DateTime)vChangeTime).TotalMilliseconds;
97+
float ms = (float)vChangeAnim.Elapsed.TotalMilliseconds;
9798
float prog = Math.Min(1, ms/LevelChangeMilliseconds);
9899
float push = 1-(float)Math.Pow(1-prog, 3);
99100
float dist = LevelChangeDistance*vChangeDir;
@@ -126,7 +127,7 @@ private void UpdateItemChangeAnim() {
126127
return;
127128
}
128129

129-
vChangeTime = null;
130+
vChangeAnim = null;
130131
DestroyPrevLevel();
131132
}
132133

Core/Solution/Hover.Cast/Hover.Cast.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
<WarningLevel>4</WarningLevel>
3838
</PropertyGroup>
3939
<ItemGroup>
40+
<Reference Include="System" />
4041
<Reference Include="System.Core" />
4142
<Reference Include="UnityEngine">
4243
<HintPath>..\..\Packages\Unity\UnityEngine.dll</HintPath>

Unity/ProjectSettings/EditorBuildSettings.asset

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,9 @@ EditorBuildSettings:
1111
path: Assets/Hover/Demo/BoardTest/HoverboardTest-VR-LookCursor.unity
1212
- enabled: 0
1313
path: Assets/Hover/Demo/BoardTest/HoverboardTest-VR-LeapCursor.unity
14-
- enabled: 0
14+
- enabled: 1
1515
path: Assets/Hover/Demo/CastCubes/Scenes/HovercastDemo-LeapVR.unity
1616
- enabled: 0
1717
path: Assets/Hover/Demo/CastCubes/Scenes/HovercastDemo-LeapLookVR.unity
18-
- enabled: 0
19-
path: Assets/Hover/Demo/CastCubes/Scenes/HovercastDemo-LeapVR.unity
2018
- enabled: 0
2119
path: Assets/Hover/Demo/BoardKeys/Scenes/HoverboardDemo-LeapVR.unity
22-
- enabled: 1
23-
path: Assets/Hover/Demo/CastCubes/Scenes/HovercastDemo-LeapLookVR.unity

0 commit comments

Comments
 (0)