NodeWeight.cs 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. // Animancer // https://kybernetik.com.au/animancer // Copyright 2018-2024 Kybernetik //
  2. using System.Text;
  3. namespace Animancer
  4. {
  5. /// <summary>An <see cref="AnimancerNode"/> and its <see cref="StartingWeight"/>.</summary>
  6. /// https://kybernetik.com.au/animancer/api/Animancer/NodeWeight
  7. public readonly struct NodeWeight
  8. {
  9. /************************************************************************************************************************/
  10. /// <summary>The <see cref="AnimancerNode"/>.</summary>
  11. public readonly AnimancerNode Node;
  12. /// <summary>The <see cref="AnimancerNode.Weight"/> from when this struct was captured.</summary>
  13. public readonly float StartingWeight;
  14. /************************************************************************************************************************/
  15. /// <summary>Creates a new <see cref="NodeWeight"/>.</summary>
  16. public NodeWeight(AnimancerNode node)
  17. {
  18. Node = node;
  19. StartingWeight = node.Weight;
  20. }
  21. /************************************************************************************************************************/
  22. /// <summary>Creates a new <see cref="NodeWeight"/>.</summary>
  23. public NodeWeight(AnimancerNode node, float startingWeight)
  24. {
  25. Node = node;
  26. StartingWeight = startingWeight;
  27. }
  28. /************************************************************************************************************************/
  29. /// <summary>Creates a copy of `copyFrom`.</summary>
  30. public NodeWeight(NodeWeight copyFrom, CloneContext context)
  31. {
  32. Node = context.GetOrCreateCloneOrOriginal(copyFrom.Node);
  33. StartingWeight = copyFrom.StartingWeight;
  34. }
  35. /************************************************************************************************************************/
  36. /// <summary>Appends a detailed descrption of this object.</summary>
  37. public void AppendDescription(StringBuilder text, float targetWeight)
  38. {
  39. if (Node == null)
  40. {
  41. text.Append("Null: ")
  42. .Append(StartingWeight)
  43. .Append(" -> ")
  44. .Append(targetWeight);
  45. }
  46. else
  47. {
  48. text.Append(Node.GetPath())
  49. .Append(": ")
  50. .Append(StartingWeight)
  51. .Append(" -> ")
  52. .Append(Node.Weight)
  53. .Append(" -> ")
  54. .Append(targetWeight);
  55. }
  56. }
  57. /************************************************************************************************************************/
  58. }
  59. }