fix: samples 1-3 + new sample 4

This commit is contained in:
SergeyVolik
2022-02-19 16:31:34 +02:00
parent e07f7f67e6
commit 57bf2dc1de
101 changed files with 10229 additions and 131 deletions

View File

@ -0,0 +1,31 @@
using Unity.Entities;
using Unity.Collections;
namespace TAO.VertexAnimation.Example4
{
public class AntAnimationComponentAuthoring : UnityEngine.MonoBehaviour, IConvertGameObjectToEntity
{
[UnityEngine.SerializeField]
private VA_Animation idle;
public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem)
{
AntAnimationComponent sampleAnimationComponent = new AntAnimationComponent
{
curAnimation = idle.GetName(),
idle = idle.GetName(),
};
dstManager.AddComponentData(entity, sampleAnimationComponent);
}
}
public struct AntAnimationComponent : IComponentData
{
public FixedString64 curAnimation;
public FixedString64 idle;
}
}

View File

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

View File

@ -0,0 +1,40 @@
using Unity.Entities;
using Unity.Mathematics;
using UnityEngine;
namespace TAO.VertexAnimation.Example4
{
public class AntAnimationSystem : SystemBase
{
protected override void OnUpdate()
{
float deltaTime = Time.DeltaTime;
Entities.ForEach((Entity entity, ref VA_AnimatorComponent ac, ref AntAnimationComponent cac) =>
{
// Get the animation lib data.
ref VA_AnimationLibraryData animationsRef = ref ac.animationLibrary.Value;
// Set the animation index on the AnimatorComponent to play this animation.
ac.animationIndex = VA_AnimationLibraryUtils.GetAnimation(ref animationsRef, cac.curAnimation);
// 'Play' the actual animation.
ac.animationTime += deltaTime * animationsRef.animations[ac.animationIndex].frameTime;
if (ac.animationTime > animationsRef.animations[ac.animationIndex].duration)
{
// Set time. Using the difference to smoothen out animations when looping.
//ac.animationTime -= animationsRef.animations[ac.animationIndex].duration;
ac.animationTime = 0;
}
}).ScheduleParallel();
}
}
}

View File

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

View File

@ -0,0 +1,29 @@
using Unity.Entities;
using Unity.Collections;
using TAO.VertexAnimation;
namespace TAO.VertexAnimation.Example4
{
public class RobotAnimationComponentAuthoring : UnityEngine.MonoBehaviour, IConvertGameObjectToEntity
{
[UnityEngine.SerializeField]
private VA_Animation anim;
public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem)
{
RobotAnimationComponent sampleAnimationComponent = new RobotAnimationComponent
{
curAnimation = anim.GetName(),
anim = anim.GetName(),
};
dstManager.AddComponentData(entity, sampleAnimationComponent);
}
}
public struct RobotAnimationComponent : IComponentData
{
public FixedString64 curAnimation;
public FixedString64 anim;
}
}

View File

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

View File

@ -0,0 +1,34 @@
using Unity.Entities;
using Unity.Mathematics;
namespace TAO.VertexAnimation.Example4
{
public class RobotAnimationSystem : SystemBase
{
protected override void OnUpdate()
{
float deltaTime = UnityEngine.Time.deltaTime;
Random random = Random.CreateFromIndex((uint)UnityEngine.Time.time);
Entities.ForEach((Entity entity, ref VA_AnimatorComponent ac, ref RobotAnimationComponent cac) =>
{
// Get the animation lib data.
ref VA_AnimationLibraryData animationsRef = ref ac.animationLibrary.Value;
// Set the animation index on the AnimatorComponent to play this animation.
ac.animationIndex = VA_AnimationLibraryUtils.GetAnimation(ref animationsRef, cac.curAnimation);
// 'Play' the actual animation.
ac.animationTime += deltaTime * animationsRef.animations[ac.animationIndex].frameTime;
if (ac.animationTime > animationsRef.animations[ac.animationIndex].duration)
{
ac.animationTime = 0;
// Set time. Using the difference to smoothen out animations when looping.
//ac.animationTime -= animationsRef.animations[ac.animationIndex].duration;
}
}).ScheduleParallel();
}
}
}

View File

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

View File

@ -0,0 +1,32 @@
using Unity.Entities;
using Unity.Collections;
namespace TAO.VertexAnimation.Example4
{
public class ZombieAnimationComponentAuthoring : UnityEngine.MonoBehaviour, IConvertGameObjectToEntity
{
[UnityEngine.SerializeField]
private VA_Animation idle;
[UnityEngine.SerializeField]
private VA_Animation run;
public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem)
{
ZombieAnimationComponent sampleAnimationComponent = new ZombieAnimationComponent
{
curAnimation = idle.GetName(),
idle = idle.GetName(),
run = run.GetName()
};
dstManager.AddComponentData(entity, sampleAnimationComponent);
}
}
public struct ZombieAnimationComponent : IComponentData
{
public FixedString64 curAnimation;
public FixedString64 idle;
public FixedString64 run;
}
}

View File

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

View File

@ -0,0 +1,43 @@
using Unity.Entities;
using Unity.Mathematics;
namespace TAO.VertexAnimation.Example4
{
public class ZombieAnimationSystem : SystemBase
{
protected override void OnUpdate()
{
float deltaTime = UnityEngine.Time.deltaTime;
Random random = Random.CreateFromIndex((uint)UnityEngine.Time.time);
Entities.ForEach((Entity entity, ref VA_AnimatorComponent ac, ref ZombieAnimationComponent cac) =>
{
// Get the animation lib data.
ref VA_AnimationLibraryData animationsRef = ref ac.animationLibrary.Value;
// Set the animation index on the AnimatorComponent to play this animation.
ac.animationIndex = VA_AnimationLibraryUtils.GetAnimation(ref animationsRef, cac.curAnimation);
// 'Play' the actual animation.
ac.animationTime += deltaTime * animationsRef.animations[ac.animationIndex].frameTime;
if (ac.animationTime > animationsRef.animations[ac.animationIndex].duration)
{
// Set time. Using the difference to smoothen out animations when looping.
//ac.animationTime -= animationsRef.animations[ac.animationIndex].duration;
ac.animationTime = 0;
// Select new animation to play.
if (random.NextBool())
{
cac.curAnimation = cac.idle;
}
else
{
cac.curAnimation = cac.run;
}
}
}).ScheduleParallel();
}
}
}

View File

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