forked from Unity-Technologies/UnityCsReference
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCacheServerWindow.cs
More file actions
129 lines (112 loc) · 4.83 KB
/
Copy pathCacheServerWindow.cs
File metadata and controls
129 lines (112 loc) · 4.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
// Unity C# reference source
// Copyright (c) Unity Technologies. For terms of use, see
// https://unity3d.com/legal/licenses/Unity_Reference_Only_License
using UnityEngine;
using UnityEditor.Experimental;
using System;
namespace UnityEditor
{
[InitializeOnLoad]
internal class CacheServerWindow : PopupWindowContent
{
private readonly GUIContent m_StatusMessageDisabled;
private readonly GUIContent m_StatusMessageConnected;
private readonly GUIContent m_StatusMessageError;
private readonly GUIContent m_OpenProjectSettings;
private readonly GUIContent m_RefreshIcon;
private readonly GUIStyle m_WindowStyle;
public CacheServerWindow()
{
m_StatusMessageDisabled = EditorGUIUtility.TrTextContent("No cache server connected");
m_StatusMessageConnected = EditorGUIUtility.TrTextContent("Connected");
m_StatusMessageError = EditorGUIUtility.TrTextContent("Attempting to reconnect");
m_OpenProjectSettings = EditorGUIUtility.TrTextContent("Open Project Settings...");
m_RefreshIcon = EditorGUIUtility.TrIconContent("Refresh", "Refresh connection");
m_WindowStyle = new GUIStyle { padding = new RectOffset(6, 6, 6, 6) };
}
public override void OnGUI(Rect rect)
{
var exit = false;
GUILayout.BeginArea(rect, m_WindowStyle);
if (AssetDatabaseExperimental.IsCacheServerEnabled())
{
var iconPosition = new Rect();
iconPosition.x = rect.width - m_RefreshIcon.image.width - m_WindowStyle.padding.right;
iconPosition.y = m_WindowStyle.padding.top;
iconPosition.width = m_RefreshIcon.image.width;
iconPosition.height = m_RefreshIcon.image.height;
GUIStyle helpIconStyle = EditorStyles.iconButton;
if (GUI.Button(iconPosition, m_RefreshIcon, helpIconStyle))
{
AssetDatabaseExperimental.RefreshSettings();
}
GUILayout.BeginHorizontal();
var style = new GUIStyle();
style.fontStyle = FontStyle.Bold;
style.normal.textColor = EditorStyles.boldLabel.normal.textColor;
if (!AssetDatabaseExperimental.IsConnectedToCacheServer())
{
style.normal.textColor = new Color(0.97f, 0.32f, 0.31f);
}
EditorGUILayout.LabelField(AssetDatabaseExperimental.GetCacheServerAddress(), style);
GUILayout.EndHorizontal();
}
GUILayout.BeginHorizontal();
var statusTextStyle = new GUIStyle()
{
normal = { textColor = Color.grey }
};
EditorGUILayout.LabelField(ConnectionStatusText(), statusTextStyle);
GUILayout.EndHorizontal();
GUILayout.BeginHorizontal();
if (GUILayout.Button(m_OpenProjectSettings, "ControlLabel"))
{
OpenProjectSettings();
}
GUILayout.EndHorizontal();
GUILayout.EndArea();
exit |= Event.current.type == EventType.KeyDown && Event.current.keyCode == KeyCode.Escape;
if (exit)
{
editorWindow.Close();
GUIUtility.ExitGUI();
}
}
private GUIContent ConnectionStatusText()
{
GUIContent status = m_StatusMessageConnected;
if (!AssetDatabaseExperimental.IsCacheServerEnabled())
{
status = m_StatusMessageDisabled;
}
else if (!AssetDatabaseExperimental.IsConnectedToCacheServer())
{
status = m_StatusMessageError;
}
return status;
}
private void OpenProjectSettings()
{
var settings = SettingsWindow.Show(SettingsScope.Project, "Project/Editor");
if (settings == null)
{
Debug.LogError("Could not find Preferences for 'Project/Editor'");
}
}
private void OpenPreferences()
{
var settings = SettingsWindow.Show(SettingsScope.User, "Preferences/Cache Server (global)");
if (settings == null)
{
Debug.LogError("Could not find Preferences for 'Preferences/Cache Server (global)'");
}
}
public override Vector2 GetWindowSize()
{
int lines = AssetDatabaseExperimental.IsCacheServerEnabled() ? 3 : 2;
int heightOfLines = (int)Math.Ceiling(EditorGUI.kSingleLineHeight * lines);
int heightOfWindowPadding = m_WindowStyle.padding.top + m_WindowStyle.padding.bottom;
return new Vector2(250, heightOfLines + heightOfWindowPadding);
}
}
}