// 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 CanvasElementRoundedRect : 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 = 1f;
///
/// 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();
}
}
[Tooltip("Apply anti-aliasing to silhouette edges of the rounded rectangle (also requires enabling this feature in the material).")]
[SerializeField]
private bool calculateSmoothEdges = true;
public bool SmoothEdges
{
get => calculateSmoothEdges;
set
{
calculateSmoothEdges = value;
SetVerticesDirty();
}
}
#region override methods
///
/// Ensures the canvas generates required vertex attributes.
///
protected override void Start()
{
base.Start();
var canvas = GetComponentInParent