mirror of
https://github.com/stride3d/stride
synced 2026-05-24 10:19:21 +00:00
61 lines
1.9 KiB
C#
61 lines
1.9 KiB
C#
// 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;
|
|
}
|
|
|
|
/// <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();
|
|
}
|
|
}
|
|
}
|