StartStopGpuEcsAnimatorScript.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. using GPUECSAnimationBaker.Engine.AnimatorSystem;
  2. using Unity.Collections;
  3. using Unity.Entities;
  4. using UnityEngine;
  5. using UnityEngine.UI;
  6. namespace GPUECSAnimationBaker.Samples.SampleScenes._0_Basics
  7. {
  8. public class StartStopGpuEcsAnimatorScript : MonoBehaviour
  9. {
  10. public void StartAnimation()
  11. {
  12. StartStopScriptSystem startStopSystem =
  13. World.DefaultGameObjectInjectionWorld.GetOrCreateSystemManaged<StartStopScriptSystem>();
  14. startStopSystem.doStart = true;
  15. }
  16. public void StopAnimation()
  17. {
  18. StartStopScriptSystem startStopSystem =
  19. World.DefaultGameObjectInjectionWorld.GetOrCreateSystemManaged<StartStopScriptSystem>();
  20. startStopSystem.doStop = true;
  21. }
  22. }
  23. public partial class StartStopScriptSystem : SystemBase
  24. {
  25. public bool doStart;
  26. public bool doStop;
  27. protected override void OnUpdate()
  28. {
  29. if (doStart)
  30. {
  31. doStart = false;
  32. Entities.ForEach((GpuEcsAnimatorAspect gpuEcsAnimatorAspect) =>
  33. {
  34. gpuEcsAnimatorAspect.StartAnimation();
  35. }).WithoutBurst().Run();
  36. }
  37. if (doStop)
  38. {
  39. doStop = false;
  40. Entities.ForEach((GpuEcsAnimatorAspect gpuEcsAnimatorAspect) =>
  41. {
  42. gpuEcsAnimatorAspect.StopAnimation();
  43. }).WithoutBurst().Run();
  44. }
  45. }
  46. }
  47. }