using MyFrameworkPure;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Events;
namespace MyFrameworkPure
{
///
/// 右键菜单
///
public class RightMenu : MonoBehaviour
{
private static Transform ktransform;
void Awake()
{
ktransform = transform;
}
// Use this for initialization
void Start()
{
}
// Update is called once per frame
void Update()
{
if (Input.GetMouseButtonDown(0) || Input.GetMouseButtonDown(1))
{
if (!RectTransformUtility.RectangleContainsScreenPoint(GetComponent(), Input.mousePosition))
{
Destroy(gameObject);
}
}
}
public static void Show(Vector3 position, string[] btnlist, float btnWidth, float btnHeight, params UnityAction[] dosomethings)
{
Debug.Assert(btnlist.Length == dosomethings.Length, "按钮数量同事件数量不匹配!");
if (ktransform != null)
{
Destroy(ktransform.gameObject);
}
GameObject go = ResourceTool.Instantiate("UI/RightMenu", GameObject.Find("Overlay").transform);
go.transform.position = position;
Transform templateBtn = go.transform.GetChild(0);
templateBtn.GetComponent().sizeDelta = new Vector2(btnWidth, btnHeight);
int i = 0;
foreach (string btn in btnlist)
{
Transform tr = Instantiate(go.transform.GetChild(0), ktransform);
tr.gameObject.SetActive(true);
tr.GetChild(0).GetComponent().text = btn;
tr.GetComponent