private static void CreateScriptableObjects(ItemCreatorWindow.CustomItem item) { var obj = ScriptableObject.CreateInstance <DynamicData>(); var fields = obj.GetType().GetFields(); Sprite currentText = ItemCreator.GetItemIcon(item.itemIconDirectory); obj.itemIcon = currentText; obj.itemName = item.name; obj.isStackable = item.isStackable; obj.stackAmount = item.stackAmount; obj.inGameName = item.inGameName; obj.description = item.description; obj.category = item.category; foreach (var field in fields) { int hasIndex = item.addedVariables.FindIndex(x => { return(x.varName == field.Name); }); if (hasIndex > -1) { item.addedVariables[hasIndex].data = Convert.ChangeType(item.addedVariables[hasIndex].data, field.FieldType); field.SetValue(obj, item.addedVariables[hasIndex].data); } } AssetDatabase.CreateAsset(obj, $"{ITEMS_FOLDER_PATH}/{item.name}.asset"); }
/// <summary> /// Draws the selection window for the item icon /// </summary> /// <param name="index"></param> private void DrawIconSelection(int index) { GUI.skin = null; Sprite currentSprite = ItemCreator.GetItemIcon(items[index].itemIconDirectory); currentSprite = (Sprite)EditorGUILayout.ObjectField("Item Icon", currentSprite, typeof(Sprite), false); if (!AssetDatabase.GetAssetPath(currentSprite).Equals(items[index].itemIconDirectory)) { items[index].itemIconDirectory = AssetDatabase.GetAssetPath(currentSprite); SaveData(); } }