-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathUnityChanAnimationController.cs
83 lines (73 loc) · 2.31 KB
/
UnityChanAnimationController.cs
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
using UnityEngine;
using UnityEngine.UI;
using UnityLibrary.Server.Hubs;
using Grpc.Core;
using MagicOnion.Client;
[RequireComponent(typeof(Animator))]
public class UnityChanAnimationController : MonoBehaviour, IUnityChanControllerReceiver
{
private Animator _animator;
[SerializeField]
private Canvas _rootUI;
[SerializeField]
private Text _text;
private Channel _channel = null;
private IUnityChanController _controller = null;
private void Awake()
{
_animator = GetComponent<Animator>();
_channel = new Channel("localhost:12345", ChannelCredentials.Insecure);
_controller = StreamingHubClient.Connect<IUnityChanController, IUnityChanControllerReceiver>(this._channel, this);
}
private async void Start()
{
await _controller?.RegisterAsync();
}
private async void OnDestroy()
{
await _controller?.UnregisterAsync();
await _controller?.DisposeAsync();
_controller = null;
await _channel?.ShutdownAsync();
_channel = null;
}
#if UNITY_EDITOR
private void OnGUI()
{
GUI.Box(new Rect(Screen.width - 110, 10, 100, 90), "Change Motion");
if (GUI.Button(new Rect(Screen.width - 100, 40, 80, 20), "Standing"))
{
(this as IUnityChanControllerReceiver).OnSetAnimation(AnimeType.Standing);
}
if (GUI.Button(new Rect(Screen.width - 100, 70, 80, 20), "Walking"))
{
(this as IUnityChanControllerReceiver).OnSetAnimation(AnimeType.Walking);
}
}
#endif
void IUnityChanControllerReceiver.OnSetAnimation(AnimeType animeType)
{
switch (animeType)
{
case AnimeType.Standing: _animator.Play("Standing@loop"); break;
case AnimeType.Walking: _animator.Play("Walking@loop"); break;
case AnimeType.Running: _animator.Play("Running@loop"); break;
case AnimeType.Jump: _animator.Play("JumpToTop"); break;
}
}
void IUnityChanControllerReceiver.OnSetMessageText(string msg)
{
if (string.IsNullOrEmpty(msg))
{
_rootUI.gameObject.SetActive(false);
}
else
{
_text.text = msg;
_rootUI.gameObject.SetActive(true);
}
}
private void OnCallChangeFace(string str)
{
}
}