How to use "SerializeObject" with an object which doesn't derive from Object?
I want to design a tool to simulate the functionality of inspector, and I have some problems. Due to the original data is not an "Unity.Object", I try to use the "ScriptableObject" to solve the problem. My code is as follows:
class MyData
{
public int propertyInt;
}
class MySerializeObject<T> : ScriptableObject
{
public T value;
}
class MySerializeTypeData : MySerializeObject<MyData>
{
}
usage:
private void Draw(object obj)
{
MySerializeTypeData mySerializeObject = ScriptableObject.CreateInstance<MySerializeTypeData>();
mySerializeObject.value = obj as MyData;
SerializedObject serializedObject = new SerializedObject(mySerializeObject);
SerializedProperty property = serializedObject.FindProperty("value.propertyInt");
EditorGUILayout.PropertyField(property);
}
It works, but when I want to make this more general, it failed. I change the value to type "object":
class MySerializeObject : ScriptableObject
{
public object value;
}
private void Draw(object obj)
{
MySerializeObject mySerializeObject = ScriptableObject.CreateInstance<MySerializeObject>();
mySerializeObject.value = obj ;
SerializedObject serializedObject = new SerializedObject(mySerializeObject);
SerializedProperty property = serializedObject.FindProperty("value.propertyInt");
EditorGUILayout.PropertyField(property);
}
I guess that unity has reflect the type "MySerializeObject " before, so it cannot recognize the specific type of "value". How should I modify my code to solve the problem, or is there any other ways to implement my requirement?
Your answer

Follow this Question
Related Questions
because my game does not access my Scriptable Object 0 Answers
Resources.unload on scriptable object resets it's prefab references 0 Answers
Making Node editor but having problem with passing through non static data to static method 0 Answers
Assets not loading correctly at startup 1 Answer
Crash when reimporting custom assets 0 Answers