Initial Commit
This commit is contained in:
parent
53eb92e9af
commit
270ab7d11f
15341 changed files with 700234 additions and 0 deletions
|
@ -0,0 +1,63 @@
|
|||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Timeline;
|
||||
|
||||
namespace UnityEditor.Timeline
|
||||
{
|
||||
class ClipsLayer : ItemsLayer<TimelineClipGUI>
|
||||
{
|
||||
static readonly GUIStyle k_ConnectorIcon = DirectorStyles.Instance.connector;
|
||||
|
||||
public ClipsLayer(Layer layerOrder, IRowGUI parent) : base(layerOrder)
|
||||
{
|
||||
var track = parent.asset;
|
||||
track.SortClips();
|
||||
TimelineClipGUI previousClipGUI = null;
|
||||
|
||||
foreach (var clip in track.clips)
|
||||
{
|
||||
var oldClipGUI = ItemToItemGui.GetGuiForClip(clip);
|
||||
var isInvalid = oldClipGUI != null && oldClipGUI.isInvalid; // HACK Make sure to carry invalidy state when refereshing the cache.
|
||||
|
||||
var currentClipGUI = new TimelineClipGUI(clip, parent, this) {isInvalid = isInvalid};
|
||||
if (previousClipGUI != null) previousClipGUI.nextClip = currentClipGUI;
|
||||
currentClipGUI.previousClip = previousClipGUI;
|
||||
AddItem(currentClipGUI);
|
||||
previousClipGUI = currentClipGUI;
|
||||
}
|
||||
|
||||
//adjust zOrder based on current clip selection
|
||||
foreach (var clipGUI in items)
|
||||
{
|
||||
if(clipGUI.IsSelected())
|
||||
clipGUI.MoveToTop();
|
||||
}
|
||||
}
|
||||
|
||||
public override void Draw(Rect rect, WindowState state)
|
||||
{
|
||||
base.Draw(rect, state); //draw clips
|
||||
DrawConnector(items);
|
||||
}
|
||||
|
||||
static void DrawConnector(List<TimelineClipGUI> clips)
|
||||
{
|
||||
if (Event.current.type != EventType.Repaint)
|
||||
return;
|
||||
|
||||
foreach (var clip in clips)
|
||||
{
|
||||
if (clip.previousClip != null && clip.visible && clip.treeViewRect.width > 14 &&
|
||||
(DiscreteTime)clip.start == (DiscreteTime)clip.previousClip.end)
|
||||
{
|
||||
// draw little connector widget
|
||||
var localRect = clip.treeViewRect;
|
||||
localRect.x -= Mathf.Floor(k_ConnectorIcon.fixedWidth / 2.0f);
|
||||
localRect.width = k_ConnectorIcon.fixedWidth;
|
||||
localRect.height = k_ConnectorIcon.fixedHeight;
|
||||
GUI.Label(localRect, GUIContent.none, k_ConnectorIcon);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: a809a4b50addbf44b9023b5e7f9fd4d2
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,133 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Timeline;
|
||||
|
||||
namespace UnityEditor.Timeline
|
||||
{
|
||||
enum Layer : byte
|
||||
{
|
||||
Clips,
|
||||
ClipHandles,
|
||||
Markers,
|
||||
MarkerHeaderTrack,
|
||||
MarkersOnHeader
|
||||
}
|
||||
|
||||
struct LayerZOrder : IComparable<LayerZOrder>
|
||||
{
|
||||
Layer m_Layer;
|
||||
int m_ZOrder;
|
||||
|
||||
public LayerZOrder(Layer layer, int zOrder)
|
||||
{
|
||||
m_Layer = layer;
|
||||
m_ZOrder = zOrder;
|
||||
}
|
||||
|
||||
public int CompareTo(LayerZOrder other)
|
||||
{
|
||||
if (m_Layer == other.m_Layer)
|
||||
return m_ZOrder.CompareTo(other.m_ZOrder);
|
||||
return m_Layer.CompareTo(other.m_Layer);
|
||||
}
|
||||
|
||||
public static LayerZOrder operator++(LayerZOrder x)
|
||||
{
|
||||
return new LayerZOrder(x.m_Layer, x.m_ZOrder + 1);
|
||||
}
|
||||
|
||||
public LayerZOrder ChangeLayer(Layer layer)
|
||||
{
|
||||
return new LayerZOrder(layer, m_ZOrder);
|
||||
}
|
||||
}
|
||||
|
||||
interface ILayerable
|
||||
{
|
||||
LayerZOrder zOrder { get; }
|
||||
}
|
||||
|
||||
interface IZOrderProvider
|
||||
{
|
||||
LayerZOrder Next();
|
||||
}
|
||||
|
||||
interface ILayer : IZOrderProvider
|
||||
{
|
||||
void Draw(Rect rect, WindowState state);
|
||||
}
|
||||
|
||||
abstract class ItemsLayer<T> : ILayer where T : TimelineItemGUI
|
||||
{
|
||||
// provide a buffer for time-based culling to allow for UI that extends slightly beyond the time (e.g. markers)
|
||||
// prevents popping of marker visibility.
|
||||
const int kVisibilityBufferInPixels = 10;
|
||||
|
||||
int m_PreviousLayerStateHash = -1;
|
||||
LayerZOrder m_LastZOrder;
|
||||
|
||||
public LayerZOrder Next()
|
||||
{
|
||||
m_NeedSort = true;
|
||||
return m_LastZOrder++;
|
||||
}
|
||||
|
||||
readonly List<T> m_Items = new List<T>();
|
||||
bool m_NeedSort = true;
|
||||
|
||||
public virtual void Draw(Rect rect, WindowState state)
|
||||
{
|
||||
if (m_Items.Count <= 0) return;
|
||||
|
||||
Sort();
|
||||
|
||||
// buffer to prevent flickering of markers at boundaries
|
||||
var onePixelTime = state.PixelDeltaToDeltaTime(kVisibilityBufferInPixels);
|
||||
var visibleTime = state.timeAreaShownRange + new Vector2(-onePixelTime, onePixelTime);
|
||||
var layerViewStateHasChanged = GetLayerViewStateChanged(rect, state);
|
||||
|
||||
foreach (var item in m_Items)
|
||||
{
|
||||
item.visible = item.end > visibleTime.x && item.start < visibleTime.y;
|
||||
if (!item.visible)
|
||||
continue;
|
||||
|
||||
item.Draw(rect, layerViewStateHasChanged, state);
|
||||
}
|
||||
}
|
||||
|
||||
public List<T> items => m_Items;
|
||||
|
||||
protected void AddItem(T item)
|
||||
{
|
||||
m_Items.Add(item);
|
||||
m_NeedSort = true;
|
||||
}
|
||||
|
||||
protected ItemsLayer(Layer layerOrder)
|
||||
{
|
||||
m_LastZOrder = new LayerZOrder(layerOrder, 0);
|
||||
}
|
||||
|
||||
void Sort()
|
||||
{
|
||||
if (!m_NeedSort)
|
||||
return;
|
||||
|
||||
m_Items.Sort((a, b) => a.zOrder.CompareTo(b.zOrder));
|
||||
m_NeedSort = false;
|
||||
}
|
||||
|
||||
bool GetLayerViewStateChanged(Rect rect, WindowState state)
|
||||
{
|
||||
var layerStateHash = rect.GetHashCode().CombineHash(state.viewStateHash);
|
||||
var layerViewStateHasChanged = layerStateHash != m_PreviousLayerStateHash;
|
||||
|
||||
if (Event.current.type == EventType.Layout && layerViewStateHasChanged)
|
||||
m_PreviousLayerStateHash = layerStateHash;
|
||||
|
||||
return layerViewStateHasChanged;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: ef97f39912c138b4cabdccedfb24093b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,80 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine.Timeline;
|
||||
|
||||
namespace UnityEditor.Timeline
|
||||
{
|
||||
class MarkersLayer : ItemsLayer<TimelineItemGUI>
|
||||
{
|
||||
public MarkersLayer(Layer layerOrder, IRowGUI parent) : base(layerOrder)
|
||||
{
|
||||
CreateLists(parent);
|
||||
}
|
||||
|
||||
void CreateLists(IRowGUI parent)
|
||||
{
|
||||
var markerCount = parent.asset.GetMarkerCount();
|
||||
if (markerCount == 0) return;
|
||||
|
||||
var accumulator = new List<IMarker>();
|
||||
var sortedMarkers = new List<IMarker>(parent.asset.GetMarkers());
|
||||
var vm = TimelineWindowViewPrefs.GetTrackViewModelData(parent.asset);
|
||||
|
||||
sortedMarkers.Sort((lhs, rhs) =>
|
||||
{
|
||||
// Sort by time first
|
||||
var timeComparison = lhs.time.CompareTo(rhs.time);
|
||||
if (timeComparison != 0)
|
||||
return timeComparison;
|
||||
|
||||
// If there's a collision, sort by edit timestamp
|
||||
var lhsObject = lhs as object;
|
||||
var rhsObject = rhs as object;
|
||||
|
||||
if (lhsObject.Equals(null) || rhsObject.Equals(null))
|
||||
return 0;
|
||||
|
||||
var lhsHash = lhsObject.GetHashCode();
|
||||
var rhsHash = rhsObject.GetHashCode();
|
||||
|
||||
if (vm.markerTimeStamps.ContainsKey(lhsHash) && vm.markerTimeStamps.ContainsKey(rhsHash))
|
||||
return vm.markerTimeStamps[lhsHash].CompareTo(vm.markerTimeStamps[rhsHash]);
|
||||
|
||||
return 0;
|
||||
});
|
||||
|
||||
foreach (var current in sortedMarkers)
|
||||
{
|
||||
// TODO: Take zoom factor into account?
|
||||
if (accumulator.Count > 0 && Math.Abs(current.time - accumulator[accumulator.Count - 1].time) > TimeUtility.kTimeEpsilon)
|
||||
ProcessAccumulator(accumulator, parent);
|
||||
|
||||
accumulator.Add(current);
|
||||
}
|
||||
|
||||
ProcessAccumulator(accumulator, parent);
|
||||
}
|
||||
|
||||
void ProcessAccumulator(List<IMarker> accumulator, IRowGUI parent)
|
||||
{
|
||||
if (accumulator.Count == 0) return;
|
||||
|
||||
if (accumulator.Count == 1)
|
||||
{
|
||||
AddItem(new TimelineMarkerGUI(accumulator[0], parent, this));
|
||||
}
|
||||
else
|
||||
{
|
||||
// Ensure that the cluster is always considered *below* the markers it contains.
|
||||
var clusterZOrder = Next();
|
||||
AddItem(
|
||||
new TimelineMarkerClusterGUI(
|
||||
accumulator.Select(m => new TimelineMarkerGUI(m, parent, this)).ToList(),
|
||||
parent, this, clusterZOrder));
|
||||
}
|
||||
|
||||
accumulator.Clear();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: bea62e1faac8f9a48a4cb919ea05cb6a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Loading…
Add table
Add a link
Reference in a new issue