Skip to content

Commit

Permalink
Merge pull request #1619 from thestonefox/fix/ui-pointer-max-length
Browse files Browse the repository at this point in the history
fix(Pointers): ensure pointer id exists when checking ui pointer length
  • Loading branch information
thestonefox authored Nov 16, 2017
2 parents e6ffb82 + 3de1e48 commit ba1f53e
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
11 changes: 11 additions & 0 deletions Assets/VRTK/Documentation/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -7967,6 +7967,17 @@ Adding the `VRTK_UIPointer_UnityEvents` component to `VRTK_UIPointer` object all

### Class Methods

#### GetPointerLength/1

> `public static float GetPointerLength(int pointerId)`

* Parameters
* `int pointerId` - The pointer ID for the UI Pointer to recieve the length for.
* Returns
* `float` - The maximum length the UI Pointer will cast to.

The GetPointerLength method retrieves the maximum UI Pointer length for the given pointer ID.

#### SetEventSystem/1

> `public virtual VRTK_VRInputModule SetEventSystem(EventSystem eventSystem)`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ protected virtual float GetHitDistance(Ray ray, float hitDistance)
//[Pure]
protected virtual void Raycast(Canvas canvas, Camera eventCamera, PointerEventData eventData, Ray ray, ref List<RaycastResult> results)
{
float hitDistance = GetHitDistance(ray, VRTK_UIPointer.pointerLengths[eventData.pointerId]);
float hitDistance = GetHitDistance(ray, VRTK_UIPointer.GetPointerLength(eventData.pointerId));
IList<Graphic> canvasGraphics = GraphicRegistry.GetGraphicsForCanvas(canvas);
for (int i = 0; i < canvasGraphics.Count; ++i)
{
Expand Down
18 changes: 16 additions & 2 deletions Assets/VRTK/Source/Scripts/UI/VRTK_UIPointer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ public struct UIPointerEventArgs
[AddComponentMenu("VRTK/Scripts/UI/VRTK_UIPointer")]
public class VRTK_UIPointer : MonoBehaviour
{
public static Dictionary<int, float> pointerLengths = new Dictionary<int, float>();

/// <summary>
/// Methods of activation.
/// </summary>
Expand Down Expand Up @@ -182,6 +180,7 @@ public enum ClickMethods
/// </summary>
public event UIPointerEventHandler UIPointerElementDragEnd;

protected static Dictionary<int, float> pointerLengths = new Dictionary<int, float>();
protected bool pointerClicked = false;
protected bool beamEnabledState = false;
protected bool lastPointerPressState = false;
Expand All @@ -193,6 +192,21 @@ public enum ClickMethods
protected EventSystem cachedEventSystem;
protected VRTK_VRInputModule cachedVRInputModule;

/// <summary>
/// The GetPointerLength method retrieves the maximum UI Pointer length for the given pointer ID.
/// </summary>
/// <param name="pointerId">The pointer ID for the UI Pointer to recieve the length for.</param>
/// <returns>The maximum length the UI Pointer will cast to.</returns>
public static float GetPointerLength(int pointerId)
{
float maxLength;
if (!pointerLengths.TryGetValue(pointerId, out maxLength))
{
maxLength = float.MaxValue;
}
return maxLength;
}

public virtual void OnUIPointerElementEnter(UIPointerEventArgs e)
{
if (e.currentTarget != currentTarget)
Expand Down

0 comments on commit ba1f53e

Please sign in to comment.