Initial commit

This commit is contained in:
AbstractConcept 2022-09-13 00:36:34 -05:00
commit 3c7cc0c973
8391 changed files with 704313 additions and 0 deletions

View file

@ -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>(); }
}
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 10db00a3c51d23d4ab8a68837ffa21fc
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,7 @@
using System;
using UnityEngine;
namespace UnityEditor.U2D.Animation
{
internal interface IBoneSelection : ITransformSelection<BoneCache> {}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 2e79c8e51ce4486409b7daf3012a1f4d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -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);
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: df44828de9ac64d44ba1a553e06eb335
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -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; }
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 08c104e7d99d71c4eb0702b4e3e4b7d5
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,11 @@
using System;
using UnityEngine;
namespace UnityEditor.U2D.Animation
{
[Serializable]
internal class IndexedSelection : SerializableSelection<int>
{
protected override int GetInvalidElement() { return -1; }
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 1a16f886b3d85c640ad6350d0db615f1
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -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;
}
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 3fe89a573a78649d2856fde6fc441e38
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -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");
}
}
}
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: c66db58fd56e0a14690d99c115527f28
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: