Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- using LitJson;
- using System.Collections.Generic;
- using System.IO;
- public class ItemDatabase : MonoBehaviour {
- private List<Item> database = new List<Item>(); //Lists the items
- private JsonData itemData; //Grabbing items from json
- void Start()
- {
- //WHERE THE VALUES WILL BE STORED
- itemData = JsonMapper.ToObject(File.ReadAllText(Application.dataPath + "/StreamingAssets/Items.json")); //Read the data from json
- ConstructItemDatabase();
- Debug.Log(database[1].Title);
- }
- public Item FetchItemByID(int id)
- {
- for (int i = 0; i < database.Count; i++)
- if (database[i].ID == id)
- return database[i];
- return null;
- }
- void ConstructItemDatabase()
- {
- for (int i = 0; i < itemData.Count; i++)
- {
- //VALUES ADDED TO DATABASE
- database.Add(new Item((int)itemData [i]["id"], itemData[i]["title"].ToString(), (int)itemData[i]["value"],
- (int)itemData[i]["stats"]["damage"], (int)itemData[i]["stats"]["attackspeed"], (int)itemData[i]["stats"]["movespeed"], (int)itemData[i]["stats"]["defense"],
- (int)itemData[i]["stats"]["warmth"], itemData[i]["description"].ToString(), (bool)itemData[i]["stackable"], itemData[i]["slug"].ToString));
- }
- }
- }
- public class Item
- { //VARIABLES THAT ALL ITEMS CAN USE
- private int ID{get; set;} //ITEM ID THAT WILL BE USED TO IDENTIFY ITEMS
- public string Title {get; set;} //NAME THAT WILL APPEAR IN-GAME
- public int Value { get; set;} //STATES THE VALUE OF THE ITEM EX. DIFFERENT COLORS
- public int Damage {get; set;} //AMOUNT OF DAMAGE THE ITEM WILL DO TO ANOTHER OBJECT
- public int AttackSpeed {get; set;} //HOW FAST THE ITEM GOES FROM IDLE ---> DEALING DAMAGE
- public int MoveSpeed {get; set;} //THE SPEED OF THE CHARACTER WHILE MOVING WITH THE ITEM
- public int Defense {get; set;} //AMOUNT OF DEFENSE THE ITEM PROTECTS THE CHARACTER WITH
- public int Warmth {get; set;} //AMOUNT OF WARMTH THE CHARCTER RECIEVES WHILE HAVING THE ITEM
- public string Description {get; set;} //DESCRIBES THE ITEM IN-GAME
- public bool Stackable {get; set;} //BOOLEAN OF WHETHER THE ITEM IS STACKABLE OR NOT
- public string Slug {get; set;}
- public Item(int id, string title, int value, int damage, int attackspeed, int movespeed, int defense, int warmth, string description, bool stackable, string slug)
- {
- this.ID = id;
- this.Title = title;
- this.Value = value;
- this.Damage = damage;
- this.AttackSpeed = attackspeed;
- this.MoveSpeed = movespeed;
- this.Defense = defense;
- this.Warmth = Warmth;
- this.Description = description;
- this.Stackable = stackable;
- this.Slug = slug;
- }
- public Item()
- {
- this.ID = -1; //INVALID ID CHECK
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement