chore: initial commit

This commit is contained in:
2026-05-08 11:04:00 +08:00
commit f55d2a57c3
6278 changed files with 866081 additions and 0 deletions

View File

@@ -0,0 +1,54 @@
// Animancer // https://kybernetik.com.au/animancer // Copyright 2018-2026 Kybernetik //
#if UNITY_EDITOR
using System.Runtime.CompilerServices;
using UnityEngine;
namespace Animancer.Editor
{
/// <summary>[Editor-Only] Caches <see cref="AnimationClip.events"/> to reduce garbage allocations.</summary>
/// https://kybernetik.com.au/animancer/api/Animancer.Editor/AnimationEventCache
///
public static class AnimationEventCache
{
/************************************************************************************************************************/
private static readonly ConditionalWeakTable<AnimationClip, AnimationEvent[]>
ClipToEvents = new();
/************************************************************************************************************************/
/// <summary>
/// Returns the <see cref="AnimationClip.events"/> and caches the result to avoid allocating more memory with
/// each subsequent call.
/// </summary>
public static AnimationEvent[] GetCachedEvents(this AnimationClip clip)
{
if (!ClipToEvents.TryGetValue(clip, out var events))
{
events = clip.events;
ClipToEvents.Add(clip, events);
}
return events;
}
/************************************************************************************************************************/
/// <summary>Clears the cache.</summary>
public static void Clear()
=> ClipToEvents.Clear();
/************************************************************************************************************************/
/// <summary>Removes the `clip` from the cache so its events will be retrieved again next time.</summary>
public static void Remove(AnimationClip clip)
=> ClipToEvents.Remove(clip);
/************************************************************************************************************************/
}
}
#endif