-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathForm1.cs
More file actions
88 lines (75 loc) · 2.74 KB
/
Copy pathForm1.cs
File metadata and controls
88 lines (75 loc) · 2.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
using System;
using System.ComponentModel;
using System.Windows.Forms;
using Grpc.Core;
using MagicOnion.Client;
using UnityLibrary.Server.Hubs;
using UnityLoader;
namespace WinFormsHost1
{
public partial class Form1 : Form, IUnityChanControllerReceiver
{
private UnityLoader.UnityLibrary _unityLibrary = null;
private AnimeType _animeType = AnimeType.Standing;
private Channel _channel = null;
private IUnityChanController _controller = null;
public Form1()
{
InitializeComponent();
_channel = new Channel("localhost:12345", ChannelCredentials.Insecure);
_controller = StreamingHubClient.Connect<IUnityChanController, IUnityChanControllerReceiver>(this._channel, this);
}
protected override async void OnLoad(EventArgs e)
{
base.OnLoad(e);
await _controller?.RegisterAsync();
_unityLibrary = new UnityProcess(@"UnityLibrary\UnityLibrary.exe", _splitContainer.Panel2.Handle);
//_unityLibrary = new UnityDLL(@"UnityPlayer.dll", _splitContainer.Panel2.Handle);
_splitContainer.Panel2.SizeChanged += (s, e) => _unityLibrary?.ResizeUnityWindow(_splitContainer.Panel2.Width, _splitContainer.Panel2.Height);
}
protected override void OnClosing(CancelEventArgs e)
{
base.OnClosing(e);
_unityLibrary?.CloseUnityWindow();
}
protected override async void OnClosed(EventArgs e)
{
base.OnClosed(e);
(_unityLibrary as IDisposable)?.Dispose();
_unityLibrary = null;
await _controller?.UnregisterAsync();
await _controller?.DisposeAsync();
_controller = null;
await _channel?.ShutdownAsync();
}
protected override void OnActivated(EventArgs e)
{
base.OnActivated(e);
_unityLibrary?.ActivateUnityWindow();
}
protected override void OnDeactivate(EventArgs e)
{
base.OnDeactivate(e);
_unityLibrary?.DeactivateUnityWindow();
}
private void BtnAnimation_OnClick(object sender, EventArgs e)
{
_animeType++;
if (_animeType > AnimeType.Running)
{
_animeType = AnimeType.Standing;
}
_controller?.SetAnimationAsync(_animeType);
}
private void TextBox_OnTextChanged(object sender, EventArgs e)
{
_controller?.SetMessageTextAsync(_textBox.Text);
}
void IUnityChanControllerReceiver.OnSetAnimation(AnimeType animeType)
{
}
void IUnityChanControllerReceiver.OnSetMessageText(string msg)
{
}
}
}