Skip to content

Commit cdfcb7f

Browse files
authored
Merge pull request #61 from canhorn/feature/Maui-Sample
✨✨✨feat: Added a MAUI Sample !! ✨✨✨
2 parents 4a919bf + 22ac0bf commit cdfcb7f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+13755
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<Application xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
2+
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
3+
xmlns:windows="clr-namespace:Microsoft.Maui.Controls.PlatformConfiguration.WindowsSpecific;assembly=Microsoft.Maui.Controls"
4+
xmlns:local="clr-namespace:EventHorizon.Maui.BabylonJS"
5+
x:Class="EventHorizon.Maui.BabylonJS.App"
6+
windows:Application.ImageDirectory="Assets">
7+
<Application.Resources>
8+
<ResourceDictionary>
9+
10+
<Color x:Key="PageBackgroundColor">#512bdf</Color>
11+
<Color x:Key="PrimaryTextColor">White</Color>
12+
13+
<Style TargetType="Label">
14+
<Setter Property="TextColor" Value="{DynamicResource PrimaryTextColor}" />
15+
<Setter Property="FontFamily" Value="OpenSansRegular" />
16+
</Style>
17+
18+
<Style TargetType="Button">
19+
<Setter Property="TextColor" Value="{DynamicResource PrimaryTextColor}" />
20+
<Setter Property="FontFamily" Value="OpenSansRegular" />
21+
<Setter Property="BackgroundColor" Value="#2b0b98" />
22+
<Setter Property="Padding" Value="14,10" />
23+
</Style>
24+
25+
</ResourceDictionary>
26+
</Application.Resources>
27+
</Application>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
namespace EventHorizon.Maui.BabylonJS
2+
{
3+
using Application = Microsoft.Maui.Controls.Application;
4+
5+
public partial class App : Application
6+
{
7+
public App()
8+
{
9+
InitializeComponent();
10+
11+
MainPage = new MainPage();
12+
}
13+
}
14+
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Razor">
2+
3+
<PropertyGroup>
4+
<TargetFrameworks>net6.0-ios;net6.0-android;net6.0-maccatalyst</TargetFrameworks>
5+
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows')) and '$(MSBuildRuntimeType)' == 'Full'">$(TargetFrameworks);net6.0-windows10.0.19041</TargetFrameworks>
6+
<OutputType>Exe</OutputType>
7+
<RootNamespace>EventHorizon.Maui.BabylonJS</RootNamespace>
8+
<UseMaui>true</UseMaui>
9+
<SingleProject>true</SingleProject>
10+
<EnablePreviewMsixTooling>true</EnablePreviewMsixTooling>
11+
12+
<!-- Display name -->
13+
<ApplicationTitle>EventHorizon.Maui.BabylonJS</ApplicationTitle>
14+
15+
<!-- App Identifier -->
16+
<ApplicationId>com.companyname.EventHorizon.Maui.BabylonJS</ApplicationId>
17+
18+
<!-- Versions -->
19+
<ApplicationVersion>1</ApplicationVersion>
20+
21+
<!-- Required for C# Hot Reload -->
22+
<UseInterpreter Condition="'$(Configuration)' == 'Debug'">True</UseInterpreter>
23+
24+
<SupportedOSPlatformVersion Condition="'$(TargetFramework)' == 'net6.0-ios'">14.2</SupportedOSPlatformVersion>
25+
<SupportedOSPlatformVersion Condition="'$(TargetFramework)' == 'net6.0-maccatalyst'">14.0</SupportedOSPlatformVersion>
26+
<SupportedOSPlatformVersion Condition="'$(TargetFramework)' == 'net6.0-android'">21.0</SupportedOSPlatformVersion>
27+
<SupportedOSPlatformVersion Condition="$(TargetFramework.Contains('-windows'))">10.0.18362.0</SupportedOSPlatformVersion>
28+
</PropertyGroup>
29+
30+
<ItemGroup>
31+
<!-- App Icon -->
32+
<MauiImage Include="Resources\appicon.svg" ForegroundFile="Resources\appiconfg.svg" IsAppIcon="true" Color="#512BD4" />
33+
34+
<!-- Splash Screen -->
35+
<MauiSplashScreen Include="Resources\appiconfg.svg" Color="#512BD4" />
36+
37+
<!-- Images -->
38+
<MauiImage Include="Resources\Images\*" />
39+
40+
<!-- Custom Fonts -->
41+
<MauiFont Include="Resources\Fonts\*" />
42+
</ItemGroup>
43+
44+
<ItemGroup Condition="$(TargetFramework.Contains('-windows'))">
45+
<!-- Required - WinUI does not yet have buildTransitive for everything -->
46+
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.0.0-experimental1" />
47+
<PackageReference Include="Microsoft.WindowsAppSDK.Foundation" Version="1.0.0-experimental1" />
48+
<PackageReference Include="Microsoft.WindowsAppSDK.WinUI" Version="1.0.0-experimental1" />
49+
<PackageReference Include="Microsoft.WindowsAppSDK.InteractiveExperiences" Version="1.0.0-experimental1" NoWarn="NU1701" />
50+
<PackageReference Include="Microsoft.Graphics.Win2D" Version="1.0.0.26-experimental1" />
51+
</ItemGroup>
52+
53+
<PropertyGroup Condition="$(TargetFramework.Contains('-windows'))">
54+
<OutputType>WinExe</OutputType>
55+
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
56+
</PropertyGroup>
57+
58+
<ItemGroup>
59+
<Content Remove="Properties\launchSettings.json" />
60+
</ItemGroup>
61+
62+
<ItemGroup>
63+
<None Include="wwwroot\assets\Animation.gltf" />
64+
<None Include="wwwroot\assets\House.gltf" />
65+
<None Include="wwwroot\assets\Player.glb" />
66+
</ItemGroup>
67+
68+
<ItemGroup>
69+
<ProjectReference Include="..\_generated\EventHorizon.Blazor.BabylonJS.Server\EventHorizon.Blazor.BabylonJS.Server.csproj" />
70+
</ItemGroup>
71+
72+
</Project>
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
Microsoft Visual Studio Solution File, Format Version 12.00
2+
# Visual Studio Version 17
3+
VisualStudioVersion = 17.0.31611.283
4+
MinimumVisualStudioVersion = 10.0.40219.1
5+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EventHorizon.Maui.BabylonJS", "EventHorizon.Maui.BabylonJS.csproj", "{0FAA66D6-C8DD-4AA3-8138-F23F5BC05205}"
6+
EndProject
7+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EventHorizon.Blazor.BabylonJS.Server", "..\_generated\EventHorizon.Blazor.BabylonJS.Server\EventHorizon.Blazor.BabylonJS.Server.csproj", "{B64AD0FE-2D8C-447A-94D0-72201EE4D2CD}"
8+
EndProject
9+
Global
10+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
11+
Debug|Any CPU = Debug|Any CPU
12+
Release|Any CPU = Release|Any CPU
13+
EndGlobalSection
14+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
15+
{0FAA66D6-C8DD-4AA3-8138-F23F5BC05205}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
16+
{0FAA66D6-C8DD-4AA3-8138-F23F5BC05205}.Debug|Any CPU.Build.0 = Debug|Any CPU
17+
{0FAA66D6-C8DD-4AA3-8138-F23F5BC05205}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
18+
{0FAA66D6-C8DD-4AA3-8138-F23F5BC05205}.Release|Any CPU.ActiveCfg = Release|Any CPU
19+
{0FAA66D6-C8DD-4AA3-8138-F23F5BC05205}.Release|Any CPU.Build.0 = Release|Any CPU
20+
{0FAA66D6-C8DD-4AA3-8138-F23F5BC05205}.Release|Any CPU.Deploy.0 = Release|Any CPU
21+
{B64AD0FE-2D8C-447A-94D0-72201EE4D2CD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
22+
{B64AD0FE-2D8C-447A-94D0-72201EE4D2CD}.Debug|Any CPU.Build.0 = Debug|Any CPU
23+
{B64AD0FE-2D8C-447A-94D0-72201EE4D2CD}.Release|Any CPU.ActiveCfg = Release|Any CPU
24+
{B64AD0FE-2D8C-447A-94D0-72201EE4D2CD}.Release|Any CPU.Build.0 = Release|Any CPU
25+
EndGlobalSection
26+
GlobalSection(SolutionProperties) = preSolution
27+
HideSolutionNode = FALSE
28+
EndGlobalSection
29+
GlobalSection(ExtensibilityGlobals) = postSolution
30+
SolutionGuid = {61F7FB11-1E47-470C-91E2-47F8143E1572}
31+
EndGlobalSection
32+
EndGlobal
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<Router AppAssembly="@GetType().Assembly">
2+
<Found Context="routeData">
3+
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
4+
</Found>
5+
<NotFound>
6+
<LayoutView Layout="@typeof(MainLayout)">
7+
<p>Sorry, there's nothing at this address.</p>
8+
</LayoutView>
9+
</NotFound>
10+
</Router>
11+
12+
@code {
13+
[Inject]
14+
public IJSRuntime JSRuntime { get; set; }
15+
16+
protected override void OnInitialized()
17+
{
18+
// This is a necessary setup for the Interop layer between the generated proxy.
19+
EventHorizon.Blazor.Server.Interop.EventHorizonBlazorInterop.JSRuntime = JSRuntime;
20+
}
21+
}
22+
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
2+
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
3+
xmlns:b="clr-namespace:Microsoft.AspNetCore.Components.WebView.Maui;assembly=Microsoft.AspNetCore.Components.WebView.Maui"
4+
xmlns:local="clr-namespace:EventHorizon.Maui.BabylonJS"
5+
x:Class="EventHorizon.Maui.BabylonJS.MainPage"
6+
BackgroundColor="{DynamicResource PageBackgroundColor}">
7+
8+
<b:BlazorWebView HostPage="wwwroot/index.html">
9+
<b:BlazorWebView.RootComponents>
10+
<b:RootComponent Selector="app" ComponentType="{x:Type local:Main}" />
11+
</b:BlazorWebView.RootComponents>
12+
</b:BlazorWebView>
13+
14+
</ContentPage>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
namespace EventHorizon.Maui.BabylonJS
2+
{
3+
using Microsoft.Maui.Controls;
4+
5+
public partial class MainPage : ContentPage
6+
{
7+
public MainPage()
8+
{
9+
InitializeComponent();
10+
}
11+
}
12+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
namespace EventHorizon.Maui.BabylonJS
2+
{
3+
using Microsoft.AspNetCore.Components.WebView.Maui;
4+
using Microsoft.Extensions.DependencyInjection;
5+
using Microsoft.Maui.Controls.Hosting;
6+
using Microsoft.Maui.Hosting;
7+
8+
public static class MauiProgram
9+
{
10+
public static MauiApp CreateMauiApp()
11+
{
12+
var builder = MauiApp.CreateBuilder();
13+
builder
14+
.RegisterBlazorMauiWebView()
15+
.UseMauiApp<App>()
16+
.ConfigureFonts(fonts =>
17+
{
18+
fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
19+
});
20+
21+
builder.Services.AddBlazorWebView();
22+
23+
return builder.Build();
24+
}
25+
}
26+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
2+
namespace EventHorizon.Blazor.Interop
3+
{
4+
using EventHorizon.Blazor.Server.Interop;
5+
6+
public static class CachedEntityExtensions
7+
{
8+
public static T ToEntity<T>(
9+
this CachedEntity entity
10+
) where T : CachedEntity, new()
11+
{
12+
return new T() { ___guid = entity.___guid };
13+
}
14+
}
15+
}
16+
17+
namespace BABYLON
18+
{
19+
using System.Threading.Tasks;
20+
using EventHorizon.Blazor.Server.Interop;
21+
22+
public static class BabylonjsNodeExtensions
23+
{
24+
public static async ValueTask setParent(
25+
this Node node,
26+
string elementId
27+
)
28+
{
29+
await EventHorizonBlazorInterop.FuncClass<CachedEntity>(
30+
entity => new CachedEntity() { ___guid = entity.___guid },
31+
new object[]
32+
{
33+
new string[] { node.___guid, "setParent" },
34+
elementId
35+
}
36+
);
37+
}
38+
39+
public static async Task<T> clone<T>(
40+
this Node node,
41+
string name
42+
) where T : CachedEntity, new()
43+
{
44+
return await EventHorizonBlazorInterop.FuncClass<T>(
45+
entity => new T() { ___guid = entity.___guid },
46+
new object[]
47+
{
48+
new string[] { node.___guid, "clone" },
49+
name
50+
}
51+
);
52+
}
53+
}
54+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
namespace EventHorizon.Maui.BabylonJS.Model
2+
{
3+
using System.Text.Json.Serialization;
4+
using System.Threading.Tasks;
5+
using EventHorizon.Blazor.Server.Interop;
6+
using Microsoft.Maui.Controls;
7+
8+
[JsonConverter(typeof(CachedEntityConverter<Canvas>))]
9+
public class Canvas : HTMLCanvasElementCachedEntity
10+
{
11+
public static async ValueTask<Canvas> GetElementById(
12+
string elementId
13+
) => await EventHorizonBlazorInterop.FuncClass(
14+
entity => new Canvas(entity),
15+
new string[] { "document", "getElementById" },
16+
elementId
17+
);
18+
19+
private Canvas(
20+
ICachedEntity entity
21+
)
22+
{
23+
___guid = entity.___guid;
24+
}
25+
26+
public static async Task RemoveBlur(
27+
string elementId
28+
)
29+
{
30+
await EventHorizonBlazorInterop.Func<CachedEntity>(
31+
new object[]
32+
{
33+
new string[] { "removeBlur" }, elementId
34+
}
35+
);
36+
}
37+
}
38+
}

0 commit comments

Comments
 (0)