using NativeEngine;
namespace Sandbox;
public partial class AnimationGraph
{
///
/// Load an animation graph from given file.
///
public static AnimationGraph Load( string filename )
{
ThreadSafe.AssertIsMainThread();
return FromNative( NativeGlue.Resources.GetAnimationGraph( filename ), filename );
}
///
/// Try to make it so only one AnimationGraph class exists for each animation graph
///
internal static AnimationGraph FromNative( HAnimationGraph native, string name = null )
{
if ( native.IsNull || !native.IsStrongHandleValid() )
return null;
var instanceId = native.GetBindingPtr().ToInt64();
if ( NativeResourceCache.TryGetValue( instanceId, out var animgraph ) )
{
// If we're using a cached one we don't need this handle, we'll leak
native.DestroyStrongHandle();
return animgraph;
}
animgraph = new AnimationGraph( native, name ?? native.GetResourceName() );
NativeResourceCache.Add( instanceId, animgraph );
return animgraph;
}
}