ushort 返回编辑器设置中缓存服务器的端口号。如果编辑器设置中未设置端口号,则返回 0。
获取编辑器设置中缓存服务器的端口号。
注意:如果您为端口号设置了新值,则在调用 AssetDatabase.RefreshSettings() 之前,您的新设置不会应用。但是,无论您是否应用了设置,此方法都会返回您设置的值。
using UnityEngine; using UnityEditor;
public class AssetDatabaseExamples : MonoBehaviour
{ [MenuItem("AssetDatabase/Debugging Connection to the Cache Server")] static void DebuggingConnectionToTheCacheServer() { //This will Enable Cache Server in Project Settings EditorSettings.cacheServerMode = CacheServerMode.Enabled; Debug.Log("Is Cache Server Enabled? - " + AssetDatabase.IsCacheServerEnabled());
var cacheServerIP = "10.37.44.195"; ushort cacheServerPort = 10443;
if (AssetDatabase.IsConnectedToCacheServer() == false) { if (AssetDatabase.CanConnectToCacheServer(cacheServerIP, cacheServerPort) == false) { Debug.Log("Cache server is not available, check IP address and Port Number"); }
else { Debug.Log("Cache server is available, but not connected now. Set correct IP and Port Number in Project Settings"); } }
else { Debug.Log("Cache Server is connected"); Debug.Log("Cache Server IP: " + AssetDatabase.GetCacheServerAddress()); Debug.Log("Cache Server Port Number: " + AssetDatabase.GetCacheServerPort()); } } }