/// <summary>
    /// 设置是否有道具
    /// </summary>
    public void SetCanHasItems(long[] listItemsId, long itemsNumber)
    {
        UserDataBean userData      = GameDataHandler.Instance.manager.GetUserData();
        bool         hasEnoughItem = false;

        for (int i = 0; i < listItemsId.Length; i++)
        {
            long itemsId = listItemsId[i];
            if (userData.HasEnoughItem(itemsId, itemsNumber))
            {
                hasEnoughItem = true;
                break;
            }
        }
        if (hasEnoughItem)
        {
            ui_TVNumber.color = Color.green;
            ui_Icon.material.SetFloat("_EffectAmount", 0);
        }
        else
        {
            ui_TVNumber.color = Color.white;
            ui_Icon.material.SetFloat("_EffectAmount", 1);
        }
    }
Exemple #2
0
    /// <summary>
    /// 检测是否能合成
    /// </summary>
    public bool CheckSynthesis()
    {
        //获取合成材料
        List <ItemsSynthesisMaterialsBean> listMaterials = GetSynthesisMaterials();
        UserDataBean userData = GameDataHandler.Instance.manager.GetUserData();

        for (int i = 0; i < listMaterials.Count; i++)
        {
            ItemsSynthesisMaterialsBean itemMaterials = listMaterials[i];
            bool hasMaterial = false;
            for (int f = 0; f < itemMaterials.itemIds.Length; f++)
            {
                long itemsId = itemMaterials.itemIds[f];
                //有其中一种素材
                bool hasEnoughItem = userData.HasEnoughItem(itemsId, itemMaterials.itemNumber);
                if (hasEnoughItem)
                {
                    hasMaterial = true;
                    break;
                }
            }
            if (hasMaterial == false)
            {
                return(false);
            }
        }
        return(true);
    }
    /// <summary>
    /// 点击-开始合成
    /// </summary>
    public void OnClickForStartSynthesis()
    {
        //当前选中的合成道具
        ItemsSynthesisBean itemsSynthesis = listSynthesisData[indexSelect];
        //检测当前道具是否能合成
        bool canSynthesis = itemsSynthesis.CheckSynthesis();

        if (!canSynthesis)
        {
            //素材不足 无法合成
            UIHandler.Instance.ToastHint <ToastView>(TextHandler.Instance.GetTextById(30002));
            return;
        }
        //首先消耗素材
        BaseUIComponent currentUI = UIHandler.Instance.GetOpenUI();
        //获取素材
        List <ItemsSynthesisMaterialsBean> listMaterials = itemsSynthesis.GetSynthesisMaterials();

        UserDataBean userData = GameDataHandler.Instance.manager.GetUserData();

        //扣除素材
        for (int i = 0; i < listMaterials.Count; i++)
        {
            ItemsSynthesisMaterialsBean itemMaterials = listMaterials[i];
            for (int f = 0; f < itemMaterials.itemIds.Length; f++)
            {
                //只要扣除其中一项素材就行
                long itemMaterialId = itemMaterials.itemIds[f];
                if (userData.HasEnoughItem(itemMaterialId, itemMaterials.itemNumber))
                {
                    userData.RemoveItem(itemMaterialId, itemMaterials.itemNumber);
                    break;
                }
                else
                {
                    continue;
                }
            }
        }
        //添加道具
        itemsSynthesis.GetSynthesisResult(out long itemsId, out int itemNum);
        int moreNum = userData.AddItems(itemsId, itemNum, null);

        //如果还有多余的道具 则丢出来
        if (moreNum > 0)
        {
            Player player = GameHandler.Instance.manager.player;
            ItemsHandler.Instance.CreateItemCptDrop(itemsId, moreNum, null, player.transform.position + Vector3.up, ItemDropStateEnum.DropNoPick);
        }

        UIViewBackpackList backpackUI = currentUI.GetComponentInChildren <UIViewBackpackList>();

        backpackUI.RefreshUI();
        UIViewShortcuts shortcutsUI = currentUI.GetComponentInChildren <UIViewShortcuts>();

        shortcutsUI.RefreshUI();
        RefreshUI();
    }