UnityEngine.Networking.NetworkDiscovery.StringToBytes C# (CSharp) Method

StringToBytes() private static method

private static StringToBytes ( string str ) : byte[]
str string
return byte[]
        private static byte[] StringToBytes(string str)
        {
            byte[] dst = new byte[str.Length * 2];
            Buffer.BlockCopy(str.ToCharArray(), 0, dst, 0, dst.Length);
            return dst;
        }

Usage Example

示例#1
0
        public bool Initialize()
        {
            bool result;

            if (this.m_BroadcastData.Length >= 1024)
            {
                if (LogFilter.logError)
                {
                    Debug.LogError("NetworkDiscovery Initialize - data too large. max is " + 1024);
                }
                result = false;
            }
            else
            {
                if (!NetworkTransport.IsStarted)
                {
                    NetworkTransport.Init();
                }
                if (this.m_UseNetworkManager && NetworkManager.singleton != null)
                {
                    this.m_BroadcastData = string.Concat(new object[]
                    {
                        "NetworkManager:",
                        NetworkManager.singleton.networkAddress,
                        ":",
                        NetworkManager.singleton.networkPort
                    });
                    if (LogFilter.logInfo)
                    {
                        Debug.Log("NetworkDiscovery set broadcast data to:" + this.m_BroadcastData);
                    }
                }
                this.m_MsgOutBuffer       = NetworkDiscovery.StringToBytes(this.m_BroadcastData);
                this.m_MsgInBuffer        = new byte[1024];
                this.m_BroadcastsReceived = new Dictionary <string, NetworkBroadcastResult>();
                ConnectionConfig connectionConfig = new ConnectionConfig();
                connectionConfig.AddChannel(QosType.Unreliable);
                this.m_DefaultTopology = new HostTopology(connectionConfig, 1);
                if (this.m_IsServer)
                {
                    this.StartAsServer();
                }
                if (this.m_IsClient)
                {
                    this.StartAsClient();
                }
                result = true;
            }
            return(result);
        }
All Usage Examples Of UnityEngine.Networking.NetworkDiscovery::StringToBytes