Search Unity

Question Set Custom Clip Duration

Discussion in 'Timeline' started by GeniusKoala, Nov 28, 2022.

  1. GeniusKoala

    GeniusKoala

    Joined:
    Oct 13, 2017
    Posts:
    97
    Hi!

    I am coding a custom playable to read data from an external file and I want to be able to read it from a timeline. I read a file to fill an array of string so now I would like the duration of the clip to be the length of this array. So far so good but I wonder how to program the "C" shortcut like for Unity animation clips to automatically set the lenght of the clip with the duration of the content. Like if an animation lasts 2sec, if you select it in the timeline and press the "C" shortcut the clip will have a 2sec duration in the timeline. How to do that for a custom playable please?


    Thanks for helping!
     
  2. superarhow

    superarhow

    Joined:
    Mar 24, 2015
    Posts:
    5
    Hello, unfortunately the "C" function is not public. So you can call it via reflection:
    Code (CSharp):
    1.     public static void DoMatchContent()
    2.     {
    3.         var method = typeof(TimelineEditor).Assembly.GetType("UnityEditor.Timeline.ClipModifier").GetMethod("MatchContent",
    4.             0, new System.Type[] { typeof(IEnumerable<UnityEngine.Timeline.TimelineClip>) } );
    5.         method.Invoke(null, new object[] { TimelineEditor.selectedClips });
    6.     }
    or, you can send the key directly:
    Code (CSharp):
    1.     public static void DoMatchContent2()
    2.     {
    3.         var e = Event.KeyboardEvent("C");
    4.         EditorWindow.focusedWindow.SendEvent(e);
    5.     }
    ※ You need to call with timeline's editor window opened.
     
    GeniusKoala likes this.