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,132 @@
|
|||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Scripting;
|
||||
|
||||
#if ENABLE_ENTITIES
|
||||
using Unity.Entities;
|
||||
#endif
|
||||
|
||||
namespace UnityEngine.U2D.Animation
|
||||
{
|
||||
|
||||
[Preserve]
|
||||
internal class SpriteSkinEntity
|
||||
#if ENABLE_ENTITIES
|
||||
: GameObjectEntity
|
||||
#else
|
||||
: MonoBehaviour
|
||||
#endif
|
||||
{
|
||||
|
||||
#if ENABLE_ENTITIES
|
||||
bool enableEntitiesCached = true;
|
||||
#if UNITY_EDITOR
|
||||
static bool assemblyReload = false;
|
||||
#endif
|
||||
|
||||
SpriteSkin m_SpriteSkin;
|
||||
SpriteSkin spriteSkin
|
||||
{
|
||||
get
|
||||
{
|
||||
if (m_SpriteSkin == null)
|
||||
m_SpriteSkin = GetComponent<SpriteSkin>();
|
||||
return m_SpriteSkin;
|
||||
}
|
||||
}
|
||||
|
||||
bool entitiesEnabled
|
||||
{
|
||||
get
|
||||
{
|
||||
if (m_SpriteSkin == null)
|
||||
return false;
|
||||
return m_SpriteSkin.entitiesEnabled;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnEnable()
|
||||
{
|
||||
if (entitiesEnabled)
|
||||
{
|
||||
base.OnEnable();
|
||||
SetupEntity();
|
||||
SetupSpriteSkin();
|
||||
|
||||
#if UNITY_EDITOR
|
||||
UnityEditor.AssemblyReloadEvents.afterAssemblyReload += OnAfterAssemblyReload;
|
||||
UnityEditor.AssemblyReloadEvents.beforeAssemblyReload += OnBeforeAssemblyReload;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
public void OnBeforeAssemblyReload()
|
||||
{
|
||||
assemblyReload = true;
|
||||
}
|
||||
|
||||
public void OnAfterAssemblyReload()
|
||||
{
|
||||
assemblyReload = false;
|
||||
}
|
||||
#endif
|
||||
|
||||
protected override void OnDisable()
|
||||
{
|
||||
if (entitiesEnabled)
|
||||
{
|
||||
DeactivateSkinning();
|
||||
#if UNITY_EDITOR
|
||||
if (!assemblyReload)
|
||||
#endif
|
||||
base.OnDisable();
|
||||
}
|
||||
if (spriteSkin.isValid)
|
||||
spriteSkin.entitiesEnabled = false;
|
||||
}
|
||||
|
||||
private void SetupEntity()
|
||||
{
|
||||
if (EntityManager == null)
|
||||
return;
|
||||
|
||||
EntityManager.AddBuffer<Vertex>(Entity);
|
||||
EntityManager.AddBuffer<BoneTransform>(Entity);
|
||||
EntityManager.AddComponent(Entity, typeof(WorldToLocal));
|
||||
EntityManager.AddSharedComponentData(Entity, new SpriteComponent() { Value = null });
|
||||
}
|
||||
|
||||
private void SetupSpriteSkin()
|
||||
{
|
||||
if (spriteSkin != null)
|
||||
{
|
||||
spriteSkin.ForceSkinning = true;
|
||||
|
||||
if (spriteSkin.bounds.extents != Vector3.zero) //Maybe log a warning?
|
||||
InternalEngineBridge.SetLocalAABB(spriteSkin.spriteRenderer, spriteSkin.bounds);
|
||||
}
|
||||
}
|
||||
|
||||
private void DeactivateSkinning()
|
||||
{
|
||||
if (spriteSkin != null)
|
||||
spriteSkin.DeactivateSkinning();
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (entitiesEnabled != enableEntitiesCached)
|
||||
{
|
||||
if (entitiesEnabled)
|
||||
OnEnable();
|
||||
else
|
||||
|
||||
OnDisable();
|
||||
enableEntitiesCached = entitiesEnabled;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue