mirror of
https://gitgud.io/AbstractConcept/rimworld-animation-studio.git
synced 2024-08-15 00:43:27 +00:00
Initial commit
This commit is contained in:
commit
3c7cc0c973
8391 changed files with 704313 additions and 0 deletions
|
@ -0,0 +1,106 @@
|
|||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace UnityEditor.U2D.Animation
|
||||
{
|
||||
#if CODE_COVERAGE
|
||||
internal class BaseObject
|
||||
{
|
||||
public static T CreateInstance<T>()
|
||||
{
|
||||
return Activator.CreateInstance<T>();
|
||||
}
|
||||
|
||||
public static void DestroyImmediate(object o)
|
||||
{
|
||||
if (o is BaseObject)
|
||||
{
|
||||
var obj = o as BaseObject;
|
||||
obj.OnDestroy();
|
||||
s_Objects.Remove(obj.GetInstanceID());
|
||||
}
|
||||
else if (o is UnityEngine.Object)
|
||||
{
|
||||
var obj = o as UnityEngine.Object;
|
||||
Undo.ClearUndo(obj);
|
||||
UnityEngine.Object.DestroyImmediate(obj);
|
||||
}
|
||||
}
|
||||
|
||||
public static BaseObject InstanceIDToObject(int instanceID)
|
||||
{
|
||||
var obj = default(BaseObject);
|
||||
s_Objects.TryGetValue(instanceID, out obj);
|
||||
return obj;
|
||||
}
|
||||
|
||||
private static Dictionary<int, BaseObject> s_Objects = new Dictionary<int, BaseObject>();
|
||||
private static int s_InstanceID = 0;
|
||||
private int m_InstanceID;
|
||||
|
||||
public string name { get; set; }
|
||||
public HideFlags hideFlags = HideFlags.None;
|
||||
|
||||
public BaseObject()
|
||||
{
|
||||
m_InstanceID = ++s_InstanceID;
|
||||
s_Objects.Add(m_InstanceID, this);
|
||||
}
|
||||
|
||||
internal virtual void OnEnable() {}
|
||||
internal virtual void OnDestroy() {}
|
||||
|
||||
public int GetInstanceID()
|
||||
{
|
||||
return m_InstanceID;
|
||||
}
|
||||
|
||||
public override bool Equals(object other)
|
||||
{
|
||||
if ((other == null))
|
||||
return false;
|
||||
|
||||
return object.ReferenceEquals(this, other);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return m_InstanceID.GetHashCode();
|
||||
}
|
||||
|
||||
public static bool operator==(BaseObject t1, BaseObject t2)
|
||||
{
|
||||
if (object.ReferenceEquals(t1, null))
|
||||
return object.ReferenceEquals(t2, null);
|
||||
|
||||
return object.ReferenceEquals(t1, t2);
|
||||
}
|
||||
|
||||
public static bool operator!=(BaseObject t1, BaseObject t2)
|
||||
{
|
||||
return !(t1 == t2);
|
||||
}
|
||||
}
|
||||
#else
|
||||
internal class BaseObject : ScriptableObject
|
||||
{
|
||||
public static void DestroyImmediate(object o)
|
||||
{
|
||||
if (o is UnityEngine.Object)
|
||||
{
|
||||
var obj = o as UnityEngine.Object;
|
||||
Undo.ClearUndo(obj);
|
||||
UnityEngine.Object.DestroyImmediate(obj);
|
||||
}
|
||||
}
|
||||
|
||||
public static BaseObject InstanceIDToObject(int instanceID)
|
||||
{
|
||||
return EditorUtility.InstanceIDToObject(instanceID) as BaseObject;
|
||||
}
|
||||
|
||||
internal virtual void OnEnable() {}
|
||||
internal virtual void OnDestroy() {}
|
||||
}
|
||||
#endif
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 9ceaf8ef48b796342bb695b046536af8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,141 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
|
||||
namespace UnityEditor.U2D.Animation
|
||||
{
|
||||
internal class Cache : BaseObject, ICacheUndo
|
||||
{
|
||||
public static T Create<T>() where T : Cache
|
||||
{
|
||||
var cache = CreateInstance<T>();
|
||||
cache.hideFlags = HideFlags.DontSave;
|
||||
return cache;
|
||||
}
|
||||
|
||||
public static void Destroy(Cache cache)
|
||||
{
|
||||
cache.Destroy();
|
||||
DestroyImmediate(cache);
|
||||
}
|
||||
|
||||
[SerializeField]
|
||||
private List<CacheObject> m_CacheObjects = new List<CacheObject>();
|
||||
[SerializeField]
|
||||
private List<CacheObject> m_RemovedCacheObjects = new List<CacheObject>();
|
||||
private string m_UndoOperationName = null;
|
||||
private IUndo m_DefaultUndo = new UnityEngineUndo();
|
||||
private IUndo m_UndoOverride = null;
|
||||
|
||||
protected IUndo undo
|
||||
{
|
||||
get
|
||||
{
|
||||
if (undoOverride != null)
|
||||
return undoOverride;
|
||||
|
||||
return m_DefaultUndo;
|
||||
}
|
||||
}
|
||||
|
||||
public IUndo undoOverride
|
||||
{
|
||||
get { return m_UndoOverride; }
|
||||
set { m_UndoOverride = value; }
|
||||
}
|
||||
|
||||
public bool isUndoOperationSet
|
||||
{
|
||||
get { return string.IsNullOrEmpty(m_UndoOperationName) == false; }
|
||||
}
|
||||
|
||||
public void IncrementCurrentGroup()
|
||||
{
|
||||
undo.IncrementCurrentGroup();
|
||||
}
|
||||
|
||||
public virtual void BeginUndoOperation(string operationName)
|
||||
{
|
||||
if (isUndoOperationSet == false)
|
||||
{
|
||||
Debug.Assert(!m_CacheObjects.Contains(null));
|
||||
|
||||
m_UndoOperationName = operationName;
|
||||
undo.RegisterCompleteObjectUndo(this, m_UndoOperationName);
|
||||
undo.RegisterCompleteObjectUndo(m_CacheObjects.ToArray(), m_UndoOperationName);
|
||||
undo.RegisterCompleteObjectUndo(m_RemovedCacheObjects.ToArray(), m_UndoOperationName);
|
||||
}
|
||||
}
|
||||
|
||||
public void EndUndoOperation()
|
||||
{
|
||||
m_UndoOperationName = null;
|
||||
}
|
||||
|
||||
public bool IsRemoved(CacheObject cacheObject)
|
||||
{
|
||||
return m_RemovedCacheObjects.Contains(cacheObject);
|
||||
}
|
||||
|
||||
public T CreateCache<T>() where T : CacheObject
|
||||
{
|
||||
var cacheObject = FindRemovedCacheObject<T>();
|
||||
|
||||
if (cacheObject != null)
|
||||
{
|
||||
m_RemovedCacheObjects.Remove(cacheObject);
|
||||
cacheObject.OnEnable();
|
||||
}
|
||||
else
|
||||
{
|
||||
cacheObject = CacheObject.Create<T>(this);
|
||||
}
|
||||
|
||||
m_CacheObjects.Add(cacheObject);
|
||||
|
||||
cacheObject.OnCreate();
|
||||
|
||||
return cacheObject;
|
||||
}
|
||||
|
||||
private T FindRemovedCacheObject<T>() where T : CacheObject
|
||||
{
|
||||
return m_RemovedCacheObjects.FirstOrDefault((o) => o.GetType().Equals(typeof(T))) as T;
|
||||
}
|
||||
|
||||
public void Destroy(CacheObject cacheObject)
|
||||
{
|
||||
Debug.Assert(cacheObject != null);
|
||||
Debug.Assert(cacheObject.owner == this);
|
||||
Debug.Assert(m_CacheObjects.Contains(cacheObject));
|
||||
|
||||
m_CacheObjects.Remove(cacheObject);
|
||||
m_RemovedCacheObjects.Add(cacheObject);
|
||||
|
||||
cacheObject.OnDestroy();
|
||||
}
|
||||
|
||||
public void Destroy()
|
||||
{
|
||||
Debug.Assert(!m_CacheObjects.Contains(null));
|
||||
|
||||
EndUndoOperation();
|
||||
|
||||
undo.ClearUndo(this);
|
||||
|
||||
var cacheObjects = m_CacheObjects.ToArray();
|
||||
|
||||
foreach (var cacheObject in cacheObjects)
|
||||
DestroyImmediate(cacheObject);
|
||||
|
||||
cacheObjects = m_RemovedCacheObjects.ToArray();
|
||||
|
||||
foreach (var cacheObject in cacheObjects)
|
||||
DestroyImmediate(cacheObject);
|
||||
|
||||
m_CacheObjects.Clear();
|
||||
m_RemovedCacheObjects.Clear();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 455f18c8a1cd7574f84ff7236cfaadea
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,39 @@
|
|||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace UnityEditor.U2D.Animation
|
||||
{
|
||||
internal class CacheObject : BaseObject, ISerializationCallbackReceiver
|
||||
{
|
||||
public static T Create<T>(Cache owner) where T : CacheObject
|
||||
{
|
||||
var cacheObject = CreateInstance<T>();
|
||||
cacheObject.hideFlags = HideFlags.HideAndDontSave;
|
||||
cacheObject.owner = owner;
|
||||
return cacheObject;
|
||||
}
|
||||
|
||||
[SerializeField]
|
||||
private Cache m_Owner;
|
||||
|
||||
public Cache owner
|
||||
{
|
||||
get { return m_Owner; }
|
||||
set { m_Owner = value; }
|
||||
}
|
||||
|
||||
void ISerializationCallbackReceiver.OnAfterDeserialize()
|
||||
{
|
||||
OnAfterDeserialize();
|
||||
}
|
||||
|
||||
void ISerializationCallbackReceiver.OnBeforeSerialize()
|
||||
{
|
||||
OnBeforeSerialize();
|
||||
}
|
||||
|
||||
internal virtual void OnCreate() {}
|
||||
protected virtual void OnAfterDeserialize() {}
|
||||
protected virtual void OnBeforeSerialize() {}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: ea21de3798988c84dbc83021a3e6ecee
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Loading…
Add table
Add a link
Reference in a new issue