首次提交

This commit is contained in:
Bob.Song
2026-03-05 18:07:55 +08:00
commit e125bb869e
4534 changed files with 563920 additions and 0 deletions

View File

@@ -0,0 +1,52 @@
using System;
namespace NBF
{
/// <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, // 位置节点
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 4ec94d1a6ab744c4bdcff56d8da8e6ea
timeCreated: 1772694755

View File

@@ -0,0 +1,16 @@
using System.Runtime.Serialization;
using LightProto;
using MongoDB.Bson.Serialization.Attributes;
using Newtonsoft.Json;
namespace Fantasy
{
public partial class ChatInfoTree
{
[BsonIgnore]
[JsonIgnore]
[ProtoIgnore]
[IgnoreDataMember]
public Scene Scene { get; set; }
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 73e6060aebcd46eca52cd4086e193fb3
timeCreated: 1772694724

View File

@@ -0,0 +1,82 @@
using System.Collections.Generic;
using Fantasy;
using Fantasy.Serialize;
namespace NBF
{
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 = SerializerManager.ProtoBufHelper.Deserialize<ChatLinkNode>(node.Data);
// 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 = SerializerManager.ProtoBufHelper.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 = SerializerManager.ProtoBufHelper.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
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 7bcf5d11cea04d86a8a9c5c3fce31ed8
timeCreated: 1772694878

View File

@@ -0,0 +1,130 @@
using Fantasy;
using Fantasy.Network;
using Fantasy.Serialize;
namespace NBF
{
/// <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 = SerializerManager.ProtoBufHelper.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 chatInfoNode = new ChatInfoNode()
{
ChatNodeType = (int)ChatNodeType.OpenUI,
ChatNodeEvent = (int)ChatNodeEvent.OpenUI,
Content = content,
Data = SerializerManager.ProtoBufHelper.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 = SerializerManager.ProtoBufHelper.Serialize(chatPositionNode)
};
chatInfoTree.Node.Add(chatInfoNode);
return chatInfoTree;
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: bbf26a0aef9841f89db6182475f50e59
timeCreated: 1772694930

View File

@@ -0,0 +1,40 @@
/**本脚本为自动生成每次生成会覆盖请勿手动修改生成插件文档及项目地址https://git.whoot.com/whoot-games/whoot.fguieditorplugin**/
using FairyGUI;
using FairyGUI.Utils;
using NBC;
using System.Collections.Generic;
namespace NBF
{
/// <summary> </summary>
public partial class ChatTestPanel
{
public GObject this[string aKey] => ContentPane.GetChild(aKey);
public override string UIPackName => "Main";
public override string UIResName => "ChatTestPanel";
[AutoFind(Name = "back")]
public GImage back;
[AutoFind(Name = "InputMessage")]
public GLabel InputMessage;
[AutoFind(Name = "BtnSendMessage")]
public GButton BtnSendMessage;
[AutoFind(Name = "BtnSendFriend")]
public GButton BtnSendFriend;
[AutoFind(Name = "BtnSendWorld")]
public GButton BtnSendWorld;
[AutoFind(Name = "ChatList")]
public GList ChatList;
[AutoFind(Name = "InputFriendId")]
public GLabel InputFriendId;
public override string[] GetDependPackages(){ return new string[] {"Common","CommonNew"}; }
public static void Show(object param = null){ UI.Inst.OpenUI<ChatTestPanel>(param); }
public static void Hide(){ UI.Inst.HideUI<ChatTestPanel>(); }
public static void Del(){ UI.Inst.DestroyUI<ChatTestPanel>(); }
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: c9910a4bd1e1d3b4a8c580bcc2cc34e7

View File

@@ -0,0 +1,115 @@
// 本脚本只在不存在时会生成一次。已存在不会再次生成覆盖
using System;
using System.Collections.Generic;
using System.Text;
using FairyGUI;
using Fantasy;
using Fantasy.Async;
using Fantasy.Network;
using NBC;
using UnityEngine;
using Log = NBC.Log;
using UIPanel = NBC.UIPanel;
namespace NBF
{
public partial class ChatTestPanel : UIPanel
{
private List<string> _messages = new List<string>();
protected override void OnInit()
{
this.AutoAddClick(OnClick);
}
protected override void OnShow()
{
}
private void RefreshList()
{
ChatList.RemoveChildrenToPool();
foreach (var item in _messages)
{
if (ChatList.AddItemFromPool() is ChatItem chatItem)
{
chatItem.InitData(item);
}
}
}
private void OnClick(GComponent btn)
{
if (btn == BtnSendWorld)
{
OnSendMessage(InputMessage.title).Coroutine();
}
else if (btn == BtnSendFriend)
{
OnSendFriendMessage().Coroutine();
}
}
#region
private async FTask OnSendMessage(string message)
{
var tree = ChatTreeFactory.Broadcast(Game.Main);
tree = tree.AddendPositionNode(message, "勇者大陆", 121, 131, 111);
var response = (Chat2C_SendMessageResponse)await Net.Call(new C2Chat_SendMessageRequest()
{
ChatInfoTree = tree
});
if (response.ErrorCode != 0)
{
Log.Error($"发送聊天消息失败 ErrorCode:{response.ErrorCode}");
}
else
{
Log.Info("发送消息成功");
}
}
private async FTask OnSendFriendMessage()
{
var tree = ChatTreeFactory.Private();
tree.Target.Add(Convert.ToInt64(InputFriendId.text));
tree.AddendTextNode("你好欢迎来到Fantasy Chat")
.AddendLinkNode("点击这里http://www.fantasy.com.cn", "http://www.fantasy.com.cn");
var response = (Chat2C_SendMessageResponse)await Net.Call(new C2Chat_SendMessageRequest()
{
ChatInfoTree = tree
});
if (response.ErrorCode != 0)
{
Log.Error($"发送私聊消息失败 ErrorCode:{response.ErrorCode}");
}
}
public void Message(ChatInfoTree tree)
{
// _messages.Add(message);
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);
}
_messages.Add(sb.ToString());
RefreshList();
}
#endregion
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 2f05d713b2557a945b45a81473963207

View File

@@ -0,0 +1,121 @@
using Fantasy;
namespace NBF
{
/// <summary>
/// 创建聊天树的总入口
/// </summary>
public static class ChatTreeFactory
{
/// <summary>
/// 创建世界聊天树
/// </summary>
/// <param name="scene"></param>
/// <returns></returns>
public static ChatInfoTree World()
{
return new ChatInfoTree()
{
Scene = Game.Main,
ChatChannelType = (int)ChatChannelType.World,
};
}
/// <summary>
/// 创建私聊聊天树
/// </summary>
/// <returns></returns>
public static ChatInfoTree Private()
{
return new ChatInfoTree()
{
Scene = Game.Main,
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,
};
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: f028a29029d74cbf8c264a7d4a245ecf
timeCreated: 1772694684