KITASENJU DESIGN BLOG

memo, html, javascript, unity

UnityRecorderをscriptから呼ぶ

how to call UnityRecorder from scripts

//using UnityEditor.Recorder;

      var window = (RecorderWindow)EditorWindow.GetWindow(typeof(RecorderWindow));
      if(!window.IsRecording()){
        window.StartRecording();
      }

//stop!
      if(window.IsRecording()){
        window.StopRecording();
      }

reference

How to manually pause/unpause by script? - Unity Forum

inspectorからrecできるように

using UnityEditor;
using UnityEngine;
using UnityEditor.Recorder;

[CustomEditor(typeof(Player))]//拡張するクラスを指定
public class PlayerEditor : Editor {

  public override void OnInspectorGUI(){

    base.OnInspectorGUI ();
    Player exampleScript = target as Player;

    //準備。まず押してpause状態
    if( GUILayout.Button("Prepare Editor")){
      EditorApplication.isPaused = true;
      EditorApplication.EnterPlaymode();
    }

    //pauseからrec
    if (GUILayout.Button("PlayMotion&Rec")){

        EditorApplication.isPaused =false;

        var window = (RecorderWindow)EditorWindow.GetWindow(typeof(RecorderWindow));
        if(!window.IsRecording()){
          window.StartRecording();
        }

        //play
        exampleScript.SendMessage ("Play", null, SendMessageOptions.DontRequireReceiver);
    }

    if (GUILayout.Button("Only Play")){
      //テスト用
      exampleScript.SendMessage ("Play", null, SendMessageOptions.DontRequireReceiver);
    }

    if (GUILayout.Button("Stop Rec")){
      var window = (RecorderWindow)EditorWindow.GetWindow(typeof(RecorderWindow));
      if(window.IsRecording()){
        window.StopRecording();
      }
      EditorApplication.ExitPlaymode();
    }

  }

}  

参考

blog.yucchiy.com

"FOOTER"