【发布时间】:2017-10-18 15:53:41
【问题描述】:
我需要向 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);
}
}
【问题讨论】:
标签: c# unity3d networking