public void CreateDropBlockInventory(Vector3 pos, InventoryStorage inventoryStorage) { var instance = Instantiate(dropPrefab, pos, Quaternion.identity); var dropBlockInventory = instance.GetComponent <DropInventory>(); if (inventoryStorage.inventory is PlaceableInventory) { var placeable = inventoryStorage.inventory as PlaceableInventory; if (placeable.blockData != null) { instance.GetComponentInChildren <MeshRenderer>().material = placeable.blockData.topTex; } } dropBlockInventory.OnPlayerEnter += () => { var storedItem = inventorySystem.inventoryStorageList.Find(val => val.inventory.inventoryName == inventoryStorage.inventory.inventoryName && val.count < 64 && val.slotID < InventorySystem.max_bottom_slot_count); var isCollected = false; if (storedItem != null) { storedItem.count += inventoryStorage.count; isCollected = true; inventorySystem.UpdateInvetoryUI(); } else { //找空闲的Slot for (var i = 0; i < InventorySystem.max_bottom_slot_count; i++) { var index = inventorySystem.inventoryStorageList.FindIndex(val => val.slotID == i); if (index == -1) { inventoryStorage.slotID = i; inventorySystem.AddStorage(inventoryStorage); isCollected = true; break; } } } if (isCollected) { dropBlockInventory.Collect(); } }; }
public void GuessRecipe() { //匹配Recipe的字符组合 var currentRecipe = new string[9] { "", "", "", "", "", "", "", "", "" }; RecipeData desireRecipeData = null; foreach (var craft in craftInventoryList) { currentRecipe[craft.slotID] = craft.inventory.inventoryName; } foreach (var recipe in recipeList) { //加热条件不满足 if (recipe.requireHeating != isHeating) { continue; } var targetRecipe = new string[9] { "", "", "", "", "", "", "", "", "" }; for (int i = 0; i < recipe.Recipe.Length; i++) { targetRecipe[i] = recipe.Recipe[i] == null ? "" : recipe.Recipe[i].inventoryName; } if (Enumerable.SequenceEqual(currentRecipe, targetRecipe)) { desireRecipeData = recipe; break; } else { //Debug.Log($"current:{JsonConvert.SerializeObject(currentRecipe)} target:{JsonConvert.SerializeObject(targetRecipe)}"); } } if (desireRecipeData != null) { Debug.Log(desireRecipeData); layout.craftedInstance.itemIcon.sprite = desireRecipeData.CraftedInventory.inventoryIcon; craftedInventory = new InventoryStorage() { count = desireRecipeData.CraftedCount, slotID = 0, inventory = desireRecipeData.CraftedInventory }; } else { layout.craftedInstance.itemIcon.sprite = null; craftedInventory = null; } }
public void AddStorage(InventoryStorage inventoryStorage) { inventoryStorageList.Add(inventoryStorage); UpdateInvetoryUI(); }
private void CurrentInventroyUsed(InventoryStorage currentStorage) { currentStorage.count -= 1; CleanUpInventory(); UpdateInvetoryUI(); }
protected InventoryStorage(InventoryStorage other) { count = other.count; slotID = other.slotID; inventory = other.inventory; }