Files
sbox-public/engine/Sandbox.Engine/Resources/Animation/AnimationGraph.Load.cs
s&box team 71f266059a Open source release
This commit imports the C# engine code and game files, excluding C++ source code.

[Source-Commit: ceb3d758046e50faa6258bc3b658a30c97743268]
2025-11-24 09:05:18 +00:00

39 lines
1.0 KiB
C#

using NativeEngine;
namespace Sandbox;
public partial class AnimationGraph
{
/// <summary>
/// Load an animation graph from given file.
/// </summary>
public static AnimationGraph Load( string filename )
{
ThreadSafe.AssertIsMainThread();
return FromNative( NativeGlue.Resources.GetAnimationGraph( filename ), filename );
}
/// <summary>
/// Try to make it so only one AnimationGraph class exists for each animation graph
/// </summary>
internal static AnimationGraph FromNative( HAnimationGraph native, string name = null )
{
if ( native.IsNull || !native.IsStrongHandleValid() )
return null;
var instanceId = native.GetBindingPtr().ToInt64();
if ( NativeResourceCache.TryGetValue<AnimationGraph>( 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;
}
}