private async Task Quit(bool close) { isCalledQuit = true; if (host != null) { host.Destroy(); host = null; } if (hub != null) { await hub.Dispose(); hub = null; } isCleanuped = true; if (close) { await Server.Program.Stop(); this.Close(); } }
private async void start_Click(object sender, RoutedEventArgs e) { if (!System.ComponentModel.DesignerProperties.GetIsInDesignMode(this)) { host = new UnityHwndHost(@"UnityApp\UnityApp.exe", ""); grid.Children.Add(host); } hub = new CommunicationHub(); hub.OnMovePositionCallback = (position, rotation, name) => { if (name != "Camera") { return; } textPosition.Text = $"{name}\r\n" + $"Position\r\n" + $" x:{position.x}\r\n" + $" y:{position.y}\r\n" + $" z:{position.z}\r\n" + $"Rotation\r\n" + $" x:{rotation.x}\r\n" + $" y:{rotation.y}\r\n" + $" z:{rotation.z}\r\n" + $" w:{rotation.w}"; }; hub.OnSendMessageCallback = (name, msg) => textMessage.Text += $"{name} : {msg}\r\n"; await hub.JoinAsync("MainWindow"); await hub.SendMessageAsync("Hello another world."); start.IsEnabled = false; stop.IsEnabled = true; }