Search Unity

Clip name -> Text

Discussion in 'Timeline' started by username132323232, Feb 26, 2018.

  1. username132323232

    username132323232

    Joined:
    Dec 9, 2014
    Posts:
    439
    I'm using dummy activation track clips as markers. Would it be possible to set a GUI text field to the name of the clip currently active?

    timeline.PNG
     
  2. seant_unity

    seant_unity

    Unity Technologies

    Joined:
    Aug 25, 2015
    Posts:
    1,010
    What do you mean by currently active? If it's 'selected' the following would work:

    Code (CSharp):
    1.             var serializedObject = new SerializedObject(Selection.activeObject);
    2.             var nameProperty = serializedObject.FindProperty("m_Item.m_DisplayName");
    3.             if (nameProperty != null)
    4.                 EditorGUILayout.PropertyField(nameProperty);
    5.             serializedObject.ApplyModifiedProperties();
    Otherwise, if you are looking for where the time head is at, you will need some combination of the time (playableDirector.time), and searching for the desired track (TimelineAsset.GetOutputTracks()) and the correct clip (TrackAsset.GetClips()).
     
  3. username132323232

    username132323232

    Joined:
    Dec 9, 2014
    Posts:
    439
    Yes, I'm looking at the time head position in the Play mode. Do you happen to have a code sample for that?
     
  4. seant_unity

    seant_unity

    Unity Technologies

    Joined:
    Aug 25, 2015
    Posts:
    1,010
    Something like:

    Code (CSharp):
    1. var time = playableDirector.time;
    2. var timeline = playableDirector.playableAsset as TimelineAsset;
    3.  
    4. TimelineClip[] activeClips = timeline.GetOutputTracks().SelectMany(t => t.GetClips().Where(c => c.start >= t && c.end < time)).ToArray();
     
  5. username132323232

    username132323232

    Joined:
    Dec 9, 2014
    Posts:
    439
    Changed

    Code (CSharp):
    1. Where(c => c.start >= t && c.end < time))
    to

    Code (CSharp):
    1. Where(c => c.start >= time && c.end < time))
    but activeClips stays empty :)
     
  6. seant_unity

    seant_unity

    Unity Technologies

    Joined:
    Aug 25, 2015
    Posts:
    1,010
    Right... typo on my part :)

    Where(c => c.start <= time && c.end > time) is the correct query.
     
    username132323232 likes this.
  7. username132323232

    username132323232

    Joined:
    Dec 9, 2014
    Posts:
    439
    It works! Thank you so much and sorry for my lack of Linq knowledge :)