private void CreateAssetsAndPrefabs(List <Dictionary <string, object> > data, int i)
    {
        // Create .asset file
        ItemAssetData itemAsset = ScriptableObject.CreateInstance <ItemAssetData>();

        itemAsset.Name       = (string)data[i]["NAME"];
        itemAsset.Range      = (int)data[i]["RANGE"];
        itemAsset.Attack     = (int)data[i]["ATTACK"];
        itemAsset.Defense    = (int)data[i]["DEFENSE"];
        itemAsset.Durability = (int)data[i]["DURABILITY"];
        itemAsset.Cost       = (int)data[i]["COST"];

        AssetDatabase.CreateAsset(itemAsset, "Assets/Resources/" + OutputFolder + itemAsset.Name + ".asset");
        AssetDatabase.SaveAssets();

        // Create .prefab files
        var gameobject = new GameObject();

        gameobject.transform.name = itemAsset.Name;
        ItemPrefabData itemPrefab = gameobject.AddComponent <ItemPrefabData>();

        itemPrefab.Initialize(itemAsset.Name, itemAsset.Range, itemAsset.Attack, itemAsset.Defense,
                              itemAsset.Durability, itemAsset.Cost);

#pragma warning disable 618
        Object prefab = EditorUtility.CreateEmptyPrefab("Assets/Resources/" + OutputFolder + itemAsset.Name + ".prefab");
        EditorUtility.ReplacePrefab(gameobject, prefab, ReplacePrefabOptions.ConnectToPrefab);
#pragma warning restore 618
        DestroyImmediate(gameobject);
    }
Exemple #2
0
    public ItemData GetItem(string itemName)
    {
        ItemAssetData result = items.TryGetValue(itemName);

        if (result != null)
        {
            return(result.GenerateItem());
        }
        else
        {
            Debug.Log("Item " + itemName + " not found.");
            return(null);
        }
    }