mirror of
https://github.com/maxartz15/VertexAnimation.git
synced 2025-07-01 14:06:08 +02:00
fix: samples 1-3 + new sample 4
This commit is contained in:
31
Samples~/Example4/Scripts/AntAnimationComponentAuthoring.cs
Normal file
31
Samples~/Example4/Scripts/AntAnimationComponentAuthoring.cs
Normal 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;
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 77596ecedf035ab4897728e401c34b80
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
40
Samples~/Example4/Scripts/AntAnimationSystem.cs
Normal file
40
Samples~/Example4/Scripts/AntAnimationSystem.cs
Normal 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();
|
||||
}
|
||||
}
|
||||
}
|
11
Samples~/Example4/Scripts/AntAnimationSystem.cs.meta
Normal file
11
Samples~/Example4/Scripts/AntAnimationSystem.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c0cd3043bca649944bc59a6cffa79c4f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -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;
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8651d812c7795e14b9279485c66c0bd4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
34
Samples~/Example4/Scripts/RobotAnimationSystem.cs
Normal file
34
Samples~/Example4/Scripts/RobotAnimationSystem.cs
Normal 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();
|
||||
}
|
||||
}
|
||||
}
|
11
Samples~/Example4/Scripts/RobotAnimationSystem.cs.meta
Normal file
11
Samples~/Example4/Scripts/RobotAnimationSystem.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b8028b94a3a01fd41b16672db6936921
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -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;
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0b7314938f540fe4780891de27564f2d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
43
Samples~/Example4/Scripts/ZombieAnimationSystem.cs
Normal file
43
Samples~/Example4/Scripts/ZombieAnimationSystem.cs
Normal 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();
|
||||
}
|
||||
}
|
||||
}
|
11
Samples~/Example4/Scripts/ZombieAnimationSystem.cs.meta
Normal file
11
Samples~/Example4/Scripts/ZombieAnimationSystem.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bfaab176bae884d4d8a494f1ed9df52a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in New Issue
Block a user