Closed nvh2001 closed 3 days ago
Let me know what is ServerResponse: I mean give me acess to ServerResponse
struct ServerResponse
{
?
}
Let me know what is ServerResponse: I mean give me acess to ServerResponse
struct ServerResponse { ? }
sorry for that The struct is here. tks
public struct ServerResponse
{
public TypeResponse typeResponse;
public string? message;
}
What is TypeResponse? (enum‽)
What is TypeResponse? (enum‽)
yep
public enum TypeResponse
{
None,
// Player - Sucess
WebSocketConnectSucces,
GetUserSuccess,
// Player - Error
RemoveSuccess,
NullId,
GetUserError,
SeverMax,
Have2PlayerId,
}
Thanks for you help I'll solve this, after I'll give you a feedback. (Nguyen Van Hao) @nvh2001, thanks for your contribution about Byter 💐
use { get; set }
on propriety
public struct ServerResponse
{
public TypeResponse typeResponse { get; set; }
public string? message { get; set; }
}
This solved your problem? :smile:
#
Fixed
use
{ get; set }
on proprietypublic struct ServerResponse { public TypeResponse typeResponse { get; set; } public string? message { get; set; } }
This solved your problem? 😄
Optional
You can use Byter Encoding Extension instead of raw System.Text.Encoding
it's not working (unity & console .NET 8)
when using {get; set} this lib has error
NullReferenceException: Object reference not set to an instance of an object
Byter.PrimitiveExtension.ToPrimitive[T] (T value, System.Type type) (at Assets/_Game/02.Script/Ultilities/Alec1oByter/extension/PrimitiveExtension.cs:20)
Byter.Primitive+PrimitiveAdd.Struct[T] (T value) (at Assets/_Game/02.Script/Ultilities/Alec1oByter/primitive/partials/PrimitiveAdd.cs:197)
Byter.PrimitiveExtension.ToPrimitive[T] (T value, System.Type type) (at Assets/_Game/02.Script/Ultilities/Alec1oByter/extension/PrimitiveExtension.cs:110)
Byter.Primitive+PrimitiveAdd.Struct[T] (T value) (at Assets/_Game/02.Script/Ultilities/Alec1oByter/primitive/partials/PrimitiveAdd.cs:197)
RoomController.CreateRoom (System.String roomName, System.Int32 password, System.Int32 point) (at Assets/_Game/02.Script/Popup/Controller/RoomController.cs:25)
PopupRoomCreation.Create () (at Assets/_Game/02.Script/Popup/View/Room/PopupRoomCreation.cs:36)
UnityEngine.Events.InvokableCall.Invoke () (at <e509afeff7384f24a8f0ac30527ff01c>:0)
UnityEngine.Events.UnityEvent.Invoke () (at <e509afeff7384f24a8f0ac30527ff01c>:0)
UnityEngine.UI.Button.Press () (at ./Library/PackageCache/com.unity.ugui@2.0.0/Runtime/UGUI/UI/Core/Button.cs:70)
UnityEngine.UI.Button.OnPointerClick (UnityEngine.EventSystems.PointerEventData eventData) (at ./Library/PackageCache/com.unity.ugui@2.0.0/Runtime/UGUI/UI/Core/Button.cs:114)
UnityEngine.EventSystems.ExecuteEvents.Execute (UnityEngine.EventSystems.IPointerClickHandler handler, UnityEngine.EventSystems.BaseEventData eventData) (at ./Library/PackageCache/com.unity.ugui@2.0.0/Runtime/UGUI/EventSystem/ExecuteEvents.cs:57)
UnityEngine.EventSystems.ExecuteEvents.Execute[T] (UnityEngine.GameObject target, UnityEngine.EventSystems.BaseEventData eventData, UnityEngine.EventSystems.ExecuteEvents+EventFunction`1[T1] functor) (at ./Library/PackageCache/com.unity.ugui@2.0.0/Runtime/UGUI/EventSystem/ExecuteEvents.cs:272)
UnityEngine.EventSystems.EventSystem:Update() (at ./Library/PackageCache/com.unity.ugui@2.0.0/Runtime/UGUI/EventSystem/EventSystem.cs:530)
I tested in dotnet 8 console application and this (get;set) fixed the problem.
Let me test it on unity 6
Tôi đã thử nghiệm trong ứng dụng giao diện điều khiển dotnet 8 và điều này (get; bộ) đã khắc phục sự cố.
Hãy để tôi kiểm tra nó trên unity 6
My code, i tested both unity and .net 8
CreateRoomRequest request = new CreateRoomRequest();
request.RoomName = roomName;
request.Password = password;
request.PriceRoom = point;
request.PlayerSessionModel = GameHelper.Instance.net.playerSessionModel;
//var sender = GameHelper.Instance.net.sender;
Primitive sender = new Primitive();
sender.Reset();
sender.Add.Struct(request);
Isn't working in .NET 8? How did you install Byter? Copy sources or Nuget
Isn't working in .NET 8? How did you install Byter? Copy sources or Nuget
i download src from github (unity & console .net 8)
It's working for me on Unity 6 and dotnet 8. Just set {get;set} on ServerResponse struct
using UnityEngine;
using Byter;
using System.Text;
public class Scrip : MonoBehaviour
{
public struct ServerResponse
{
public TypeResponse typeResponse { get; set; }
public string message { get; set; }
}
public enum TypeResponse
{
None,
// Player - Sucess
WebSocketConnectSucces,
GetUserSuccess,
// Player - Error
RemoveSuccess,
NullId,
GetUserError,
SeverMax,
Have2PlayerId,
}
private void Start()
{
// set data
Primitive primitive = new();
var a = new ServerResponse() { typeResponse = TypeResponse.WebSocketConnectSucces, message = "xxx1" };
primitive.Add.Struct(a);
// get data
byte[] buffer = primitive.GetBytes();
var message = Encoding.UTF8.GetString(buffer);
Debug.Log(message);
Debug.Log(message.Length);
}
}
On your server: (i think you are using console application)
# cd myserverpath
dotnet add package byter --version 3.0.0
On your unity
NOTE: Note even without putting {get;set} I never got an exception, Byter should never throw an exception (so you should never need try/catch), I think you might be using outdated source-code
- Delete all sources code on your server and unity
On your server: (i think you are using console application)
# cd myserverpath dotnet add package byter --version 3.0.0
On your unity
- Download Byter300.dll and include on /Asset/Plugins/Byter300.dll
NOTE: Note even without putting {get;set} I never got an exception, Byter should never throw an exception (so you should never need try/catch), I think you might be using outdated source-code
Thank you, I will try, my project has a short deadline :)))
Debug.Log(message);
Debug.Log(message.Length);
Thank you, I will try, my project has a short deadline :)))
Maybe this looks hard, I'll show you how do this.
Delete Alec1oByter folder (image)
Download Byter300 (v3.0.0) compiled (image). use this link to download
Copy Byter300.dll to your unity folder. that's all :grinning: . (image)
Error when the Struct has a Struct as children. (maybe i think) roomName, password and priceRoom will null if i add { get; set; } for 'public PlayerSessionModel playerSessionModel;' but no null if delete { get; set; } for public PlayerSessionModel playerSessionModel;
[Serializable]
public struct CreateRoomRequest
{
public string roomName { get; set; }
public int password { get; set; }
public int priceRoom { get; set; }
public PlayerSessionModel playerSessionModel;
}
[Serializable]
public struct PlayerSessionModel
{
public TypeStatePlayer? statePlayer { get; set; }
public string? name { get; set; }
public string? id { get; set; }
public long? point { get; set; }
public WebUserInfo? webUserInfo;
public void SetWebUserInfo(WebUserInfo? webUserInfo)
{
this.webUserInfo = webUserInfo;
}
public void SetModel(PlayerSessionModel model)
{
this = model;
}
}
[Serializable]
public struct WebUserInfo
{
[JsonProperty("phone")]
public string? phone { get; set; }
[JsonProperty("_id")]
public string? _id { get; set; }
[JsonProperty("name")]
public string? name { get; set; }
[JsonProperty("email")]
public string? email { get; set; }
[JsonProperty("username")]
public string? username { get; set; }
[JsonProperty("telegram_id")]
public string? telegram_id { get; set; }
[JsonProperty("avatar")]
public Avatar? avatar { get; set; }
[JsonProperty("banner")]
public object? banner { get; set; }
[JsonProperty("is_active")]
public bool? is_active { get; set; }
[JsonProperty("invite_code")]
public string? invite_code { get; set; }
[JsonProperty("balance")]
public long? balance { get; set; }
[JsonProperty("titles")]
public string? titles { get; set; }
[JsonProperty("wallets")]
public object? wallets { get; set; }
[JsonProperty("is_online")]
public bool? is_online { get; set; }
[JsonProperty("is_email_verified")]
public bool? is_email_verified { get; set; }
[JsonProperty("is_phone_verified")]
public bool? is_phone_verified { get; set; }
[JsonProperty("is_telegram_verified")]
public bool? is_telegram_verified { get; set; }
[JsonProperty("is_wallet_connect")]
public bool? is_wallet_connect { get; set; }
[JsonProperty("tickets")]
public int? tickets { get; set; }
[JsonProperty("usdt_balance")]
public int? usdt_balance { get; set; }
[JsonProperty("last_online_at")]
public DateTime? last_online_at { get; set; }
[JsonProperty("about")]
public string? about { get; set; }
[JsonProperty("is_use_password")]
public bool? is_use_password { get; set; }
[JsonProperty("id")]
public string? id { get; set; }
[JsonProperty("telegram_ref")]
public string? telegram_ref;
}
have same issue when Struct in struct
I see more. Byter error on WEBGL unity
ok lemme test it
1st. Byter does not support object type "typeof(object)": (WebUserInfo->banner, wallets is object type), The reason has already been answered here: Good way to put Struct and Class in params object[] args? #26 (comment)
2nd. [STOP USE C# NULLABLE] Nullable has been added since C# 8 .0 (.net core 3.0). Don't use (? suffix), Byter uses .NET Standard 2.0 (to support legacy and recent versions, from .NET framework 4.6.1 to the latest) and byter doesn't know what (?) is for example (Avatar? avatar) , If you stop using (?) the byter will understand your code. Note it is "impossible" to add support to (?) because of using .NET standard 2.0 and not .NET Standard 2.1 (just supported by .NET 3, 5, 6, 7, 8, 9...)
:heart: Everything is working, just fix the 2 errors mentioned above! :rose:
(maybe i think) roomName, password and priceRoom will null if i add { get; set; } for 'public PlayerSessionModel playerSessionModel;' but no null if delete { get; set; } for public PlayerSessionModel playerSessionModel;
No, that's not it, always use { get; set; } 1000% recommended instead of removing this (as much as it works without { get or set }, I always recommend adding {get; set;})
(maybe i think) roomName, password and priceRoom will null if i add { get; set; } for 'public PlayerSessionModel playerSessionModel;' but no null if delete { get; set; } for public PlayerSessionModel playerSessionModel;
No, that's not it, always use { get; set; } 1000% recommended instead of removing this (as much as it works without { get or set }, I always recommend adding {get; set;})
It's work incorrecly, group will be null
public struct Idol
{
public string name { get; set; }
public ushort birthdayYear { get; set; }
public Group group;
}
public struct Group
{
public string name { get; set; }
public ushort birthdayYear { get; set; }
}
Idol idol = new Idol();
idol.name = "Karina";
idol.birthdayYear = 2000;
idol.group = new Group();
idol.group.name = "aespa";
idol.group.birthdayYear = 2019;
Primitive send = new Primitive();
send.Add.Struct(idol);
Primitive recive = new Primitive(send.GetBytes());
var reIdol = recive.Get.Struct<Idol>();
Debug.Log(reIdol.name);
Debug.Log(reIdol.birthdayYear);
Debug.Log(reIdol.group.name);
Debug.Log(reIdol.group.birthdayYear);
add {get; set;} to Idol->group
add {get; set;} to Idol->group
Severity Code Description Project File Line Suppression State Error CS1612 Cannot modify the return value of 'Idol.group' because it is not a variable Assembly-CSharp
Give me 1s
Give me 1s
just slowly comfortable
Just slowly comfortable :rofl: :rofl: :rofl: :rofl:
It's working! :rofl: :rofl: :rofl: :rofl:
Idol idol = new Idol();
idol.name = "Karina";
idol.birthdayYear = 2000;
idol.group = new Group
{
name = "aespa",
birthdayYear = 2019,
};
Primitive send = new Primitive();
send.Add.Struct(idol);
Primitive recive = new Primitive(send.GetBytes());
var reIdol = recive.Get.Struct<Idol>();
Debug.Log(reIdol.name);
Debug.Log(reIdol.birthdayYear);
Debug.Log(reIdol.group.name);
Debug.Log(reIdol.group.birthdayYear);
you make a mistake (c# side)
idol.group = new Group();
idol.group.name = "aespa";
idol.group.birthdayYear = 2019;
idol.group = new Group()
{
name = "aespa";
birthdayYear = 2019;
}
Struct looks like a class but is liite but more complex.
It's working now?
It's woking!!!!!!!! Now I trying test with list and array of struct !!!!
It's woking!!!!!!!! Now I trying test with list and array of struct !!!!
Ok, I think this supports Array<Struct|Class|List<Array
Example:
class A
{
List<B> MyB;
}
class B
{
C[] MyCs;
}
class C
{
List<A[]> MyAs;
List<List<B>> MyBs;
}
Yep it's working with Array and List of struct, so I trying Struc in struct of a struct
Byter don't have data deep limitation, Make how much complex data it's possible. :rofl: :partying_face:
Byter don't have data deep limitation, Make how much complex data it's possible. 🤣 🥳
work work!!!!! just get set. And add data from within (a bit tricky)
Byter don't have data deep limitation, Make how much complex data it's possible. 🤣 🥳
A thing i can reveal for u, dll CAN'T build on Webgl but folder src can do it
Give me 1s
A thing i can reveal for u, dll CAN'T build on Webgl but folder src can do it
I know. you told me before! :rofl: :rofl: :rofl:
I was not know that you had build to WebGL :globe_with_meridians:
Delete Byter300.dll to your unity folder. (WebGL don't accept ddl files, but Android, iOS, macOS and Linux supports .dll files). (image)
Download Byter-300-Include.zip (v3.0.0 sources). (image). use this link to download
Unzip Byter-300-Include.zip and Copy unziped (Byter-300-Include) folder to your unity folder. that's all :grinning: . (image)
It's working?
Byter don't have data deep limitation, Make how much complex data it's possible. 🤣 🥳
A thing i can reveal for u, dll CAN'T build on Webgl but folder src can do it
You reminded me C/C++ programmer, always download and unzip library, GLFW, ImGUI, Glad, GLM... :rofl: :rofl: :rofl: (I love use package manager instead of manual past sources in my projects) :rofl: :rofl:
I try to send struct with byter but error, the data is null. Tks