Skip to content

Commit

Permalink
feat(Presence): add policy list to headset collision fade
Browse files Browse the repository at this point in the history
The Headset Collision Fade script can now accept a policy list to
determine which targets cause the headset fade on collision.
  • Loading branch information
thestonefox committed Dec 12, 2017
1 parent d7f5346 commit 3c2b5cc
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
1 change: 1 addition & 0 deletions Assets/VRTK/Documentation/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -7488,6 +7488,7 @@ Initiates a fade of the headset view when a headset collision event is detected.
* **Time Till Fade:** The amount of time to wait until a fade occurs.
* **Blink Transition Speed:** The fade blink speed on collision.
* **Fade Color:** The colour to fade the headset to on collision.
* **Target List Policy:** A specified VRTK_PolicyList to use to determine whether any objects will be acted upon by the Headset Collision Fade.
* **Headset Collision:** The VRTK Headset Collision script to use when determining headset collisions. If this is left blank then the script will need to be applied to the same GameObject.
* **Headset Fade:** The VRTK Headset Fade script to use when fading the headset. If this is left blank then the script will need to be applied to the same GameObject.

Expand Down
19 changes: 16 additions & 3 deletions Assets/VRTK/Source/Scripts/Presence/VRTK_HeadsetCollisionFade.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ public class VRTK_HeadsetCollisionFade : MonoBehaviour
public float blinkTransitionSpeed = 0.1f;
[Tooltip("The colour to fade the headset to on collision.")]
public Color fadeColor = Color.black;
[Tooltip("A specified VRTK_PolicyList to use to determine whether any objects will be acted upon by the Headset Collision Fade.")]
public VRTK_PolicyList targetListPolicy;

[Header("Custom Settings")]

Expand Down Expand Up @@ -68,18 +70,29 @@ protected virtual void OnDisable()

protected virtual void OnHeadsetCollisionDetect(object sender, HeadsetCollisionEventArgs e)
{
Invoke("StartFade", timeTillFade);
if (ValidTarget(e.collider))
{
Invoke("StartFade", timeTillFade);
}
}

protected virtual void OnHeadsetCollisionEnded(object sender, HeadsetCollisionEventArgs e)
{
CancelInvoke("StartFade");
headsetFade.Unfade(blinkTransitionSpeed);
if (ValidTarget(e.collider))
{
CancelInvoke("StartFade");
headsetFade.Unfade(blinkTransitionSpeed);
}
}

protected virtual void StartFade()
{
headsetFade.Fade(fadeColor, blinkTransitionSpeed);
}

protected virtual bool ValidTarget(Collider target)
{
return (target != null && !(VRTK_PolicyList.Check(target.gameObject, targetListPolicy)));
}
}
}

0 comments on commit 3c2b5cc

Please sign in to comment.