提交示例代码
This commit is contained in:
BIN
聊天系统课程代码/Client/Unity/Assets/.DS_Store
vendored
Normal file
BIN
聊天系统课程代码/Client/Unity/Assets/.DS_Store
vendored
Normal file
Binary file not shown.
8
聊天系统课程代码/Client/Unity/Assets/Scenes.meta
Normal file
8
聊天系统课程代码/Client/Unity/Assets/Scenes.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 73da031d8461248aeab395b3a1f17c41
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
3067
聊天系统课程代码/Client/Unity/Assets/Scenes/SampleScene.unity
Normal file
3067
聊天系统课程代码/Client/Unity/Assets/Scenes/SampleScene.unity
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9fc0d4010bbf28b4594072e72b8655ab
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
聊天系统课程代码/Client/Unity/Assets/Scripts.meta
Normal file
8
聊天系统课程代码/Client/Unity/Assets/Scripts.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: dcecc97fbd8214f2fb856c62b80b50f1
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
BIN
聊天系统课程代码/Client/Unity/Assets/Scripts/.DS_Store
vendored
Normal file
BIN
聊天系统课程代码/Client/Unity/Assets/Scripts/.DS_Store
vendored
Normal file
Binary file not shown.
182
聊天系统课程代码/Client/Unity/Assets/Scripts/Entry.cs
Normal file
182
聊天系统课程代码/Client/Unity/Assets/Scripts/Entry.cs
Normal file
@@ -0,0 +1,182 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Fantasy;
|
||||
using Fantasy.Async;
|
||||
using Fantasy.Entitas;
|
||||
using Fantasy.Network;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public sealed class EntryComponent : Entity
|
||||
{
|
||||
public Entry Entry;
|
||||
}
|
||||
|
||||
public class Entry : MonoBehaviour
|
||||
{
|
||||
private Scene _scene;
|
||||
private Session _session;
|
||||
|
||||
public GameObject LoginPanel;
|
||||
public GameObject ChatPanel;
|
||||
|
||||
public Text MessageText;
|
||||
public InputField PrivateText;
|
||||
public InputField UserName;
|
||||
public InputField SendMessageText;
|
||||
public Button LoginButton;
|
||||
public Button ExitButton;
|
||||
public Button BroadcastButton;
|
||||
public Button ChannelButton;
|
||||
public Button PrivateButton;
|
||||
|
||||
public Button SendButton1;
|
||||
public Button ChatNodeEventButton;
|
||||
void Start()
|
||||
{
|
||||
LoginPanel.SetActive(true);
|
||||
ChatPanel.SetActive(false);
|
||||
StartAsync().Coroutine();
|
||||
LoginButton.onClick.RemoveAllListeners();
|
||||
LoginButton.onClick.AddListener(() => { OnLoginButtonClick().Coroutine();});
|
||||
ExitButton.onClick.RemoveAllListeners();
|
||||
ExitButton.onClick.AddListener(() => { OnExitButtonClick().Coroutine();});
|
||||
SendButton1.onClick.RemoveAllListeners();
|
||||
SendButton1.onClick.AddListener(() => { OnSendButton1Click().Coroutine();});
|
||||
BroadcastButton.onClick.RemoveAllListeners();
|
||||
BroadcastButton.onClick.AddListener(() => { OnBroadcastButtonClick().Coroutine();});
|
||||
ChannelButton.onClick.RemoveAllListeners();
|
||||
ChannelButton.onClick.AddListener(() => { OnChannelButtonClick().Coroutine();});
|
||||
PrivateButton.onClick.RemoveAllListeners();
|
||||
PrivateButton.onClick.AddListener(() => { OnPrivateButtonClick().Coroutine();});
|
||||
}
|
||||
|
||||
private async FTask StartAsync()
|
||||
{
|
||||
Fantasy.Platform.Unity.Entry.Initialize(GetType().Assembly);
|
||||
_scene = await Scene.Create(SceneRuntimeType.MainThread);
|
||||
_scene.AddComponent<EntryComponent>().Entry = this;
|
||||
_scene.AddComponent<SerializerComponent>().Initialize();
|
||||
}
|
||||
|
||||
private async FTask OnLoginButtonClick()
|
||||
{
|
||||
// 创建一个连接,这里是连接到目标的Gate服务器
|
||||
_session = _scene.Connect(
|
||||
"127.0.0.1:20000",
|
||||
NetworkProtocolType.KCP,
|
||||
() =>
|
||||
{
|
||||
Log.Debug("连接成功!");
|
||||
_session.AddComponent<SessionHeartbeatComponent>().Start(2000);
|
||||
},
|
||||
() =>
|
||||
{
|
||||
Log.Debug("连接失败!");
|
||||
},
|
||||
() =>
|
||||
{
|
||||
Log.Debug("断开连接!");
|
||||
},
|
||||
false, 5000);
|
||||
// 发送登录请求
|
||||
var response = (G2C_LoginResponse)await _session.Call(new C2G_LoginRequest()
|
||||
{
|
||||
UserName = UserName.text
|
||||
});
|
||||
// 查看错误码
|
||||
if (response.ErrorCode != 0)
|
||||
{
|
||||
Log.Error($"登录错误 ErrorCode:{response.ErrorCode}");
|
||||
return;
|
||||
}
|
||||
LoginPanel.SetActive(false);
|
||||
ChatPanel.SetActive(true);
|
||||
Log.Debug("登录成功!");
|
||||
}
|
||||
|
||||
private async FTask OnExitButtonClick()
|
||||
{
|
||||
var response = (G2C_ExitResponse)await _session.Call(new C2G_ExitRequest());
|
||||
if (response.ErrorCode != 0)
|
||||
{
|
||||
Log.Error($"退出游戏错误 ErrorCode:{response.ErrorCode}");
|
||||
return;
|
||||
}
|
||||
LoginPanel.SetActive(true);
|
||||
ChatPanel.SetActive(false);
|
||||
Log.Debug("退出游戏成功!");
|
||||
}
|
||||
|
||||
private async FTask OnSendButton1Click()
|
||||
{
|
||||
await FTask.CompletedTask;
|
||||
// SendButton1.interactable = false;
|
||||
// var response = (Chat2C_SendMessageResponse) await _session.Call(new C2Chat_SendMessageRequest());
|
||||
// if (response.ErrorCode != 0)
|
||||
// {
|
||||
// Log.Error($"发送聊天消息失败 ErrorCode:{response.ErrorCode}");
|
||||
// return;
|
||||
// }
|
||||
// Log.Debug("发送聊天消息成功!");
|
||||
// SendButton1.interactable = true;
|
||||
}
|
||||
|
||||
private async FTask OnBroadcastButtonClick()
|
||||
{
|
||||
BroadcastButton.interactable = false;
|
||||
var tree = ChatTreeFactory.Broadcast(_scene);
|
||||
tree = tree.AddendPositionNode(SendMessageText.text, "勇者大陆", 121, 131, 111);
|
||||
|
||||
var response = (Chat2C_SendMessageResponse)await _session.Call(new C2Chat_SendMessageRequest()
|
||||
{
|
||||
ChatInfoTree = tree
|
||||
});
|
||||
if (response.ErrorCode != 0)
|
||||
{
|
||||
Log.Error($"发送聊天消息失败 ErrorCode:{response.ErrorCode}");
|
||||
}
|
||||
|
||||
BroadcastButton.interactable = true;
|
||||
}
|
||||
|
||||
private async FTask OnChannelButtonClick()
|
||||
{
|
||||
ChannelButton.interactable = false;
|
||||
var tree = ChatTreeFactory.Team(_scene);
|
||||
tree.ChatChannelId = 1;
|
||||
// tree = tree.AddendTextNode("你好,欢迎来到Fantasy Chat!").AddendLinkNode("点击这里http://www.fantasy.com.cn");
|
||||
var response = (Chat2C_SendMessageResponse)await _session.Call(new C2Chat_SendMessageRequest()
|
||||
{
|
||||
ChatInfoTree = tree
|
||||
});
|
||||
if (response.ErrorCode != 0)
|
||||
{
|
||||
Log.Error($"发送频道聊天消息失败 ErrorCode:{response.ErrorCode}");
|
||||
}
|
||||
|
||||
ChannelButton.interactable = true;
|
||||
}
|
||||
|
||||
private async FTask OnPrivateButtonClick()
|
||||
{
|
||||
PrivateButton.interactable = false;
|
||||
var tree = ChatTreeFactory.Private(_scene);
|
||||
tree.Target.Add(Convert.ToInt64(PrivateText.text));
|
||||
// tree = tree.AddendTextNode("你好,欢迎来到Fantasy Chat!").AddendLinkNode("点击这里http://www.fantasy.com.cn");
|
||||
|
||||
var response = (Chat2C_SendMessageResponse)await _session.Call(new C2Chat_SendMessageRequest()
|
||||
{
|
||||
ChatInfoTree = tree
|
||||
});
|
||||
if (response.ErrorCode != 0)
|
||||
{
|
||||
Log.Error($"发送私聊消息失败 ErrorCode:{response.ErrorCode}");
|
||||
}
|
||||
|
||||
PrivateButton.interactable = true;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
11
聊天系统课程代码/Client/Unity/Assets/Scripts/Entry.cs.meta
Normal file
11
聊天系统课程代码/Client/Unity/Assets/Scripts/Entry.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ff1382f197f7f4cf39f6ae0745b57ee6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
聊天系统课程代码/Client/Unity/Assets/Scripts/Hotfix.meta
Normal file
8
聊天系统课程代码/Client/Unity/Assets/Scripts/Hotfix.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 019a0eb317f11413fa9c6be7fd61e28e
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
BIN
聊天系统课程代码/Client/Unity/Assets/Scripts/Hotfix/.DS_Store
vendored
Normal file
BIN
聊天系统课程代码/Client/Unity/Assets/Scripts/Hotfix/.DS_Store
vendored
Normal file
Binary file not shown.
8
聊天系统课程代码/Client/Unity/Assets/Scripts/Hotfix/Chat.meta
Normal file
8
聊天系统课程代码/Client/Unity/Assets/Scripts/Hotfix/Chat.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 84d0e5cdfe24a42e4b1a6a5d3fa0796b
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,52 @@
|
||||
using System;
|
||||
|
||||
namespace Fantasy
|
||||
{
|
||||
/// <summary>
|
||||
/// 聊天频道类型
|
||||
/// </summary>
|
||||
[Flags]
|
||||
public enum ChatChannelType
|
||||
{
|
||||
None = 0,
|
||||
World = 1 << 1, // 世界频道
|
||||
Private = 1 << 2, // 私聊频道
|
||||
System = 1 << 3, // 系统频道
|
||||
Broadcast = 1 << 4, // 广播频道
|
||||
Notice = 1 << 5, // 公告频道
|
||||
Team = 1 << 6, // 队伍频道
|
||||
Near = 1 << 7, // 附近频道
|
||||
CurrentMap = 1 << 8, // 当前地图频道
|
||||
|
||||
// 所有频道
|
||||
All = World | Private | System | Broadcast | Notice | Team | Near,
|
||||
// 其他聊天栏显示的频道
|
||||
Display = World | Private | System | Broadcast | Notice | Team | Near | CurrentMap
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 聊天节点类型
|
||||
/// </summary>
|
||||
public enum ChatNodeType
|
||||
{
|
||||
None = 0,
|
||||
Position = 1, // 位置节点
|
||||
OpenUI = 2, // 打开UI节点
|
||||
Link = 3, // 链接节点
|
||||
Item = 4, // 物品节点
|
||||
Text = 5, // 文本节点
|
||||
Image = 6, // 图片节点
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 聊天节点事件类型
|
||||
/// </summary>
|
||||
public enum ChatNodeEvent
|
||||
{
|
||||
None = 0,
|
||||
OpenUI = 1, // 打开UI节点
|
||||
ClickLink = 2, // 点击链接节点
|
||||
UseItem = 3, // 使用物品节点
|
||||
Position = 4, // 位置节点
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1cf2785958c454fb98765b594d346806
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,16 @@
|
||||
using System.Runtime.Serialization;
|
||||
using MongoDB.Bson.Serialization.Attributes;
|
||||
using Newtonsoft.Json;
|
||||
using ProtoBuf;
|
||||
|
||||
namespace Fantasy
|
||||
{
|
||||
public partial class ChatInfoTree
|
||||
{
|
||||
[BsonIgnore]
|
||||
[JsonIgnore]
|
||||
[ProtoIgnore]
|
||||
[IgnoreDataMember]
|
||||
public Scene Scene { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0079ff8530a474be1a7962b88311db20
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,78 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Fantasy
|
||||
{
|
||||
public static class ChatNodeEventHelper
|
||||
{
|
||||
public static void Handler(Scene scene, ChatInfoNode node)
|
||||
{
|
||||
switch ((ChatNodeEvent)node.ChatNodeEvent)
|
||||
{
|
||||
case ChatNodeEvent.ClickLink:
|
||||
{
|
||||
ClickLinkHandler(scene, node);
|
||||
return;
|
||||
}
|
||||
case ChatNodeEvent.OpenUI:
|
||||
{
|
||||
OpenUIHandler(scene, node);
|
||||
return;
|
||||
}
|
||||
case ChatNodeEvent.Position:
|
||||
{
|
||||
PositionHandler(scene, node);
|
||||
return;
|
||||
}
|
||||
case ChatNodeEvent.UseItem:
|
||||
{
|
||||
UseItemHandler(scene, node);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void ClickLinkHandler(Scene scene, ChatInfoNode node)
|
||||
{
|
||||
if (node.Data == null || node.Data.Length == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var chatLinkNode = scene.GetComponent<SerializerComponent>().Deserialize<ChatLinkNode>(node.Data);
|
||||
// 拿到这个之后,就可以为所欲为了。
|
||||
// 根据自己的逻辑和UI设计,做出相应的处理。
|
||||
Log.Debug($"ClickLinkHandler Link:{chatLinkNode.Link}");
|
||||
}
|
||||
|
||||
private static void OpenUIHandler(Scene scene, ChatInfoNode node)
|
||||
{
|
||||
if (node.Data == null || node.Data.Length == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var chatOpenUINode =scene.GetComponent<SerializerComponent>().Deserialize<ChatOpenUINode>(node.Data);
|
||||
// 拿到这个之后,就可以为所欲为了。
|
||||
// 根据自己的逻辑和UI设计,做出相应的处理。
|
||||
Log.Debug($"OpenUIHandler UIName:{chatOpenUINode.UIName}");
|
||||
}
|
||||
|
||||
private static void PositionHandler(Scene scene, ChatInfoNode node)
|
||||
{
|
||||
if (node.Data == null || node.Data.Length == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var chatPositionNode =scene.GetComponent<SerializerComponent>().Deserialize<ChatPositionNode>(node.Data);
|
||||
// 拿到这个之后,就可以为所欲为了。
|
||||
// 根据自己的逻辑和UI设计,做出相应的处理。
|
||||
Log.Debug($"PositionHandler MapName:{chatPositionNode.MapName} X:{chatPositionNode.PosX} Y:{chatPositionNode.PosY} Z:{chatPositionNode.PosZ}");
|
||||
}
|
||||
|
||||
private static void UseItemHandler(Scene scene, ChatInfoNode node)
|
||||
{
|
||||
// TODO: Implement UseItemHandler
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 17bb297b8f01b4b90a7f306acd81b672
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,126 @@
|
||||
namespace Fantasy
|
||||
{
|
||||
/// <summary>
|
||||
/// 聊天信息节点
|
||||
/// </summary>
|
||||
public static class ChatNodeFactory
|
||||
{
|
||||
/// <summary>
|
||||
/// 添加文本节点
|
||||
/// </summary>
|
||||
/// <param name="chatInfoTree"></param>
|
||||
/// <param name="content"></param>
|
||||
/// <returns></returns>
|
||||
public static ChatInfoTree AddendTextNode(this ChatInfoTree chatInfoTree, string content)
|
||||
{
|
||||
var chatInfoNode = new ChatInfoNode()
|
||||
{
|
||||
ChatNodeType = (int)ChatNodeType.Text,
|
||||
Content = content
|
||||
};
|
||||
chatInfoTree.Node.Add(chatInfoNode);
|
||||
return chatInfoTree;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加链接节点
|
||||
/// </summary>
|
||||
/// <param name="chatInfoTree"></param>
|
||||
/// <param name="content"></param>
|
||||
/// <param name="link"></param>
|
||||
/// <returns></returns>
|
||||
public static ChatInfoTree AddendLinkNode(this ChatInfoTree chatInfoTree, string content,string link)
|
||||
{
|
||||
var chatLinkNode = new ChatLinkNode()
|
||||
{
|
||||
Link = link
|
||||
};
|
||||
var serializerComponent = chatInfoTree.Scene.GetComponent<SerializerComponent>();
|
||||
var chatInfoNode = new ChatInfoNode()
|
||||
{
|
||||
ChatNodeType = (int)ChatNodeType.Link,
|
||||
ChatNodeEvent = (int)ChatNodeEvent.ClickLink,
|
||||
Content = content,
|
||||
Data = serializerComponent.Serialize(chatLinkNode)
|
||||
};
|
||||
chatInfoTree.Node.Add(chatInfoNode);
|
||||
return chatInfoTree;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加图片节点
|
||||
/// </summary>
|
||||
/// <param name="chatInfoTree"></param>
|
||||
/// <param name="content"></param>
|
||||
/// <returns></returns>
|
||||
public static ChatInfoTree AddendImageNode(this ChatInfoTree chatInfoTree, string content)
|
||||
{
|
||||
var chatInfoNode = new ChatInfoNode()
|
||||
{
|
||||
ChatNodeType = (int)ChatNodeType.Image,
|
||||
Content = content
|
||||
};
|
||||
chatInfoTree.Node.Add(chatInfoNode);
|
||||
return chatInfoTree;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加打开UI节点
|
||||
/// </summary>
|
||||
/// <param name="chatInfoTree"></param>
|
||||
/// <param name="content"></param>
|
||||
/// <param name="uiName"></param>
|
||||
/// <returns></returns>
|
||||
public static ChatInfoTree AddendOpenUINode(this ChatInfoTree chatInfoTree, string content,string uiName)
|
||||
{
|
||||
var chatOpenUINode = new ChatOpenUINode()
|
||||
{
|
||||
UIName = uiName
|
||||
};
|
||||
var serializerComponent = chatInfoTree.Scene.GetComponent<SerializerComponent>();
|
||||
var chatInfoNode = new ChatInfoNode()
|
||||
{
|
||||
ChatNodeType = (int)ChatNodeType.OpenUI,
|
||||
ChatNodeEvent = (int)ChatNodeEvent.OpenUI,
|
||||
Content = content,
|
||||
Data = serializerComponent.Serialize(chatOpenUINode)
|
||||
};
|
||||
chatInfoTree.Node.Add(chatInfoNode);
|
||||
return chatInfoTree;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加位置节点
|
||||
/// </summary>
|
||||
/// <param name="chatInfoTree"></param>
|
||||
/// <param name="content"></param>
|
||||
/// <param name="mapName"></param>
|
||||
/// <param name="mapX"></param>
|
||||
/// <param name="mapY"></param>
|
||||
/// <param name="mapZ"></param>
|
||||
/// <returns></returns>
|
||||
public static ChatInfoTree AddendPositionNode(this ChatInfoTree chatInfoTree, string content, string mapName,
|
||||
float mapX, float mapY, float mapZ)
|
||||
{
|
||||
var chatPositionNode = new ChatPositionNode()
|
||||
{
|
||||
MapName = mapName,
|
||||
PosX = mapX,
|
||||
PosY = mapY,
|
||||
PosZ = mapZ,
|
||||
};
|
||||
|
||||
var serializerComponent = chatInfoTree.Scene.GetComponent<SerializerComponent>();
|
||||
var chatInfoNode = new ChatInfoNode()
|
||||
{
|
||||
ChatNodeType = (int)ChatNodeType.Position,
|
||||
ChatNodeEvent = (int)ChatNodeEvent.Position,
|
||||
Content = content,
|
||||
Data = serializerComponent.Serialize(chatPositionNode)
|
||||
};
|
||||
|
||||
chatInfoTree.Node.Add(chatInfoNode);
|
||||
return chatInfoTree;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 608005f1b93de4f9c965dd56e560e9c4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,120 @@
|
||||
namespace Fantasy
|
||||
{
|
||||
/// <summary>
|
||||
/// 创建聊天树的总入口
|
||||
/// </summary>
|
||||
public static class ChatTreeFactory
|
||||
{
|
||||
/// <summary>
|
||||
/// 创建世界聊天树
|
||||
/// </summary>
|
||||
/// <param name="scene"></param>
|
||||
/// <returns></returns>
|
||||
public static ChatInfoTree World(Scene scene)
|
||||
{
|
||||
return new ChatInfoTree()
|
||||
{
|
||||
Scene = scene,
|
||||
ChatChannelType = (int)ChatChannelType.World,
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建私聊聊天树
|
||||
/// </summary>
|
||||
/// <param name="scene"></param>
|
||||
/// <returns></returns>
|
||||
public static ChatInfoTree Private(Scene scene)
|
||||
{
|
||||
return new ChatInfoTree()
|
||||
{
|
||||
Scene = scene,
|
||||
ChatChannelType = (int)ChatChannelType.Private,
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建系统聊天树
|
||||
/// </summary>
|
||||
/// <param name="scene"></param>
|
||||
/// <returns></returns>
|
||||
public static ChatInfoTree System(Scene scene)
|
||||
{
|
||||
return new ChatInfoTree()
|
||||
{
|
||||
Scene = scene,
|
||||
ChatChannelType = (int)ChatChannelType.System,
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建公广播聊天树
|
||||
/// </summary>
|
||||
/// <param name="scene"></param>
|
||||
/// <returns></returns>
|
||||
public static ChatInfoTree Broadcast(Scene scene)
|
||||
{
|
||||
return new ChatInfoTree()
|
||||
{
|
||||
Scene = scene,
|
||||
ChatChannelType = (int)ChatChannelType.Broadcast,
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建公告聊天树
|
||||
/// </summary>
|
||||
/// <param name="scene"></param>
|
||||
/// <returns></returns>
|
||||
public static ChatInfoTree Notice(Scene scene)
|
||||
{
|
||||
return new ChatInfoTree()
|
||||
{
|
||||
Scene = scene,
|
||||
ChatChannelType = (int)ChatChannelType.Notice,
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建队伍聊天树
|
||||
/// </summary>
|
||||
/// <param name="scene"></param>
|
||||
/// <returns></returns>
|
||||
public static ChatInfoTree Team(Scene scene)
|
||||
{
|
||||
return new ChatInfoTree()
|
||||
{
|
||||
Scene = scene,
|
||||
ChatChannelType = (int)ChatChannelType.Team,
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建附近人聊天树
|
||||
/// </summary>
|
||||
/// <param name="scene"></param>
|
||||
/// <returns></returns>
|
||||
public static ChatInfoTree Near(Scene scene)
|
||||
{
|
||||
return new ChatInfoTree()
|
||||
{
|
||||
Scene = scene,
|
||||
ChatChannelType = (int)ChatChannelType.Near,
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建当前地图聊天树
|
||||
/// </summary>
|
||||
/// <param name="scene"></param>
|
||||
/// <returns></returns>
|
||||
public static ChatInfoTree CurrentMap(Scene scene)
|
||||
{
|
||||
return new ChatInfoTree()
|
||||
{
|
||||
Scene = scene,
|
||||
ChatChannelType = (int)ChatChannelType.CurrentMap,
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 13c4041549f6e405a985eea47dbf08b7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6edca5b81b75f4d49b42c024e919cb3b
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c3689f1e79f954f2fbe17fbf98116bc7
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,318 @@
|
||||
using ProtoBuf;
|
||||
|
||||
using System.Collections.Generic;
|
||||
using Fantasy;
|
||||
using Fantasy.Network.Interface;
|
||||
using Fantasy.Serialize;
|
||||
#pragma warning disable CS8618
|
||||
|
||||
namespace Fantasy
|
||||
{
|
||||
/// <summary>
|
||||
/// 登录游戏
|
||||
/// </summary>
|
||||
[ProtoContract]
|
||||
public partial class C2G_LoginRequest : AMessage, IRequest, IProto
|
||||
{
|
||||
public static C2G_LoginRequest Create(Scene scene)
|
||||
{
|
||||
return scene.MessagePoolComponent.Rent<C2G_LoginRequest>();
|
||||
}
|
||||
public override void Dispose()
|
||||
{
|
||||
UserName = default;
|
||||
#if FANTASY_NET || FANTASY_UNITY
|
||||
GetScene().MessagePoolComponent.Return<C2G_LoginRequest>(this);
|
||||
#endif
|
||||
}
|
||||
[ProtoIgnore]
|
||||
public G2C_LoginResponse ResponseType { get; set; }
|
||||
public uint OpCode() { return OuterOpcode.C2G_LoginRequest; }
|
||||
[ProtoMember(1)]
|
||||
public string UserName { get; set; }
|
||||
}
|
||||
[ProtoContract]
|
||||
public partial class G2C_LoginResponse : AMessage, IResponse, IProto
|
||||
{
|
||||
public static G2C_LoginResponse Create(Scene scene)
|
||||
{
|
||||
return scene.MessagePoolComponent.Rent<G2C_LoginResponse>();
|
||||
}
|
||||
public override void Dispose()
|
||||
{
|
||||
ErrorCode = default;
|
||||
#if FANTASY_NET || FANTASY_UNITY
|
||||
GetScene().MessagePoolComponent.Return<G2C_LoginResponse>(this);
|
||||
#endif
|
||||
}
|
||||
public uint OpCode() { return OuterOpcode.G2C_LoginResponse; }
|
||||
[ProtoMember(1)]
|
||||
public uint ErrorCode { get; set; }
|
||||
}
|
||||
/// <summary>
|
||||
/// 退出游戏
|
||||
/// </summary>
|
||||
[ProtoContract]
|
||||
public partial class C2G_ExitRequest : AMessage, IRequest, IProto
|
||||
{
|
||||
public static C2G_ExitRequest Create(Scene scene)
|
||||
{
|
||||
return scene.MessagePoolComponent.Rent<C2G_ExitRequest>();
|
||||
}
|
||||
public override void Dispose()
|
||||
{
|
||||
#if FANTASY_NET || FANTASY_UNITY
|
||||
GetScene().MessagePoolComponent.Return<C2G_ExitRequest>(this);
|
||||
#endif
|
||||
}
|
||||
[ProtoIgnore]
|
||||
public G2C_ExitResponse ResponseType { get; set; }
|
||||
public uint OpCode() { return OuterOpcode.C2G_ExitRequest; }
|
||||
}
|
||||
[ProtoContract]
|
||||
public partial class G2C_ExitResponse : AMessage, IResponse, IProto
|
||||
{
|
||||
public static G2C_ExitResponse Create(Scene scene)
|
||||
{
|
||||
return scene.MessagePoolComponent.Rent<G2C_ExitResponse>();
|
||||
}
|
||||
public override void Dispose()
|
||||
{
|
||||
ErrorCode = default;
|
||||
#if FANTASY_NET || FANTASY_UNITY
|
||||
GetScene().MessagePoolComponent.Return<G2C_ExitResponse>(this);
|
||||
#endif
|
||||
}
|
||||
public uint OpCode() { return OuterOpcode.G2C_ExitResponse; }
|
||||
[ProtoMember(1)]
|
||||
public uint ErrorCode { get; set; }
|
||||
}
|
||||
/// <summary>
|
||||
/// 发送一个聊天消息给Chat服务器,中间是经过Gate中转的
|
||||
/// </summary>
|
||||
[ProtoContract]
|
||||
public partial class C2Chat_SendMessageRequest : AMessage, ICustomRouteRequest, IProto
|
||||
{
|
||||
public static C2Chat_SendMessageRequest Create(Scene scene)
|
||||
{
|
||||
return scene.MessagePoolComponent.Rent<C2Chat_SendMessageRequest>();
|
||||
}
|
||||
public override void Dispose()
|
||||
{
|
||||
ChatInfoTree = default;
|
||||
#if FANTASY_NET || FANTASY_UNITY
|
||||
GetScene().MessagePoolComponent.Return<C2Chat_SendMessageRequest>(this);
|
||||
#endif
|
||||
}
|
||||
[ProtoIgnore]
|
||||
public Chat2C_SendMessageResponse ResponseType { get; set; }
|
||||
public uint OpCode() { return OuterOpcode.C2Chat_SendMessageRequest; }
|
||||
[ProtoIgnore]
|
||||
public int RouteType => Fantasy.RouteType.ChatRoute;
|
||||
[ProtoMember(1)]
|
||||
public ChatInfoTree ChatInfoTree { get; set; }
|
||||
}
|
||||
[ProtoContract]
|
||||
public partial class Chat2C_SendMessageResponse : AMessage, ICustomRouteResponse, IProto
|
||||
{
|
||||
public static Chat2C_SendMessageResponse Create(Scene scene)
|
||||
{
|
||||
return scene.MessagePoolComponent.Rent<Chat2C_SendMessageResponse>();
|
||||
}
|
||||
public override void Dispose()
|
||||
{
|
||||
ErrorCode = default;
|
||||
#if FANTASY_NET || FANTASY_UNITY
|
||||
GetScene().MessagePoolComponent.Return<Chat2C_SendMessageResponse>(this);
|
||||
#endif
|
||||
}
|
||||
public uint OpCode() { return OuterOpcode.Chat2C_SendMessageResponse; }
|
||||
[ProtoMember(1)]
|
||||
public uint ErrorCode { get; set; }
|
||||
}
|
||||
[ProtoContract]
|
||||
public partial class Chat2C_Message : AMessage, ICustomRouteMessage, IProto
|
||||
{
|
||||
public static Chat2C_Message Create(Scene scene)
|
||||
{
|
||||
return scene.MessagePoolComponent.Rent<Chat2C_Message>();
|
||||
}
|
||||
public override void Dispose()
|
||||
{
|
||||
ChatInfoTree = default;
|
||||
#if FANTASY_NET || FANTASY_UNITY
|
||||
GetScene().MessagePoolComponent.Return<Chat2C_Message>(this);
|
||||
#endif
|
||||
}
|
||||
public uint OpCode() { return OuterOpcode.Chat2C_Message; }
|
||||
[ProtoIgnore]
|
||||
public int RouteType => Fantasy.RouteType.ChatRoute;
|
||||
[ProtoMember(1)]
|
||||
public ChatInfoTree ChatInfoTree { get; set; }
|
||||
}
|
||||
/// <summary>
|
||||
/// 聊天消息树
|
||||
/// </summary>
|
||||
[ProtoContract]
|
||||
public partial class ChatInfoTree : AMessage, IProto
|
||||
{
|
||||
public static ChatInfoTree Create(Scene scene)
|
||||
{
|
||||
return scene.MessagePoolComponent.Rent<ChatInfoTree>();
|
||||
}
|
||||
public override void Dispose()
|
||||
{
|
||||
ChatChannelType = default;
|
||||
ChatChannelId = default;
|
||||
UnitId = default;
|
||||
UserName = default;
|
||||
Target.Clear();
|
||||
Node.Clear();
|
||||
#if FANTASY_NET || FANTASY_UNITY
|
||||
GetScene().MessagePoolComponent.Return<ChatInfoTree>(this);
|
||||
#endif
|
||||
}
|
||||
[ProtoMember(1)]
|
||||
public int ChatChannelType { get; set; }
|
||||
[ProtoMember(2)]
|
||||
public long ChatChannelId { get; set; }
|
||||
[ProtoMember(3)]
|
||||
public long UnitId { get; set; }
|
||||
[ProtoMember(4)]
|
||||
public string UserName { get; set; }
|
||||
[ProtoMember(5)]
|
||||
public List<long> Target = new List<long>();
|
||||
[ProtoMember(6)]
|
||||
public List<ChatInfoNode> Node = new List<ChatInfoNode>();
|
||||
}
|
||||
/// <summary>
|
||||
/// 聊天信息节点
|
||||
/// </summary>
|
||||
[ProtoContract]
|
||||
public partial class ChatInfoNode : AMessage, IProto
|
||||
{
|
||||
public static ChatInfoNode Create(Scene scene)
|
||||
{
|
||||
return scene.MessagePoolComponent.Rent<ChatInfoNode>();
|
||||
}
|
||||
public override void Dispose()
|
||||
{
|
||||
ChatNodeType = default;
|
||||
ChatNodeEvent = default;
|
||||
Content = default;
|
||||
Color = default;
|
||||
Data = default;
|
||||
#if FANTASY_NET || FANTASY_UNITY
|
||||
GetScene().MessagePoolComponent.Return<ChatInfoNode>(this);
|
||||
#endif
|
||||
}
|
||||
[ProtoMember(1)]
|
||||
public int ChatNodeType { get; set; }
|
||||
[ProtoMember(2)]
|
||||
public int ChatNodeEvent { get; set; }
|
||||
[ProtoMember(3)]
|
||||
public string Content { get; set; }
|
||||
[ProtoMember(4)]
|
||||
public string Color { get; set; }
|
||||
[ProtoMember(5)]
|
||||
public byte[] Data { get; set; }
|
||||
}
|
||||
/// <summary>
|
||||
/// 聊天位置信息节点
|
||||
/// </summary>
|
||||
[ProtoContract]
|
||||
public partial class ChatPositionNode : AMessage, IProto
|
||||
{
|
||||
public static ChatPositionNode Create(Scene scene)
|
||||
{
|
||||
return scene.MessagePoolComponent.Rent<ChatPositionNode>();
|
||||
}
|
||||
public override void Dispose()
|
||||
{
|
||||
MapName = default;
|
||||
PosX = default;
|
||||
PosY = default;
|
||||
PosZ = default;
|
||||
#if FANTASY_NET || FANTASY_UNITY
|
||||
GetScene().MessagePoolComponent.Return<ChatPositionNode>(this);
|
||||
#endif
|
||||
}
|
||||
[ProtoMember(1)]
|
||||
public string MapName { get; set; }
|
||||
[ProtoMember(2)]
|
||||
public float PosX { get; set; }
|
||||
[ProtoMember(3)]
|
||||
public float PosY { get; set; }
|
||||
[ProtoMember(4)]
|
||||
public float PosZ { get; set; }
|
||||
}
|
||||
/// <summary>
|
||||
/// 聊天位置信息节点
|
||||
/// </summary>
|
||||
[ProtoContract]
|
||||
public partial class ChatOpenUINode : AMessage, IProto
|
||||
{
|
||||
public static ChatOpenUINode Create(Scene scene)
|
||||
{
|
||||
return scene.MessagePoolComponent.Rent<ChatOpenUINode>();
|
||||
}
|
||||
public override void Dispose()
|
||||
{
|
||||
UIName = default;
|
||||
#if FANTASY_NET || FANTASY_UNITY
|
||||
GetScene().MessagePoolComponent.Return<ChatOpenUINode>(this);
|
||||
#endif
|
||||
}
|
||||
[ProtoMember(1)]
|
||||
public string UIName { get; set; }
|
||||
}
|
||||
/// <summary>
|
||||
/// 聊天连接信息节点
|
||||
/// </summary>
|
||||
[ProtoContract]
|
||||
public partial class ChatLinkNode : AMessage, IProto
|
||||
{
|
||||
public static ChatLinkNode Create(Scene scene)
|
||||
{
|
||||
return scene.MessagePoolComponent.Rent<ChatLinkNode>();
|
||||
}
|
||||
public override void Dispose()
|
||||
{
|
||||
Link = default;
|
||||
#if FANTASY_NET || FANTASY_UNITY
|
||||
GetScene().MessagePoolComponent.Return<ChatLinkNode>(this);
|
||||
#endif
|
||||
}
|
||||
[ProtoMember(1)]
|
||||
public string Link { get; set; }
|
||||
}
|
||||
/// <summary>
|
||||
/// 装备信息实体
|
||||
/// </summary>
|
||||
[ProtoContract]
|
||||
public partial class Item : AMessage, IProto
|
||||
{
|
||||
public static Item Create(Scene scene)
|
||||
{
|
||||
return scene.MessagePoolComponent.Rent<Item>();
|
||||
}
|
||||
public override void Dispose()
|
||||
{
|
||||
Level = default;
|
||||
Name = default;
|
||||
HP = default;
|
||||
MP = default;
|
||||
#if FANTASY_NET || FANTASY_UNITY
|
||||
GetScene().MessagePoolComponent.Return<Item>(this);
|
||||
#endif
|
||||
}
|
||||
[ProtoMember(1)]
|
||||
public string Level { get; set; }
|
||||
[ProtoMember(2)]
|
||||
public string Name { get; set; }
|
||||
[ProtoMember(3)]
|
||||
public string HP { get; set; }
|
||||
[ProtoMember(4)]
|
||||
public string MP { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d8b7e9d1d45c14f28ba2e43726bae843
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,13 @@
|
||||
namespace Fantasy
|
||||
{
|
||||
public static partial class OuterOpcode
|
||||
{
|
||||
public const uint C2G_LoginRequest = 268445457;
|
||||
public const uint G2C_LoginResponse = 402663185;
|
||||
public const uint C2G_ExitRequest = 268445458;
|
||||
public const uint G2C_ExitResponse = 402663186;
|
||||
public const uint C2Chat_SendMessageRequest = 2281711377;
|
||||
public const uint Chat2C_SendMessageResponse = 2415929105;
|
||||
public const uint Chat2C_Message = 2147493649;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 99247fb17248243e591419cbf976f158
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,9 @@
|
||||
namespace Fantasy
|
||||
{
|
||||
// Route协议定义(需要定义1000以上、因为1000以内的框架预留)
|
||||
public static class RouteType
|
||||
{
|
||||
public const int GateRoute = 1001; // Gate
|
||||
public const int ChatRoute = 1002; // Chat
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c84127d566a0345b19311b3a293ab9cc
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
3
聊天系统课程代码/Client/Unity/Assets/Scripts/Hotfix/Handler.meta
Normal file
3
聊天系统课程代码/Client/Unity/Assets/Scripts/Hotfix/Handler.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 330f024527274b83903606afd0c61e91
|
||||
timeCreated: 1730859225
|
||||
@@ -0,0 +1,38 @@
|
||||
using System.Text;
|
||||
using Fantasy.Async;
|
||||
using Fantasy.Network;
|
||||
using Fantasy.Network.Interface;
|
||||
|
||||
namespace Fantasy
|
||||
{
|
||||
public sealed class Chat2C_MessageHandler : Message<Chat2C_Message>
|
||||
{
|
||||
protected override async FTask Run(Session session, Chat2C_Message message)
|
||||
{
|
||||
ChatTreeParser.Parse(session.Scene,message.ChatInfoTree);
|
||||
Log.Info("收到聊天信息:");
|
||||
await FTask.CompletedTask;
|
||||
}
|
||||
}
|
||||
|
||||
public static class ChatTreeParser
|
||||
{
|
||||
public static void Parse(Scene scene, ChatInfoTree tree)
|
||||
{
|
||||
var entryComponent = scene.GetComponent<EntryComponent>();
|
||||
var sb = new StringBuilder();
|
||||
foreach (var chatInfoNode in tree.Node)
|
||||
{
|
||||
// 这里只是演示一下处理事件的效果,实际使用时,需要根据实际情况处理事件
|
||||
// 明显我现在这样做的方式不是对的,应该是自己拼接一个聊天信息,然后调用这个接口来处理事件
|
||||
entryComponent.Entry.ChatNodeEventButton.onClick.RemoveAllListeners();
|
||||
entryComponent.Entry.ChatNodeEventButton.onClick.AddListener(() =>
|
||||
{
|
||||
ChatNodeEventHelper.Handler(scene, chatInfoNode);
|
||||
});
|
||||
sb.Append(chatInfoNode.Content);
|
||||
}
|
||||
entryComponent.Entry.MessageText.text = sb.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: afa90e99edd2f4388a789f81ed9a7b33
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
聊天系统课程代码/Client/Unity/Assets/Scripts/Hotfix/Share.meta
Normal file
8
聊天系统课程代码/Client/Unity/Assets/Scripts/Hotfix/Share.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bec9e556fd6314d1c91b0c661e9ad9e0
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 08d331f22f1e247d59c27aacbd722f8d
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 78bb35e99848447fa8ac1ffee50625db
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,12 @@
|
||||
using Fantasy.Entitas;
|
||||
using Fantasy.Network;
|
||||
using Fantasy.Serialize;
|
||||
|
||||
namespace Fantasy
|
||||
{
|
||||
public class SerializerComponent : Entity
|
||||
{
|
||||
public ISerialize Serialize;
|
||||
public readonly MemoryStreamBufferPool BufferPool = new MemoryStreamBufferPool();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a4d1516b4175743438426bd6554bf1e1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b82fed53e9e2c4773a399408912da4c6
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,24 @@
|
||||
using Fantasy.Serialize;
|
||||
|
||||
namespace Fantasy
|
||||
{
|
||||
public static class SerializerComponentSystem
|
||||
{
|
||||
public static void Initialize(this SerializerComponent self)
|
||||
{
|
||||
self.Serialize = SerializerManager.GetSerializer(FantasySerializerType.ProtoBuf);
|
||||
}
|
||||
|
||||
public static byte[] Serialize<T>(this SerializerComponent self, T @object)
|
||||
{
|
||||
using var memoryStreamBuffer = self.BufferPool.RentMemoryStream(MemoryStreamBufferSource.None);
|
||||
self.Serialize.Serialize(typeof(T), @object, memoryStreamBuffer);
|
||||
return memoryStreamBuffer.ToArray();
|
||||
}
|
||||
|
||||
public static T Deserialize<T>(this SerializerComponent self, byte[] bytes)
|
||||
{
|
||||
return self.Serialize.Deserialize<T>(bytes);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8608556722ae54798affab26b57a36d1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user