Exemple #1
0
    /// <summary>
    /// Function used by the GameManager to initialize the client's item database.
    /// </summary>
    static void LoadItemDictionary()
    {
        ItemPathSerial itemDataCollection = new ItemPathSerial();

        try
        {
            string itemPathJson = CustomTextService.ReadJsonFromResources("JsonData/ItemPathData/itempaths"); //Take all of the item's filepath json file and convert to string
            itemDataCollection = CustomTextService.DeSerializeJson <ItemPathSerial>(itemPathJson);            //DeSerialize the json
        }
        catch (Exception e)
        {
            Debug.LogError(e.ToString());
        }

        ItemList = new Dictionary <string, ItemBase>(); // Initialize the ItemDatabase Dictionary
        foreach (ItemPath item in itemDataCollection.data)
        {
            ItemBase itembs = (Resources.Load(item.resourcesPath) as GameObject).GetComponent <ItemBase>(); //as simple as it gets
            ItemList.Add(item.itemIdentifier, itembs);
        }
        DebugConsole.LogDev(string.Format("Item Database was succesfully loaded with {0} total items.", ItemList.Count));
    }