mirror of
https://github.com/maxartz15/VertexAnimation.git
synced 2025-04-18 22:46:44 +02:00
BlobAsset test and animation looping.
BlobAsset creaton and testing BlobAssetStore. Start working on AnimationLibrary. Added animation looping based upon BlobAsset data.
This commit is contained in:
parent
13f6da9437
commit
5ac8db608e
51
Runtime/Scripts/VA_AnimationLibrary.cs
Normal file
51
Runtime/Scripts/VA_AnimationLibrary.cs
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
using Unity.Entities;
|
||||||
|
using Unity.Collections;
|
||||||
|
|
||||||
|
namespace TAO.VertexAnimation
|
||||||
|
{
|
||||||
|
[System.Serializable]
|
||||||
|
public struct VA_AnimationData
|
||||||
|
{
|
||||||
|
public int frames;
|
||||||
|
public int maxFrames;
|
||||||
|
}
|
||||||
|
|
||||||
|
public struct VA_AnimationDataBlobAsset
|
||||||
|
{
|
||||||
|
public BlobArray<VA_AnimationData> animations;
|
||||||
|
}
|
||||||
|
|
||||||
|
public class VA_AnimationDataBlobAssetConversionSystem : GameObjectConversionSystem
|
||||||
|
{
|
||||||
|
protected override void OnUpdate()
|
||||||
|
{
|
||||||
|
BlobAssetReference<VA_AnimationDataBlobAsset> animationDataBlobAssetRef;
|
||||||
|
|
||||||
|
// Blob builder to build.
|
||||||
|
using (BlobBuilder blobBuilder = new BlobBuilder(Allocator.Temp))
|
||||||
|
{
|
||||||
|
// Construct the root.
|
||||||
|
ref VA_AnimationDataBlobAsset animationDataBlobAsset = ref blobBuilder.ConstructRoot<VA_AnimationDataBlobAsset>();
|
||||||
|
|
||||||
|
// Set all the data.
|
||||||
|
BlobBuilderArray<VA_AnimationData> animationDataArray = blobBuilder.Allocate(ref animationDataBlobAsset.animations, 2);
|
||||||
|
for (int i = 0; i < animationDataArray.Length; i++)
|
||||||
|
{
|
||||||
|
animationDataArray[i] = new VA_AnimationData
|
||||||
|
{
|
||||||
|
frames = 36,
|
||||||
|
maxFrames = 43
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
// Construct blob asset reference.
|
||||||
|
animationDataBlobAssetRef = blobBuilder.CreateBlobAssetReference<VA_AnimationDataBlobAsset>(Allocator.Persistent);
|
||||||
|
|
||||||
|
UnityEngine.Debug.Log("Created: " + animationDataBlobAssetRef.Value.animations.Length.ToString());
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Generate Hash based on Guid.
|
||||||
|
BlobAssetStore.TryAdd(new Hash128("AnimationLib"), animationDataBlobAssetRef);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
11
Runtime/Scripts/VA_AnimationLibrary.cs.meta
Normal file
11
Runtime/Scripts/VA_AnimationLibrary.cs.meta
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 79884e6263d984c44af76267d129d76b
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
@ -17,23 +17,28 @@ namespace TAO.VertexAnimation
|
|||||||
public int animationIndex;
|
public int animationIndex;
|
||||||
public int animationIndexSchedule;
|
public int animationIndexSchedule;
|
||||||
public float animationTime;
|
public float animationTime;
|
||||||
|
public BlobAssetReference<VA_AnimationDataBlobAsset> animationsRef;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[UpdateAfter(typeof(VA_AnimationDataBlobAssetConversionSystem))]
|
||||||
public class VA_AnimatorConversionSystem : GameObjectConversionSystem
|
public class VA_AnimatorConversionSystem : GameObjectConversionSystem
|
||||||
{
|
{
|
||||||
protected override void OnUpdate()
|
protected override void OnUpdate()
|
||||||
{
|
{
|
||||||
|
BlobAssetStore.TryGet(new Unity.Entities.Hash128("AnimationLib"), out BlobAssetReference<VA_AnimationDataBlobAsset> assetReference);
|
||||||
|
|
||||||
Entities.ForEach((VA_AnimatorComponentAuthoring animator) =>
|
Entities.ForEach((VA_AnimatorComponentAuthoring animator) =>
|
||||||
{
|
{
|
||||||
Entity entity = GetPrimaryEntity(animator);
|
Entity entity = GetPrimaryEntity(animator);
|
||||||
|
|
||||||
// Add animator to 'parent'.
|
// Add animator to 'parent'.
|
||||||
VA_AnimatorComponent animatorComponent = new VA_AnimatorComponent
|
VA_AnimatorComponent animatorComponent = new VA_AnimatorComponent
|
||||||
{
|
{
|
||||||
animationIndex = 0,
|
animationIndex = 0,
|
||||||
animationIndexSchedule = -1,
|
animationIndexSchedule = -1,
|
||||||
animationTime = 0,
|
animationTime = 0,
|
||||||
};
|
animationsRef = assetReference
|
||||||
|
};
|
||||||
DstEntityManager.AddComponentData(entity, animatorComponent);
|
DstEntityManager.AddComponentData(entity, animatorComponent);
|
||||||
|
|
||||||
// Add the Material data to the children.
|
// Add the Material data to the children.
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
using Unity.Entities;
|
using Unity.Entities;
|
||||||
using Unity.Rendering;
|
using Unity.Rendering;
|
||||||
using Unity.Transforms;
|
using Unity.Transforms;
|
||||||
using UnityEngine;
|
using Unity.Mathematics;
|
||||||
|
|
||||||
namespace TAO.VertexAnimation
|
namespace TAO.VertexAnimation
|
||||||
{
|
{
|
||||||
@ -75,53 +75,69 @@ namespace TAO.VertexAnimation
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class VA_AnimatorSystem2 : SystemBase
|
//public class VA_AnimatorSystem2 : SystemBase
|
||||||
{
|
//{
|
||||||
protected override void OnCreate()
|
// protected override void OnCreate()
|
||||||
{
|
// {
|
||||||
base.OnCreate();
|
// base.OnCreate();
|
||||||
|
|
||||||
Enabled = false;
|
// Enabled = false;
|
||||||
}
|
// }
|
||||||
|
|
||||||
protected override void OnUpdate()
|
// protected override void OnUpdate()
|
||||||
{
|
// {
|
||||||
Entities.ForEach((ref VA_AnimatorComponent ac, in DynamicBuffer<Child> children) =>
|
// Entities.ForEach((ref VA_AnimatorComponent ac, in DynamicBuffer<Child> children) =>
|
||||||
{
|
// {
|
||||||
for (int i = 0; i < children.Length; i++)
|
// for (int i = 0; i < children.Length; i++)
|
||||||
{
|
// {
|
||||||
// Get child.
|
// // Get child.
|
||||||
Entity child = children[i].Value;
|
// Entity child = children[i].Value;
|
||||||
|
|
||||||
//if(HasComponent<VA_AnimationTimeComponent>(child))
|
// //if(HasComponent<VA_AnimationTimeComponent>(child))
|
||||||
//{
|
// //{
|
||||||
var atc = GetComponent<VA_AnimationTimeComponent>(child);
|
// var atc = GetComponent<VA_AnimationTimeComponent>(child);
|
||||||
atc.Value = ac.animationTime;
|
// atc.Value = ac.animationTime;
|
||||||
SetComponent(child, atc);
|
// SetComponent(child, atc);
|
||||||
//}
|
// //}
|
||||||
|
|
||||||
//if(HasComponent<VA_AnimationIndexComponent>(child))
|
// //if(HasComponent<VA_AnimationIndexComponent>(child))
|
||||||
//{
|
// //{
|
||||||
var aic = GetComponent<VA_AnimationIndexComponent>(child);
|
// var aic = GetComponent<VA_AnimationIndexComponent>(child);
|
||||||
aic.Value = ac.animationIndex;
|
// aic.Value = ac.animationIndex;
|
||||||
SetComponent(child, aic);
|
// SetComponent(child, aic);
|
||||||
//}
|
// //}
|
||||||
}
|
// }
|
||||||
})
|
// })
|
||||||
.Run();
|
// .Run();
|
||||||
}
|
// }
|
||||||
}
|
//}
|
||||||
|
|
||||||
[UpdateBefore(typeof(VA_AnimatorSystem))]
|
[UpdateBefore(typeof(VA_AnimatorSystem))]
|
||||||
public class VA_AnimationTimeSystem : SystemBase
|
public class VA_AnimationTimeSystem : SystemBase
|
||||||
{
|
{
|
||||||
protected override void OnUpdate()
|
protected override void OnUpdate()
|
||||||
{
|
{
|
||||||
float time = UnityEngine.Time.deltaTime;
|
float deltaTime = UnityEngine.Time.deltaTime;
|
||||||
|
|
||||||
Entities.ForEach((ref VA_AnimatorComponent ac) =>
|
Entities.ForEach((ref VA_AnimatorComponent ac) =>
|
||||||
{
|
{
|
||||||
ac.animationTime += time;
|
// Get the animation lib data.
|
||||||
|
ref VA_AnimationDataBlobAsset animationsRef = ref ac.animationsRef.Value;
|
||||||
|
int aFrames = animationsRef.animations[ac.animationIndex].frames;
|
||||||
|
int aMaxFrames = animationsRef.animations[ac.animationIndex].maxFrames;
|
||||||
|
|
||||||
|
ac.animationTime += deltaTime;
|
||||||
|
|
||||||
|
// Time per frame.
|
||||||
|
float fTime = 1.0f / aMaxFrames;
|
||||||
|
// Animation time.
|
||||||
|
float cTime = fTime * (aFrames);
|
||||||
|
|
||||||
|
if (ac.animationTime > cTime)
|
||||||
|
{
|
||||||
|
ac.animationTime = ac.animationTime - cTime;
|
||||||
|
}
|
||||||
|
|
||||||
}).ScheduleParallel();
|
}).ScheduleParallel();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user