public void LoadData(SaveDataBase saveData) { PlayerSaveData playerData = (PlayerSaveData)saveData; if (playerData == null) { return; } Transform playerTransform = transform; playerTransform.position = playerData.Position; playerTransform.rotation = playerData.Rotation; Health.SetCurrentHealth(playerData.CurrentHealth); foreach (ItemSaveData itemSaveData in playerData.ItemList) { ItemScriptables item = InventoryReferencer.Instance.GetItemReference(itemSaveData.Name); Inventory.AddItem(item, itemSaveData.Amount); } WeaponScriptable weapon = (WeaponScriptable)Inventory.FindItem(playerData.EquippedWeaponData.Name); if (!weapon) { return; } weapon.WeaponStats = playerData.EquippedWeaponData.WeaponStats; WeaponHolderComponent.EquipWeapon(weapon); }
public void AddItem(ItemScriptables item, int amount = 0) { int itemIndex = Items.FindIndex(itemScript => itemScript.Name == item.Name); if (itemIndex != -1) { ItemScriptables listItem = Items[itemIndex]; if (listItem.Stackable && listItem.Amount < listItem.MaxStack) { listItem.ChangeAmount(item.Amount); } } else { if (item == null) { return; } ItemScriptables itemClone = Instantiate(item); itemClone.Initialize(Controller); itemClone.SetAmount(amount <= 1 ? item.Amount : amount); Items.Add(itemClone); } }
public void Initialize(ItemScriptables item) { Item = item; ItemText.text = item.Name; AmountWidget.Initialize(item); EquippedWidget.Initialize(item); ItemButton.onClick.AddListener(UseItem); Item.OnItemDestroyed += OnItemDestroyed; }
internal void Initialize(ItemScriptables item) { if (!Item.Stackable) return; Item = item; ShowWidget(); Item.OnAmountChange += OnAmountChange; OnAmountChange(); }
public void Instantiate() { ItemInstance = Instantiate(PickUpItem); if (Amount > 0) { ItemInstance.SetAmount(Amount); } ApplyMesh(); }
public void DeleteItem(ItemScriptables item) { int itemIndex = Items.FindIndex(listItem => listItem.Name == item.Name); if (itemIndex == -1) { return; } Items.Remove(item); }
public void Initialize(ItemScriptables item) { if (!(item is EquipableScriptable eqItem)) { return; } Equipable = eqItem; ShowWidget(); Equipable.OnEquipStatusChange += OnEquipmentChange; OnEquipmentChange(); }
public void Initialize(ItemScriptables item) { if (!item.Stackable) { return; } Item = item; ShowWidget(); Item.OnAmountChange += OnAmountChange; OnAmountChange(); }
public ItemSaveData(ItemScriptables item) { Name = item.Name; Amount = item.Amount; }
private void OnItemDestroyed() { Item = null; Destroy(gameObject); }