I have the following data container.
[System.Serializable]
public class SomeDataType
{
public int Value;
}
With the following object holding a list of those objects.
public class DataTypeHolder : ScriptableObject
{
public List<SomeDataType> ListOfData;
}
Then I try to create a menu item to create the object
using UnityEngine;
using UnityEditor;
using System.Collections;
public class DataTypeCreator
{
[MenuItem("Assets/Create/Some Data Type")]
public static void CreateAsset()
{
ScriptableObjectUtility.CreateAsset<DataTypeHolder>();
}
}
and lastly the ScriptableObjectUtility
using UnityEngine;
using UnityEditor;
using System.IO;
public static class ScriptableObjectUtility
{
public static void CreateAsset<T>() where T : ScriptableObject
{
T asset = ScriptableObject.CreateInstance<T>();
string path = AssetDatabase.GetAssetPath(Selection.activeObject);
if (path == "")
{
path = "Assets";
}
else if (Path.GetExtension(path) != "")
{
path = path.Replace(Path.GetFileName(AssetDatabase.GetAssetPath(Selection.activeObject)), "");
}
string assetPathAndName = AssetDatabase.GenerateUniqueAssetPath(path + "/New " + typeof(T).ToString() + ".asset");
AssetDatabase.CreateAsset(asset, assetPathAndName);
AssetDatabase.SaveAssets();
EditorUtility.FocusProjectWindow();
Selection.activeObject = asset;
}
}
Thanks in advance for helping point me in the right direction
Edit: I must be too tired … I forgot to post the error I am getting …
Instance of DataTypeHolder couldn’t be created because there is no script with that name.
UnityEngine.ScriptableObject:CreateInstance()