-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExample.cs
More file actions
91 lines (78 loc) · 1.82 KB
/
Copy pathExample.cs
File metadata and controls
91 lines (78 loc) · 1.82 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
89
90
91
using UnityEngine;
using SoopChatNet;
using SoopChatNet.Data;
using System;
#if UNITY_EDITOR
using UnityEditor;
#endif
public class Example : MonoBehaviour
{
public string bjid = "ecvhao";
SoopChat soopChat;
private void OnDestroy()
{
soopChat?.Dispose();
}
public void StartChat()
{
if (soopChat != null)
soopChat.Dispose();
soopChat = new SoopChat(bjid);
soopChat.OnMessageReceived += OnChat;
soopChat.OnBalloonReceived += OnBallon;
soopChat.OnSocketOpened += OnOpen;
soopChat.OnSocketError += OnError;
soopChat.OnSocketClosed += (message) => Debug.Log(message);
_ = soopChat.OpenAsync();
}
public void StopChat()
{
_ = soopChat.CloseAsync();
}
void Update()
{
if(soopChat != null && soopChat.IsConnected)
soopChat.Update();
}
void OnOpen(string message)
{
Debug.Log(message);
}
void OnError(string message)
{
Debug.Log(message);
}
void OnChat(Chat chat)
{
Debug.Log($"{chat.nickname}({chat.sender}) : {chat.message}");
}
void OnBallon(Ballon ballon)
{
Debug.Log($"{ballon.nickname}({ballon.sender}) : 별풍선 {ballon.amount}개 / {ballon.message}");
}
#if UNITY_EDITOR
void OnEditorUpdate()
{
if(soopChat != null && soopChat.IsConnected)
soopChat.Update();
}
#endif
}
#if UNITY_EDITOR
[CustomEditor(typeof(Example))]
public class ExampleButton : Editor
{
public override void OnInspectorGUI() {
base.OnInspectorGUI();
Example script = (Example)target;
if (GUILayout.Button("Start"))
{
script.StartChat();
}
if (GUILayout.Button("Stop"))
{
script.StopChat();
}
}
}
#endif