Greetings.
As a need of saving and exchanging data for 4D models, I digged more into Unity’s inner functionalities, and found this question on Unity’s official forum. Thanks to my Google-fu, I’m aware that a derived class of ScriptableObject can be serialized and used just as a asset in UnityEditor, as I’ve tried Object derived class for saved assets before, but it won’t drop into a property field in the inspector.
I created several classes for a quick test (formatted / abridged for a better delivery of ideas):
TestData.cs:
[CreateAssetMenu(fileName = "TestData", menuName = "TestData")]
public class TestData : ScriptableObject {
public int foo;
public float bar;
}
TestDataLoader.cs:
[ExecuteInEditMode]
public class TestDataLoader : MonoBehaviour {
public TestData data;
void OnValidate() {
Debug.Log("TestData : " + (data == null ? "null" : data.foo + " " + data.bar));
}
}
TestDataSaver.cs
public class TestDataSaver : MonoBehaviour {
public int foo;
public float bar;
void OnValidate() {
var data = ScriptableObject.CreateInstance<TestData>();
data.foo = foo;
data.bar = bar;
AssetDatabase.CreateAsset(data, "Assets/TestDataSaved.asset");
AssetDatabase.SaveAssets();
}
}
As I finished class TestData, I noticed that there is a menu item available to create a asset of class TestData with properties editable.
Data saving and loading works well too.
After the end of searching, I’d like to put some useful links to refer and give credit to. (Although all testing above is enough for me!)