Skip to content

Commit

Permalink
Buttons slightly raise on finger hover.
Browse files Browse the repository at this point in the history
  • Loading branch information
keratin-zz committed Aug 6, 2020
1 parent f2c96f7 commit ecd976a
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 4 deletions.
17 changes: 16 additions & 1 deletion Assets/HandPrototypes/MainScene.unity
Original file line number Diff line number Diff line change
Expand Up @@ -2345,7 +2345,7 @@ PrefabInstance:
- target: {fileID: 1730906851016468429, guid: 6b84f7d98a80f164294b139ecbd34010,
type: 3}
propertyPath: m_Enabled
value: 1
value: 0
objectReference: {fileID: 0}
- target: {fileID: 5694575601483139583, guid: 6b84f7d98a80f164294b139ecbd34010,
type: 3}
Expand Down Expand Up @@ -3788,6 +3788,11 @@ PrefabInstance:
m_Modification:
m_TransformParent: {fileID: 1762622714}
m_Modifications:
- target: {fileID: 229006733337189751, guid: dea9f279749939440b0b1bf2b6460e55,
type: 3}
propertyPath: iconZRaiseAmount
value: -0.003
objectReference: {fileID: 0}
- target: {fileID: 510854079520875842, guid: dea9f279749939440b0b1bf2b6460e55,
type: 3}
propertyPath: m_textInfo.characterCount
Expand All @@ -3808,6 +3813,11 @@ PrefabInstance:
propertyPath: m_textInfo.pageCount
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2892746865250970467, guid: dea9f279749939440b0b1bf2b6460e55,
type: 3}
propertyPath: iconZRaiseAmount
value: -0.003
objectReference: {fileID: 0}
- target: {fileID: 3179095552238441302, guid: dea9f279749939440b0b1bf2b6460e55,
type: 3}
propertyPath: m_textInfo.characterCount
Expand Down Expand Up @@ -3858,6 +3868,11 @@ PrefabInstance:
propertyPath: m_Mesh
value:
objectReference: {fileID: 0}
- target: {fileID: 7488734276970437891, guid: dea9f279749939440b0b1bf2b6460e55,
type: 3}
propertyPath: iconZRaiseAmount
value: -0.003
objectReference: {fileID: 0}
- target: {fileID: 7594332645057486051, guid: dea9f279749939440b0b1bf2b6460e55,
type: 3}
propertyPath: m_Name
Expand Down
2 changes: 1 addition & 1 deletion Assets/HandPrototypes/Prefabs/MainSlate.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -8732,7 +8732,7 @@ PrefabInstance:
- target: {fileID: 2264288032279184651, guid: a193c7f8a518d8649aa3860812d3cbfa,
type: 3}
propertyPath: untoggledKey
value: 94
value: 92
objectReference: {fileID: 0}
- target: {fileID: 2585705128737116992, guid: a193c7f8a518d8649aa3860812d3cbfa,
type: 3}
Expand Down
2 changes: 1 addition & 1 deletion Assets/HandPrototypes/Prefabs/TabButton.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 5b9bedc9ad37d9c47971e5289fe0fcdf, type: 3}
m_Name:
m_EditorClassIdentifier:
interactionStyle: 0
interactionStyle: 1
toggled: 0
focus: {fileID: 4740404185345162967}
pressSound: {fileID: 4996866513072381586}
Expand Down
1 change: 1 addition & 0 deletions Assets/HandPrototypes/Prefabs/UguiButton.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ MonoBehaviour:
iconController: {fileID: 2585705128737116992}
toggledKey: 0
untoggledKey: 0
iconZRaiseAmount: -0.4
buttonBackground: {fileID: 2030449889531097754}
--- !u!114 &1505123739738324399
MonoBehaviour:
Expand Down
2 changes: 1 addition & 1 deletion Assets/HandPrototypes/Scripts/PushyButtonController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ private ButtonState UpdateState()
{
Vector3 localPos = GetLocalFingerPosition();
Pressedness = localPos.z;
if (localPos.z < 0 && (State == ButtonState.Ready || State == ButtonState.Hovered))
if (localPos.z <= 0 && (State == ButtonState.Ready || State == ButtonState.Hovered))
{
return ButtonState.Hovered;
}
Expand Down
36 changes: 36 additions & 0 deletions Assets/HandPrototypes/Scripts/UguiButtonVisualsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,20 @@ public class UguiButtonVisualsController : ButtonVisualController

private Material backgroundMat;

[SerializeField]
private float iconZRaiseAmount = -.4f;
private float iconZ;

private RectTransform backgroundRect;

[SerializeField]
private Image buttonBackground;
private void Start()
{
buttonBackground.material = new Material(buttonBackground.material);
backgroundMat = buttonBackground.material;
button = GetComponent<PushyButtonController>();
backgroundRect = buttonBackground.GetComponent<RectTransform>();
button.Pressed += Button_Pressed;
}

Expand All @@ -41,10 +49,38 @@ private void Button_Pressed(object sender, EventArgs e)

private void Update()
{
UpdateIconPosition();
UpdateColors();
UpdatePulse();
}

private void UpdateIconPosition()
{
float zTarget = GetIconZTarget();
iconZ = Mathf.Lerp(iconZ, zTarget, Time.deltaTime * 10);
iconController.transform.localPosition = new Vector3(iconController.transform.localPosition.x, iconController.transform.localPosition.y, iconZ);
}

private float GetIconZTarget()
{
if(button.State == ButtonState.Hovered)
{
float dist = GetDistToFinger(backgroundRect.transform, Hands.Instance.RightHandProxy.IndexTip.position);
return Mathf.Max(dist, iconZRaiseAmount);
}
if(button.State == ButtonState.Pressed)
{
return iconZRaiseAmount;
}
return 0;
}

private float GetDistToFinger(Transform transform, Vector3 position)
{
Plane plane = new Plane(transform.forward, transform.position);
return plane.GetDistanceToPoint(position);
}

private void UpdatePulse()
{
float prog = Mathf.Clamp01(button.Outro / button.OutroDuration);
Expand Down

0 comments on commit ecd976a

Please sign in to comment.