EditableBoneWeight.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. using UnityEngine;
  2. using System;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. namespace UnityEditor.U2D.Animation
  6. {
  7. [Serializable]
  8. internal class BoneWeightChannel : IComparable<BoneWeightChannel>
  9. {
  10. [SerializeField]
  11. private bool m_Enabled;
  12. [SerializeField]
  13. private int m_BoneIndex;
  14. [SerializeField]
  15. private float m_Weight;
  16. public bool enabled
  17. {
  18. get { return m_Enabled; }
  19. set { m_Enabled = value; }
  20. }
  21. public int boneIndex
  22. {
  23. get { return m_BoneIndex; }
  24. set { m_BoneIndex = value; }
  25. }
  26. public float weight
  27. {
  28. get { return m_Weight; }
  29. set { m_Weight = value; }
  30. }
  31. public BoneWeightChannel() : this(0, 0f, false)
  32. {
  33. }
  34. public BoneWeightChannel(int i, float w, bool e)
  35. {
  36. enabled = e;
  37. boneIndex = i;
  38. weight = w;
  39. }
  40. public int CompareTo(BoneWeightChannel other)
  41. {
  42. int result = other.enabled.CompareTo(enabled);
  43. if (result == 0)
  44. result = other.weight.CompareTo(weight);
  45. return result;
  46. }
  47. }
  48. [Serializable]
  49. internal class EditableBoneWeight : IEnumerable<BoneWeightChannel>
  50. {
  51. [SerializeField]
  52. private List<BoneWeightChannel> m_Channels = new List<BoneWeightChannel>(5);
  53. public BoneWeightChannel this[int i]
  54. {
  55. get { return m_Channels[i]; }
  56. set { m_Channels[i] = value; }
  57. }
  58. public int Count
  59. {
  60. get { return m_Channels.Count; }
  61. }
  62. public void Clear()
  63. {
  64. m_Channels.Clear();
  65. }
  66. public void AddChannel(int boneIndex, float weight, bool enabled)
  67. {
  68. m_Channels.Add(new BoneWeightChannel(boneIndex, weight, enabled));
  69. }
  70. public void RemoveChannel(int channelIndex)
  71. {
  72. Debug.Assert(channelIndex < Count);
  73. m_Channels.RemoveAt(channelIndex);
  74. }
  75. public void Sort()
  76. {
  77. m_Channels.Sort();
  78. }
  79. public IEnumerator<BoneWeightChannel> GetEnumerator()
  80. {
  81. return ((IEnumerable<BoneWeightChannel>)m_Channels).GetEnumerator();
  82. }
  83. IEnumerator IEnumerable.GetEnumerator()
  84. {
  85. return ((IEnumerable<BoneWeightChannel>)m_Channels).GetEnumerator();
  86. }
  87. }
  88. }