This commit is contained in:
huyulong 2024-12-04 15:05:38 +08:00
parent 1345268590
commit 5baf3a71b5
66 changed files with 26074 additions and 4 deletions

View File

@ -2,10 +2,10 @@ using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CharacterAttribute : MonoBehaviour
public class CharacterAttribute
{
[Header("需要显示的")]
public int hp;//Ѫ<><D1AA>
public float hp;//Ѫ<><D1AA>
public int defend;//抗火
[Header("内部数据")]

View File

@ -0,0 +1,40 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerState : MonoBehaviour
{
[Header("鯤소悧沂좆")]
public float totalHp;
[Header("鯤소뎠품沂좆")]
public float currentHp;
[Header("둬예제")]
public float defend;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
public void beHurt(int hurt)
{
Debug.Log(currentHp -= hurt);
if(currentHp <= 0)
{
Debug.Log("콱价죄");
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 95a6a9a5d2e4ad24da328a2ea07ab37c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

@ -1 +0,0 @@
Subproject commit b5b0154db30b63c14cba8a3a8633d1684f907a9f

View File

@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 910847e8e0fbf8d46a30f26382e00051
guid: 337af4673c7b99248a6164040f94dbb9
folderAsset: yes
DefaultImporter:
externalObjects: {}

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 238d5690fe411f84da0c68ad5efd0d81
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,281 @@
// <auto-generated>
// Generated by the protocol buffer compiler. DO NOT EDIT!
// source: common.proto
// </auto-generated>
#pragma warning disable 1591, 0612, 3021, 8981
#region Designer generated code
using pb = global::Google.Protobuf;
using pbc = global::Google.Protobuf.Collections;
using pbr = global::Google.Protobuf.Reflection;
using scg = global::System.Collections.Generic;
/// <summary>Holder for reflection information generated from common.proto</summary>
public static partial class CommonReflection {
#region Descriptor
/// <summary>File descriptor for common.proto</summary>
public static pbr::FileDescriptor Descriptor {
get { return descriptor; }
}
private static pbr::FileDescriptor descriptor;
static CommonReflection() {
byte[] descriptorData = global::System.Convert.FromBase64String(
string.Concat(
"Cgxjb21tb24ucHJvdG8iLgoNUmVzdWx0TWVzc2FnZRIMCgRjb2RlGAEgASgF",
"Eg8KB21lc3NhZ2UYAiABKAlCB1oFLi87cGJiBnByb3RvMw=="));
descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData,
new pbr::FileDescriptor[] { },
new pbr::GeneratedClrTypeInfo(null, null, new pbr::GeneratedClrTypeInfo[] {
new pbr::GeneratedClrTypeInfo(typeof(global::ResultMessage), global::ResultMessage.Parser, new[]{ "Code", "Message" }, null, null, null, null)
}));
}
#endregion
}
#region Messages
[global::System.Diagnostics.DebuggerDisplayAttribute("{ToString(),nq}")]
public sealed partial class ResultMessage : pb::IMessage<ResultMessage>
#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
, pb::IBufferMessage
#endif
{
private static readonly pb::MessageParser<ResultMessage> _parser = new pb::MessageParser<ResultMessage>(() => new ResultMessage());
private pb::UnknownFieldSet _unknownFields;
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public static pb::MessageParser<ResultMessage> Parser { get { return _parser; } }
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public static pbr::MessageDescriptor Descriptor {
get { return global::CommonReflection.Descriptor.MessageTypes[0]; }
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
pbr::MessageDescriptor pb::IMessage.Descriptor {
get { return Descriptor; }
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public ResultMessage() {
OnConstruction();
}
partial void OnConstruction();
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public ResultMessage(ResultMessage other) : this() {
code_ = other.code_;
message_ = other.message_;
_unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public ResultMessage Clone() {
return new ResultMessage(this);
}
/// <summary>Field number for the "code" field.</summary>
public const int CodeFieldNumber = 1;
private int code_;
/// <summary>
/// 错误码
/// </summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public int Code {
get { return code_; }
set {
code_ = value;
}
}
/// <summary>Field number for the "message" field.</summary>
public const int MessageFieldNumber = 2;
private string message_ = "";
/// <summary>
/// 错误信息
/// </summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public string Message {
get { return message_; }
set {
message_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
}
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public override bool Equals(object other) {
return Equals(other as ResultMessage);
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public bool Equals(ResultMessage other) {
if (ReferenceEquals(other, null)) {
return false;
}
if (ReferenceEquals(other, this)) {
return true;
}
if (Code != other.Code) return false;
if (Message != other.Message) return false;
return Equals(_unknownFields, other._unknownFields);
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public override int GetHashCode() {
int hash = 1;
if (Code != 0) hash ^= Code.GetHashCode();
if (Message.Length != 0) hash ^= Message.GetHashCode();
if (_unknownFields != null) {
hash ^= _unknownFields.GetHashCode();
}
return hash;
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public override string ToString() {
return pb::JsonFormatter.ToDiagnosticString(this);
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public void WriteTo(pb::CodedOutputStream output) {
#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
output.WriteRawMessage(this);
#else
if (Code != 0) {
output.WriteRawTag(8);
output.WriteInt32(Code);
}
if (Message.Length != 0) {
output.WriteRawTag(18);
output.WriteString(Message);
}
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
#endif
}
#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
if (Code != 0) {
output.WriteRawTag(8);
output.WriteInt32(Code);
}
if (Message.Length != 0) {
output.WriteRawTag(18);
output.WriteString(Message);
}
if (_unknownFields != null) {
_unknownFields.WriteTo(ref output);
}
}
#endif
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public int CalculateSize() {
int size = 0;
if (Code != 0) {
size += 1 + pb::CodedOutputStream.ComputeInt32Size(Code);
}
if (Message.Length != 0) {
size += 1 + pb::CodedOutputStream.ComputeStringSize(Message);
}
if (_unknownFields != null) {
size += _unknownFields.CalculateSize();
}
return size;
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public void MergeFrom(ResultMessage other) {
if (other == null) {
return;
}
if (other.Code != 0) {
Code = other.Code;
}
if (other.Message.Length != 0) {
Message = other.Message;
}
_unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public void MergeFrom(pb::CodedInputStream input) {
#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
input.ReadRawMessage(this);
#else
uint tag;
while ((tag = input.ReadTag()) != 0) {
if ((tag & 7) == 4) {
// Abort on any end group tag.
return;
}
switch(tag) {
default:
_unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
break;
case 8: {
Code = input.ReadInt32();
break;
}
case 18: {
Message = input.ReadString();
break;
}
}
}
#endif
}
#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) {
uint tag;
while ((tag = input.ReadTag()) != 0) {
if ((tag & 7) == 4) {
// Abort on any end group tag.
return;
}
switch(tag) {
default:
_unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input);
break;
case 8: {
Code = input.ReadInt32();
break;
}
case 18: {
Message = input.ReadString();
break;
}
}
}
}
#endif
}
#endregion
#endregion Designer generated code

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 8f08a6ce1ce72944ab924e71bac47c6f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,83 @@
// <auto-generated>
// Generated by the protocol buffer compiler. DO NOT EDIT!
// source: config.proto
// </auto-generated>
#pragma warning disable 1591, 0612, 3021, 8981
#region Designer generated code
using pb = global::Google.Protobuf;
using pbc = global::Google.Protobuf.Collections;
using pbr = global::Google.Protobuf.Reflection;
using scg = global::System.Collections.Generic;
/// <summary>Holder for reflection information generated from config.proto</summary>
public static partial class ConfigReflection {
#region Descriptor
/// <summary>File descriptor for config.proto</summary>
public static pbr::FileDescriptor Descriptor {
get { return descriptor; }
}
private static pbr::FileDescriptor descriptor;
static ConfigReflection() {
byte[] descriptorData = global::System.Convert.FromBase64String(
string.Concat(
"Cgxjb25maWcucHJvdG8qnQEKCkVSUk9SX0NPREUSCgoGRVJSX09rEAASEAoM",
"RVJSX05vUGxheWVyEAESDgoKRVJSX05vUm9vbRACEg0KCUVSUl9Ub2tlbhAE",
"Eg0KCUVSUl9Mb2dpbhAFEg4KCkVSUl9BY3Rpb24QBhIOCgpFUlJfUGFyYW1z",
"EAcSDgoKRVJSX1NlcnZlchAIEhMKD0VSUl9Ob0F1dGhvcml0eRAJQgdaBS4v",
"O3BiYgZwcm90bzM="));
descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData,
new pbr::FileDescriptor[] { },
new pbr::GeneratedClrTypeInfo(new[] {typeof(global::ERROR_CODE), }, null, null));
}
#endregion
}
#region Enums
/// <summary>
///错误码
/// </summary>
public enum ERROR_CODE {
/// <summary>
///OK
/// </summary>
[pbr::OriginalName("ERR_Ok")] ErrOk = 0,
/// <summary>
///没有这个玩家
/// </summary>
[pbr::OriginalName("ERR_NoPlayer")] ErrNoPlayer = 1,
/// <summary>
///加入房间失败
/// </summary>
[pbr::OriginalName("ERR_NoRoom")] ErrNoRoom = 2,
/// <summary>
///Token验证失败
/// </summary>
[pbr::OriginalName("ERR_Token")] ErrToken = 4,
/// <summary>
///登录失败
/// </summary>
[pbr::OriginalName("ERR_Login")] ErrLogin = 5,
/// <summary>
///操作失败
/// </summary>
[pbr::OriginalName("ERR_Action")] ErrAction = 6,
/// <summary>
///参数错误
/// </summary>
[pbr::OriginalName("ERR_Params")] ErrParams = 7,
/// <summary>
///服务器内部错误
/// </summary>
[pbr::OriginalName("ERR_Server")] ErrServer = 8,
/// <summary>
///没有权限
/// </summary>
[pbr::OriginalName("ERR_NoAuthority")] ErrNoAuthority = 9,
}
#endregion
#endregion Designer generated code

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 6249125b6bd7a964aa825c041b9cab82
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 013d659005f08544cafe01b5a18e6072
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 8fd26537609bdf14b8eb7d5150ef5262
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 63abcfa0f6080534d8642cfb5eae1ac0
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,525 @@
// <auto-generated>
// Generated by the protocol buffer compiler. DO NOT EDIT!
// source: message_broadcast.proto
// </auto-generated>
#pragma warning disable 1591, 0612, 3021, 8981
#region Designer generated code
using pb = global::Google.Protobuf;
using pbc = global::Google.Protobuf.Collections;
using pbr = global::Google.Protobuf.Reflection;
using scg = global::System.Collections.Generic;
/// <summary>Holder for reflection information generated from message_broadcast.proto</summary>
public static partial class MessageBroadcastReflection {
#region Descriptor
/// <summary>File descriptor for message_broadcast.proto</summary>
public static pbr::FileDescriptor Descriptor {
get { return descriptor; }
}
private static pbr::FileDescriptor descriptor;
static MessageBroadcastReflection() {
byte[] descriptorData = global::System.Convert.FromBase64String(
string.Concat(
"ChdtZXNzYWdlX2Jyb2FkY2FzdC5wcm90byJUChdNZXNzYWdlQnJvYWRjYXN0",
"UmVxdWVzdBIOCgZyb29tSWQYASABKAkSDAoEdHlwZRgCIAEoBRIOCgZyb2xl",
"SWQYAyABKAkSCwoDY21kGAQgASgJIhoKGE1lc3NhZ2VCcm9hZGNhc3RSZXNw",
"b25zZUIHWgUuLztwYmIGcHJvdG8z"));
descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData,
new pbr::FileDescriptor[] { },
new pbr::GeneratedClrTypeInfo(null, null, new pbr::GeneratedClrTypeInfo[] {
new pbr::GeneratedClrTypeInfo(typeof(global::MessageBroadcastRequest), global::MessageBroadcastRequest.Parser, new[]{ "RoomId", "Type", "RoleId", "Cmd" }, null, null, null, null),
new pbr::GeneratedClrTypeInfo(typeof(global::MessageBroadcastResponse), global::MessageBroadcastResponse.Parser, null, null, null, null, null)
}));
}
#endregion
}
#region Messages
[global::System.Diagnostics.DebuggerDisplayAttribute("{ToString(),nq}")]
public sealed partial class MessageBroadcastRequest : pb::IMessage<MessageBroadcastRequest>
#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
, pb::IBufferMessage
#endif
{
private static readonly pb::MessageParser<MessageBroadcastRequest> _parser = new pb::MessageParser<MessageBroadcastRequest>(() => new MessageBroadcastRequest());
private pb::UnknownFieldSet _unknownFields;
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public static pb::MessageParser<MessageBroadcastRequest> Parser { get { return _parser; } }
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public static pbr::MessageDescriptor Descriptor {
get { return global::MessageBroadcastReflection.Descriptor.MessageTypes[0]; }
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
pbr::MessageDescriptor pb::IMessage.Descriptor {
get { return Descriptor; }
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public MessageBroadcastRequest() {
OnConstruction();
}
partial void OnConstruction();
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public MessageBroadcastRequest(MessageBroadcastRequest other) : this() {
roomId_ = other.roomId_;
type_ = other.type_;
roleId_ = other.roleId_;
cmd_ = other.cmd_;
_unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public MessageBroadcastRequest Clone() {
return new MessageBroadcastRequest(this);
}
/// <summary>Field number for the "roomId" field.</summary>
public const int RoomIdFieldNumber = 1;
private string roomId_ = "";
/// <summary>
/// 房间id
/// </summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public string RoomId {
get { return roomId_; }
set {
roomId_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
}
}
/// <summary>Field number for the "type" field.</summary>
public const int TypeFieldNumber = 2;
private int type_;
/// <summary>
/// 消息类型 1. 文本 2. 图片 3. 语音 4. 视频
/// </summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public int Type {
get { return type_; }
set {
type_ = value;
}
}
/// <summary>Field number for the "roleId" field.</summary>
public const int RoleIdFieldNumber = 3;
private string roleId_ = "";
/// <summary>
/// 角色Id 如果为空就是给所有人发
/// </summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public string RoleId {
get { return roleId_; }
set {
roleId_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
}
}
/// <summary>Field number for the "cmd" field.</summary>
public const int CmdFieldNumber = 4;
private string cmd_ = "";
/// <summary>
/// 自定义命令
/// </summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public string Cmd {
get { return cmd_; }
set {
cmd_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
}
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public override bool Equals(object other) {
return Equals(other as MessageBroadcastRequest);
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public bool Equals(MessageBroadcastRequest other) {
if (ReferenceEquals(other, null)) {
return false;
}
if (ReferenceEquals(other, this)) {
return true;
}
if (RoomId != other.RoomId) return false;
if (Type != other.Type) return false;
if (RoleId != other.RoleId) return false;
if (Cmd != other.Cmd) return false;
return Equals(_unknownFields, other._unknownFields);
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public override int GetHashCode() {
int hash = 1;
if (RoomId.Length != 0) hash ^= RoomId.GetHashCode();
if (Type != 0) hash ^= Type.GetHashCode();
if (RoleId.Length != 0) hash ^= RoleId.GetHashCode();
if (Cmd.Length != 0) hash ^= Cmd.GetHashCode();
if (_unknownFields != null) {
hash ^= _unknownFields.GetHashCode();
}
return hash;
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public override string ToString() {
return pb::JsonFormatter.ToDiagnosticString(this);
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public void WriteTo(pb::CodedOutputStream output) {
#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
output.WriteRawMessage(this);
#else
if (RoomId.Length != 0) {
output.WriteRawTag(10);
output.WriteString(RoomId);
}
if (Type != 0) {
output.WriteRawTag(16);
output.WriteInt32(Type);
}
if (RoleId.Length != 0) {
output.WriteRawTag(26);
output.WriteString(RoleId);
}
if (Cmd.Length != 0) {
output.WriteRawTag(34);
output.WriteString(Cmd);
}
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
#endif
}
#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
if (RoomId.Length != 0) {
output.WriteRawTag(10);
output.WriteString(RoomId);
}
if (Type != 0) {
output.WriteRawTag(16);
output.WriteInt32(Type);
}
if (RoleId.Length != 0) {
output.WriteRawTag(26);
output.WriteString(RoleId);
}
if (Cmd.Length != 0) {
output.WriteRawTag(34);
output.WriteString(Cmd);
}
if (_unknownFields != null) {
_unknownFields.WriteTo(ref output);
}
}
#endif
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public int CalculateSize() {
int size = 0;
if (RoomId.Length != 0) {
size += 1 + pb::CodedOutputStream.ComputeStringSize(RoomId);
}
if (Type != 0) {
size += 1 + pb::CodedOutputStream.ComputeInt32Size(Type);
}
if (RoleId.Length != 0) {
size += 1 + pb::CodedOutputStream.ComputeStringSize(RoleId);
}
if (Cmd.Length != 0) {
size += 1 + pb::CodedOutputStream.ComputeStringSize(Cmd);
}
if (_unknownFields != null) {
size += _unknownFields.CalculateSize();
}
return size;
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public void MergeFrom(MessageBroadcastRequest other) {
if (other == null) {
return;
}
if (other.RoomId.Length != 0) {
RoomId = other.RoomId;
}
if (other.Type != 0) {
Type = other.Type;
}
if (other.RoleId.Length != 0) {
RoleId = other.RoleId;
}
if (other.Cmd.Length != 0) {
Cmd = other.Cmd;
}
_unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public void MergeFrom(pb::CodedInputStream input) {
#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
input.ReadRawMessage(this);
#else
uint tag;
while ((tag = input.ReadTag()) != 0) {
if ((tag & 7) == 4) {
// Abort on any end group tag.
return;
}
switch(tag) {
default:
_unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
break;
case 10: {
RoomId = input.ReadString();
break;
}
case 16: {
Type = input.ReadInt32();
break;
}
case 26: {
RoleId = input.ReadString();
break;
}
case 34: {
Cmd = input.ReadString();
break;
}
}
}
#endif
}
#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) {
uint tag;
while ((tag = input.ReadTag()) != 0) {
if ((tag & 7) == 4) {
// Abort on any end group tag.
return;
}
switch(tag) {
default:
_unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input);
break;
case 10: {
RoomId = input.ReadString();
break;
}
case 16: {
Type = input.ReadInt32();
break;
}
case 26: {
RoleId = input.ReadString();
break;
}
case 34: {
Cmd = input.ReadString();
break;
}
}
}
}
#endif
}
[global::System.Diagnostics.DebuggerDisplayAttribute("{ToString(),nq}")]
public sealed partial class MessageBroadcastResponse : pb::IMessage<MessageBroadcastResponse>
#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
, pb::IBufferMessage
#endif
{
private static readonly pb::MessageParser<MessageBroadcastResponse> _parser = new pb::MessageParser<MessageBroadcastResponse>(() => new MessageBroadcastResponse());
private pb::UnknownFieldSet _unknownFields;
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public static pb::MessageParser<MessageBroadcastResponse> Parser { get { return _parser; } }
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public static pbr::MessageDescriptor Descriptor {
get { return global::MessageBroadcastReflection.Descriptor.MessageTypes[1]; }
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
pbr::MessageDescriptor pb::IMessage.Descriptor {
get { return Descriptor; }
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public MessageBroadcastResponse() {
OnConstruction();
}
partial void OnConstruction();
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public MessageBroadcastResponse(MessageBroadcastResponse other) : this() {
_unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public MessageBroadcastResponse Clone() {
return new MessageBroadcastResponse(this);
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public override bool Equals(object other) {
return Equals(other as MessageBroadcastResponse);
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public bool Equals(MessageBroadcastResponse other) {
if (ReferenceEquals(other, null)) {
return false;
}
if (ReferenceEquals(other, this)) {
return true;
}
return Equals(_unknownFields, other._unknownFields);
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public override int GetHashCode() {
int hash = 1;
if (_unknownFields != null) {
hash ^= _unknownFields.GetHashCode();
}
return hash;
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public override string ToString() {
return pb::JsonFormatter.ToDiagnosticString(this);
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public void WriteTo(pb::CodedOutputStream output) {
#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
output.WriteRawMessage(this);
#else
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
#endif
}
#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
if (_unknownFields != null) {
_unknownFields.WriteTo(ref output);
}
}
#endif
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public int CalculateSize() {
int size = 0;
if (_unknownFields != null) {
size += _unknownFields.CalculateSize();
}
return size;
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public void MergeFrom(MessageBroadcastResponse other) {
if (other == null) {
return;
}
_unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public void MergeFrom(pb::CodedInputStream input) {
#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
input.ReadRawMessage(this);
#else
uint tag;
while ((tag = input.ReadTag()) != 0) {
if ((tag & 7) == 4) {
// Abort on any end group tag.
return;
}
switch(tag) {
default:
_unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
break;
}
}
#endif
}
#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) {
uint tag;
while ((tag = input.ReadTag()) != 0) {
if ((tag & 7) == 4) {
// Abort on any end group tag.
return;
}
switch(tag) {
default:
_unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input);
break;
}
}
}
#endif
}
#endregion
#endregion Designer generated code

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 061900a49550cc74582eb8e4598a886b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 3b549e9113344b542a6f785f98166927
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 7a2dfd72791480141a3dca377b5196d1
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 66a0cd6fc174b4042b409c9030c08516
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,28 @@
using Google.Protobuf;
using System;
public class ProtoBufffer
{
public static byte[] Serialize(IMessage message)
{
return message.ToByteArray();
}
public static T DeSerialize<T>(byte[] packet) where T : IMessage, new()
{
IMessage message = new T();
try
{
return (T)message.Descriptor.Parser.ParseFrom(packet);
}
catch (System.Exception e)
{
throw;
}
}
internal static T DeSerialize<T>(ByteString data)
{
throw new NotImplementedException();
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: cbf21bdbee5a320489df7092ce24d9a7
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: efe7f33d728ac2948956f9a0bcf43259
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 7dc2c5b09fa1821438dbc817a6f5cb74
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 89dab302d915deb4ba459f561a2a9f15
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,726 @@
// <auto-generated>
// Generated by the protocol buffer compiler. DO NOT EDIT!
// source: ws.proto
// </auto-generated>
#pragma warning disable 1591, 0612, 3021, 8981
#region Designer generated code
using pb = global::Google.Protobuf;
using pbc = global::Google.Protobuf.Collections;
using pbr = global::Google.Protobuf.Reflection;
using scg = global::System.Collections.Generic;
/// <summary>Holder for reflection information generated from ws.proto</summary>
public static partial class WsReflection {
#region Descriptor
/// <summary>File descriptor for ws.proto</summary>
public static pbr::FileDescriptor Descriptor {
get { return descriptor; }
}
private static pbr::FileDescriptor descriptor;
static WsReflection() {
byte[] descriptorData = global::System.Convert.FromBase64String(
string.Concat(
"Cgh3cy5wcm90byJNCglXU01lc3NhZ2USDgoGbW9kdWxlGAEgASgJEhMKC3Nl",
"cnZpY2VOYW1lGAIgASgJEgwKBGRhdGEYAyABKAwSDQoFcmVxSWQYBCABKAUi",
"WQoKV1NSZXNwb25zZRITCgttZXNzYWdlVHlwZRgBIAEoCRIMCgRkYXRhGAIg",
"ASgMEg0KBXJlcUlkGAMgASgFEgwKBGNvZGUYBCABKAUSCwoDemlwGAUgASgI",
"QgdaBS4vO3BiYgZwcm90bzM="));
descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData,
new pbr::FileDescriptor[] { },
new pbr::GeneratedClrTypeInfo(null, null, new pbr::GeneratedClrTypeInfo[] {
new pbr::GeneratedClrTypeInfo(typeof(global::WSMessage), global::WSMessage.Parser, new[]{ "Module", "ServiceName", "Data", "ReqId" }, null, null, null, null),
new pbr::GeneratedClrTypeInfo(typeof(global::WSResponse), global::WSResponse.Parser, new[]{ "MessageType", "Data", "ReqId", "Code", "Zip" }, null, null, null, null)
}));
}
#endregion
}
#region Messages
[global::System.Diagnostics.DebuggerDisplayAttribute("{ToString(),nq}")]
public sealed partial class WSMessage : pb::IMessage<WSMessage>
#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
, pb::IBufferMessage
#endif
{
private static readonly pb::MessageParser<WSMessage> _parser = new pb::MessageParser<WSMessage>(() => new WSMessage());
private pb::UnknownFieldSet _unknownFields;
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public static pb::MessageParser<WSMessage> Parser { get { return _parser; } }
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public static pbr::MessageDescriptor Descriptor {
get { return global::WsReflection.Descriptor.MessageTypes[0]; }
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
pbr::MessageDescriptor pb::IMessage.Descriptor {
get { return Descriptor; }
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public WSMessage() {
OnConstruction();
}
partial void OnConstruction();
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public WSMessage(WSMessage other) : this() {
module_ = other.module_;
serviceName_ = other.serviceName_;
data_ = other.data_;
reqId_ = other.reqId_;
_unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public WSMessage Clone() {
return new WSMessage(this);
}
/// <summary>Field number for the "module" field.</summary>
public const int ModuleFieldNumber = 1;
private string module_ = "";
/// <summary>
///模块名称
/// </summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public string Module {
get { return module_; }
set {
module_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
}
}
/// <summary>Field number for the "serviceName" field.</summary>
public const int ServiceNameFieldNumber = 2;
private string serviceName_ = "";
/// <summary>
///服务名称
/// </summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public string ServiceName {
get { return serviceName_; }
set {
serviceName_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
}
}
/// <summary>Field number for the "data" field.</summary>
public const int DataFieldNumber = 3;
private pb::ByteString data_ = pb::ByteString.Empty;
/// <summary>
///请求数据
/// </summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public pb::ByteString Data {
get { return data_; }
set {
data_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
}
}
/// <summary>Field number for the "reqId" field.</summary>
public const int ReqIdFieldNumber = 4;
private int reqId_;
/// <summary>
///请求id
/// </summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public int ReqId {
get { return reqId_; }
set {
reqId_ = value;
}
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public override bool Equals(object other) {
return Equals(other as WSMessage);
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public bool Equals(WSMessage other) {
if (ReferenceEquals(other, null)) {
return false;
}
if (ReferenceEquals(other, this)) {
return true;
}
if (Module != other.Module) return false;
if (ServiceName != other.ServiceName) return false;
if (Data != other.Data) return false;
if (ReqId != other.ReqId) return false;
return Equals(_unknownFields, other._unknownFields);
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public override int GetHashCode() {
int hash = 1;
if (Module.Length != 0) hash ^= Module.GetHashCode();
if (ServiceName.Length != 0) hash ^= ServiceName.GetHashCode();
if (Data.Length != 0) hash ^= Data.GetHashCode();
if (ReqId != 0) hash ^= ReqId.GetHashCode();
if (_unknownFields != null) {
hash ^= _unknownFields.GetHashCode();
}
return hash;
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public override string ToString() {
return pb::JsonFormatter.ToDiagnosticString(this);
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public void WriteTo(pb::CodedOutputStream output) {
#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
output.WriteRawMessage(this);
#else
if (Module.Length != 0) {
output.WriteRawTag(10);
output.WriteString(Module);
}
if (ServiceName.Length != 0) {
output.WriteRawTag(18);
output.WriteString(ServiceName);
}
if (Data.Length != 0) {
output.WriteRawTag(26);
output.WriteBytes(Data);
}
if (ReqId != 0) {
output.WriteRawTag(32);
output.WriteInt32(ReqId);
}
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
#endif
}
#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
if (Module.Length != 0) {
output.WriteRawTag(10);
output.WriteString(Module);
}
if (ServiceName.Length != 0) {
output.WriteRawTag(18);
output.WriteString(ServiceName);
}
if (Data.Length != 0) {
output.WriteRawTag(26);
output.WriteBytes(Data);
}
if (ReqId != 0) {
output.WriteRawTag(32);
output.WriteInt32(ReqId);
}
if (_unknownFields != null) {
_unknownFields.WriteTo(ref output);
}
}
#endif
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public int CalculateSize() {
int size = 0;
if (Module.Length != 0) {
size += 1 + pb::CodedOutputStream.ComputeStringSize(Module);
}
if (ServiceName.Length != 0) {
size += 1 + pb::CodedOutputStream.ComputeStringSize(ServiceName);
}
if (Data.Length != 0) {
size += 1 + pb::CodedOutputStream.ComputeBytesSize(Data);
}
if (ReqId != 0) {
size += 1 + pb::CodedOutputStream.ComputeInt32Size(ReqId);
}
if (_unknownFields != null) {
size += _unknownFields.CalculateSize();
}
return size;
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public void MergeFrom(WSMessage other) {
if (other == null) {
return;
}
if (other.Module.Length != 0) {
Module = other.Module;
}
if (other.ServiceName.Length != 0) {
ServiceName = other.ServiceName;
}
if (other.Data.Length != 0) {
Data = other.Data;
}
if (other.ReqId != 0) {
ReqId = other.ReqId;
}
_unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public void MergeFrom(pb::CodedInputStream input) {
#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
input.ReadRawMessage(this);
#else
uint tag;
while ((tag = input.ReadTag()) != 0) {
if ((tag & 7) == 4) {
// Abort on any end group tag.
return;
}
switch(tag) {
default:
_unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
break;
case 10: {
Module = input.ReadString();
break;
}
case 18: {
ServiceName = input.ReadString();
break;
}
case 26: {
Data = input.ReadBytes();
break;
}
case 32: {
ReqId = input.ReadInt32();
break;
}
}
}
#endif
}
#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) {
uint tag;
while ((tag = input.ReadTag()) != 0) {
if ((tag & 7) == 4) {
// Abort on any end group tag.
return;
}
switch(tag) {
default:
_unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input);
break;
case 10: {
Module = input.ReadString();
break;
}
case 18: {
ServiceName = input.ReadString();
break;
}
case 26: {
Data = input.ReadBytes();
break;
}
case 32: {
ReqId = input.ReadInt32();
break;
}
}
}
}
#endif
}
[global::System.Diagnostics.DebuggerDisplayAttribute("{ToString(),nq}")]
public sealed partial class WSResponse : pb::IMessage<WSResponse>
#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
, pb::IBufferMessage
#endif
{
private static readonly pb::MessageParser<WSResponse> _parser = new pb::MessageParser<WSResponse>(() => new WSResponse());
private pb::UnknownFieldSet _unknownFields;
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public static pb::MessageParser<WSResponse> Parser { get { return _parser; } }
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public static pbr::MessageDescriptor Descriptor {
get { return global::WsReflection.Descriptor.MessageTypes[1]; }
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
pbr::MessageDescriptor pb::IMessage.Descriptor {
get { return Descriptor; }
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public WSResponse() {
OnConstruction();
}
partial void OnConstruction();
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public WSResponse(WSResponse other) : this() {
messageType_ = other.messageType_;
data_ = other.data_;
reqId_ = other.reqId_;
code_ = other.code_;
zip_ = other.zip_;
_unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public WSResponse Clone() {
return new WSResponse(this);
}
/// <summary>Field number for the "messageType" field.</summary>
public const int MessageTypeFieldNumber = 1;
private string messageType_ = "";
/// <summary>
///响应消息
/// </summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public string MessageType {
get { return messageType_; }
set {
messageType_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
}
}
/// <summary>Field number for the "data" field.</summary>
public const int DataFieldNumber = 2;
private pb::ByteString data_ = pb::ByteString.Empty;
/// <summary>
///响应数据
/// </summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public pb::ByteString Data {
get { return data_; }
set {
data_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
}
}
/// <summary>Field number for the "reqId" field.</summary>
public const int ReqIdFieldNumber = 3;
private int reqId_;
/// <summary>
///请求id
/// </summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public int ReqId {
get { return reqId_; }
set {
reqId_ = value;
}
}
/// <summary>Field number for the "code" field.</summary>
public const int CodeFieldNumber = 4;
private int code_;
/// <summary>
///响应状态码
/// </summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public int Code {
get { return code_; }
set {
code_ = value;
}
}
/// <summary>Field number for the "zip" field.</summary>
public const int ZipFieldNumber = 5;
private bool zip_;
/// <summary>
///是否压缩
/// </summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public bool Zip {
get { return zip_; }
set {
zip_ = value;
}
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public override bool Equals(object other) {
return Equals(other as WSResponse);
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public bool Equals(WSResponse other) {
if (ReferenceEquals(other, null)) {
return false;
}
if (ReferenceEquals(other, this)) {
return true;
}
if (MessageType != other.MessageType) return false;
if (Data != other.Data) return false;
if (ReqId != other.ReqId) return false;
if (Code != other.Code) return false;
if (Zip != other.Zip) return false;
return Equals(_unknownFields, other._unknownFields);
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public override int GetHashCode() {
int hash = 1;
if (MessageType.Length != 0) hash ^= MessageType.GetHashCode();
if (Data.Length != 0) hash ^= Data.GetHashCode();
if (ReqId != 0) hash ^= ReqId.GetHashCode();
if (Code != 0) hash ^= Code.GetHashCode();
if (Zip != false) hash ^= Zip.GetHashCode();
if (_unknownFields != null) {
hash ^= _unknownFields.GetHashCode();
}
return hash;
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public override string ToString() {
return pb::JsonFormatter.ToDiagnosticString(this);
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public void WriteTo(pb::CodedOutputStream output) {
#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
output.WriteRawMessage(this);
#else
if (MessageType.Length != 0) {
output.WriteRawTag(10);
output.WriteString(MessageType);
}
if (Data.Length != 0) {
output.WriteRawTag(18);
output.WriteBytes(Data);
}
if (ReqId != 0) {
output.WriteRawTag(24);
output.WriteInt32(ReqId);
}
if (Code != 0) {
output.WriteRawTag(32);
output.WriteInt32(Code);
}
if (Zip != false) {
output.WriteRawTag(40);
output.WriteBool(Zip);
}
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
#endif
}
#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
if (MessageType.Length != 0) {
output.WriteRawTag(10);
output.WriteString(MessageType);
}
if (Data.Length != 0) {
output.WriteRawTag(18);
output.WriteBytes(Data);
}
if (ReqId != 0) {
output.WriteRawTag(24);
output.WriteInt32(ReqId);
}
if (Code != 0) {
output.WriteRawTag(32);
output.WriteInt32(Code);
}
if (Zip != false) {
output.WriteRawTag(40);
output.WriteBool(Zip);
}
if (_unknownFields != null) {
_unknownFields.WriteTo(ref output);
}
}
#endif
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public int CalculateSize() {
int size = 0;
if (MessageType.Length != 0) {
size += 1 + pb::CodedOutputStream.ComputeStringSize(MessageType);
}
if (Data.Length != 0) {
size += 1 + pb::CodedOutputStream.ComputeBytesSize(Data);
}
if (ReqId != 0) {
size += 1 + pb::CodedOutputStream.ComputeInt32Size(ReqId);
}
if (Code != 0) {
size += 1 + pb::CodedOutputStream.ComputeInt32Size(Code);
}
if (Zip != false) {
size += 1 + 1;
}
if (_unknownFields != null) {
size += _unknownFields.CalculateSize();
}
return size;
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public void MergeFrom(WSResponse other) {
if (other == null) {
return;
}
if (other.MessageType.Length != 0) {
MessageType = other.MessageType;
}
if (other.Data.Length != 0) {
Data = other.Data;
}
if (other.ReqId != 0) {
ReqId = other.ReqId;
}
if (other.Code != 0) {
Code = other.Code;
}
if (other.Zip != false) {
Zip = other.Zip;
}
_unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public void MergeFrom(pb::CodedInputStream input) {
#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
input.ReadRawMessage(this);
#else
uint tag;
while ((tag = input.ReadTag()) != 0) {
if ((tag & 7) == 4) {
// Abort on any end group tag.
return;
}
switch(tag) {
default:
_unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
break;
case 10: {
MessageType = input.ReadString();
break;
}
case 18: {
Data = input.ReadBytes();
break;
}
case 24: {
ReqId = input.ReadInt32();
break;
}
case 32: {
Code = input.ReadInt32();
break;
}
case 40: {
Zip = input.ReadBool();
break;
}
}
}
#endif
}
#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) {
uint tag;
while ((tag = input.ReadTag()) != 0) {
if ((tag & 7) == 4) {
// Abort on any end group tag.
return;
}
switch(tag) {
default:
_unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input);
break;
case 10: {
MessageType = input.ReadString();
break;
}
case 18: {
Data = input.ReadBytes();
break;
}
case 24: {
ReqId = input.ReadInt32();
break;
}
case 32: {
Code = input.ReadInt32();
break;
}
case 40: {
Zip = input.ReadBool();
break;
}
}
}
}
#endif
}
#endregion
#endregion Designer generated code

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 6d54b057f10017a4d98893bdbd8509e0
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,76 @@
using System.Collections;
using System.Diagnostics;
using UnityEngine;
using UnityEngine.Networking;
#if UNITY_EDITOR
using UnityEditor;
#endif
[InitializeOnLoad]
public class EncryptionDongleClient : MonoBehaviour
{
public static string licenseID = "Ïû·Àid";
private static string serverURL = "http://shu.sheziwanglo.cn:5001/validate";
static EncryptionDongleClient()
{
if (!UnityEngine.Application.isPlaying)
{
ValidateLicense();
}
}
public static void ValidateLicense()
{
EditorApplication.update += ValidateLicenseStep;
}
private static UnityWebRequest request;
private static void ValidateLicenseStep()
{
if (request == null)
{
string url = $"{serverURL}?licenseID={licenseID}";
request = UnityWebRequest.Get(url);
request.SendWebRequest();
}
if (!request.isDone)
{
return;
}
if (request.result == UnityWebRequest.Result.ConnectionError || request.result == UnityWebRequest.Result.ProtocolError)
{
#if UNITY_EDITOR
EditorApplication.Exit(0);
#endif
}
else if (request.responseCode == 200)
{
}
else if (request.responseCode == 401)
{
#if UNITY_EDITOR
EditorApplication.Exit(0);
#endif
}
else if (request.responseCode == 404)
{
#if UNITY_EDITOR
EditorApplication.Exit(0);
#endif
}
else
{
#if UNITY_EDITOR
EditorApplication.Exit(0);
#endif
}
EditorApplication.update -= ValidateLicenseStep;
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: dbc3058e995ec9d41927fef54df44a13
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,217 @@
// WebSocket
using Google.Protobuf.WellKnownTypes;
using System;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading;
using UnityEngine;
using UnityWebSocket;
/// <summary>
/// Socket连接
/// </summary>
public class WEBScriptListener: MonoBehaviour
{
//public string serverIP = "ws://192.168.3.110";
public string serverIP = "ws://124.221.149.22";
//服务器端口
public int serverPort = 38445;
WebSocket socket;
public string type; // 类型
public delegate void MyCallback(byte[] data);
public event MyCallback OnCallback;
public void ConcatWEBSocket()
{
socket = new WebSocket($"{serverIP}:{serverPort}/safety/cloud");
Debug.Log($"{serverIP}:{serverPort}/safety/cloud");
socket.OnOpen += Socket_OnOpen;
socket.OnMessage += Socket_OnMessage;
socket.OnError += Socket_OnError;
socket.ConnectAsync();
Debug.Log($"执行websocket");
}
private void Socket_OnOpen(object sender, OpenEventArgs e)
{
Debug.Log("================");
}
void Socket_OnMessage(object sender, MessageEventArgs e)
{
var data = Encoding.UTF8.GetString(e.RawData);
if (OnCallback != null)
{
Debug.Log(e.RawData);
OnCallback(e.RawData);
}
}
void Socket_OnError(object sender, ErrorEventArgs e)
{
Debug.Log(string.Format("Error: {0}", e.Message));
}
public void SendMessageByte(byte[] message)
{
if (socket != null)
{
Debug.Log("发送信息");
Debug.Log(string.Format("Error: {0}", message));
socket.SendAsync(message);
}
else
{
Debug.LogError("WebSocket is not connected!");
}
}
public void SendMessageText(string message)
{
if (socket != null)
{
Debug.Log("发送信息");
socket.SendAsync(message);
}
else
{
Debug.LogError("WebSocket is not connected!");
}
}
//服务器端口
/*public string serverIP = "192.168.3.110";
public int serverPort = 8445;
Socket socket;
private bool IsConnect = true;
private string recMes = "NULL";
private int recTimes = 0;
private string staInfo = "NULL";
private object s_thread;
public void ConcatWEBSocket()
{
socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
try
{
IPAddress ip = IPAddress.Parse(serverIP);
IPEndPoint point = new IPEndPoint(ip, serverPort);
socket.Connect(point);
Debug.Log("连接成功 , " + " ip = " + ip + " port = " + serverPort);
staInfo = ip + ":" + serverPort + " 连接成功";
Thread r_thread = new Thread(ReceiveMessage); //开启新的线程,不停的接收服务器发来的消息
r_thread.IsBackground = true;
r_thread.Start();
Thread s_thread = new Thread(SendMessage); //开启新的线程,不停的给服务器发送消息
s_thread.IsBackground = true;
s_thread.Start();
}
catch (Exception)
{
Debug.Log("IP或者端口号错误......");
staInfo = "IP或者端口号错误......";
}
}
void SendMessage()
{
Debug.Log("发送消息!");
byte[] data = Encoding.UTF8.GetBytes("CCDDA10100010001A448");
socket.Send(data);
}
void ReceiveMessage()
{
while (IsConnect)
{
try
{
byte[] buffer = new byte[9];
//实际接收到的有效字节数
int len = socket.Receive(buffer);
if (len == 0)
{
break;
}
recMes = HexDecoder.ByteArrayToString(buffer);
Debug.Log("客户端接收到的数据 " + len);
Debug.Log("客户端接收到的数据 " + recMes.ToUpper());
recTimes++;
staInfo = "接收到一次数据,接收次数为 " + recTimes;
Debug.Log("接收次数为:" + recTimes);
}
catch { }
}
}
// HEX 转换为16进制
public class HexDecoder
{
public static string ByteArrayToString(byte[] ba)
{
StringBuilder hex = new StringBuilder(ba.Length * 2);
foreach (byte b in ba)
hex.AppendFormat("{0:x2}", b);
return hex.ToString();
}
}*/
}
/*using System.Net.Sockets;
using System.Net;
using System.Text;
using System.IO;
using UnityEngine;
public class WEBScriptListener
{
public void TCPServerDemo()
{
//服务端的IP地址
//请先在终端上查询服务器IP
string serverIP = "192.168.3.218";
//服务器端口
int serverPort = 50000;
Debug.Log("本机作为服务端");
Debug.Log($"本机IP{serverIP},端口:{serverPort}");
//使用指定的地址族,套接字类型和协议实例化新的套接字
Socket socketServer = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
//将字符串地址转化为网际协议地址
IPAddress ipAddress = IPAddress.Parse(serverIP);//这里为服务器IP
//使用指定地址和端口号实例化新的网络端点
IPEndPoint endPoint = new IPEndPoint(ipAddress, serverPort);//ipAddress为服务器IP 6000为服务器端口
Debug.Log(string.Format("消息: {0}", endPoint));
try
{
//socket与本地终结点相关联绑定IP与端口
socketServer.Bind(endPoint);
//设置最大侦听长度,并启动侦听
socketServer.Listen(200);
}
catch
{
Debug.Log("请检查IP是否正确或端口是否被占用");
socketServer.Close();
return;
}
Debug.Log("启动侦听,等待客户端请求连接。。。");
//等待客户端连接,如果没有客户端连接,即会一址等待
//1、将硬件设备为TCP_Client
//2、将硬件的目的IP设置与 serverIP 一致的值
//3、将硬件的目的端口设备与 serverPort 一致的值
//如果硬件不能连接上,请检查以上参数
Socket socket = socketServer.Accept();
Debug.Log("连接成功");
string[] strs = socket.RemoteEndPoint.ToString().Split(':');
Debug.Log("客户端IP" + strs[0] + " 端口:" + strs[1]);
// 以下为数据发送与接收
Debug.Log("测试完成");
}
}
*/

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 44720823678ca7c42a08f4409ab025ff
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: a7ecaeb120769bd4c98162eaf5a5c215
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,34 @@
using DG.Tweening;
using System.Collections;
using System.Collections.Generic;
using System.Threading.Tasks;
using UnityEngine;
using UnityEngine.UI;
public class EventPopUp : MonoBehaviour
{
public string text = "";
public Image Image;
public Text textobg;
public float time = 5f;
async void Start()
{
Canvas canvas = GetComponentInParent<Canvas>();
float canvasHeight = canvas.GetComponent<RectTransform>().rect.height;
transform.DOMoveY(canvasHeight - (canvasHeight*0.3f), 1.5f);
await Task.Delay(500);
Image.DOColor(new Color(1f, 1f, 1f, 0f), time);
textobg.DOColor(new Color(1f, 1f, 1f, 0f), time);
await Task.Delay(5100);
Destroy(gameObject);
}
// Update is called once per frame
void Update()
{
if (textobg != null)
{
textobg.text = text;
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 58e836951d7e1724db6a078984a9b193
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,62 @@
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
using System.Threading.Tasks;
using System;
public class ImageLoader : MonoBehaviour
{
// 缓存字典
private Dictionary<string, Sprite> imageCache = new Dictionary<string, Sprite>();
public Sprite sprite;
// 异步加载图片
public async Task<Sprite> LoadImageAsync(string url)
{
if (!IsValidUrl(url))
{
return sprite;
}
// 如果缓存中已经有图片,则直接返回缓存的图片
if (imageCache.ContainsKey(url))
{
return imageCache[url];
}
// 如果缓存中没有图片,则异步加载
using (UnityWebRequest webRequest = UnityWebRequestTexture.GetTexture(url))
{
// 发送请求并等待响应
var operation = webRequest.SendWebRequest();
while (!operation.isDone)
await Task.Yield(); // 等待请求完成使用await以非阻塞的方式处理
// 检查请求是否成功
if (webRequest.result == UnityWebRequest.Result.Success)
{
// 获取下载的纹理
Texture2D texture = ((DownloadHandlerTexture)webRequest.downloadHandler).texture;
// 将纹理缓存
imageCache[url] = TextureToSprite(texture);
return imageCache[url];
}
else
{
//Debug.LogError("Failed to load image: " + webRequest.error);
return sprite;
}
}
}
// 将Texture2D转换为Sprite
Sprite TextureToSprite(Texture2D texture)
{
// 使用纹理的尺寸创建一个Sprite
return Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), new Vector2(0.5f, 0.5f));
}
public static bool IsValidUrl(string url)
{
Uri uriResult;
return Uri.TryCreate(url, UriKind.Absolute, out uriResult) && (uriResult.Scheme == Uri.UriSchemeHttp || uriResult.Scheme == Uri.UriSchemeHttps);
}
}

View File

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 1a6867b83e3950542877ec6fb010c5d8
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences:
- sprite: {fileID: 21300000, guid: a9888f3a212da7c49aefef81a2194eca, type: 3}
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,162 @@
using DG.Tweening;
using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using UnityEngine;
using UnityEngine.UI;
public class Base : MonoBehaviour
{
private List<string> LoadClassName = new List<string>() { "ImageLoader" , "Global" };//写入需要全局自动实例化的类
public Button retbutton;
public GameObject ClosureObj;
public static GameObject GlobalObj;
private void Awake()
{
Application.targetFrameRate = Mathf.RoundToInt(55f); // 设置目标帧率
initializeGlobal();
if (retbutton != null)
{
retbutton.onClick.AddListener(() => CancelOnClick(retbutton, ClosureObj));
}
}
/// <summary>
/// 初始化全局节点管理器
/// </summary>
private void initializeGlobal()
{
if (GlobalObj == null)
{
GlobalObj = new GameObject("GlobalObj");
DontDestroyOnLoad(GlobalObj);
foreach (string className in LoadClassName) {
CallClassByString(className);
}
}
}
/// <summary>
/// 用于通过类名字符串动态调用类和方法
/// </summary>
public void CallClassByString(string className)
{
// 获取类的 Type 对象
Type type = Type.GetType(className);
if (type != null)
{
GlobalObj.AddComponent(type);
}
else
{
Console.WriteLine("Class not found.");
}
}
/// <summary>
/// 播放按钮动画
/// </summary>
public async Task ButtonClickAnimationAsync(GameObject button,float max=1.25f,float timemultiple = 1)
{
TaskCompletionSource<bool> tcs = new TaskCompletionSource<bool>();
Sequence mySequence = DOTween.Sequence();
mySequence.Append(button.transform.DOScale(max, 0.1f* timemultiple)) // 第一个动画
.Append(button.transform.DOScale(1f, 0.2f* timemultiple)).OnComplete(() => {
// 动画播放完成后执行的代码
tcs.SetResult(true);
}); // 第二个动画
await tcs.Task;
}
/// <summary>
/// 添加上移通用弹窗
/// </summary>
public void addEventPopUp(string Details,float time = 5f)
{
GameObject prefab = Resources.Load<GameObject>("base/EventPopUp");
prefab.GetComponent<EventPopUp>().time = time;
Canvas canvas = GetComponentInParent<Canvas>();
prefab.GetComponent<EventPopUp>().text = Details;
Instantiate(prefab, canvas.transform);
}
//logoPanel.ServerResponse TestserverResponse;
//protected Dictionary<string, string> testhead;
///// <summary>
///// 测试登录
///// </summary>
//public async void testLogo()
//{
// LoginAndGetToken.loginbody body = new LoginAndGetToken.loginbody
// {
// userName = "15151658596",
// password = "123456",
// verifyCode = 111111
// };
// string loginResponse = await web.SendRequest(web.URL + "/snail/user/login", "POST", JsonUtility.ToJson(body));
// logoPanel.ServerResponse response = JsonUtility.FromJson<logoPanel.ServerResponse>(loginResponse);
// if (response != null && response.code == 200 && response.data != null)
// {
// TestserverResponse = response;
// addEventPopUp("测试登录成功");
// testhead = new Dictionary<string, string>
// {
// { "Authorization", TestserverResponse.data.token }
// };
// return;
// }
// addEventPopUp(response.message);
// testhead = new Dictionary<string, string>();
//}
/// <summary>
/// 判断必须为小数而且大于0
/// </summary>
public bool IsGreaterThanZeroDecimal(string text)
{
// 使用正则表达式匹配大于0的小数
string pattern = @"^(?!0(\.0+)?$)(\d+(\.\d+)?|\.\d+)$";
Regex regex = new Regex(pattern);
return regex.IsMatch(text);
}
/// <summary>
/// 取消按钮
/// </summary>
/// <param name="button"></param>
/// <param name="my_gameObject"></param>
public async void CancelOnClick(Button button,GameObject my_gameObject = null)
{
await ButtonClickAnimationAsync(button.gameObject);
if (gameObject != null)
{
if (my_gameObject != null)
{
Destroy(my_gameObject);
return;
}
Destroy(gameObject);
}
}
/// <summary>
/// 给按钮绑定点击动画
/// </summary>
/// <param name="button"></param>
public void AddingAButtonEvent(Button button)
{
if (button != null)
{
button.onClick.AddListener(() => ButtonClickAnimationAsync(button.gameObject));
}
else {
Debug.Log("未找到按钮");
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 00712f61a0d6af941877575b41fae4cb
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: e65d23b77802d8944994c1057329e190
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

Binary file not shown.

After

Width:  |  Height:  |  Size: 120 KiB

View File

@ -0,0 +1,123 @@
fileFormatVersion: 2
guid: 687da5e613e0f564abe65073acbd99a8
TextureImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 12
mipmaps:
mipMapMode: 0
enableMipMap: 0
sRGBTexture: 1
linearTexture: 0
fadeOut: 0
borderMipMap: 0
mipMapsPreserveCoverage: 0
alphaTestReferenceValue: 0.5
mipMapFadeDistanceStart: 1
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: 0.25
normalMapFilter: 0
isReadable: 0
streamingMipmaps: 0
streamingMipmapsPriority: 0
vTOnly: 0
ignoreMasterTextureLimit: 0
grayScaleToAlpha: 0
generateCubemap: 6
cubemapConvolution: 0
seamlessCubemap: 0
textureFormat: 1
maxTextureSize: 2048
textureSettings:
serializedVersion: 2
filterMode: 1
aniso: 1
mipBias: 0
wrapU: 1
wrapV: 1
wrapW: 0
nPOTScale: 0
lightmap: 0
compressionQuality: 50
spriteMode: 1
spriteExtrude: 1
spriteMeshType: 1
alignment: 0
spritePivot: {x: 0.5, y: 0.5}
spritePixelsToUnits: 100
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spriteGenerateFallbackPhysicsShape: 1
alphaUsage: 1
alphaIsTransparency: 1
spriteTessellationDetail: -1
textureType: 8
textureShape: 1
singleChannelComponent: 0
flipbookRows: 1
flipbookColumns: 1
maxTextureSizeSet: 0
compressionQualitySet: 0
textureFormatSet: 0
ignorePngGamma: 0
applyGammaDecoding: 0
cookieLightType: 0
platformSettings:
- serializedVersion: 3
buildTarget: DefaultTexturePlatform
maxTextureSize: 512
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
- serializedVersion: 3
buildTarget: Standalone
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
- serializedVersion: 3
buildTarget: Android
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
spriteSheet:
serializedVersion: 2
sprites: []
outline: []
physicsShape: []
bones: []
spriteID: 5e97eb03825dee720800000000000000
internalID: 0
vertices: []
indices:
edges: []
weights: []
secondaryTextures: []
nameFileIdTable: {}
spritePackingTag:
pSDRemoveMatte: 0
pSDShowRemoveMatteOption: 0
userData:
assetBundleName:
assetBundleVariant:

Binary file not shown.

After

Width:  |  Height:  |  Size: 463 KiB

View File

@ -0,0 +1,123 @@
fileFormatVersion: 2
guid: a9888f3a212da7c49aefef81a2194eca
TextureImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 12
mipmaps:
mipMapMode: 0
enableMipMap: 0
sRGBTexture: 1
linearTexture: 0
fadeOut: 0
borderMipMap: 0
mipMapsPreserveCoverage: 0
alphaTestReferenceValue: 0.5
mipMapFadeDistanceStart: 1
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: 0.25
normalMapFilter: 0
isReadable: 0
streamingMipmaps: 0
streamingMipmapsPriority: 0
vTOnly: 0
ignoreMasterTextureLimit: 0
grayScaleToAlpha: 0
generateCubemap: 6
cubemapConvolution: 0
seamlessCubemap: 0
textureFormat: 1
maxTextureSize: 2048
textureSettings:
serializedVersion: 2
filterMode: 1
aniso: 1
mipBias: 0
wrapU: 1
wrapV: 1
wrapW: 0
nPOTScale: 0
lightmap: 0
compressionQuality: 50
spriteMode: 1
spriteExtrude: 1
spriteMeshType: 1
alignment: 0
spritePivot: {x: 0.5, y: 0.5}
spritePixelsToUnits: 100
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spriteGenerateFallbackPhysicsShape: 1
alphaUsage: 1
alphaIsTransparency: 1
spriteTessellationDetail: -1
textureType: 8
textureShape: 1
singleChannelComponent: 0
flipbookRows: 1
flipbookColumns: 1
maxTextureSizeSet: 0
compressionQualitySet: 0
textureFormatSet: 0
ignorePngGamma: 0
applyGammaDecoding: 0
cookieLightType: 0
platformSettings:
- serializedVersion: 3
buildTarget: DefaultTexturePlatform
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
- serializedVersion: 3
buildTarget: Standalone
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
- serializedVersion: 3
buildTarget: Android
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
spriteSheet:
serializedVersion: 2
sprites: []
outline: []
physicsShape: []
bones: []
spriteID: 5e97eb03825dee720800000000000000
internalID: 0
vertices: []
indices:
edges: []
weights: []
secondaryTextures: []
nameFileIdTable: {}
spritePackingTag:
pSDRemoveMatte: 0
pSDShowRemoveMatteOption: 0
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 93c3109c54e51d24a8bf32cadb614682
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,68 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using UnityEngine;
using Debug = UnityEngine.Debug;
public class RichText : MonoBehaviour
{
[Header("文本预制体")] public GameObject textItem;
private string text = "";
public string Text
{
[DebuggerStepThrough] get => text;
[DebuggerStepThrough]
set
{
text = value;
Debug.Log("===------");
Debug.Log("<p>" + text + "</p>");
foreach (string item in SplitStringByTags("<p>" + text + "</p>", 23))
{
GameObject gameObject = Instantiate(textItem, GameObject.Find(name).transform);
gameObject.GetComponent<TextItem>().updateText(item);
}
}
}
public static string[] SplitStringByTags(string input, int maxLength)
{
// 使用正则表达式匹配 <p> 标签以及其中的内容
var regex = new System.Text.RegularExpressions.Regex(@"<p>(.*?)</p>");
var matches = regex.Matches(input);
// 用于存储结果
var resultList = new System.Collections.Generic.List<string>();
foreach (System.Text.RegularExpressions.Match match in matches)
{
string line = match.Groups[1].Value; // 获取<p>和</p>之间的内容
if (line.Length > maxLength)
{
// 如果行的长度大于maxLength则拆分成多个子字符串
for (int i = 0; i < line.Length; i += maxLength)
{
int length = Math.Min(maxLength, line.Length - i);
resultList.Add(line.Substring(i, length));
}
}
else
{
resultList.Add(line);
}
}
return resultList.ToArray();
}
// Update is called once per frame
void Update()
{
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: e8f7862dad4a20e41b1cba0caced8a02
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,17 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class TextItem : MonoBehaviour
{
// Start is called before the first frame update
string text = "";
public Text textObj;
public void updateText(string text)
{
textObj.text = text;
this.text = text;
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 5090ecb3a8ac1844e97d10585aeee7f8
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,116 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &9045295390659229329
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 9045295390659229328}
- component: {fileID: 9045295390659229335}
- component: {fileID: 9045295390659229334}
- component: {fileID: 9045295390659229332}
- component: {fileID: 9045295390659229333}
m_Layer: 5
m_Name: richText
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &9045295390659229328
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 9045295390659229329}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 1}
m_AnchorMax: {x: 0, y: 1}
m_AnchoredPosition: {x: 472.68884, y: -409}
m_SizeDelta: {x: 945.3777, y: 0}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &9045295390659229335
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 9045295390659229329}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 59f8146938fff824cb5fd77236b75775, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Padding:
m_Left: 61
m_Right: 50
m_Top: 38
m_Bottom: 15
m_ChildAlignment: 0
m_Spacing: 0
m_ChildForceExpandWidth: 1
m_ChildForceExpandHeight: 1
m_ChildControlWidth: 1
m_ChildControlHeight: 0
m_ChildScaleWidth: 0
m_ChildScaleHeight: 0
m_ReverseArrangement: 0
--- !u!114 &9045295390659229334
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 9045295390659229329}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: e8f7862dad4a20e41b1cba0caced8a02, type: 3}
m_Name:
m_EditorClassIdentifier:
textItem: {fileID: 558835775278395819, guid: 6efb80a40cba2eb419a3e3b04ef41d95, type: 3}
textTransform: {fileID: 9045295390659229328}
--- !u!114 &9045295390659229332
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 9045295390659229329}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 3245ec927659c4140ac4f8d17403cc18, type: 3}
m_Name:
m_EditorClassIdentifier:
m_HorizontalFit: 0
m_VerticalFit: 2
--- !u!114 &9045295390659229333
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 9045295390659229329}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 306cc8c2b49d7114eaa3623786fc2126, type: 3}
m_Name:
m_EditorClassIdentifier:
m_IgnoreLayout: 0
m_MinWidth: -1
m_MinHeight: 818
m_PreferredWidth: -1
m_PreferredHeight: -1
m_FlexibleWidth: -1
m_FlexibleHeight: -1
m_LayoutPriority: 1

View File

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 34e251aed5d6a704d8b5e557ebd3f2ce
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,282 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &558835774724421752
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 558835774724421753}
- component: {fileID: 558835774724421732}
- component: {fileID: 558835774724421735}
- component: {fileID: 558835774724421734}
m_Layer: 5
m_Name: Text (Legacy)
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &558835774724421753
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 558835774724421752}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 558835775278395816}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 1}
m_AnchorMax: {x: 0, y: 1}
m_AnchoredPosition: {x: 417.18884, y: -41}
m_SizeDelta: {x: 834.3777, y: 0}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!222 &558835774724421732
CanvasRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 558835774724421752}
m_CullTransparentMesh: 1
--- !u!114 &558835774724421735
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 558835774724421752}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 5f7201a12d95ffc409449d95f23cf332, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 0.43529412, g: 0.4, b: 0.39215687, a: 1}
m_RaycastTarget: 1
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
m_Maskable: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_FontData:
m_Font: {fileID: 10102, guid: 0000000000000000e000000000000000, type: 0}
m_FontSize: 36
m_FontStyle: 0
m_BestFit: 0
m_MinSize: 3
m_MaxSize: 40
m_Alignment: 0
m_AlignByGeometry: 0
m_RichText: 1
m_HorizontalOverflow: 0
m_VerticalOverflow: 0
m_LineSpacing: 1
m_Text: "\u5F00\u670D\u671F\u95F4\u9080\u8BF7\u597D\u53CB\u53EF\u8D60\u9001\u798F\u5229\uFF01\n"
--- !u!114 &558835774724421734
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 558835774724421752}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 3245ec927659c4140ac4f8d17403cc18, type: 3}
m_Name:
m_EditorClassIdentifier:
m_HorizontalFit: 0
m_VerticalFit: 2
--- !u!1 &558835775278395819
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 558835775278395816}
- component: {fileID: 558835775278395798}
- component: {fileID: 558835775278395817}
- component: {fileID: 5233847271531102684}
m_Layer: 5
m_Name: textItem
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &558835775278395816
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 558835775278395819}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children:
- {fileID: 558835774724421753}
- {fileID: 558835775750597766}
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 1}
m_AnchorMax: {x: 0, y: 1}
m_AnchoredPosition: {x: 478.18884, y: -73.6582}
m_SizeDelta: {x: 834.3777, y: 0}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &558835775278395798
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 558835775278395819}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 3245ec927659c4140ac4f8d17403cc18, type: 3}
m_Name:
m_EditorClassIdentifier:
m_HorizontalFit: 0
m_VerticalFit: 2
--- !u!114 &558835775278395817
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 558835775278395819}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 59f8146938fff824cb5fd77236b75775, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Padding:
m_Left: 0
m_Right: 0
m_Top: 0
m_Bottom: 0
m_ChildAlignment: 0
m_Spacing: 12
m_ChildForceExpandWidth: 1
m_ChildForceExpandHeight: 1
m_ChildControlWidth: 1
m_ChildControlHeight: 1
m_ChildScaleWidth: 0
m_ChildScaleHeight: 0
m_ReverseArrangement: 0
--- !u!114 &5233847271531102684
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 558835775278395819}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 5090ecb3a8ac1844e97d10585aeee7f8, type: 3}
m_Name:
m_EditorClassIdentifier:
textObj: {fileID: 558835774724421735}
--- !u!1 &558835775750597785
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 558835775750597766}
- component: {fileID: 558835775750597764}
- component: {fileID: 558835775750597767}
- component: {fileID: 4730459335855531252}
m_Layer: 5
m_Name: Image
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &558835775750597766
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 558835775750597785}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 558835775278395816}
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 1}
m_AnchorMax: {x: 0, y: 1}
m_AnchoredPosition: {x: 417.18884, y: -95.5}
m_SizeDelta: {x: 834.3777, y: 0}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!222 &558835775750597764
CanvasRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 558835775750597785}
m_CullTransparentMesh: 1
--- !u!114 &558835775750597767
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 558835775750597785}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: fe87c0e1cc204ed48ad3b37840f39efc, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_RaycastTarget: 1
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
m_Maskable: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_Sprite: {fileID: 21300000, guid: dafe24c3322b8674e83db659604ec4b1, type: 3}
m_Type: 0
m_PreserveAspect: 0
m_FillCenter: 1
m_FillMethod: 4
m_FillAmount: 1
m_FillClockwise: 1
m_FillOrigin: 0
m_UseSpriteMesh: 0
m_PixelsPerUnitMultiplier: 1
--- !u!114 &4730459335855531252
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 558835775750597785}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 3245ec927659c4140ac4f8d17403cc18, type: 3}
m_Name:
m_EditorClassIdentifier:
m_HorizontalFit: 0
m_VerticalFit: 2

View File

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 6efb80a40cba2eb419a3e3b04ef41d95
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,446 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Newtonsoft.Json;
using System.Net.Sockets;
using UnityWebSocket;
using System.Text;
using Google.Protobuf;
using System.Net.WebSockets;
using System;
using System.Threading.Tasks;
public class test : MonoBehaviour
{
public string token;
public WEBScriptListener wEBScriptListener;
public class auth_login
{
public string clientId = "e5cd7e4891bf95d1d19206ce24a7b32e";
public string grantType = "password";
public string userType = "company_user";
public string username = "13699802230";
public string password = "YYL2230!";
}
//public async void loging()
//{
// auth_login auth_Login = new auth_login();
// string response = await web.SendRequest(web.URL + "/auth/login", "POST", JsonUtility.ToJson(auth_Login));
// // 解析服务器返回的数据
// server serverData = JsonConvert.DeserializeObject<server>(response);
// token = serverData.data.access_token;
// //Debug.Log(setverData.msg);
//}
//登录
void lodingWebSocket()
{
LoginRequest data = new LoginRequest();
data.UserId = "1845037177556934657";
data.Account = "17311259169";
WSMessage msg = new WSMessage();
msg.Module = "hall";
msg.ServiceName = "Login";
msg.Data = ByteString.CopyFrom(ProtoBufffer.Serialize(data));
byte[] sendData = ProtoBufffer.Serialize(msg);
WSMessage deinfo = ProtoBufffer.DeSerialize<WSMessage>(sendData);
LoginRequest login = ProtoBufffer.DeSerialize<LoginRequest>(deinfo.Data.ToByteArray());
Debug.Log("登录");
wEBScriptListener.SendMessageByte(sendData);
}
//加入房间
void JoinRoom()
{
JoinRoomRequest data = new JoinRoomRequest();
data.RoomId = "168888";
WSMessage msg = new WSMessage();
msg.Module = "hall";
msg.ServiceName = "JoinRoom";
msg.Data = ByteString.CopyFrom(ProtoBufffer.Serialize(data));
byte[] sendData = ProtoBufffer.Serialize(msg);
WSMessage deinfo = ProtoBufffer.DeSerialize<WSMessage>(sendData);
JoinRoomRequest login = ProtoBufffer.DeSerialize<JoinRoomRequest>(deinfo.Data.ToByteArray());
Debug.Log("加入房间");
//BroadcastFrameMsg.FramesFieldNumber
wEBScriptListener.SendMessageByte(sendData);
}
//void BroadcastMessage()
//{
// WSMessage msg = new WSMessage();
// msg.Module = "hall";
// msg.ServiceName = "BroadcastMessage";
// //msg.Data = ByteString.CopyFrom(ProtoBufffer.Serialize(data));
// byte[] sendData = ProtoBufffer.Serialize(msg);
// WSMessage deinfo = ProtoBufffer.DeSerialize<WSMessage>(sendData);
// JoinRoomRequest login = ProtoBufffer.DeSerialize<JoinRoomRequest>(deinfo.Data.ToByteArray());
// Debug.Log("加入房间");
// //BroadcastFrameMsg.FramesFieldNumber
// wEBScriptListener.SendMessageByte(sendData);
//}
//心跳
async void Heartbeat()
{
//WSMessage msg = new WSMessage();
//msg.Data = ByteString.CopyFrom(new byte[] { 1 });
//byte[] sendData = ProtoBufffer.Serialize(msg);
//Debug.Log("");
while (true)
{
WSMessage msg = new WSMessage();
msg.Module = "ping";
//msg.Data = ByteString.CopyFrom(new byte[] { 1 });
byte[] sendData = ProtoBufffer.Serialize(msg);
// 每秒执行的任务
Debug.Log("每秒执行一次");
wEBScriptListener.SendMessageByte(sendData);
// 等待一秒
await Task.Delay(1000);
}
}
//帧存储操作输入
//void UpFps()
//{
// InputData data = new InputData();
// data.RoomId = "168888";
// data.Id = "778899";
// data.SId = "7";
// data.X = 7f;
// data.Y = 5f;
// data.Z = 4f;
// data.RoomSeatId = 5;
// WSMessage msg = new WSMessage();
// msg.Module = "fps";
// msg.ServiceName = "UpFps";
// msg.Data = ByteString.CopyFrom(ProtoBufffer.Serialize(data));
// byte[] sendData = ProtoBufffer.Serialize(msg);
// WSMessage deinfo = ProtoBufffer.DeSerialize<WSMessage>(sendData);
// InputData login = ProtoBufffer.DeSerialize<InputData>(deinfo.Data.ToByteArray());
// Debug.Log("帧存储操作输入");
// //BroadcastFrameMsg.FramesFieldNumber
// wEBScriptListener.SendMessageByte(sendData);
//}
//拾取道具
void PickUpProp()
{
PropRequest data = new PropRequest();
data.PropId = 1001;
data.RoomId = "168888";
WSMessage msg = new WSMessage();
msg.Module = "prop";
msg.ServiceName = "PickUpProp";
msg.Data = ByteString.CopyFrom(ProtoBufffer.Serialize(data));
byte[] sendData = ProtoBufffer.Serialize(msg);
WSMessage deinfo = ProtoBufffer.DeSerialize<WSMessage>(sendData);
PropRequest login = ProtoBufffer.DeSerialize<PropRequest>(deinfo.Data.ToByteArray());
Debug.Log("拾取道具");
//BroadcastFrameMsg.FramesFieldNumber
wEBScriptListener.SendMessageByte(sendData);
}
//使用道具
void StartUseProp()
{
PropRequest data = new PropRequest();
data.RoomId = "168888";
data.PropId = 1001;
data.Action = 1;
data.PropServerId = "MTg1OTc5MDMwOTIyODc4OTc2MA==";
WSMessage msg = new WSMessage();
msg.Module = "prop";
msg.ServiceName = "StartUseProp";
msg.Data = ByteString.CopyFrom(ProtoBufffer.Serialize(data));
byte[] sendData = ProtoBufffer.Serialize(msg);
WSMessage deinfo = ProtoBufffer.DeSerialize<WSMessage>(sendData);
PropRequest login = ProtoBufffer.DeSerialize<PropRequest>(deinfo.Data.ToByteArray());
Debug.Log("使用道具");
//BroadcastFrameMsg.FramesFieldNumber
wEBScriptListener.SendMessageByte(sendData);
}
//停止使用道具
void StopUseProp()
{
PropRequest data = new PropRequest();
data.RoomId = "168888";
data.PropId = 1001;
data.PropServerId = "MTg1OTc5MDMwOTIyODc4OTc2MA==";
WSMessage msg = new WSMessage();
msg.Module = "prop";
msg.ServiceName = "StopUseProp";
msg.Data = ByteString.CopyFrom(ProtoBufffer.Serialize(data));
byte[] sendData = ProtoBufffer.Serialize(msg);
WSMessage deinfo = ProtoBufffer.DeSerialize<WSMessage>(sendData);
PropRequest login = ProtoBufffer.DeSerialize<PropRequest>(deinfo.Data.ToByteArray());
Debug.Log("停止使用道具");
//BroadcastFrameMsg.FramesFieldNumber
wEBScriptListener.SendMessageByte(sendData);
}
//创建NPC ========================暂时不需要
//void CreateNpc()
//{
// PropRequest data = new PropRequest();
// data.RoomId = "168888";
// WSMessage msg = new WSMessage();
// msg.Module = "move";
// msg.ServiceName = "CreateNpc";
// msg.Data = ByteString.CopyFrom(ProtoBufffer.Serialize(data));
// byte[] sendData = ProtoBufffer.Serialize(msg);
// WSMessage deinfo = ProtoBufffer.DeSerialize<WSMessage>(sendData);
// PropRequest login = ProtoBufffer.DeSerialize<PropRequest>(deinfo.Data.ToByteArray());
// Debug.Log("创建NPC");
// //BroadcastFrameMsg.FramesFieldNumber
// wEBScriptListener.SendMessageByte(sendData);
//}
//推送npc和玩家的信息 ===============只需要收消息
//void Location()
//{
// PropRequest data = new PropRequest();
// data.RoomId = "168888";
// WSMessage msg = new WSMessage();
// msg.Module = "prop";
// msg.ServiceName = "CreateNpc";
// msg.Data = ByteString.CopyFrom(ProtoBufffer.Serialize(data));
// byte[] sendData = ProtoBufffer.Serialize(msg);
// WSMessage deinfo = ProtoBufffer.DeSerialize<WSMessage>(sendData);
// PropRequest login = ProtoBufffer.DeSerialize<PropRequest>(deinfo.Data.ToByteArray());
// Debug.Log("推送npc和玩家的信息");
// //BroadcastFrameMsg.FramesFieldNumber
// wEBScriptListener.SendMessageByte(sendData);
//}
//开始计时
void RoomStartTime()
{
JoinRoomRequest data = new JoinRoomRequest();
data.RoomId = "168888";
WSMessage msg = new WSMessage();
msg.Module = "hall";
msg.ServiceName = "RoomStartTime";
msg.Data = ByteString.CopyFrom(ProtoBufffer.Serialize(data));
byte[] sendData = ProtoBufffer.Serialize(msg);
WSMessage deinfo = ProtoBufffer.DeSerialize<WSMessage>(sendData);
JoinRoomRequest login = ProtoBufffer.DeSerialize<JoinRoomRequest>(deinfo.Data.ToByteArray());
Debug.Log("推送npc和玩家的信息");
//BroadcastFrameMsg.FramesFieldNumber
wEBScriptListener.SendMessageByte(sendData);
}
void Location()
{
MoveResponse data = new MoveResponse();
data.RoomId = "168888";
WSMessage msg = new WSMessage();
msg.Module = "move";
msg.ServiceName = "Location";
msg.Data = ByteString.CopyFrom(ProtoBufffer.Serialize(data));
byte[] sendData = ProtoBufffer.Serialize(msg);
WSMessage deinfo = ProtoBufffer.DeSerialize<WSMessage>(sendData);
MoveResponse login = ProtoBufffer.DeSerialize<MoveResponse>(deinfo.Data.ToByteArray());
Debug.Log("推送npc和玩家的信息");
//BroadcastFrameMsg.FramesFieldNumber
wEBScriptListener.SendMessageByte(sendData);
}
// Start is called before the first frame update
async void Start()
{
//loging();
wEBScriptListener.ConcatWEBSocket();
wEBScriptListener.OnCallback += callback;
if (wEBScriptListener != null)
{
lodingWebSocket();
//JoinRoom();
//Heartbeat();
//BroadcastMessage();
//UpFps();
//PickUpProp();
//StartUseProp();
//StopUseProp();
//RoomStartTime();
//Location();
}
int index = 0;
//while (true)
//{
// index++;
// NpcData moveData = new NpcData();
// moveData.X = index;
// moveData.Y = 1;
// moveData.Z = 1;
// MoveResponse data = new MoveResponse();
// data.MoveData.Add(moveData);
// WSResponse ws = new WSResponse();
// ws.MessageType = "move.Location";
// ws.Data = ByteString.CopyFrom(data.ToByteArray());
// callback(ProtoBufffer.Serialize(ws));
// //PlayerJoinResponse pj = new PlayerJoinResponse();
// //pj.UserName = "abc";
// //pj.RoomId = "2";
// //pj.Status = 0;
// //pj.RoleName = "ABC";
// //pj.IsLeadingNPC = 5;
// //pj.Online = true;
// //pj.RoleId = 7;
// //pj.GroupLeader = 0;
// //pj.ActionMode = 2;
// //pj.Group = -1;
// //pj.X = 11;
// //pj.Y = 12;
// //pj.Z = 13;
// //pj.OverseeCond = "14";
// //pj.SendFrameCount = 15;
// //pj.MoveSpeedFirst = 16;
// //pj.MoveSpeedSecond = 17;
// //pj.MoveSpeedThird = 18;
// //pj.BearLoad = 19;
// //pj.Protection = 20;
// //pj.Health = 21;
// //pj.RoleStatus = 22;
// //pj.UserId = 23;
// //JoinRoomResponse data = new JoinRoomResponse();
// //data.Data = pj;
// //WSResponse ws = new WSResponse();
// //ws.MessageType = "hall.JoinRoom";
// //ws.Data = ByteString.CopyFrom(data.ToByteArray());
// //callback(ProtoBufffer.Serialize(ws));
// await Task.Delay(1000);
//}
}
void callback(byte[] data)
{
WSResponse deinfo = ProtoBufffer.DeSerialize<WSResponse>(data);
Debug.Log("返回数据类型:"+deinfo.MessageType);
byte[] bytes = deinfo.Data.ToByteArray();
switch (deinfo.MessageType)
{
//监听
//登录
case "hall.Login":
Debug.Log("-=====--");
LoginResponse user = ProtoBufffer.DeSerialize<LoginResponse>(bytes);
Debug.Log(user);
break;
//加入房间
case "hall.JoinRoom":
JoinRoomResponse joinRoomResponse = ProtoBufffer.DeSerialize<JoinRoomResponse>(bytes);
byte[] joinByte = joinRoomResponse.Data.ToByteArray();
PlayerJoinResponse playerJoinResponse = ProtoBufffer.DeSerialize<PlayerJoinResponse>(joinByte);
Debug.Log("玩家:"+playerJoinResponse.UserName+"加入房间:"+playerJoinResponse.RoomId.ToString());
break;
//广播
case "hall.BroadcastMessage":
UserJoinResponse userJoinResponse = ProtoBufffer.DeSerialize<UserJoinResponse>(bytes);
Debug.Log("玩家昵称:" + userJoinResponse.NickName + ",房间:" + userJoinResponse.RoomId.ToString() + ",用户角色"+ userJoinResponse.RoleName);
Debug.Log(userJoinResponse.IncidentPosition);
Debug.Log(userJoinResponse);
break;
//
case "fps.UpFps":
InputData inputData = ProtoBufffer.DeSerialize<InputData>(bytes);
Debug.Log("Id" + inputData.Id + ",sId :" + inputData.SId + "X:"+ inputData.X.ToString() + "Y:" + inputData.Y.ToString() + "roomSeatId :" + inputData.RoomSeatId + "z:" + inputData.Z.ToString() + "roomId:" + inputData.RoomId);
break;
case "prop.PickUpProp":
PropRequest propRequest = ProtoBufffer.DeSerialize<PropRequest>(bytes);
Debug.Log("PropId:" + propRequest.PropId);
break;
case "prop.StartUseProp":
PropResponse useProp = ProtoBufffer.DeSerialize<PropResponse>(bytes);
Debug.Log("PropId:" + useProp);
break;
case "prop.StopUseProp":
PropResponse stopuseProp = ProtoBufffer.DeSerialize<PropResponse>(bytes);
Debug.Log("PropId:" + stopuseProp);
break;
case "move.Location":
Debug.Log("move.Location接受到了");
NpcData npcData = ProtoBufffer.DeSerialize<NpcData>(bytes);
Debug.Log(npcData);
float x = npcData.X;
float y = npcData.Y;
float z = npcData.Z;
GameObject npc = GameObject.CreatePrimitive(PrimitiveType.Cube);
npc.transform.name = npcData.UserId;
npc.transform.localScale = new Vector3(0.5f, 0.5f, 0.5f);
npc.transform.position = new Vector3(x, y + 0.25f, z);
npc.transform.parent = GameObject.Find("schoo103").transform;
break;
//case "prop.CreateNpc":
// MoveResponse moveResponse = ProtoBufffer.DeSerialize<MoveResponse>(bytes);
// Debug.Log("UserId:" + moveResponse.UserId + "RoomId:" + moveResponse.RoomId + "x:" + moveResponse.MoveData);
// break;
//case "hall.RoomStartTime":
// JoinRoomRequest joinRoomRequest = ProtoBufffer.DeSerialize<JoinRoomRequest>(bytes);
// Debug.Log("PropId:" + joinRoomRequest.RoomId);
// break;
//case " hall.MessageToUser":
// //JoinRoomRequest joinRoomRequest = ProtoBufffer.DeSerialize<JoinRoomRequest>(bytes);
// //Debug.Log("PropId:" + joinRoomRequest.RoomId);
// break;
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: c68b1dcfbba61b44ca68572c16b16b95
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 8793aaca69ae59144b8d5ec239fdd04e
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,20 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class test1 : Base
{
// Start is called before the first frame update
async void Start()
{
GetComponent<Image>().sprite = await GlobalObj.GetComponent<ImageLoader>().LoadImageAsync("https://fantasymonster-app.oss-cn-hangzhou.aliyuncs.com/goods/mall/c7860d8909194d479b6f27ccb922e863.png");
}
// Update is called once per frame
void Update()
{
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: c02b3c0b40de2c84c8cd8d2edb52f70d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,109 @@
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using Unity.VisualScripting.Antlr3.Runtime;
using UnityEngine;
using UnityEngine.Networking;
public class web : MonoBehaviour
{
public const string URL = "http://192.168.3.103:8089"; // 被注释掉的服务器地址(常量)
//public const string URL = "ws://124.221.149.22:38445/safety/cloud"; // 被注释掉的服务器地址(常量)
// 存储服务器返回的Cookie
private static Dictionary<string, string> cookieJar = new Dictionary<string, string>();
// 发送HTTP请求的方法支持GET和POST等不同的请求方式
public static async Task<string> SendRequest(string url, string method = "GET", string jsonData = "{}", Dictionary<string, string> head = null)
{
Debug.Log(url + "启动web"); // 调试输出,启动网络请求
// 使用UnityWebRequest类进行HTTP请求支持自定义请求方法
using (UnityWebRequest request = new UnityWebRequest(url, method))
{
// 设置下载处理器,用于处理服务器响应的数据
request.downloadHandler = new DownloadHandlerBuffer();
// 如果是POST请求设置请求体
if (method == "POST" && jsonData != null)
{
// 将JSON字符串转换为字节数组
byte[] bodyRaw = Encoding.UTF8.GetBytes(jsonData);
// 设置上传处理器,用于发送请求体数据
request.uploadHandler = new UploadHandlerRaw(bodyRaw);
// 设置请求头指定请求体内容类型为JSON
request.SetRequestHeader("Content-Type", "application/json");
}
// 如果请求头部存在,添加请求头部信息
if (head != null)
foreach (string key in head.Keys)
{
// 遍历传入的头部字典,逐项设置请求头部
request.SetRequestHeader(key, head[key]);
}
// 设置已存储的 Cookie
if (cookieJar.Count > 0)
{
// 用于存储多个cookie值的字符串
string cookieHeader = "";
foreach (var cookie in cookieJar)
{
// 格式化每个cookie为“键=值”的形式,并附加到字符串中,以分号分隔
cookieHeader += $"{cookie.Key}={cookie.Value}; ";
}
// 设置请求头中的Cookie字段
request.SetRequestHeader("Cookie", cookieHeader);
}
// 发送请求并等待响应
var operation = request.SendWebRequest();
while (!operation.isDone)
await Task.Yield(); // 等待请求完成使用await以非阻塞的方式处理
// 检查是否存在网络错误或协议错误
if (request.result == UnityWebRequest.Result.ConnectionError || request.result == UnityWebRequest.Result.ProtocolError)
{
// 如果有错误输出错误信息并返回null
Debug.LogError($"Error: {request.error}" + url);
// 可以自定义弹窗提示用户错误信息,代码被注释掉了
// Promptmgr.Instance.PromptBubble(request.error, Color.black,Color.red);
return null;
}
else
{
// 处理返回的Cookie
string setCookieHeader;
string str = request.downloadHandler.text; // 获取服务器返回的文本内容
//Debug.Log(str); // 输出返回内容到控制台
// 尝试获取响应头中的“Set-Cookie”字段
if (request.GetResponseHeaders().TryGetValue("Set-Cookie", out setCookieHeader))
{
// 将“Set-Cookie”字段的内容按分号分隔为多个部分
string[] cookies = setCookieHeader.Split(';');
foreach (var cookie in cookies)
{
// 将每个cookie分为“键=值”的形式
var cookieParts = cookie.Split('=');
if (cookieParts.Length == 2)
{
string key = cookieParts[0].Trim(); // 去掉键的空格
string value = cookieParts[1].Trim(); // 去掉值的空格
// 存储到cookieJar中以备后续请求使用
cookieJar[key] = value;
}
}
}
// 返回响应内容(文本形式)
return request.downloadHandler.text;
}
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 2c4b51a8b53ef05469c7aa617c131ad1
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: