Exemplo n.º 1
0
    // 初始化UI和获取UI的GameObjects,Components
    void CreateUI(ConfirmType type = ConfirmType.Cancel_OK_Btn)
    {
        PromptUIObj = GameObject.Instantiate(Resources.Load(PromptUIPath)) as GameObject;

        GameObject contentLabel = GameObjectUtils.DirectFind("ConfirmBox/ContentLabel", PromptUIObj);
        GameObject cancelBtn    = GameObjectUtils.DirectFind("ConfirmBox/CancelBtn", PromptUIObj);
        GameObject cancelLabel  = GameObjectUtils.DirectFind("ConfirmBox/CancelBtn/Label", PromptUIObj);
        GameObject allowBtn     = GameObjectUtils.DirectFind("ConfirmBox/ConfirmBtn", PromptUIObj);
        GameObject allowLabel   = GameObjectUtils.DirectFind("ConfirmBox/ConfirmBtn/Label", PromptUIObj);
        GameObject centerBtn    = GameObjectUtils.DirectFind("ConfirmBox/CenterBtn", PromptUIObj);
        GameObject centerLabel  = GameObjectUtils.DirectFind("ConfirmBox/CenterBtn/Label", PromptUIObj);

        ContentLabelTxt = contentLabel != null?contentLabel.GetComponent <UILabel>() : null;

        CancelLabelTxt = cancelLabel != null?cancelLabel.GetComponent <UILabel>() : null;

        AllowLabelTxt = allowLabel != null?allowLabel.GetComponent <UILabel>() : null;

        CenterLabelTxt = centerLabel != null?centerLabel.GetComponent <UILabel>() : null;

        CancelBtnListen = cancelBtn != null?cancelBtn.GetComponent <UIEventListener>() : null;

        AllowBtnListen = allowBtn != null?allowBtn.GetComponent <UIEventListener>() : null;

        CenterAllowBtnListen = centerBtn != null?centerBtn.GetComponent <UIEventListener>() : null;

        // 这里初始化不同的确认框类型
        // 这里其实可以写成 cancelBtn.SetActive(type == ConfirmType.Cancel_OK_Btn)
        if (type == ConfirmType.Cancel_OK_Btn)
        {
            cancelBtn.SetActive(true);
            allowBtn.SetActive(true);
            centerBtn.SetActive(false);
        }
        else if (type == ConfirmType.Single_OK_Btn)
        {
            cancelBtn.SetActive(false);
            allowBtn.SetActive(false);
            centerBtn.SetActive(true);
        }
        else
        {
            // none
            cancelBtn.SetActive(true);
            allowBtn.SetActive(true);
            centerBtn.SetActive(false);
        }
    }
 static public int DirectFind_s(IntPtr l)
 {
     try {
         System.String a1;
         checkType(l, 1, out a1);
         UnityEngine.GameObject a2;
         checkType(l, 2, out a2);
         var ret = GameObjectUtils.DirectFind(a1, a2);
         pushValue(l, true);
         pushValue(l, ret);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }