Compare commits

...

20 Commits
0.0.4 ... main

Author SHA1 Message Date
xiaohang 7f3921b163 update: set version to 0.1.2 2024-04-26 11:04:39 +08:00
xiaohang a885a394c0 namespace名称修改;Loom类名修改防止和其他工程冲突 2024-04-26 11:03:04 +08:00
xiaohang 40d8710f37 update: set version to 0.1.1 2023-11-08 11:20:04 +08:00
xiaohang e4d89d821a 更新proto和c# 2023-11-08 11:19:02 +08:00
xiaohang 82a635ffa2 Revert "add assignment test matchmake"
This reverts commit da8167162a.
2023-10-20 17:15:28 +08:00
xiaohang da8167162a add assignment test matchmake 2023-10-20 17:02:57 +08:00
xiaohang cd0c8ca54d update: set version to 0.1.0 2023-10-18 10:18:48 +08:00
xiaohang cceee2b05a 注释log 2023-10-18 10:17:44 +08:00
xiaohang a6cd2af2d0 update: set version to 0.0.9 2023-09-21 10:40:15 +08:00
xiaohang 8aaf25d998 接口脚本添加PlayerLeave接口 2023-09-21 10:39:51 +08:00
xiaohang 76c8a3dc9a update: set version to 0.0.8 2023-09-21 10:35:22 +08:00
xiaohang 33dd76ac5d 添加玩家离开消息发送 2023-09-21 10:34:54 +08:00
xiaohang fbbe434809 update: set version to 0.0.7 2023-09-18 15:55:37 +08:00
xiaohang 5f06a17ee3 添加服务器心跳包消息处理 2023-09-18 15:55:06 +08:00
xiaohang f217a3ad6c fix compile error 2023-09-18 15:10:43 +08:00
xiaohang 9a791a0402 update: set version to 0.0.6 2023-09-18 15:08:47 +08:00
xiaohang 099cccd2fb 添加超时时间参数设置接口 2023-09-18 15:08:25 +08:00
xiaohang 3b195db157 update: set version to 0.0.5 2023-09-18 11:03:01 +08:00
xiaohang d5ca66eda0 添加连接断开事件接口 2023-09-18 11:02:00 +08:00
xiaohang 2453fd8879 fix compile error 2023-09-17 21:47:30 +08:00
12 changed files with 87 additions and 21 deletions

View File

@ -1,4 +1,4 @@
Version=0.0.4
Version=0.1.2
Branch=main

View File

@ -2,7 +2,7 @@
using System.Collections.Generic;
using UnityEngine;
namespace Guru
namespace DofLibrary
{
public class GameEventMgr

View File

@ -13,11 +13,13 @@ namespace DofLibrary
public class GameKcpClient : KcpListener
{
public Action OnConnected;
public Action OnDisConnected;
private KcpClient _kcpClient;
public IMessageSender sender { get; private set; } = new MessageSender();
private IMessageReceiver _receiver;
private bool _running;
private int? _timeoutMillis;
public GameKcpClient(DotNetty.Unity.Level level = DotNetty.Unity.Level.ALL)
{
@ -53,7 +55,8 @@ namespace DofLibrary
channelConfig.Crc32Check = false;
channelConfig.UseConvChannel = true;
//channelConfig.Conv = UnityEngine.Random.Range(1, int.MaxValue);
channelConfig.TimeoutMillis = 10000;
if(_timeoutMillis.HasValue)
channelConfig.TimeoutMillis = _timeoutMillis.Value;
_kcpClient = new KcpClient();
_kcpClient.init(channelConfig);
@ -67,7 +70,7 @@ namespace DofLibrary
private void ProcessMessage(ServerMessage serverMessage)
{
Debug.Log("[ProcessMessage]");
//Debug.Log("[ProcessMessage]");
if (serverMessage.PlayerEntered != null)
{
//Debug.Log("[ProcessMessage]PlayerEntered");
@ -95,6 +98,11 @@ namespace DofLibrary
//Debug.Log("[ProcessMessage]GameFinish");
_receiver.OnGameFinish(serverMessage.GameFinish);
}
else if (serverMessage.Heartbeat != null)
{
//Debug.Log("[ProcessMessage]Heartbeat");
_receiver.OnHeartbeat(serverMessage.Heartbeat);
}
}
/// <summary>
@ -108,7 +116,7 @@ namespace DofLibrary
if (OnConnected != null)
{
Loom.QueueOnMainThread(() =>
LoomUtil.QueueOnMainThread(() =>
{
OnConnected.Invoke();
});
@ -131,7 +139,7 @@ namespace DofLibrary
if (msg is ServerMessage server_msg)
{
Loom.QueueOnMainThread(() =>
LoomUtil.QueueOnMainThread(() =>
{
ProcessMessage(server_msg);
});
@ -159,8 +167,20 @@ namespace DofLibrary
public void handleClose(Ukcp ukcp)
{
Debug.Log("[GameKcpClient]: Connection closed");
if (OnDisConnected != null)
{
LoomUtil.QueueOnMainThread(() =>
{
OnDisConnected.Invoke();
});
}
}
public void setTimeoutMillis(int timeoutMillis)
{
_timeoutMillis = timeoutMillis;
}
/// <summary>
/// 关闭 Client应该在游戏结束时调用
/// </summary>

View File

@ -41,5 +41,10 @@ namespace DofLibrary
/// </summary>
/// <param name="gameFinish">两个玩家的得分</param>
void OnGameFinish(GameFinish gameFinish);
/// <summary>
/// 心跳包
/// </summary>
void OnHeartbeat(Heartbeat heartbeat);
}
}

View File

@ -55,10 +55,15 @@ namespace DofLibrary
/// 发送 AllLevelEnd 所有关卡结束 消息
/// </summary>
void AllLevelEnd(float timeSpent);
/// <summary>
/// 发送 玩家中途离开房间 消息
/// </summary>
void PlayerLeave();
/// <summary>
/// 发送心跳包
/// </summary>
void Heartbeat(long timestamp)
void Heartbeat(long timestamp);
}
}

View File

@ -3,17 +3,17 @@ using System.Collections.Generic;
using System.Threading;
using UnityEngine;
namespace Guru
namespace DofLibrary
{
// Loom lets you easily run code on another thread and have that other thread run code on the main game thread when it needs to.
public class Loom : MonoBehaviour
public class LoomUtil : MonoBehaviour
{
public static int maxThreads = 10;
private static int numThreads;
private static Loom _instance;
private static LoomUtil _instance;
public static Loom Instance
public static LoomUtil Instance
{
get
{
@ -39,7 +39,7 @@ namespace Guru
initialized = true;
var g = new GameObject("Loom");
DontDestroyOnLoad(g);
_instance = g.AddComponent<Loom>();
_instance = g.AddComponent<LoomUtil>();
}
}

View File

@ -49,7 +49,7 @@ namespace DofLibrary
}
};
Send(playerEnter);
Debug.Log("PlayerEnter message sent");
//Debug.Log("PlayerEnter message sent");
}
public void LevelPrepared(string levelId)
@ -63,7 +63,7 @@ namespace DofLibrary
}
};
Send(message);
Debug.Log("LevelPrepared message sent");
//Debug.Log("LevelPrepared message sent");
}
public void PointFound(string levelId, int pointId, float combo)
@ -79,7 +79,7 @@ namespace DofLibrary
}
};
Send(message);
Debug.Log("PointFound message sent");
//Debug.Log("PointFound message sent");
}
public void LevelEnd(string levelId)
@ -93,7 +93,7 @@ namespace DofLibrary
}
};
Send(message);
Debug.Log("LevelEnd message sent");
//Debug.Log("LevelEnd message sent");
}
public void AllLevelEnd(float timeSpent)
@ -107,9 +107,22 @@ namespace DofLibrary
}
};
Send(message);
Debug.Log("AllLevelEnd message sent");
//Debug.Log("AllLevelEnd message sent");
}
public void PlayerLeave()
{
var message = new ClientMessage
{
PlayerLeave = new PlayerLeave
{
Cid = _cid
}
};
Send(message);
//Debug.Log("PlayerLeave message sent");
}
public void Heartbeat(long timestamp)
{
var message = new ClientMessage
@ -120,7 +133,7 @@ namespace DofLibrary
}
};
Send(message);
Debug.Log("Heartbeat message sent");
//Debug.Log("Heartbeat message sent");
}
private void Send(ClientMessage message)

View File

@ -137,6 +137,15 @@ namespace Dof
public bool ShouldSerializeGameFinish() => __pbn__actual.Is(5);
public void ResetGameFinish() => global::ProtoBuf.DiscriminatedUnionObject.Reset(ref __pbn__actual, 5);
[global::ProtoBuf.ProtoMember(21, Name = @"heartbeat")]
public Heartbeat Heartbeat
{
get => __pbn__actual.Is(21) ? ((Heartbeat)__pbn__actual.Object) : default;
set => __pbn__actual = new global::ProtoBuf.DiscriminatedUnionObject(21, value);
}
public bool ShouldSerializeHeartbeat() => __pbn__actual.Is(21);
public void ResetHeartbeat() => global::ProtoBuf.DiscriminatedUnionObject.Reset(ref __pbn__actual, 21);
}
[global::ProtoBuf.ProtoContract()]
@ -191,6 +200,9 @@ namespace Dof
[global::System.ComponentModel.DefaultValue("")]
public string IosGeneration { get; set; } = "";
[global::ProtoBuf.ProtoMember(4, Name = @"diff_count")]
public int DiffCount { get; set; }
}
[global::ProtoBuf.ProtoContract()]
@ -316,6 +328,12 @@ namespace Dof
[global::ProtoBuf.ProtoMember(2, Name = @"score")]
public int Score { get; set; }
[global::ProtoBuf.ProtoMember(3, Name = @"rank")]
public int Rank { get; set; }
[global::ProtoBuf.ProtoMember(4, Name = @"award")]
public int Award { get; set; }
}
[global::ProtoBuf.ProtoContract()]

View File

@ -2,7 +2,7 @@
using System.IO;
using ProtoBuf.Meta;
namespace Guru
namespace DofLibrary
{
public interface ISupportInitialize
{

View File

@ -24,6 +24,8 @@ message ServerMessage {
LevelStart level_start = 3;
PointFound point_found = 4;
GameFinish game_finish = 5;
Heartbeat heartbeat = 21;
}
}
@ -41,6 +43,7 @@ message LevelResource {
string level_id = 1;
string android_generation = 2;
string ios_generation = 3;
int32 diff_count = 4;
}
// PlayerEntered PlayerEnter
@ -82,6 +85,8 @@ message AllLevelEnd {
message GameScore {
string uid = 1;
int32 score = 2;
int32 rank = 3;
int32 award = 4;
}
message GameFinish {

View File

@ -1,7 +1,7 @@
{
"name": "com.guru.unity.gurudoflib",
"displayName": "GuruDofLib",
"version": "0.0.4",
"version": "0.1.2",
"description": "\u57fa\u4e8eGuru kcp\u5e93\u5b9e\u73b0\u7684\u5ba2\u6237\u7aef\u63a5\u53e3\u5c01\u88c5",
"keywords": [
"unity",