Skip to content

Commit 16e973f

Browse files
committed
修改userinfo和websocket
1 parent 7bb23c3 commit 16e973f

File tree

3 files changed

+78
-29
lines changed

3 files changed

+78
-29
lines changed

Demo/API_V2/Assets/API/Network/UnityWebSocket/UnityWebSocket.cs

Lines changed: 67 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace UnityWebSocket.Demo
44
{
5-
public class UnityWebSocket: MonoBehaviour
5+
public class UnityWebSocket : MonoBehaviour
66
{
77
public string address = "ws://127.0.0.1:8080";
88
public string sendText = "Hello World!";
@@ -23,33 +23,44 @@ private void OnGUI()
2323
var scale = UnityEngine.Screen.width / 800f;
2424
GUI.matrix = Matrix4x4.TRS(new Vector3(0, 0, 0), Quaternion.identity, new Vector3(scale, scale, 1));
2525
var width = GUILayout.Width(UnityEngine.Screen.width / scale - 10);
26-
26+
var w = UnityEngine.Screen.width / scale - 10;
2727
WebSocketState state = socket == null ? WebSocketState.Closed : socket.ReadyState;
2828

29+
GUIStyle style = new GUIStyle(GUI.skin.label);
30+
style.fontSize = 26;
31+
32+
GUILayout.BeginHorizontal();
33+
GUILayout.Label("", GUILayout.Width(UnityEngine.Screen.width / scale - 100), GUILayout.Height(250));
34+
GUILayout.EndHorizontal();
35+
2936
GUILayout.BeginHorizontal();
30-
GUILayout.Label("SDK Version: " + Settings.VERSION, GUILayout.Width(UnityEngine.Screen.width / scale - 100),
31-
GUILayout.Height(250));
37+
GUILayout.Label("SDK Version: " + Settings.VERSION, style, GUILayout.Width(UnityEngine.Screen.width / scale - 300));
3238
GUI.color = green;
33-
GUILayout.Label($"FPS: {fps:F2}", GUILayout.Width(80));
39+
GUILayout.Label($"FPS: {fps:F2}", style, GUILayout.Width(300));
3440
GUI.color = Color.white;
3541
GUILayout.EndHorizontal();
3642

3743
GUILayout.BeginHorizontal();
38-
GUILayout.Label("State: ", GUILayout.Width(36));
44+
GUILayout.Label("State: ", style, GUILayout.Width(70));
3945
GUI.color = WebSocketState.Closed == state ? red : WebSocketState.Open == state ? green : wait;
40-
GUILayout.Label($"{state}", GUILayout.Width(120));
46+
GUILayout.Label($"{state}", style, GUILayout.Width(300));
4147
GUI.color = Color.white;
4248
GUILayout.EndHorizontal();
4349

4450
GUI.enabled = state == WebSocketState.Closed;
45-
GUILayout.Label("Address: ", width);
46-
address = GUILayout.TextField(address, width);
51+
GUILayout.Label("Address: ", style, width);
52+
style.normal.background = MakeTex(2, 2, Color.grey);
53+
address = GUILayout.TextField(address, style, width, GUILayout.Height(50));
4754

4855
GUILayout.BeginHorizontal();
56+
style.alignment = TextAnchor.MiddleCenter;
57+
style.normal.background = MakeTex(2, 2, Color.grey);
58+
4959
GUI.enabled = state == WebSocketState.Closed;
50-
if (GUILayout.Button(state == WebSocketState.Connecting ? "Connecting..." : "Connect"))
60+
if (GUILayout.Button(state == WebSocketState.Connecting ? "Connecting..." : "Connect", style, GUILayout.Width(w / 2), GUILayout.Height(45)))
5161
{
52-
if (WebSocketState.Connecting != 0) {
62+
if (WebSocketState.Connecting != 0)
63+
{
5364
AddLog(string.Format("something is wrong"));
5465
}
5566
socket = new WebSocket(address);
@@ -62,31 +73,43 @@ private void OnGUI()
6273
}
6374

6475
GUI.enabled = state == WebSocketState.Open;
65-
if (GUILayout.Button(state == WebSocketState.Closing ? "Closing..." : "Close"))
76+
if (GUILayout.Button(state == WebSocketState.Closing ? "Closing..." : "Close", style, GUILayout.Width(w / 2), GUILayout.Height(45)))
6677
{
6778
AddLog(string.Format("Closing..."));
6879
socket.CloseAsync();
6980
}
7081
GUILayout.EndHorizontal();
7182

72-
GUILayout.Label("Text: ");
73-
sendText = GUILayout.TextArea(sendText, GUILayout.MinHeight(50), width);
83+
GUILayout.BeginHorizontal();
84+
GUILayout.Label("", GUILayout.Width(UnityEngine.Screen.width), GUILayout.Height(20));
85+
GUILayout.EndHorizontal();
86+
87+
style.alignment = TextAnchor.UpperLeft;
88+
style.normal.background = null;
89+
GUI.color = Color.white;
90+
GUILayout.Label("Text: ", style);
91+
style.normal.background = MakeTex(2, 2, Color.grey);
92+
sendText = GUILayout.TextArea(sendText, style, GUILayout.MinHeight(100), width);
7493

7594
GUILayout.BeginHorizontal();
76-
if (GUILayout.Button("Send") && !string.IsNullOrEmpty(sendText))
95+
style.alignment = TextAnchor.MiddleCenter;
96+
if (GUILayout.Button("Send", style, GUILayout.Width(w / 2), GUILayout.Height(45)) && !string.IsNullOrEmpty(sendText))
7797
{
7898
socket.SendAsync(sendText);
7999
AddLog(string.Format("Send: {0}", sendText));
80100
sendCount += 1;
81101
}
82-
if (GUILayout.Button("Send Bytes") && !string.IsNullOrEmpty(sendText))
102+
if (GUILayout.Button("Send Bytes", style, GUILayout.Width(w / 2), GUILayout.Height(45)) && !string.IsNullOrEmpty(sendText))
83103
{
84104
var bytes = System.Text.Encoding.UTF8.GetBytes(sendText);
85105
socket.SendAsync(bytes);
86106
AddLog(string.Format("Send Bytes ({1}): {0}", sendText, bytes.Length));
87107
sendCount += 1;
88108
}
89-
if (GUILayout.Button("Send x100") && !string.IsNullOrEmpty(sendText))
109+
GUILayout.EndHorizontal();
110+
111+
GUILayout.BeginHorizontal();
112+
if (GUILayout.Button("Send x100", style, GUILayout.Width(w / 2), GUILayout.Height(45)) && !string.IsNullOrEmpty(sendText))
90113
{
91114
for (int i = 0; i < 100; i++)
92115
{
@@ -96,7 +119,7 @@ private void OnGUI()
96119
sendCount += 1;
97120
}
98121
}
99-
if (GUILayout.Button("Send Bytes x100") && !string.IsNullOrEmpty(sendText))
122+
if (GUILayout.Button("Send Bytes x100", style, GUILayout.Width(w / 2), GUILayout.Height(45)) && !string.IsNullOrEmpty(sendText))
100123
{
101124
for (int i = 0; i < 100; i++)
102125
{
@@ -111,21 +134,25 @@ private void OnGUI()
111134
GUILayout.EndHorizontal();
112135

113136
GUI.enabled = true;
114-
GUILayout.BeginHorizontal();
115-
logMessage = GUILayout.Toggle(logMessage, "Log Message");
116-
GUILayout.Label(string.Format("Send Count: {0}", sendCount));
117-
GUILayout.Label(string.Format("Receive Count: {0}", receiveCount));
118-
GUILayout.EndHorizontal();
137+
// GUILayout.BeginHorizontal();
138+
// style.normal.background = null;
139+
// logMessage = GUILayout.Toggle(logMessage, "Log Message", style);
140+
// GUILayout.Label(string.Format("Send Count: {0}", sendCount), style);
141+
// GUILayout.Label(string.Format("Receive Count: {0}", receiveCount), style);
142+
// GUILayout.EndHorizontal();
143+
144+
style.normal.background = MakeTex(2, 2, Color.grey);
119145

120-
if (GUILayout.Button("Clear"))
146+
if (GUILayout.Button("Clear", style, GUILayout.Width(w), GUILayout.Height(45)))
121147
{
122148
log = "";
123149
receiveCount = 0;
124150
sendCount = 0;
125151
}
126-
152+
style.alignment = TextAnchor.UpperLeft;
127153
scrollPos = GUILayout.BeginScrollView(scrollPos, GUILayout.MaxHeight(UnityEngine.Screen.height / scale - 270), width);
128-
GUILayout.Label(log);
154+
style.normal.background = null;
155+
GUILayout.Label(log, style);
129156
GUILayout.EndScrollView();
130157
}
131158

@@ -141,6 +168,20 @@ private void AddLog(string str)
141168
scrollPos.y = int.MaxValue;
142169
}
143170

171+
// 创建一个纹理
172+
private Texture2D MakeTex(int width, int height, Color col)
173+
{
174+
Color[] pix = new Color[width * height];
175+
for (int i = 0; i < pix.Length; i++)
176+
pix[i] = col;
177+
178+
Texture2D result = new Texture2D(width, height);
179+
result.SetPixels(pix);
180+
result.Apply();
181+
182+
return result;
183+
}
184+
144185
private void Socket_OnOpen(object sender, OpenEventArgs e)
145186
{
146187
AddLog(string.Format("Connected: {0}", address));

Demo/API_V2/Assets/API/OpenInterface/UserInfo/UserInfo.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,15 @@ IEnumerator SetTimeout(float delay)
3131
Vector2 position = GameManager.Instance.detailsController.GetInitialButtonPosition();
3232
Debug.Log(position);
3333
Debug.Log(size);
34-
_button = WX.CreateUserInfoButton(Math.Abs((int)position.x), Math.Abs((int)position.y), (int)size.x, (int)size.y, "en", true);
34+
var systemInfo = WX.GetSystemInfoSync();
35+
var canvasWidth = (int)(systemInfo.screenWidth * systemInfo.pixelRatio);
36+
var canvasHeight = (int)(systemInfo.screenHeight * systemInfo.pixelRatio);
37+
_button = WX.CreateUserInfoButton(Math.Abs((int)position.x),
38+
Math.Abs((int)position.y),
39+
(int)(size.x * canvasWidth / 1080f),
40+
(int)(size.y * canvasWidth / 1080f),
41+
"en",
42+
true);
3543
_button.OnTap(_onTap);
3644
}
3745

Demo/API_V2/Assets/Scenes/MainScene.unity

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14266,7 +14266,7 @@ MonoBehaviour:
1426614266
m_ScaleFactor: 1
1426714267
m_ReferenceResolution: {x: 1080, y: 1920}
1426814268
m_ScreenMatchMode: 0
14269-
m_MatchWidthOrHeight: 0.5
14269+
m_MatchWidthOrHeight: 0
1427014270
m_PhysicalUnit: 3
1427114271
m_FallbackScreenDPI: 96
1427214272
m_DefaultSpriteDPI: 96
@@ -17637,7 +17637,7 @@ MonoBehaviour:
1763717637
m_ScaleFactor: 1
1763817638
m_ReferenceResolution: {x: 1080, y: 1920}
1763917639
m_ScreenMatchMode: 0
17640-
m_MatchWidthOrHeight: 0.5
17640+
m_MatchWidthOrHeight: 0
1764117641
m_PhysicalUnit: 3
1764217642
m_FallbackScreenDPI: 96
1764317643
m_DefaultSpriteDPI: 96

0 commit comments

Comments
 (0)