Unity-jump-proj

This commit is contained in:
2024-09-09 11:07:16 +03:00
parent 2c29906bbf
commit fd96a5627d
13707 changed files with 866380 additions and 0 deletions

View File

@ -0,0 +1,41 @@
using System;
namespace UnityEditor.Timeline.Actions
{
/// <summary>
/// Use this attribute on action classes (<see cref="TimelineAction"/>,
/// <see cref="ClipAction"/>,
/// <see cref="MarkerAction"/> and
/// <see cref="TrackAction"/>)
/// to have the default undo behaviour applied.
///
/// By default, applying this attribute will record all objects passed to the Execute method with the Undo system,
/// using the name of Action it is applied to.
///
/// <example>
/// Simple track Action example (with context menu and shortcut support).
/// <code source="../../DocCodeExamples/TimelineAttributesExamples.cs" region="declare-applyDefaultUndoAttr" title="ApplyDefaultUndoAttr"/>
/// </example>
/// </summary>
/// <seealso cref="TimelineAction"/>
/// <seealso cref="TrackAction"/>
/// <seealso cref="ClipAction"/>
/// <seealso cref="MarkerAction"/>
[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
public class ApplyDefaultUndoAttribute : Attribute
{
/// <summary>
/// The title of the action to appear in the undo history. If not specified, the name is taken from the DisplayName attribute,
/// or derived from the name of the class this attribute is applied to.
/// </summary>
public string UndoTitle;
/// <summary>Use this attribute on action classes to have the default undo behaviour applied.
/// </summary>
/// <param name="undoTitle">The title of the action to appear in the undo history.</param>
public ApplyDefaultUndoAttribute(string undoTitle = null)
{
UndoTitle = undoTitle;
}
}
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: b46a1ab31b3043b88cc57df2167383ac
timeCreated: 1590517869

View File

@ -0,0 +1,198 @@
using System;
using System.Collections.Generic;
using UnityEditor.Timeline.Actions;
using UnityEngine;
using UnityEngine.Playables;
using UnityEngine.Timeline;
using Object = UnityEngine.Object;
namespace UnityEditor.Timeline
{
/// <summary>
/// Provides methods that record the state of a timeline, and its components, prior to modification.
/// </summary>
/// <remarks>
/// The methods in this class are not required when adding or deleting tracks, clips, or markers.
/// Use methods in the UnityEngine.Timeline namespace, such as <see cref="UnityEngine.Timeline.TimelineAsset.CreateTrack"/>
/// or <see cref="UnityEngine.Timeline.TrackAsset.CreateDefaultClip"/>, to apply the appropriate
/// Undo calls when using the Editor.
/// </remarks>
public static class UndoExtensions
{
/// <summary>
/// Records changes to all items contained in an action context.
/// </summary>
/// <param name="context">The action context to record into the Undo system.</param>
/// <param name="undoTitle">The title of the action that appears in the undo history. For example, this title is shown in the Undo menu.</param>
public static void RegisterContext(ActionContext context, string undoTitle)
{
using (var undo = new UndoScope(undoTitle))
{
undo.Add(context.tracks);
undo.Add(context.clips, true);
undo.Add(context.markers);
}
}
/// <summary>
/// Records changes to timeline asset properties.
/// This method does not record changes to tracks or clips.
/// </summary>
/// <param name="asset">The timeline asset being modified.</param>
/// <param name="undoTitle">The title of the action that appears in the undo history. For example, this title is shown in the Undo menu.</param>
public static void RegisterTimeline(TimelineAsset asset, string undoTitle)
{
using (var undo = new UndoScope(undoTitle))
undo.AddObject(asset);
}
/// <summary>
/// Records all timeline changes including changes to tracks, clips, and markers.
/// </summary>
/// <param name="asset">The timeline asset being modified.</param>
/// <param name="undoTitle">The title of the action that appears in the undo history. For example, this title is shown in the Undo menu.</param>
public static void RegisterCompleteTimeline(TimelineAsset asset, string undoTitle)
{
if (asset == null)
return;
using (var undo = new UndoScope(undoTitle))
{
undo.AddObject(asset);
undo.Add(asset.flattenedTracks);
foreach (var t in asset.flattenedTracks)
{
undo.Add(t.GetClips(), true);
undo.Add(t.GetMarkers());
}
}
}
/// <summary>
/// Records changes to tracks and clips but not to markers nor PlayableAssets attached to clips.
/// </summary>
/// <param name="asset">The timeline track being modified.</param>
/// <param name="undoTitle">The title of the action that appears in the undo history. For example, this title is shown in the Undo menu.</param>
public static void RegisterTrack(TrackAsset asset, string undoTitle)
{
using (var undo = new UndoScope(undoTitle))
undo.AddObject(asset);
}
/// <summary>
/// Records changes to tracks. This includes changes
/// to clips on these tracks, but not changes to markers nor PlayableAssets attached to clips.
/// </summary>
/// <param name="tracks">The timeline track being modified.</param>
/// <param name="undoTitle">The title of the action that appears in the undo history. For example, this title is shown in the Undo menu.</param>
public static void RegisterTracks(IEnumerable<TrackAsset> tracks, string undoTitle)
{
using (var undo = new UndoScope(undoTitle))
undo.Add(tracks);
}
/// <summary>
/// Records changes to a clip.
/// </summary>
/// <param name="clip">The timeline clip being modified.</param>
/// <param name="undoTitle">The title of the action that appears in the undo history. For example, this title is shown in the Undo menu.</param>
/// <param name="includePlayableAsset">Set this value to true to record changes to the attached playable asset.</param>
public static void RegisterClip(TimelineClip clip, string undoTitle, bool includePlayableAsset = true)
{
using (var undo = new UndoScope(undoTitle))
{
undo.AddClip(clip, includePlayableAsset);
}
}
/// <summary>
/// Records changes to a PlayableAsset.
/// </summary>
/// <param name="asset">The PlayableAsset being modified.</param>
/// <param name="undoTitle">The title of the action that appears in the undo history. For example, this title is shown in the Undo menu.</param>
public static void RegisterPlayableAsset(PlayableAsset asset, string undoTitle)
{
using (var undo = new UndoScope(undoTitle))
undo.AddObject(asset);
}
/// <summary>
/// Records changes to clips.
/// </summary>
/// <param name="clips">The timeline clips being modified.</param>
/// <param name="name">The title of the action that appears in the undo history. For example, this title is shown in the Undo menu.</param>
/// <param name="includePlayableAssets">Set this value to true to also record changes to attached playable assets.</param>
public static void RegisterClips(IEnumerable<TimelineClip> clips, string name, bool includePlayableAssets = true)
{
using (var undo = new UndoScope(name))
undo.Add(clips, includePlayableAssets);
}
/// <summary>
/// Records changes to a timeline marker.
/// </summary>
/// <param name="marker">The timeline marker being modified.</param>
/// <param name="undoTitle">The title of the action that appears in the undo history. For example, this title is shown in the Undo menu.</param>
public static void RegisterMarker(IMarker marker, string undoTitle)
{
using (var undo = new UndoScope(undoTitle))
{
if (marker is Object o)
undo.AddObject(o);
else if (marker != null)
undo.AddObject(marker.parent);
}
}
/// <summary>
/// Records changes to timeline markers.
/// </summary>
/// <param name="markers">The timeline markers being modified.</param>
/// <param name="undoTitle">The title of the action that appears in the undo history. For example, this title is shown in the Undo menu.</param>
public static void RegisterMarkers(IEnumerable<IMarker> markers, string undoTitle)
{
using (var undo = new UndoScope(undoTitle))
undo.Add(markers);
}
/// <summary>
/// This class provides an object which prevents the creation of undos for all Timeline operations. Undos are restored when the object is disposed.
/// </summary>
/// <remarks>
/// Use this class to procedurally create or modify TimelineAssets when undos are not needed.
/// If multiple DisableTimelineUndoScope instances are created, undos are only restored after all instances are disposed.
///
/// It is recommended to use this object within a using scope.
/// </remarks>
/// <example>
/// <code>
/// var timelineAsset = new TimelineAsset();
/// using (new DisableTimelineUndoScope())
/// {
/// //Creates a track without generating an undo
/// timelineAsset.CreateTrack<ActivationTrack>();
/// }
/// </code>
/// </example>
internal sealed class DisableTimelineUndoScope : IDisposable
{
TimelineUndo.DisableUndoScope m_DisableScope;
/// <summary>
/// Creates a new DisableTimelineUndoScope object which prevents undos from being created by Timeline operations.
/// </summary>
public DisableTimelineUndoScope()
{
m_DisableScope = new TimelineUndo.DisableUndoScope();
}
/// <summary>
/// Disposes the DisableTimelineUndoScope object.
/// </summary>
public void Dispose()
{
m_DisableScope.Dispose();
}
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 3484c53050e20474bb37d3808245721a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,85 @@
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine.Timeline;
using Object = UnityEngine.Object;
namespace UnityEditor.Timeline
{
/// <summary>
/// Disposable scope object used to collect multiple items for Undo.
/// Automatically filters out duplicates
/// </summary>
struct UndoScope : IDisposable
{
private static readonly HashSet<UnityEngine.Object> s_ObjectsToUndo = new HashSet<Object>();
private string m_Name;
public UndoScope(string name)
{
m_Name = name;
}
public void Dispose()
{
ApplyUndo(m_Name);
}
public void AddObject(UnityEngine.Object asset)
{
if (asset != null)
s_ObjectsToUndo.Add(asset);
}
public void AddClip(TimelineClip clip, bool includeAsset)
{
if (clip != null && clip.GetParentTrack() != null)
s_ObjectsToUndo.Add(clip.GetParentTrack());
if (includeAsset && clip != null && clip.asset != null)
s_ObjectsToUndo.Add(clip.asset);
}
public void Add(IEnumerable<TrackAsset> tracks)
{
if (tracks == null)
return;
foreach (var track in tracks)
AddObject(track);
}
public void Add(IEnumerable<TimelineClip> clips, bool includeAssets)
{
if (clips == null)
return;
foreach (var clip in clips)
{
AddClip(clip, includeAssets);
}
}
public void Add(IEnumerable<IMarker> markers)
{
if (markers == null)
return;
foreach (var marker in markers)
{
if (marker is Object o)
AddObject(o);
else if (marker != null)
AddObject(marker.parent);
}
}
private static void ApplyUndo(string name)
{
if (s_ObjectsToUndo.Count == 1)
TimelineUndo.PushUndo(s_ObjectsToUndo.First(), name);
else if (s_ObjectsToUndo.Count > 1)
TimelineUndo.PushUndo(s_ObjectsToUndo.ToArray(), name);
s_ObjectsToUndo.Clear();
}
}
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: ef85e74dfd3749279eff9e7fbfbaf3f8
timeCreated: 1590436732