Skeleton.cs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. using System;
  2. using System.Runtime.InteropServices;
  3. namespace Urho {
  4. // Skeletons are typically references to internal storage in other objects
  5. // we surface this to C# as a pointer to the data, but to ensure that we do not
  6. // have dangling pointers, we only surface the constructor that retains a copy
  7. // to the container
  8. public partial class Skeleton
  9. {
  10. IntPtr handle;
  11. [Preserve]
  12. public Skeleton (IntPtr handle, object container)
  13. {
  14. this.handle = handle;
  15. }
  16. public BoneWrapper GetBoneSafe(uint index)
  17. {
  18. Runtime.ValidateObject(this);
  19. unsafe
  20. {
  21. Bone* result = Skeleton_GetBone(handle, index);
  22. if (result == null)
  23. return null;
  24. return new BoneWrapper(this, result);
  25. }
  26. }
  27. public BoneWrapper GetBoneSafe(StringHash nameHash)
  28. {
  29. Runtime.ValidateObject(this);
  30. unsafe
  31. {
  32. Bone* result = Skeleton_GetBone0(handle, nameHash.Code);
  33. if (result == null)
  34. return null;
  35. return new BoneWrapper(this, result);
  36. }
  37. }
  38. public BoneWrapper GetBoneSafe(string name) => GetBoneSafe(new StringHash(name));
  39. }
  40. public partial class AnimatedModel {
  41. [DllImport (Consts.NativeImport, CallingConvention=CallingConvention.Cdecl)]
  42. extern static IntPtr AnimatedModel_GetSkeleton (IntPtr handle);
  43. public Skeleton Skeleton {
  44. get
  45. {
  46. Runtime.ValidateObject(this);
  47. return new Skeleton (AnimatedModel_GetSkeleton (handle), this);
  48. }
  49. }
  50. }
  51. }