Editor子类复写以下方法
public override bool RequiresConstantRepaint()
{
return true;
}
eg:
using System.Globalization;
using UnityEditor;
using UnityEngine;
using UnityEngine.Video;
[CustomEditor(typeof(VideoPlayer))]
public class VideoPlayerEditor : Editor
{
private VideoPlayer _videoPlayer;
private float _curProcess;
private string buttonStr;
protected void OnEnable()
{
_videoPlayer = (VideoPlayer)target;
}
public override void OnInspectorGUI()
{
base.OnInspectorGUI();
GUILayout.Space(5);
GUILayout.Label(_curProcess.ToString(CultureInfo.InvariantCulture) + "s");
_curProcess = GUILayout.HorizontalSlider(_curProcess, 0, (float)_videoPlayer.length);
buttonStr = _videoPlayer.isPlaying ? "Pause" : "Play";
_curProcess = (float)_videoPlayer.time;
if (GUILayout.Button(buttonStr))
{
if (_videoPlayer.isPlaying)
{
_videoPlayer.Pause();
}
else
{
_videoPlayer.Play();
}
}
}
public override bool RequiresConstantRepaint()
{
return true;
}
}
|