示例#1
0
    public void EditorStractureIntoSubAssets()
    {
        bool equals = inventoryStracture.Count != inventory.Count;

        foreach (Unit_Item item in inventoryStracture)
        {
            if (equals)
            {
                Unit_Item newItem = ScriptableObject.CreateInstance <Unit_Item>();
                newItem.name = item.name;
                newItem.Initialize(item.item_Icon, item.item_Text, item.isWearable, item.basePrice);
                #if UNITY_EDITOR
                AssetDatabase.AddObjectToAsset(newItem, inventory_Path);
                #endif
                inventory.Add(newItem);
                equals = inventoryStracture.Count != inventory.Count;
            }
        }
    }
    public static void TradeItem(Unit_Item item, Unit_InventoryReader removeFromInv, Unit_InventoryReader addToInv)
    {
        Unit_Item tempItem = (Unit_Item)Resources.Load("Items/" + item.name);

        tempItem.name = item.name;
        tempItem.Initialize(item.item_Icon, item.item_Text, item.isWearable, item.basePrice);
        int invIndex = removeFromInv.inventory.FindIndex(i => i.name == item.name);
        int strIndex = removeFromInv.inventoryStracture.FindIndex(i => i.name == item.name);

        removeFromInv.inventory[invIndex].ResetItem();
        removeFromInv.inventoryStracture.RemoveAt(strIndex);

        foreach (Unit_Item i  in addToInv.inventory)
        {
            if (string.IsNullOrWhiteSpace(i.name))
            {
                i.Initialize(tempItem.item_Icon, tempItem.item_Text, tempItem.isWearable, tempItem.basePrice);
                break;
            }
        }
        addToInv.inventoryStracture.Add((Unit_Item)Resources.Load("Items/" + tempItem.name));
    }
示例#3
0
    public void Initialize(Unit_Item item)
    {
        Unit_InventoryReader cacheInventory = GameObject.FindWithTag("Player").GetComponent <Player>().self_UnitInventory;
        Unit_InventoryReader tempMainAsset;

        self_UnitItem    = item;
        self_Icon.sprite = self_UnitItem.item_Icon;
        self_Text.text   = self_UnitItem.item_Text;
        if (transform.root.GetComponentInChildren <NPC>() == null)
        {
            tempMainAsset = transform.root.GetComponentInChildren <Unit>().self_UnitInventory;
            if (cacheInventory == tempMainAsset)
            {
                self_ItemPrice.text = "+" + (item.basePrice / tempMainAsset.buySellFactor).ToString();
                self_tradingButton.onClick.AddListener(self_UnitItem.SellItem);
                return;
            }
        }
        else
        {
            self_ItemPrice.text = "-" + (item.basePrice * cacheInventory.buySellFactor).ToString();
            self_tradingButton.onClick.AddListener(self_UnitItem.BuyItem);
        }
    }