31 lines
876 B
C#
31 lines
876 B
C#
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.");
|
|
}
|
|
}
|
|
}
|