Network
- AllocateViewID
- CloseConnection
- connections
- connectionTesterIP
- connectionTesterPort
- Connect
- DestroyPlayerObjects
- Destroy
- Disconnect
- GetAveragePing
- GetLastPing
- HavePublicAddress
- incomingPassword
- InitializeSecurity
- InitializeServer
- Instantiate
- isClient
- isMessageQueueRunning
- isServer
- logLevel
- maxConnections
- minimumAllocatableViewIDs
- natFacilitatorIP
- natFacilitatorPort
- OnConnectedToServer
- OnDisconnectedFromServer
- OnFailedToConnectToM...
- OnFailedToConnect
- OnNetworkInstantiate
- OnPlayerConnected
- OnPlayerDisconnected
- OnSerializeNetworkView
- OnServerInitialized
- peerType
- player
- proxyIP
- proxyPassword
- proxyPort
- RemoveRPCsInGroup
- RemoveRPCs
- sendRate
- SetLevelPrefix
- SetReceivingEnabled
- SetSendingEnabled
- TestConnectionNAT
- TestConnection
- time
- useProxy
Network.HavePublicAddress 有公网地址?
static function HavePublicAddress () : bool
Description描述
Check if this machine has a public IP address.
检测这台机器是否有一个公网IP地址。
It checks all the network interfaces for IPv4 public addresses and returns true if one address is found.
检查所有网络接口来获取Ipv4公网地址,如发现返回true。
using UnityEngine;
using System.Collections;
public class example : MonoBehaviour {
void OnGUI() {
if (GUILayout.Button("Start Server")) {
bool useNat = !Network.HavePublicAddress();
Network.InitializeServer(32, 25002, useNat);
MasterServer.RegisterHost("MyUniqueGameType", "JohnDoes game", "l33t game for all");
}
}
}
function OnGUI() {
if (GUILayout.Button ("Start Server")) {
// Use NAT punchthrough if no public IP present
//如果没有公网IP,使用NAT穿透
var useNat = !Network.HavePublicAddress();
Network.InitializeServer(32, 25002, useNat);
MasterServer.RegisterHost("MyUniqueGameType",
"JohnDoes game", "l33t game for all");
}
}
最后修改:2011年4月4日 Monday 18:02