2021-04-19 03:49:55 +00:00
// Copyright (c) .NET Foundation and Contributors (https://dotnetfoundation.org/ & https://stride3d.net) and Silicon Studio Corp. (https://www.siliconstudio.co.jp)
2018-06-19 09:06:54 +00:00
// 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 ;
2020-04-14 14:37:41 +00:00
using Stride.Core ;
using Stride.Core.Mathematics ;
using Stride.Animations ;
using Stride.Input ;
using Stride.Engine ;
2018-06-19 09:06:54 +00:00
namespace ParticlesSample
{
[DataContract]
public class PlayAnimation
{
public AnimationClip Clip ;
public AnimationBlendOperation BlendOperation = AnimationBlendOperation . LinearBlend ;
public double StartTime = 0 ;
}
/// <summary>
/// Script which starts a few playing animations on a target and halts
/// </summary>
public class AnimationStart : StartupScript
{
/// <summary>
/// If <c>null</c>, will target the same entity it is attached to.
/// </summary>
public AnimationComponent Target { get ; set ; }
/// <summary>
/// Al list of animations to be loaded when the script starts
/// </summary>
public readonly List < PlayAnimation > Animations = new List < PlayAnimation > ( ) ;
public override void Start ( )
{
var animComponent = Target ? ? Entity . Get < AnimationComponent > ( ) ;
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 ( ) ;
}
}
}