That is because you are serializing the “value” of the property, not the property itself. I dont think you really want the “name” and “type” data.
As i see it, a Copy/Paste for a PropertyDrawer would copy the “value” of the property, so you can paste it onto another property of the same type (not onto the “same” property, of another instance).
So
public class Foo {
public int someInt;
public float someFloat;
}
would produce (ill give it some random values):
{
"someInt" = 1,
"someFloat" = 3.14
}
What i think you are saying, is that if you have some type that holds an instance of Foo
public class SomeImportantType
{
public Foo myFooProperty;
}
and seems that you want the “Copy·” to produce something like
"myFooProperty" = {
"type" = "MyNamespace.Foo, MyAssembly",
"properties" = {
"someInt" = 1,
"someFloat" = 3.14
}
}
But first, this would not be valid Json, because there is no { } wrapper, and if there were, then that json would represent "An object with a ‘myFooProperty’ " of type Foo with this fields.
But do you really need all this?
If you just go for the first approach (just serializing the inner properties), and copy that to the systemCopyBuffer. Then for “Paste” you would check the type you are pasting into, and see if the Json can produce a value of that type, like
public bool IsJsonOfType<T>(string myJsonString)
{
T foo;
try{
foo = JsonUtility.FromJson<T>(myJsonString);
return foo != null;
}
catch{
// the contents of the "myJsonString" are not a T object or not even valid Json
return false;
}
}