// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
using UnityEngine;
using UnityEngine.UI;
namespace Microsoft.MixedReality.Toolkit.Input.Utilities
{
///
/// On Unity UI components the unity_ObjectToWorld matrix is not the transformation matrix of the local
/// transform the Graphic component lives on, but that of its parent Canvas. Many MRTK/Standard shader
/// effects require object scale to be known. To solve this issue the ScaleMeshEffect will store scaling
/// information into UV channel attributes during UI mesh construction. Ideally we would store the scale
/// in one attribute but UGUI only supports two scalers per attribute (even in the tangent attribute).
///
[RequireComponent(typeof(RectTransform), typeof(Graphic))]
[HelpURL("https://docs.microsoft.com/windows/mixed-reality/mrtk-unity/features/rendering/mrtk-standard-shader#ugui-support")]
[AddComponentMenu("Scripts/MRTK/Services/ScaleMeshEffect")]
public class ScaleMeshEffect : BaseMeshEffect
{
///
/// Enforces the parent canvas uses UV channel attributes.
///
protected override void Awake()
{
base.Awake();
// Make sure the parent canvas is configured to use UV channel attributes for scaling data.
var canvas = GetComponentInParent