// Copyright (c) .NET Foundation and Contributors (https://dotnetfoundation.org/ & https://stride3d.net) and Silicon Studio Corp. (https://www.siliconstudio.co.jp) // Distributed under the MIT license. See the LICENSE.md file in the project root for more information. using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Stride.Core; using Stride.Core.Mathematics; using Stride.Animations; using Stride.Input; using Stride.Engine; namespace ParticlesSample { [DataContract] public class PlayAnimation { public AnimationClip Clip; public AnimationBlendOperation BlendOperation = AnimationBlendOperation.LinearBlend; public double StartTime = 0; } /// /// Script which starts a few playing animations on a target and halts /// public class AnimationStart : StartupScript { /// /// If null, will target the same entity it is attached to. /// public AnimationComponent Target { get; set; } /// /// Al list of animations to be loaded when the script starts /// public readonly List Animations = new List(); public override void Start() { var animComponent = Target ?? Entity.Get(); if (animComponent != null) PlayAnimations(animComponent); // Destroy this script since it's no longer needed Entity.Remove(this); } private void PlayAnimations(AnimationComponent animComponent) { foreach (var anim in Animations) { if (anim.Clip != null) animComponent.Add(anim.Clip, anim.StartTime, anim.BlendOperation); } Animations.Clear(); } } }