提交Cue案例

This commit is contained in:
DESKTOP-5RP3AKU\Jisol
2024-10-26 02:35:38 +08:00
parent 6cf78b53bb
commit 1ad20b67da
72 changed files with 24536 additions and 1264 deletions

View File

@@ -1,6 +1,9 @@
using System;
using System.Collections.Generic;
using System.IO;
using HotScripts.JNGame.Runtime.Sync.System.Logic;
using JNGame.Sync.Frame;
using UnityEngine;
namespace JNGame.Sync.System.Data
{
@@ -12,10 +15,6 @@ namespace JNGame.Sync.System.Data
public abstract class SEventDataSystem : SDataSystemBase
{
/// <summary>
/// 服务器事件
/// </summary>
private Queue<SEvent> ServerEvents = new();
/// <summary>
/// 客户端事件
/// </summary>
@@ -39,35 +38,60 @@ namespace JNGame.Sync.System.Data
}
public override void OnSyncUpdate(int dt)
{
while (WaitUBytes.Count > 0)
{
OnUByteUpdate(WaitUBytes.Dequeue());
}
if (isServer)
JNEventSystem Event = GetSystem<JNEventSystem>();
if (Event is null)
{
if (ServerEvents.Count <= 0) return;
using (MemoryStream ms = new MemoryStream())
Debug.LogWarning("请保证逻辑层有 JNEventSystem 系统");
return;
}
//如果是帧同步系统则直接保存
if (Sync is JNSyncFrameService)
{
while (Event.ViewEvent.Count > 0)
{
using (BinaryWriter writer = new BinaryWriter(ms))
{
int count = ServerEvents.Count;
//写入数量
writer.Write(count);
for (int i = count - 1; i >= 0; i--)
{
var data = ServerEvents.Dequeue().ToByteArray();
//写入数据大小
writer.Write(data.Length);
//写入数据
writer.Write(data);
}
}
// 发送完整的字节数组
OnSendUBytes(ms.ToArray());
ClientEvents.Enqueue(Event.ViewEvent.Dequeue());
}
}
else
{
while (WaitUBytes.Count > 0)
{
OnUByteUpdate(WaitUBytes.Dequeue());
}
if (isServer)
{
if (Event.ViewEvent.Count <= 0) return;
using (MemoryStream ms = new MemoryStream())
{
using (BinaryWriter writer = new BinaryWriter(ms))
{
int count = Event.ViewEvent.Count;
//写入数量
writer.Write(count);
for (int i = count - 1; i >= 0; i--)
{
var data = Event.ViewEvent.Dequeue().ToByteArray();
//写入数据大小
writer.Write(data.Length);
//写入数据
writer.Write(data);
}
}
// 发送完整的字节数组
OnSendUBytes(ms.ToArray());
}
}
}
//触发事件
while (ClientEvents.Count > 0)
{
ReceiveEvent(ClientEvents.Dequeue());
}
}
@@ -77,6 +101,11 @@ namespace JNGame.Sync.System.Data
/// <param name="bytes"></param>
/// <returns>是否清空UBytes</returns>
public abstract void OnSendUBytes(byte[] bytes);
/// <summary>
/// 接收事件 实现
/// </summary>
protected abstract void ReceiveEvent(SEvent @event);
/// <summary>
@@ -110,19 +139,6 @@ namespace JNGame.Sync.System.Data
}
}
public void AddEvent(int type,byte[] data)
{
//只有服务器才可以添加事件
if (isServer)
{
ServerEvents.Enqueue(new SEvent()
{
Type = type,
Data = data,
});
}
}
public class SEvent
{
/// <summary>

View File

@@ -1,4 +1,5 @@
using System.Collections.Generic;
using JNGame.Sync.Frame;
using UnityEngine;
namespace JNGame.Sync.System.Data
@@ -90,6 +91,14 @@ namespace JNGame.Sync.System.Data
public override void OnSyncUpdate(int dt)
{
//如果是帧同步系统则直接保存
if (Sync is JNSyncFrameService)
{
Data = GetLatest();
return;
}
while (WaitUBytes.Count > 0)
{

View File

@@ -0,0 +1,29 @@
using System.Collections.Generic;
using JNGame.Sync.System;
using JNGame.Sync.System.Data;
namespace HotScripts.JNGame.Runtime.Sync.System.Logic
{
public class JNEventSystem : SLogicSystem
{
/// <summary>
/// 渲染层 专用事件
/// </summary>
public Queue<SEventDataSystem.SEvent> ViewEvent = new();
/// <summary>
/// 添加数据层事件(用于通知渲染层)
/// </summary>
public void AddViewEvent(int type,byte[] data)
{
ViewEvent.Enqueue(new SEventDataSystem.SEvent()
{
Type = type,
Data = data,
});
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 1116c94f10954a2084f93bc6e8a61ece
timeCreated: 1729876016