Hi guys,
I have a small problem. So I have a scriptable object class:
public class Item : ScriptableObject
{
[SerializeField] private string m_name;
public string Name => m_name;
[SerializeField] private Sprite m_spriteItem;
public Sprite SpriteItem => m_spriteItem;
}
A few class inherit from it:
public class Weapon : Item
{
[SerializeField] private int m_damage;
public int Damage => m_damage;
}
public class Shield : Item
{
}
And I have a class where I create this scriptable object:
public abstract class Items<T> : ScriptableObject where T : Item
{
protected const string ASSET_EXTENSION = ".asset";
[SerializeField, FolderPath(RequireExistingPath = true), Required] protected string m_scriptableObjectPath;
[SerializeField] private List<T> m_items = new List<T>();
public List<T> ListOfItems => m_items;
[SerializeField, FolderPath(RequireExistingPath = true), Required] protected string m_scriptableObjectPathForNewItem;
[field: SerializeField, ValueDropdown("FindItemClass")] public T NewItem { get; private set; }
[SerializeField] private string m_newItemName;
public string NewItemName => m_newItemName;
[SerializeField] private Sprite m_newItemSprite;
public Sprite NewSpriteItem => m_newItemSprite;
[Button("Create item")]
private void CreateItem()
{
if (m_newItemName != string.Empty && m_scriptableObjectPath != string.Empty)
{
AssetDatabase.CreateAsset(NewItem, m_scriptableObjectPathForNewItem + "/" + m_newItemName + ASSET_EXTENSION);
AssetDatabase.SaveAssets();
}
}
}
And then I want to inherit from Items class:
public class Weapons : Items<Weapon>
{
}
And next I have class:
public class CreateItems<T> : CreateDataBaseClass where T : Items<Item>
{
[field: SerializeField] public T Items { get; private set; }
public CreateItems()
{
Items = ScriptableObject.CreateInstance<T>();
}
[Button("Create list with items"), PropertyOrder(0)]
protected override void CreateData()
{
if (m_scriptableObjectName != string.Empty && m_scriptableObjectPath != string.Empty)
{
AssetDatabase.CreateAsset(Items, m_scriptableObjectPath + "/" + m_scriptableObjectName + ASSET_EXTENSION);
AssetDatabase.SaveAssets();
}
}
}
And on the and I want to create object from CreateItems<> like this:
public class PlayerDataWindow : OdinMenuEditorWindow
{
[MenuItem("Windows/ Player data window")]
private static void OpenWindow()
{
GetWindow<PlayerDataWindow>().Show();
}
private CreatePlayerData m_createPlayerMovmentData;
private CreateItems<Weapons> m_createWeaponItems;
private CreateItems<Shields> m_createShieldsItems;
protected override OdinMenuTree BuildMenuTree()
{
var tree = new OdinMenuTree();
m_createPlayerMovmentData = new CreatePlayerData();
m_createWeaponItems = new CreateItems<Weapons>();
m_createShieldsItems = new CreateItems<Shields>();
tree.Add("Create New Player Data", m_createPlayerMovmentData);
tree.Add("Create new weapons List", m_createWeaponItems);
tree.Add("Create new shields list", m_createShieldsItems);
tree.AddAllAssetsAtPath("Palyer data", "Assets/ScriptableObjects/PlayerData/", typeof(PlayerData));
tree.AddAllAssetsAtPath("Items", "Assets/ScriptableObjects/Items/Weapons/", typeof(Items<Weapon>));
tree.AddAllAssetsAtPath("Items", "Assets/ScriptableObjects/Items/Weapons/", typeof(Items<Shield>));
return tree;
}
protected override void OnDestroy()
{
base.OnDestroy();
if (m_createPlayerMovmentData != null)
{
DestroyImmediate(m_createPlayerMovmentData.PlayerData);
}
}
protected override void OnBeginDrawEditors()
{
OdinMenuTreeSelection odinMenuSelectied = this.MenuTree.Selection;
SirenixEditorGUI.BeginHorizontalToolbar();
{
GUILayout.FlexibleSpace();
if (SirenixEditorGUI.ToolbarButton("Delete current"))
{
PlayerData asset = odinMenuSelectied.SelectedValue as PlayerData;
string pathToAsset = AssetDatabase.GetAssetPath(asset);
AssetDatabase.DeleteAsset(pathToAsset);
AssetDatabase.SaveAssets();
}
}
SirenixEditorGUI.EndHorizontalToolbar();
}
}
And I have an error from line:
And the message is:
The question is, is there a posibility to create class like I do in PlayerDataWindow class? And what I should change to fix this problem?
Also when I inherit in Weapons class like this:
public class Weapons : Items<Item>
{
}
I don’t have an error in editor, but it dosen’t work as I want.
If anybody prefer normal repository there is a link: pgproject/FPSGame (github.com)
Branch: PlayerEquipment
I will be so greatufull for help.