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 //
using UnityEngine.Animations;
namespace Animancer
{
/// <summary>[Pro-Only]
/// A base class that allows Animation Jobs to be easily inserted into an Animancer graph.
/// </summary>
///
/// <remarks>
/// <strong>Documentation:</strong>
/// <see href="https://kybernetik.com.au/animancer/docs/manual/ik#animated-properties">
/// Animated Properties</see>
/// </remarks>
///
/// https://kybernetik.com.au/animancer/api/Animancer/AnimancerJob_1
///
public abstract class AnimancerJob<T> where T : struct, IAnimationJob
{
/************************************************************************************************************************/
/// <summary>The <see cref="IAnimationJob"/>.</summary>
protected T _Job;
/// <summary>The <see cref="AnimationScriptPlayable"/> running the job.</summary>
protected AnimationScriptPlayable _Playable;
/************************************************************************************************************************/
/// <summary>Creates the <see cref="_Playable"/> and inserts it between the root and the graph output.</summary>
protected void CreatePlayable(AnimancerGraph animancer)
{
_Playable = animancer.InsertOutputJob(_Job);
}
/************************************************************************************************************************/
/// <summary>
/// Destroys the <see cref="_Playable"/> and restores the graph connection it was intercepting.
/// </summary>
/// <remarks>
/// This method is NOT called automatically, so if you need to guarantee that things will get cleaned up you
/// should use <see cref="AnimancerGraph.Disposables"/>.
/// </remarks>
public virtual void Destroy()
{
AnimancerUtilities.RemovePlayable(_Playable);
}
/************************************************************************************************************************/
}
}

View File

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

View File

@@ -0,0 +1,72 @@
// Animancer // https://kybernetik.com.au/animancer // Copyright 2018-2026 Kybernetik //
using UnityEngine.Animations;
using Unity.Collections;
namespace Animancer
{
/// <summary>[Pro-Only]
/// A wrapper which allows access to the value of <see cref="bool"/> properties that are controlled by animations.
/// </summary>
///
/// <remarks>
/// <strong>Documentation:</strong>
/// <see href="https://kybernetik.com.au/animancer/docs/manual/ik#animated-properties">
/// Animated Properties</see>
/// </remarks>
///
/// https://kybernetik.com.au/animancer/api/Animancer/AnimatedBool
///
public class AnimatedBool : AnimatedProperty<AnimatedBool.Job, bool>
{
/************************************************************************************************************************/
/// <summary>
/// Allocates room for a specified number of properties to be filled by
/// <see cref="InitializeProperty(int, Transform, Type, string)"/>.
/// </summary>
public AnimatedBool(IAnimancerComponent animancer, int propertyCount,
NativeArrayOptions options = NativeArrayOptions.ClearMemory)
: base(animancer, propertyCount, options)
{ }
/// <summary>Initializes a single property.</summary>
public AnimatedBool(IAnimancerComponent animancer, string propertyName)
: base(animancer, propertyName)
{ }
/// <summary>Initializes a group of properties.</summary>
public AnimatedBool(IAnimancerComponent animancer, params string[] propertyNames)
: base(animancer, propertyNames)
{ }
/************************************************************************************************************************/
protected override void CreateJob()
{
_Job = new() { properties = _Properties, values = _Values };
}
/************************************************************************************************************************/
/// <summary>An <see cref="IAnimationJob"/> which reads an array of <see cref="bool"/> values.</summary>
/// https://kybernetik.com.au/animancer/api/Animancer/Job
///
public struct Job : IAnimationJob
{
public NativeArray<PropertyStreamHandle> properties;
public NativeArray<bool> values;
public void ProcessRootMotion(AnimationStream stream) { }
public void ProcessAnimation(AnimationStream stream)
{
for (int i = properties.Length - 1; i >= 0; i--)
values[i] = properties[i].GetBool(stream);
}
}
/************************************************************************************************************************/
}
}

View File

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

View File

@@ -0,0 +1,72 @@
// Animancer // https://kybernetik.com.au/animancer // Copyright 2018-2026 Kybernetik //
using UnityEngine.Animations;
using Unity.Collections;
namespace Animancer
{
/// <summary>[Pro-Only]
/// A wrapper which allows access to the value of <see cref="float"/> properties that are controlled by animations.
/// </summary>
///
/// <remarks>
/// <strong>Documentation:</strong>
/// <see href="https://kybernetik.com.au/animancer/docs/manual/ik#animated-properties">
/// Animated Properties</see>
/// </remarks>
///
/// https://kybernetik.com.au/animancer/api/Animancer/AnimatedFloat
///
public class AnimatedFloat : AnimatedProperty<AnimatedFloat.Job, float>
{
/************************************************************************************************************************/
/// <summary>
/// Allocates room for a specified number of properties to be filled by
/// <see cref="InitializeProperty(int, Transform, Type, string)"/>.
/// </summary>
public AnimatedFloat(IAnimancerComponent animancer, int propertyCount,
NativeArrayOptions options = NativeArrayOptions.ClearMemory)
: base(animancer, propertyCount, options)
{ }
/// <summary>Initializes a single property.</summary>
public AnimatedFloat(IAnimancerComponent animancer, string propertyName)
: base(animancer, propertyName)
{ }
/// <summary>Initializes a group of properties.</summary>
public AnimatedFloat(IAnimancerComponent animancer, params string[] propertyNames)
: base(animancer, propertyNames)
{ }
/************************************************************************************************************************/
protected override void CreateJob()
{
_Job = new() { properties = _Properties, values = _Values };
}
/************************************************************************************************************************/
/// <summary>An <see cref="IAnimationJob"/> which reads an array of <see cref="float"/> values.</summary>
/// https://kybernetik.com.au/animancer/api/Animancer/Job
///
public struct Job : IAnimationJob
{
public NativeArray<PropertyStreamHandle> properties;
public NativeArray<float> values;
public void ProcessRootMotion(AnimationStream stream) { }
public void ProcessAnimation(AnimationStream stream)
{
for (int i = properties.Length - 1; i >= 0; i--)
values[i] = properties[i].GetFloat(stream);
}
}
/************************************************************************************************************************/
}
}

View File

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

View File

@@ -0,0 +1,72 @@
// Animancer // https://kybernetik.com.au/animancer // Copyright 2018-2026 Kybernetik //
using UnityEngine.Animations;
using Unity.Collections;
namespace Animancer
{
/// <summary>[Pro-Only]
/// A wrapper which allows access to the value of <see cref="int"/> properties that are controlled by animations.
/// </summary>
///
/// <remarks>
/// <strong>Documentation:</strong>
/// <see href="https://kybernetik.com.au/animancer/docs/manual/ik#animated-properties">
/// Animated Properties</see>
/// </remarks>
///
/// https://kybernetik.com.au/animancer/api/Animancer/AnimatedInt
///
public class AnimatedInt : AnimatedProperty<AnimatedInt.Job, int>
{
/************************************************************************************************************************/
/// <summary>
/// Allocates room for a specified number of properties to be filled by
/// <see cref="InitializeProperty(int, Transform, Type, string)"/>.
/// </summary>
public AnimatedInt(IAnimancerComponent animancer, int propertyCount,
NativeArrayOptions options = NativeArrayOptions.ClearMemory)
: base(animancer, propertyCount, options)
{ }
/// <summary>Initializes a single property.</summary>
public AnimatedInt(IAnimancerComponent animancer, string propertyName)
: base(animancer, propertyName)
{ }
/// <summary>Initializes a group of properties.</summary>
public AnimatedInt(IAnimancerComponent animancer, params string[] propertyNames)
: base(animancer, propertyNames)
{ }
/************************************************************************************************************************/
protected override void CreateJob()
{
_Job = new() { properties = _Properties, values = _Values };
}
/************************************************************************************************************************/
/// <summary>An <see cref="IAnimationJob"/> which reads an array of <see cref="int"/> values.</summary>
/// https://kybernetik.com.au/animancer/api/Animancer/Job
///
public struct Job : IAnimationJob
{
public NativeArray<PropertyStreamHandle> properties;
public NativeArray<int> values;
public readonly void ProcessRootMotion(AnimationStream stream) { }
public void ProcessAnimation(AnimationStream stream)
{
for (int i = properties.Length - 1; i >= 0; i--)
values[i] = properties[i].GetInt(stream);
}
}
/************************************************************************************************************************/
}
}

View File

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

View File

@@ -0,0 +1,162 @@
// Animancer // https://kybernetik.com.au/animancer // Copyright 2018-2026 Kybernetik //
using System;
using UnityEngine;
using UnityEngine.Animations;
using Unity.Collections;
namespace Animancer
{
/// <summary>[Pro-Only]
/// A base wrapper which allows access to the value of properties that are controlled by animations.
/// </summary>
///
/// <remarks>
/// <strong>Documentation:</strong>
/// <see href="https://kybernetik.com.au/animancer/docs/manual/ik#animated-properties">
/// Animated Properties</see>
/// </remarks>
///
/// https://kybernetik.com.au/animancer/api/Animancer/AnimatedProperty_2
///
public abstract class AnimatedProperty<TJob, TValue> : AnimancerJob<TJob>, IDisposable
where TJob : struct, IAnimationJob
where TValue : struct
{
/************************************************************************************************************************/
/// <summary>The properties wrapped by this object.</summary>
protected NativeArray<PropertyStreamHandle> _Properties;
/// <summary>The value of each of the <see cref="_Properties"/> from the most recent update.</summary>
protected NativeArray<TValue> _Values;
/************************************************************************************************************************/
#region Initialization
/************************************************************************************************************************/
/// <summary>
/// Allocates room for a specified number of properties to be filled by
/// <see cref="InitializeProperty(int, Transform, Type, string)"/>.
/// </summary>
public AnimatedProperty(
IAnimancerComponent animancer,
int propertyCount,
NativeArrayOptions options = NativeArrayOptions.ClearMemory)
{
_Properties = new(propertyCount, Allocator.Persistent, options);
_Values = new(propertyCount, Allocator.Persistent);
CreateJob();
var playable = animancer.Graph;
CreatePlayable(playable);
playable.Disposables.Add(this);
}
/// <summary>Initializes a single property.</summary>
public AnimatedProperty(IAnimancerComponent animancer, string propertyName)
: this(animancer, 1, NativeArrayOptions.UninitializedMemory)
{
var animator = animancer.Animator;
_Properties[0] = animator.BindStreamProperty(animator.transform, typeof(Animator), propertyName);
}
/// <summary>Initializes a group of properties.</summary>
public AnimatedProperty(IAnimancerComponent animancer, params string[] propertyNames)
: this(animancer, propertyNames.Length, NativeArrayOptions.UninitializedMemory)
{
var count = propertyNames.Length;
var animator = animancer.Animator;
var transform = animator.transform;
for (int i = 0; i < count; i++)
InitializeProperty(animator, i, transform, typeof(Animator), propertyNames[i]);
}
/************************************************************************************************************************/
/// <summary>Initializes a property on the target <see cref="Animator"/>.</summary>
public void InitializeProperty(Animator animator, int index, string name)
=> InitializeProperty(animator, index, animator.transform, typeof(Animator), name);
/// <summary>Initializes the specified `index` to read a property with the specified `name`.</summary>
public void InitializeProperty(Animator animator, int index, Transform transform, Type type, string name)
=> _Properties[index] = animator.BindStreamProperty(transform, type, name);
/************************************************************************************************************************/
/// <summary>Creates and assigns the <see cref="AnimancerJob._Job"/>.</summary>
protected abstract void CreateJob();
/************************************************************************************************************************/
#endregion
/************************************************************************************************************************/
#region Accessors
/************************************************************************************************************************/
/// <summary>Returns the value of the first property.</summary>
public TValue Value
=> this[0];
/// <summary>Returns the value of the first property.</summary>
public static implicit operator TValue(AnimatedProperty<TJob, TValue> properties)
=> properties[0];
/************************************************************************************************************************/
/// <summary>Returns the value of the property at the specified `index`.</summary>
/// <remarks>This method is identical to <see cref="this[int]"/>.</remarks>
public TValue GetValue(int index)
=> _Values[index];
/// <summary>Returns the value of the property at the specified `index`.</summary>
/// <remarks>This indexer is identical to <see cref="GetValue(int)"/>.</remarks>
public TValue this[int index]
=> _Values[index];
/************************************************************************************************************************/
/// <summary>Resizes the `values` if necessary and copies the value of each property into it.</summary>
public void GetValues(ref TValue[] values)
{
AnimancerUtilities.SetLength(ref values, _Values.Length);
_Values.CopyTo(values);
}
/// <summary>Returns a new array containing the values of all properties.</summary>
/// <remarks>Use <see cref="GetValues(ref TValue[])"/> to avoid allocating a new array every call.</remarks>
public TValue[] GetValues()
{
var values = new TValue[_Values.Length];
_Values.CopyTo(values);
return values;
}
/************************************************************************************************************************/
#endregion
/************************************************************************************************************************/
void IDisposable.Dispose() => Dispose();
/// <summary>Cleans up the <see cref="NativeArray{T}"/>s.</summary>
/// <remarks>Called by <see cref="AnimancerGraph.OnPlayableDestroy"/>.</remarks>
protected virtual void Dispose()
{
if (_Properties.IsCreated)
{
_Properties.Dispose();
_Values.Dispose();
}
}
/// <summary>Destroys the <see cref="_Playable"/> and restores the graph connection it was intercepting.</summary>
public override void Destroy()
{
Dispose();
base.Destroy();
}
/************************************************************************************************************************/
}
}

View File

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