String from input field to datastream
Hi,
I'm very new to Unity and I'm trying to learn how to work with the transport layer but am finding the documentation difficult to follow. Here are some of the details:
Unity 2021.2.8f1
Unity Transport 1.0.0-pre.12
jobs 0.11.0-preview.6
I've found a really helpful tutorial however, it was created 11 months ago and I believe there have been a few versions of Transport and Jobs released since then. That being said:
The Setup: I have an Input Field used to enter text. The text should be passed to the server and displayed in the log.
The Code: ChatMessageTest.cs using TMPro; using UnityEngine; using Unity.Collections;
public class ChatMessageTest : MonoBehaviour
{
[SerializeField] private TMP_InputField chatInput;
public void OnSubmitClick()
{
Net_ChatMessage msg = new Net_ChatMessage(chatInput.text);
FindObjectOfType<BaseClient>().SendToServer(msg);
}
}
Net_ChatMessage using Unity.Collections; using Unity.Networking.Transport; using UnityEngine;
public class Net_ChatMessage : NetMessage
{
// 0 - 8 first bits are reserved for the OP Code
// 8 - 128 String message
public FixedString128Bytes ChatMessage { set; get; }
public Net_ChatMessage()
{
Code = OpCode.CHAT_MESSAGE;
}
public Net_ChatMessage(DataStreamReader reader)
{
Code = OpCode.CHAT_MESSAGE;
Deserialize(reader);
}
public override void Serialize(ref DataStreamWriter writer)
{
writer.WriteByte((byte)Code);
writer.WriteFixedString128(ChatMessage);
}
public override void Deserialize(DataStreamReader reader)
{
// The first byte is already handled by the 'OnData' function in base server.
ChatMessage = reader.ReadFixedString128();
}
public override void ReceivedOnServer()
{
Debug.Log("SERVER::" + ChatMessage);
//base.ReceivedOnServer();
}
public override void ReceivedOnClient()
{
Debug.Log("CLIENT::" + ChatMessage);
//base.ReceivedOnServer();
}
}
The error message:
CS1503 Argument 1: cannot convert from 'string' to Unity.Networking.Transport.DataStreamReader'
I have that funny feeling that I'm missing something simply. I just can't seem to figure out how convert it. It's been a long day. I'm open to any help on this and any suggestions you may have for documentation/tutorials/sources for more information