Initialer Upload neues Unity-Projekt
This commit is contained in:
@ -0,0 +1,317 @@
|
||||
/*
|
||||
* 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 Oculus.Interaction.Surfaces;
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Oculus.Interaction.UnityCanvas
|
||||
{
|
||||
public class CanvasCylinder : CanvasMesh, ICurvedPlane, ICylinderClipper
|
||||
{
|
||||
[Serializable]
|
||||
public struct MeshGenerationSettings
|
||||
{
|
||||
[Delayed]
|
||||
public float VerticesPerDegree;
|
||||
|
||||
[Delayed]
|
||||
public int MaxHorizontalResolution;
|
||||
|
||||
[Delayed]
|
||||
public int MaxVerticalResolution;
|
||||
}
|
||||
|
||||
public const int MIN_RESOLUTION = 2;
|
||||
|
||||
[SerializeField]
|
||||
[Tooltip("The cylinder used to dictate the position and radius of the mesh.")]
|
||||
private Cylinder _cylinder;
|
||||
|
||||
[SerializeField]
|
||||
[Tooltip("Determines how the mesh is projected on the cylinder wall. " +
|
||||
"Vertical results in a left-to-right curvature, Horizontal results in a top-to-bottom curvature.")]
|
||||
private CylinderOrientation _orientation = CylinderOrientation.Vertical;
|
||||
|
||||
[SerializeField]
|
||||
private MeshGenerationSettings _meshGeneration = new MeshGenerationSettings()
|
||||
{
|
||||
VerticesPerDegree = 1.4f,
|
||||
MaxHorizontalResolution = 128,
|
||||
MaxVerticalResolution = 32
|
||||
};
|
||||
|
||||
public float Radius => _cylinder.Radius;
|
||||
public Cylinder Cylinder => _cylinder;
|
||||
public float ArcDegrees { get; private set; }
|
||||
public float Rotation { get; private set; }
|
||||
public float Bottom { get; private set; }
|
||||
public float Top { get; private set; }
|
||||
|
||||
private float CylinderRelativeScale => _cylinder.transform.lossyScale.x / transform.lossyScale.x;
|
||||
|
||||
public bool GetCylinderSegment(out CylinderSegment segment)
|
||||
{
|
||||
segment = new CylinderSegment(Rotation, ArcDegrees, Bottom, Top);
|
||||
return _started && isActiveAndEnabled;
|
||||
}
|
||||
|
||||
protected override void Start()
|
||||
{
|
||||
this.BeginStart(ref _started, () => base.Start());
|
||||
this.AssertField(_cylinder, nameof(_cylinder));
|
||||
this.EndStart(ref _started);
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
protected virtual void OnValidate()
|
||||
{
|
||||
_meshGeneration.MaxHorizontalResolution = Mathf.Max(MIN_RESOLUTION,
|
||||
_meshGeneration.MaxHorizontalResolution);
|
||||
_meshGeneration.MaxVerticalResolution = Mathf.Max(MIN_RESOLUTION,
|
||||
_meshGeneration.MaxVerticalResolution);
|
||||
_meshGeneration.VerticesPerDegree = Mathf.Max(0, _meshGeneration.VerticesPerDegree);
|
||||
|
||||
if (Application.isPlaying && _started)
|
||||
{
|
||||
EditorApplication.delayCall += () =>
|
||||
{
|
||||
UpdateImposter();
|
||||
};
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
protected override void UpdateImposter()
|
||||
{
|
||||
base.UpdateImposter();
|
||||
UpdateMeshPosition();
|
||||
UpdateCurvedPlane();
|
||||
}
|
||||
|
||||
protected override Vector3 MeshInverseTransform(Vector3 localPosition)
|
||||
{
|
||||
float angle = Mathf.Atan2(localPosition.x, localPosition.z + Radius);
|
||||
float x = angle * Radius;
|
||||
float y = localPosition.y;
|
||||
return new Vector3(x, y);
|
||||
}
|
||||
|
||||
protected override void GenerateMesh(out List<Vector3> verts,
|
||||
out List<int> tris,
|
||||
out List<Vector2> uvs)
|
||||
{
|
||||
verts = new List<Vector3>();
|
||||
tris = new List<int>();
|
||||
uvs = new List<Vector2>();
|
||||
|
||||
Vector2 worldSize = GetWorldSize();
|
||||
float scaledRadius = Radius * CylinderRelativeScale;
|
||||
|
||||
float xPos = worldSize.x * 0.5f;
|
||||
float xNeg = -xPos;
|
||||
float yPos = worldSize.y * 0.5f;
|
||||
float yNeg = -yPos;
|
||||
|
||||
Vector2Int GetClampedResolution(float arcMax, float axisMax)
|
||||
{
|
||||
int horizontalResolution = Mathf.Max(2,
|
||||
Mathf.RoundToInt(_meshGeneration.VerticesPerDegree *
|
||||
Mathf.Rad2Deg * arcMax / scaledRadius));
|
||||
int verticalResolution =
|
||||
Mathf.Max(2, Mathf.RoundToInt(horizontalResolution * axisMax / arcMax));
|
||||
|
||||
horizontalResolution = Mathf.Clamp(horizontalResolution, 2,
|
||||
_meshGeneration.MaxHorizontalResolution);
|
||||
verticalResolution = Mathf.Clamp(verticalResolution, 2,
|
||||
_meshGeneration.MaxVerticalResolution);
|
||||
|
||||
return new Vector2Int(horizontalResolution, verticalResolution);
|
||||
}
|
||||
|
||||
Vector3 GetCurvedPoint(float u, float v)
|
||||
{
|
||||
float x = Mathf.Lerp(xNeg, xPos, u);
|
||||
float y = Mathf.Lerp(yNeg, yPos, v);
|
||||
|
||||
float angle;
|
||||
Vector3 point;
|
||||
|
||||
switch (_orientation)
|
||||
{
|
||||
default:
|
||||
case CylinderOrientation.Vertical:
|
||||
angle = x / scaledRadius;
|
||||
point.x = Mathf.Sin(angle) * scaledRadius;
|
||||
point.y = y;
|
||||
point.z = Mathf.Cos(angle) * scaledRadius - scaledRadius;
|
||||
break;
|
||||
case CylinderOrientation.Horizontal:
|
||||
angle = y / scaledRadius;
|
||||
point.x = x;
|
||||
point.y = Mathf.Sin(angle) * scaledRadius;
|
||||
point.z = Mathf.Cos(angle) * scaledRadius - scaledRadius;
|
||||
break;
|
||||
}
|
||||
return point;
|
||||
}
|
||||
|
||||
Vector2Int resolution;
|
||||
switch (_orientation)
|
||||
{
|
||||
default:
|
||||
case CylinderOrientation.Vertical:
|
||||
resolution = GetClampedResolution(xPos, yPos);
|
||||
break;
|
||||
case CylinderOrientation.Horizontal:
|
||||
resolution = GetClampedResolution(yPos, xPos);
|
||||
break;
|
||||
}
|
||||
|
||||
for (int y = 0; y < resolution.y; y++)
|
||||
{
|
||||
for (int x = 0; x < resolution.x; x++)
|
||||
{
|
||||
float u = x / (resolution.x - 1.0f);
|
||||
float v = y / (resolution.y - 1.0f);
|
||||
|
||||
verts.Add(GetCurvedPoint(u, v));
|
||||
uvs.Add(new Vector2(u, v));
|
||||
}
|
||||
}
|
||||
|
||||
for (int y = 0; y < resolution.y - 1; y++)
|
||||
{
|
||||
for (int x = 0; x < resolution.x - 1; x++)
|
||||
{
|
||||
int v00 = x + y * resolution.x;
|
||||
int v10 = v00 + 1;
|
||||
int v01 = v00 + resolution.x;
|
||||
int v11 = v00 + 1 + resolution.x;
|
||||
|
||||
tris.Add(v00);
|
||||
tris.Add(v11);
|
||||
tris.Add(v10);
|
||||
|
||||
tris.Add(v00);
|
||||
tris.Add(v01);
|
||||
tris.Add(v11);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateMeshPosition()
|
||||
{
|
||||
Vector3 posInCylinder = _cylinder.transform.InverseTransformPoint(transform.position);
|
||||
|
||||
Vector3 localYOffset = new Vector3(0, posInCylinder.y, 0);
|
||||
Vector3 localCancelY = posInCylinder - localYOffset;
|
||||
|
||||
// If canvas position is on cylinder center axis, project forward.
|
||||
// Otherwise, project canvas onto cylinder wall from center axis.
|
||||
Vector3 projection = Mathf.Approximately(localCancelY.sqrMagnitude, 0f) ?
|
||||
Vector3.forward : localCancelY.normalized;
|
||||
|
||||
Vector3 localUp;
|
||||
switch (_orientation)
|
||||
{
|
||||
default:
|
||||
case CylinderOrientation.Vertical:
|
||||
localUp = Vector3.up;
|
||||
break;
|
||||
case CylinderOrientation.Horizontal:
|
||||
localUp = Vector3.right;
|
||||
break;
|
||||
}
|
||||
|
||||
transform.position = _cylinder.transform.TransformPoint((projection * _cylinder.Radius) + localYOffset);
|
||||
transform.rotation = _cylinder.transform.rotation * Quaternion.LookRotation(projection, localUp);
|
||||
|
||||
if (_meshCollider != null &&
|
||||
_meshCollider.transform != transform &&
|
||||
!transform.IsChildOf(_meshCollider.transform))
|
||||
{
|
||||
_meshCollider.transform.position = transform.position;
|
||||
_meshCollider.transform.rotation = transform.rotation;
|
||||
_meshCollider.transform.localScale *= transform.lossyScale.x / _meshCollider.transform.lossyScale.x;
|
||||
}
|
||||
}
|
||||
|
||||
private Vector2 GetWorldSize()
|
||||
{
|
||||
Vector2Int resolution = _canvasRenderTexture.GetBaseResolutionToUse();
|
||||
float width = _canvasRenderTexture.PixelsToUnits(Mathf.RoundToInt(resolution.x));
|
||||
float height = _canvasRenderTexture.PixelsToUnits(Mathf.RoundToInt(resolution.y));
|
||||
return new Vector2(width, height) / transform.lossyScale;
|
||||
}
|
||||
|
||||
private void UpdateCurvedPlane()
|
||||
{
|
||||
// Get world size in cylinder space
|
||||
Vector2 cylinderSize = GetWorldSize() / CylinderRelativeScale;
|
||||
|
||||
float arcSize, axisSize;
|
||||
switch (_orientation)
|
||||
{
|
||||
default:
|
||||
case CylinderOrientation.Vertical:
|
||||
arcSize = cylinderSize.x;
|
||||
axisSize = cylinderSize.y;
|
||||
break;
|
||||
case CylinderOrientation.Horizontal:
|
||||
arcSize = cylinderSize.y;
|
||||
axisSize = cylinderSize.x;
|
||||
break;
|
||||
}
|
||||
|
||||
Vector3 posInCylinder = Cylinder.transform.InverseTransformPoint(transform.position);
|
||||
Rotation = Mathf.Atan2(posInCylinder.x, posInCylinder.z) * Mathf.Rad2Deg;
|
||||
ArcDegrees = (arcSize * 0.5f / Radius) * 2f * Mathf.Rad2Deg;
|
||||
Top = posInCylinder.y + (axisSize * 0.5f);
|
||||
Bottom = posInCylinder.y - (axisSize * 0.5f);
|
||||
}
|
||||
|
||||
#region Inject
|
||||
|
||||
public void InjectAllCanvasCylinder(CanvasRenderTexture canvasRenderTexture,
|
||||
MeshFilter meshFilter,
|
||||
Cylinder cylinder,
|
||||
CylinderOrientation orientation)
|
||||
{
|
||||
InjectAllCanvasMesh(canvasRenderTexture, meshFilter);
|
||||
InjectCylinder(cylinder);
|
||||
InjectOrientation(orientation);
|
||||
}
|
||||
|
||||
public void InjectCylinder(Cylinder cylinder)
|
||||
{
|
||||
_cylinder = cylinder;
|
||||
}
|
||||
|
||||
public void InjectOrientation(CylinderOrientation orientation)
|
||||
{
|
||||
_orientation = orientation;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 85ef10d17088b3c4cad9a5d13887b157
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -0,0 +1,149 @@
|
||||
/*
|
||||
* 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 UnityEngine;
|
||||
using UnityEngine.Profiling;
|
||||
|
||||
namespace Oculus.Interaction.UnityCanvas
|
||||
{
|
||||
[DisallowMultipleComponent]
|
||||
public abstract class CanvasMesh : MonoBehaviour
|
||||
{
|
||||
[Tooltip("Mesh construction will be driven by this texture.")]
|
||||
[SerializeField]
|
||||
protected CanvasRenderTexture _canvasRenderTexture;
|
||||
|
||||
[Tooltip("The mesh filter that will be driven.")]
|
||||
[SerializeField]
|
||||
protected MeshFilter _meshFilter;
|
||||
|
||||
[Tooltip("Optional mesh collider that will be driven.")]
|
||||
[SerializeField, Optional]
|
||||
protected MeshCollider _meshCollider = null;
|
||||
|
||||
protected bool _started = false;
|
||||
|
||||
protected abstract Vector3 MeshInverseTransform(Vector3 localPosition);
|
||||
|
||||
protected abstract void GenerateMesh(out List<Vector3> verts, out List<int> tris, out List<Vector2> uvs);
|
||||
|
||||
/// <summary>
|
||||
/// Transform a position in world space relative to the imposter to an associated position relative
|
||||
/// to the original canvas in world space.
|
||||
/// </summary>
|
||||
public Vector3 ImposterToCanvasTransformPoint(Vector3 worldPosition)
|
||||
{
|
||||
Vector3 localToImposter =
|
||||
_meshFilter.transform.InverseTransformPoint(worldPosition);
|
||||
Vector3 canvasLocalPosition = MeshInverseTransform(localToImposter) /
|
||||
_canvasRenderTexture.transform.localScale.x;
|
||||
Vector3 transformedWorldPosition = _canvasRenderTexture.transform.TransformPoint(canvasLocalPosition);
|
||||
return transformedWorldPosition;
|
||||
}
|
||||
|
||||
protected virtual void Start()
|
||||
{
|
||||
this.BeginStart(ref _started);
|
||||
this.AssertField(_meshFilter, nameof(_meshFilter));
|
||||
this.AssertField(_canvasRenderTexture, nameof(_canvasRenderTexture));
|
||||
this.EndStart(ref _started);
|
||||
}
|
||||
|
||||
protected virtual void OnEnable()
|
||||
{
|
||||
if (_started)
|
||||
{
|
||||
UpdateImposter();
|
||||
|
||||
_canvasRenderTexture.OnUpdateRenderTexture += HandleUpdateRenderTexture;
|
||||
if (_canvasRenderTexture.Texture != null)
|
||||
{
|
||||
HandleUpdateRenderTexture(_canvasRenderTexture.Texture);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void OnDisable()
|
||||
{
|
||||
if (_started)
|
||||
{
|
||||
_canvasRenderTexture.OnUpdateRenderTexture -= HandleUpdateRenderTexture;
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void HandleUpdateRenderTexture(Texture texture)
|
||||
{
|
||||
UpdateImposter();
|
||||
}
|
||||
|
||||
protected virtual void UpdateImposter()
|
||||
{
|
||||
Profiler.BeginSample("InterfaceRenderer.UpdateImposter");
|
||||
try
|
||||
{
|
||||
GenerateMesh(out List<Vector3> verts, out List<int> tris, out List<Vector2> uvs);
|
||||
|
||||
Mesh mesh = new Mesh();
|
||||
mesh.SetVertices(verts);
|
||||
mesh.SetUVs(0, uvs);
|
||||
mesh.SetTriangles(tris, 0);
|
||||
|
||||
mesh.RecalculateBounds();
|
||||
mesh.RecalculateNormals();
|
||||
|
||||
_meshFilter.mesh = mesh;
|
||||
if (_meshCollider != null)
|
||||
{
|
||||
_meshCollider.sharedMesh = _meshFilter.sharedMesh;
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
Profiler.EndSample();
|
||||
}
|
||||
}
|
||||
|
||||
#region Inject
|
||||
|
||||
public void InjectAllCanvasMesh(CanvasRenderTexture canvasRenderTexture, MeshFilter meshFilter)
|
||||
{
|
||||
InjectCanvasRenderTexture(canvasRenderTexture);
|
||||
InjectMeshFilter(meshFilter);
|
||||
}
|
||||
|
||||
public void InjectCanvasRenderTexture(CanvasRenderTexture canvasRenderTexture)
|
||||
{
|
||||
_canvasRenderTexture = canvasRenderTexture;
|
||||
}
|
||||
|
||||
public void InjectMeshFilter(MeshFilter meshFilter)
|
||||
{
|
||||
_meshFilter = meshFilter;
|
||||
}
|
||||
|
||||
public void InjectOptionalMeshCollider(MeshCollider meshCollider)
|
||||
{
|
||||
_meshCollider = meshCollider;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1e17f00312f4fea429367cb5b305689d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -0,0 +1,188 @@
|
||||
/*
|
||||
* 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 UnityEngine.Profiling;
|
||||
|
||||
namespace Oculus.Interaction.UnityCanvas
|
||||
{
|
||||
public class CanvasMeshRenderer : MonoBehaviour
|
||||
{
|
||||
private static readonly int MainTexShaderID = Shader.PropertyToID("_MainTex");
|
||||
|
||||
[Tooltip("The canvas texture that will be rendered.")]
|
||||
[SerializeField]
|
||||
protected CanvasRenderTexture _canvasRenderTexture;
|
||||
|
||||
[Tooltip("The mesh renderer that will be driven.")]
|
||||
[SerializeField]
|
||||
protected MeshRenderer _meshRenderer;
|
||||
|
||||
[Tooltip("Determines the shader used for rendering. " +
|
||||
"See the documentation for details on these rendering modes.")]
|
||||
[SerializeField]
|
||||
protected int _renderingMode = (int)RenderingMode.AlphaCutout;
|
||||
|
||||
[Tooltip("Requires MSAA. Provides limited transparency useful for " +
|
||||
"anti-aliasing soft edges of UI elements.")]
|
||||
[SerializeField]
|
||||
private bool _useAlphaToMask = true;
|
||||
|
||||
[Tooltip("Select the alpha cutoff used for the cutout rendering.")]
|
||||
[Range(0, 1)]
|
||||
[SerializeField]
|
||||
private float _alphaCutoutThreshold = 0.5f;
|
||||
|
||||
private RenderingMode RenderingMode => (RenderingMode)_renderingMode;
|
||||
|
||||
protected virtual string GetShaderName()
|
||||
{
|
||||
switch (RenderingMode)
|
||||
{
|
||||
case RenderingMode.AlphaBlended:
|
||||
return "Hidden/Imposter_AlphaBlended";
|
||||
case RenderingMode.AlphaCutout:
|
||||
if (_useAlphaToMask)
|
||||
{
|
||||
return "Hidden/Imposter_AlphaToMask";
|
||||
}
|
||||
else
|
||||
{
|
||||
return "Hidden/Imposter_AlphaCutout";
|
||||
}
|
||||
default:
|
||||
case RenderingMode.Opaque:
|
||||
return "Hidden/Imposter_Opaque";
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void SetAdditionalProperties(MaterialPropertyBlock block)
|
||||
{
|
||||
block.SetFloat("_Cutoff", GetAlphaCutoutThreshold());
|
||||
}
|
||||
|
||||
protected virtual float GetAlphaCutoutThreshold()
|
||||
{
|
||||
if (RenderingMode == RenderingMode.AlphaCutout &&
|
||||
!_useAlphaToMask)
|
||||
{
|
||||
return _alphaCutoutThreshold;
|
||||
}
|
||||
return 1f;
|
||||
}
|
||||
|
||||
protected Material _material;
|
||||
protected bool _started;
|
||||
|
||||
protected virtual void HandleUpdateRenderTexture(Texture texture)
|
||||
{
|
||||
_meshRenderer.material = _material;
|
||||
var block = new MaterialPropertyBlock();
|
||||
_meshRenderer.GetPropertyBlock(block);
|
||||
block.SetTexture(MainTexShaderID, texture);
|
||||
SetAdditionalProperties(block);
|
||||
_meshRenderer.SetPropertyBlock(block);
|
||||
}
|
||||
|
||||
protected virtual void Start()
|
||||
{
|
||||
this.BeginStart(ref _started);
|
||||
this.AssertField(_meshRenderer, nameof(_meshRenderer));
|
||||
this.AssertField(_canvasRenderTexture, nameof(_canvasRenderTexture));
|
||||
this.EndStart(ref _started);
|
||||
}
|
||||
|
||||
protected virtual void OnEnable()
|
||||
{
|
||||
if (_started)
|
||||
{
|
||||
Profiler.BeginSample("InterfaceRenderer.UpdateMaterial");
|
||||
try
|
||||
{
|
||||
_material = new Material(Shader.Find(GetShaderName()));
|
||||
}
|
||||
finally
|
||||
{
|
||||
Profiler.EndSample();
|
||||
}
|
||||
|
||||
_canvasRenderTexture.OnUpdateRenderTexture += HandleUpdateRenderTexture;
|
||||
if (_canvasRenderTexture.Texture != null)
|
||||
{
|
||||
HandleUpdateRenderTexture(_canvasRenderTexture.Texture);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void OnDisable()
|
||||
{
|
||||
if (_started)
|
||||
{
|
||||
if (_material != null)
|
||||
{
|
||||
Destroy(_material);
|
||||
_material = null;
|
||||
}
|
||||
_canvasRenderTexture.OnUpdateRenderTexture -= HandleUpdateRenderTexture;
|
||||
}
|
||||
}
|
||||
|
||||
public static partial class Properties
|
||||
{
|
||||
public static readonly string RenderingMode = nameof(_renderingMode);
|
||||
public static readonly string UseAlphaToMask = nameof(_useAlphaToMask);
|
||||
public static readonly string AlphaCutoutThreshold = nameof(_alphaCutoutThreshold);
|
||||
}
|
||||
|
||||
#region Inject
|
||||
public void InjectAllCanvasMeshRenderer(CanvasRenderTexture canvasRenderTexture,
|
||||
MeshRenderer meshRenderer)
|
||||
{
|
||||
InjectCanvasRenderTexture(canvasRenderTexture);
|
||||
InjectMeshRenderer(meshRenderer);
|
||||
}
|
||||
|
||||
public void InjectCanvasRenderTexture(CanvasRenderTexture canvasRenderTexture)
|
||||
{
|
||||
_canvasRenderTexture = canvasRenderTexture;
|
||||
}
|
||||
|
||||
public void InjectMeshRenderer(MeshRenderer meshRenderer)
|
||||
{
|
||||
_meshRenderer = meshRenderer;
|
||||
}
|
||||
|
||||
public void InjectOptionalRenderingMode(RenderingMode renderingMode)
|
||||
{
|
||||
_renderingMode = (int)renderingMode;
|
||||
}
|
||||
|
||||
public void InjectOptionalAlphaCutoutThreshold(float alphaCutoutThreshold)
|
||||
{
|
||||
_alphaCutoutThreshold = alphaCutoutThreshold;
|
||||
}
|
||||
|
||||
public void InjectOptionalUseAlphaToMask(bool useAlphaToMask)
|
||||
{
|
||||
_useAlphaToMask = useAlphaToMask;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 49d3bbd18ed10f44ba1e0b24dbfee754
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -0,0 +1,81 @@
|
||||
/*
|
||||
* 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 UnityEngine;
|
||||
|
||||
namespace Oculus.Interaction.UnityCanvas
|
||||
{
|
||||
public class CanvasRect : CanvasMesh
|
||||
{
|
||||
protected override Vector3 MeshInverseTransform(Vector3 localPosition)
|
||||
{
|
||||
return localPosition;
|
||||
}
|
||||
|
||||
protected override void GenerateMesh(out List<Vector3> verts,
|
||||
out List<int> tris,
|
||||
out List<Vector2> uvs)
|
||||
{
|
||||
verts = new List<Vector3>();
|
||||
tris = new List<int>();
|
||||
uvs = new List<Vector2>();
|
||||
|
||||
var resolution = _canvasRenderTexture.GetBaseResolutionToUse();
|
||||
Vector2 worldSize = new Vector2(
|
||||
_canvasRenderTexture.PixelsToUnits(Mathf.RoundToInt(resolution.x)),
|
||||
_canvasRenderTexture.PixelsToUnits(Mathf.RoundToInt(resolution.y))
|
||||
) / transform.lossyScale;
|
||||
|
||||
float xPos = worldSize.x * 0.5f;
|
||||
float xNeg = -xPos;
|
||||
|
||||
float yPos = worldSize.y * 0.5f;
|
||||
float yNeg = -yPos;
|
||||
|
||||
verts.Add(new Vector3(xNeg, yNeg, 0));
|
||||
verts.Add(new Vector3(xNeg, yPos, 0));
|
||||
verts.Add(new Vector3(xPos, yPos, 0));
|
||||
verts.Add(new Vector3(xPos, yNeg, 0));
|
||||
|
||||
tris.Add(0);
|
||||
tris.Add(1);
|
||||
tris.Add(2);
|
||||
|
||||
tris.Add(0);
|
||||
tris.Add(2);
|
||||
tris.Add(3);
|
||||
|
||||
uvs.Add(new Vector2(0, 0));
|
||||
uvs.Add(new Vector2(0, 1));
|
||||
uvs.Add(new Vector2(1, 1));
|
||||
uvs.Add(new Vector2(1, 0));
|
||||
}
|
||||
|
||||
#region Inject
|
||||
|
||||
public void InjectAllCanvasRect(CanvasRenderTexture canvasRenderTexture, MeshFilter meshFilter)
|
||||
{
|
||||
InjectAllCanvasMesh(canvasRenderTexture, meshFilter);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2025423b67857c349bf8cf435762b5cd
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -0,0 +1,384 @@
|
||||
/*
|
||||
* 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 UnityEngine.Profiling;
|
||||
|
||||
#if UNITY_EDITOR
|
||||
using UnityEditor;
|
||||
#endif
|
||||
|
||||
namespace Oculus.Interaction.UnityCanvas
|
||||
{
|
||||
[DisallowMultipleComponent]
|
||||
public class CanvasRenderTexture : MonoBehaviour
|
||||
{
|
||||
private class TransformChangeListener : MonoBehaviour
|
||||
{
|
||||
public event Action WhenRectTransformDimensionsChanged = delegate { };
|
||||
|
||||
private void OnRectTransformDimensionsChange()
|
||||
{
|
||||
WhenRectTransformDimensionsChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public enum DriveMode
|
||||
{
|
||||
Auto,
|
||||
Manual
|
||||
}
|
||||
|
||||
public const int DEFAULT_UI_LAYERMASK = 1 << 5; //Hardcoded as the UI layer in Unity.
|
||||
|
||||
private static readonly Vector2Int DEFAULT_TEXTURE_RES = new Vector2Int(128, 128);
|
||||
|
||||
[Tooltip("The Unity canvas that will be rendered.")]
|
||||
[SerializeField]
|
||||
private Canvas _canvas;
|
||||
|
||||
[Tooltip("If you need extra resolution, you can use this as a whole-integer multiplier " +
|
||||
"of the final resolution used to render the texture.")]
|
||||
[Range(1, 3)]
|
||||
[Delayed]
|
||||
[SerializeField]
|
||||
private int _renderScale = 1;
|
||||
|
||||
[Tooltip("If set to auto, texture dimensions will take the size of the attached " +
|
||||
"RectTransform into consideration, in addition to the configured pixel-per-unit ratio.")]
|
||||
[SerializeField]
|
||||
private DriveMode _dimensionsDriveMode = DriveMode.Auto;
|
||||
|
||||
[Tooltip("The exact pixel resolution of the texture used for interface rendering.")]
|
||||
[Delayed]
|
||||
[SerializeField]
|
||||
private Vector2Int _resolution = DEFAULT_TEXTURE_RES;
|
||||
|
||||
[Tooltip("Whether or not mip-maps should be auto-generated for the texture. " +
|
||||
"Can help aliasing if the texture can be " +
|
||||
"viewed from many difference distances.")]
|
||||
[SerializeField]
|
||||
private bool _generateMipMaps = false;
|
||||
|
||||
[Tooltip("Pixels per unit ratio used to drive the texture dimensions.")]
|
||||
[SerializeField]
|
||||
private int _pixelsPerUnit = 100;
|
||||
|
||||
[Header("Rendering Settings")]
|
||||
[Tooltip("The layers to render when the rendering texture is created. " +
|
||||
"All child renderers should be part of this mask.")]
|
||||
[SerializeField]
|
||||
private LayerMask _renderingLayers = DEFAULT_UI_LAYERMASK;
|
||||
|
||||
public LayerMask RenderingLayers => _renderingLayers;
|
||||
|
||||
public Action<Texture> OnUpdateRenderTexture = delegate { };
|
||||
|
||||
public int RenderScale
|
||||
{
|
||||
get
|
||||
{
|
||||
return _renderScale;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (_renderScale < 1 || _renderScale > 3)
|
||||
{
|
||||
throw new ArgumentException($"Render scale must be between 1 and 3, but was {value}");
|
||||
}
|
||||
|
||||
if (_renderScale == value)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_renderScale = value;
|
||||
|
||||
if (isActiveAndEnabled && Application.isPlaying)
|
||||
{
|
||||
UpdateCamera();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Camera OverlayCamera => _camera;
|
||||
|
||||
public Texture Texture => _tex;
|
||||
|
||||
private TransformChangeListener _listener;
|
||||
private RenderTexture _tex;
|
||||
private Camera _camera;
|
||||
|
||||
protected bool _started = false;
|
||||
|
||||
public Vector2Int CalcAutoResolution()
|
||||
{
|
||||
if (_canvas == null)
|
||||
{
|
||||
return DEFAULT_TEXTURE_RES;
|
||||
}
|
||||
|
||||
var rectTransform = _canvas.GetComponent<RectTransform>();
|
||||
if (rectTransform == null)
|
||||
{
|
||||
return DEFAULT_TEXTURE_RES;
|
||||
}
|
||||
|
||||
Vector2 size = rectTransform.sizeDelta;
|
||||
size.x *= rectTransform.lossyScale.x;
|
||||
size.y *= rectTransform.lossyScale.y;
|
||||
|
||||
int x = Mathf.RoundToInt(UnitsToPixels(size.x));
|
||||
int y = Mathf.RoundToInt(UnitsToPixels(size.y));
|
||||
return new Vector2Int(Mathf.Max(x, 1), Mathf.Max(y, 1));
|
||||
}
|
||||
|
||||
public Vector2Int GetBaseResolutionToUse()
|
||||
{
|
||||
if (_dimensionsDriveMode == DriveMode.Auto)
|
||||
{
|
||||
return CalcAutoResolution();
|
||||
}
|
||||
else
|
||||
{
|
||||
return _resolution;
|
||||
}
|
||||
}
|
||||
|
||||
public Vector2Int GetScaledResolutionToUse()
|
||||
{
|
||||
Vector2 resolution = GetBaseResolutionToUse();
|
||||
return Vector2Int.RoundToInt(resolution * _renderScale);
|
||||
}
|
||||
|
||||
public float PixelsToUnits(float pixels)
|
||||
{
|
||||
return (1f / _pixelsPerUnit) * pixels;
|
||||
}
|
||||
|
||||
public float UnitsToPixels(float units)
|
||||
{
|
||||
return _pixelsPerUnit * units;
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
protected void OnValidate()
|
||||
{
|
||||
if (Application.isPlaying && _started)
|
||||
{
|
||||
EditorApplication.delayCall += () =>
|
||||
{
|
||||
UpdateCamera();
|
||||
};
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
protected void Start()
|
||||
{
|
||||
this.BeginStart(ref _started);
|
||||
this.AssertField(_canvas, nameof(_canvas));
|
||||
this.EndStart(ref _started);
|
||||
}
|
||||
|
||||
protected void OnEnable()
|
||||
{
|
||||
if (_started)
|
||||
{
|
||||
if (_listener == null)
|
||||
{
|
||||
_listener = _canvas.gameObject.AddComponent<TransformChangeListener>();
|
||||
}
|
||||
_listener.WhenRectTransformDimensionsChanged += WhenCanvasRectTransformDimensionsChanged;
|
||||
UpdateCamera();
|
||||
}
|
||||
}
|
||||
|
||||
private void WhenCanvasRectTransformDimensionsChanged()
|
||||
{
|
||||
UpdateCamera();
|
||||
}
|
||||
|
||||
protected void OnDisable()
|
||||
{
|
||||
if (_started)
|
||||
{
|
||||
if (_camera?.gameObject != null)
|
||||
{
|
||||
Destroy(_camera.gameObject);
|
||||
}
|
||||
if (_tex != null)
|
||||
{
|
||||
DestroyImmediate(_tex);
|
||||
}
|
||||
if (_listener != null)
|
||||
{
|
||||
_listener.WhenRectTransformDimensionsChanged -= WhenCanvasRectTransformDimensionsChanged;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void UpdateCamera()
|
||||
{
|
||||
if (!Application.isPlaying || !_started)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Profiler.BeginSample("InterfaceRenderer.UpdateCamera");
|
||||
try
|
||||
{
|
||||
if (_camera == null)
|
||||
{
|
||||
GameObject cameraObj = CreateChildObject("__Camera");
|
||||
_camera = cameraObj.AddComponent<Camera>();
|
||||
|
||||
_camera.orthographic = true;
|
||||
_camera.nearClipPlane = -0.1f;
|
||||
_camera.farClipPlane = 0.1f;
|
||||
_camera.backgroundColor = new Color(0, 0, 0, 0);
|
||||
_camera.clearFlags = CameraClearFlags.SolidColor;
|
||||
}
|
||||
|
||||
UpdateRenderTexture();
|
||||
UpdateOrthoSize();
|
||||
UpdateCameraCullingMask();
|
||||
}
|
||||
finally
|
||||
{
|
||||
Profiler.EndSample();
|
||||
}
|
||||
}
|
||||
|
||||
protected void UpdateRenderTexture()
|
||||
{
|
||||
Profiler.BeginSample("InterfaceRenderer.UpdateRenderTexture");
|
||||
try
|
||||
{
|
||||
Vector2Int resolutionToUse = GetScaledResolutionToUse();
|
||||
|
||||
if (_tex == null ||
|
||||
_tex.width != resolutionToUse.x ||
|
||||
_tex.height != resolutionToUse.y ||
|
||||
_tex.autoGenerateMips != _generateMipMaps)
|
||||
{
|
||||
if (_tex != null)
|
||||
{
|
||||
_camera.targetTexture = null;
|
||||
DestroyImmediate(_tex);
|
||||
}
|
||||
|
||||
_tex = new RenderTexture(resolutionToUse.x, resolutionToUse.y, 24, RenderTextureFormat.ARGB32, RenderTextureReadWrite.sRGB);
|
||||
_tex.filterMode = FilterMode.Bilinear;
|
||||
_tex.autoGenerateMips = _generateMipMaps;
|
||||
_camera.targetTexture = _tex;
|
||||
|
||||
OnUpdateRenderTexture(_tex);
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
Profiler.EndSample();
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateOrthoSize()
|
||||
{
|
||||
if (_camera != null)
|
||||
{
|
||||
_camera.orthographicSize = PixelsToUnits(GetBaseResolutionToUse().y) * 0.5f;
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateCameraCullingMask()
|
||||
{
|
||||
if (_camera != null)
|
||||
{
|
||||
_camera.cullingMask = _renderingLayers.value;
|
||||
}
|
||||
}
|
||||
|
||||
protected GameObject CreateChildObject(string name)
|
||||
{
|
||||
GameObject obj = new GameObject(name);
|
||||
|
||||
obj.transform.SetParent(_canvas.transform);
|
||||
obj.transform.localPosition = Vector3.zero;
|
||||
obj.transform.localRotation = Quaternion.identity;
|
||||
obj.transform.localScale = Vector3.one;
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
public static class Properties
|
||||
{
|
||||
public static readonly string DimensionDriveMode = nameof(_dimensionsDriveMode);
|
||||
public static readonly string Resolution = nameof(_resolution);
|
||||
public static readonly string RenderScale = nameof(_renderScale);
|
||||
public static readonly string PixelsPerUnit = nameof(_pixelsPerUnit);
|
||||
public static readonly string RenderLayers = nameof(_renderingLayers);
|
||||
public static readonly string GenerateMipMaps = nameof(_generateMipMaps);
|
||||
public static readonly string Canvas = nameof(_canvas);
|
||||
}
|
||||
|
||||
#region Inject
|
||||
|
||||
public void InjectAllCanvasRenderTexture(Canvas canvas,
|
||||
int pixelsPerUnit,
|
||||
int renderScale,
|
||||
LayerMask renderingLayers,
|
||||
bool generateMipMaps)
|
||||
{
|
||||
InjectCanvas(canvas);
|
||||
InjectPixelsPerUnit(pixelsPerUnit);
|
||||
InjectRenderScale(renderScale);
|
||||
InjectRenderingLayers(renderingLayers);
|
||||
InjectGenerateMipMaps(generateMipMaps);
|
||||
}
|
||||
|
||||
public void InjectCanvas(Canvas canvas)
|
||||
{
|
||||
_canvas = canvas;
|
||||
}
|
||||
|
||||
public void InjectPixelsPerUnit(int pixelsPerUnit)
|
||||
{
|
||||
_pixelsPerUnit = pixelsPerUnit;
|
||||
}
|
||||
|
||||
public void InjectRenderScale(int renderScale)
|
||||
{
|
||||
_renderScale = renderScale;
|
||||
}
|
||||
|
||||
public void InjectRenderingLayers(LayerMask renderingLayers)
|
||||
{
|
||||
_renderingLayers = renderingLayers;
|
||||
}
|
||||
|
||||
public void InjectGenerateMipMaps(bool generateMipMaps)
|
||||
{
|
||||
_generateMipMaps = generateMipMaps;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,16 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b7ecff74e52843a41ab3a441ac81379e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences:
|
||||
- _defaultUIMaterial: {fileID: 2100000, guid: bc9f80a2ae0e0a24d870176e48ab1b93,
|
||||
type: 2}
|
||||
- _imposterMaterial: {fileID: 2100000, guid: 5c093e4058df12042a75bcb967ca1554, type: 2}
|
||||
- _depthQuadMaterial: {fileID: 2100000, guid: c7cda63c3ebb50847950fc3a925d784f,
|
||||
type: 2}
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -0,0 +1,34 @@
|
||||
/*
|
||||
* 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.UnityCanvas
|
||||
{
|
||||
public enum RenderingMode
|
||||
{
|
||||
[InspectorName("Alpha-Blended")]
|
||||
AlphaBlended = 0,
|
||||
[InspectorName("Alpha-Cutout")]
|
||||
AlphaCutout,
|
||||
[InspectorName("Opaque")]
|
||||
Opaque,
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3e5de7ab187e8dc47a0f654ad1e1107a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -0,0 +1,43 @@
|
||||
/*
|
||||
* 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.UnityCanvas
|
||||
{
|
||||
/// <summary>
|
||||
/// Dropdowns menus in Unity are automatically set to sorting order 30000, which
|
||||
/// does not play nicely with world space UIs.
|
||||
/// Meant to be used in conjunction with an EventTrigger on a given Dropdown, this component
|
||||
/// can be used to set a different sorting order on this and any child canvas.
|
||||
/// </summary>
|
||||
public class UpdateCanvasSortingOrder : MonoBehaviour
|
||||
{
|
||||
public void SetCanvasSortingOrder(int sortingOrder)
|
||||
{
|
||||
Canvas[] canvases = transform.parent.gameObject.GetComponentsInChildren<Canvas>();
|
||||
if (canvases == null) return;
|
||||
foreach (Canvas canvas in canvases)
|
||||
{
|
||||
canvas.sortingOrder = sortingOrder;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f40996cdf2361b8478af26d6e2630d42
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user