Fix XamlUnityConnection for Unity 5.3
This commit is contained in:
Родитель
7c256b0f16
Коммит
c578642d75
|
@ -1,7 +1,7 @@
|
|||
<Application
|
||||
x:Class="Template.App"
|
||||
x:Class="XAMLUnityConnection.App"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:local="using:Template">
|
||||
xmlns:local="using:XAMLUnityConnection">
|
||||
|
||||
</Application>
|
||||
|
|
|
@ -18,7 +18,7 @@ using Windows.UI.Xaml.Navigation;
|
|||
using UnityPlayer;
|
||||
// The Blank Application template is documented at http://go.microsoft.com/fwlink/?LinkId=234227
|
||||
|
||||
namespace Template
|
||||
namespace XAMLUnityConnection
|
||||
{
|
||||
/// <summary>
|
||||
/// Provides application-specific behavior to supplement the default Application class.
|
||||
|
@ -34,7 +34,7 @@ namespace Template
|
|||
public App()
|
||||
{
|
||||
this.InitializeComponent();
|
||||
appCallbacks = new AppCallbacks(false);
|
||||
appCallbacks = new AppCallbacks();
|
||||
appCallbacks.Initialized += RemoveSplashScreen;
|
||||
}
|
||||
|
||||
|
@ -61,7 +61,7 @@ namespace Template
|
|||
_bridge = new WinRTBridge.WinRTBridge();
|
||||
appCallbacks.SetBridge(_bridge);
|
||||
|
||||
appCallbacks.SetSwapChainBackgroundPanel(mainPage.GetSwapChainBackgroundPanel());
|
||||
appCallbacks.SetSwapChainPanel(mainPage.GetSwapChainPanel());
|
||||
|
||||
|
||||
appCallbacks.SetCoreWindowEvents(Window.Current.CoreWindow);
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
<Page
|
||||
x:Class="Template.MainPage"
|
||||
x:Class="XAMLUnityConnection.MainPage"
|
||||
IsTabStop="false"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:local="using:Template"
|
||||
xmlns:local="using:XAMLUnityConnection"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
mc:Ignorable="d">
|
||||
|
||||
<SwapChainBackgroundPanel x:Name="DXSwapChainBackgroundPanel">
|
||||
<SwapChainPanel x:Name="DXSwapChainPanel">
|
||||
<Grid x:Name="ExtendedSplashGrid">
|
||||
<Image x:Name="ExtendedSplashImage" Source="Assets/SplashScreen.png"/>
|
||||
</Grid>
|
||||
|
@ -19,5 +19,5 @@
|
|||
<TextBox x:Name="textBox" HorizontalAlignment="Left" Margin="435,369,0,0" TextWrapping="Wrap" Text="TextBox" VerticalAlignment="Top" IsReadOnly="True"/>
|
||||
<TextBox HorizontalAlignment="Left" Margin="67,10,0,0" TextWrapping="Wrap" Text="Communications from XAML to Unity" VerticalAlignment="Top" Height="47" Width="291" IsReadOnly="True"/>
|
||||
|
||||
</SwapChainBackgroundPanel>
|
||||
</SwapChainPanel>
|
||||
</Page>
|
|
@ -1,122 +1,126 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using UnityEngine.Windows;
|
||||
using Windows.ApplicationModel.Activation;
|
||||
using Windows.Foundation;
|
||||
using Windows.Foundation.Collections;
|
||||
using Windows.Storage;
|
||||
using Windows.UI;
|
||||
using Windows.UI.Core;
|
||||
using Windows.UI.Xaml;
|
||||
using Windows.UI.Xaml.Controls;
|
||||
using Windows.UI.Xaml.Controls.Primitives;
|
||||
using Windows.UI.Xaml.Data;
|
||||
using Windows.UI.Xaml.Input;
|
||||
using Windows.UI.Xaml.Media;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using UnityEngine.Windows;
|
||||
using Windows.ApplicationModel.Activation;
|
||||
using Windows.Foundation;
|
||||
using Windows.Foundation.Collections;
|
||||
using Windows.Storage;
|
||||
using Windows.UI;
|
||||
using Windows.UI.Core;
|
||||
using Windows.UI.Xaml;
|
||||
using Windows.UI.Xaml.Controls;
|
||||
using Windows.UI.Xaml.Controls.Primitives;
|
||||
using Windows.UI.Xaml.Data;
|
||||
using Windows.UI.Xaml.Input;
|
||||
using Windows.UI.Xaml.Media;
|
||||
using Windows.UI.Xaml.Navigation;
|
||||
|
||||
// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238
|
||||
|
||||
namespace Template
|
||||
{
|
||||
/// <summary>
|
||||
/// An empty page that can be used on its own or navigated to within a Frame.
|
||||
/// </summary>
|
||||
public sealed partial class MainPage : Page
|
||||
{
|
||||
private SplashScreen splash;
|
||||
private Rect splashImageRect;
|
||||
using UnityPlayer;
|
||||
|
||||
// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238
|
||||
|
||||
namespace XAMLUnityConnection
|
||||
{
|
||||
/// <summary>
|
||||
/// An empty page that can be used on its own or navigated to within a Frame.
|
||||
/// </summary>
|
||||
public sealed partial class MainPage : Page
|
||||
{
|
||||
private SplashScreen splash;
|
||||
private Rect splashImageRect;
|
||||
private WindowSizeChangedEventHandler onResizeHandler;
|
||||
private int eventWasReceivedCount = 0;
|
||||
public MainPage(SplashScreen splashScreen)
|
||||
{
|
||||
this.InitializeComponent();
|
||||
|
||||
splash = splashScreen;
|
||||
GetSplashBackgroundColor();
|
||||
OnResize();
|
||||
private int eventWasReceivedCount = 0;
|
||||
public MainPage(SplashScreen splashScreen)
|
||||
{
|
||||
this.InitializeComponent();
|
||||
|
||||
splash = splashScreen;
|
||||
GetSplashBackgroundColor();
|
||||
OnResize();
|
||||
Window.Current.SizeChanged += onResizeHandler = new WindowSizeChangedEventHandler((o, e) => OnResize());
|
||||
UnityPlayer.AppCallbacks.Instance.Initialized += OnInitialized;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Invoked when this page is about to be displayed in a Frame.
|
||||
/// </summary>
|
||||
/// <param name="e">Event data that describes how this page was reached. The Parameter
|
||||
/// property is typically used to configure the page.</param>
|
||||
protected override void OnNavigatedTo(NavigationEventArgs e)
|
||||
{
|
||||
splash = (SplashScreen)e.Parameter;
|
||||
OnResize();
|
||||
}
|
||||
|
||||
private void OnResize()
|
||||
{
|
||||
if (splash != null)
|
||||
{
|
||||
splashImageRect = splash.ImageLocation;
|
||||
PositionImage();
|
||||
}
|
||||
}
|
||||
|
||||
private void PositionImage()
|
||||
{
|
||||
ExtendedSplashImage.SetValue(Canvas.LeftProperty, splashImageRect.X);
|
||||
ExtendedSplashImage.SetValue(Canvas.TopProperty, splashImageRect.Y);
|
||||
ExtendedSplashImage.Height = splashImageRect.Height;
|
||||
ExtendedSplashImage.Width = splashImageRect.Width;
|
||||
}
|
||||
|
||||
private async void GetSplashBackgroundColor()
|
||||
{
|
||||
try
|
||||
{
|
||||
StorageFile file = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///AppxManifest.xml"));
|
||||
string manifest = await FileIO.ReadTextAsync(file);
|
||||
int idx = manifest.IndexOf("SplashScreen");
|
||||
manifest = manifest.Substring(idx);
|
||||
idx = manifest.IndexOf("BackgroundColor");
|
||||
if (idx < 0) // background is optional
|
||||
return;
|
||||
manifest = manifest.Substring(idx);
|
||||
idx = manifest.IndexOf("\"");
|
||||
manifest = manifest.Substring(idx + 2); // also remove quote and # char after it
|
||||
idx = manifest.IndexOf("\"");
|
||||
manifest = manifest.Substring(0, idx);
|
||||
int value = Convert.ToInt32(manifest, 16) & 0x00FFFFFF;
|
||||
byte r = (byte) (value >> 16);
|
||||
byte g = (byte) ((value & 0x0000FF00) >> 8);
|
||||
byte b = (byte) (value & 0x000000FF);
|
||||
|
||||
await CoreWindow.GetForCurrentThread().Dispatcher.RunAsync(CoreDispatcherPriority.High, delegate()
|
||||
{
|
||||
ExtendedSplashGrid.Background = new SolidColorBrush(Color.FromArgb(0xFF, r, g, b));
|
||||
});
|
||||
}
|
||||
catch (Exception)
|
||||
{}
|
||||
}
|
||||
|
||||
public SwapChainBackgroundPanel GetSwapChainBackgroundPanel()
|
||||
{
|
||||
return DXSwapChainBackgroundPanel;
|
||||
}
|
||||
|
||||
public void RemoveSplashScreen()
|
||||
{
|
||||
DXSwapChainBackgroundPanel.Children.Remove(ExtendedSplashGrid);
|
||||
if (onResizeHandler != null)
|
||||
{
|
||||
Window.Current.SizeChanged -= onResizeHandler;
|
||||
onResizeHandler = null;
|
||||
}
|
||||
UnityPlayer.AppCallbacks.Instance.Initialized += OnInitialized;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Invoked when this page is about to be displayed in a Frame.
|
||||
/// </summary>
|
||||
/// <param name="e">Event data that describes how this page was reached. The Parameter
|
||||
/// property is typically used to configure the page.</param>
|
||||
protected override void OnNavigatedTo(NavigationEventArgs e)
|
||||
{
|
||||
splash = (SplashScreen)e.Parameter;
|
||||
OnResize();
|
||||
}
|
||||
|
||||
private void OnResize()
|
||||
{
|
||||
if (splash != null)
|
||||
{
|
||||
splashImageRect = splash.ImageLocation;
|
||||
PositionImage();
|
||||
}
|
||||
}
|
||||
|
||||
private void PositionImage()
|
||||
{
|
||||
ExtendedSplashImage.SetValue(Canvas.LeftProperty, splashImageRect.X);
|
||||
ExtendedSplashImage.SetValue(Canvas.TopProperty, splashImageRect.Y);
|
||||
ExtendedSplashImage.Height = splashImageRect.Height;
|
||||
ExtendedSplashImage.Width = splashImageRect.Width;
|
||||
}
|
||||
|
||||
private async void GetSplashBackgroundColor()
|
||||
{
|
||||
try
|
||||
{
|
||||
StorageFile file = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///AppxManifest.xml"));
|
||||
string manifest = await FileIO.ReadTextAsync(file);
|
||||
int idx = manifest.IndexOf("SplashScreen");
|
||||
manifest = manifest.Substring(idx);
|
||||
idx = manifest.IndexOf("BackgroundColor");
|
||||
if (idx < 0) // background is optional
|
||||
return;
|
||||
manifest = manifest.Substring(idx);
|
||||
idx = manifest.IndexOf("\"");
|
||||
manifest = manifest.Substring(idx + 2); // also remove quote and # char after it
|
||||
idx = manifest.IndexOf("\"");
|
||||
manifest = manifest.Substring(0, idx);
|
||||
int value = Convert.ToInt32(manifest, 16) & 0x00FFFFFF;
|
||||
byte r = (byte) (value >> 16);
|
||||
byte g = (byte) ((value & 0x0000FF00) >> 8);
|
||||
byte b = (byte) (value & 0x000000FF);
|
||||
|
||||
await CoreWindow.GetForCurrentThread().Dispatcher.RunAsync(CoreDispatcherPriority.High, delegate()
|
||||
{
|
||||
ExtendedSplashGrid.Background = new SolidColorBrush(Color.FromArgb(0xFF, r, g, b));
|
||||
});
|
||||
}
|
||||
catch (Exception)
|
||||
{}
|
||||
}
|
||||
|
||||
public SwapChainPanel GetSwapChainPanel()
|
||||
{
|
||||
return DXSwapChainPanel;
|
||||
}
|
||||
|
||||
public void RemoveSplashScreen()
|
||||
{
|
||||
DXSwapChainPanel.Children.Remove(ExtendedSplashGrid);
|
||||
if (onResizeHandler != null)
|
||||
{
|
||||
Window.Current.SizeChanged -= onResizeHandler;
|
||||
onResizeHandler = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnInitialized()
|
||||
{
|
||||
Communications.SetEvent(UnityToXAML);
|
||||
AppCallbacks.Instance.InvokeOnAppThread(() =>
|
||||
{
|
||||
Communications.SetEvent(UnityToXAML);
|
||||
}, false);
|
||||
}
|
||||
public void UnityToXAML(object arg)
|
||||
{
|
||||
|
@ -143,7 +147,7 @@ namespace Template
|
|||
), false);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public delegate void UnityEvent(object arg);
|
||||
|
@ -167,5 +171,5 @@ namespace Template
|
|||
throw new Exception("Cube not found, have exported the correct scene?");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
<Resource Language="x-generate" />
|
||||
</Resources>
|
||||
<Applications>
|
||||
<Application Id="App" Executable="Template.exe" EntryPoint="XAMLUnityConnection.App">
|
||||
<Application Id="App" Executable="XAMLUnityConnection.exe" EntryPoint="XAMLUnityConnection.App">
|
||||
<VisualElements DisplayName="XAMLUnityConnection" Logo="Assets\SquareTile.png" SmallLogo="Assets\SmallTile.png" Description="XAMLUnityConnection" ForegroundText="light" BackgroundColor="#000000">
|
||||
<DefaultTile ShortName="XAMLUnityConn" />
|
||||
<SplashScreen Image="Assets\SplashScreen.png" />
|
||||
|
|
Двоичный файл не отображается.
Двоичные данные
XAMLUnityConnection/ProjectSettings/GraphicsSettings.asset
Двоичные данные
XAMLUnityConnection/ProjectSettings/GraphicsSettings.asset
Двоичный файл не отображается.
Двоичный файл не отображается.
Двоичный файл не отображается.
Двоичные данные
XAMLUnityConnection/ProjectSettings/ProjectSettings.asset
Двоичные данные
XAMLUnityConnection/ProjectSettings/ProjectSettings.asset
Двоичный файл не отображается.
|
@ -0,0 +1,2 @@
|
|||
m_EditorVersion: 5.3.4p4
|
||||
m_StandardAssetsVersion: 0
|
Двоичный файл не отображается.
Двоичный файл не отображается.
|
@ -1,8 +1,7 @@
|
|||
XAMLUnityConnection is an example which shows how to connect between Unity and XAML.
|
||||
|
||||
To test the example, perform following steps:
|
||||
* Open XAMLUnityConnection with UnityEditor
|
||||
* Open 'test' scene
|
||||
* Build XAML C# project from UnityEditor on top of XAMLUnityConnection\Export directory
|
||||
* Open XAMLUnityConnection with Unity 5.3 or higher
|
||||
* Build to Windows Store Apps (SDK 8.1) on top of Export folder
|
||||
* Open XAMLUnityConnection\Export\XAMLConnection.sln and build it.
|
||||
* You should three sliders and a button drawn by Unity GUI. When you move the sliders you send data to Unity and the color of the cube changes. When you click on the button, you send data from Unity to XAML
|
Загрузка…
Ссылка в новой задаче