File size: 12,700 Bytes
18a519f | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 | using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Playables;
using UnityEngine.Timeline;
namespace UnityEditor.Timeline
{
/// <summary>
/// Description of the on-screen area where a clip is drawn
/// </summary>
public struct ClipBackgroundRegion
{
/// <summary>
/// The rectangle where the background of the clip is drawn.
/// </summary>
/// <remarks>
/// The rectangle is clipped to the screen. The rectangle does not include clip borders.
/// </remarks>
public Rect position { get; private set; }
/// <summary>
/// The start time of the region, relative to the clip.
/// </summary>
public double startTime { get; private set; }
/// <summary>
/// The end time of the region, relative to the clip.
/// </summary>
public double endTime { get; private set; }
/// <summary>
/// Constructor
/// </summary>
/// <param name="_position"></param>
/// <param name="_startTime"></param>
/// <param name="_endTime"></param>
public ClipBackgroundRegion(Rect _position, double _startTime, double _endTime)
{
position = _position;
startTime = _startTime;
endTime = _endTime;
}
/// <summary>
/// Indicates whether this instance and a specified object are equal.
/// </summary>
/// <param name="obj">The object to compare with the current instance.</param>
/// <returns>Returns <c>true</c> if <paramref name="obj"/> and this instance are the same type and represent the same value.</returns>
public override bool Equals(object obj)
{
if (!(obj is ClipBackgroundRegion))
return false;
return Equals((ClipBackgroundRegion)obj);
}
/// <summary>
/// Compares this object with another <c>ClipBackgroundRegion</c>.
/// </summary>
/// <param name="other">The object to compare with.</param>
/// <returns>Returns true if <c>this</c> and <paramref name="other"/> are equal.</returns>
public bool Equals(ClipBackgroundRegion other)
{
return position.Equals(other.position) &&
startTime == other.startTime &&
endTime == other.endTime;
}
/// <summary>
/// Returns the hash code for this instance.
/// </summary>
/// <returns>A 32-bit signed integer that is the hash code for this instance.</returns>
public override int GetHashCode()
{
return HashUtility.CombineHash(
position.GetHashCode(),
startTime.GetHashCode(),
endTime.GetHashCode()
);
}
/// <summary>
/// Compares two <c>ClipBackgroundRegion</c> objects.
/// </summary>
/// <param name="region1">The first object.</param>
/// <param name="region2">The second object.</param>
/// <returns>Returns true if they are equal.</returns>
public static bool operator ==(ClipBackgroundRegion region1, ClipBackgroundRegion region2)
{
return region1.Equals(region2);
}
/// <summary>
/// Compares two <c>ClipBackgroundRegion</c> objects.
/// </summary>
/// <param name="region1">The first object.</param>
/// <param name="region2">The second object.</param>
/// <returns>Returns true if they are not equal.</returns>
public static bool operator !=(ClipBackgroundRegion region1, ClipBackgroundRegion region2)
{
return !region1.Equals(region2);
}
}
/// <summary>
/// The user-defined options for drawing a clip.
/// </summary>
public struct ClipDrawOptions
{
private IEnumerable<Texture2D> m_Icons;
private bool m_HideClipName;
/// <summary>
/// Text that indicates if the clip should display an error.
/// </summary>
/// <remarks>
/// If the error text is not empty or null, then the clip displays a warning. The error text is used as the tooltip.
/// </remarks>
public string errorText { get; set; }
/// <summary>
/// Controls the display of the clip name.
/// </summary>
/// <remarks>
/// Set to true to display the clip name. Set to false to avoid drawing the clip name.
/// </remarks>
public bool displayClipName
{
get { return !m_HideClipName; }
set { m_HideClipName = !value; }
}
/// <summary>
/// Controls the display of the clip scale indicator.
/// </summary>
/// <remarks>
/// Set to true to hide the clip scale indicator.
/// This is useful if the scale indicator is interfering with your custom clip rendering, or if the scale indicator
/// is not useful for your clip.
/// </remarks>
public bool hideScaleIndicator { get; set; }
/// <summary>
/// The tooltip to show for the clip.
/// </summary>
public string tooltip { get; set; }
/// <summary>
/// The color drawn under the clip. By default, the color is the same as the track color.
/// </summary>
public Color highlightColor { get; set; }
/// <summary>
/// Icons to display on the clip.
/// </summary>
public IEnumerable<Texture2D> icons
{
get { return m_Icons ?? System.Linq.Enumerable.Empty<Texture2D>(); }
set { m_Icons = value; }
}
/// <summary>
/// Indicates whether this instance and a specified object are equal.
/// </summary>
/// <param name="obj">The object to compare with the current instance.</param>
/// <returns>Returns <c>true</c> if <paramref name="obj"/> and this instance are the same type and represent the same value.</returns>
public override bool Equals(object obj)
{
if (!(obj is ClipDrawOptions))
return false;
return Equals((ClipDrawOptions)obj);
}
/// <summary>
/// Compares this object with another <c>ClipDrawOptions</c>.
/// </summary>
/// <param name="other">The object to compare with.</param>
/// <returns>Returns true if <c>this</c> and <paramref name="other"/> are equal.</returns>
public bool Equals(ClipDrawOptions other)
{
return errorText == other.errorText &&
tooltip == other.tooltip &&
highlightColor == other.highlightColor &&
System.Linq.Enumerable.SequenceEqual(icons, other.icons);
}
/// <summary>
/// Returns the hash code for this instance.
/// </summary>
/// <returns>A 32-bit signed integer that is the hash code for this instance.</returns>
public override int GetHashCode()
{
return HashUtility.CombineHash(
errorText != null ? errorText.GetHashCode() : 0,
tooltip != null ? tooltip.GetHashCode() : 0,
highlightColor.GetHashCode(),
icons != null ? icons.GetHashCode() : 0
);
}
/// <summary>
/// Compares two <c>ClipDrawOptions</c> objects.
/// </summary>
/// <param name="options1">The first object.</param>
/// <param name="options2">The second object.</param>
/// <returns>Returns true if they are equal.</returns>
public static bool operator ==(ClipDrawOptions options1, ClipDrawOptions options2)
{
return options1.Equals(options2);
}
/// <summary>
/// Compares two <c>ClipDrawOptions</c> objects.
/// </summary>
/// <param name="options1">The first object.</param>
/// <param name="options2">The second object.</param>
/// <returns>Returns true if they are not equal.</returns>
public static bool operator !=(ClipDrawOptions options1, ClipDrawOptions options2)
{
return !options1.Equals(options2);
}
}
/// <summary>
/// Use this class to customize clip types in the TimelineEditor.
/// </summary>
public class ClipEditor
{
static readonly string k_NoPlayableAssetError = L10n.Tr("This clip does not contain a valid playable asset");
static readonly string k_ScriptLoadError = L10n.Tr("The associated script can not be loaded");
internal readonly bool supportsSubTimelines;
/// <summary>
/// Default constructor
/// </summary>
public ClipEditor()
{
supportsSubTimelines = TypeUtility.HasOverrideMethod(GetType(), nameof(GetSubTimelines));
}
/// <summary>
/// Implement this method to override the default options for drawing a clip.
/// </summary>
/// <param name="clip">The clip being drawn.</param>
/// <returns>The options for drawing a clip.</returns>
public virtual ClipDrawOptions GetClipOptions(TimelineClip clip)
{
return new ClipDrawOptions()
{
errorText = GetErrorText(clip),
tooltip = string.Empty,
highlightColor = GetDefaultHighlightColor(clip),
icons = System.Linq.Enumerable.Empty<Texture2D>()
};
}
/// <summary>
/// Override this method to draw a background for a clip .
/// </summary>
/// <param name="clip">The clip being drawn.</param>
/// <param name="region">The on-screen area where the clip is drawn.</param>
public virtual void DrawBackground(TimelineClip clip, ClipBackgroundRegion region)
{
}
/// <summary>
/// Called when a clip is created.
/// </summary>
/// <param name="clip">The newly created clip.</param>
/// <param name="track">The track that the clip is assigned to.</param>
/// <param name="clonedFrom">The source that the clip was copied from. This can be set to null if the clip is not a copy.</param>
/// <remarks>
/// The callback occurs before the clip is assigned to the track.
/// </remarks>
public virtual void OnCreate(TimelineClip clip, TrackAsset track, TimelineClip clonedFrom)
{
}
/// <summary>
/// Gets the error text for the specified clip.
/// </summary>
/// <param name="clip">The clip being drawn.</param>
/// <returns>Returns the error text to be displayed as the tool tip for the clip. If there is no error to be displayed, this method returns string.Empty.</returns>
public string GetErrorText(TimelineClip clip)
{
if (clip == null || clip.asset == null)
return k_NoPlayableAssetError;
var playableAsset = clip.asset as ScriptableObject;
if (playableAsset == null || MonoScript.FromScriptableObject(playableAsset) == null)
return k_ScriptLoadError;
return string.Empty;
}
/// <summary>
/// The color drawn under the clip. By default, the color is the same as the track color.
/// </summary>
/// <param name="clip">The clip being drawn.</param>
/// <returns>Returns the highlight color of the clip being drawn.</returns>
public Color GetDefaultHighlightColor(TimelineClip clip)
{
if (clip == null)
return Color.white;
return TrackResourceCache.GetTrackColor(clip.GetParentTrack());
}
/// <summary>
/// Called when a clip is changed by the Editor.
/// </summary>
/// <param name="clip">The clip that changed.</param>
public virtual void OnClipChanged(TimelineClip clip)
{
}
/// <summary>
/// Gets the sub-timelines for a specific clip. Implement this method if your clip supports playing nested timelines.
/// </summary>
/// <param name="clip">The clip with the ControlPlayableAsset.</param>
/// <param name="director">The playable director driving the Timeline Clip. This may not be the same as TimelineEditor.inspectedDirector.</param>
/// <param name="subTimelines">Specify the sub-timelines to control.</param>
public virtual void GetSubTimelines(TimelineClip clip, PlayableDirector director, List<PlayableDirector> subTimelines)
{
}
}
}
|