Add ultimate xr
This commit is contained in:
@@ -0,0 +1,93 @@
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
// <copyright file="RotateShoulder.cs" company="VRMADA">
|
||||
// Copyright (c) VRMADA, All rights reserved.
|
||||
// </copyright>
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
using UltimateXR.Core;
|
||||
using UltimateXR.Core.Components;
|
||||
using UnityEngine;
|
||||
|
||||
namespace UltimateXR.Mechanics.CyborgAvatar
|
||||
{
|
||||
/// <summary>
|
||||
/// Component that rotates the Cyborg shoulder so that the opening points in the arm direction to leave it
|
||||
/// more space.
|
||||
/// </summary>
|
||||
public class RotateShoulder : UxrComponent
|
||||
{
|
||||
#region Inspector Properties/Serialized Fields
|
||||
|
||||
[SerializeField] private Transform _rotatingShoulder;
|
||||
[SerializeField] private Vector3 _rotatingShoulderAxis;
|
||||
[SerializeField] private Vector3 _rotatingShoulderOpeningAxis;
|
||||
[SerializeField] private Transform _arm;
|
||||
[SerializeField] private Vector3 _armLocalForward;
|
||||
[SerializeField] private float _rotationDampingMin = 1.0f;
|
||||
[SerializeField] private float _rotationDampingMax = 0.2f;
|
||||
[SerializeField] private float _armAngleToRotateMin = 30.0f;
|
||||
[SerializeField] private float _armAngleToRotateMax = 60.0f;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Unity
|
||||
|
||||
/// <summary>
|
||||
/// Subscribes to events.
|
||||
/// </summary>
|
||||
protected override void OnEnable()
|
||||
{
|
||||
base.OnEnable();
|
||||
|
||||
UxrManager.AvatarsUpdated += UxrManager_AvatarsUpdated;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Unsubscribes from events.
|
||||
/// </summary>
|
||||
protected override void OnDisable()
|
||||
{
|
||||
base.OnDisable();
|
||||
|
||||
UxrManager.AvatarsUpdated -= UxrManager_AvatarsUpdated;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Event Handling Methods
|
||||
|
||||
/// <summary>
|
||||
/// Performs the shoulder rotation.
|
||||
/// </summary>
|
||||
private void UxrManager_AvatarsUpdated()
|
||||
{
|
||||
Vector3 armForward = _arm.TransformDirection(_armLocalForward);
|
||||
Vector3 rotatingShoulderAxis = _rotatingShoulder.TransformDirection(_rotatingShoulderAxis);
|
||||
|
||||
float armAngle = Vector3.Angle(armForward, rotatingShoulderAxis);
|
||||
|
||||
if (armAngle > _armAngleToRotateMin)
|
||||
{
|
||||
float t = Mathf.Clamp01((armAngle - _armAngleToRotateMin) / (_armAngleToRotateMax - _armAngleToRotateMin));
|
||||
|
||||
Vector3 openingCurrent = _rotatingShoulder.TransformDirection(_rotatingShoulderOpeningAxis);
|
||||
Vector3 openingTarget = Vector3.ProjectOnPlane(armForward, rotatingShoulderAxis);
|
||||
float currentAngle = Vector3.SignedAngle(openingCurrent, openingTarget, rotatingShoulderAxis);
|
||||
float dampedAngle = Mathf.SmoothDampAngle(currentAngle, 0.0f, ref _currentAngleVelocity, Mathf.Lerp(_rotationDampingMin, _rotationDampingMax, t));
|
||||
|
||||
_rotatingShoulder.Rotate(_rotatingShoulderAxis, currentAngle - dampedAngle, Space.Self);
|
||||
}
|
||||
else
|
||||
{
|
||||
_currentAngleVelocity = 0.0f;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private Types & Data
|
||||
|
||||
private float _currentAngleVelocity;
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 66858c08b0019284683fe834e616d2d2
|
||||
timeCreated: 1548833695
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,75 @@
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
// <copyright file="WristConnectionRays.RayProperties.cs" company="VRMADA">
|
||||
// Copyright (c) VRMADA, All rights reserved.
|
||||
// </copyright>
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace UltimateXR.Mechanics.CyborgAvatar
|
||||
{
|
||||
public partial class WristConnectionRays
|
||||
{
|
||||
#region Private Types & Data
|
||||
|
||||
/// <summary>
|
||||
/// Stores the properties of a connection ray.
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
private class RayProperties
|
||||
{
|
||||
#region Inspector Properties/Serialized Fields
|
||||
|
||||
[SerializeField] [ColorUsage(true, true)] private Color _color;
|
||||
[SerializeField] private float _thickness;
|
||||
[SerializeField] private float _offset;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Types & Data
|
||||
|
||||
/// <summary>
|
||||
/// Gets the ray thickness.
|
||||
/// </summary>
|
||||
public float Thickness => _thickness;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the ray offset.
|
||||
/// </summary>
|
||||
public float Offset => _offset;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the ray color.
|
||||
/// </summary>
|
||||
public Color Color
|
||||
{
|
||||
get => _color;
|
||||
set => _color = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the GameObject created at runtime for the ray.
|
||||
/// </summary>
|
||||
public GameObject GameObject { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the line renderer component created at runtime for the ray.
|
||||
/// </summary>
|
||||
public LineRenderer LineRenderer { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the offset in the 2d section of the ray direction.
|
||||
/// </summary>
|
||||
public Vector2 OffsetXY { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the start color.
|
||||
/// </summary>
|
||||
public Color StartColor { get; set; }
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0d398127f73748839a21126772e4539b
|
||||
timeCreated: 1643732645
|
||||
@@ -0,0 +1,194 @@
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
// <copyright file="WristConnectionRays.cs" company="VRMADA">
|
||||
// Copyright (c) VRMADA, All rights reserved.
|
||||
// </copyright>
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
using System.Collections.Generic;
|
||||
using UltimateXR.Core;
|
||||
using UltimateXR.Core.Components;
|
||||
using UnityEngine;
|
||||
|
||||
namespace UltimateXR.Mechanics.CyborgAvatar
|
||||
{
|
||||
/// <summary>
|
||||
/// Component that drives the two devices that connect the Cyborg wrist to the arm.
|
||||
/// </summary>
|
||||
public partial class WristConnectionRays : UxrComponent
|
||||
{
|
||||
#region Inspector Properties/Serialized Fields
|
||||
|
||||
[SerializeField] private float _gradientPosStart1 = 0.15f;
|
||||
[SerializeField] private float _gradientPosStart2 = 0.2f;
|
||||
[SerializeField] private float _gradientPosEnd1 = 0.8f;
|
||||
[SerializeField] private float _gradientPosEnd2 = 0.85f;
|
||||
[SerializeField] private Material _rayMaterial;
|
||||
[SerializeField] private bool _useMaterialNoiseParameters;
|
||||
[SerializeField] private Transform _src;
|
||||
[SerializeField] private Transform _dst;
|
||||
[SerializeField] private List<RayProperties> _rays;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Unity
|
||||
|
||||
/// <summary>
|
||||
/// Subscribes to avatar update event.
|
||||
/// </summary>
|
||||
protected override void OnEnable()
|
||||
{
|
||||
base.OnEnable();
|
||||
|
||||
UxrManager.AvatarsUpdated += UxrManager_AvatarsUpdated;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Unsubscribes from avatar update events.
|
||||
/// </summary>
|
||||
protected override void OnDisable()
|
||||
{
|
||||
base.OnDisable();
|
||||
|
||||
UxrManager.AvatarsUpdated -= UxrManager_AvatarsUpdated;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes the component.
|
||||
/// </summary>
|
||||
protected override void Start()
|
||||
{
|
||||
base.Start();
|
||||
|
||||
Create(_src.position, _dst.position);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Event Handling Methods
|
||||
|
||||
/// <summary>
|
||||
/// Updates the component.
|
||||
/// </summary>
|
||||
private void UxrManager_AvatarsUpdated()
|
||||
{
|
||||
if (_src != null && _dst != null)
|
||||
{
|
||||
UpdateRays(_src.position, _dst.position);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private Methods
|
||||
|
||||
/// <summary>
|
||||
/// Creates the connections.
|
||||
/// </summary>
|
||||
/// <param name="src">Source position</param>
|
||||
/// <param name="dst">Destination position</param>
|
||||
private void Create(Vector3 src, Vector3 dst)
|
||||
{
|
||||
foreach (RayProperties ray in _rays)
|
||||
{
|
||||
ray.GameObject = new GameObject("Ray");
|
||||
ray.GameObject.transform.SetParent(transform, true);
|
||||
ray.GameObject.transform.localPosition = Vector3.zero;
|
||||
ray.GameObject.transform.localRotation = Quaternion.identity;
|
||||
|
||||
ray.LineRenderer = ray.GameObject.AddComponent<LineRenderer>();
|
||||
ray.LineRenderer.material = _rayMaterial;
|
||||
|
||||
if (_useMaterialNoiseParameters)
|
||||
{
|
||||
ray.LineRenderer.material.SetFloat(DistortTimeStartVarName, Random.value * 10000.0f);
|
||||
}
|
||||
|
||||
ray.LineRenderer.textureMode = LineTextureMode.Stretch;
|
||||
ray.OffsetXY = Random.insideUnitCircle;
|
||||
}
|
||||
|
||||
UpdateRays(src, dst);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates the connection rays.
|
||||
/// </summary>
|
||||
/// <param name="src">Source position</param>
|
||||
/// <param name="dst">End position</param>
|
||||
private void UpdateRays(Vector3 src, Vector3 dst)
|
||||
{
|
||||
foreach (RayProperties ray in _rays)
|
||||
{
|
||||
if (ray.GameObject == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
ray.GameObject.transform.position = src;
|
||||
ray.GameObject.transform.LookAt(dst);
|
||||
|
||||
float rayLength = Vector3.Distance(src, dst) / ray.LineRenderer.transform.lossyScale.z;
|
||||
|
||||
Vector3[] positions =
|
||||
{
|
||||
new Vector3(0.0f, 0.0f, 0.0f),
|
||||
new Vector3(0.0f, 0.0f, rayLength * _gradientPosStart1),
|
||||
new Vector3(0.0f, 0.0f, rayLength * _gradientPosStart2),
|
||||
new Vector3(0.0f, 0.0f, rayLength * _gradientPosEnd1),
|
||||
new Vector3(0.0f, 0.0f, rayLength * _gradientPosEnd2),
|
||||
new Vector3(0.0f, 0.0f, rayLength)
|
||||
};
|
||||
|
||||
Vector3 offset = (ray.GameObject.transform.right * ray.OffsetXY.x + ray.GameObject.transform.up * ray.OffsetXY.y).normalized * ray.Offset;
|
||||
|
||||
for (int pos = 0; pos < positions.Length; ++pos)
|
||||
{
|
||||
positions[pos] = ray.LineRenderer.transform.InverseTransformPoint(ray.GameObject.transform.TransformPoint(positions[pos]) + offset);
|
||||
}
|
||||
|
||||
ray.LineRenderer.useWorldSpace = false;
|
||||
ray.LineRenderer.positionCount = 6;
|
||||
ray.LineRenderer.SetPositions(positions);
|
||||
ray.LineRenderer.startWidth = ray.Thickness;
|
||||
ray.LineRenderer.endWidth = ray.Thickness;
|
||||
ray.LineRenderer.material.color = ray.Color;
|
||||
|
||||
if (ray.LineRenderer.material.mainTexture != null)
|
||||
{
|
||||
ray.LineRenderer.material.mainTextureScale = new Vector2(rayLength / ray.Thickness / (ray.LineRenderer.material.mainTexture.width / (float)ray.LineRenderer.material.mainTexture.height), 1.0f);
|
||||
}
|
||||
|
||||
Gradient colorGradient = new Gradient();
|
||||
|
||||
colorGradient.colorKeys = new[]
|
||||
{
|
||||
new GradientColorKey(Color.white, 0.0f),
|
||||
new GradientColorKey(Color.white, _gradientPosStart1),
|
||||
new GradientColorKey(Color.white, _gradientPosStart2),
|
||||
new GradientColorKey(Color.white, _gradientPosEnd1),
|
||||
new GradientColorKey(Color.white, _gradientPosEnd2),
|
||||
new GradientColorKey(Color.white, 1.0f)
|
||||
};
|
||||
|
||||
colorGradient.alphaKeys = new[]
|
||||
{
|
||||
new GradientAlphaKey(0.0f, 0.0f),
|
||||
new GradientAlphaKey(0.0f, _gradientPosStart1),
|
||||
new GradientAlphaKey(1.0f, _gradientPosStart2),
|
||||
new GradientAlphaKey(1.0f, _gradientPosEnd1),
|
||||
new GradientAlphaKey(0.0f, _gradientPosEnd2),
|
||||
new GradientAlphaKey(0.0f, 1.0f)
|
||||
};
|
||||
|
||||
ray.LineRenderer.colorGradient = colorGradient;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private Types & Data
|
||||
|
||||
private readonly string DistortTimeStartVarName = "_DistortTimeStart";
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 956417d4411d10142ac02fcd9618b664
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user