Advertisement
Guest User

Unity Error Code

a guest
Jan 3rd, 2016
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.68 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3. using LitJson;
  4. using System.Collections.Generic;
  5. using System.IO;
  6.  
  7. public class ItemDatabase : MonoBehaviour {
  8.  
  9.     private List<Item> database = new List<Item>();    //Lists the items
  10.     private JsonData itemData;                      //Grabbing items from json
  11.  
  12.     void Start()
  13.     {
  14.         //WHERE THE VALUES WILL BE STORED
  15.         itemData = JsonMapper.ToObject(File.ReadAllText(Application.dataPath + "/StreamingAssets/Items.json"));  //Read the data from json
  16.         ConstructItemDatabase();
  17.  
  18.         Debug.Log(database[1].Title);
  19.     }
  20.  
  21.     public Item FetchItemByID(int id)
  22.     {
  23.         for (int i = 0; i < database.Count; i++)
  24.             if (database[i].ID  == id)
  25.                 return database[i];
  26.         return null;
  27.     }
  28.  
  29.     void ConstructItemDatabase()
  30.     {
  31.         for (int i = 0; i < itemData.Count; i++)
  32.         {
  33.             //VALUES ADDED TO DATABASE
  34.             database.Add(new Item((int)itemData [i]["id"], itemData[i]["title"].ToString(), (int)itemData[i]["value"],
  35.                 (int)itemData[i]["stats"]["damage"], (int)itemData[i]["stats"]["attackspeed"], (int)itemData[i]["stats"]["movespeed"], (int)itemData[i]["stats"]["defense"],
  36.                 (int)itemData[i]["stats"]["warmth"], itemData[i]["description"].ToString(), (bool)itemData[i]["stackable"], itemData[i]["slug"].ToString));
  37.         }
  38.     }
  39.  
  40. }
  41.  
  42.  
  43. public class Item
  44. {                       //VARIABLES THAT ALL ITEMS CAN USE
  45.     private int ID{get; set;}               //ITEM ID THAT WILL BE USED TO IDENTIFY ITEMS
  46.     public string Title {get; set;}         //NAME THAT WILL APPEAR IN-GAME
  47.     public int Value { get; set;}           //STATES THE VALUE OF THE ITEM  EX. DIFFERENT COLORS
  48.     public int Damage {get; set;}           //AMOUNT OF DAMAGE THE ITEM WILL DO TO ANOTHER OBJECT
  49.     public int AttackSpeed {get; set;}      //HOW FAST THE ITEM GOES FROM IDLE ---> DEALING DAMAGE
  50.     public int MoveSpeed {get; set;}        //THE SPEED OF THE CHARACTER WHILE MOVING WITH THE ITEM
  51.     public int Defense {get; set;}          //AMOUNT OF DEFENSE THE ITEM PROTECTS THE CHARACTER WITH
  52.     public int Warmth {get; set;}           //AMOUNT OF WARMTH THE CHARCTER RECIEVES WHILE HAVING THE ITEM
  53.     public string Description {get; set;}   //DESCRIBES THE ITEM IN-GAME
  54.     public bool Stackable {get; set;}       //BOOLEAN OF WHETHER THE ITEM IS STACKABLE OR NOT
  55.     public string Slug {get; set;}
  56.  
  57.  
  58.     public Item(int id, string title, int value, int damage, int attackspeed, int movespeed, int defense, int warmth, string description, bool stackable, string slug)
  59.     {
  60.         this.ID = id;
  61.         this.Title = title;
  62.         this.Value = value;
  63.         this.Damage = damage;
  64.         this.AttackSpeed = attackspeed;
  65.         this.MoveSpeed = movespeed;
  66.         this.Defense = defense;
  67.         this.Warmth = Warmth;
  68.         this.Description = description;
  69.         this.Stackable = stackable;
  70.         this.Slug = slug;  
  71.     }
  72.     public Item()
  73.     {
  74.         this.ID = -1;       //INVALID ID CHECK
  75.     }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement