Exemplo n.º 1
0
    // Use this for initialization
    void Start()
    {
        Object     testobject = Resources.Load("Button") as Object;
        GameObject gameobject = Instantiate(testobject) as GameObject;

        CButton btn = gameobject.GetComponent <CButton>();

        btn.AddClick(clickevent);
    }
Exemplo n.º 2
0
 // Use this for initialization
 void Start()
 {
     prefab = Resources.Load("TestPanel.prefab") as GameObject;
     CButton[] btns = prefab.GetComponentsInChildren <CButton>();
     foreach (CButton btn in btns)
     {
         if (btn.gameObject.name == "button")
         {
             button = btn;
             break;
         }
     }
     button.AddClick(OnClick);
 }
Exemplo n.º 3
0
        public static CButton CreateButton(string text, int depth, int x, int y, Transform parent, int w = 0, int h = 0, UIEventListener.VoidDelegate OnClick = null, string name = "Button", string toolTip = null)
        {
            GameObject obj = UnityEngine.Object.Instantiate(FuncUtil.GetUIAssetByPath(BUTTON_URL)) as GameObject;

            if (obj == null)
            {
                return(null);
            }
            obj.name                    = name;
            obj.transform.parent        = parent;
            obj.transform.localScale    = Vector3.one;
            obj.transform.localPosition = new Vector3(x, y, 0);
            CButton btn = obj.GetComponent <CButton>();

            btn.Text = text ?? "";
            UISprite sp = btn.GetComponent <UISprite>();

            btn.Label.SetAnchor(btn.transform);
            btn.Label.leftAnchor.Set(0, -38);
            btn.Label.rightAnchor.Set(1, 38);
            btn.Label.topAnchor.Set(1, 32);
            btn.Label.bottomAnchor.Set(0, -40);
            sp.depth = depth;
            if (w > 0 || h > 0)
            {
                sp.width  = w;
                sp.height = h;
            }
            if (toolTip != null)
            {
                btn.AddToolTip(toolTip);
            }
            btn.Label.depth = 200; //整个界面的文字基本不会重叠,搞成同一层避免隔开具有相同图集的其他组件的深度
            if (OnClick != null)
            {
                //UIEventListener.Get(obj).onClick = OnClick;
                btn.AddClick(OnClick);
            }
            return(btn);
        }