style: naming conventions

This commit is contained in:
Paul Pacheco 2019-04-06 07:50:58 -05:00
parent aa75387d60
commit cadb0cc51c

View File

@ -60,11 +60,11 @@ public Styles()
} }
} }
List<NetworkIdentityInfo> m_Info; List<NetworkIdentityInfo> info;
List<NetworkBehaviourInfo> m_Behaviours; List<NetworkBehaviourInfo> m_Behaviours;
NetworkIdentity m_Identity; NetworkIdentity identity;
GUIContent m_Title; GUIContent title;
Styles m_Styles = new Styles(); Styles styles = new Styles();
public override void Initialize(UnityObject[] targets) public override void Initialize(UnityObject[] targets)
{ {
@ -74,16 +74,16 @@ public override void Initialize(UnityObject[] targets)
public override GUIContent GetPreviewTitle() public override GUIContent GetPreviewTitle()
{ {
if (m_Title == null) if (title == null)
{ {
m_Title = new GUIContent("Network Information"); title = new GUIContent("Network Information");
} }
return m_Title; return title;
} }
public override bool HasPreviewGUI() public override bool HasPreviewGUI()
{ {
return m_Info != null && m_Info.Count > 0; return info != null && info.Count > 0;
} }
public override void OnPreviewGUI(Rect r, GUIStyle background) public override void OnPreviewGUI(Rect r, GUIStyle background)
@ -91,11 +91,11 @@ public override void OnPreviewGUI(Rect r, GUIStyle background)
if (Event.current.type != EventType.Repaint) if (Event.current.type != EventType.Repaint)
return; return;
if (m_Info == null || m_Info.Count == 0) if (info == null || info.Count == 0)
return; return;
if (m_Styles == null) if (styles == null)
m_Styles = new Styles(); styles = new Styles();
// Get required label size for the names of the information values we're going to show // Get required label size for the names of the information values we're going to show
// There are two columns, one with label for the name of the info and the next for the value // There are two columns, one with label for the name of the info and the next for the value
@ -113,10 +113,10 @@ public override void OnPreviewGUI(Rect r, GUIStyle background)
Rect labelRect = new Rect(initialX, initialY, maxNameLabelSize.x, maxNameLabelSize.y); Rect labelRect = new Rect(initialX, initialY, maxNameLabelSize.x, maxNameLabelSize.y);
Rect idLabelRect = new Rect(maxNameLabelSize.x, initialY, maxValueLabelSize.x, maxValueLabelSize.y); Rect idLabelRect = new Rect(maxNameLabelSize.x, initialY, maxValueLabelSize.x, maxValueLabelSize.y);
foreach (NetworkIdentityInfo info in m_Info) foreach (NetworkIdentityInfo info in info)
{ {
GUI.Label(labelRect, info.name, m_Styles.labelStyle); GUI.Label(labelRect, info.name, styles.labelStyle);
GUI.Label(idLabelRect, info.value, m_Styles.componentName); GUI.Label(idLabelRect, info.value, styles.componentName);
labelRect.y += labelRect.height; labelRect.y += labelRect.height;
labelRect.x = initialX; labelRect.x = initialX;
idLabelRect.y += idLabelRect.height; idLabelRect.y += idLabelRect.height;
@ -129,7 +129,7 @@ public override void OnPreviewGUI(Rect r, GUIStyle background)
Vector2 maxBehaviourLabelSize = GetMaxBehaviourLabelSize(); Vector2 maxBehaviourLabelSize = GetMaxBehaviourLabelSize();
Rect behaviourRect = new Rect(initialX, labelRect.y + 10, maxBehaviourLabelSize.x, maxBehaviourLabelSize.y); Rect behaviourRect = new Rect(initialX, labelRect.y + 10, maxBehaviourLabelSize.x, maxBehaviourLabelSize.y);
GUI.Label(behaviourRect, new GUIContent("Network Behaviours"), m_Styles.labelStyle); GUI.Label(behaviourRect, new GUIContent("Network Behaviours"), styles.labelStyle);
behaviourRect.x += 20; // indent names behaviourRect.x += 20; // indent names
behaviourRect.y += behaviourRect.height; behaviourRect.y += behaviourRect.height;
@ -141,31 +141,31 @@ public override void OnPreviewGUI(Rect r, GUIStyle background)
continue; continue;
} }
GUI.Label(behaviourRect, info.name, info.behaviour.enabled ? m_Styles.componentName : m_Styles.disabledName); GUI.Label(behaviourRect, info.name, info.behaviour.enabled ? styles.componentName : styles.disabledName);
behaviourRect.y += behaviourRect.height; behaviourRect.y += behaviourRect.height;
lastY = behaviourRect.y; lastY = behaviourRect.y;
} }
if (m_Identity.observers != null && m_Identity.observers.Count > 0) if (identity.observers != null && identity.observers.Count > 0)
{ {
Rect observerRect = new Rect(initialX, lastY + 10, 200, 20); Rect observerRect = new Rect(initialX, lastY + 10, 200, 20);
GUI.Label(observerRect, new GUIContent("Network observers"), m_Styles.labelStyle); GUI.Label(observerRect, new GUIContent("Network observers"), styles.labelStyle);
observerRect.x += 20; // indent names observerRect.x += 20; // indent names
observerRect.y += observerRect.height; observerRect.y += observerRect.height;
foreach (KeyValuePair<int, NetworkConnection> kvp in m_Identity.observers) foreach (KeyValuePair<int, NetworkConnection> kvp in identity.observers)
{ {
GUI.Label(observerRect, kvp.Value.address + ":" + kvp.Value.connectionId, m_Styles.componentName); GUI.Label(observerRect, kvp.Value.address + ":" + kvp.Value.connectionId, styles.componentName);
observerRect.y += observerRect.height; observerRect.y += observerRect.height;
lastY = observerRect.y; lastY = observerRect.y;
} }
} }
if (m_Identity.clientAuthorityOwner != null) if (identity.clientAuthorityOwner != null)
{ {
Rect ownerRect = new Rect(initialX, lastY + 10, 400, 20); Rect ownerRect = new Rect(initialX, lastY + 10, 400, 20);
GUI.Label(ownerRect, new GUIContent("Client Authority: " + m_Identity.clientAuthorityOwner), m_Styles.labelStyle); GUI.Label(ownerRect, new GUIContent("Client Authority: " + identity.clientAuthorityOwner), styles.labelStyle);
} }
} }
} }
@ -174,9 +174,9 @@ public override void OnPreviewGUI(Rect r, GUIStyle background)
Vector2 GetMaxNameLabelSize() Vector2 GetMaxNameLabelSize()
{ {
Vector2 maxLabelSize = Vector2.zero; Vector2 maxLabelSize = Vector2.zero;
foreach (NetworkIdentityInfo info in m_Info) foreach (NetworkIdentityInfo info in info)
{ {
Vector2 labelSize = m_Styles.labelStyle.CalcSize(info.value); Vector2 labelSize = styles.labelStyle.CalcSize(info.value);
if (maxLabelSize.x < labelSize.x) if (maxLabelSize.x < labelSize.x)
{ {
maxLabelSize.x = labelSize.x; maxLabelSize.x = labelSize.x;
@ -194,7 +194,7 @@ Vector2 GetMaxBehaviourLabelSize()
Vector2 maxLabelSize = Vector2.zero; Vector2 maxLabelSize = Vector2.zero;
foreach (NetworkBehaviourInfo behaviour in m_Behaviours) foreach (NetworkBehaviourInfo behaviour in m_Behaviours)
{ {
Vector2 labelSize = m_Styles.labelStyle.CalcSize(behaviour.name); Vector2 labelSize = styles.labelStyle.CalcSize(behaviour.name);
if (maxLabelSize.x < labelSize.x) if (maxLabelSize.x < labelSize.x)
{ {
maxLabelSize.x = labelSize.x; maxLabelSize.x = labelSize.x;
@ -209,13 +209,13 @@ Vector2 GetMaxBehaviourLabelSize()
void GetNetworkInformation(GameObject gameObject) void GetNetworkInformation(GameObject gameObject)
{ {
m_Identity = gameObject.GetComponent<NetworkIdentity>(); identity = gameObject.GetComponent<NetworkIdentity>();
if (m_Identity != null) if (identity != null)
{ {
m_Info = new List<NetworkIdentityInfo> info = new List<NetworkIdentityInfo>
{ {
GetAssetId(), GetAssetId(),
GetString("Scene ID", m_Identity.sceneId.ToString("X")) GetString("Scene ID", identity.sceneId.ToString("X"))
}; };
if (!Application.isPlaying) if (!Application.isPlaying)
@ -223,12 +223,12 @@ void GetNetworkInformation(GameObject gameObject)
return; return;
} }
m_Info.Add(GetString("Network ID", m_Identity.netId.ToString())); info.Add(GetString("Network ID", identity.netId.ToString()));
m_Info.Add(GetBoolean("Is Client", m_Identity.isClient)); info.Add(GetBoolean("Is Client", identity.isClient));
m_Info.Add(GetBoolean("Is Server", m_Identity.isServer)); info.Add(GetBoolean("Is Server", identity.isServer));
m_Info.Add(GetBoolean("Has Authority", m_Identity.hasAuthority)); info.Add(GetBoolean("Has Authority", identity.hasAuthority));
m_Info.Add(GetBoolean("Is Local Player", m_Identity.isLocalPlayer)); info.Add(GetBoolean("Is Local Player", identity.isLocalPlayer));
NetworkBehaviour[] behaviours = gameObject.GetComponents<NetworkBehaviour>(); NetworkBehaviour[] behaviours = gameObject.GetComponents<NetworkBehaviour>();
if (behaviours.Length > 0) if (behaviours.Length > 0)
@ -249,7 +249,7 @@ void GetNetworkInformation(GameObject gameObject)
NetworkIdentityInfo GetAssetId() NetworkIdentityInfo GetAssetId()
{ {
string assetId = m_Identity.assetId.ToString(); string assetId = identity.assetId.ToString();
if (string.IsNullOrEmpty(assetId)) if (string.IsNullOrEmpty(assetId))
{ {
assetId = "<object has no prefab>"; assetId = "<object has no prefab>";