// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
#if GT_USE_UGUI
using UnityEngine;
using UnityEngine.UI;
namespace Microsoft.MixedReality.GraphicsTools
{
///
/// Procedurally generates a 3D rounded rect mesh to be rendered within a UnityUI canvas.
///
[RequireComponent(typeof(CanvasRenderer))]
public class CanvasElementBeveledRect : MaskableGraphic
{
[Tooltip("Specifies the corner radius of the rounded rect in world units. Should be less than half the width or height.")]
[SerializeField]
private float radius = 10f;
///
/// Specifies the corner radius in world units. Should be less than half the width or height.
///
public float Radius
{
get => radius;
set
{
radius = value;
SetVerticesDirty();
}
}
[Tooltip("Controls the depth of the rounded rect along the local z axis.")]
[SerializeField]
private float thickness = 3f;
///
/// Controls the depth of the rounded rect along the local z axis.
///
public float Thickness
{
get => thickness;
set
{
thickness = value;
SetVerticesDirty();
}
}
[Tooltip("Controls how many subdivisions at the corners of the rounded rect. More wedges produces smoother corners at the expense of more triangles.")]
[SerializeField]
private int wedges = 8;
///
/// Controls how many subdivisions at the corners of the rounded rect. More wedges produces smoother corners at the expense of more triangles.
///
public int Wedges
{
get => wedges;
set
{
wedges = value;
SetVerticesDirty();
}
}
[Header("Bevel")]
[Tooltip("Specifies the front bevel radius in world units. Should be less than the corner radius.")]
[SerializeField]
private float frontBevelRadius = 1f;
///
/// Specifies the front bevel radius in world units. Should be less than the radius
///
public float FrontBevelRadius
{
get => frontBevelRadius;
set
{
frontBevelRadius = value;
SetVerticesDirty();
}
}
[Tooltip("Specifies the front bevel radius in world units. Should be less than the corner radius.")]
[SerializeField]
private int frontBevelSections = 4;
///
/// Specifies the front bevel radius in world units. Should be less than half the radius
///
public int FrontBevelSections
{
get => frontBevelSections;
set
{
frontBevelSections = value;
SetVerticesDirty();
}
}
[Tooltip("Specifies the back bevel radius in world units. Should be less than the corner radius.")]
[SerializeField]
private float backBevelRadius = 1f;
///
/// Specifies the back bevel radius in world units. Should be less than the radius
///
public float BackBevelRadius
{
get => backBevelRadius;
set
{
backBevelRadius = value;
SetVerticesDirty();
}
}
[Tooltip("Specifies the back bevel radius in world units. Should be less than the corner radius.")]
[SerializeField]
private int backBevelSections = 4;
///
/// Specifies the back bevel radius in world units. Should be less than half the radius
///
public int BackBevelSections
{
get => backBevelSections;
set
{
backBevelSections = value;
SetVerticesDirty();
}
}
#region override methods
///
/// Ensures the canvas generates required vertex attributes.
///
protected override void Start()
{
base.Start();
var canvas = GetComponentInParent