Files
Main/Assets/Editor/DIY/FormTools/NGUICreateEx.cs

31 lines
876 B
C#
Raw Normal View History

2025-01-25 04:38:09 +08:00
using UnityEditor;
using UnityEngine;
namespace Thousandto.DIY
{
public class NGUICreateEx
{
[MenuItem("NGUI/Create/Button")]
static void AddButton()
{
GameObject go = NGUIEditorTools.SelectedRoot(true);
if (go != null)
{
var sprite = NGUISettings.AddSprite(go);
var collider = sprite.gameObject.RequireComponent<BoxCollider>();
sprite.gameObject.RequireComponent<UIButton>();
sprite.autoResizeBoxCollider = true;
collider.size = new Vector3(sprite.width, sprite.height);
sprite.gameObject.name = "Button";
Selection.activeGameObject = sprite.gameObject;
}
else Debug.Log("You must select a game object first.");
}
}
}