SkeletonSelection.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. using System;
  2. using UnityEngine;
  3. namespace UnityEditor.U2D.Animation
  4. {
  5. [Serializable]
  6. internal class SkeletonSelection : IBoneSelection
  7. {
  8. [SerializeField]
  9. private BoneSelection m_BoneSelection = new BoneSelection();
  10. public int Count
  11. {
  12. get { return m_BoneSelection.Count; }
  13. }
  14. public BoneCache activeElement
  15. {
  16. get { return m_BoneSelection.activeElement; }
  17. set
  18. {
  19. ValidateBone(value);
  20. m_BoneSelection.activeElement = value;
  21. }
  22. }
  23. public BoneCache[] elements
  24. {
  25. get { return m_BoneSelection.elements; }
  26. set
  27. {
  28. foreach (var bone in value)
  29. ValidateBone(bone);
  30. m_BoneSelection.elements = value;
  31. }
  32. }
  33. public BoneCache root
  34. {
  35. get { return m_BoneSelection.root; }
  36. }
  37. public BoneCache[] roots
  38. {
  39. get { return m_BoneSelection.roots; }
  40. }
  41. public void BeginSelection()
  42. {
  43. m_BoneSelection.BeginSelection();
  44. }
  45. public void Clear()
  46. {
  47. m_BoneSelection.Clear();
  48. }
  49. public bool Contains(BoneCache element)
  50. {
  51. return m_BoneSelection.Contains(element);
  52. }
  53. public void EndSelection(bool select)
  54. {
  55. m_BoneSelection.EndSelection(select);
  56. }
  57. public void Select(BoneCache element, bool select)
  58. {
  59. ValidateBone(element);
  60. m_BoneSelection.Select(element, select);
  61. }
  62. private void ValidateBone(BoneCache bone)
  63. {
  64. if (bone == null)
  65. return;
  66. var skinningCache = bone.skinningCache;
  67. if (skinningCache.hasCharacter)
  68. {
  69. if (bone.skeleton != skinningCache.character.skeleton)
  70. throw new Exception("Selection Exception: bone does not belong to character skeleton");
  71. }
  72. else
  73. {
  74. var selectedSprite = skinningCache.selectedSprite;
  75. if (selectedSprite == null)
  76. throw new Exception("Selection Exception: skeleton not selected");
  77. else
  78. {
  79. var skeleton = selectedSprite.GetSkeleton();
  80. if (bone.skeleton != skeleton)
  81. throw new Exception("Selection Exception: bone's skeleton does not match selected skeleton");
  82. }
  83. }
  84. }
  85. }
  86. }