https://imgur.com/a/HOu31sT
Hey Joel, not sure if my gmail message went through so going to post on here! In the process of making a Castaway Sim that will see the player explore an island and unlock new segments and NPC's over time! They will also be able to craft items in the future that will help make stat replishinment on the island a little bit easier! So far I have managed to get my Slider Value (stats) data saving pretty flawlessly by saving the Slider values as floats and then loading them back in when the load button is hit, but now I've hit a tougher problem it would seem.
I have recently been following Brackeys RPG tutorial as that has a guide on how to set up a Scriptable Objects based Inventory which I had used for this project, my only question now is how to save the status of that Inventory using Easy Save 3.
This is some code from my Inventory scripts that hopefully show you how it works in general!
Code: Select all
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TMPro;
public class Inventory : MonoBehaviour {
#region Singleton
public GameObject player;
public static Inventory instance;
//Tooltip Variables
[SerializeField]
private GameObject tooltip;
public TextMeshProUGUI tooltipTitle;
public Image tooltipImage;
private void Awake()
{
instance = this;
tooltipTitle.GetComponent<TextMeshProUGUI>();
tooltipImage.GetComponent<Image>();
}
#endregion
public delegate void OnItemChanged();
public OnItemChanged onItemChangedCallBack;
public int space = 20;
public List<Item> items = new List<Item>();
public void Add (Item item)
{
// if (!item.isKeyItem)
// {
if (items.Count >= space)
{
Debug.Log("Now enough space in Inventory!");
return;
}
items.Add(item);
if (onItemChangedCallBack != null)
{
onItemChangedCallBack.Invoke();
}
// }
return;
}
public void Remove (Item item)
{
items.Remove(item);
if (onItemChangedCallBack != null)
{
onItemChangedCallBack.Invoke();
}
}
public void ShowToolTip(IDescribable ToolTipitem)
{
tooltip.SetActive(true);
tooltipTitle.text = ToolTipitem.GetTitle();
tooltipImage.sprite = ToolTipitem.GetSprite();
}
public void HideToolTip()
{
tooltip.SetActive(false);
}
}
Code: Select all
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
public class InventoryUI : MonoBehaviour
{
public Transform itemsParent;
public GameObject inventoryUI;
Inventory inventory;
// Start is called before the first frame update
void Start()
{
inventory = Inventory.instance;
inventory.onItemChangedCallBack += UpdateUI;
}
// Update is called once per frame
void Update()
{
if (Input.GetButtonDown("Inventory"))
{
inventoryUI.SetActive(!inventoryUI.activeSelf);
UpdateUI();
}
}
void UpdateUI()
{
InventorySlot[] slots = itemsParent.GetComponentsInChildren<InventorySlot>();
for (int i = 0; i < slots.Length; i++)
{
if (i < inventory.items.Count)
{
slots[i].AddItem(inventory.items[i]);
}
else
{
slots[i].ClearSlot();
}
}
}
}
Code: Select all
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;
using System.Collections;
using System.Collections.Generic;
using TMPro;
public class InventorySlot : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler
{
public TextMeshProUGUI itemText;
public Image icon;
Item item;
public Button removeButton;
public GameObject dropItemModal;
public Animator spriteAnim;
public Button yesButton;
public void Start()
{
}
public void AddItem (Item newItem)
{
spriteAnim.Play("SpriteBounce");
item = newItem;
icon.sprite = item.icon;
icon.enabled = true;
removeButton.interactable = true;
}
public void ClearSlot()
{
item = null;
icon.sprite = null;
icon.enabled = false;
removeButton.interactable = false;
}
public void onRemoveButton()
{
Inventory.instance.Remove(item);
#region
/* dropItemModal.SetActive(true);
yesButton.onClick.AddListener(onYesClick);
itemText.text = item.name;
if (item.isKeyItem != false)
{
yesButtonDisabled.interactable = false;
itemText.text = "You Can't Drop a Key Item!";
}
else
{
yesButtonDisabled.interactable = true;
}
*/
#endregion
}
#region
/* public void onYesClick()
{
// Inventory.instance.Remove(item);
dropItemModal.SetActive(false);
}
public void onNoClick()
{
dropItemModal.SetActive(false);
} */
#endregion
public void UseItem()
{
if (item != null)
{
item.Use();
}
}
public void OnPointerEnter(PointerEventData eventData)
{
//Show Tooltip
if (item != null)
{
Debug.Log(item.name + " " + "Is in this slot");
Inventory.instance.ShowToolTip(item);
}
else
{
Debug.Log("Inventory Slot Empty");
}
}
public void OnPointerExit(PointerEventData eventData)
{
//Hide Tooltip
Debug.Log("Exit");
Inventory.instance.HideToolTip();
}
}