提交测试代码
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1116,7 +1116,7 @@ Transform:
|
||||
m_GameObject: {fileID: 909052969}
|
||||
serializedVersion: 2
|
||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: -53, y: -1.75, z: -55.52}
|
||||
m_LocalPosition: {x: -53, y: -0.75, z: -55.52}
|
||||
m_LocalScale: {x: 100, y: 100, z: 100}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children: []
|
||||
@@ -2143,8 +2143,9 @@ MonoBehaviour:
|
||||
m_EditorClassIdentifier: Assembly-CSharp::Test.BobberTest
|
||||
rb: {fileID: 1518432885}
|
||||
line: {fileID: 8144283643417267672}
|
||||
lineLength: 2
|
||||
lineLength: 3
|
||||
floatLength: 1
|
||||
Tension: 0
|
||||
--- !u!1 &1529912227
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
@@ -2659,6 +2660,7 @@ GameObject:
|
||||
- component: {fileID: 1876288043}
|
||||
- component: {fileID: 1876288042}
|
||||
- component: {fileID: 1876288041}
|
||||
- component: {fileID: 1876288046}
|
||||
m_Layer: 0
|
||||
m_Name: Capsule
|
||||
m_TagString: Untagged
|
||||
@@ -2787,6 +2789,18 @@ Transform:
|
||||
m_Children: []
|
||||
m_Father: {fileID: 0}
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!114 &1876288046
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 1876288040}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: d5bfa3f53f894e7a87315e5cbc220e12, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier: Assembly-CSharp::Test.CollisionTest
|
||||
--- !u!1 &1899034788
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
@@ -2884,25 +2898,6 @@ MonoBehaviour:
|
||||
m_Script: {fileID: 11500000, guid: 3481fc2889d14a00a9de205cc39d9c33, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier: Assembly-CSharp::CentimeterBuoyancy
|
||||
waterDensity: 1000
|
||||
buoyancyScale: 2
|
||||
dragScale: 1
|
||||
waterLevel: 0
|
||||
waterLayer:
|
||||
m_Bits: 16
|
||||
showDebugInfo: 1
|
||||
debugColor:
|
||||
r: 0
|
||||
g: 1
|
||||
b: 1
|
||||
a: 1
|
||||
rb: {fileID: 0}
|
||||
objCollider: {fileID: 0}
|
||||
volumeInCm: 0
|
||||
samplePoints: []
|
||||
localBounds:
|
||||
m_Center: {x: 0, y: 0, z: 0}
|
||||
m_Extent: {x: 0, y: 0, z: 0}
|
||||
--- !u!4 &1948332548 stripped
|
||||
Transform:
|
||||
m_CorrespondingSourceObject: {fileID: 8356280719142672529, guid: 84f17dfc7c7a7485296643a4e64d6200, type: 3}
|
||||
@@ -7339,7 +7334,7 @@ MonoBehaviour:
|
||||
uprightAxis: 1
|
||||
extraDragInWater: 0.8
|
||||
extraAngularDragInWater: 0.8
|
||||
Water: {fileID: 2531380344179187550}
|
||||
Water: {fileID: 4652288250947343381}
|
||||
_Layer: 1
|
||||
_ObjectWidth: 0.2
|
||||
drawDebug: 0
|
||||
|
||||
3
Assets/Scripts/Common/Entity.meta
Normal file
3
Assets/Scripts/Common/Entity.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b25d7e65501b49c18f57eec3b4209ad0
|
||||
timeCreated: 1772695059
|
||||
30
Assets/Scripts/Common/Entity/SerializerComponent.cs
Normal file
30
Assets/Scripts/Common/Entity/SerializerComponent.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
// using Fantasy.Entitas;
|
||||
// using Fantasy.Network;
|
||||
// using Fantasy.Serialize;
|
||||
//
|
||||
// namespace NBF
|
||||
// {
|
||||
// public class SerializerComponent : Entity
|
||||
// {
|
||||
// public ISerialize Serialize;
|
||||
// public readonly MemoryStreamBufferPool BufferPool = new MemoryStreamBufferPool();
|
||||
//
|
||||
//
|
||||
// public void Initialize()
|
||||
// {
|
||||
// Serialize = SerializerManager.ProtoBufHelper;
|
||||
// }
|
||||
//
|
||||
// public byte[] Serialize<T>(T @object)
|
||||
// {
|
||||
// using var memoryStreamBuffer = BufferPool.RentMemoryStream(MemoryStreamBufferSource.None);
|
||||
// Serialize.Serialize(typeof(T), @object, memoryStreamBuffer);
|
||||
// return memoryStreamBuffer.ToArray();
|
||||
// }
|
||||
//
|
||||
// public T Deserialize<T>(byte[] bytes)
|
||||
// {
|
||||
// return Serialize.Deserialize<T>(bytes);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
3
Assets/Scripts/Common/Entity/SerializerComponent.cs.meta
Normal file
3
Assets/Scripts/Common/Entity/SerializerComponent.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0a4cb7f8b3fe47e0852a2081f714dec4
|
||||
timeCreated: 1772695064
|
||||
@@ -1,4 +1,5 @@
|
||||
using Fantasy;
|
||||
using System.Text;
|
||||
using Fantasy;
|
||||
using Fantasy.Async;
|
||||
using Fantasy.Network;
|
||||
using Fantasy.Network.Interface;
|
||||
@@ -7,17 +8,54 @@ using Log = NBC.Log;
|
||||
|
||||
namespace NBF
|
||||
{
|
||||
public class Chat2C_MessageHandler : Message<S2C_Message>
|
||||
// public class Chat2C_MessageHandler : Message<S2C_Message>
|
||||
// {
|
||||
// protected override async FTask Run(Session session, S2C_Message message)
|
||||
// {
|
||||
// Log.Info($"收到一条消息推送,message={message.Msg}");
|
||||
// var chatTestPanel = UI.Inst.GetUI<ChatTestPanel>();
|
||||
// if (chatTestPanel != null)
|
||||
// {
|
||||
// chatTestPanel.Message(message.Msg.Content);
|
||||
// }
|
||||
// await FTask.CompletedTask;
|
||||
// }
|
||||
// }
|
||||
|
||||
public sealed class Chat2C_MessageHandler : Message<Chat2C_Message>
|
||||
{
|
||||
protected override async FTask Run(Session session, S2C_Message message)
|
||||
protected override async FTask Run(Session session, Chat2C_Message message)
|
||||
{
|
||||
Log.Info($"收到一条消息推送,message={message.Msg}");
|
||||
var chatTestPanel = UI.Inst.GetUI<ChatTestPanel>();
|
||||
if (chatTestPanel != null)
|
||||
{
|
||||
chatTestPanel.Message(message.Msg.Content);
|
||||
}
|
||||
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 chatTestPanel = UI.Inst.GetUI<ChatTestPanel>();
|
||||
if (chatTestPanel != null)
|
||||
{
|
||||
chatTestPanel.Message(tree);
|
||||
}
|
||||
|
||||
// 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using UnityEngine;
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NBF
|
||||
{
|
||||
@@ -10,11 +11,19 @@ namespace NBF
|
||||
|
||||
public ConfigurableJoint Joint => joint;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
RBody.detectCollisions = true;
|
||||
RBody.collisionDetectionMode = CollisionDetectionMode.ContinuousDynamic;
|
||||
RBody.interpolation = RigidbodyInterpolation.Interpolate;
|
||||
}
|
||||
|
||||
public void SetJoint(Rigidbody rb)
|
||||
{
|
||||
joint.connectedBody = rb;
|
||||
}
|
||||
|
||||
|
||||
public void EnableCollision(bool enable)
|
||||
{
|
||||
if (rBody == null)
|
||||
@@ -22,7 +31,7 @@ namespace NBF
|
||||
rBody = GetComponent<Rigidbody>();
|
||||
}
|
||||
|
||||
rBody.detectCollisions = enable;
|
||||
// rBody.detectCollisions = enable;
|
||||
}
|
||||
|
||||
public void SetKinematic(bool value)
|
||||
@@ -37,5 +46,14 @@ namespace NBF
|
||||
limit = limit
|
||||
};
|
||||
}
|
||||
|
||||
private void OnCollisionEnter(Collision other)
|
||||
{
|
||||
Debug.Log($"OnCollisionEnter:{other.gameObject.name}");
|
||||
}
|
||||
private void OnCollisionExit(Collision other)
|
||||
{
|
||||
Debug.Log($"OnCollisionExit:{other.gameObject.name}");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -62,6 +62,21 @@ namespace NBF
|
||||
return base.onUpdate();
|
||||
}
|
||||
|
||||
// IEnumerator ThrowCoroutine(float distance)
|
||||
// {
|
||||
// float startLength = 0.5f;
|
||||
// Debug.Log($"REST LENGTH : {rope.restLength}");
|
||||
// do
|
||||
// {
|
||||
// float a = Vector3.Distance(rodTipTarget.position, attachedBody.transform.position);
|
||||
// attachedBody.RBody.AddForce(playerForward.Value, ForceMode.VelocityChange);
|
||||
// startLength = Mathf.Max(a, startLength);
|
||||
// UnwindLine(attachedBody.RBody.linearVelocity.magnitude * Time.deltaTime);
|
||||
// yield return null;
|
||||
// }
|
||||
// while ((bool)isBailOpen);
|
||||
// }
|
||||
|
||||
#region 动画回调
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -472,6 +472,30 @@ namespace Fantasy
|
||||
session.Send(S2C_MailState_message);
|
||||
}
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static async FTask<Chat2C_SendMessageResponse> C2Chat_SendMessageRequest(this Session session, C2Chat_SendMessageRequest C2Chat_SendMessageRequest_request)
|
||||
{
|
||||
return (Chat2C_SendMessageResponse)await session.Call(C2Chat_SendMessageRequest_request);
|
||||
}
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static async FTask<Chat2C_SendMessageResponse> C2Chat_SendMessageRequest(this Session session, ChatInfoTree chatInfoTree)
|
||||
{
|
||||
using var C2Chat_SendMessageRequest_request = Fantasy.C2Chat_SendMessageRequest.Create();
|
||||
C2Chat_SendMessageRequest_request.ChatInfoTree = chatInfoTree;
|
||||
return (Chat2C_SendMessageResponse)await session.Call(C2Chat_SendMessageRequest_request);
|
||||
}
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void Chat2C_Message(this Session session, Chat2C_Message Chat2C_Message_message)
|
||||
{
|
||||
session.Send(Chat2C_Message_message);
|
||||
}
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void Chat2C_Message(this Session session, ChatInfoTree chatInfoTree)
|
||||
{
|
||||
using var Chat2C_Message_message = Fantasy.Chat2C_Message.Create();
|
||||
Chat2C_Message_message.ChatInfoTree = chatInfoTree;
|
||||
session.Send(Chat2C_Message_message);
|
||||
}
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static async FTask<S2C_CreateChannelResponse> C2S_CreateChannelRequest(this Session session, C2S_CreateChannelRequest C2S_CreateChannelRequest_request)
|
||||
{
|
||||
return (S2C_CreateChannelResponse)await session.Call(C2S_CreateChannelRequest_request);
|
||||
|
||||
@@ -903,7 +903,7 @@ namespace Fantasy
|
||||
public uint ErrorCode { get; set; }
|
||||
}
|
||||
/// <summary>
|
||||
/// 奖励推送
|
||||
/// 活动奖励推送
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
[ProtoContract]
|
||||
@@ -2839,7 +2839,398 @@ namespace Fantasy
|
||||
[ProtoMember(2)]
|
||||
public long MailId { get; set; }
|
||||
}
|
||||
/// <summary>
|
||||
/// 发送一个聊天消息给Chat服务器,中间是经过Gate中转的
|
||||
/// </summary>
|
||||
////////// ******** 频道聊天 *******/////////////
|
||||
[Serializable]
|
||||
[ProtoContract]
|
||||
public partial class C2Chat_SendMessageRequest : AMessage, ICustomRouteRequest
|
||||
{
|
||||
public static C2Chat_SendMessageRequest Create(bool autoReturn = true)
|
||||
{
|
||||
var c2Chat_SendMessageRequest = MessageObjectPool<C2Chat_SendMessageRequest>.Rent();
|
||||
c2Chat_SendMessageRequest.AutoReturn = autoReturn;
|
||||
|
||||
if (!autoReturn)
|
||||
{
|
||||
c2Chat_SendMessageRequest.SetIsPool(false);
|
||||
}
|
||||
|
||||
return c2Chat_SendMessageRequest;
|
||||
}
|
||||
|
||||
public void Return()
|
||||
{
|
||||
if (!AutoReturn)
|
||||
{
|
||||
SetIsPool(true);
|
||||
AutoReturn = true;
|
||||
}
|
||||
else if (!IsPool())
|
||||
{
|
||||
return;
|
||||
}
|
||||
Dispose();
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (!IsPool()) return;
|
||||
if (ChatInfoTree != null)
|
||||
{
|
||||
ChatInfoTree.Dispose();
|
||||
ChatInfoTree = null;
|
||||
}
|
||||
MessageObjectPool<C2Chat_SendMessageRequest>.Return(this);
|
||||
}
|
||||
public uint OpCode() { return OuterOpcode.C2Chat_SendMessageRequest; }
|
||||
[ProtoIgnore]
|
||||
public Chat2C_SendMessageResponse ResponseType { get; set; }
|
||||
[ProtoIgnore]
|
||||
public int RouteType => Fantasy.RouteType.SocialRoute;
|
||||
[ProtoMember(1)]
|
||||
public ChatInfoTree ChatInfoTree { get; set; }
|
||||
}
|
||||
[Serializable]
|
||||
[ProtoContract]
|
||||
public partial class Chat2C_SendMessageResponse : AMessage, ICustomRouteResponse
|
||||
{
|
||||
public static Chat2C_SendMessageResponse Create(bool autoReturn = true)
|
||||
{
|
||||
var chat2C_SendMessageResponse = MessageObjectPool<Chat2C_SendMessageResponse>.Rent();
|
||||
chat2C_SendMessageResponse.AutoReturn = autoReturn;
|
||||
|
||||
if (!autoReturn)
|
||||
{
|
||||
chat2C_SendMessageResponse.SetIsPool(false);
|
||||
}
|
||||
|
||||
return chat2C_SendMessageResponse;
|
||||
}
|
||||
|
||||
public void Return()
|
||||
{
|
||||
if (!AutoReturn)
|
||||
{
|
||||
SetIsPool(true);
|
||||
AutoReturn = true;
|
||||
}
|
||||
else if (!IsPool())
|
||||
{
|
||||
return;
|
||||
}
|
||||
Dispose();
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (!IsPool()) return;
|
||||
ErrorCode = 0;
|
||||
MessageObjectPool<Chat2C_SendMessageResponse>.Return(this);
|
||||
}
|
||||
public uint OpCode() { return OuterOpcode.Chat2C_SendMessageResponse; }
|
||||
[ProtoMember(1)]
|
||||
public uint ErrorCode { get; set; }
|
||||
}
|
||||
[Serializable]
|
||||
[ProtoContract]
|
||||
public partial class Chat2C_Message : AMessage, ICustomRouteMessage
|
||||
{
|
||||
public static Chat2C_Message Create(bool autoReturn = true)
|
||||
{
|
||||
var chat2C_Message = MessageObjectPool<Chat2C_Message>.Rent();
|
||||
chat2C_Message.AutoReturn = autoReturn;
|
||||
|
||||
if (!autoReturn)
|
||||
{
|
||||
chat2C_Message.SetIsPool(false);
|
||||
}
|
||||
|
||||
return chat2C_Message;
|
||||
}
|
||||
|
||||
public void Return()
|
||||
{
|
||||
if (!AutoReturn)
|
||||
{
|
||||
SetIsPool(true);
|
||||
AutoReturn = true;
|
||||
}
|
||||
else if (!IsPool())
|
||||
{
|
||||
return;
|
||||
}
|
||||
Dispose();
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (!IsPool()) return;
|
||||
if (ChatInfoTree != null)
|
||||
{
|
||||
ChatInfoTree.Dispose();
|
||||
ChatInfoTree = null;
|
||||
}
|
||||
MessageObjectPool<Chat2C_Message>.Return(this);
|
||||
}
|
||||
public uint OpCode() { return OuterOpcode.Chat2C_Message; }
|
||||
[ProtoIgnore]
|
||||
public int RouteType => Fantasy.RouteType.SocialRoute;
|
||||
[ProtoMember(1)]
|
||||
public ChatInfoTree ChatInfoTree { get; set; }
|
||||
}
|
||||
/// <summary>
|
||||
/// 聊天消息树
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
[ProtoContract]
|
||||
public partial class ChatInfoTree : AMessage, IDisposable
|
||||
{
|
||||
public static ChatInfoTree Create(bool autoReturn = true)
|
||||
{
|
||||
var chatInfoTree = MessageObjectPool<ChatInfoTree>.Rent();
|
||||
chatInfoTree.AutoReturn = autoReturn;
|
||||
|
||||
if (!autoReturn)
|
||||
{
|
||||
chatInfoTree.SetIsPool(false);
|
||||
}
|
||||
|
||||
return chatInfoTree;
|
||||
}
|
||||
|
||||
public void Return()
|
||||
{
|
||||
if (!AutoReturn)
|
||||
{
|
||||
SetIsPool(true);
|
||||
AutoReturn = true;
|
||||
}
|
||||
else if (!IsPool())
|
||||
{
|
||||
return;
|
||||
}
|
||||
Dispose();
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (!IsPool()) return;
|
||||
ChatChannelType = default;
|
||||
ChatChannelId = default;
|
||||
UnitId = default;
|
||||
UserName = default;
|
||||
Target.Clear();
|
||||
Node.Clear();
|
||||
MessageObjectPool<ChatInfoTree>.Return(this);
|
||||
}
|
||||
[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 { get; set; } = new List<long>();
|
||||
[ProtoMember(6)]
|
||||
public List<ChatInfoNode> Node { get; set; } = new List<ChatInfoNode>();
|
||||
}
|
||||
/// <summary>
|
||||
/// 聊天信息节点
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
[ProtoContract]
|
||||
public partial class ChatInfoNode : AMessage, IDisposable
|
||||
{
|
||||
public static ChatInfoNode Create(bool autoReturn = true)
|
||||
{
|
||||
var chatInfoNode = MessageObjectPool<ChatInfoNode>.Rent();
|
||||
chatInfoNode.AutoReturn = autoReturn;
|
||||
|
||||
if (!autoReturn)
|
||||
{
|
||||
chatInfoNode.SetIsPool(false);
|
||||
}
|
||||
|
||||
return chatInfoNode;
|
||||
}
|
||||
|
||||
public void Return()
|
||||
{
|
||||
if (!AutoReturn)
|
||||
{
|
||||
SetIsPool(true);
|
||||
AutoReturn = true;
|
||||
}
|
||||
else if (!IsPool())
|
||||
{
|
||||
return;
|
||||
}
|
||||
Dispose();
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (!IsPool()) return;
|
||||
ChatNodeType = default;
|
||||
ChatNodeEvent = default;
|
||||
Content = default;
|
||||
Color = default;
|
||||
Data = null;
|
||||
MessageObjectPool<ChatInfoNode>.Return(this);
|
||||
}
|
||||
[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>
|
||||
[Serializable]
|
||||
[ProtoContract]
|
||||
public partial class ChatPositionNode : AMessage, IDisposable
|
||||
{
|
||||
public static ChatPositionNode Create(bool autoReturn = true)
|
||||
{
|
||||
var chatPositionNode = MessageObjectPool<ChatPositionNode>.Rent();
|
||||
chatPositionNode.AutoReturn = autoReturn;
|
||||
|
||||
if (!autoReturn)
|
||||
{
|
||||
chatPositionNode.SetIsPool(false);
|
||||
}
|
||||
|
||||
return chatPositionNode;
|
||||
}
|
||||
|
||||
public void Return()
|
||||
{
|
||||
if (!AutoReturn)
|
||||
{
|
||||
SetIsPool(true);
|
||||
AutoReturn = true;
|
||||
}
|
||||
else if (!IsPool())
|
||||
{
|
||||
return;
|
||||
}
|
||||
Dispose();
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (!IsPool()) return;
|
||||
MapName = default;
|
||||
PosX = default;
|
||||
PosY = default;
|
||||
PosZ = default;
|
||||
MessageObjectPool<ChatPositionNode>.Return(this);
|
||||
}
|
||||
[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>
|
||||
[Serializable]
|
||||
[ProtoContract]
|
||||
public partial class ChatOpenUINode : AMessage, IDisposable
|
||||
{
|
||||
public static ChatOpenUINode Create(bool autoReturn = true)
|
||||
{
|
||||
var chatOpenUINode = MessageObjectPool<ChatOpenUINode>.Rent();
|
||||
chatOpenUINode.AutoReturn = autoReturn;
|
||||
|
||||
if (!autoReturn)
|
||||
{
|
||||
chatOpenUINode.SetIsPool(false);
|
||||
}
|
||||
|
||||
return chatOpenUINode;
|
||||
}
|
||||
|
||||
public void Return()
|
||||
{
|
||||
if (!AutoReturn)
|
||||
{
|
||||
SetIsPool(true);
|
||||
AutoReturn = true;
|
||||
}
|
||||
else if (!IsPool())
|
||||
{
|
||||
return;
|
||||
}
|
||||
Dispose();
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (!IsPool()) return;
|
||||
UIName = default;
|
||||
MessageObjectPool<ChatOpenUINode>.Return(this);
|
||||
}
|
||||
[ProtoMember(1)]
|
||||
public string UIName { get; set; }
|
||||
}
|
||||
/// <summary>
|
||||
/// 聊天连接信息节点
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
[ProtoContract]
|
||||
public partial class ChatLinkNode : AMessage, IDisposable
|
||||
{
|
||||
public static ChatLinkNode Create(bool autoReturn = true)
|
||||
{
|
||||
var chatLinkNode = MessageObjectPool<ChatLinkNode>.Rent();
|
||||
chatLinkNode.AutoReturn = autoReturn;
|
||||
|
||||
if (!autoReturn)
|
||||
{
|
||||
chatLinkNode.SetIsPool(false);
|
||||
}
|
||||
|
||||
return chatLinkNode;
|
||||
}
|
||||
|
||||
public void Return()
|
||||
{
|
||||
if (!AutoReturn)
|
||||
{
|
||||
SetIsPool(true);
|
||||
AutoReturn = true;
|
||||
}
|
||||
else if (!IsPool())
|
||||
{
|
||||
return;
|
||||
}
|
||||
Dispose();
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (!IsPool()) return;
|
||||
Link = default;
|
||||
MessageObjectPool<ChatLinkNode>.Return(this);
|
||||
}
|
||||
[ProtoMember(1)]
|
||||
public string Link { get; set; }
|
||||
}
|
||||
[Serializable]
|
||||
[ProtoContract]
|
||||
public partial class ChatUserInfo : AMessage, IDisposable
|
||||
@@ -4485,7 +4876,7 @@ namespace Fantasy
|
||||
MessageObjectPool<AwardInfo>.Return(this);
|
||||
}
|
||||
[ProtoMember(1)]
|
||||
public int ConfigId { get; set; }
|
||||
public long ConfigId { get; set; }
|
||||
[ProtoMember(2)]
|
||||
public int Count { get; set; }
|
||||
}
|
||||
@@ -4646,7 +5037,7 @@ namespace Fantasy
|
||||
[ProtoMember(4)]
|
||||
public uint Sort { get; set; }
|
||||
[ProtoMember(5)]
|
||||
public string Tag { get; set; }
|
||||
public uint Tag { get; set; }
|
||||
}
|
||||
/// <summary>
|
||||
/// fish信息
|
||||
|
||||
@@ -61,29 +61,32 @@ namespace Fantasy
|
||||
public const uint S2C_DeleteMailResponse = 2415929119;
|
||||
public const uint S2C_HaveMail = 2147493663;
|
||||
public const uint S2C_MailState = 2147493664;
|
||||
public const uint C2S_CreateChannelRequest = 2281711392;
|
||||
public const uint S2C_CreateChannelResponse = 2415929120;
|
||||
public const uint C2S_JoinChannelRequest = 2281711393;
|
||||
public const uint S2C_JoinChannelResponse = 2415929121;
|
||||
public const uint C2S_SendMessageRequest = 2281711394;
|
||||
public const uint S2C_SendMessageResponse = 2415929122;
|
||||
public const uint S2C_Message = 2147493665;
|
||||
public const uint C2S_CreateClubRequest = 2281711395;
|
||||
public const uint S2C_CreateClubResponse = 2415929123;
|
||||
public const uint C2S_GetClubInfoRequest = 2281711396;
|
||||
public const uint S2C_GetClubInfoResponse = 2415929124;
|
||||
public const uint C2S_GetMemberListRequest = 2281711397;
|
||||
public const uint S2C_GetMemberListResponse = 2415929125;
|
||||
public const uint C2S_GetClubListRequest = 2281711398;
|
||||
public const uint S2C_GetClubListResponse = 2415929126;
|
||||
public const uint C2S_JoinClubRequest = 2281711399;
|
||||
public const uint S2C_JoinClubResponse = 2415929127;
|
||||
public const uint C2S_LeaveClubRequest = 2281711400;
|
||||
public const uint S2C_LeaveClubResponse = 2415929128;
|
||||
public const uint C2S_DissolveClubRequest = 2281711401;
|
||||
public const uint S2C_DissolveClubResponse = 2415929129;
|
||||
public const uint C2S_DisposeJoinRequest = 2281711402;
|
||||
public const uint S2C_DisposeJoinResponse = 2415929130;
|
||||
public const uint S2C_ClubChange = 2147493666;
|
||||
public const uint C2Chat_SendMessageRequest = 2281711392;
|
||||
public const uint Chat2C_SendMessageResponse = 2415929120;
|
||||
public const uint Chat2C_Message = 2147493665;
|
||||
public const uint C2S_CreateChannelRequest = 2281711393;
|
||||
public const uint S2C_CreateChannelResponse = 2415929121;
|
||||
public const uint C2S_JoinChannelRequest = 2281711394;
|
||||
public const uint S2C_JoinChannelResponse = 2415929122;
|
||||
public const uint C2S_SendMessageRequest = 2281711395;
|
||||
public const uint S2C_SendMessageResponse = 2415929123;
|
||||
public const uint S2C_Message = 2147493666;
|
||||
public const uint C2S_CreateClubRequest = 2281711396;
|
||||
public const uint S2C_CreateClubResponse = 2415929124;
|
||||
public const uint C2S_GetClubInfoRequest = 2281711397;
|
||||
public const uint S2C_GetClubInfoResponse = 2415929125;
|
||||
public const uint C2S_GetMemberListRequest = 2281711398;
|
||||
public const uint S2C_GetMemberListResponse = 2415929126;
|
||||
public const uint C2S_GetClubListRequest = 2281711399;
|
||||
public const uint S2C_GetClubListResponse = 2415929127;
|
||||
public const uint C2S_JoinClubRequest = 2281711400;
|
||||
public const uint S2C_JoinClubResponse = 2415929128;
|
||||
public const uint C2S_LeaveClubRequest = 2281711401;
|
||||
public const uint S2C_LeaveClubResponse = 2415929129;
|
||||
public const uint C2S_DissolveClubRequest = 2281711402;
|
||||
public const uint S2C_DissolveClubResponse = 2415929130;
|
||||
public const uint C2S_DisposeJoinRequest = 2281711403;
|
||||
public const uint S2C_DisposeJoinResponse = 2415929131;
|
||||
public const uint S2C_ClubChange = 2147493667;
|
||||
}
|
||||
}
|
||||
@@ -12,6 +12,7 @@ namespace Test
|
||||
public float lineLength = 1f;
|
||||
public float floatLength = 0.5f;
|
||||
|
||||
public float Tension = 0;
|
||||
public void Start()
|
||||
{
|
||||
line.InitTest(rb);
|
||||
@@ -20,5 +21,49 @@ namespace Test
|
||||
line.Bobber.SetJointDistance(lineLength - floatLength);
|
||||
line.SetObiRopeStretch(lineLength - floatLength);
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (Input.GetKeyDown(KeyCode.Alpha0))
|
||||
{
|
||||
SetLineLength(lineLength);
|
||||
}
|
||||
else if (Input.GetKeyDown(KeyCode.Plus) || Input.GetKeyDown(KeyCode.Equals))
|
||||
{
|
||||
lineLength += 0.1f;
|
||||
SetLineLength(lineLength);
|
||||
}
|
||||
else if (Input.GetKeyDown(KeyCode.Minus))
|
||||
{
|
||||
lineLength -= 0.1f;
|
||||
SetLineLength(lineLength);
|
||||
}
|
||||
}
|
||||
|
||||
public void SetLineLength(float lineLength, bool stretchRope = true)
|
||||
{
|
||||
Debug.Log($"lineLength={lineLength}");
|
||||
if (!line) return;
|
||||
if (line.IsLure)
|
||||
{
|
||||
//没有浮漂类型
|
||||
line.Lure.SetJointDistance(lineLength);
|
||||
if (stretchRope)
|
||||
{
|
||||
line.SetObiRopeStretch(Tension > 0f ? 0f : lineLength);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//有浮漂
|
||||
line.Lure.SetJointDistance(floatLength);
|
||||
line.Bobber.SetJointDistance(lineLength - floatLength);
|
||||
if (stretchRope)
|
||||
{
|
||||
line.SetObiRopeStretch(Tension > 0f ? 0f : lineLength - floatLength);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
16
Assets/Scripts/Test/CollisionTest.cs
Normal file
16
Assets/Scripts/Test/CollisionTest.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace Test
|
||||
{
|
||||
public class CollisionTest : MonoBehaviour
|
||||
{
|
||||
private void OnCollisionEnter(Collision other)
|
||||
{
|
||||
Debug.Log($"OnCollisionEnter:{other.gameObject.name}");
|
||||
}
|
||||
private void OnCollisionExit(Collision other)
|
||||
{
|
||||
Debug.Log($"OnCollisionExit:{other.gameObject.name}");
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/Test/CollisionTest.cs.meta
Normal file
3
Assets/Scripts/Test/CollisionTest.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d5bfa3f53f894e7a87315e5cbc220e12
|
||||
timeCreated: 1772767361
|
||||
3
Assets/Scripts/UI/Chat.meta
Normal file
3
Assets/Scripts/UI/Chat.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6169cecd85b9472e989a7ef14fc83964
|
||||
timeCreated: 1772694660
|
||||
52
Assets/Scripts/UI/Chat/ChatChannelType.cs
Normal file
52
Assets/Scripts/UI/Chat/ChatChannelType.cs
Normal 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, // 位置节点
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/UI/Chat/ChatChannelType.cs.meta
Normal file
3
Assets/Scripts/UI/Chat/ChatChannelType.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4ec94d1a6ab744c4bdcff56d8da8e6ea
|
||||
timeCreated: 1772694755
|
||||
16
Assets/Scripts/UI/Chat/ChatInfoTree.cs
Normal file
16
Assets/Scripts/UI/Chat/ChatInfoTree.cs
Normal 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; }
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/UI/Chat/ChatInfoTree.cs.meta
Normal file
3
Assets/Scripts/UI/Chat/ChatInfoTree.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 73e6060aebcd46eca52cd4086e193fb3
|
||||
timeCreated: 1772694724
|
||||
82
Assets/Scripts/UI/Chat/ChatNodeEventHelper.cs
Normal file
82
Assets/Scripts/UI/Chat/ChatNodeEventHelper.cs
Normal 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
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/UI/Chat/ChatNodeEventHelper.cs.meta
Normal file
3
Assets/Scripts/UI/Chat/ChatNodeEventHelper.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7bcf5d11cea04d86a8a9c5c3fce31ed8
|
||||
timeCreated: 1772694878
|
||||
130
Assets/Scripts/UI/Chat/ChatNodeFactory.cs
Normal file
130
Assets/Scripts/UI/Chat/ChatNodeFactory.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/UI/Chat/ChatNodeFactory.cs.meta
Normal file
3
Assets/Scripts/UI/Chat/ChatNodeFactory.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bbf26a0aef9841f89db6182475f50e59
|
||||
timeCreated: 1772694930
|
||||
@@ -16,14 +16,6 @@ namespace NBF
|
||||
|
||||
[AutoFind(Name = "back")]
|
||||
public GImage back;
|
||||
[AutoFind(Name = "TextLoginInfo")]
|
||||
public GTextField TextLoginInfo;
|
||||
[AutoFind(Name = "InputAccount")]
|
||||
public GLabel InputAccount;
|
||||
[AutoFind(Name = "BtnLogout")]
|
||||
public GButton BtnLogout;
|
||||
[AutoFind(Name = "BtnLogin")]
|
||||
public GButton BtnLogin;
|
||||
[AutoFind(Name = "InputMessage")]
|
||||
public GLabel InputMessage;
|
||||
[AutoFind(Name = "BtnSendMessage")]
|
||||
@@ -34,6 +26,8 @@ namespace NBF
|
||||
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); }
|
||||
115
Assets/Scripts/UI/Chat/ChatTestPanel.cs
Normal file
115
Assets/Scripts/UI/Chat/ChatTestPanel.cs
Normal 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
|
||||
}
|
||||
}
|
||||
121
Assets/Scripts/UI/Chat/ChatTreeFactory.cs
Normal file
121
Assets/Scripts/UI/Chat/ChatTreeFactory.cs
Normal 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,
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/UI/Chat/ChatTreeFactory.cs.meta
Normal file
3
Assets/Scripts/UI/Chat/ChatTreeFactory.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f028a29029d74cbf8c264a7d4a245ecf
|
||||
timeCreated: 1772694684
|
||||
@@ -1,179 +0,0 @@
|
||||
// 本脚本只在不存在时会生成一次。已存在不会再次生成覆盖
|
||||
|
||||
using System.Collections.Generic;
|
||||
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()
|
||||
{
|
||||
SetLoginState(false);
|
||||
}
|
||||
|
||||
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 == BtnLogin)
|
||||
{
|
||||
if (string.IsNullOrEmpty(InputAccount.text))
|
||||
{
|
||||
Notices.Info("没有输入账号密码");
|
||||
return;
|
||||
}
|
||||
|
||||
OnLoginButtonClick(InputAccount.text).Coroutine();
|
||||
}
|
||||
else if (btn == BtnSendWorld)
|
||||
{
|
||||
OnSendMessage(InputMessage.title).Coroutine();
|
||||
}
|
||||
}
|
||||
|
||||
private void SetLoginState(bool isLogin = false, string account = "")
|
||||
{
|
||||
if (isLogin)
|
||||
{
|
||||
BtnLogin.visible = false;
|
||||
BtnLogout.visible = true;
|
||||
TextLoginInfo.text = account;
|
||||
}
|
||||
else
|
||||
{
|
||||
BtnLogin.visible = true;
|
||||
BtnLogout.visible = false;
|
||||
}
|
||||
}
|
||||
|
||||
#region 登录测试
|
||||
|
||||
private Session _session;
|
||||
|
||||
private async FTask OnLoginButtonClick(string account)
|
||||
{
|
||||
// NBC.Platform.Unity.Entry.Initialize(GetType().Assembly);
|
||||
|
||||
// 根据用户名来选择目标的鉴权服务器
|
||||
// 根据鉴权服务器地址来创建一个新的网络会话
|
||||
_session = SessionHelper.CreateSession(Game.Main, "127.0.0.1:20001", OnConnectComplete,
|
||||
OnConnectFail,
|
||||
OnConnectDisconnect);
|
||||
|
||||
var acc = account;
|
||||
|
||||
// 发送登录的请求给服务器
|
||||
var response = (A2C_LoginResponse)await _session.Call(new C2A_LoginRequest()
|
||||
{
|
||||
Username = acc,
|
||||
Password = acc,
|
||||
LoginType = 1
|
||||
});
|
||||
|
||||
if (response.ErrorCode != 0)
|
||||
{
|
||||
Log.Error($"登录发生错误{response.ErrorCode}");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!Game.Main.GetComponent<JWTParseComponent>().Parse(response.ToKen, out var payload))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// 根据ToKen返回的Address登录到Gate服务器
|
||||
_session = SessionHelper.CreateSession(Game.Main, payload.Address, OnConnectComplete, OnConnectFail,
|
||||
OnConnectDisconnect);
|
||||
// 发送登录请求到Gate服务器
|
||||
var loginResponse = (G2C_LoginResponse)await _session.Call(new C2G_LoginRequest()
|
||||
{
|
||||
ToKen = response.ToKen
|
||||
});
|
||||
if (loginResponse.ErrorCode != 0)
|
||||
{
|
||||
Log.Error($"登录发生错误{loginResponse.ErrorCode}");
|
||||
return;
|
||||
}
|
||||
|
||||
SetLoginState(true, InputAccount.text);
|
||||
Log.Info(
|
||||
$"登录到Gate服务器成功!ErrorCode:{loginResponse.ErrorCode}");
|
||||
// Log.Debug(
|
||||
// $"登录到Gate服务器成功!LoginTime:{loginResponse.GameAccountInfo.LoginTime} CreateTime:{loginResponse.GameAccountInfo.CreateTime}");
|
||||
|
||||
// var getResponse = (G2C_GetAccountInfoResponse)await _session.Call(new C2G_GetAccountInfoRequest());
|
||||
// var gameAcc = getResponse.GameAccountInfo;
|
||||
// Log.Info($"gameAcc LoginTime:{gameAcc.LoginTime} CreateTime:{gameAcc.CreateTime}");
|
||||
// getResponse.GameAccountInfo.LoginTime.ToString()
|
||||
}
|
||||
|
||||
private void OnConnectComplete()
|
||||
{
|
||||
Log.Info("连接成功");
|
||||
// 添加心跳组件给Session。
|
||||
// Start(2000)就是2000毫秒。
|
||||
_session.AddComponent<SessionHeartbeatComponent>().Start(5000);
|
||||
}
|
||||
|
||||
private void OnConnectFail()
|
||||
{
|
||||
Log.Info("连接失败");
|
||||
SetLoginState(false);
|
||||
}
|
||||
|
||||
private void OnConnectDisconnect()
|
||||
{
|
||||
Log.Info("连接断开");
|
||||
SetLoginState(false);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 发生消息测试
|
||||
|
||||
private async FTask OnSendMessage(string message)
|
||||
{
|
||||
var messageResponse = (S2C_SendMessageResponse)await _session.Call(new C2S_SendMessageRequest()
|
||||
{
|
||||
Message = message
|
||||
});
|
||||
if (messageResponse.ErrorCode != 0)
|
||||
{
|
||||
Notices.Info($"发送消息失败,code={messageResponse.ErrorCode}");
|
||||
}
|
||||
}
|
||||
|
||||
public void Message(string message)
|
||||
{
|
||||
_messages.Add(message);
|
||||
RefreshList();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -32,7 +32,9 @@ namespace NBF
|
||||
{
|
||||
await LoginHelper.Login(InputAccount.text);
|
||||
|
||||
await Fishing.Instance.Go(RoleModel.Instance.Info.MapId);
|
||||
// await Fishing.Instance.Go(RoleModel.Instance.Info.MapId);
|
||||
|
||||
ChatTestPanel.Show();
|
||||
|
||||
// FishingShopPanel.Show();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user