Compare commits

..

No commits in common. "main" and "0.0.3" have entirely different histories.
main ... 0.0.3

12 changed files with 23 additions and 94 deletions

View File

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

View File

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

View File

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

View File

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

View File

@ -30,7 +30,7 @@ namespace DofLibrary
/// <param name="uid">玩家ID</param> /// <param name="uid">玩家ID</param>
/// <param name="nickName">玩家昵称</param> /// <param name="nickName">玩家昵称</param>
/// <param name="country">玩家国家</param> /// <param name="country">玩家国家</param>
void PlayerEnter(string roomId, string uid, string nickName, string country, string appId, string token); void PlayerEnter(string roomId, string uid, string nickName, string country);
/// <summary> /// <summary>
/// 发送 LevelPrepared 关卡准备完毕 消息 /// 发送 LevelPrepared 关卡准备完毕 消息
@ -43,7 +43,7 @@ namespace DofLibrary
/// </summary> /// </summary>
/// <param name="levelId">当前关卡ID</param> /// <param name="levelId">当前关卡ID</param>
/// <param name="pointId">点位编号</param> /// <param name="pointId">点位编号</param>
void PointFound(string levelId, int pointId, float combo); void PointFound(string levelId, int pointId);
/// <summary> /// <summary>
/// 发送 LevelEnd 关卡结束 消息 /// 发送 LevelEnd 关卡结束 消息
@ -54,16 +54,6 @@ namespace DofLibrary
/// <summary> /// <summary>
/// 发送 AllLevelEnd 所有关卡结束 消息 /// 发送 AllLevelEnd 所有关卡结束 消息
/// </summary> /// </summary>
void AllLevelEnd(float timeSpent); void AllLevelEnd();
/// <summary>
/// 发送 玩家中途离开房间 消息
/// </summary>
void PlayerLeave();
/// <summary>
/// 发送心跳包
/// </summary>
void Heartbeat(long timestamp);
} }
} }

View File

@ -3,17 +3,17 @@ using System.Collections.Generic;
using System.Threading; using System.Threading;
using UnityEngine; using UnityEngine;
namespace DofLibrary namespace Guru
{ {
// 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. // 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 LoomUtil : MonoBehaviour public class Loom : MonoBehaviour
{ {
public static int maxThreads = 10; public static int maxThreads = 10;
private static int numThreads; private static int numThreads;
private static LoomUtil _instance; private static Loom _instance;
public static LoomUtil Instance public static Loom Instance
{ {
get get
{ {
@ -39,7 +39,7 @@ namespace DofLibrary
initialized = true; initialized = true;
var g = new GameObject("Loom"); var g = new GameObject("Loom");
DontDestroyOnLoad(g); DontDestroyOnLoad(g);
_instance = g.AddComponent<LoomUtil>(); _instance = g.AddComponent<Loom>();
} }
} }

View File

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

View File

@ -137,15 +137,6 @@ namespace Dof
public bool ShouldSerializeGameFinish() => __pbn__actual.Is(5); public bool ShouldSerializeGameFinish() => __pbn__actual.Is(5);
public void ResetGameFinish() => global::ProtoBuf.DiscriminatedUnionObject.Reset(ref __pbn__actual, 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()] [global::ProtoBuf.ProtoContract()]
@ -200,9 +191,6 @@ namespace Dof
[global::System.ComponentModel.DefaultValue("")] [global::System.ComponentModel.DefaultValue("")]
public string IosGeneration { get; set; } = ""; public string IosGeneration { get; set; } = "";
[global::ProtoBuf.ProtoMember(4, Name = @"diff_count")]
public int DiffCount { get; set; }
} }
[global::ProtoBuf.ProtoContract()] [global::ProtoBuf.ProtoContract()]
@ -328,12 +316,6 @@ namespace Dof
[global::ProtoBuf.ProtoMember(2, Name = @"score")] [global::ProtoBuf.ProtoMember(2, Name = @"score")]
public int Score { get; set; } 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()] [global::ProtoBuf.ProtoContract()]

View File

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

View File

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

View File

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