我在检查器中显示Serializable泛型类时遇到问题.
Serializable泛型类如下:
using UnityEngine;
using System;
using System.Collections;
[Serializable]
public class GenericClass<T> where T : struct
{
[SerializeField]
string _serializedString;
public string SerializedString
{
get { return _serializedString; }
set { _serializedString = value; }
}
... // Functions using the generic type
}
Run Code Online (Sandbox Code Playgroud)
自定义属性抽屉如下:
using UnityEngine;
using UnityEditor;
[CustomPropertyDrawer(typeof(GenericClass<>))]
public class GenericClassDrawer: PropertyDrawer
{
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
SerializedProperty stringProperty = property.FindPropertyRelative("SerializedString");
stringProperty.stringValue = EditorGUI.TextField(position, stringProperty.stringValue);
}
}
Run Code Online (Sandbox Code Playgroud)
MonoBehaviour我正在使用测试泛型类如下:
using UnityEngine;
using System.Collections; …Run Code Online (Sandbox Code Playgroud)