testss
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace UnityEditor.U2D.Animation
|
||||
{
|
||||
[Serializable]
|
||||
internal class BoneSelection : SerializableSelection<BoneCache>, IBoneSelection
|
||||
{
|
||||
protected override BoneCache GetInvalidElement() { return null; }
|
||||
|
||||
public BoneCache root
|
||||
{
|
||||
get { return activeElement.FindRoot<BoneCache>(elements); }
|
||||
}
|
||||
|
||||
public BoneCache[] roots
|
||||
{
|
||||
get { return elements.FindRoots<BoneCache>(); }
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,7 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace UnityEditor.U2D.Animation
|
||||
{
|
||||
internal interface IBoneSelection : ITransformSelection<BoneCache> {}
|
||||
}
|
@@ -0,0 +1,14 @@
|
||||
namespace UnityEditor.U2D.Animation
|
||||
{
|
||||
internal interface ISelection<T>
|
||||
{
|
||||
int Count { get; }
|
||||
T activeElement { get; set; }
|
||||
T[] elements { get; set; }
|
||||
void Clear();
|
||||
void BeginSelection();
|
||||
void EndSelection(bool select);
|
||||
void Select(T element, bool select);
|
||||
bool Contains(T element);
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace UnityEditor.U2D.Animation
|
||||
{
|
||||
internal interface ITransformSelection<T> : ISelection<T> where T : TransformCache
|
||||
{
|
||||
T root { get; }
|
||||
T[] roots { get; }
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace UnityEditor.U2D.Animation
|
||||
{
|
||||
[Serializable]
|
||||
internal class IndexedSelection : SerializableSelection<int>
|
||||
{
|
||||
protected override int GetInvalidElement() { return -1; }
|
||||
}
|
||||
}
|
@@ -0,0 +1,138 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace UnityEditor.U2D.Animation
|
||||
{
|
||||
[Serializable]
|
||||
internal abstract class SerializableSelection<T> : ISelection<T>, ISerializationCallbackReceiver
|
||||
{
|
||||
internal readonly static int kInvalidID = -1;
|
||||
|
||||
[SerializeField]
|
||||
private T[] m_Keys = new T[0];
|
||||
|
||||
private HashSet<T> m_Selection = new HashSet<T>();
|
||||
private HashSet<T> m_TemporalSelection = new HashSet<T>();
|
||||
private bool m_SelectionInProgress = false;
|
||||
|
||||
public int Count
|
||||
{
|
||||
get { return m_Selection.Count + m_TemporalSelection.Count; }
|
||||
}
|
||||
|
||||
public T activeElement
|
||||
{
|
||||
get { return First(); }
|
||||
set
|
||||
{
|
||||
Clear();
|
||||
Select(value, true);
|
||||
}
|
||||
}
|
||||
|
||||
public T[] elements
|
||||
{
|
||||
get
|
||||
{
|
||||
var set = m_Selection;
|
||||
|
||||
if (m_SelectionInProgress)
|
||||
{
|
||||
var union = new HashSet<T>(m_Selection);
|
||||
union.UnionWith(m_TemporalSelection);
|
||||
set = union;
|
||||
}
|
||||
|
||||
return new List<T>(set).ToArray();
|
||||
}
|
||||
set
|
||||
{
|
||||
Clear();
|
||||
foreach(var element in value)
|
||||
Select(element, true);
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract T GetInvalidElement();
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
GetSelection().Clear();
|
||||
}
|
||||
|
||||
public void BeginSelection()
|
||||
{
|
||||
m_SelectionInProgress = true;
|
||||
Clear();
|
||||
}
|
||||
|
||||
public void EndSelection(bool select)
|
||||
{
|
||||
m_SelectionInProgress = false;
|
||||
|
||||
if (select)
|
||||
m_Selection.UnionWith(m_TemporalSelection);
|
||||
else
|
||||
m_Selection.ExceptWith(m_TemporalSelection);
|
||||
|
||||
m_TemporalSelection.Clear();
|
||||
}
|
||||
|
||||
public void Select(T element, bool select)
|
||||
{
|
||||
if(EqualityComparer<T>.Default.Equals(element, GetInvalidElement()))
|
||||
return;
|
||||
|
||||
if (select)
|
||||
GetSelection().Add(element);
|
||||
else if (Contains(element))
|
||||
GetSelection().Remove(element);
|
||||
}
|
||||
|
||||
public bool Contains(T element)
|
||||
{
|
||||
return m_Selection.Contains(element) || m_TemporalSelection.Contains(element);
|
||||
}
|
||||
|
||||
private HashSet<T> GetSelection()
|
||||
{
|
||||
if (m_SelectionInProgress)
|
||||
return m_TemporalSelection;
|
||||
|
||||
return m_Selection;
|
||||
}
|
||||
|
||||
private T First()
|
||||
{
|
||||
T element = First(m_Selection);
|
||||
|
||||
if(EqualityComparer<T>.Default.Equals(element, GetInvalidElement()))
|
||||
element = First(m_TemporalSelection);
|
||||
|
||||
return element;
|
||||
}
|
||||
|
||||
private T First(HashSet<T> set)
|
||||
{
|
||||
if(set.Count == 0)
|
||||
return GetInvalidElement();
|
||||
|
||||
using (var enumerator = set.GetEnumerator())
|
||||
{
|
||||
Debug.Assert(enumerator.MoveNext());
|
||||
return enumerator.Current;
|
||||
}
|
||||
}
|
||||
|
||||
void ISerializationCallbackReceiver.OnBeforeSerialize()
|
||||
{
|
||||
m_Keys = new List<T>(m_Selection).ToArray();
|
||||
}
|
||||
|
||||
void ISerializationCallbackReceiver.OnAfterDeserialize()
|
||||
{
|
||||
elements = m_Keys;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,102 @@
|
||||
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");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user