123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- using System;
- using UnityEngine;
- namespace UnityEditor.U2D.Animation
- {
- [Serializable]
- internal class SkeletonSelection : IBoneSelection
- {
- [SerializeField]
- private BoneSelection m_BoneSelection = new BoneSelection();
- public int Count
- {
- get { return m_BoneSelection.Count; }
- }
- public BoneCache activeElement
- {
- get { return m_BoneSelection.activeElement; }
- set
- {
- ValidateBone(value);
- m_BoneSelection.activeElement = value;
- }
- }
- public BoneCache[] elements
- {
- get { return m_BoneSelection.elements; }
- set
- {
- foreach (var bone in value)
- ValidateBone(bone);
- m_BoneSelection.elements = value;
- }
- }
- public BoneCache root
- {
- get { return m_BoneSelection.root; }
- }
- public BoneCache[] roots
- {
- get { return m_BoneSelection.roots; }
- }
- public void BeginSelection()
- {
- m_BoneSelection.BeginSelection();
- }
- public void Clear()
- {
- m_BoneSelection.Clear();
- }
- public bool Contains(BoneCache element)
- {
- return m_BoneSelection.Contains(element);
- }
- public void EndSelection(bool select)
- {
- m_BoneSelection.EndSelection(select);
- }
- public void Select(BoneCache element, bool select)
- {
- ValidateBone(element);
- m_BoneSelection.Select(element, select);
- }
- private void ValidateBone(BoneCache bone)
- {
- if (bone == null)
- return;
- var skinningCache = bone.skinningCache;
- if (skinningCache.hasCharacter)
- {
- if (bone.skeleton != skinningCache.character.skeleton)
- throw new Exception("Selection Exception: bone does not belong to character skeleton");
- }
- else
- {
- var selectedSprite = skinningCache.selectedSprite;
- if (selectedSprite == null)
- throw new Exception("Selection Exception: skeleton not selected");
- else
- {
- var skeleton = selectedSprite.GetSkeleton();
- if (bone.skeleton != skeleton)
- throw new Exception("Selection Exception: bone's skeleton does not match selected skeleton");
- }
- }
- }
- }
- }
|