VR Development Framework
v 1.0.0
 All Classes Namespaces Functions Variables Enumerations Enumerator Properties Events Pages
AVR_Controller.cs
1 using System.Collections;
2 using System.Collections.Generic;
3 using UnityEngine;
4 using UnityEngine.XR;
5 
6 namespace AVR.Core {
7  /// <summary>
8  /// Represents a VR controller. Provides functionality for spacial tracking and haptic feedback.
9  /// Can also be used to represent hardware trackers, game controllers or other references.
10  /// </summary>
11  [AVR.Core.Attributes.DocumentationUrl("class_a_v_r_1_1_core_1_1_a_v_r___controller.html")]
13  {
14  /// <summary>
15  /// Returns the AVR_Controller that represents the left hand controller (if it exists). This value depends on the controllerNode value and is not updated if this one is changed during runtime.
16  /// </summary>
17  public static AVR_Controller leftHandController { get; private set; }
18 
19  /// <summary>
20  /// Returns the AVR_Controller that represents the right hand controller (if it exists). This value depends on the controllerNode value and is not updated if this one is changed during runtime.
21  /// </summary>
22  public static AVR_Controller rightHandController { get; private set; }
23 
24  /// <summary>
25  /// the AVR_ControllerInputManager assigned to this controller. Returns null if no inputmanager is assigned
26  /// </summary>
27  public AVR_ControllerInputManager inputManager {
28  get {
29  return _inputManager;
30  }
31  }
32  private AVR_ControllerInputManager _inputManager=null;
33 
34  protected override void Awake() {
35  base.Awake();
36  _inputManager = GetComponentInChildren<AVR_ControllerInputManager>();
37 
38  if (controllerNode==XRNode.LeftHand && !leftHandController) leftHandController = this;
39  if (controllerNode == XRNode.RightHand && !rightHandController) rightHandController = this;
40  }
41 
42  /// <summary>
43  /// Returns the haptic capabilites of this controller.
44  /// </summary>
45  public HapticCapabilities GetHapticCapabilities() {
46  if(inputDevice.TryGetHapticCapabilities(out var capabilities)) {
47  return capabilities;
48  }
49  else {
50  AVR_DevConsole.cwarn("Could not retrieve haptic capavilites from controller.", this);
51  return default(HapticCapabilities);
52  }
53  }
54 
55  /// <summary>
56  /// Performs a haptic pulse on this controller (if available)
57  /// <param name="amplitude"> Normalized amplitude of the pulse. Must be in [0, 1] </param>
58  /// <param name="duration"> Duration of the pulse in seconds. </param>
59  /// </summary>
60  public void HapticPulse(float amplitude, float duration) {
61  if (GetHapticCapabilities().supportsImpulse)
62  {
63  inputDevice.SendHapticImpulse(0u, amplitude, duration);
64  }
65  }
66  }
67 }
Represents a VR controller. Provides functionality for spacial tracking and haptic feedback...
Manages inputs of a controller such as button presses and track-pad inputs.
Sets the documentation html file inside of Packages/com.avr.core/Documentation/html of a given class...
HapticCapabilities GetHapticCapabilities()
Returns the haptic capabilites of this controller.
void HapticPulse(float amplitude, float duration)
Performs a haptic pulse on this controller (if available) Normalized amplitude of the pulse...
override void Awake()
Represents some spatially tracked XR device. Provides functionality for spacial tracking. Can be used to represent hardware trackers, game controllers or other references.