Scriptum/Assets/Scripts/SceneManager/SaveItem/ItemData/ItemData.cs
kabix09 602c94726a Add scene manager for items
Start rebuild Save & Load game system
2022-06-19 01:25:49 +02:00

57 lines
1.6 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
[System.Serializable]
public class ItemData
{
public int id;
public string name;
public string description;
public int level;
public string imageName;
// to handle object created on scene for example after removing from inventory
public string itemModelName;
private const string SPRITE_LOCALIZATION = "Sprites/Object Sprites/";
private const string ITEM_LOCALIZATION = "Assets/Items/";
public ItemData(Item item)
{
id = item.id;
name = item.name;
description = item.description;
level = item.level;
imageName = item.image.name;
itemModelName = item.itemModel.name;
}
public Item MapDataToItem(string prefarbAssetName)
{
// Find prefarb in Assets/
Item item = (Item)AssetDatabase.LoadAssetAtPath(ITEM_LOCALIZATION + prefarbAssetName + ".asset", typeof(Item));
///
// DONT OVERWRITE PROPERTIES BECOUSE ITS EDIT MAIN OBJECT IN ASSET/
///
// item.Id = this.id;
// item.Name = this.name;
// item.Description = this.description;
// item.Level = this.level;
// Debug.Log(ITEM_LOCALIZATION + this.imageName);
// item.Image = (Sprite)AssetDatabase.LoadAssetAtPath(ITEM_LOCALIZATION + this.imageName, typeof(Sprite));
// Debug.Log(item.Image);
// item.ItemModel = (GameObject)AssetDatabase.LoadAssetAtPath(ITEM_LOCALIZATION + "Gold Ore" + ".prefab", typeof(GameObject));
return item;
}
}