powerfun-unity/Assets/Scripts/UI/Control/PFUIRoundButton.cs

33 lines
979 B
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
using UnityEngine.UI;
namespace Assets.Scripts.UI.Control
{
[RequireComponent(typeof(Button))]
public class PFUIRoundButton : PFUIComponentBase
{
private Image image;
private Text text;
protected void Awake()
{
image = gameObject.GetComponent<Image>();
text = this.transform.Find("Text").GetComponent<Text>();
Material material = null;
if (material == null)
{
material = Instantiate(Resources.Load<Material>("UI/Material/RoundedCornersTextureMaterial"));
}
var rect = ((RectTransform)transform).rect;
material.SetVector(Shader.PropertyToID("_WidthHeightRadius"), new Vector4(rect.width, rect.height, rect.height * 0.5f, 0));
image.material = material;
}
}
}