Skip to content

Commit

Permalink
chore(SDK): remove interface and impose contract with abstract class
Browse files Browse the repository at this point in the history
  > ** Breaking Changes **

The SDK interfaces have now been removed and the Base classes are now
responsible for enforcing the concrete SDK implemented methods.

All public SDK methods are now abstract in the Base class to ensure
they have to be implemented by any concrete SDK.

The Base classes may also contain protected methods to share common
logic to any concrete implementation but this change now means it
is easier to know which methods need to be implemented when writing
an SDK.

Some of the public enums have been moved into the Base SDK classes
as they make more sense to have them located within the SDK and as
such any references to these enums has been updated to point to the
SDK abstract class.
  • Loading branch information
thestonefox committed Dec 22, 2016
1 parent b49ea92 commit 2b511ac
Show file tree
Hide file tree
Showing 26 changed files with 408 additions and 397 deletions.
4 changes: 2 additions & 2 deletions Assets/VRTK/Editor/VRTK_SDKManagerEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,14 +141,14 @@ private void AutoPopulate(VRTK_SDKManager sdkManager)

if (controllerSDK && (!sdkManager.modelAliasLeftController || !previousControllerSDK || controllerSDK.GetType() != previousControllerSDK.GetType()))
{
var controllerLeft = controllerSDK.GetControllerModel(VRTK_DeviceFinder.ControllerHand.Left);
var controllerLeft = controllerSDK.GetControllerModel(SDK_BaseController.ControllerHand.Left);
sdkManager.modelAliasLeftController = (controllerLeft ? controllerLeft : null);
setPreviousControllerSDK = true;
}

if (controllerSDK && (!sdkManager.modelAliasRightController || !previousControllerSDK || controllerSDK.GetType() != previousControllerSDK.GetType()))
{
var controllerRight = controllerSDK.GetControllerModel(VRTK_DeviceFinder.ControllerHand.Right);
var controllerRight = controllerSDK.GetControllerModel(SDK_BaseController.ControllerHand.Right);
sdkManager.modelAliasRightController = (controllerRight ? controllerRight : null);
setPreviousControllerSDK = true;
}
Expand Down
4 changes: 2 additions & 2 deletions Assets/VRTK/Examples/Resources/Scripts/RealGun.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,14 @@ public override void Grabbed(GameObject currentGrabbingObject)
ToggleSafetySwitch(true);

//Limit hands grabbing when picked up
if (VRTK_DeviceFinder.GetControllerHand(currentGrabbingObject) == VRTK_DeviceFinder.ControllerHand.Left)
if (VRTK_DeviceFinder.GetControllerHand(currentGrabbingObject) == SDK_BaseController.ControllerHand.Left)
{
allowedTouchControllers = AllowedController.Left_Only;
allowedUseControllers = AllowedController.Left_Only;
slide.allowedGrabControllers = AllowedController.Right_Only;
safetySwitch.allowedGrabControllers = AllowedController.Right_Only;
}
else if (VRTK_DeviceFinder.GetControllerHand(currentGrabbingObject) == VRTK_DeviceFinder.ControllerHand.Right)
else if (VRTK_DeviceFinder.GetControllerHand(currentGrabbingObject) == SDK_BaseController.ControllerHand.Right)
{
allowedTouchControllers = AllowedController.Right_Only;
allowedUseControllers = AllowedController.Right_Only;
Expand Down
10 changes: 5 additions & 5 deletions Assets/VRTK/Prefabs/Resources/Scripts/VRTK_ControllerTooltips.cs
Original file line number Diff line number Diff line change
Expand Up @@ -222,31 +222,31 @@ private void InitialiseTips()
{
case "trigger":
tipText = triggerText;
tipTransform = GetTransform(trigger, VRTK_ControllerElements.Trigger);
tipTransform = GetTransform(trigger, SDK_BaseController.ControllerElements.Trigger);
if (tipTransform != null)
{
triggerInitialised = true;
}
break;
case "grip":
tipText = gripText;
tipTransform = GetTransform(grip, VRTK_ControllerElements.GripLeft);
tipTransform = GetTransform(grip, SDK_BaseController.ControllerElements.GripLeft);
if (tipTransform != null)
{
gripInitialised = true;
}
break;
case "touchpad":
tipText = touchpadText;
tipTransform = GetTransform(touchpad, VRTK_ControllerElements.Touchpad);
tipTransform = GetTransform(touchpad, SDK_BaseController.ControllerElements.Touchpad);
if (tipTransform != null)
{
touchpadInitialised = true;
}
break;
case "buttonone":
tipText = buttonOneText;
tipTransform = GetTransform(buttonOne, VRTK_ControllerElements.ButtonOne);
tipTransform = GetTransform(buttonOne, SDK_BaseController.ControllerElements.ButtonOne);
if (tipTransform != null)
{
buttonOneInitialised = true;
Expand Down Expand Up @@ -275,7 +275,7 @@ private bool TipsInitialised()
return (triggerInitialised && gripInitialised && touchpadInitialised && buttonOneInitialised);
}

private Transform GetTransform(Transform setTransform, VRTK_ControllerElements findElement)
private Transform GetTransform(Transform setTransform, SDK_BaseController.ControllerElements findElement)
{
Transform returnTransform = null;
if (setTransform)
Expand Down
24 changes: 13 additions & 11 deletions Assets/VRTK/SDK/Base/SDK_BaseBoundaries.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,15 @@ namespace VRTK
/// <remarks>
/// This is an abstract class to implement the interface required by all implemented SDKs.
/// </remarks>
public abstract class SDK_BaseBoundaries : ScriptableObject, SDK_InterfaceBoundaries
public abstract class SDK_BaseBoundaries : ScriptableObject
{
protected Transform cachedPlayArea;

/// <summary>
/// The GetPlayArea method returns the Transform of the object that is used to represent the play area in the scene.
/// </summary>
/// <returns>A transform of the object representing the play area in the scene.</returns>
public virtual Transform GetPlayArea()
{
var sdkManager = VRTK_SDKManager.instance;
if (sdkManager != null)
{
cachedPlayArea = sdkManager.actualBoundaries.transform;
return cachedPlayArea;
}
return null;
}
public abstract Transform GetPlayArea();

/// <summary>
/// The GetPlayAreaVertices method returns the points of the play area boundaries.
Expand All @@ -48,5 +39,16 @@ public virtual Transform GetPlayArea()
/// <param name="playArea">The GameObject containing the play area representation.</param>
/// <returns>Returns true if the play area size has been auto calibrated and set by external sensors.</returns>
public abstract bool IsPlayAreaSizeCalibrated(GameObject playArea);

protected Transform GetSDKManagerPlayArea()
{
var sdkManager = VRTK_SDKManager.instance;
if (sdkManager != null)
{
cachedPlayArea = sdkManager.actualBoundaries.transform;
return cachedPlayArea;
}
return null;
}
}
}
191 changes: 126 additions & 65 deletions Assets/VRTK/SDK/Base/SDK_BaseController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,17 @@ namespace VRTK
/// <remarks>
/// This is an abstract class to implement the interface required by all implemented SDKs.
/// </remarks>
public abstract class SDK_BaseController : ScriptableObject, SDK_InterfaceController
public abstract class SDK_BaseController : ScriptableObject
{
/// <summary>
/// Concepts of controller button press
/// </summary>
/// <param name="Press">The button is currently being pressed.</param>
/// <param name="PressDown">The button has just been pressed down.</param>
/// <param name="PressUp">The button has just been released.</param>
/// <param name="Touch">The button is currently being touched.</param>
/// <param name="TouchDown">The button has just been touched.</param>
/// <param name="TouchUp">The button is no longer being touched.</param>
public enum ButtonPressTypes
{
Press,
Expand All @@ -21,6 +30,42 @@ public enum ButtonPressTypes
TouchUp
}

/// <summary>
/// The elements of a generic controller
/// </summary>
/// <param name="AttachPoint">The default point on the controller to attach grabbed objects to.</param>
/// <param name="Trigger">The trigger button.</param>
/// <param name="GripLeft">The left part of the grip button collection.</param>
/// <param name="GripRight">The right part of the grip button collection.</param>
/// <param name="Touchpad">The touch pad/stick.</param>
/// <param name="ButtonOne">The first generic button.</param>
/// <param name="SystemMenu">The system menu button.</param>
/// <param name="Body">The encompassing mesh of the controller body.</param>
public enum ControllerElements
{
AttachPoint,
Trigger,
GripLeft,
GripRight,
Touchpad,
ButtonOne,
SystemMenu,
Body
}

/// <summary>
/// Controller hand reference.
/// </summary>
/// <param name="None">No hand is assigned.</param>
/// <param name="Left">The left hand is assigned.</param>
/// <param name="Right">The right hand is assigned.</param>
public enum ControllerHand
{
None,
Left,
Right
}

/// <summary>
/// The GetControllerDefaultColliderPath returns the path to the prefab that contains the collider objects for the default controller of this SDK.
/// </summary>
Expand All @@ -34,7 +79,7 @@ public enum ButtonPressTypes
/// <param name="hand">The controller hand to look up.</param>
/// <param name="fullPath">Whether to get the initial path or the full path to the element.</param>
/// <returns>A string containing the path to the game object that the controller element resides in.</returns>
public abstract string GetControllerElementPath(VRTK_ControllerElements element, VRTK_DeviceFinder.ControllerHand hand, bool fullPath = false);
public abstract string GetControllerElementPath(ControllerElements element, ControllerHand hand, bool fullPath = false);

/// <summary>
/// The GetControllerIndex method returns the index of the given controller.
Expand Down Expand Up @@ -63,114 +108,59 @@ public enum ButtonPressTypes
/// </summary>
/// <param name="actual">If true it will return the actual controller, if false it will return the script alias controller GameObject.</param>
/// <returns>The GameObject containing the left hand controller.</returns>
public virtual GameObject GetControllerLeftHand(bool actual = false)
{
var sdkManager = VRTK_SDKManager.instance;
if (sdkManager != null)
{
return (actual ? sdkManager.actualLeftController : sdkManager.scriptAliasLeftController);
}
return null;
}
public abstract GameObject GetControllerLeftHand(bool actual = false);

/// <summary>
/// The GetControllerRightHand method returns the GameObject containing the representation of the right hand controller.
/// </summary>
/// <param name="actual">If true it will return the actual controller, if false it will return the script alias controller GameObject.</param>
/// <returns>The GameObject containing the right hand controller.</returns>
public virtual GameObject GetControllerRightHand(bool actual = false)
{
var sdkManager = VRTK_SDKManager.instance;
if (sdkManager != null)
{
return (actual ? sdkManager.actualRightController : sdkManager.scriptAliasRightController);
}
return null;
}
public abstract GameObject GetControllerRightHand(bool actual = false);

/// <summary>
/// The IsControllerLeftHand/1 method is used to check if the given controller is the the left hand controller.
/// </summary>
/// <param name="controller">The GameObject to check.</param>
/// <returns>Returns true if the given controller is the left hand controller.</returns>
public virtual bool IsControllerLeftHand(GameObject controller)
{
return (IsControllerLeftHand(controller, true) || IsControllerLeftHand(controller, false));
}
public abstract bool IsControllerLeftHand(GameObject controller);

/// <summary>
/// The IsControllerRightHand/1 method is used to check if the given controller is the the right hand controller.
/// </summary>
/// <param name="controller">The GameObject to check.</param>
/// <returns>Returns true if the given controller is the right hand controller.</returns>
public virtual bool IsControllerRightHand(GameObject controller)
{
return (IsControllerRightHand(controller, true) || IsControllerRightHand(controller, false));
}
public abstract bool IsControllerRightHand(GameObject controller);

/// <summary>
/// The IsControllerLeftHand/2 method is used to check if the given controller is the the left hand controller.
/// </summary>
/// <param name="controller">The GameObject to check.</param>
/// <param name="actual">If true it will check the actual controller, if false it will check the script alias controller.</param>
/// <returns>Returns true if the given controller is the left hand controller.</returns>
public virtual bool IsControllerLeftHand(GameObject controller, bool actual)
{
var sdkManager = VRTK_SDKManager.instance;
if (sdkManager != null)
{
return (actual ? controller.Equals(sdkManager.actualLeftController) : controller.Equals(sdkManager.scriptAliasLeftController));
}
return false;
}
public abstract bool IsControllerLeftHand(GameObject controller, bool actual);

/// <summary>
/// The IsControllerRightHand/2 method is used to check if the given controller is the the right hand controller.
/// </summary>
/// <param name="controller">The GameObject to check.</param>
/// <param name="actual">If true it will check the actual controller, if false it will check the script alias controller.</param>
/// <returns>Returns true if the given controller is the right hand controller.</returns>
public virtual bool IsControllerRightHand(GameObject controller, bool actual)
{
var sdkManager = VRTK_SDKManager.instance;
if (sdkManager != null)
{
return (actual ? controller.Equals(sdkManager.actualRightController) : controller.Equals(sdkManager.scriptAliasRightController));
}
return false;
}
public abstract bool IsControllerRightHand(GameObject controller, bool actual);

/// <summary>
/// The GetControllerModel method returns the model alias for the given GameObject.
/// </summary>
/// <param name="controller">The GameObject to get the model alias for.</param>
/// <returns>The GameObject that has the model alias within it.</returns>
public virtual GameObject GetControllerModel(GameObject controller)
{
return GetControllerModel(VRTK_DeviceFinder.GetControllerHand(controller));
}
public abstract GameObject GetControllerModel(GameObject controller);


/// <summary>
/// The GetControllerModel method returns the model alias for the given controller hand.
/// </summary>
/// <param name="hand">The hand enum of which controller model to retrieve.</param>
/// <returns>The GameObject that has the model alias within it.</returns>
public virtual GameObject GetControllerModel(VRTK_DeviceFinder.ControllerHand hand)
{
var sdkManager = VRTK_SDKManager.instance;
if (sdkManager != null)
{
switch (hand)
{
case VRTK_DeviceFinder.ControllerHand.Left:
return sdkManager.modelAliasLeftController;
case VRTK_DeviceFinder.ControllerHand.Right:
return sdkManager.modelAliasRightController;
}
}
return null;
}
public abstract GameObject GetControllerModel(ControllerHand hand);

/// <summary>
/// The GetControllerRenderModel method gets the game object that contains the given controller's render model.
Expand Down Expand Up @@ -437,5 +427,76 @@ public virtual GameObject GetControllerModel(VRTK_DeviceFinder.ControllerHand ha
/// <param name="index">The index of the tracked object to check for.</param>
/// <returns>Returns true if the button has just been released.</returns>
public abstract bool IsButtonOneTouchedUpOnIndex(uint index);

protected GameObject GetSDKManagerControllerLeftHand(bool actual = false)
{
var sdkManager = VRTK_SDKManager.instance;
if (sdkManager != null)
{
return (actual ? sdkManager.actualLeftController : sdkManager.scriptAliasLeftController);
}
return null;
}

protected GameObject GetSDKManagerControllerRightHand(bool actual = false)
{
var sdkManager = VRTK_SDKManager.instance;
if (sdkManager != null)
{
return (actual ? sdkManager.actualRightController : sdkManager.scriptAliasRightController);
}
return null;
}

protected bool CheckActualOrScriptAliasControllerIsLeftHand(GameObject controller)
{
return (IsControllerLeftHand(controller, true) || IsControllerLeftHand(controller, false));
}

protected bool CheckActualOrScriptAliasControllerIsRightHand(GameObject controller)
{
return (IsControllerRightHand(controller, true) || IsControllerRightHand(controller, false));
}

protected bool CheckControllerLeftHand(GameObject controller, bool actual)
{
var sdkManager = VRTK_SDKManager.instance;
if (sdkManager != null)
{
return (actual ? controller.Equals(sdkManager.actualLeftController) : controller.Equals(sdkManager.scriptAliasLeftController));
}
return false;
}

protected bool CheckControllerRightHand(GameObject controller, bool actual)
{
var sdkManager = VRTK_SDKManager.instance;
if (sdkManager != null)
{
return (actual ? controller.Equals(sdkManager.actualRightController) : controller.Equals(sdkManager.scriptAliasRightController));
}
return false;
}

protected GameObject GetControllerModelFromController(GameObject controller)
{
return GetControllerModel(VRTK_DeviceFinder.GetControllerHand(controller));
}

protected GameObject GetSDKManagerControllerModelForHand(ControllerHand hand)
{
var sdkManager = VRTK_SDKManager.instance;
if (sdkManager != null)
{
switch (hand)
{
case ControllerHand.Left:
return sdkManager.modelAliasLeftController;
case ControllerHand.Right:
return sdkManager.modelAliasRightController;
}
}
return null;
}
}
}
Loading

0 comments on commit 2b511ac

Please sign in to comment.