Example #1
0
    public bool DeleteItem(UIMenuListItem item)
    {
        DeleteChildItem(item);

        Debug.Log(item.gameObject.name);
        if (item.gameObject != null)
        {
            item.gameObject.transform.parent = null;
            if (Application.isEditor)
            {
                GameObject.DestroyImmediate(item.gameObject);
            }
            else
            {
                GameObject.Destroy(item.gameObject);
            }
        }
        Items.Remove(item);

        UpdateIndex();

        UIMenuPanel panel = FindMenuPanel(item.Parent);

        if (panel != null)
        {
            panel.UpdatePosition();
        }

        int count = GetChildItems(item.Parent).Count;

        if (count == 0)
        {
            DeletePanel(item.Parent);
            if (item.Parent != null)
            {
                item.Parent.IsHaveChild = false;
            }
        }

        return(true);
    }
Example #2
0
    public UIMenuListItem AddItem(UIMenuListItem parent, string text, UIGameMenuCtrl.MenuItemFlag flag, string icoName = "")
    {
        GameObject obj = AddObj();

        UIMenuPanel panel = FindMenuPanel(parent);

        if (panel == null)
        {
            panel = CreatePanel(parent, this);
        }

        UIMenuListItem item = obj.GetComponent <UIMenuListItem>();

        item.Text              = text;
        item.Parent            = parent;
        item.icoName           = icoName;
        item.mMenuItemFlag     = flag;
        item.e_OnClick        += ItemOnClick;
        item.e_OnMouseMoveIn  += ItemOnMouseMoveIn;
        item.e_OnMouseMoveOut += ItemOnMouseMoveOut;

        obj.transform.parent        = panel.content.transform;
        obj.transform.localScale    = Vector3.one;
        obj.transform.localPosition = Vector3.zero;

        Items.Insert(Items.Count, item);
        UpdateIndex();
        panel.UpdatePosition();

        if (parent != null)
        {
            parent.IsHaveChild = true;
        }

        return(item);
    }