Initialer Upload neues Unity-Projekt
This commit is contained in:
@ -0,0 +1,183 @@
|
||||
/*
|
||||
* 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 System.Collections.Generic;
|
||||
|
||||
namespace Oculus.Interaction
|
||||
{
|
||||
/// <summary>
|
||||
/// Non-allocating HashSet extension methods mirroring MS implementation
|
||||
/// https://referencesource.microsoft.com/#system.core/system/Collections/Generic/HashSet.cs
|
||||
/// </summary>
|
||||
public static class HashSetExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Take the union of this HashSet with other. Modifies this set.
|
||||
/// </summary>
|
||||
/// <param name="other">HashSet with items to add</param>
|
||||
public static void UnionWithNonAlloc<T>(this HashSet<T> hashSetToModify, HashSet<T> other)
|
||||
{
|
||||
if (hashSetToModify == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(hashSetToModify));
|
||||
}
|
||||
if (other == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(other));
|
||||
}
|
||||
foreach (T item in other)
|
||||
{
|
||||
hashSetToModify.Add(item);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Take the union of this HashSet with other. Modifies this set.
|
||||
/// </summary>
|
||||
/// <param name="other">IList with items to add</param>
|
||||
public static void UnionWithNonAlloc<T>(this HashSet<T> hashSetToModify, IList<T> other)
|
||||
{
|
||||
if (hashSetToModify == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(hashSetToModify));
|
||||
}
|
||||
if (other == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(other));
|
||||
}
|
||||
for (int i = 0; i < other.Count; ++i)
|
||||
{
|
||||
hashSetToModify.Add(other[i]);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remove items in other from this set. Modifies this set
|
||||
/// </summary>
|
||||
/// <param name="other">HashSet with items to remove</param>
|
||||
public static void ExceptWithNonAlloc<T>(this HashSet<T> hashSetToModify, HashSet<T> other)
|
||||
{
|
||||
if (hashSetToModify == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(hashSetToModify));
|
||||
}
|
||||
if (other == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(other));
|
||||
}
|
||||
if (hashSetToModify.Count == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (other == hashSetToModify)
|
||||
{
|
||||
hashSetToModify.Clear();
|
||||
return;
|
||||
}
|
||||
foreach (T element in other)
|
||||
{
|
||||
hashSetToModify.Remove(element);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remove items in other from this set. Modifies this set
|
||||
/// </summary>
|
||||
/// <param name="other">IList with items to remove</param>
|
||||
public static void ExceptWithNonAlloc<T>(this HashSet<T> hashSetToModify, IList<T> other)
|
||||
{
|
||||
if (hashSetToModify == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(hashSetToModify));
|
||||
}
|
||||
if (other == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(other));
|
||||
}
|
||||
if (hashSetToModify.Count == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
for (int i = 0; i < other.Count; ++i)
|
||||
{
|
||||
hashSetToModify.Remove(other[i]);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if this set overlaps other (i.e. they share at least one item)
|
||||
/// </summary>
|
||||
/// <param name="other">HashSet to check overlap against</param>
|
||||
/// <returns>true if these have at least one common element; false if disjoint</returns>
|
||||
public static bool OverlapsNonAlloc<T>(this HashSet<T> hashSetToCheck, HashSet<T> other)
|
||||
{
|
||||
if (hashSetToCheck == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(hashSetToCheck));
|
||||
}
|
||||
if (other == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(other));
|
||||
}
|
||||
if (hashSetToCheck.Count == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
foreach (T element in other)
|
||||
{
|
||||
if (hashSetToCheck.Contains(element))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if this set overlaps other (i.e. they share at least one item)
|
||||
/// </summary>
|
||||
/// <param name="other">IList to check overlap against</param>
|
||||
/// <returns>true if these have at least one common element; false if disjoint</returns>
|
||||
public static bool OverlapsNonAlloc<T>(this HashSet<T> hashSetToCheck, IList<T> other)
|
||||
{
|
||||
if (hashSetToCheck == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(hashSetToCheck));
|
||||
}
|
||||
if (other == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(other));
|
||||
}
|
||||
if (hashSetToCheck.Count == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
for (int i = 0; i < other.Count; ++i)
|
||||
{
|
||||
if (hashSetToCheck.Contains(other[i]))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 09d0907b32d460349ae989d67adb26ee
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -0,0 +1,61 @@
|
||||
/*
|
||||
* 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>
|
||||
/// By adding BeginStart and EndStart at the beginning and end of Start, MonoBehaviours with
|
||||
/// OnEnable and OnDisable logic can wrap their contents within a _started flag and effectively
|
||||
/// skip over logic in those methods until after Start has been invoked.
|
||||
///
|
||||
/// To not bypass the Unity Lifecycle, the enabled property is used to disable the most derived
|
||||
/// MonoBehaviour, invoke Start up the hierarchy chain, and finally re-enable the MonoBehaviour.
|
||||
/// </summary>
|
||||
public static class MonoBehaviourStartExtensions
|
||||
{
|
||||
public static void BeginStart(this MonoBehaviour monoBehaviour, ref bool started,
|
||||
Action baseStart = null)
|
||||
{
|
||||
if (!started)
|
||||
{
|
||||
monoBehaviour.enabled = false;
|
||||
started = true;
|
||||
baseStart?.Invoke();
|
||||
started = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
baseStart?.Invoke();
|
||||
}
|
||||
}
|
||||
|
||||
public static void EndStart(this MonoBehaviour monoBehaviour, ref bool started)
|
||||
{
|
||||
if (!started)
|
||||
{
|
||||
started = true;
|
||||
monoBehaviour.enabled = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7e905110e6125b442b02d7a80ba72015
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -0,0 +1,91 @@
|
||||
/*
|
||||
* 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 TransformExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Transforms position from world space to local space
|
||||
/// </summary>
|
||||
public static Vector3 InverseTransformPointUnscaled(this Transform transform, Vector3 position)
|
||||
{
|
||||
Matrix4x4 worldToLocal = Matrix4x4.TRS(transform.position, transform.rotation, Vector3.one).inverse;
|
||||
return worldToLocal.MultiplyPoint3x4(position);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Transforms position from local space to world space
|
||||
/// </summary>
|
||||
public static Vector3 TransformPointUnscaled(this Transform transform, Vector3 position)
|
||||
{
|
||||
Matrix4x4 localToWorld = Matrix4x4.TRS(transform.position, transform.rotation, Vector3.one);
|
||||
return localToWorld.MultiplyPoint3x4(position);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Transform a bounding box from local to world space.
|
||||
/// </summary>
|
||||
/// <param name="transform">Transfrom that
|
||||
/// <paramref name="bounds"/> is local to</param>
|
||||
/// <param name="bounds">The bounds to transform, in local space</param>
|
||||
/// <returns>The bounding box in world space</returns>
|
||||
public static Bounds TransformBounds(this Transform transform, in Bounds bounds)
|
||||
{
|
||||
Bounds worldBounds = new Bounds();
|
||||
|
||||
Vector3 boundsMin = bounds.min;
|
||||
Vector3 boundsMax = bounds.max;
|
||||
Vector3 min = transform.position;
|
||||
Vector3 max = transform.position;
|
||||
Matrix4x4 m = transform.localToWorldMatrix;
|
||||
|
||||
for (int i = 0; i < 3; ++i)
|
||||
{
|
||||
for (int j = 0; j < 3; ++j)
|
||||
{
|
||||
float e = m[i, j] * boundsMin[j];
|
||||
float f = m[i, j] * boundsMax[j];
|
||||
min[i] += (e < f) ? e : f;
|
||||
max[i] += (e < f) ? f : e;
|
||||
}
|
||||
}
|
||||
|
||||
worldBounds.SetMinMax(min, max);
|
||||
return worldBounds;
|
||||
}
|
||||
|
||||
public static Transform FindChildRecursive(this Transform parent, string name)
|
||||
{
|
||||
foreach (Transform child in parent)
|
||||
{
|
||||
if (child.name.Contains(name))
|
||||
return child;
|
||||
|
||||
var result = child.FindChildRecursive(name);
|
||||
if (result != null)
|
||||
return result;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0efedf2e13db9f24c88029611537cf97
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -0,0 +1,36 @@
|
||||
/*
|
||||
* 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 VectorExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Are two points within <see cref="Vector3.kEpsilon"/>
|
||||
/// distance of each other
|
||||
/// </summary>
|
||||
public static bool Approximately(this Vector3 a, Vector3 b, float epsilon = Vector3.kEpsilon)
|
||||
{
|
||||
return (a - b).sqrMagnitude <= epsilon * epsilon;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 08b019013fb2a7143befda25a24a2ac0
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user