Skip to content

Commit

Permalink
feat(Teleport): add events to teleport
Browse files Browse the repository at this point in the history
Adds 'Teleporting' and 'Teleported' events which pass along
DestinationMarkerEventArgs to any interested parties.
  • Loading branch information
bjennings76 committed Jun 12, 2016
1 parent be64a8c commit b182678
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions Assets/SteamVR_Unity_Toolkit/Scripts/VRTK_BasicTeleport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ namespace VRTK
using UnityEngine;
using System.Collections;

public delegate void TeleportEventHandler(object sender, DestinationMarkerEventArgs e);

public class VRTK_BasicTeleport : MonoBehaviour
{
public float blinkTransitionSpeed = 0.6f;
Expand All @@ -22,6 +24,9 @@ public class VRTK_BasicTeleport : MonoBehaviour
public bool headsetPositionCompensation = true;
public string ignoreTargetWithTagOrClass;

public event TeleportEventHandler Teleporting;
public event TeleportEventHandler Teleported;

protected Transform eyeCamera;
protected bool adjustYForTerrain = false;
protected bool enableTeleport = true;
Expand All @@ -31,6 +36,16 @@ public class VRTK_BasicTeleport : MonoBehaviour
private float maxBlinkTransitionSpeed = 1.5f;
private float maxBlinkDistance = 33f;

private void OnTeleporting(DestinationMarkerEventArgs e) {
if (Teleporting != null)
Teleporting(this, e);
}

private void OnTeleported(DestinationMarkerEventArgs e) {
if (Teleported != null)
Teleported(this, e);
}

public void InitDestinationSetListener(GameObject markerMaker)
{
if (markerMaker)
Expand Down Expand Up @@ -74,10 +89,12 @@ protected virtual void DoTeleport(object sender, DestinationMarkerEventArgs e)
{
if (enableTeleport && ValidLocation(e.target) && e.enableTeleport)
{
OnTeleporting(e);
Vector3 newPosition = GetNewPosition(e.destinationPosition, e.target);
CalculateBlinkDelay(blinkTransitionSpeed, newPosition);
Blink(blinkTransitionSpeed);
SetNewPosition(newPosition, e.target);
OnTeleported(e);
}
}

Expand Down

0 comments on commit b182678

Please sign in to comment.