Exemplo n.º 1
0
    /// <summary>
    /// 设置素材
    /// </summary>
    public void SetSynthesisMaterials()
    {
        if (listUIMaterial == null)
        {
            listUIMaterial = new List <UIViewSynthesisMaterial>();
        }
        listUIMaterial.Clear();

        //先删除所有素材
        ui_SynthesisMaterials.DestroyAllChild();
        //获取当前选中合成道具
        ItemsSynthesisBean itemsSynthesis = listSynthesisData[indexSelect];
        List <ItemsSynthesisMaterialsBean> listMaterials = itemsSynthesis.GetSynthesisMaterials();

        //获取起始点位置
        Vector2[] listCirclePosition = VectorUtil.GetListCirclePosition(listMaterials.Count, 0, Vector2.zero, 95);
        //创建所有素材
        int itemAngle = 360 / listMaterials.Count;

        for (int i = 0; i < listMaterials.Count; i++)
        {
            GameObject objMaterial = Instantiate(ui_SynthesisMaterials.gameObject, ui_ViewSynthesisMaterial.gameObject);
            UIViewSynthesisMaterial itemMaterial = objMaterial.GetComponent <UIViewSynthesisMaterial>();

            ItemsSynthesisMaterialsBean itemData = listMaterials[i];
            itemMaterial.SetData(itemData, itemAngle * i);
            itemMaterial.rectTransform.anchoredPosition = listCirclePosition[i];
            listUIMaterial.Add(itemMaterial);
        }
    }
Exemplo n.º 2
0
    /// <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();
    }