我正在尝试为 Unity 创建一个组件GameObject
,我们称之为它MediaController
。我希望它能够管理不同媒体(音频/视频)的时间(播放/暂停/等)。我创建了一个PlayableMedia
具有基本属性/字段/方法的抽象类,并创建了 2 个类,PlayableVideo
并且PlayableAudio
,它们根据我们的需要继承和实现。
目的是有一个PlayableMedia
可能与音频/视频无关的单一列表,允许media.Play()
在特定应用程序时间进行简单(即)调用,而不管类型如何......但我的字段public List<PlayableMedia> MediaList;
没有出现在编辑器中并且没有错误。
所以最终我的问题是标题所述:是否可以将PlayableMedia
类用作字段的类型?
根据我的经验,我怀疑“不”,但我发现链接说“是”或“是的,有点”似乎指向自定义编辑器/检查员/抽屉,但我有 0 经验那些并且无法实现它(见下文)。
[System.Serializable]
public class RegisteredMedia
{
public float StartTime;
public PlayableMedia Media;
}
[CustomPropertyDrawer(typeof(RegisteredMedia))]
class RegisteredMediaDrawer : PropertyDrawer
{
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
EditorGUI.BeginProperty(position, label, property);
position = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), new GUIContent("Playable Media"));
var indent = EditorGUI.indentLevel;
EditorGUI.indentLevel = 0;
Rect rectStartTime = new Rect(position.x, position.y, 30, position.height);
Rect rectMedia = new Rect(position.x + 35, position.y, 50, position.height);
EditorGUI.PropertyField(rectStartTime, property.FindPropertyRelative("StartTime"), GUIContent.none);
EditorGUI.PropertyField(rectMedia, property.FindPropertyRelative("Media"), GUIContent.none);
EditorGUI.indentLevel = indent;
EditorGUI.EndProperty();
}
}
public class MediaController : MonoBehaviour
{
public List<RegisteredMedia> MediaList = new List<RegisteredMedia>();
\\[...] rest of implementation
}
谁能帮我吗?要么确认这是不可能的,或者如果是的话,请帮助我实施?
另外,如果可以使用自定义编辑器/检查器/抽屉来完成,有人可以帮我在 中获取单个项目List<RegisteredMedia>
以显示为Start Time ____ Playable Media [=====]
(附有适当组件PlayableMedia
的 a 将在哪里)?GameObject