NEW HVR 2.9.1f
This commit is contained in:
@@ -5,6 +5,10 @@ using UnityEngine.Events;
|
||||
|
||||
namespace HurricaneVR.Framework.Components
|
||||
{
|
||||
/// <summary>
|
||||
/// Basic button check for travel along a defined axis, requires the user to have setup their own constraint system.
|
||||
/// Superceded by the new HVRPhysicsButton component which helps create joints and limits for you
|
||||
/// </summary>
|
||||
[RequireComponent(typeof(Rigidbody))]
|
||||
public class HVRButton : MonoBehaviour
|
||||
{
|
||||
@@ -38,11 +42,6 @@ namespace HurricaneVR.Framework.Components
|
||||
Rigidbody = GetComponent<Rigidbody>();
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void FixedUpdate()
|
||||
{
|
||||
var distance = (StartPosition - transform.localPosition).magnitude;
|
||||
|
||||
@@ -2,18 +2,12 @@
|
||||
|
||||
namespace HurricaneVR.Framework.Components
|
||||
{
|
||||
/// <summary>
|
||||
/// Tags a grabbable object as climbable which is then used by the player controller to know if they can climb or not.
|
||||
/// For the hexabody integration it will kick in the climbing strength override set on the HexaHands component.
|
||||
/// </summary>
|
||||
public class HVRClimbable : MonoBehaviour
|
||||
{
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,9 @@ using UnityEngine.Events;
|
||||
|
||||
namespace HurricaneVR.Framework.Components
|
||||
{
|
||||
/// <summary>
|
||||
/// Helper component used to propogate a collision if a force or velocity threshold was met.
|
||||
/// </summary>
|
||||
public class HVRCollisionEvents : MonoBehaviour
|
||||
{
|
||||
[Header("Settings")]
|
||||
|
||||
+16
-8
@@ -5,6 +5,10 @@ using UnityEngine;
|
||||
|
||||
namespace HurricaneVR.Framework.Components
|
||||
{
|
||||
/// <summary>
|
||||
/// Handles offsettings the physics hand target based on the connected device. Also offsets the target based on grab point settings if desired.
|
||||
/// To manage custom offsets please use the SetMiscPositionOffset(Vector3 position, Vector3 rotation) and ResetGrabPointOffsets() functions.
|
||||
/// </summary>
|
||||
public class HVRControllerOffset : MonoBehaviour
|
||||
{
|
||||
/// <summary>
|
||||
@@ -30,16 +34,20 @@ namespace HurricaneVR.Framework.Components
|
||||
public Vector3 ControllerRotationOffset => _offsets != null ? _offsets.Rotation : Vector3.zero;
|
||||
|
||||
[Header("Debugging")]
|
||||
public Vector3 TargetGrabPointPositionOffset;
|
||||
public Vector3 TargetGrabPointRotationOffset;
|
||||
|
||||
public Vector3 GrabPointPositionOffset;
|
||||
public Vector3 GrabPointRotationOffset;
|
||||
|
||||
public Vector3 MiscPositionOffset;
|
||||
public Vector3 MiscRotationOffset;
|
||||
|
||||
[Tooltip("Enable to test live updating of the Misc offset fields.")]
|
||||
public bool LiveUpdateOffsets;
|
||||
|
||||
[SerializeField] private Vector3 TargetGrabPointPositionOffset;
|
||||
[SerializeField] private Vector3 TargetGrabPointRotationOffset;
|
||||
|
||||
[SerializeField] private Vector3 GrabPointPositionOffset;
|
||||
[SerializeField] private Vector3 GrabPointRotationOffset;
|
||||
|
||||
[SerializeField] private Vector3 MiscPositionOffset;
|
||||
[SerializeField] private Vector3 MiscRotationOffset;
|
||||
|
||||
|
||||
private Quaternion _teleportStartRotation;
|
||||
|
||||
public bool _updatingRotation;
|
||||
|
||||
+18
-2
@@ -15,10 +15,13 @@ namespace HurricaneVR.Framework.Components
|
||||
{
|
||||
[Header("Unity XR")]
|
||||
public HVRDevicePoseOffset Oculus;
|
||||
|
||||
public HVRDevicePoseOffset WMR;
|
||||
public HVRDevicePoseOffset Pico;
|
||||
|
||||
[Header("SteamVR")]
|
||||
public HVRDevicePoseOffset OculusSteamVR;
|
||||
|
||||
public HVRDevicePoseOffset WMRSteamVR;
|
||||
public HVRDevicePoseOffset ReverbG2SteamVR;
|
||||
public HVRDevicePoseOffset CosmosSteamVR;
|
||||
@@ -27,11 +30,13 @@ namespace HurricaneVR.Framework.Components
|
||||
|
||||
[Header("OpenXR")]
|
||||
public HVRDevicePoseOffset OculusOpenXR;
|
||||
|
||||
public HVRDevicePoseOffset WMROpenXR;
|
||||
public HVRDevicePoseOffset ReverbG2OpenXR;
|
||||
public HVRDevicePoseOffset ViveOpenXR;
|
||||
public HVRDevicePoseOffset CosmosOpenXR;
|
||||
public HVRDevicePoseOffset KnucklesOpenXR;
|
||||
public HVRDevicePoseOffset PicoOpenXR;
|
||||
|
||||
public HVRDevicePoseOffset GetDeviceOffset(HVRHandSide side)
|
||||
{
|
||||
@@ -47,7 +52,6 @@ namespace HurricaneVR.Framework.Components
|
||||
|
||||
switch (type)
|
||||
{
|
||||
|
||||
case HVRControllerType.Oculus:
|
||||
if (steamVR)
|
||||
{
|
||||
@@ -83,6 +87,7 @@ namespace HurricaneVR.Framework.Components
|
||||
{
|
||||
return ViveOpenXR;
|
||||
}
|
||||
|
||||
break;
|
||||
case HVRControllerType.Knuckles:
|
||||
if (steamVR)
|
||||
@@ -93,6 +98,7 @@ namespace HurricaneVR.Framework.Components
|
||||
{
|
||||
return KnucklesOpenXR;
|
||||
}
|
||||
|
||||
break;
|
||||
case HVRControllerType.Cosmos:
|
||||
if (steamVR)
|
||||
@@ -103,6 +109,7 @@ namespace HurricaneVR.Framework.Components
|
||||
{
|
||||
return CosmosOpenXR;
|
||||
}
|
||||
|
||||
break;
|
||||
case HVRControllerType.ReverbG2:
|
||||
if (steamVR)
|
||||
@@ -113,7 +120,14 @@ namespace HurricaneVR.Framework.Components
|
||||
{
|
||||
return ReverbG2OpenXR;
|
||||
}
|
||||
|
||||
break;
|
||||
case HVRControllerType.Pico:
|
||||
if (steamVR) //is there a way to detect pico when using steamvr? it's emulated as a oculus device
|
||||
return null;
|
||||
if (openXr)
|
||||
return PicoOpenXR;
|
||||
return Pico;
|
||||
}
|
||||
|
||||
return null;
|
||||
@@ -124,7 +138,9 @@ namespace HurricaneVR.Framework.Components
|
||||
public class HVRDevicePoseOffset
|
||||
{
|
||||
public Vector3 Position;
|
||||
[FormerlySerializedAs("_rotation")] [SerializeField]
|
||||
|
||||
[FormerlySerializedAs("_rotation")]
|
||||
[SerializeField]
|
||||
public Vector3 Rotation;
|
||||
}
|
||||
}
|
||||
@@ -13,8 +13,6 @@ namespace HurricaneVR.Framework.Components
|
||||
|
||||
public HVRDestructible Desctructible;
|
||||
|
||||
|
||||
|
||||
void Start()
|
||||
{
|
||||
Rigidbody = GetComponent<Rigidbody>();
|
||||
|
||||
@@ -4,6 +4,9 @@ using UnityEngine.Events;
|
||||
|
||||
namespace HurricaneVR.Framework.Components
|
||||
{
|
||||
/// <summary>
|
||||
/// Publishes the destroyed event so others may know, used by the hand grabber to know if the held object is destroyed
|
||||
/// </summary>
|
||||
public class HVRDestroyListener : MonoBehaviour
|
||||
{
|
||||
public HVRDestroyedEvent Destroyed = new HVRDestroyedEvent();
|
||||
|
||||
@@ -3,6 +3,9 @@ using UnityEngine;
|
||||
|
||||
namespace HurricaneVR.Framework.Components
|
||||
{
|
||||
/// <summary>
|
||||
/// Destroys this game object after a timeout
|
||||
/// </summary>
|
||||
public class HVRDestroyTimer : MonoBehaviour
|
||||
{
|
||||
public void StartTimer(float timeout)
|
||||
|
||||
@@ -3,6 +3,11 @@ using UnityEngine;
|
||||
|
||||
namespace HurricaneVR.Framework.Components
|
||||
{
|
||||
/// <summary>
|
||||
/// Helper component that spawns a prefab game object when the Destroy function is called.
|
||||
/// If the spawned game object has a rigidbodies then they will have force added to them based on the
|
||||
/// fields provided.
|
||||
/// </summary>
|
||||
public class HVRDestructible : MonoBehaviour
|
||||
{
|
||||
public GameObject DestroyedVersion;
|
||||
@@ -17,8 +22,12 @@ namespace HurricaneVR.Framework.Components
|
||||
|
||||
public bool IgnorePlayerCollision = true;
|
||||
|
||||
public bool Destroyed { get; protected set; }
|
||||
|
||||
public virtual void Destroy()
|
||||
{
|
||||
if (Destroyed) return;
|
||||
|
||||
if (DestroyedVersion)
|
||||
{
|
||||
var destroyed = Instantiate(DestroyedVersion, transform.position, transform.rotation);
|
||||
@@ -59,6 +68,7 @@ namespace HurricaneVR.Framework.Components
|
||||
}
|
||||
}
|
||||
|
||||
Destroyed = true;
|
||||
Destroy(gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,9 @@ using UnityEngine;
|
||||
|
||||
namespace HurricaneVR.Framework.Components
|
||||
{
|
||||
/// <summary>
|
||||
/// Deprecated and left in for older projects. Superceded by HVRPhysicsDial and HVRRotationTracker
|
||||
/// </summary>
|
||||
[RequireComponent(typeof(HVRGrabbable))]
|
||||
public class HVRDial : MonoBehaviour
|
||||
{
|
||||
|
||||
+25
-1
@@ -1,18 +1,42 @@
|
||||
using HurricaneVR.Framework.Core.Grabbers;
|
||||
using HurricaneVR.Framework.Core.Player;
|
||||
using UnityEngine;
|
||||
|
||||
namespace HurricaneVR.Framework.Components
|
||||
{
|
||||
|
||||
public class HVRHandImpactHaptics : HVRImpactHapticsBase
|
||||
{
|
||||
public HVRHandGrabber Hand;
|
||||
|
||||
[Tooltip("If true and the hand is holding something, haptics will not play.")]
|
||||
public bool HandGrabbingPrevents = true;
|
||||
|
||||
[Tooltip("If true the max force for the haptic amplitude calc will use the hand's default max force.")]
|
||||
public bool UseHandMaxStrength = true;
|
||||
|
||||
private HVRJointHand _hand;
|
||||
|
||||
public override float MaxForce
|
||||
{
|
||||
get
|
||||
{
|
||||
if (UseHandMaxStrength)
|
||||
{
|
||||
if ( _hand && _hand.JointSettings)
|
||||
return _hand.JointSettings.XDrive.MaxForce;
|
||||
}
|
||||
|
||||
return base.MaxForce;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void Awake()
|
||||
{
|
||||
base.Awake();
|
||||
|
||||
if (!Hand) TryGetComponent(out Hand);
|
||||
|
||||
TryGetComponent(out _hand);
|
||||
}
|
||||
|
||||
protected override void Vibrate(float duration, float amplitude, float frequency)
|
||||
|
||||
+4
-4
@@ -46,10 +46,10 @@ namespace HurricaneVR.Framework.Components
|
||||
{
|
||||
Folder = DateTime.Now.ToString("yyyyMMdd_HH_mm");
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
void Update()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
|
||||
|
||||
if (DisablePhysics && !_previousDisable)
|
||||
{
|
||||
@@ -79,9 +79,9 @@ namespace HurricaneVR.Framework.Components
|
||||
_previousDisable = DisablePhysics;
|
||||
|
||||
CheckSnapshot();
|
||||
#endif
|
||||
}
|
||||
|
||||
}
|
||||
#endif
|
||||
private void CheckSnapshot()
|
||||
{
|
||||
HVRPosableHand hand = null;
|
||||
|
||||
@@ -12,10 +12,19 @@ namespace HurricaneVR.Framework.Components
|
||||
public class HVRImpactHaptics : ScriptableObject
|
||||
{
|
||||
public float Timeout = .3f;
|
||||
|
||||
[Tooltip("Collision Velocity Square Magnitude cut off filter")]
|
||||
public float SqrMagThreshold = .30f;
|
||||
public float MaxForce = 600f;
|
||||
|
||||
[Tooltip("Collision force divided by this and fed into the AmpCurve. ")]
|
||||
public float MaxForce = 300f;
|
||||
|
||||
public AnimationCurve AmpCurve;
|
||||
|
||||
[Tooltip("Duration fed into haptics API.")]
|
||||
public float Duration = .25f;
|
||||
|
||||
[Tooltip("Frequency fed into haptics API")]
|
||||
public float Frequency = 150f;
|
||||
|
||||
public void Reset()
|
||||
|
||||
+3
-1
@@ -16,6 +16,8 @@ namespace HurricaneVR.Framework.Components
|
||||
private float _lastHaptic;
|
||||
private Rigidbody Rb;
|
||||
|
||||
public virtual float MaxForce => Data.MaxForce;
|
||||
|
||||
protected virtual void Awake()
|
||||
{
|
||||
TryGetComponent(out Rb);
|
||||
@@ -50,7 +52,7 @@ namespace HurricaneVR.Framework.Components
|
||||
|
||||
Force = impulse / Time.fixedDeltaTime;
|
||||
|
||||
var amp = Data.AmpCurve.Evaluate(Force / Data.MaxForce);
|
||||
var amp = Data.AmpCurve.Evaluate(Force / MaxForce);
|
||||
|
||||
Vibrate(Data.Duration, amp, Data.Frequency);
|
||||
|
||||
|
||||
@@ -6,7 +6,9 @@ using UnityEngine;
|
||||
|
||||
namespace HurricaneVR.Framework.Components
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Depecrecated and left in for older projects, superceded by HVRPhysicsLever and HVRRotationTracker
|
||||
/// </summary>
|
||||
[RequireComponent(typeof(HVRGrabbable))]
|
||||
[RequireComponent(typeof(HingeJoint))]
|
||||
public class HVRLever : MonoBehaviour
|
||||
|
||||
@@ -2,6 +2,9 @@
|
||||
|
||||
namespace HurricaneVR.Framework.Components
|
||||
{
|
||||
/// <summary>
|
||||
/// Helper component to parent this transform to the assigned transform on game start
|
||||
/// </summary>
|
||||
public class HVRParentOnStart : MonoBehaviour
|
||||
{
|
||||
public Transform Parent;
|
||||
|
||||
@@ -7,13 +7,24 @@ using UnityEngine.Events;
|
||||
|
||||
namespace HurricaneVR.Framework.Components
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a joint constrained along one axis with limits based on start and end points defined in the inspector editor.
|
||||
/// </summary>
|
||||
[RequireComponent(typeof(Rigidbody))]
|
||||
public class HVRPhysicsButton : MonoBehaviour
|
||||
{
|
||||
[Header("Settings")]
|
||||
|
||||
[Tooltip("Axis the button will travel on in local space.")]
|
||||
public HVRAxis Axis;
|
||||
|
||||
[Tooltip("Rigidbody this button will connect to with a joint.")]
|
||||
public Rigidbody ConnectedBody;
|
||||
|
||||
[Tooltip("Spring value of the joint")]
|
||||
public float Spring = 1000f;
|
||||
|
||||
[Tooltip("Damper of the joint")]
|
||||
public float Damper = 50f;
|
||||
|
||||
|
||||
|
||||
@@ -8,11 +8,12 @@ using UnityEngine.Serialization;
|
||||
|
||||
namespace HurricaneVR.Framework.Components
|
||||
{
|
||||
/// <summary>
|
||||
/// Simple component to help setup a joint constrained on one axis. With bonus rotation friction option when held.
|
||||
/// </summary>
|
||||
[RequireComponent(typeof(Rigidbody))]
|
||||
public class HVRPhysicsDial : MonoBehaviour
|
||||
{
|
||||
[SerializeField] public HVRGrabbable Grabbable;
|
||||
|
||||
[Header("Settings")]
|
||||
[Tooltip("Local axis of rotation")]
|
||||
public HVRAxis Axis;
|
||||
@@ -23,6 +24,7 @@ namespace HurricaneVR.Framework.Components
|
||||
[Tooltip("If true the angular velocity will be zero'd out on release.")]
|
||||
public bool StopOnRelease = true;
|
||||
|
||||
[Tooltip("Defaults to true to prevent rotation when not held")]
|
||||
public bool DisableGravity = true;
|
||||
|
||||
[Header("Joint Limits")]
|
||||
@@ -41,6 +43,7 @@ namespace HurricaneVR.Framework.Components
|
||||
[Tooltip("Angular Damper when the dial is not grabbed")]
|
||||
public float Damper = 3;
|
||||
|
||||
[Tooltip("Optional spring value of the joint to return to starting rotation if desired")]
|
||||
public float Spring;
|
||||
|
||||
[Header("Editor")]
|
||||
@@ -52,6 +55,8 @@ namespace HurricaneVR.Framework.Components
|
||||
|
||||
public Rigidbody Rigidbody { get; private set; }
|
||||
|
||||
public HVRGrabbable Grabbable { get; private set; }
|
||||
|
||||
public ConfigurableJoint Joint { get; set; }
|
||||
|
||||
protected virtual void Awake()
|
||||
@@ -60,26 +65,14 @@ namespace HurricaneVR.Framework.Components
|
||||
|
||||
Rigidbody.useGravity = !DisableGravity;
|
||||
|
||||
if (!Grabbable) Grabbable = GetComponent<HVRGrabbable>();
|
||||
|
||||
Grabbable = GetComponent<HVRGrabbable>();
|
||||
if (Grabbable)
|
||||
{
|
||||
Grabbable.HandGrabbed.AddListener(OnDialGrabbed);
|
||||
Grabbable.HandReleased.AddListener(OnDialReleased);
|
||||
}
|
||||
|
||||
if (MinAngle > 0)
|
||||
{
|
||||
MinAngle *= -1;
|
||||
}
|
||||
|
||||
if (MaxAngle < 0)
|
||||
{
|
||||
MaxAngle *= -1;
|
||||
}
|
||||
|
||||
MinAngle = Mathf.Clamp(MinAngle, MinAngle, 0);
|
||||
MaxAngle = Mathf.Clamp(MaxAngle, 0, MaxAngle);
|
||||
FixAngle(ref MinAngle, ref MaxAngle);
|
||||
|
||||
SetupJoint();
|
||||
AfterJointCreated(Joint);
|
||||
@@ -95,7 +88,7 @@ namespace HurricaneVR.Framework.Components
|
||||
if (TargetAngularVelocity > 0f || TargetAngularVelocity < 0f) Joint.targetAngularVelocity = new Vector3(TargetAngularVelocity, 0f, 0f);
|
||||
}
|
||||
|
||||
private void OnDialReleased(HVRHandGrabber arg0, HVRGrabbable arg1)
|
||||
protected virtual void OnDialReleased(HVRHandGrabber arg0, HVRGrabbable arg1)
|
||||
{
|
||||
Joint.SetAngularXDrive(Spring, Damper, 10000f);
|
||||
if (StopOnRelease)
|
||||
@@ -104,7 +97,7 @@ namespace HurricaneVR.Framework.Components
|
||||
}
|
||||
}
|
||||
|
||||
private void OnDialGrabbed(HVRHandGrabber arg0, HVRGrabbable arg1)
|
||||
protected virtual void OnDialGrabbed(HVRHandGrabber arg0, HVRGrabbable arg1)
|
||||
{
|
||||
Joint.SetAngularXDrive(0f, GrabbedDamper, 10000f);
|
||||
}
|
||||
@@ -143,18 +136,53 @@ namespace HurricaneVR.Framework.Components
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the rotation limits on the Joint's main rotation axis
|
||||
/// </summary>
|
||||
public void SetLimits(float minAngle, float maxAngle)
|
||||
{
|
||||
FixAngle(ref minAngle, ref maxAngle);
|
||||
|
||||
Joint.LimitAngularXMotion();
|
||||
Joint.SetAngularXHighLimit(minAngle);
|
||||
Joint.SetAngularXLowLimit(maxAngle);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Resets the limit's to the -MinAngle and MaxAngle values of this component.
|
||||
/// </summary>
|
||||
public void ResetLimits()
|
||||
{
|
||||
Joint.LimitAngularXMotion();
|
||||
Joint.SetAngularXHighLimit(-MinAngle);
|
||||
Joint.SetAngularXLowLimit(-MaxAngle);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Frees the axis of rotation
|
||||
/// </summary>
|
||||
public void RemoveLimits()
|
||||
{
|
||||
Joint.angularXMotion = ConfigurableJointMotion.Free;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sanity check on the angles for the joint high and low settings
|
||||
/// </summary>
|
||||
private void FixAngle(ref float min, ref float max)
|
||||
{
|
||||
if (min > 0)
|
||||
{
|
||||
min *= -1;
|
||||
}
|
||||
|
||||
if (max < 0)
|
||||
{
|
||||
max *= -1;
|
||||
}
|
||||
|
||||
min = Mathf.Clamp(min, min, 0);
|
||||
max = Mathf.Clamp(max, 0, max);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,42 +7,76 @@ using UnityEngine;
|
||||
|
||||
namespace HurricaneVR.Framework.Components
|
||||
{
|
||||
/// <summary>
|
||||
/// This component helps setup the basic functionality of a hinged door.
|
||||
/// Includes locking and latching capability. Handle required rotation for unlatching.
|
||||
/// </summary>
|
||||
[HelpURL("https://cloudwalker2020.github.io/HurricaneVR-Docs/manual/components/door.html")]
|
||||
[RequireComponent(typeof(HVRRotationTracker))]
|
||||
[RequireComponent(typeof(Rigidbody))]
|
||||
public class HVRPhysicsDoor : MonoBehaviour
|
||||
{
|
||||
[Header("Settings")]
|
||||
[Tooltip("Local axis of rotation")]
|
||||
[Header("Settings")] [Tooltip("Local axis of rotation")]
|
||||
public HVRAxis Axis;
|
||||
public float Mass = 10f;
|
||||
|
||||
[Tooltip("Door's rigidbody mass.")] public float Mass = 10f;
|
||||
|
||||
public bool DisableGravity = true;
|
||||
|
||||
[Tooltip("If true the door and it's handle will have their joint limit's locked on start.")]
|
||||
public bool StartLocked;
|
||||
|
||||
[Tooltip("Rigidbody to connect the joint to")]
|
||||
public Rigidbody ConnectedBody;
|
||||
|
||||
[Header("Door Closing Settings")]
|
||||
[Header("Door Closing Settings")] [Tooltip("Angle threshold to determine if the door is closed or not.")]
|
||||
public float CloseAngle = 5f;
|
||||
|
||||
[Tooltip("The door will automatically shut over this amount of time once it's close enough to be closed.")]
|
||||
public float CloseOverTime = .25f;
|
||||
|
||||
[Tooltip("How long the door angle must be below 'CloseAngle' to become closed.")]
|
||||
public float CloseDetectionTime = .5f;
|
||||
|
||||
[Header("SFX")]
|
||||
[Header("SFX")] [Tooltip("Angle threshold to play opening and closing sound effects.")]
|
||||
public float SFXThresholdAngle = 2.5f;
|
||||
|
||||
public float SFXResetThreshold = 1f;
|
||||
public AudioClip SFXOpened;
|
||||
public AudioClip SFXClosed;
|
||||
|
||||
[Tooltip("Delay before the open / close sfx can be played again")]
|
||||
public float SFXTimeout = 1f;
|
||||
|
||||
[Tooltip("Optional transform to define the position of the open / close sound fx.")]
|
||||
public Transform SFXPosition;
|
||||
|
||||
[Header("Handle")]
|
||||
[Header("Handle")] [Tooltip("If true the handle must rotate beyond 'HandThreshold' amount of degrees before it will unlatch, if false the door will not latch automatically.")]
|
||||
public bool HandleRequiresRotation;
|
||||
|
||||
[Tooltip("Required handle rotation to unlatch the door.")]
|
||||
public float HandleThreshold = 45f;
|
||||
|
||||
[Tooltip("The rotation tracker that reports the amount of rotation of the handle.")]
|
||||
public HVRRotationTracker HandleRotationTracker;
|
||||
|
||||
[Tooltip("If provided (and held) the door will not automatically shut when it is below 'CloseAngle' in degrees.")]
|
||||
public HVRGrabbable HandleGrabbable;
|
||||
|
||||
[Tooltip("Rotational physics component that let's this door component lock the door handle's rotation when the door locks.")]
|
||||
public HVRPhysicsDial DoorKnob;
|
||||
|
||||
|
||||
[Header("Joint Limits")]
|
||||
public bool LimitRotation = true;
|
||||
[Tooltip("The rotation tracker that reports the amount of rotation of the handle.")]
|
||||
public HVRRotationTracker SecondHandleRotationTracker;
|
||||
|
||||
[Tooltip("If provided (and held) the door will not automatically shut when it is below 'CloseAngle' in degrees.")]
|
||||
public HVRGrabbable SecondHandleGrabbable;
|
||||
|
||||
[Tooltip("Rotational physics component that let's this door component lock the door handle's rotation when the door locks.")]
|
||||
public HVRPhysicsDial SecondDoorKnob;
|
||||
|
||||
[Header("Joint Limits")] public bool LimitRotation = true;
|
||||
|
||||
[Tooltip("Minimum Angle about the axis of rotation")]
|
||||
public float MinAngle;
|
||||
@@ -50,19 +84,17 @@ namespace HurricaneVR.Framework.Components
|
||||
[Tooltip("Maximum rotation about the axis of rotation")]
|
||||
public float MaxAngle;
|
||||
|
||||
[Header("Joint Settings")]
|
||||
|
||||
[Tooltip("Angular Damper when the dial is not grabbed")]
|
||||
[Header("Joint Settings")] [Tooltip("Angular Damper of the door hinge.")]
|
||||
public float Damper = 10;
|
||||
|
||||
[Tooltip("Angular Spring that will return the door to it's starting rotation")]
|
||||
public float Spring;
|
||||
|
||||
//[Header("Editor")]
|
||||
//[SerializeField]
|
||||
//protected Quaternion JointStartRotation;
|
||||
|
||||
[Header("Debugging")]
|
||||
public float TargetAngularVelocity = 0f;
|
||||
[Header("Debugging")] public float TargetAngularVelocity = 0f;
|
||||
public bool DoorLatched;
|
||||
public bool DoorClosed;
|
||||
public bool Opened;
|
||||
@@ -161,7 +193,7 @@ namespace HurricaneVR.Framework.Components
|
||||
DoorClosed = false;
|
||||
}
|
||||
|
||||
if (HandleGrabbable && HandleGrabbable.IsBeingHeld)
|
||||
if (HandleGrabbable && HandleGrabbable.IsBeingHeld || SecondHandleGrabbable && SecondHandleGrabbable.IsBeingHeld)
|
||||
{
|
||||
_detectionTimer = 0f;
|
||||
}
|
||||
@@ -209,11 +241,14 @@ namespace HurricaneVR.Framework.Components
|
||||
|
||||
if (HandleRequiresRotation)
|
||||
{
|
||||
if (HandleRotationTracker.UnsignedAngle >= HandleThreshold)
|
||||
if (HandleRotationTracker.UnsignedAngle >= HandleThreshold ||
|
||||
(SecondHandleRotationTracker && SecondHandleRotationTracker.UnsignedAngle >= HandleThreshold))
|
||||
{
|
||||
DoorLatched = false;
|
||||
}
|
||||
else if (HandleRotationTracker.UnsignedAngle < HandleThreshold && Tracker.UnsignedAngle < CloseAngle)
|
||||
else if (HandleRotationTracker.UnsignedAngle < HandleThreshold &&
|
||||
(!SecondHandleRotationTracker || SecondHandleRotationTracker.UnsignedAngle < HandleThreshold) &&
|
||||
Tracker.UnsignedAngle < CloseAngle)
|
||||
{
|
||||
DoorLatched = true;
|
||||
}
|
||||
@@ -235,7 +270,7 @@ namespace HurricaneVR.Framework.Components
|
||||
PreviousClosed = DoorClosed;
|
||||
}
|
||||
|
||||
private Vector3 GetSFXPosition()
|
||||
protected virtual Vector3 GetSFXPosition()
|
||||
{
|
||||
var position = transform.position;
|
||||
if (SFXPosition)
|
||||
@@ -248,31 +283,30 @@ namespace HurricaneVR.Framework.Components
|
||||
|
||||
protected virtual void PlayClosedSFX()
|
||||
{
|
||||
|
||||
if(SFXPlayer.Instance) SFXPlayer.Instance.PlaySFX(SFXClosed, GetSFXPosition());
|
||||
if (SFXPlayer.Instance) SFXPlayer.Instance.PlaySFX(SFXClosed, GetSFXPosition());
|
||||
}
|
||||
|
||||
|
||||
|
||||
protected virtual void PlayOpenedSFX()
|
||||
{
|
||||
if(SFXPlayer.Instance) SFXPlayer.Instance.PlaySFX(SFXOpened, GetSFXPosition());
|
||||
if (SFXPlayer.Instance) SFXPlayer.Instance.PlaySFX(SFXOpened, GetSFXPosition());
|
||||
}
|
||||
|
||||
protected virtual void OnDoorUnLatched()
|
||||
public virtual void OnDoorUnLatched()
|
||||
{
|
||||
if (VerboseLogging)
|
||||
Debug.Log($"OnDoorUnLatched");
|
||||
UnlockDoorJoint();
|
||||
}
|
||||
|
||||
protected virtual void OnDoorLatched()
|
||||
public virtual void OnDoorLatched()
|
||||
{
|
||||
if (VerboseLogging)
|
||||
Debug.Log($"OnDoorLatched");
|
||||
LockDoorJoint();
|
||||
}
|
||||
|
||||
// ReSharper disable Unity.PerformanceAnalysis
|
||||
protected virtual void OnDoorClosed()
|
||||
{
|
||||
if (VerboseLogging)
|
||||
@@ -281,6 +315,7 @@ namespace HurricaneVR.Framework.Components
|
||||
StartCoroutine(DoorCloseRoutine());
|
||||
}
|
||||
|
||||
// ReSharper disable Unity.PerformanceAnalysis
|
||||
protected virtual void OnDoorOpened()
|
||||
{
|
||||
if (VerboseLogging)
|
||||
@@ -302,6 +337,9 @@ namespace HurricaneVR.Framework.Components
|
||||
Joint.SetAngularXLowLimit(-MaxAngle);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Locks the door joint, and the door knob's joint.
|
||||
/// </summary>
|
||||
public virtual void Lock()
|
||||
{
|
||||
Locked = true;
|
||||
@@ -309,6 +347,9 @@ namespace HurricaneVR.Framework.Components
|
||||
LockDoorKnob();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Unlocks the door and allows the door handle to rotate.
|
||||
/// </summary>
|
||||
public virtual void Unlock()
|
||||
{
|
||||
Locked = false;
|
||||
@@ -323,18 +364,14 @@ namespace HurricaneVR.Framework.Components
|
||||
|
||||
protected virtual void LockDoorKnob()
|
||||
{
|
||||
if (DoorKnob)
|
||||
{
|
||||
DoorKnob.SetLimits(0, 0);
|
||||
}
|
||||
if (DoorKnob) DoorKnob.SetLimits(0, 0);
|
||||
if (SecondDoorKnob) SecondDoorKnob.SetLimits(0, 0);
|
||||
}
|
||||
|
||||
protected virtual void UnlockDoorKnob()
|
||||
{
|
||||
if (DoorKnob)
|
||||
{
|
||||
DoorKnob.ResetLimits();
|
||||
}
|
||||
if (DoorKnob) DoorKnob.ResetLimits();
|
||||
if (SecondDoorKnob) SecondDoorKnob.ResetLimits();
|
||||
}
|
||||
|
||||
protected IEnumerator DoorCloseRoutine()
|
||||
@@ -353,7 +390,7 @@ namespace HurricaneVR.Framework.Components
|
||||
_doorClosing = false;
|
||||
}
|
||||
|
||||
private void SetupJoint()
|
||||
protected virtual void SetupJoint()
|
||||
{
|
||||
var currentRotation = transform.localRotation;
|
||||
//transform.localRotation = JointStartRotation;
|
||||
@@ -362,7 +399,7 @@ namespace HurricaneVR.Framework.Components
|
||||
Joint.LockLinearMotion();
|
||||
Joint.LockAngularYMotion();
|
||||
Joint.LockAngularZMotion();
|
||||
|
||||
Joint.anchor = Vector3.zero;
|
||||
Joint.axis = Axis.GetVector();
|
||||
|
||||
if (LimitRotation)
|
||||
|
||||
@@ -6,16 +6,28 @@ using UnityEngine;
|
||||
|
||||
namespace HurricaneVR.Framework.Components
|
||||
{
|
||||
/// <summary>
|
||||
/// Helper component to constrain a drawer along the desired movement axis handling the joint creation and limiting for you.
|
||||
/// Joint is constrained between the start and end position which is defined in the component inspector.
|
||||
/// </summary>
|
||||
[RequireComponent(typeof(Rigidbody))]
|
||||
public class HVRPhysicsDrawer : MonoBehaviour
|
||||
{
|
||||
[Header("Settings")]
|
||||
[Tooltip("Axis the drawer will travel on in local space.")]
|
||||
public HVRAxis Axis;
|
||||
|
||||
[Tooltip("Rigidbody to joint to.")]
|
||||
public Rigidbody ConnectedBody;
|
||||
|
||||
[Tooltip("Optional spring that will return to the starting position")]
|
||||
public float Spring = 0;
|
||||
|
||||
[Tooltip("Damper to provide 'friction' to the drawer.")]
|
||||
public float Damper = 10;
|
||||
|
||||
[Header("SFX")] public float SFXResetThreshold = .02f;
|
||||
[Header("SFX")]
|
||||
public float SFXResetThreshold = .02f;
|
||||
public AudioClip SFXOpened;
|
||||
public AudioClip SFXClosed;
|
||||
|
||||
|
||||
@@ -7,23 +7,14 @@ using UnityEngine;
|
||||
|
||||
namespace HurricaneVR.Framework.Components
|
||||
{
|
||||
/// <summary>
|
||||
/// Lever behaves similar to the dial in rigidbody joint behaviour at this time...
|
||||
/// </summary>
|
||||
[RequireComponent(typeof(Rigidbody))]
|
||||
public class HVRPhysicsLever : HVRPhysicsDial
|
||||
{
|
||||
public bool DrawGizmos = true;
|
||||
public ConfigurableJoint preJoint;
|
||||
|
||||
protected override void SetupJoint()
|
||||
{
|
||||
if(!preJoint)
|
||||
{
|
||||
base.SetupJoint();
|
||||
}
|
||||
else
|
||||
{
|
||||
Joint = preJoint;
|
||||
}
|
||||
}
|
||||
|
||||
public void OnDrawGizmosSelected()
|
||||
{
|
||||
|
||||
+5
-2
@@ -3,6 +3,9 @@ using UnityEngine;
|
||||
|
||||
namespace HurricaneVR.Framework.Components
|
||||
{
|
||||
/// <summary>
|
||||
/// Helper component to override various rigidbody properties
|
||||
/// </summary>
|
||||
[RequireComponent(typeof(Rigidbody))]
|
||||
public class HVRRigidBodyOverrides : MonoBehaviour
|
||||
{
|
||||
@@ -22,7 +25,7 @@ namespace HurricaneVR.Framework.Components
|
||||
[Header("Debug")]
|
||||
public Vector3 COMGizmoSize = new Vector3(.02f, .02f, .02f);
|
||||
public bool LiveUpdate;
|
||||
|
||||
public bool ShowCOMGizmo;
|
||||
public Rigidbody Rigidbody;
|
||||
|
||||
void Awake()
|
||||
@@ -75,7 +78,7 @@ namespace HurricaneVR.Framework.Components
|
||||
|
||||
void OnDrawGizmosSelected()
|
||||
{
|
||||
//if (OverrideCOM)
|
||||
if (ShowCOMGizmo)
|
||||
{
|
||||
Gizmos.color = Color.yellow;
|
||||
if (OverrideCOM)
|
||||
|
||||
@@ -3,6 +3,9 @@ using UnityEngine;
|
||||
|
||||
namespace HurricaneVR.Framework.Components
|
||||
{
|
||||
/// <summary>
|
||||
/// Helps constrain loose joints on the desired axis.
|
||||
/// </summary>
|
||||
public class HVRRigidbodyLocker : MonoBehaviour
|
||||
{
|
||||
public LockOptions Locks;
|
||||
|
||||
@@ -10,17 +10,22 @@ namespace HurricaneVR.Framework.Components
|
||||
public Transform Camera;
|
||||
|
||||
[Header("Settings")]
|
||||
|
||||
[Tooltip("Ring must be within this distance from the camera to be displayed")]
|
||||
public float Distance = 5f;
|
||||
|
||||
|
||||
[Header("Line of Sight Settings")]
|
||||
|
||||
[Tooltip("Use ray cast to the camera collider to determine if we should show")]
|
||||
public bool RequireLineOfSight = true;
|
||||
|
||||
[Tooltip("Layer mask for checking line of sight, include the layer of the camera(default is Player)")]
|
||||
public LayerMask LayerMask;
|
||||
|
||||
[Tooltip("Check line of sight only if distance greater than this")]
|
||||
public float LineOfSightThreshold = 1.5f;
|
||||
|
||||
[Tooltip("Timeout to check line of sight")]
|
||||
public float Delay = 1f;
|
||||
|
||||
@@ -30,7 +35,7 @@ namespace HurricaneVR.Framework.Components
|
||||
|
||||
protected override void Start()
|
||||
{
|
||||
if (!Camera)
|
||||
if (!Camera && HVRManager.Instance)
|
||||
{
|
||||
Camera = HVRManager.Instance.Camera;
|
||||
}
|
||||
|
||||
@@ -7,15 +7,26 @@ using UnityEngine;
|
||||
|
||||
namespace HurricaneVR.Framework.Components
|
||||
{
|
||||
/// <summary>
|
||||
/// Used to limit rotations beyond the default Physx limit of 177 degrees. Joint is recreated at certain thresholds to allow the wider
|
||||
/// range of motion, only use this if you need range of motion beyond 177 degrees.
|
||||
/// </summary>
|
||||
[RequireComponent(typeof(Rigidbody))]
|
||||
[RequireComponent(typeof(HVRRotationTracker))]
|
||||
public class HVRRotationLimiter : MonoBehaviour
|
||||
{
|
||||
public const float PhysxMaxLimit = 177f;
|
||||
|
||||
[Tooltip("Connected Body of the Joint")]
|
||||
public Rigidbody ConnectedBody;
|
||||
|
||||
[Tooltip("Minimum angle of rotation")]
|
||||
public int MinAngle;
|
||||
|
||||
[Tooltip("Maximum angle of rotation")]
|
||||
public int MaxAngle;
|
||||
|
||||
[Tooltip("Distance traveled before the joint is recreated with new limits")]
|
||||
public float JointResetThreshold = 90f;
|
||||
|
||||
|
||||
|
||||
@@ -3,11 +3,18 @@ using UnityEngine;
|
||||
|
||||
namespace HurricaneVR.Framework.Components
|
||||
{
|
||||
/// <summary>
|
||||
/// Used in conjunction with the HVRRotationTracker to play SFX based on rotation amount.
|
||||
/// </summary>
|
||||
public class HVRRotationSFX : MonoBehaviour
|
||||
{
|
||||
[Tooltip("Tracker required to know how far something has rotated")]
|
||||
public HVRRotationTracker Tracker;
|
||||
|
||||
[Tooltip("Clip chosen at random from this list when rotated beyond 'AngleThreshold'")]
|
||||
public AudioClip[] SFX;
|
||||
|
||||
[Tooltip("Rotation distance must exceed this to play another sfx clip")]
|
||||
public float AngleThreshold = 30f;
|
||||
|
||||
[Header("Debug")]
|
||||
@@ -41,11 +48,6 @@ namespace HurricaneVR.Framework.Components
|
||||
}
|
||||
}
|
||||
|
||||
public void Update()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
protected virtual void PlaySFX(AudioClip sfx)
|
||||
{
|
||||
if(SFXPlayer.Instance) SFXPlayer.Instance.PlaySFX(sfx, transform.position);
|
||||
|
||||
@@ -7,6 +7,10 @@ using UnityEngine.Events;
|
||||
|
||||
namespace HurricaneVR.Framework.Components
|
||||
{
|
||||
/// <summary>
|
||||
/// Used to track the rotation in degrees about a defined axis of rotation.
|
||||
/// Degrees are reported from the starting rotation of the transform.
|
||||
/// </summary>
|
||||
public class HVRRotationTracker : MonoBehaviour
|
||||
{
|
||||
[Tooltip("Local axis of rotation")]
|
||||
|
||||
@@ -2,6 +2,9 @@
|
||||
|
||||
namespace HurricaneVR.Framework.Components
|
||||
{
|
||||
/// <summary>
|
||||
/// Specialized hover behaviour that scales this transform over time when a hand or force grabber is hovering it.
|
||||
/// </summary>
|
||||
public class HVRScaleHighlight : HVRGrabbableHoverBase
|
||||
{
|
||||
public Vector3 HoverScale = new Vector3(1.3f, 1.3f, 1.3f);
|
||||
|
||||
+4
@@ -4,6 +4,9 @@ using UnityEngine;
|
||||
|
||||
namespace HurricaneVR.Framework.Components
|
||||
{
|
||||
/// <summary>
|
||||
/// Used to define center of mass of the controller relative to the hand for bonus throwing velocity calculations
|
||||
/// </summary>
|
||||
public class HVRThrowingCenterOfMass : MonoBehaviour
|
||||
{
|
||||
public HVRHandSide HandSide;
|
||||
@@ -36,6 +39,7 @@ namespace HurricaneVR.Framework.Components
|
||||
|
||||
switch (controller.ControllerType)
|
||||
{
|
||||
case HVRControllerType.Pico:
|
||||
case HVRControllerType.Oculus:
|
||||
CenterOfMass = Oculus;
|
||||
break;
|
||||
|
||||
+21
-2
@@ -19,6 +19,7 @@ namespace HurricaneVR.Framework.Components
|
||||
Grabbable = GetComponent<HVRGrabbable>();
|
||||
|
||||
Grabbable.HandGrabbed.AddListener(OnHandGrabbed);
|
||||
Grabbable.HandReleased.AddListener(OnHandReleased);
|
||||
|
||||
if (Others != null)
|
||||
{
|
||||
@@ -33,6 +34,11 @@ namespace HurricaneVR.Framework.Components
|
||||
}
|
||||
}
|
||||
|
||||
private void OnHandReleased(HVRHandGrabber arg0, HVRGrabbable arg1)
|
||||
{
|
||||
Grabbable.ForceTwoHandSettings = false;
|
||||
}
|
||||
|
||||
private void OnHandGrabbed(HVRHandGrabber arg0, HVRGrabbable arg1)
|
||||
{
|
||||
foreach (var other in Others)
|
||||
@@ -45,9 +51,22 @@ namespace HurricaneVR.Framework.Components
|
||||
}
|
||||
}
|
||||
|
||||
private void OnOtherGrabbableHandReleased(HVRHandGrabber arg0, HVRGrabbable arg1)
|
||||
private void OnOtherGrabbableHandReleased(HVRHandGrabber arg0, HVRGrabbable g)
|
||||
{
|
||||
Grabbable.ForceTwoHandSettings = false;
|
||||
//handle scenario if two "others" are held, then one was released.
|
||||
var force = false;
|
||||
for (int i = 0; i < Others.Length; i++)
|
||||
{
|
||||
var other = Others[i];
|
||||
if (other == g || other.HandGrabbers.Count == 0)
|
||||
continue;
|
||||
|
||||
force = true;
|
||||
break;
|
||||
}
|
||||
|
||||
if (!force)
|
||||
Grabbable.ForceTwoHandSettings = false;
|
||||
}
|
||||
|
||||
private void OnOtherGrabbableHandGrabbed(HVRHandGrabber arg0, HVRGrabbable arg1)
|
||||
|
||||
Reference in New Issue
Block a user