stride/samples/Particles/ParticlesSample/ParticlesSample.Game/NextSceneScript.cs

77 lines
2.3 KiB
C#
Raw Normal View History

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.
2020-04-14 14:37:41 +00:00
using Stride.Core.Mathematics;
using Stride.Engine;
using Stride.Graphics;
using Stride.UI;
using Stride.UI.Controls;
using Stride.UI.Panels;
2018-06-19 09:06:54 +00:00
namespace ParticlesSample
{
public class NextSceneScript : SyncScript
{
public Scene Next;
public Scene Previous;
public SpriteFont Font;
public override void Start()
{
SetupUI();
}
public override void Update() { }
private void SetupUI()
{
var uiComponent = Entity.Get<UIComponent>();
if (uiComponent == null)
return;
// Create the UI
Entity.Get<UIComponent>().Page = new UIPage
{
RootElement = new Grid
{
Children =
{
CreateButton("<<", 72, 0, Previous),
CreateButton(">>", 72, 2, Next)
},
ColumnDefinitions =
{
new StripDefinition(StripType.Auto, 10),
new StripDefinition(StripType.Star, 80),
new StripDefinition(StripType.Auto, 10),
}
}
};
}
private Button CreateButton(string text, int textSize, int columnId, Scene targetScene)
{
var button = new Button
{
Name = text,
HorizontalAlignment = HorizontalAlignment.Center,
Content = new TextBlock { Text = text, Font = Font, TextSize = textSize, TextColor = new Color(200, 200, 200, 255), VerticalAlignment = VerticalAlignment.Center },
BackgroundColor = new Color(new Vector4(0.2f, 0.2f, 0.2f, 0.2f)),
};
button.SetGridColumn(columnId);
button.Click += (sender, args) =>
{
SceneSystem.SceneInstance.RootScene = targetScene;
Cancel();
};
return button;
}
}
}