Ejemplo n.º 1
0
    public void Show(SaveableNumberDictionary <int> items, Action <int> selectCallback = null, Func <Jyx2Item, bool> filter = null)
    {
        HSUnityTools.DestroyChildren(m_Container);
        callback = selectCallback;
        foreach (var kv in items)
        {
            string id    = kv.Key;
            int    count = kv.Value;

            var item = ConfigTable.Get <Jyx2Item>(id);
            if (item == null)
            {
                Debug.LogError("调用了错误的物品,id=" + id);
                continue;
            }

            //过滤器逻辑
            if (filter != null && filter(item) == false)
            {
                continue;
            }

            var itemUI = Jyx2ItemUI.Create(int.Parse(id), count);
            itemUI.transform.SetParent(m_Container);
            var btn = itemUI.GetComponent <Button>();

            btn.onClick.RemoveAllListeners();
            btn.onClick.AddListener(() => {
                SelectItem(itemUI);
            });
        }
    }
Ejemplo n.º 2
0
    protected override void OnShowPanel(params object[] allParams)
    {
        base.OnShowPanel(allParams);
        m_itemDatas = (SaveableNumberDictionary <int>)allParams[0];
        if (allParams.Length > 1)
        {
            m_callback = (Action <int>)allParams[1];
        }
        if (allParams.Length > 2)
        {
            m_filter = (Func <Jyx2Item, bool>)allParams[2];
        }

        RefreshScroll();
    }
Ejemplo n.º 3
0
    /// <summary>
    /// 创建背包面板
    /// </summary>
    /// <param name="parent"></param>
    /// <param name="items"></param>
    /// <param name="selectCallback">如果取消,则返回-1</param>
    public static void Create(Transform parent, SaveableNumberDictionary <int> items, Action <int> selectCallback = null, Func <Jyx2Item, bool> filter = null)
    {
        var prefab = Jyx2ResourceHelper.GetCachedPrefab("Assets/Prefabs/BagPanel.prefab");
        var obj    = Instantiate(prefab);

        obj.transform.SetParent(parent);

        var rt = obj.GetComponent <RectTransform>();

        rt.localPosition = Vector3.zero;
        rt.localScale    = Vector3.one;

        var bagPanel = obj.GetComponent <BagPanel>();

        bagPanel.Show(items, selectCallback, filter);
    }