public static void Test() { GameObject[] obj = Selection.gameObjects; for (int i = 0, length = obj.Length; i < length; i++) { MVideoPlayer mVideoPlayer = obj[i].GetComponentInChildren <MVideoPlayer>(); //if (mVideoPlayer) //{ //if (mVideoPlayer.isPlaying) // mVideoPlayer.Stop(); //else // mVideoPlayer.Play(); //} mVideoPlayer.Play(0, MVideoPlayer.MPlayType.EasyIn); //Debug.Log("frame:"+mVideoPlayer.frame+" ,frame count:"+mVideoPlayer.frameCount+" ,time:"+mVideoPlayer.time+" ,length:"+mVideoPlayer.length); //mVideoPlayer.RegisterEvent(50f, new HotKey().Callback); } }
private void Callback(MVideoPlayer mVideoPlayer) { Debug.Log("Callback:" + mVideoPlayer.time + " " + mVideoPlayer.frame); }
void OnGUI() { if (Selection.activeGameObject != null) { mVideoPlayer = Selection.activeGameObject.GetComponent <MVideoPlayer>(); if (mVideoPlayer.clip != null) { length = mVideoPlayer.clip.length; frameCount = mVideoPlayer.clip.frameCount; } speed = mVideoPlayer.playbackSpeed; currentTime = mVideoPlayer.time; frame = (ulong)mVideoPlayer.frame; if (length != 0) { progress = (float)(currentTime / length); } } EditorGUILayout.Space(); EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("Play")) { if (mVideoPlayer == null) { Debug.LogError("Please select a MVideoPlayer script GameObject!"); } else { mVideoPlayer.Play(); isPlaying = true; pause = false; stop = false; } } if (GUILayout.Button("Pause")) { if (mVideoPlayer == null) { Debug.LogError("Please select a MVideoPlayer script GameObject!"); } else { mVideoPlayer.Pause(); isPlaying = false; pause = true; stop = false; } } if (GUILayout.Button("Stop")) { if (mVideoPlayer == null) { Debug.LogError("Please select a MVideoPlayer script GameObject!"); } else { mVideoPlayer.Stop(); isPlaying = false; pause = false; stop = true; } } EditorGUILayout.EndHorizontal(); newProgress = EditorGUILayout.Slider(progress, 0, 1); if (Mathf.Abs(newProgress - progress) > 0.001f)//滑动改变播放进度 { if (mVideoPlayer != null) { if (isPlaying) { mVideoPlayer.time = (newProgress * length); } } } }