private static void OnPreferencesReadGUI()
        {
            bool shouldTryConnect = s_ConnectionState == ConnectionState.Unknown &&
                                    (AssetDatabase.IsV1Enabled() ? s_CacheServerMode != CacheServerMode.Disabled : s_CacheServer2Mode != CacheServer2Mode.Disabled);

            if (shouldTryConnect)
            {
                var canConnect = false;
                if (AssetDatabase.IsV1Enabled())
                {
                    canConnect = InternalEditorUtility.CanConnectToCacheServer();
                }
                else
                {
                    canConnect = AssetDatabaseExperimental.IsConnectedToCacheServer();
                }

                if (canConnect)
                {
                    s_ConnectionState = ConnectionState.Success;
                }
                else
                {
                    s_ConnectionState = ConnectionState.Failure;
                }
            }
        }
 public static void OnGUI()
 {
     GUILayout.Space(10f);
     if (!InternalEditorUtility.HasPro())
     {
         GUILayout.Label(EditorGUIUtility.TempContent("You need to have a Pro license to use the cache server.", EditorGUIUtility.GetHelpIcon(MessageType.Warning)), EditorStyles.helpBox, new GUILayoutOption[0]);
     }
     EditorGUI.BeginDisabledGroup(!InternalEditorUtility.HasPro());
     if (!CacheServerPreferences.s_PrefsLoaded)
     {
         CacheServerPreferences.ReadPreferences();
         CacheServerPreferences.s_PrefsLoaded = true;
     }
     EditorGUI.BeginChangeCheck();
     CacheServerPreferences.s_CacheServerEnabled = EditorGUILayout.Toggle("Use Cache Server", CacheServerPreferences.s_CacheServerEnabled, new GUILayoutOption[0]);
     EditorGUI.BeginDisabledGroup(!CacheServerPreferences.s_CacheServerEnabled);
     CacheServerPreferences.s_CacheServerIPAddress = EditorGUILayout.TextField("IP Address", CacheServerPreferences.s_CacheServerIPAddress, new GUILayoutOption[0]);
     if (GUI.changed)
     {
         CacheServerPreferences.s_ConnectionState = CacheServerPreferences.ConnectionState.Unknown;
     }
     GUILayout.Space(5f);
     if (GUILayout.Button("Check Connection", new GUILayoutOption[]
     {
         GUILayout.Width(150f)
     }))
     {
         if (InternalEditorUtility.CanConnectToCacheServer())
         {
             CacheServerPreferences.s_ConnectionState = CacheServerPreferences.ConnectionState.Success;
         }
         else
         {
             CacheServerPreferences.s_ConnectionState = CacheServerPreferences.ConnectionState.Failure;
         }
     }
     GUILayout.Space(-25f);
     CacheServerPreferences.ConnectionState connectionState = CacheServerPreferences.s_ConnectionState;
     if (connectionState != CacheServerPreferences.ConnectionState.Success)
     {
         if (connectionState == CacheServerPreferences.ConnectionState.Failure)
         {
             EditorGUILayout.HelpBox("Connection failed.", MessageType.Warning, false);
         }
     }
     else
     {
         EditorGUILayout.HelpBox("Connection successful.", MessageType.Info, false);
     }
     EditorGUI.EndDisabledGroup();
     if (EditorGUI.EndChangeCheck())
     {
         CacheServerPreferences.WritePreferences();
         CacheServerPreferences.ReadPreferences();
     }
     EditorGUI.EndDisabledGroup();
 }
Beispiel #3
0
        static void CacheServerVersion2GUI(bool allowCacheServerChanges, string overrideAddress)
        {
            GUILayout.Label(Properties.assetPipelineVersion2, EditorStyles.boldLabel);

            GUILayout.Space(5);

            bool changeStateBeforeControls = GUI.changed;

            s_CacheServer2Mode = (CacheServer2Mode)EditorGUILayout.EnumPopup(Properties.cacheServerDefaultMode, s_CacheServer2Mode);

            s_CacheServer2IPAddress = EditorGUILayout.DelayedTextField(Properties.cacheServerIPLabel, s_CacheServer2IPAddress);

            if (GUI.changed != changeStateBeforeControls)
            {
                s_ConnectionState = ConnectionState.Unknown;
            }

            GUILayout.Space(5);

            using (new EditorGUI.DisabledScope(AssetDatabase.IsV1Enabled()))
            {
                if (GUILayout.Button("Check Connection", GUILayout.Width(150)))
                {
                    if (InternalEditorUtility.CanConnectToCacheServer())
                    {
                        s_ConnectionState = ConnectionState.Success;
                    }
                    else
                    {
                        s_ConnectionState = ConnectionState.Failure;
                    }
                }
            }

            GUILayout.Space(-25);

            var s = AssetDatabase.IsV2Enabled() ? s_ConnectionState : ConnectionState.Unknown;

            switch (s)
            {
            case ConnectionState.Success:
                EditorGUILayout.HelpBox("Connection successful.", MessageType.Info, false);
                break;

            case ConnectionState.Failure:
                EditorGUILayout.HelpBox("Connection failed.", MessageType.Warning, false);
                break;

            case ConnectionState.Unknown:
                GUILayout.Space(44);
                break;
            }
        }
        public static void DisableCacheServer()
        {
            bool connectCacheServer = InternalEditorUtility.CanConnectToCacheServer();

            if (!connectCacheServer)
            {
                return;
            }

            EditorPrefs.SetInt("CacheServerMode", 2);
            EditorPrefs.SetBool("CacheServerEnabled", false);

            Debug.Log("CanConnectToCacheServer:" + InternalEditorUtility.CanConnectToCacheServer());
        }
		public static void OnGUI()
		{
			EventType type = Event.current.type;
			if (CacheServerPreferences.s_Constants == null)
			{
				CacheServerPreferences.s_Constants = new CacheServerPreferences.Constants();
			}
			if (!InternalEditorUtility.HasTeamLicense())
			{
				GUILayout.Label(EditorGUIUtility.TempContent("You need to have a Pro or Team license to use the cache server.", EditorGUIUtility.GetHelpIcon(MessageType.Warning)), EditorStyles.helpBox, new GUILayoutOption[0]);
			}
			using (new EditorGUI.DisabledScope(!InternalEditorUtility.HasTeamLicense()))
			{
				if (!CacheServerPreferences.s_PrefsLoaded)
				{
					CacheServerPreferences.ReadPreferences();
					if (CacheServerPreferences.s_CacheServerMode != CacheServerPreferences.CacheServerMode.Disabled && CacheServerPreferences.s_ConnectionState == CacheServerPreferences.ConnectionState.Unknown)
					{
						if (InternalEditorUtility.CanConnectToCacheServer())
						{
							CacheServerPreferences.s_ConnectionState = CacheServerPreferences.ConnectionState.Success;
						}
						else
						{
							CacheServerPreferences.s_ConnectionState = CacheServerPreferences.ConnectionState.Failure;
						}
					}
					CacheServerPreferences.s_PrefsLoaded = true;
				}
				EditorGUI.BeginChangeCheck();
				CacheServerPreferences.s_CacheServerMode = (CacheServerPreferences.CacheServerMode)EditorGUILayout.EnumPopup("Cache Server Mode", CacheServerPreferences.s_CacheServerMode, new GUILayoutOption[0]);
				if (CacheServerPreferences.s_CacheServerMode == CacheServerPreferences.CacheServerMode.Remote)
				{
					CacheServerPreferences.s_CacheServerIPAddress = EditorGUILayout.DelayedTextField("IP Address", CacheServerPreferences.s_CacheServerIPAddress, new GUILayoutOption[0]);
					if (GUI.changed)
					{
						CacheServerPreferences.s_ConnectionState = CacheServerPreferences.ConnectionState.Unknown;
					}
					GUILayout.Space(5f);
					if (GUILayout.Button("Check Connection", new GUILayoutOption[]
					{
						GUILayout.Width(150f)
					}))
					{
						if (InternalEditorUtility.CanConnectToCacheServer())
						{
							CacheServerPreferences.s_ConnectionState = CacheServerPreferences.ConnectionState.Success;
						}
						else
						{
							CacheServerPreferences.s_ConnectionState = CacheServerPreferences.ConnectionState.Failure;
						}
					}
					GUILayout.Space(-25f);
					CacheServerPreferences.ConnectionState connectionState = CacheServerPreferences.s_ConnectionState;
					if (connectionState != CacheServerPreferences.ConnectionState.Success)
					{
						if (connectionState != CacheServerPreferences.ConnectionState.Failure)
						{
							if (connectionState == CacheServerPreferences.ConnectionState.Unknown)
							{
								GUILayout.Space(44f);
							}
						}
						else
						{
							EditorGUILayout.HelpBox("Connection failed.", MessageType.Warning, false);
						}
					}
					else
					{
						EditorGUILayout.HelpBox("Connection successful.", MessageType.Info, false);
					}
				}
				else if (CacheServerPreferences.s_CacheServerMode == CacheServerPreferences.CacheServerMode.Local)
				{
					CacheServerPreferences.s_LocalCacheServerSize = EditorGUILayout.IntSlider(CacheServerPreferences.Styles.maxCacheSize, CacheServerPreferences.s_LocalCacheServerSize, 1, 200, new GUILayoutOption[0]);
					CacheServerPreferences.s_EnableCustomPath = EditorGUILayout.Toggle(CacheServerPreferences.Styles.customCacheLocation, CacheServerPreferences.s_EnableCustomPath, new GUILayoutOption[0]);
					if (CacheServerPreferences.s_EnableCustomPath)
					{
						GUIStyle miniButton = EditorStyles.miniButton;
						GUILayout.BeginHorizontal(new GUILayoutOption[0]);
						EditorGUILayout.PrefixLabel(CacheServerPreferences.Styles.cacheFolderLocation, miniButton);
						Rect rect = GUILayoutUtility.GetRect(GUIContent.none, miniButton);
						GUIContent content = (!string.IsNullOrEmpty(CacheServerPreferences.s_CachePath)) ? new GUIContent(CacheServerPreferences.s_CachePath) : CacheServerPreferences.Styles.browse;
						if (EditorGUI.DropdownButton(rect, content, FocusType.Passive, miniButton))
						{
							string folder = CacheServerPreferences.s_CachePath;
							string text = EditorUtility.OpenFolderPanel(CacheServerPreferences.Styles.browseCacheLocation.text, folder, "");
							if (!string.IsNullOrEmpty(text))
							{
								if (LocalCacheServer.CheckValidCacheLocation(text))
								{
									CacheServerPreferences.s_CachePath = text;
									CacheServerPreferences.WritePreferences();
								}
								else
								{
									EditorUtility.DisplayDialog("Invalid Cache Location", "The directory " + text + " contains some files which don't look like Unity Cache server files. Please delete the directory contents or choose another directory.", "OK");
								}
								GUIUtility.ExitGUI();
							}
						}
						GUILayout.EndHorizontal();
					}
					else
					{
						CacheServerPreferences.s_CachePath = "";
					}
					bool flag = LocalCacheServer.CheckCacheLocationExists();
					if (flag)
					{
						GUIContent label = EditorGUIUtility.TextContent("Cache size is unknown");
						if (CacheServerPreferences.s_LocalCacheServerUsedSize != -1L)
						{
							label = EditorGUIUtility.TextContent("Cache size is " + EditorUtility.FormatBytes(CacheServerPreferences.s_LocalCacheServerUsedSize));
						}
						GUILayout.BeginHorizontal(new GUILayoutOption[0]);
						GUIStyle miniButton2 = EditorStyles.miniButton;
						EditorGUILayout.PrefixLabel(label, miniButton2);
						Rect rect2 = GUILayoutUtility.GetRect(GUIContent.none, miniButton2);
						if (EditorGUI.Button(rect2, CacheServerPreferences.Styles.enumerateCache, miniButton2))
						{
							CacheServerPreferences.s_LocalCacheServerUsedSize = ((!LocalCacheServer.CheckCacheLocationExists()) ? 0L : FileUtil.GetDirectorySize(LocalCacheServer.GetCacheLocation()));
						}
						GUILayout.EndHorizontal();
						GUILayout.BeginHorizontal(new GUILayoutOption[0]);
						GUIContent blankContent = EditorGUIUtility.blankContent;
						EditorGUILayout.PrefixLabel(blankContent, miniButton2);
						Rect rect3 = GUILayoutUtility.GetRect(GUIContent.none, miniButton2);
						if (EditorGUI.Button(rect3, CacheServerPreferences.Styles.cleanCache, miniButton2))
						{
							LocalCacheServer.Clear();
							CacheServerPreferences.s_LocalCacheServerUsedSize = 0L;
						}
						GUILayout.EndHorizontal();
					}
					else
					{
						EditorGUILayout.HelpBox("Local cache directory does not exist - please check that you can access the cache folder and are able to write to it", MessageType.Warning, false);
						CacheServerPreferences.s_LocalCacheServerUsedSize = -1L;
					}
					GUILayout.Label(CacheServerPreferences.Styles.cacheFolderLocation.text + ":", new GUILayoutOption[0]);
					GUILayout.Label(LocalCacheServer.GetCacheLocation(), CacheServerPreferences.s_Constants.cacheFolderLocation, new GUILayoutOption[0]);
				}
				if (EditorGUI.EndChangeCheck())
				{
					CacheServerPreferences.s_HasPendingChanges = true;
				}
				if (CacheServerPreferences.s_HasPendingChanges && GUIUtility.hotControl == 0)
				{
					CacheServerPreferences.s_HasPendingChanges = false;
					CacheServerPreferences.WritePreferences();
					CacheServerPreferences.ReadPreferences();
				}
			}
		}
Beispiel #6
0
        static void CacheServerVersion1GUI(bool allowCacheServerChanges, string overrideAddress)
        {
            GUILayout.Label(Properties.assetPipelineVersion1, EditorStyles.boldLabel);

            GUILayout.Space(5);

            if (!allowCacheServerChanges)
            {
                EditorGUILayout.HelpBox("Cache Server preferences cannot be modified because a remote address was specified via command line argument. To modify Cache Server preferences, restart Unity without the " + kIpAddressKeyArgs + " command line argument.", MessageType.Info, true);
            }

            using (new EditorGUI.DisabledScope(!allowCacheServerChanges))
            {
                var displayMode = !allowCacheServerChanges ? CacheServerMode.Remote : s_CacheServerMode;
                s_CacheServerMode = (CacheServerMode)EditorGUILayout.EnumPopup("Cache Server Mode", displayMode);
            }

            if (s_CacheServerMode == CacheServerMode.Remote)
            {
                using (new EditorGUI.DisabledScope(!allowCacheServerChanges))
                {
                    var displayAddress = overrideAddress != null ? overrideAddress : s_CacheServerIPAddress;
                    s_CacheServerIPAddress = EditorGUILayout.DelayedTextField("IP Address", displayAddress);

                    if (GUI.changed)
                    {
                        s_ConnectionState = ConnectionState.Unknown;
                    }
                }

                GUILayout.Space(5);

                using (new EditorGUI.DisabledScope(AssetDatabase.IsV2Enabled()))
                {
                    if (GUILayout.Button("Check Connection", GUILayout.Width(150)))
                    {
                        if (InternalEditorUtility.CanConnectToCacheServer())
                        {
                            s_ConnectionState = ConnectionState.Success;
                        }
                        else
                        {
                            s_ConnectionState = ConnectionState.Failure;
                        }
                    }
                }

                GUILayout.Space(-25);

                var s = AssetDatabase.IsV1Enabled() ? s_ConnectionState : ConnectionState.Unknown;

                switch (s)
                {
                case ConnectionState.Success:
                    EditorGUILayout.HelpBox("Connection successful.", MessageType.Info, false);
                    break;

                case ConnectionState.Failure:
                    EditorGUILayout.HelpBox("Connection failed.", MessageType.Warning, false);
                    break;

                case ConnectionState.Unknown:
                    GUILayout.Space(44);
                    break;
                }
            }
            else if (s_CacheServerMode == CacheServerMode.Local)
            {
                const int kMinSizeInGigabytes = 1;
                const int kMaxSizeInGigabytes = 200;

                // Write size in GigaBytes.
                s_LocalCacheServerSize = EditorGUILayout.IntSlider(Properties.maxCacheSize, s_LocalCacheServerSize, kMinSizeInGigabytes, kMaxSizeInGigabytes);

                s_EnableCustomPath = EditorGUILayout.Toggle(Properties.customCacheLocation, s_EnableCustomPath);
                // browse for cache folder if not per project
                if (s_EnableCustomPath)
                {
                    GUIStyle style = EditorStyles.miniButton;
                    GUILayout.BeginHorizontal();
                    EditorGUILayout.PrefixLabel(Properties.cacheFolderLocation, style);
                    Rect       r       = GUILayoutUtility.GetRect(GUIContent.none, style);
                    GUIContent guiText = string.IsNullOrEmpty(s_CachePath) ? Properties.browse : new GUIContent(s_CachePath);
                    if (EditorGUI.DropdownButton(r, guiText, FocusType.Passive, style))
                    {
                        string pathToOpen = s_CachePath;
                        string path       = EditorUtility.OpenFolderPanel(Properties.browseCacheLocation.text, pathToOpen, "");
                        if (!string.IsNullOrEmpty(path))
                        {
                            if (LocalCacheServer.CheckValidCacheLocation(path))
                            {
                                s_CachePath = path;
                                WritePreferences();
                            }
                            else
                            {
                                EditorUtility.DisplayDialog("Invalid Cache Location", string.Format("The directory {0} contains some files which don't look like Unity Cache server files. Please delete the directory contents or choose another directory.", path), "OK");
                            }
                            EditorGUIUtility.ExitGUI();
                        }
                    }
                    GUILayout.EndHorizontal();
                }
                else
                {
                    s_CachePath = "";
                }

                bool locationExists = LocalCacheServer.CheckCacheLocationExists();
                if (locationExists == true)
                {
                    GUIContent cacheSizeIs = EditorGUIUtility.TrTextContent("Cache size is unknown");
                    if (s_LocalCacheServerUsedSize != -1)
                    {
                        cacheSizeIs = EditorGUIUtility.TextContent("Cache size is " + EditorUtility.FormatBytes(s_LocalCacheServerUsedSize));
                    }

                    GUILayout.BeginHorizontal();
                    GUIStyle style = EditorStyles.miniButton;
                    EditorGUILayout.PrefixLabel(cacheSizeIs, style);
                    Rect r = GUILayoutUtility.GetRect(GUIContent.none, style);
                    if (EditorGUI.Button(r, Properties.enumerateCache, style))
                    {
                        s_LocalCacheServerUsedSize = LocalCacheServer.CheckCacheLocationExists() ? FileUtil.GetDirectorySize(LocalCacheServer.GetCacheLocation()) : 0;
                    }
                    GUILayout.EndHorizontal();

                    GUILayout.BeginHorizontal();
                    GUIContent spacerContent = EditorGUIUtility.blankContent;
                    EditorGUILayout.PrefixLabel(spacerContent, style);
                    Rect r2 = GUILayoutUtility.GetRect(GUIContent.none, style);
                    if (EditorGUI.Button(r2, Properties.cleanCache, style))
                    {
                        LocalCacheServer.Clear();
                        s_LocalCacheServerUsedSize = 0;
                    }
                    GUILayout.EndHorizontal();
                }
                else
                {
                    EditorGUILayout.HelpBox("Local cache directory does not exist - please check that you can access the cache folder and are able to write to it", MessageType.Warning, false);
                    //If the cache server was on an external HDD or on a temporarily unavailable network drive, set the size to unknown so that the user re-queries it when they've reconnected
                    s_LocalCacheServerUsedSize = -1;
                }

                GUILayout.Label(Properties.cacheFolderLocation.text + ":");
                GUILayout.Label(LocalCacheServer.GetCacheLocation(), Styles.cacheFolderLocation);
            }
        }
        private void DoCacheServerSettings()
        {
            GUILayout.Space(10);
            GUILayout.Label(Content.cacheServer, EditorStyles.boldLabel);

            var overrideAddress = CacheServerPreferences.GetCommandLineRemoteAddressOverride();

            if (overrideAddress != null)
            {
                EditorGUILayout.HelpBox("Cache Server remote address forced via command line argument. To use the cache server address specified here please restart Unity without the -CacheServerIPAddress command line argument.", MessageType.Info, true);
            }

            int index = Mathf.Clamp((int)EditorSettings.cacheServerMode, 0, cacheServerModePopupList.Length - 1);

            CreatePopupMenu(Content.mode.text, cacheServerModePopupList, index, SetCacheServerMode);

            if (index != (int)CacheServerMode.Disabled)
            {
                bool isCacheServerEnabled = true;

                if (index == (int)CacheServerMode.AsPreferences)
                {
                    if (CacheServerPreferences.IsCacheServerV2Enabled)
                    {
                        var cacheServerIP = CacheServerPreferences.CachesServerV2Address;
                        cacheServerIP = string.IsNullOrEmpty(cacheServerIP) ? "Not set in preferences" : cacheServerIP;
                        EditorGUILayout.HelpBox(cacheServerIP, MessageType.None, false);
                    }
                    else
                    {
                        isCacheServerEnabled = false;
                        EditorGUILayout.HelpBox("Disabled", MessageType.None, false);
                    }
                }

                if (isCacheServerEnabled)
                {
                    var oldEndpoint = EditorSettings.cacheServerEndpoint;
                    var newEndpoint = EditorGUILayout.TextField(Content.cacheServerIPLabel, oldEndpoint);
                    if (newEndpoint != oldEndpoint)
                    {
                        EditorSettings.cacheServerEndpoint = newEndpoint;
                    }

                    EditorGUILayout.BeginHorizontal();

                    if (GUILayout.Button("Check Connection", GUILayout.Width(150)))
                    {
                        if (AssetDatabase.IsV2Enabled())
                        {
                            var    address = EditorSettings.cacheServerEndpoint.Split(':');
                            var    ip      = address[0];
                            UInt16 port    = 0; // If 0, will use the default set port
                            if (address.Length == 2)
                            {
                                port = Convert.ToUInt16(address[1]);
                            }

                            if (AssetDatabaseExperimental.CanConnectToCacheServer(ip, port))
                            {
                                m_CacheServerConnectionState = CacheServerConnectionState.Success;
                            }
                            else
                            {
                                m_CacheServerConnectionState = CacheServerConnectionState.Failure;
                            }
                        }
                        else
                        {
                            if (InternalEditorUtility.CanConnectToCacheServer())
                            {
                                m_CacheServerConnectionState = CacheServerConnectionState.Success;
                            }
                            else
                            {
                                m_CacheServerConnectionState = CacheServerConnectionState.Failure;
                            }
                        }
                    }

                    GUILayout.Space(25);

                    switch (m_CacheServerConnectionState)
                    {
                    case CacheServerConnectionState.Success:
                        EditorGUILayout.HelpBox("Connection successful.", MessageType.Info, true);
                        break;

                    case CacheServerConnectionState.Failure:
                        EditorGUILayout.HelpBox("Connection failed.", MessageType.Warning, true);
                        break;

                    case CacheServerConnectionState.Unknown:
                        GUILayout.Space(44);
                        break;
                    }

                    EditorGUILayout.EndHorizontal();

                    var old      = EditorSettings.cacheServerNamespacePrefix;
                    var newvalue = EditorGUILayout.TextField(Content.cacheServerNamespacePrefixLabel, old);
                    if (newvalue != old)
                    {
                        EditorSettings.cacheServerNamespacePrefix = newvalue;
                    }

                    EditorGUI.BeginChangeCheck();
                    bool enableDownload = EditorSettings.cacheServerEnableDownload;
                    enableDownload = EditorGUILayout.Toggle(Content.cacheServerEnableDownloadLabel, enableDownload);
                    if (EditorGUI.EndChangeCheck())
                    {
                        EditorSettings.cacheServerEnableDownload = enableDownload;
                    }

                    EditorGUI.BeginChangeCheck();
                    bool enableUpload = EditorSettings.cacheServerEnableUpload;
                    enableUpload = EditorGUILayout.Toggle(Content.cacheServerEnableUploadLabel, enableUpload);
                    if (EditorGUI.EndChangeCheck())
                    {
                        EditorSettings.cacheServerEnableUpload = enableUpload;
                    }

                    bool enableAuth = EditorSettings.cacheServerEnableAuth;
                    using (new EditorGUI.DisabledScope(enableAuth))
                    {
                        EditorGUI.BeginChangeCheck();
                        bool enableTls = EditorSettings.cacheServerEnableTls;
                        enableTls = EditorGUILayout.Toggle(Content.cacheServerEnableTlsLabel, enableTls);
                        if (EditorGUI.EndChangeCheck())
                        {
                            EditorSettings.cacheServerEnableTls = enableTls;
                        }
                    }

                    EditorGUI.BeginChangeCheck();
                    enableAuth = EditorGUILayout.Toggle(Content.cacheServerEnableAuthLabel, enableAuth);
                    if (EditorGUI.EndChangeCheck())
                    {
                        EditorSettings.cacheServerEnableAuth = enableAuth;
                        if (enableAuth)
                        {
                            EditorSettings.cacheServerEnableTls = true;
                        }
                    }

                    EditorGUI.indentLevel++;
                    using (new EditorGUI.DisabledScope(!enableAuth))
                    {
                        int authModeIndex = Convert.ToInt32(EditorUserSettings.GetConfigValue("cacheServerAuthMode"));
                        CreatePopupMenu(Content.mode.text, cacheServerAuthMode, authModeIndex, SetCacheServerAuthMode);

                        string oldUserVal = EditorUserSettings.GetConfigValue("cacheServerAuthUser");
                        var    newUserVal = EditorGUILayout.TextField(Content.cacheServerAuthUserLabel, oldUserVal);
                        if (newUserVal != oldUserVal)
                        {
                            EditorUserSettings.SetConfigValue("cacheServerAuthUser", newUserVal);
                        }

                        var oldPasswordVal = EditorUserSettings.GetConfigValue("cacheServerAuthPassword");
                        var newPasswordVal = EditorGUILayout.PasswordField(Content.cacheServerAuthPasswordLabel, oldPasswordVal);
                        if (newPasswordVal != oldPasswordVal)
                        {
                            EditorUserSettings.SetPrivateConfigValue("cacheServerAuthPassword", newPasswordVal);
                        }
                    }
                    EditorGUI.indentLevel--;
                }
            }
        }
        private static void OnGUI(string searchContext)
        {
            EditorGUIUtility.labelWidth = 200f;
            // Get event type before the event is used.
            var eventType = Event.current.type;

            if (!InternalEditorUtility.HasTeamLicense())
            {
                GUILayout.Label(EditorGUIUtility.TempContent("You need to have a Pro or Team license to use the cache server.", EditorGUIUtility.GetHelpIcon(MessageType.Warning)), EditorStyles.helpBox);
            }


            using (new EditorGUI.DisabledScope(!InternalEditorUtility.HasTeamLicense()))
            {
                if (!s_PrefsLoaded)
                {
                    ReadPreferences();

                    if (s_CacheServerMode != CacheServerMode.Disabled && s_ConnectionState == ConnectionState.Unknown)
                    {
                        if (InternalEditorUtility.CanConnectToCacheServer())
                        {
                            s_ConnectionState = ConnectionState.Success;
                        }
                        else
                        {
                            s_ConnectionState = ConnectionState.Failure;
                        }
                    }

                    s_PrefsLoaded = true;
                }

                EditorGUI.BeginChangeCheck();

                var overrideAddress = GetCommandLineRemoteAddressOverride();

                if (overrideAddress != null)
                {
                    EditorGUILayout.HelpBox("Cache Server preferences cannot be modified because a remote address was specified via command line argument. To modify Cache Server preferences, restart Unity without the " + kIpAddressKeyArgs + " command line argument.", MessageType.Info, true);
                }

                using (new EditorGUI.DisabledScope(overrideAddress != null))
                {
                    var displayMode = overrideAddress != null ? CacheServerMode.Remote : s_CacheServerMode;
                    s_CacheServerMode = (CacheServerMode)EditorGUILayout.EnumPopup("Cache Server Mode", displayMode);
                }

                if (s_CacheServerMode == CacheServerMode.Remote)
                {
                    using (new EditorGUI.DisabledScope(overrideAddress != null))
                    {
                        var displayAddress = overrideAddress != null ? overrideAddress : s_CacheServerIPAddress;
                        s_CacheServerIPAddress = EditorGUILayout.DelayedTextField("IP Address", displayAddress);
                        if (GUI.changed)
                        {
                            s_ConnectionState = ConnectionState.Unknown;
                        }
                    }

                    GUILayout.Space(5);

                    if (GUILayout.Button("Check Connection", GUILayout.Width(150)))
                    {
                        if (InternalEditorUtility.CanConnectToCacheServer())
                        {
                            s_ConnectionState = ConnectionState.Success;
                        }
                        else
                        {
                            s_ConnectionState = ConnectionState.Failure;
                        }
                    }

                    GUILayout.Space(-25);
                    switch (s_ConnectionState)
                    {
                    case ConnectionState.Success:
                        EditorGUILayout.HelpBox("Connection successful.", MessageType.Info, false);
                        break;

                    case ConnectionState.Failure:
                        EditorGUILayout.HelpBox("Connection failed.", MessageType.Warning, false);
                        break;

                    case ConnectionState.Unknown:
                        GUILayout.Space(44);
                        break;
                    }
                }
                else if (s_CacheServerMode == CacheServerMode.Local)
                {
                    const int kMinSizeInGigabytes = 1;
                    const int kMaxSizeInGigabytes = 200;

                    // Write size in GigaBytes.
                    s_LocalCacheServerSize = EditorGUILayout.IntSlider(Properties.maxCacheSize, s_LocalCacheServerSize, kMinSizeInGigabytes, kMaxSizeInGigabytes);

                    s_EnableCustomPath = EditorGUILayout.Toggle(Properties.customCacheLocation, s_EnableCustomPath);
                    // browse for cache folder if not per project
                    if (s_EnableCustomPath)
                    {
                        GUIStyle style = EditorStyles.miniButton;
                        GUILayout.BeginHorizontal();
                        EditorGUILayout.PrefixLabel(Properties.cacheFolderLocation, style);
                        Rect       r       = GUILayoutUtility.GetRect(GUIContent.none, style);
                        GUIContent guiText = string.IsNullOrEmpty(s_CachePath) ? Properties.browse : new GUIContent(s_CachePath);
                        if (EditorGUI.DropdownButton(r, guiText, FocusType.Passive, style))
                        {
                            string pathToOpen = s_CachePath;
                            string path       = EditorUtility.OpenFolderPanel(Properties.browseCacheLocation.text, pathToOpen, "");
                            if (!string.IsNullOrEmpty(path))
                            {
                                if (LocalCacheServer.CheckValidCacheLocation(path))
                                {
                                    s_CachePath = path;
                                    WritePreferences();
                                }
                                else
                                {
                                    EditorUtility.DisplayDialog("Invalid Cache Location", string.Format("The directory {0} contains some files which don't look like Unity Cache server files. Please delete the directory contents or choose another directory.", path), "OK");
                                }
                                EditorGUIUtility.ExitGUI();
                            }
                        }
                        GUILayout.EndHorizontal();
                    }
                    else
                    {
                        s_CachePath = "";
                    }

                    bool locationExists = LocalCacheServer.CheckCacheLocationExists();
                    if (locationExists == true)
                    {
                        GUIContent cacheSizeIs = EditorGUIUtility.TrTextContent("Cache size is unknown");
                        if (s_LocalCacheServerUsedSize != -1)
                        {
                            cacheSizeIs = EditorGUIUtility.TextContent("Cache size is " + EditorUtility.FormatBytes(s_LocalCacheServerUsedSize));
                        }

                        GUILayout.BeginHorizontal();
                        GUIStyle style = EditorStyles.miniButton;
                        EditorGUILayout.PrefixLabel(cacheSizeIs, style);
                        Rect r = GUILayoutUtility.GetRect(GUIContent.none, style);
                        if (EditorGUI.Button(r, Properties.enumerateCache, style))
                        {
                            s_LocalCacheServerUsedSize = LocalCacheServer.CheckCacheLocationExists() ? FileUtil.GetDirectorySize(LocalCacheServer.GetCacheLocation()) : 0;
                        }
                        GUILayout.EndHorizontal();

                        GUILayout.BeginHorizontal();
                        GUIContent spacerContent = EditorGUIUtility.blankContent;
                        EditorGUILayout.PrefixLabel(spacerContent, style);
                        Rect r2 = GUILayoutUtility.GetRect(GUIContent.none, style);
                        if (EditorGUI.Button(r2, Properties.cleanCache, style))
                        {
                            LocalCacheServer.Clear();
                            s_LocalCacheServerUsedSize = 0;
                        }
                        GUILayout.EndHorizontal();
                    }
                    else
                    {
                        EditorGUILayout.HelpBox("Local cache directory does not exist - please check that you can access the cache folder and are able to write to it", MessageType.Warning, false);
                        //If the cache server was on an external HDD or on a temporarily unavailable network drive, set the size to unknown so that the user re-queries it when they've reconnected
                        s_LocalCacheServerUsedSize = -1;
                    }

                    GUILayout.Label(Properties.cacheFolderLocation.text + ":");
                    GUILayout.Label(LocalCacheServer.GetCacheLocation(), Styles.cacheFolderLocation);
                }

                if (EditorGUI.EndChangeCheck())
                {
                    s_HasPendingChanges = true;
                }

                // Only commit changes when we don't have an active hot control, to avoid restarting the cache server all the time while the slider is dragged, slowing down the UI.
                if (s_HasPendingChanges && GUIUtility.hotControl == 0)
                {
                    s_HasPendingChanges = false;
                    WritePreferences();
                    ReadPreferences();
                }
            }
        }
        public static void OnGUI()
        {
            EventType type = Event.current.type;

            if (CacheServerPreferences.s_Constants == null)
            {
                CacheServerPreferences.s_Constants = new CacheServerPreferences.Constants();
            }
            GUILayout.Space(10f);
            if (!InternalEditorUtility.HasTeamLicense())
            {
                GUILayout.Label(EditorGUIUtility.TempContent("You need to have a Pro or Team license to use the cache server.", EditorGUIUtility.GetHelpIcon(MessageType.Warning)), EditorStyles.helpBox, new GUILayoutOption[0]);
            }
            using (new EditorGUI.DisabledScope(!InternalEditorUtility.HasTeamLicense()))
            {
                if (!CacheServerPreferences.s_PrefsLoaded)
                {
                    CacheServerPreferences.ReadPreferences();
                    if (CacheServerPreferences.s_CacheServerMode != CacheServerPreferences.CacheServerMode.Disabled && CacheServerPreferences.s_ConnectionState == CacheServerPreferences.ConnectionState.Unknown)
                    {
                        if (InternalEditorUtility.CanConnectToCacheServer())
                        {
                            CacheServerPreferences.s_ConnectionState = CacheServerPreferences.ConnectionState.Success;
                        }
                        else
                        {
                            CacheServerPreferences.s_ConnectionState = CacheServerPreferences.ConnectionState.Failure;
                        }
                    }
                    CacheServerPreferences.s_PrefsLoaded = true;
                }
                EditorGUI.BeginChangeCheck();
                if (Collab.instance.collabInfo.whitelisted && CacheServerPreferences.IsCollabCacheEnabled())
                {
                    CacheServerPreferences.s_CollabCacheEnabled = EditorGUILayout.Toggle("Use Collab Cache", CacheServerPreferences.s_CollabCacheEnabled, new GUILayoutOption[0]);
                    using (new EditorGUI.DisabledScope(!CacheServerPreferences.s_CollabCacheEnabled))
                    {
                        CacheServerPreferences.s_CollabCacheIPAddress = EditorGUILayout.TextField("Collab Cache IP Address", CacheServerPreferences.s_CollabCacheIPAddress, new GUILayoutOption[0]);
                    }
                }
                CacheServerPreferences.s_CacheServerMode = (CacheServerPreferences.CacheServerMode)EditorGUILayout.EnumPopup("Cache Server Mode", CacheServerPreferences.s_CacheServerMode, new GUILayoutOption[0]);
                if (CacheServerPreferences.s_CacheServerMode == CacheServerPreferences.CacheServerMode.Remote)
                {
                    CacheServerPreferences.s_CacheServerIPAddress = EditorGUILayout.DelayedTextField("IP Address", CacheServerPreferences.s_CacheServerIPAddress, new GUILayoutOption[0]);
                    if (GUI.changed)
                    {
                        CacheServerPreferences.s_ConnectionState = CacheServerPreferences.ConnectionState.Unknown;
                    }
                    GUILayout.Space(5f);
                    if (GUILayout.Button("Check Connection", new GUILayoutOption[]
                    {
                        GUILayout.Width(150f)
                    }))
                    {
                        if (InternalEditorUtility.CanConnectToCacheServer())
                        {
                            CacheServerPreferences.s_ConnectionState = CacheServerPreferences.ConnectionState.Success;
                        }
                        else
                        {
                            CacheServerPreferences.s_ConnectionState = CacheServerPreferences.ConnectionState.Failure;
                        }
                    }
                    GUILayout.Space(-25f);
                    CacheServerPreferences.ConnectionState connectionState = CacheServerPreferences.s_ConnectionState;
                    if (connectionState != CacheServerPreferences.ConnectionState.Success)
                    {
                        if (connectionState != CacheServerPreferences.ConnectionState.Failure)
                        {
                            if (connectionState == CacheServerPreferences.ConnectionState.Unknown)
                            {
                                GUILayout.Space(44f);
                            }
                        }
                        else
                        {
                            EditorGUILayout.HelpBox("Connection failed.", MessageType.Warning, false);
                        }
                    }
                    else
                    {
                        EditorGUILayout.HelpBox("Connection successful.", MessageType.Info, false);
                    }
                }
                else if (CacheServerPreferences.s_CacheServerMode == CacheServerPreferences.CacheServerMode.Local)
                {
                    CacheServerPreferences.s_LocalCacheServerSize = EditorGUILayout.IntSlider(CacheServerPreferences.Styles.maxCacheSize, CacheServerPreferences.s_LocalCacheServerSize, 1, 200, new GUILayoutOption[0]);
                    CacheServerPreferences.s_EnableCustomPath     = EditorGUILayout.Toggle(CacheServerPreferences.Styles.customCacheLocation, CacheServerPreferences.s_EnableCustomPath, new GUILayoutOption[0]);
                    if (CacheServerPreferences.s_EnableCustomPath)
                    {
                        GUIStyle popup = EditorStyles.popup;
                        GUILayout.BeginHorizontal(new GUILayoutOption[0]);
                        EditorGUILayout.PrefixLabel(CacheServerPreferences.Styles.cacheFolderLocation, popup);
                        Rect       rect    = GUILayoutUtility.GetRect(GUIContent.none, popup);
                        GUIContent content = (!string.IsNullOrEmpty(CacheServerPreferences.s_CachePath)) ? new GUIContent(CacheServerPreferences.s_CachePath) : CacheServerPreferences.Styles.browse;
                        if (EditorGUI.ButtonMouseDown(rect, content, FocusType.Passive, popup))
                        {
                            string folder = CacheServerPreferences.s_CachePath;
                            string text   = EditorUtility.OpenFolderPanel(CacheServerPreferences.Styles.browseCacheLocation.text, folder, "");
                            if (!string.IsNullOrEmpty(text))
                            {
                                if (LocalCacheServer.CheckValidCacheLocation(text))
                                {
                                    CacheServerPreferences.s_CachePath = text;
                                    CacheServerPreferences.WritePreferences();
                                }
                                else
                                {
                                    EditorUtility.DisplayDialog("Invalid Cache Location", "The directory " + text + " contains some files which don't look like Unity Cache server files. Please delete the directory contents or choose another directory.", "OK");
                                }
                            }
                        }
                        GUILayout.EndHorizontal();
                    }
                    else
                    {
                        CacheServerPreferences.s_CachePath = "";
                    }
                    if (GUILayout.Button(CacheServerPreferences.Styles.cleanCache, new GUILayoutOption[]
                    {
                        GUILayout.Width(120f)
                    }))
                    {
                        LocalCacheServer.Clear();
                        CacheServerPreferences.s_LocalCacheServerUsedSize = 0L;
                    }
                    if (CacheServerPreferences.s_LocalCacheServerUsedSize == -1L)
                    {
                        CacheServerPreferences.s_LocalCacheServerUsedSize = FileUtil.GetDirectorySize(LocalCacheServer.GetCacheLocation());
                    }
                    GUILayout.Label(CacheServerPreferences.Styles.cacheSizeIs.text + " " + EditorUtility.FormatBytes(CacheServerPreferences.s_LocalCacheServerUsedSize), new GUILayoutOption[0]);
                    GUILayout.Label(CacheServerPreferences.Styles.cacheFolderLocation.text + ":", new GUILayoutOption[0]);
                    GUILayout.Label(LocalCacheServer.GetCacheLocation(), CacheServerPreferences.s_Constants.cacheFolderLocation, new GUILayoutOption[0]);
                }
                if (EditorGUI.EndChangeCheck())
                {
                    CacheServerPreferences.s_HasPendingChanges = true;
                }
                if ((CacheServerPreferences.s_HasPendingChanges && type == EventType.MouseUp) || type == EventType.KeyDown)
                {
                    CacheServerPreferences.WritePreferences();
                    CacheServerPreferences.ReadPreferences();
                    CacheServerPreferences.s_HasPendingChanges = false;
                }
            }
        }
        private void DoCacheServerSettings()
        {
            GUILayout.Space(10);
            GUILayout.Label(Content.cacheServer, EditorStyles.boldLabel);

            var overrideAddress = CacheServerPreferences.GetCommandLineRemoteAddressOverride();

            if (overrideAddress != null)
            {
                EditorGUILayout.HelpBox("Cache Server remote address forced via command line argument. To use the cache server address specified here please restart Unity without the -CacheServerIPAddress command line argument.", MessageType.Info, true);
            }

            int index = Mathf.Clamp((int)m_CacheServerMode.intValue, 0, cacheServerModePopupList.Length - 1);

            CreatePopupMenu(Content.mode.text, cacheServerModePopupList, index, SetCacheServerMode);

            if (index != (int)CacheServerMode.Disabled)
            {
                bool isCacheServerEnabled = true;

                if (index == (int)CacheServerMode.AsPreferences)
                {
                    if (CacheServerPreferences.IsCacheServerV2Enabled)
                    {
                        var cacheServerIP = CacheServerPreferences.CachesServerV2Address;
                        cacheServerIP = string.IsNullOrEmpty(cacheServerIP) ? "Not set in preferences" : cacheServerIP;
                        EditorGUILayout.HelpBox(cacheServerIP, MessageType.None, false);
                    }
                    else
                    {
                        isCacheServerEnabled = false;
                        EditorGUILayout.HelpBox("Disabled", MessageType.None, false);
                    }
                }

                if (isCacheServerEnabled)
                {
                    m_CacheServerList.DoLayoutList();

                    EditorGUILayout.BeginHorizontal();

                    if (GUILayout.Button("Check Connection", GUILayout.Width(150)))
                    {
                        if (InternalEditorUtility.CanConnectToCacheServer())
                        {
                            m_CacheServerConnectionState = CacheServerConnectionState.Success;
                        }
                        else
                        {
                            m_CacheServerConnectionState = CacheServerConnectionState.Failure;
                        }
                    }

                    GUILayout.Space(25);

                    switch (m_CacheServerConnectionState)
                    {
                    case CacheServerConnectionState.Success:
                        EditorGUILayout.HelpBox("Connection successful.", MessageType.Info, true);
                        break;

                    case CacheServerConnectionState.Failure:
                        EditorGUILayout.HelpBox("Connection failed.", MessageType.Warning, true);
                        break;

                    case CacheServerConnectionState.Unknown:
                        GUILayout.Space(44);
                        break;
                    }

                    EditorGUILayout.EndHorizontal();
                }
            }
        }
Beispiel #11
0
        public static void OnGUI()
        {
            GUILayout.Space(10f);
            if (!InternalEditorUtility.HasTeamLicense())
            {
                GUILayout.Label(EditorGUIUtility.TempContent("You need to have a Pro or Team license to use the cache server.", EditorGUIUtility.GetHelpIcon(MessageType.Warning)), EditorStyles.helpBox, new GUILayoutOption[0]);
            }
            EditorGUI.BeginDisabledGroup(!InternalEditorUtility.HasTeamLicense());
            if (!s_PrefsLoaded)
            {
                ReadPreferences();
                s_PrefsLoaded = true;
            }
            if (s_CacheServerEnabled && (s_ConnectionState == ConnectionState.Unknown))
            {
                if (InternalEditorUtility.CanConnectToCacheServer())
                {
                    s_ConnectionState = ConnectionState.Success;
                }
                else
                {
                    s_ConnectionState = ConnectionState.Failure;
                }
            }
            EditorGUI.BeginChangeCheck();
            s_CacheServerEnabled = EditorGUILayout.Toggle("Use Cache Server", s_CacheServerEnabled, new GUILayoutOption[0]);
            EditorGUI.BeginDisabledGroup(!s_CacheServerEnabled);
            s_CacheServerIPAddress = EditorGUILayout.TextField("IP Address", s_CacheServerIPAddress, new GUILayoutOption[0]);
            if (GUI.changed)
            {
                s_ConnectionState = ConnectionState.Unknown;
            }
            GUILayout.Space(5f);
            GUILayoutOption[] options = new GUILayoutOption[] { GUILayout.Width(150f) };
            if (GUILayout.Button("Check Connection", options))
            {
                if (InternalEditorUtility.CanConnectToCacheServer())
                {
                    s_ConnectionState = ConnectionState.Success;
                }
                else
                {
                    s_ConnectionState = ConnectionState.Failure;
                }
            }
            GUILayout.Space(-25f);
            switch (s_ConnectionState)
            {
            case ConnectionState.Unknown:
                GUILayout.Space(44f);
                break;

            case ConnectionState.Success:
                EditorGUILayout.HelpBox("Connection successful.", MessageType.Info, false);
                break;

            case ConnectionState.Failure:
                EditorGUILayout.HelpBox("Connection failed.", MessageType.Warning, false);
                break;
            }
            EditorGUI.EndDisabledGroup();
            if (EditorGUI.EndChangeCheck())
            {
                WritePreferences();
                ReadPreferences();
            }
            EditorGUI.EndDisabledGroup();
        }
        public static void OnGUI()
        {
            GUILayout.Space(10f);
            if (!InternalEditorUtility.HasTeamLicense())
            {
                GUILayout.Label(EditorGUIUtility.TempContent("You need to have a Pro or Team license to use the cache server.", EditorGUIUtility.GetHelpIcon(MessageType.Warning)), EditorStyles.helpBox, new GUILayoutOption[0]);
            }
            using (new EditorGUI.DisabledScope(!InternalEditorUtility.HasTeamLicense()))
            {
                if (!CacheServerPreferences.s_PrefsLoaded)
                {
                    CacheServerPreferences.ReadPreferences();
                    if (CacheServerPreferences.s_CacheServerEnabled && CacheServerPreferences.s_ConnectionState == CacheServerPreferences.ConnectionState.Unknown)
                    {
                        if (InternalEditorUtility.CanConnectToCacheServer())
                        {
                            CacheServerPreferences.s_ConnectionState = CacheServerPreferences.ConnectionState.Success;
                        }
                        else
                        {
                            CacheServerPreferences.s_ConnectionState = CacheServerPreferences.ConnectionState.Failure;
                        }
                    }
                    CacheServerPreferences.s_PrefsLoaded = true;
                }
                EditorGUI.BeginChangeCheck();
                if (Collab.instance.collabInfo.whitelisted)
                {
                    CacheServerPreferences.s_CollabCacheEnabled = EditorGUILayout.Toggle("Use Collab Cache", CacheServerPreferences.s_CollabCacheEnabled, new GUILayoutOption[0]);
                    using (new EditorGUI.DisabledScope(!CacheServerPreferences.s_CollabCacheEnabled))
                    {
                        CacheServerPreferences.s_CollabCacheIPAddress = EditorGUILayout.TextField("Collab Cache IP Address", CacheServerPreferences.s_CollabCacheIPAddress, new GUILayoutOption[0]);
                    }
                }
                CacheServerPreferences.s_CacheServerEnabled = EditorGUILayout.Toggle("Use Cache Server", CacheServerPreferences.s_CacheServerEnabled, new GUILayoutOption[0]);
                using (new EditorGUI.DisabledScope(!CacheServerPreferences.s_CacheServerEnabled))
                {
                    Rect controlRect = EditorGUILayout.GetControlRect(true, new GUILayoutOption[0]);
                    int  controlID   = GUIUtility.GetControlID(FocusType.Keyboard, controlRect);
                    CacheServerPreferences.s_CacheServerIPAddress = EditorGUI.DelayedTextFieldInternal(controlRect, controlID, GUIContent.Temp("IP Address"), CacheServerPreferences.s_CacheServerIPAddress, null, EditorStyles.textField);
                    if (GUI.changed)
                    {
                        CacheServerPreferences.s_ConnectionState = CacheServerPreferences.ConnectionState.Unknown;
                        CacheServerPreferences.WritePreferences();
                    }
                    GUILayout.Space(5f);
                    if (GUILayout.Button("Check Connection", new GUILayoutOption[]
                    {
                        GUILayout.Width(150f)
                    }))
                    {
                        if (EditorGUI.s_DelayedTextEditor.IsEditingControl(controlID))
                        {
                            string text = EditorGUI.s_DelayedTextEditor.text;
                            EditorGUI.s_DelayedTextEditor.EndEditing();
                            if (text != CacheServerPreferences.s_CacheServerIPAddress)
                            {
                                CacheServerPreferences.s_CacheServerIPAddress = text;
                                CacheServerPreferences.WritePreferences();
                            }
                        }
                        if (InternalEditorUtility.CanConnectToCacheServer())
                        {
                            CacheServerPreferences.s_ConnectionState = CacheServerPreferences.ConnectionState.Success;
                        }
                        else
                        {
                            CacheServerPreferences.s_ConnectionState = CacheServerPreferences.ConnectionState.Failure;
                        }
                    }
                    GUILayout.Space(-25f);
                    switch (CacheServerPreferences.s_ConnectionState)
                    {
                    case CacheServerPreferences.ConnectionState.Unknown:
                        GUILayout.Space(44f);
                        break;

                    case CacheServerPreferences.ConnectionState.Success:
                        EditorGUILayout.HelpBox("Connection successful.", MessageType.Info, false);
                        break;

                    case CacheServerPreferences.ConnectionState.Failure:
                        EditorGUILayout.HelpBox("Connection failed.", MessageType.Warning, false);
                        break;
                    }
                }
                if (EditorGUI.EndChangeCheck())
                {
                    CacheServerPreferences.WritePreferences();
                    CacheServerPreferences.ReadPreferences();
                }
            }
        }
        public static void OnGUI()
        {
            EventType type = Event.current.type;

            if (s_Constants == null)
            {
                s_Constants = new Constants();
            }
            GUILayout.Space(10f);
            if (!InternalEditorUtility.HasTeamLicense())
            {
                GUILayout.Label(EditorGUIUtility.TempContent("You need to have a Pro or Team license to use the cache server.", EditorGUIUtility.GetHelpIcon(MessageType.Warning)), EditorStyles.helpBox, new GUILayoutOption[0]);
            }
            using (new EditorGUI.DisabledScope(!InternalEditorUtility.HasTeamLicense()))
            {
                if (!s_PrefsLoaded)
                {
                    ReadPreferences();
                    if ((s_CacheServerMode != CacheServerMode.Disabled) && (s_ConnectionState == ConnectionState.Unknown))
                    {
                        if (InternalEditorUtility.CanConnectToCacheServer())
                        {
                            s_ConnectionState = ConnectionState.Success;
                        }
                        else
                        {
                            s_ConnectionState = ConnectionState.Failure;
                        }
                    }
                    s_PrefsLoaded = true;
                }
                EditorGUI.BeginChangeCheck();
                if (Collab.instance.collabInfo.whitelisted && IsCollabCacheEnabled())
                {
                    s_CollabCacheEnabled = EditorGUILayout.Toggle("Use Collab Cache", s_CollabCacheEnabled, new GUILayoutOption[0]);
                    using (new EditorGUI.DisabledScope(!s_CollabCacheEnabled))
                    {
                        s_CollabCacheIPAddress = EditorGUILayout.TextField("Collab Cache IP Address", s_CollabCacheIPAddress, new GUILayoutOption[0]);
                    }
                }
                s_CacheServerMode = (CacheServerMode)EditorGUILayout.EnumPopup("Cache Server Mode", s_CacheServerMode, new GUILayoutOption[0]);
                if (s_CacheServerMode != CacheServerMode.Remote)
                {
                    goto Label_0238;
                }
                s_CacheServerIPAddress = EditorGUILayout.DelayedTextField("IP Address", s_CacheServerIPAddress, new GUILayoutOption[0]);
                if (GUI.changed)
                {
                    s_ConnectionState = ConnectionState.Unknown;
                }
                GUILayout.Space(5f);
                GUILayoutOption[] options = new GUILayoutOption[] { GUILayout.Width(150f) };
                if (GUILayout.Button("Check Connection", options))
                {
                    if (InternalEditorUtility.CanConnectToCacheServer())
                    {
                        s_ConnectionState = ConnectionState.Success;
                    }
                    else
                    {
                        s_ConnectionState = ConnectionState.Failure;
                    }
                }
                GUILayout.Space(-25f);
                ConnectionState state = s_ConnectionState;
                if (state != ConnectionState.Success)
                {
                    if (state == ConnectionState.Failure)
                    {
                        goto Label_0212;
                    }
                    if (state == ConnectionState.Unknown)
                    {
                        goto Label_0223;
                    }
                }
                else
                {
                    EditorGUILayout.HelpBox("Connection successful.", MessageType.Info, false);
                }
                goto Label_04B9;
Label_0212:
                EditorGUILayout.HelpBox("Connection failed.", MessageType.Warning, false);
                goto Label_04B9;
Label_0223:
                GUILayout.Space(44f);
                goto Label_04B9;
Label_0238:
                if (s_CacheServerMode == CacheServerMode.Local)
                {
                    s_LocalCacheServerSize = EditorGUILayout.IntSlider(Styles.maxCacheSize, s_LocalCacheServerSize, 1, 200, new GUILayoutOption[0]);
                    s_EnableCustomPath     = EditorGUILayout.Toggle(Styles.customCacheLocation, s_EnableCustomPath, new GUILayoutOption[0]);
                    if (s_EnableCustomPath)
                    {
                        GUIStyle popup = EditorStyles.popup;
                        GUILayout.BeginHorizontal(new GUILayoutOption[0]);
                        EditorGUILayout.PrefixLabel(Styles.cacheFolderLocation, popup);
                        Rect       position = GUILayoutUtility.GetRect(GUIContent.none, popup);
                        GUIContent content  = !string.IsNullOrEmpty(s_CachePath) ? new GUIContent(s_CachePath) : Styles.browse;
                        if (EditorGUI.ButtonMouseDown(position, content, FocusType.Passive, popup))
                        {
                            string folder = s_CachePath;
                            string str2   = EditorUtility.OpenFolderPanel(Styles.browseCacheLocation.text, folder, "");
                            if (!string.IsNullOrEmpty(str2))
                            {
                                if (LocalCacheServer.CheckValidCacheLocation(str2))
                                {
                                    s_CachePath = str2;
                                    WritePreferences();
                                }
                                else
                                {
                                    EditorUtility.DisplayDialog("Invalid Cache Location", "The directory " + str2 + " contains some files which don't look like Unity Cache server files. Please delete the directory contents or choose another directory.", "OK");
                                }
                            }
                        }
                        GUILayout.EndHorizontal();
                    }
                    else
                    {
                        s_CachePath = "";
                    }
                    if (LocalCacheServer.CheckCacheLocationExists())
                    {
                        GUIContent label = EditorGUIUtility.TextContent("Cache size is unknown");
                        if (s_LocalCacheServerUsedSize != -1L)
                        {
                            label = EditorGUIUtility.TextContent("Cache size is " + EditorUtility.FormatBytes(s_LocalCacheServerUsedSize));
                        }
                        GUILayout.BeginHorizontal(new GUILayoutOption[0]);
                        GUIStyle miniButton = EditorStyles.miniButton;
                        EditorGUILayout.PrefixLabel(label, miniButton);
                        if (EditorGUI.Button(GUILayoutUtility.GetRect(GUIContent.none, miniButton), Styles.enumerateCache, miniButton))
                        {
                            s_LocalCacheServerUsedSize = !LocalCacheServer.CheckCacheLocationExists() ? 0L : FileUtil.GetDirectorySize(LocalCacheServer.GetCacheLocation());
                        }
                        GUILayout.EndHorizontal();
                        GUILayout.BeginHorizontal(new GUILayoutOption[0]);
                        EditorGUILayout.PrefixLabel(EditorGUIUtility.blankContent, miniButton);
                        if (EditorGUI.Button(GUILayoutUtility.GetRect(GUIContent.none, miniButton), Styles.cleanCache, miniButton))
                        {
                            LocalCacheServer.Clear();
                            s_LocalCacheServerUsedSize = 0L;
                        }
                        GUILayout.EndHorizontal();
                    }
                    else
                    {
                        EditorGUILayout.HelpBox("Local cache directory does not exist - please check that you can access the cache folder and are able to write to it", MessageType.Warning, false);
                        s_LocalCacheServerUsedSize = -1L;
                    }
                    GUILayout.Label(Styles.cacheFolderLocation.text + ":", new GUILayoutOption[0]);
                    GUILayout.Label(LocalCacheServer.GetCacheLocation(), s_Constants.cacheFolderLocation, new GUILayoutOption[0]);
                }
Label_04B9:
                if (EditorGUI.EndChangeCheck())
                {
                    s_HasPendingChanges = true;
                }
                if (s_HasPendingChanges && (GUIUtility.hotControl == 0))
                {
                    s_HasPendingChanges = false;
                    WritePreferences();
                    ReadPreferences();
                }
            }
        }