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