Im following the Burgzerg Arcade course to make RPG items, and im having the next problems:
Dont know what to do because in second image it should be showing the 2 fields (Name and sprite) and not what is showing, and in the first image is not saving to database.
Second Code should look like this one: Screenshot by Lightshot
Here are my codes:
using UnityEngine;
using System.Collections;
namespace Sakyadu.ItemSystem {
[System.Serializable]
public class ISTier : IISTier {
[SerializeField] string _name;
[SerializeField] Sprite _icon;
public ISTier(){
_name = "Common";
_icon = new Sprite();
}
public string Name{
get {return _name;}
set {_name = value;}
}
public Sprite Icon{
get {return _icon;}
set {_icon = value;}
}
}
}
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
namespace Sakyadu.ItemSystem {
public class ISTierDatabase : ScriptableObject {
//[SerializeField]
public List<ISTier> database = new List<ISTier>();
}
}
The second one
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
namespace Sakyadu.ItemSystem {
public class ISTierDatabase : ScriptableObject {
//[SerializeField]
public List<ISTier> database = new List<ISTier>();
}
}
The last one
using UnityEditor;
using UnityEngine;
using System.Collections;
namespace Sakyadu.ItemSystem.Editor {
public class ISTierDatabaseEditor : EditorWindow {
ISTierDatabase tierDatabase;
ISTier selectedItem;
Texture2D selectedTexture;
const int SPRITE_BUTTON_SIZE = 46;
const string FILE_NAME = @"sakyaduTierDatabase.asset";
const string DATABASE_FOLDER_NAME = @"Database";
const string DATABASE_FULL_PATH = @"Assets/" + DATABASE_FOLDER_NAME + "/" + FILE_NAME;
[MenuItem("SakyaduEditor/Database/Tier Editor %#i")]
public static void Init() {
ISTierDatabaseEditor window = EditorWindow.GetWindow<ISTierDatabaseEditor> ();
window.minSize = new Vector2 (200, 300);
window.title = "Tier DB";
window.Show ();
}
void OnEnable(){
tierDatabase = AssetDatabase.LoadAssetAtPath (DATABASE_FULL_PATH, typeof(ISTierDatabase)) as ISTierDatabase;
if (tierDatabase == null) {
if (!AssetDatabase.IsValidFolder("Assets/" + DATABASE_FOLDER_NAME))
AssetDatabase.CreateFolder("Assets", DATABASE_FOLDER_NAME);
tierDatabase = ScriptableObject.CreateInstance<ISTierDatabase>();
AssetDatabase.CreateAsset(tierDatabase,DATABASE_FULL_PATH);
AssetDatabase.SaveAssets();
AssetDatabase.Refresh();
}
selectedItem = new ISTier ();
}
void OnGUI(){
AddTierToDetabase();
}
void AddTierToDetabase(){
//Name
selectedItem.Name = EditorGUILayout.TextField("Name:", selectedItem.Name);
//Sprite
if (selectedItem.Icon)
selectedTexture = selectedItem.Icon.texture;
else
selectedTexture = null;
if (GUILayout.Button (selectedTexture, GUILayout.Width (SPRITE_BUTTON_SIZE), GUILayout.Height (SPRITE_BUTTON_SIZE))) {
int controlerID = EditorGUIUtility.GetControlID(FocusType.Passive);
EditorGUIUtility.ShowObjectPicker<Sprite>(null, true, null, controlerID);
}
string commandName = Event.current.commandName;
if (commandName == "ObjectSelectorUpdated") {
selectedItem.Icon = (Sprite)EditorGUIUtility.GetObjectPickerObject();
Repaint();
}
if (GUILayout.Button ("Save")) {
if (selectedItem == null)
return;
tierDatabase.database.Add(selectedItem);
selectedItem = new ISTier();
}
}
}
}