Skip to content
This repository has been archived by the owner on Aug 11, 2024. It is now read-only.

Commit

Permalink
Dev input updates (#193)
Browse files Browse the repository at this point in the history
* All the things needed to get the touch scrolling to work.

* Fixed a regression with registering for events

* removed always true expression

* updated sdk checkout for input updates

* ported deadzone fixes
enabled warnings as errors

* updated controller popout window to include inverted axes

* sdk changes for last commit

* Get the proper SDK checkout

* preliminary scroll support

* cleaned up focus provider a bit

* added is parent or child helper extension

* default bounds. not new

* added a few more checks just in case

* Cancel the async stuff if the editor changes playmode states

* Fix build error

* added a few helper methods to the clipping primitive

* added some parem docs

* Fixed common root lookup

* disabled wysisyg

* Fixed merge conflict
  • Loading branch information
StephenHodgson authored and SimonDarksideJ committed Jun 19, 2019
1 parent 3e070fd commit 840524d
Show file tree
Hide file tree
Showing 19 changed files with 591 additions and 289 deletions.
27 changes: 26 additions & 1 deletion Definitions/Devices/ControllerMappingLibrary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
using UnityEngine;
using XRTK.Definitions.Utilities;
using XRTK.Providers.Controllers;
using XRTK.Services;
using XRTK.Utilities.Editor;
#endif

Expand All @@ -21,6 +20,31 @@ public static class ControllerMappingLibrary
{
#region Constants

/// <summary>
/// Built in mouse x input axis
/// </summary>
public const string MouseY = "Mouse Y";

/// <summary>
/// Built in mouse y input axis
/// </summary>
public const string MouseX = "Mouse X";

/// <summary>
/// Built in mouse scroll input axis
/// </summary>
public const string MouseScroll = "Mouse ScrollWheel";

/// <summary>
/// Built in horizontal input axis
/// </summary>
public const string Horizontal = "Horizontal";

/// <summary>
/// Built in vertical input axis
/// </summary>
public const string Vertical = "Vertical";

/// <summary>
/// Mouse: Position Horizontal Movement<para/>
/// HTC Vive Controller: Left Controller Trackpad (2) Horizontal Movement<para/>
Expand Down Expand Up @@ -253,6 +277,7 @@ public static Texture2D GetControllerTexture(BaseMixedRealityControllerMappingPr
/// <summary>
/// Gets a scaled texture for the <see cref="SupportedControllerType"/> based on a list of the active <see cref="MixedRealityControllerMappingProfiles"/>.
/// </summary>
/// <param name="mappingProfile"></param>
/// <param name="controllerType"></param>
/// <param name="handedness"></param>
/// <returns>The scaled texture for the controller type, if none found then a generic texture is returned.</returns>
Expand Down
1 change: 0 additions & 1 deletion EventDatum/Input/GraphicInputEventData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ public void Clear()
pressPosition = Vector2.zero;
rawPointerPress = null;
scrollDelta = Vector2.zero;
selectedObject = null;
useDragThreshold = false;
}
}
Expand Down
24 changes: 24 additions & 0 deletions Extensions/GameObjectExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -206,5 +206,29 @@ public static GameObject FindCommonRoot(this GameObject g1, GameObject g2)

return null;
}

/// <summary>
/// Checks if the provided GameObjects are child/parent related.
/// </summary>
/// <param name="g1"></param>
/// <param name="g2"></param>
/// <returns>True if either GameObject is the parent of the other or if they are the same</returns>
public static bool IsParentOrChildOf(this GameObject g1, GameObject g2)
{
if (g1 == null || g2 == null)
{
return false;
}

var t1 = g1.transform;
var t2 = g2.transform;

if (t1 == null || t2 == null)
{
return false;
}

return t1.IsParentOrChildOf(t2);
}
}
}
38 changes: 31 additions & 7 deletions Extensions/TransformExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,11 @@ private static IEnumerable<Transform> EnumerateHierarchyCore(this Transform root
/// If no colliders attached, returns a bounds of center and extents 0</returns>
public static Bounds GetColliderBounds(this Transform transform)
{
Collider[] colliders = transform.GetComponentsInChildren<Collider>();
var colliders = transform.GetComponentsInChildren<Collider>();

if (colliders.Length == 0) { return new Bounds(); }
if (colliders.Length == 0) { return default; }

Bounds bounds = colliders[0].bounds;
var bounds = colliders[0].bounds;

for (int i = 1; i < colliders.Length; i++)
{
Expand Down Expand Up @@ -132,7 +132,7 @@ public static bool IsParentOrChildOf(this Transform transform1, Transform transf
/// <returns>The component of type <typeparamref name="T"/>. Null if it none was found.</returns>
public static T FindAncestorComponent<T>(this Transform startTransform, bool includeSelf = true) where T : Component
{
foreach (Transform transform in startTransform.EnumerateAncestors(includeSelf))
foreach (var transform in startTransform.EnumerateAncestors(includeSelf))
{
T component = transform.GetComponent<T>();

Expand All @@ -158,7 +158,7 @@ public static IEnumerable<Transform> EnumerateAncestors(this Transform startTran
startTransform = startTransform.parent;
}

for (Transform transform = startTransform; transform != null; transform = transform.parent)
for (var transform = startTransform; transform != null; transform = transform.parent)
{
yield return transform;
}
Expand Down Expand Up @@ -256,6 +256,24 @@ public static bool TryGetDepth(Transform target, Transform parent, ref int depth
return false;
}

/// <summary>
/// Get a point on the <see cref="Bounds"/> edge in the specified direction
/// </summary>
/// <param name="transform"></param>
/// <param name="direction"></param>
/// <returns></returns>
public static Vector3 GetPointOnBoundsEdge(this Transform transform, Vector3 direction)
{
if (direction != Vector3.zero)
{
direction /= Mathf.Max(Mathf.Max(Mathf.Abs(direction.x), Mathf.Abs(direction.y), Mathf.Abs(direction.y)));
}

var bounds = transform.GetColliderBounds();
direction = bounds.center + Vector3.Scale(bounds.size, direction * 0.5f);
return direction;
}

/// <summary>
/// Given 2 Transforms, return a common root Transform (or null).
/// </summary>
Expand All @@ -268,6 +286,8 @@ public static Transform FindCommonRoot(this Transform t1, Transform t2)
return null;
}

var t2root = t2;

while (t1 != null)
{
while (t2 != null)
Expand All @@ -278,9 +298,13 @@ public static Transform FindCommonRoot(this Transform t1, Transform t2)
}

t2 = t2.parent;
}

t1 = t1.parent;
if (t2 == null)
{
t1 = t1.parent;
t2 = t2root;
}
}
}

return null;
Expand Down
23 changes: 22 additions & 1 deletion Extensions/VectorExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEngine.EventSystems;

namespace XRTK.Extensions
{
Expand Down Expand Up @@ -234,12 +235,32 @@ public static Vector3 RadialMapping(Vector3 source, float radialRange, float rad
/// <param name="source">The source <see cref="Vector3"/> to be mapped to cylinder</param>
/// <param name="radius">This is a <see cref="float"/> for the radius of the cylinder</param>
/// <returns></returns>
public static Vector3 ScatterMapping(Vector3 source, float radius)
public static Vector3 ScatterMapping(this Vector3 source, float radius)
{
source.x = UnityEngine.Random.Range(-radius, radius);
source.y = UnityEngine.Random.Range(-radius, radius);
return source;
}

/// <summary>
/// Determine the move direction based off of the direction provided
/// </summary>
/// <param name="direction"></param>
/// <param name="deadZone"></param>
/// <returns></returns>
public static MoveDirection DetermineMoveDirection(this Vector2 direction, float deadZone = 0.6f)
{
if (direction.sqrMagnitude < deadZone * deadZone)
{
return MoveDirection.None;
}

if (Mathf.Abs(direction.x) > Mathf.Abs(direction.y))
{
return direction.x > 0 ? MoveDirection.Right : MoveDirection.Left;
}

return direction.y > 0 ? MoveDirection.Up : MoveDirection.Down;
}
}
}
Loading

0 comments on commit 840524d

Please sign in to comment.