WordPress database error: [INSERT, UPDATE command denied to user '51213-2'@'10.10.20.149' for table 'wp_options']INSERT INTO `wp_options` (`option_name`, `option_value`, `autoload`) VALUES ('_transient_doing_cron', '1715265460.4458808898925781250000', 'yes') ON DUPLICATE KEY UPDATE `option_name` = VALUES(`option_name`), `option_value` = VALUES(`option_value`), `autoload` = VALUES(`autoload`)
We wil do this using DirectX and Unity.
As you can see in this video, the “context” of the leaved Windows is kept : the scroll position does not change.
Since a long time now, you can open a new Windows from a Windows Store app (UWP or Universal). For instance, the Mail app does this to let you edit an email in another dedicated window.
To perform this, you have to ask the SDK to create a new View (CoreApplicationView) which maps to a Window (CoreWindow) and an associated Dispatcher. This last point is interesting because you have to be very careful, when you share your ViewModels between windows, to be on the good Dispatcher when raising INotifyPropertyChanged event or doing some UI-related work.
Here is the code to create a Window :
// récupération de l'id courant pour usage ultérieur var appViewId = ApplicationView.GetForCurrentView().Id; //Create a new view \o/ CoreApplicationView newCoreAppView = CoreApplication.CreateNewView(); await newCoreAppView.Dispatcher.RunAsync( Windows.UI.Core.CoreDispatcherPriority.Low, () => { //Get the created Windows Window window = Window.Current; ApplicationView newAppView = ApplicationView.GetForCurrentView(); // create a new frame and navigate to the page var secondFrame = new Frame(); window.Content = secondFrame; secondFrame.Navigate(typeof(MainPage)); // activate the new Window window.Activate(); // make the new window standalone ApplicationViewSwitcher.TryShowAsStandaloneAsync(newAppView.Id, ViewSizePreference.UseMore, appViewId, ViewSizePreference.Default); });
By providing no argument to the CreateNewView method, we ask the XAML framework to create and manage a XAML UI.
We could also provide an argument of type IFrameworkViewSource to be able to have our own Window managed by our code. This is what DirectX does and it will let us create holograms !
By using the “HolographicDirectXApp” Visual Studio sample, I have all I need to create and display a 3D rotating cube by. The generated code creates an instance of IFrameworkView using DirectX. The sample use SharpDX, some C# classes and shaders that I can simply copy/Paste directly in a new XAML UWP project.
I then only have to use the previous snippet and ask it to use the DirectX AppView.
I have to carefully :
Of course, as all 3D holographic view, my start screen and the 2D View will disappear to let only the 3D objects in my space.
An Unity app being an UWP app the code to write will be very similar. We will only have to customize the generated Unity code to stay in a 2D World instead of going directly to the 3D exclusive View.
To be in the right configuration, I generate a XAML project instead of a Direct3D player in Unity. I then have this :
To have a “standard” Xaml project, I then perform these modifications :
The next steps are easy : I create a new Window, add a frame in it and navigate to the MainPage. I use exactly the same snippet as before and I only have to register an event handler to the activation of the created Window to be able to initialize Unity then. I also store the main view’s Id for further use.
private async Task CreateNewHoloWindowAsync() { var appViewId = MainAppViewId = ApplicationView.GetForCurrentView().Id; var _newCoreAppView = CoreApplication.CreateNewView(); await _newCoreAppView.Dispatcher .RunAsync(CoreDispatcherPriority.Low, async () => { var frame = new Frame(); Window.Current.Content = frame; frame.Navigate(typeof(MainPage)); var res = await ApplicationViewSwitcher.TryShowAsStandaloneAsync( ApplicationView.GetForCurrentView().Id, ViewSizePreference.Default, appViewId, ViewSizePreference.Default); _newCoreAppView.CoreWindow.Activated += WindowActivated; _newCoreAppView.CoreWindow.Activate(); }); } private void WindowActivated(object sender, WindowActivatedEventArgs e) { if (e.WindowActivationState == CoreWindowActivationState.CodeActivated || e.WindowActivationState == CoreWindowActivationState.PointerActivated) { AppCallbacks.Instance.SetInitialViewActive(); // Only need to mark initial activation once so unregister ourself CoreWindow coreWindowSender = sender as CoreWindow; coreWindowSender.Activated -= WindowActivated; } }
To go back to the 2D XAML view, you have to use the ApplicationViewSwitcher class and ask it to go switch back to the main Window.
I provide my Unity’s code an Action (GoBackToEarth.CloseThisHolographicView) it can call when needed.
// let's capture the dispatcher of the current view var dispatcher = Dispatcher; GoBackToEarth.CloseThisHolographicView = () => { // be sure to be on the Window's Dispatcher dispatcher.RunIdleAsync(async _ => { // go back to the main Window await ApplicationViewSwitcher.SwitchAsync(StartupPage.MainAppViewId); // we close the 3D holographic Window Window.Current.Close(); }); };
Happy coding !
]]>