Initialer Upload neues Unity-Projekt

This commit is contained in:
Daniel Ocks
2025-07-21 09:11:14 +02:00
commit eeca72985b
14558 changed files with 1508140 additions and 0 deletions

View File

@ -0,0 +1,210 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
* All rights reserved.
*
* Licensed under the Oculus SDK License Agreement (the "License");
* you may not use the Oculus SDK except in compliance with the License,
* which is provided at the time of installation or download, or which
* otherwise accompanies this software in either electronic or hard copy form.
*
* You may obtain a copy of the License at
*
* https://developer.oculus.com/licenses/oculussdk/
*
* Unless required by applicable law or agreed to in writing, the Oculus SDK
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text.RegularExpressions;
using UnityEngine;
using UnityEngine.Assertions;
namespace Oculus.Interaction
{
public static class AssertUtils
{
public const string HiglightColor = "#3366ff";
/// <summary>
/// Asserts that the expression is True.
/// In case of failure, it will print an error showing where the failure happened.
/// </summary>
/// <param name="component">The component to which the value expression belongs</param>
/// <param name="value">The expression that should be true</param>
/// <param name="whyItFailed">Optional parameter specifying the reason the assert failed</param>
/// <param name="whereItFailed">Optional parameter specifying where the failure can be found.
/// If none is provided it will print the component address (GameObject->Component).</param>
/// <param name="howToFix">Optional parameter suggesting how to fix the problem.</param>
[Conditional("UNITY_ASSERTIONS")]
public static void AssertIsTrue(this Component component,
bool value,
string whyItFailed = null, string whereItFailed = null, string howToFix = null)
{
string gameObjectName = component.name;
string componentName = component.GetType().Name;
Assert.IsTrue(value,
(whereItFailed ?? $"At GameObject <color={ HiglightColor}><b>{ gameObjectName}</b></color>, component <b>{ componentName}</b>. ") +
(whyItFailed ?? "") +
(howToFix ?? ""));
}
/// <summary>
/// Asserts that an Aspect exists.
/// In case of failure, it will print an error showing why it failed, where it failed
/// and suggest how to fix it.
/// </summary>
/// <typeparam name="TValue">The type of Aspect to be checked</typeparam>
/// <param name="component">The component requiring this Aspect</param>
/// <param name="aspect">The Aspect to be checked</param>
/// <param name="aspectLocation">The expected location of the Aspect</param>
/// <param name="whyItFailed">Optional parameter specifying the reason the assert failed.
/// If none is provided it will print the expected aspect type and location.</param>
/// <param name="whereFailed">Optional parameter specifying where the failure can be found.
/// If none is provided it will print the component address (GameObject->Component).</param>
/// <param name="howToFix">Optional parameter suggesting how to fix the problem.
/// If none is provided it will suggest assigning an Aspect of the required type to the expected location.</param>
[Conditional("UNITY_ASSERTIONS")]
public static void AssertAspect<TValue>(this Component component,
TValue aspect, string aspectLocation,
string whyItFailed = null, string whereFailed = null, string howToFix = null)
where TValue : class
{
string gameObjectName = component.name;
string componentName = component.GetType().Name;
string niceVariableName = Nicify(aspectLocation);
string aspectType = typeof(TValue).Name;
Assert.IsNotNull(aspect,
(whereFailed ?? $"At GameObject <color={HiglightColor}><b>{gameObjectName}</b></color>, component <b>{componentName}</b>. ") +
(whyItFailed ?? $"Could not find the required Aspect <b>{aspectType}</b> in the associated <b>{niceVariableName}</b>. ") +
(howToFix ?? $"Assign an Aspect of type <b>{aspectType}</b> to the associated <b>{niceVariableName}</b>."));
}
/// <summary>
/// Asserts that a Serialized Field in a Component is not null.
/// In case of failure, it will print an error showing why it failed, where it failed
/// and suggest how to fix it.
/// </summary>
/// <typeparam name="TValue">The type of field to be checked</typeparam>
/// <param name="component">The component to which this field belongs.</param>
/// <param name="value">The value of the field.</param>
/// <param name="variableName">The printed name of the serialized field.</param>
/// <param name="whyItFailed">Optional parameter specifying the reason the assert failed.
/// If none is provided it will indicate that the field value was null.</param>
/// <param name="whereItFailed">Optional parameter specifying where the failure can be found.
/// If none is provided it will print the component address (GameObject->Component->Field Name).</param>
/// <param name="howToFix">Optional parameter suggesting how to fix the problem.
/// If none is provided it will suggest assigning a value of the required type to the field.</param>
[Conditional("UNITY_ASSERTIONS")]
public static void AssertField<TValue>(this Component component,
TValue value, string variableName,
string whyItFailed = null, string whereItFailed = null, string howToFix = null)
where TValue : class
{
string gameObjectName = component.name;
string componentName = component.GetType().Name;
string niceVariableName = Nicify(variableName);
string variableType = typeof(TValue).Name;
Assert.IsNotNull(value,
(whereItFailed ?? $"At GameObject <color={HiglightColor}><b>{gameObjectName}</b></color>, component <b>{componentName}</b>. ") +
(whyItFailed ?? $"Required <b>{niceVariableName}</b> reference is missing. ") +
(howToFix ?? $"Assign a <b>{variableType}</b> to the field <b>{niceVariableName}</b>."));
}
/// <summary>
/// Asserts that a Serialized collection in a Component is not null, is not empty and
/// all of its items exist.
/// In case of failure, it will print an error showing why it failed, where it failed
/// and suggest how to fix it.
/// </summary>
/// <typeparam name="TValue">The type of the items in the collection.</typeparam>
/// <param name="component">The component to which this collection belongs.</param>
/// <param name="value">The value of the collection.</param>
/// <param name="variableName">The printed name of the serialized collection.</param>
/// <param name="whyItFailed">Optional parameter specifying the reason the assert failed.
/// If none is provided it will indicate that the collection value needs at least one valid item.</param>
/// <param name="whereFailed">Optional parameter specifying where the failure can be found.
/// If none is provided it will print the component address (GameObject->Component->Collection Name).</param>
/// <param name="howToFix">Optional parameter suggesting how to fix the problem.
/// If none is provided it will suggest assigning at least one valid item of the required type to the collection.</param>
[Conditional("UNITY_ASSERTIONS")]
public static void AssertCollectionField<TValue>(this Component component,
IEnumerable<TValue> value, string variableName,
string whyItFailed = null, string whereFailed = null, string howToFix = null)
{
string gameObjectName = component.name;
string componentName = component.GetType().Name;
string niceVariableName = Nicify(variableName);
string variableType = typeof(TValue).Name;
Assert.IsTrue(value != null && value.Count() > 0,
(whereFailed ?? $"At GameObject <color={HiglightColor}><b>{gameObjectName}</b></color>: the <b>{componentName}</b> component has an missing or empty <b>{niceVariableName}</b> collection. ") +
(whyItFailed ?? "") +
(howToFix ?? $"Assign at least one <b>{variableType}</b> to the collection <b>{niceVariableName}</b>. "));
component.AssertCollectionItems(value, variableName);
}
/// <summary>
/// Asserts that each item in a Serialized collection in a Component is not null.
/// Note that the collection it might contain 0 items.
/// In case of failure, it will print an error showing why it failed, where it failed
/// and suggest how to fix it.
/// </summary>
/// <typeparam name="TValue">The type of the items in the collection</typeparam>
/// <param name="component">The component to which the collection belongs.</param>
/// <param name="value">The value of the collection.</param>
/// <param name="variableName">The printed name of the serialized collection.</param>
/// <param name="whyItFailed">Optional parameter specifying the reason the assert failed.
/// If none is provided it will indicate, for each failed item, that the item must not be null.</param>
/// <param name="whereItFailed">Optional parameter specifying where the failure can be found.
/// If none is provided it will print the component address (GameObject->Component->Collection Name).</param>
/// <param name="howToFix">Optional parameter suggesting how to fix the problem.
/// If none is provided it will suggest assigning a valid item of the required type to the collection at each missing index.</param>
[Conditional("UNITY_ASSERTIONS")]
public static void AssertCollectionItems<TValue>(this Component component,
IEnumerable<TValue> value, string variableName,
string whyItFailed = null, string whereItFailed = null, string howToFix = null)
{
string gameObjectName = component.name;
string componentName = component.GetType().Name;
string niceVariableName = Nicify(variableName);
string variableType = typeof(TValue).Name;
int index = 0;
foreach (TValue item in value)
{
Assert.IsFalse(item is null,
(whereItFailed ?? $"At GameObject <color={HiglightColor}><b>{gameObjectName}</b></color>, component <b>{componentName}</b>. ") +
(whyItFailed ?? $"Invalid item in the collection <b>{niceVariableName}</b> at index <b>{index}</b>. ") +
(howToFix ?? $"Assign a <b>{variableType}</b> to the collection <b>{niceVariableName}</b> at index <b>{index}</b>. "));
index++;
}
}
/// <summary>
/// Make a displayable name for a variable.
/// This function will insert spaces before capital letters and remove optional m_, _ or k followed by uppercase letter in front of the name.
/// </summary>
/// <param name="variableName">The variable name as used in code</param>
/// <returns>The nicified variable</returns>
public static string Nicify(string variableName)
{
variableName = Regex.Replace(variableName, "_([a-z])", match => match.Value.ToUpper(), RegexOptions.Compiled);
variableName = Regex.Replace(variableName, "m_|_", " ", RegexOptions.Compiled);
variableName = Regex.Replace(variableName, "k([A-Z])", "$1", RegexOptions.Compiled);
variableName = Regex.Replace(variableName, "([A-Z])", " $1", RegexOptions.Compiled);
variableName = variableName.Trim();
return variableName;
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 450649e236e9f204891b374b09567d32
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,45 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
* All rights reserved.
*
* Licensed under the Oculus SDK License Agreement (the "License");
* you may not use the Oculus SDK except in compliance with the License,
* which is provided at the time of installation or download, or which
* otherwise accompanies this software in either electronic or hard copy form.
*
* You may obtain a copy of the License at
*
* https://developer.oculus.com/licenses/oculussdk/
*
* Unless required by applicable law or agreed to in writing, the Oculus SDK
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
using UnityEngine;
namespace Oculus.Interaction
{
public static class BoundsExtensions
{
public static bool Clip(this Bounds bounds,
in Bounds clipper, out Bounds result)
{
result = new Bounds();
Vector3 min = Vector3.Max(bounds.min, clipper.min);
Vector3 max = Vector3.Min(bounds.max, clipper.max);
if (min.x > max.x ||
min.y > max.y ||
min.z > max.z)
{
return false;
}
result.SetMinMax(min, max);
return true;
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 5533abf1024a93142ada781f7cd73994
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,42 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
* All rights reserved.
*
* Licensed under the Oculus SDK License Agreement (the "License");
* you may not use the Oculus SDK except in compliance with the License,
* which is provided at the time of installation or download, or which
* otherwise accompanies this software in either electronic or hard copy form.
*
* You may obtain a copy of the License at
*
* https://developer.oculus.com/licenses/oculussdk/
*
* Unless required by applicable law or agreed to in writing, the Oculus SDK
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
using UnityEngine;
namespace Oculus.Interaction
{
public class ConeUtils
{
public static bool RayWithinCone(Ray ray, Vector3 position, float apertureDegrees)
{
float minDotProductThreshold = Mathf.Cos(apertureDegrees * Mathf.Deg2Rad);
var vectorToInteractable = position - ray.origin;
var distanceToInteractable = vectorToInteractable.magnitude;
if (Mathf.Abs(distanceToInteractable) < 0.001f) return true;
vectorToInteractable /= distanceToInteractable;
var dotProduct = Vector3.Dot(vectorToInteractable, ray.direction);
return dotProduct >= minDotProductThreshold;
}
}
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 57e4c8fb882d4c2b8234cbdaa168a46e
timeCreated: 1632799161

View File

@ -0,0 +1,69 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
* All rights reserved.
*
* Licensed under the Oculus SDK License Agreement (the "License");
* you may not use the Oculus SDK except in compliance with the License,
* which is provided at the time of installation or download, or which
* otherwise accompanies this software in either electronic or hard copy form.
*
* You may obtain a copy of the License at
*
* https://developer.oculus.com/licenses/oculussdk/
*
* Unless required by applicable law or agreed to in writing, the Oculus SDK
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
using System;
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
namespace Oculus.Interaction
{
/// <summary>
/// This extension allows easily registering an unregistering callback at the EndOfFrame
/// which happens after rendering but before the next fixed Update.
/// Call RegisterEndOfFrameCallback to start receiving updates and
/// UnregisterEndOfFrameCallback to stop.
/// </summary>
internal static class MonoBehaviourEndOfFrameExtensions
{
private static YieldInstruction _endOfFrame = new WaitForEndOfFrame();
private static Dictionary<MonoBehaviour, Coroutine> _routines = new Dictionary<MonoBehaviour, Coroutine>();
internal static void RegisterEndOfFrameCallback(this MonoBehaviour monoBehaviour, Action callback)
{
if (_routines.ContainsKey(monoBehaviour))
{
throw new ArgumentException("This MonoBehaviour is already registered for the EndOfFrameCallback");
}
Coroutine routine = monoBehaviour.StartCoroutine(EndOfFrameCoroutine(callback));
_routines.Add(monoBehaviour, routine);
}
internal static void UnregisterEndOfFrameCallback(this MonoBehaviour monoBehaviour)
{
if (!_routines.ContainsKey(monoBehaviour))
{
throw new ArgumentException("This MonoBehaviour is not registered for the EndOfFrameCallback");
}
monoBehaviour.StopCoroutine(_routines[monoBehaviour]);
_routines.Remove(monoBehaviour);
}
private static IEnumerator EndOfFrameCoroutine(Action callback)
{
while (true)
{
yield return _endOfFrame;
callback.Invoke();
}
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 4963c9479a6c3c341b813b80a8e0fca6
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,37 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
* All rights reserved.
*
* Licensed under the Oculus SDK License Agreement (the "License");
* you may not use the Oculus SDK except in compliance with the License,
* which is provided at the time of installation or download, or which
* otherwise accompanies this software in either electronic or hard copy form.
*
* You may obtain a copy of the License at
*
* https://developer.oculus.com/licenses/oculussdk/
*
* Unless required by applicable law or agreed to in writing, the Oculus SDK
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
using System.Runtime.InteropServices;
using System.Security;
namespace Oculus.Interaction
{
/// <summary>
/// Native methods for Interactor
/// </summary>
[SuppressUnmanagedCodeSecurity]
internal static class NativeMethods
{
[DllImport("InteractionSdk")]
public static extern int isdk_NativeComponent_Activate(ulong id);
public const int IsdkSuccess = 0;
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: fa35f54c3240e4d4c85471af32b1fe2e
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,300 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
* All rights reserved.
*
* Licensed under the Oculus SDK License Agreement (the "License");
* you may not use the Oculus SDK except in compliance with the License,
* which is provided at the time of installation or download, or which
* otherwise accompanies this software in either electronic or hard copy form.
*
* You may obtain a copy of the License at
*
* https://developer.oculus.com/licenses/oculussdk/
*
* Unless required by applicable law or agreed to in writing, the Oculus SDK
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
using UnityEngine;
namespace Oculus.Interaction
{
/// <summary>
/// Tools for working with Unity Poses
/// </summary>
public static class PoseUtils
{
/// <summary>
/// Assigns a Pose to a given transform.
/// </summary>
/// <param name="transform"> The transform to which apply the pose.</param>
/// <param name="pose">The desired pose.</param>
/// <param name="space">If the pose should be applied to the local position/rotation or world position/rotation.</param>
public static void SetPose(this Transform transform, in Pose pose, Space space = Space.World)
{
if (space == Space.World)
{
transform.SetPositionAndRotation(pose.position, pose.rotation);
}
else
{
transform.localRotation = pose.rotation;
transform.localPosition = pose.position;
}
}
/// <summary>
/// Extract the position/rotation of a given transform.
/// </summary>
/// <param name="transform">The transform from which to extract the pose.</param>
/// <param name="space">If the desired position/rotation is the world or local one.</param>
/// <returns>A Pose containing the position/rotation of the transform.</returns>
public static Pose GetPose(this Transform transform, Space space = Space.World)
{
if (space == Space.World)
{
return new Pose(transform.position, transform.rotation);
}
else
{
return new Pose(transform.localPosition, transform.localRotation);
}
}
/// <summary>
/// Compose two poses, applying the first to the second one.
/// </summary>
/// <param name="a">First pose to compose.</param>
/// <param name="b">Pose to compose over the first one.</param>
/// <param name="result">A Pose with the two operands applied.</param>
public static void Multiply(in Pose a, in Pose b, ref Pose result)
{
result.position = a.position + a.rotation * b.position;
result.rotation = a.rotation * b.rotation;
}
public static Pose Multiply(in Pose a, in Pose b)
{
Pose result = new Pose();
Multiply(a, b, ref result);
return result;
}
/// <summary>
/// Compose two poses, applying the provided one on top of the caller.
/// </summary>
/// <param name="a">Pose to compose upon.</param>
/// <param name="b">Pose to compose over the first one.</param>
public static void Premultiply(this ref Pose a, in Pose b)
{
Multiply(a, b, ref a);
}
/// <summary>
/// Compose two poses, applying the caller on top of the provided pose.
/// </summary>
/// <param name="a">Pose to compose upon.</param>
/// <param name="b">Pose to compose over the first one.</param>
public static void Postmultiply(this ref Pose a, in Pose b)
{
Multiply(b, a, ref a);
}
/// <summary>
/// Moves the calling pose towards a target one using interpolation
/// </summary>
/// <param name="from">Original pose to interpolate from</param>
/// <param name="to">Target pose for the interpolation.</param>
/// <param name="t">Interpolation factor, normalized but will not be clamped.</param>
public static void Lerp(this ref Pose from, in Pose to, float t)
{
Lerp(from, to, t, ref from);
}
/// <summary>
/// Interpolation between two poses.
/// </summary>
/// <param name="from">From pose.</param>
/// <param name="to">To pose.</param>
/// <param name="t">Interpolation factor, normalized but will not be clamped.</param>
/// <param name="result">A Pose between a and b</param>
public static void Lerp(in Pose from, in Pose to, float t, ref Pose result)
{
result.position = Vector3.LerpUnclamped(from.position, to.position, t);
result.rotation = Quaternion.SlerpUnclamped(from.rotation, to.rotation, t);
}
public static void Inverse(in Pose a, ref Pose result)
{
result.rotation = Quaternion.Inverse(a.rotation);
result.position = result.rotation * -a.position;
}
public static void Invert(this ref Pose a)
{
Inverse(a, ref a);
}
public static void CopyFrom(this ref Pose to, in Pose from)
{
to.position = from.position;
to.rotation = from.rotation;
}
/// <summary>
/// Get the position/rotation difference between two transforms.
/// Unaffected by scale.
/// </summary>
/// <param name="from">The base transform.</param>
/// <param name="to">The target transform.</param>
/// <returns>A Pose indicating the position/rotation change</returns>
public static Pose Delta(this Transform from, Transform to)
{
return Delta(from.position, from.rotation, to.position, to.rotation);
}
/// <summary>
/// Get the position/rotation difference between a transform and a pose.
/// Unaffected by scale.
/// </summary>
/// <param name="from">The base transform.</param>
/// <param name="to">The target pose.</param>
/// <returns>A Pose indicating the delta.</returns>
public static Pose Delta(this Transform from, in Pose to)
{
return Delta(from.position, from.rotation, to.position, to.rotation);
}
/// <summary>
/// Get the position/rotation difference between a transform and a pose.
/// Unaffected by scale.
/// </summary>
/// <param name="from">The base transform.</param>
/// <param name="to">The target pose.</param>
/// <param name="result">Output: The pose with the delta</param>
public static void Delta(this Transform from, in Pose to, ref Pose result)
{
Delta(from.position, from.rotation, to.position, to.rotation, ref result);
}
/// <summary>
/// Get the position/rotation difference between two poses.
/// Unaffected by scale.
/// </summary>
/// <param name="from">The base pose.</param>
/// <param name="to">The target pose.</param>
/// <returns>A Pose indicating the delta.</returns>
public static Pose Delta(in Pose from, in Pose to)
{
return Delta(from.position, from.rotation, to.position, to.rotation);
}
/// <summary>
/// Get the position/rotation difference between two poses, indicated with separated positions and rotations.
/// </summary>
/// <param name="fromPosition">The base position.</param>
/// <param name="fromRotation">The base rotation.</param>
/// <param name="toPosition">The target position.</param>
/// <param name="toRotation">The target rotation.</param>
/// <returns>A Pose indicating the delta.</returns>
private static Pose Delta(Vector3 fromPosition, Quaternion fromRotation, Vector3 toPosition, Quaternion toRotation)
{
Pose result = new Pose();
Delta(fromPosition, fromRotation, toPosition, toRotation, ref result);
return result;
}
private static void Delta(Vector3 fromPosition, Quaternion fromRotation, Vector3 toPosition, Quaternion toRotation, ref Pose result)
{
Quaternion inverseFromRot = Quaternion.Inverse(fromRotation);
result.position = inverseFromRot * (toPosition - fromPosition);
result.rotation = inverseFromRot * toRotation;
}
/// <summary>
/// Get the position/rotation difference between two transforms.
/// Affected by the scale of from.
/// </summary>
/// <param name="from">The base transform.</param>
/// <param name="to">The target transform.</param>
/// <returns>Output: The pose with the delta</returns>
public static Pose DeltaScaled(Transform from, Transform to)
{
Pose delta;
delta.position = from.InverseTransformPoint(to.position);
delta.rotation = Quaternion.Inverse(from.rotation) * to.rotation;
return delta;
}
/// <summary>
/// Get the position/rotation difference between a transform and a pose.
/// Affected by the scale of from.
/// </summary>
/// <param name="from">The base transform.</param>
/// <param name="to">The target pose.</param>
/// <returns>The pose with the delta</returns>
public static Pose DeltaScaled(Transform from, Pose to)
{
Pose delta;
delta.position = from.InverseTransformPoint(to.position);
delta.rotation = Quaternion.Inverse(from.rotation) * to.rotation;
return delta;
}
/// <summary>
/// Get the world position/rotation of a relative position.
/// Unaffected by scale.
/// </summary>
/// <param name="reference">The transform in which the offset is local.</param>
/// <param name="offset">The offset from the reference.</param>
/// <returns>A Pose in world units.</returns>
public static Pose GlobalPose(this Transform reference, in Pose offset)
{
return new Pose(
reference.position + reference.rotation * offset.position,
reference.rotation * offset.rotation);
}
/// <summary>
/// Get the world position/rotation of a relative position.
/// Affected by the scale of the transform.
/// </summary>
/// <param name="relativeTo">The transform in which the offset is local.</param>
/// <param name="offset">The offset from the reference.</param>
/// <returns>A Pose in world units.</returns>
public static Pose GlobalPoseScaled(Transform relativeTo, Pose offset)
{
Pose pose;
pose.position = relativeTo.TransformPoint(offset.position);
pose.rotation = relativeTo.rotation * offset.rotation;
return pose;
}
/// <summary>
/// Rotate a pose around an axis.
/// </summary>
/// <param name="pose">The pose to mirror.</param>
/// <param name="normal">The direction of the mirror.</param>
/// <param name="tangent">The tangent of the mirror.</param>
/// <returns>A mirrored pose.</returns>
public static Pose MirrorPoseRotation(this in Pose pose, Vector3 normal, Vector3 tangent)
{
Pose mirrorPose = pose;
Vector3 forward = pose.rotation * -Vector3.forward;
Vector3 projectedForward = Vector3.ProjectOnPlane(forward, normal);
float angleForward = Vector3.SignedAngle(projectedForward, tangent, normal);
Vector3 mirrorForward = Quaternion.AngleAxis(2 * angleForward, normal) * forward;
Vector3 up = pose.rotation * -Vector3.up;
Vector3 projectedUp = Vector3.ProjectOnPlane(up, normal);
float angleUp = Vector3.SignedAngle(projectedUp, tangent, normal);
Vector3 mirrorUp = Quaternion.AngleAxis(2 * angleUp, normal) * up;
mirrorPose.rotation = Quaternion.LookRotation(mirrorForward, mirrorUp);
return mirrorPose;
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: e14a569bbf2df7941875327c2e66d6d4
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,143 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
* All rights reserved.
*
* Licensed under the Oculus SDK License Agreement (the "License");
* you may not use the Oculus SDK except in compliance with the License,
* which is provided at the time of installation or download, or which
* otherwise accompanies this software in either electronic or hard copy form.
*
* You may obtain a copy of the License at
*
* https://developer.oculus.com/licenses/oculussdk/
*
* Unless required by applicable law or agreed to in writing, the Oculus SDK
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
using System;
using UnityEngine;
namespace Oculus.Interaction
{
/// <summary>
/// ProgressCurve provides a helper for creating curves for easing.
/// In some respects it works like an AnimationCurve except that ProgressCurve
/// always takes in a normalized AnimationCurve and a second parameter
/// defines the length of the animation.
///
/// A few helper methods are provided to track progress through the animation.
/// </summary>
[Serializable]
public class ProgressCurve
{
[SerializeField]
private AnimationCurve _animationCurve;
public AnimationCurve AnimationCurve
{
get
{
return _animationCurve;
}
set
{
_animationCurve = value;
}
}
[SerializeField]
private float _animationLength;
public float AnimationLength
{
get
{
return _animationLength;
}
set
{
_animationLength = value;
}
}
private Func<float> _timeProvider = () => Time.time;
public Func<float> TimeProvider
{
get
{
return _timeProvider;
}
set
{
_timeProvider = value;
}
}
private float _animationStartTime;
public ProgressCurve()
{
_animationCurve = AnimationCurve.EaseInOut(0f, 0f, 1f, 1f);
_animationLength = 1.0f;
}
public ProgressCurve(AnimationCurve animationCurve, float animationLength)
{
_animationCurve = animationCurve;
_animationLength = animationLength;
}
public ProgressCurve(ProgressCurve other)
{
Copy(other);
}
public void Copy(ProgressCurve other)
{
_animationCurve = other._animationCurve;
_animationLength = other._animationLength;
_animationStartTime = other._animationStartTime;
_timeProvider = other._timeProvider;
}
public void Start()
{
_animationStartTime = _timeProvider();
}
public float Progress()
{
if (_animationLength <= 0f)
{
return _animationCurve.Evaluate(1.0f);
}
float normalizedTimeProgress = Mathf.Clamp01(ProgressTime() / _animationLength);
return _animationCurve.Evaluate(normalizedTimeProgress);
}
public float ProgressIn(float time)
{
if (_animationLength <= 0f)
{
return _animationCurve.Evaluate(1.0f);
}
float normalizedTimeProgress = Mathf.Clamp01((ProgressTime() + time) / _animationLength);
return _animationCurve.Evaluate(normalizedTimeProgress);
}
public float ProgressTime()
{
return Mathf.Clamp(_timeProvider() - _animationStartTime, 0f, _animationLength);
}
public void End()
{
_animationStartTime = _timeProvider() - _animationLength;
}
}
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: b5e7786aac2a4568a735ea49fe66f278
timeCreated: 1632508318

View File

@ -0,0 +1,87 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
* All rights reserved.
*
* Licensed under the Oculus SDK License Agreement (the "License");
* you may not use the Oculus SDK except in compliance with the License,
* which is provided at the time of installation or download, or which
* otherwise accompanies this software in either electronic or hard copy form.
*
* You may obtain a copy of the License at
*
* https://developer.oculus.com/licenses/oculussdk/
*
* Unless required by applicable law or agreed to in writing, the Oculus SDK
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
using UnityEngine;
using Oculus.Interaction.Surfaces;
namespace Oculus.Interaction
{
/// <summary>
/// Tools for working Surfaces on Interactables
/// </summary>
public static class SurfaceUtils
{
/// <summary>
/// The distance above a surface along the closest normal.
/// Returns 0 for where the sphere touches the surface along the normal.
/// </summary>
/// <param name="interactable"> The PokeInteractable surface to test</param>
/// <param name="point"> The origin point to compute distance from the surface</param>
/// <param name="radius"> The radius of the sphere positioned at the origin point</param>
public static float ComputeDistanceAbove(ISurfacePatch surfacePatch, Vector3 point, float radius)
{
surfacePatch.BackingSurface.ClosestSurfacePoint(point, out SurfaceHit hit);
Vector3 surfaceToPoint = point - hit.Point;
return Vector3.Dot(surfaceToPoint, hit.Normal) - radius;
}
/// <summary>
/// The distance to a surface along the tangent.
/// </summary>
/// <param name="interactable"> The PokeInteractable surface to test</param>
/// <param name="point"> The origin point to compute distance from the surface</param>
/// <param name="radius"> The radius of the sphere positioned at the origin point</param>
public static float ComputeTangentDistance(ISurfacePatch surfacePatch, Vector3 point, float radius)
{
surfacePatch.ClosestSurfacePoint(point, out SurfaceHit patchHit);
surfacePatch.BackingSurface.ClosestSurfacePoint(point, out SurfaceHit backingHit);
Vector3 proximityToPoint = point - patchHit.Point;
Vector3 projOnNormal = Vector3.Dot(proximityToPoint, backingHit.Normal) *
backingHit.Normal;
Vector3 lateralVec = proximityToPoint - projOnNormal;
return lateralVec.magnitude - radius;
}
/// <summary>
/// The distance below a surface along the closest normal. always positive.
/// </summary>
/// <param name="interactable"> the pokeinteractable surface to test</param>
/// <param name="point"> the origin point to compute distance from the surface</param>
/// <param name="radius"> the radius of the sphere positioned at the origin point</param>
public static float ComputeDepth(ISurfacePatch surfacePatch, Vector3 point, float radius)
{
return Mathf.Max(0f, -ComputeDistanceAbove(surfacePatch, point, radius));
}
/// <summary>
/// The distance from the closest point as computed by the proximity field and surface.
/// Returns the distance to the point without taking into account the surface normal.
/// </summary>
/// <param name="interactable"> the pokeinteractable surface to test</param>
/// <param name="point"> the origin point to compute distance from the surface</param>
/// <param name="radius"> the radius of the sphere positioned at the origin point</param>
public static float ComputeDistanceFrom(ISurfacePatch surfacePatch, Vector3 point, float radius)
{
surfacePatch.ClosestSurfacePoint(point, out SurfaceHit hit);
Vector3 surfaceToPoint = point - hit.Point;
return surfaceToPoint.magnitude - radius;
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: ac17132688fa96946843f199ad9da593
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,52 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
* All rights reserved.
*
* Licensed under the Oculus SDK License Agreement (the "License");
* you may not use the Oculus SDK except in compliance with the License,
* which is provided at the time of installation or download, or which
* otherwise accompanies this software in either electronic or hard copy form.
*
* You may obtain a copy of the License at
*
* https://developer.oculus.com/licenses/oculussdk/
*
* Unless required by applicable law or agreed to in writing, the Oculus SDK
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
using TMPro;
using UnityEngine;
using UnityEngine.Assertions;
namespace Oculus.Interaction
{
public class VersionTextVisual : MonoBehaviour
{
[SerializeField]
private TextMeshPro _text;
protected virtual void Start()
{
this.AssertField(_text, nameof(_text));
_text.text = "Version: " + Application.version;
}
#region Inject
public void InjectAllVersionTextVisual(TextMeshPro text)
{
InjectText(text);
}
public void InjectText(TextMeshPro text)
{
_text = text;
}
#endregion
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: a6e92325d3f262043b29d3fb96464192
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: