Getting Started - TheKeyblader/Stridelonia GitHub Wiki
This tutorial was made with stride 4.0.1.1400 (.NET 5)
-
Start Stride and create a new game.
-
Optionnal (Very Recommmended) Use this tutorial to clean UI.
-
Open the file .sln of your project or use the "open in ide" button from the game studio
Now we are two solutions:
- You can add Avalonia to your main project.
Making this is easier to communicate with stride code.
But your code may be less clean. - You can add Avalonia to this own project.
Making this makes your code cleaner.
But you will need some intermediate interfaces in another project.
Making the project more complicated to code.
Now I will explain the second solution as the first need the second. For the next step you will need to install this extension
-
Change the target of your main project to .NET 5
-
Create a project called "YourProjectName".UI with one of the templates of Avalonia
-
Reference the UI project to main.
-
If you use the second solution. create a .net core library project called "YourProjectName".Core .
Change the project target to .net 5.0 and add project references to the core to your main project and UI project -
We will make the previewer working with "YourProjectName".Windows .
To do this add these lines to your app file.public static AppBuilder BuildAvaloniaApp() => AppBuilder.Configure<App>() .UsePlatformDetect() .LogToTrace() .UseReactiveUI();
Now we will make Stridelonia load your Avalonia application.
-
Add the Stridelonia package to your main project.
Install also Stridelonia.Avalonia package to your UI project -
Create a class called Game that inherits from StrideloniaGame
public class Game : StrideloniaGame
{
}
- Create a public constructor and this line of code
public Game() : base()
{
AvaloniaLocator.CurrentMutable.BindToSelf(new StridePlatformOptions
{
ApplicationType = typeof(App),
ConfigureApp = builder => builder.LogToTrace().UseReactiveUI(),
WaitCopyTexture = true
});
}
- Use this game class in the app class of every executable project.
Now normally you will see a Welcome to Avalonia if we execute the project
We have finished the second solution. (12 steps too long need to find better method 🤔)
Now it time to do the fusion of the UI to main to do the first solution.
-
Create a folder AvaloniaAssets on the main project to avoid conflicts with assets of stride.
Then copy the content of the Assets folder from the UI project to AvaloniaAssets of the main folder. -
Add these lines to the main project csproj
To allow assets from the AvaloniaAssets folder to be referenced for avalonia.
<ItemGroup>
<AvaloniaResource Include="AvaloniaAssets\**" />
</ItemGroup>
-
Copy all files and folders from the UI project to the main project in a folder called UI (Except Program.cs)
-
Add the missings avalonia packages to main project
- Avalonia
- Avalonia.Desktop
- Avalonia.ReactiveUI
- Avalonia.Diagnostics
-
In MainWindow.xaml correct the path to Icon from "/Assets/avalonia-logo.ico" to "/AvaloniaAssets/avalonia-logo.ico"
-
Finish! 🎉