というわけで表題のエラーの話
今回はEditorGUI.PropertyFieldでVector3型を表示しようとしてできなかったので対応した話。
// ここで表題のエラーが出る
EditorGUI.PropertyField(rect, action.FindPropertyRelative("targetPosition"));
action.FindPropertyRelative("targetPosition")はVector3型が格納されている
action.FindPropertyRelative("targetPosition").vector3value等を見ると正常に取れている事がわかる
EditorGUI.PropertyField(rect, action.FindPropertyRelative("targetPosition"));
を使いたいけど表題のエラーが出てうまくいかない場合は以下のように直す事で解決ができる。
action.FindPropertyRelative("targetPosition").vector3Value = EditorGUI.Vector3Field(rect, "hoge", action.FindPropertyRelative("targetPosition").vector3Value);
しかし厳密な解決じゃないというか
例えば
var properties = new string[] { "hoge", "fuga", "targetPosition" };
foreach (var p in properties)
{
EditorGUI.PropertyField(rect, action.FindPropertyRelative(p));
}
のようにしたい場合にこまるかもしれない。
1つ2つの例外ならいいかもしれないけどそうもいかないとおもう。
そこについては解決したらまたなんか描きます
追記
var properties = new string[]{"hoge", "fuga", "targetPosition"};
foreach (var p in properties)
{
var property = action.FindPropertyRelative(p);
switch(property.propertyType)
{
case SerializedPropertyType.Vector3:
property.vector3Value = EditorGUI.Vector3Field(rect, property.displayName, property.vector3Value);
break;
default:
EditorGUI.PropertyField(rect, property);
break;
}
}
これで良さそう