Search Unity

TimeLineClip OnSceneGUI()

Discussion in 'Timeline' started by tinyant, Feb 5, 2018.

  1. tinyant

    tinyant

    Joined:
    Aug 28, 2015
    Posts:
    127
    Is there any way to make OnSceneGUI method for my TimeLineClip?
    When I select clip in the TimeLine, I want use OnSceneGUI for my TimeLineClip and draw some in my Scene View.

    Thanks.
     
  2. seant_unity

    seant_unity

    Unity Technologies

    Joined:
    Aug 25, 2015
    Posts:
    1,516
    If you write a custom editor for the PlayableAsset derived class for your clip - instead of or in addition to a property drawer for the behaviour - you should be able to implement OnSceneGUI() in the editor.

    This is how the Root motion handles are implemented for timeline animaton clips.
     
  3. tinyant

    tinyant

    Joined:
    Aug 28, 2015
    Posts:
    127
    Thanks.

    When I have implement OnSceneGUI() in my PlayAsset's Editor but when I select the Target Clip In TimeLine ,The OnSceneGUI() never be called.

    Code (CSharp):
    1.     public sealed class CinemachineShot : PlayableAsset, IPropertyPreview
    2.     {
    3.         public ExposedReference<CinemachineVirtualCameraBase> VirtualCamera;
    4.  
    5.         public override Playable CreatePlayable(PlayableGraph graph, GameObject owner)
    6.         {
    7.             var playable = ScriptPlayable<CinemachineShotPlayable>.Create(graph);
    8.             playable.GetBehaviour().VirtualCamera = VirtualCamera.Resolve(graph.GetResolver());
    9.             return playable;
    10.         }
    11.     }
    Code (CSharp):
    1.     [CustomEditor(typeof(CinemachineShot))]
    2.     internal sealed class CinemachineShotEditor : UnityEditor.Editor
    3.     {
    4.  
    5.         void OnSceneGUI()
    6.         {
    7.             Debug.Log("### On scene GUI called :" + this.GetInstanceID());
    8.         }
    9.     }
    Did I make some wrong?
     
  4. seant_unity

    seant_unity

    Unity Technologies

    Joined:
    Aug 25, 2015
    Posts:
    1,516
    Oh, my mistake... you need to register your OnSceneGUI() call.

    Code (CSharp):
    1. public void OnEnable()
    2. {
    3.      SceneView.onSceneGUIDelegate += OnSceneGUI;
    4. }
    5.  
    (also make sure to remove it)
     
    senkal_ likes this.