Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Resolved How to change TimelineClip's color?

Discussion in 'Timeline' started by Threeyes, Sep 17, 2020.

  1. Threeyes

    Threeyes

    Joined:
    Jun 19, 2014
    Posts:
    32
    As mention on title, I want to change every Clip's color base on it's state, is there a way to do this? upload_2020-9-17_10-56-55.png

    By the way, Unity has provide a way to chang the whole track's color:
    Code (CSharp):
    1. [TrackColor(0f, 1f, 0f)]
     
  2. VOTRUBEC

    VOTRUBEC

    Joined:
    Dec 17, 2014
    Posts:
    70
    Here's what I've been doing.

    An actor clip contains an actor profile, that has a colour as one of the fields. I use THAT as the clip colour so we can see straight away what character drives the clip.

    Code (CSharp):
    1.  
    2.     [CustomTimelineEditor ( typeof ( ActorClip ) )]
    3.     public class ActorClipEditor : ClipEditor
    4.     {
    5.         public override ClipDrawOptions GetClipOptions ( TimelineClip clip )
    6.         {
    7.             var clipOptions = base.GetClipOptions ( clip );
    8.             var characterProfile = ( ( ActorClip ) clip.asset ).behaviour.characterProfile;
    9.             clipOptions.highlightColor = characterProfile?.ConversationColor ?? Color.grey;
    10.             return clipOptions;
    11.         }
    12.     }
     
    seant_unity and Threeyes like this.
  3. Threeyes

    Threeyes

    Joined:
    Jun 19, 2014
    Posts:
    32
    Thanks for your help, but I can't found any info about 'ClipEditor' or 'ClipDrawOptions', can you tell me which version of Unity you are using?
     
  4. VOTRUBEC

    VOTRUBEC

    Joined:
    Dec 17, 2014
    Posts:
    70
    I'm using 2020, but .. I'm pretty sure it's been available since UnityEngine.Timeline.

    I took a look at ClipEditor, and it returned this (ILspy would be even better):

    using System.Collections.Generic;
    using UnityEngine;
    using UnityEngine.Playables;
    using UnityEngine.Timeline;
    namespace UnityEditor.Timeline
    {
    public class ClipEditor
    {
    public ClipEditor ( );
    public virtual void DrawBackground ( TimelineClip clip, ClipBackgroundRegion region );
    public virtual ClipDrawOptions GetClipOptions ( TimelineClip clip );
    public Color GetDefaultHighlightColor ( TimelineClip clip );
    public string GetErrorText ( TimelineClip clip );
    public virtual void GetSubTimelines ( TimelineClip clip, PlayableDirector director, List<PlayableDirector> subTimelines );
    public virtual void OnClipChanged ( TimelineClip clip );
    public virtual void OnCreate ( TimelineClip clip, TrackAsset track, TimelineClip clonedFrom );
    }
    }
     
  5. seant_unity

    seant_unity

    Unity Technologies

    Joined:
    Aug 25, 2015
    Posts:
    1,433
    The solution posted by @VOTRUBEC is spot on. ClipEditors were introduced in 2019.2, IIRC.
     
    Threeyes likes this.
unityunity