示例#1
0
    public void OnClick(int id)
    {
        DestroyAllNeedItem();
        NeedItemList.transform.localPosition = Vector3.zero;

        int idx = WorkBenchDatabase.instance.FindIdxById(id);

        CurrentSpot = idx;
        WorkBenchDatabase.WorkBenchSetDic item = WorkBenchDatabase.instance.WorkBenchSetList[CurrentSpot];

        Recipe.transform.FindChild("Item").GetComponent <Image>().sprite = ItemDatabase.instance.Items[item.ReturnItemId].sprite;
        Recipe.transform.FindChild("Name").GetComponent <Text>().text    = ItemDatabase.instance.Items[item.ReturnItemId].name;

        for (int i = 0; i < item.NeedItem.Count; i++)
        {
            Transform obj = Instantiate(WorkbenchNeedItemPrefab, NeedItemList.transform).transform;
            obj.localScale = Vector3.one;
            obj.transform.localPosition = new Vector3(0, 300, 0) - new Vector3(0, i * 150, 0);
            obj.FindChild("Item").GetComponent <Image>().sprite = ItemDatabase.instance.Items[item.NeedItem[i].id].sprite;
            obj.FindChild("Name").GetComponent <Text>().text    = ItemDatabase.instance.Items[item.NeedItem[i].id].name;
            obj.FindChild("QTY").GetComponent <Text>().text     = playerinvenytory.getQTYofId(item.NeedItem[i].id).ToString();
            obj.FindChild("NeedQTY").GetComponent <Text>().text = item.NeedItem[i].QTY.ToString();
        }
        WorkButton.enabled = CheckWorkAble(CurrentSpot);
    }
示例#2
0
 public void ClickWork()
 {
     WorkBenchDatabase.WorkBenchSetDic item = WorkBenchDatabase.instance.WorkBenchSetList[CurrentSpot];
     if (CheckWorkAble(CurrentSpot) && playerinvenytory.getEmptySmallNum() != -1)
     {
         for (int i = 0; i < item.NeedItem.Count; i++)
         {
             playerinvenytory.DestroyItem(playerinvenytory.getItemById(item.NeedItem[i].id), item.NeedItem[i].QTY);
         }
         playerinvenytory.MakeNewItem(playerinvenytory.getEmptySmallNum(), item.ReturnItemId, 1, Inventory.ITEMPARENT.PLAYER);
     }
 }
示例#3
0
    bool CheckWorkAble(int cspot)
    {
        bool workable = true;

        WorkBenchDatabase.WorkBenchSetDic item = WorkBenchDatabase.instance.WorkBenchSetList[cspot];
        for (int i = 0; i < item.NeedItem.Count; i++)
        {
            if (playerinvenytory.getQTYofId(item.NeedItem[i].id) < item.NeedItem[i].QTY)
            {
                workable = false;
            }
        }
        return(workable);
    }
示例#4
0
    void Start()
    {
        CurrentSpot      = 0;
        playerinvenytory = FindObjectOfType <Inventory>();

        WorkButton.onClick.AddListener(delegate { ClickWork(); });
        for (int i = 0; i < WorkBenchDatabase.instance.WorkBenchSetList.Count; i++)
        {
            WorkBenchDatabase.WorkBenchSetDic item = WorkBenchDatabase.instance.WorkBenchSetList[i];
            Transform obj = Instantiate(WorkbenchItemPrefab, RecipeList.transform).transform;
            obj.localScale    = Vector3.one;
            obj.localPosition = new Vector3(0, 300, 0) - new Vector3(0, i * 150, 0);
            obj.FindChild("Item").GetComponent <Image>().sprite = ItemDatabase.instance.Items[item.ReturnItemId].sprite;
            obj.FindChild("Name").GetComponent <Text>().text    = ItemDatabase.instance.Items[item.ReturnItemId].name;
            obj.GetComponent <Button>().onClick.AddListener(delegate { OnClick(item.ReturnItemId); });
        }
    }