0
我需要補充的服務渠道模式,NetworkManager的一些額外的質量,我試圖做這樣:添加的服務渠道模式的其他質量NetworkManager的
NetworkManager netMan;
void Start() {
ConnectionConfig cc = new ConnectionConfig();
reliableChannel = cc.AddChannel(QosType.Reliable);
reliableSeqChannel = cc.AddChannel(QosType.ReliableSequenced);
reliableFragChannel = cc.AddChannel(QosType.ReliableFragmented);
unreliableChannel = cc.AddChannel(QosType.Unreliable);
unreliableSeqChannel = cc.AddChannel(QosType.UnreliableSequenced);
cc.PacketSize = 1440;
netMan.connectionConfig = cc;
}
但我發現了錯誤:Property or indexer 'NetworkManager.connectionConfig' cannot be assigned to -- it is readonly
如果該屬性是隻讀的,那麼創建其他渠道到NetworkManager的正確方法是什麼?
...下面
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
public class Server : MonoBehaviour {
public Texture2D textureToSend;
string messageToSend = "Test Message";
NetworkManager netMan;
private int reliableChannel;
private int reliableSeqChannel;
private int reliableFragChannel;
private int unreliableChannel;
private int unreliableSeqChannel;
// Use this for initialization
void Start() {
ConnectionConfig cc = new ConnectionConfig();
reliableChannel = cc.AddChannel(QosType.Reliable);
reliableSeqChannel = cc.AddChannel(QosType.ReliableSequenced);
reliableFragChannel = cc.AddChannel(QosType.ReliableFragmented);
unreliableChannel = cc.AddChannel(QosType.Unreliable);
unreliableSeqChannel = cc.AddChannel(QosType.UnreliableSequenced);
cc.PacketSize = 1440;
netMan.connectionConfig = cc;
NetworkManager.singleton.StartHost();
Debug.Log("Server Started.");
}
public void SendOnButtonPress()
{
SendTexture(textureToSend, messageToSend);
}
//Call to send the Texture and a simple string message
public void SendTexture(Texture2D texture, string message)
{
TextureMessage msg = new TextureMessage();
//Convert Texture2D to byte array
msg.textureBytes = texture.GetRawTextureData();
msg.message = message;
NetworkServer.SendToAll(MyMsgType.texture, msg);
}
}