Cleaning up network behaviour inspector (#1565)

split large method into smaller ones
This commit is contained in:
James Frowen 2020-03-20 01:46:53 +00:00 committed by GitHub
parent cc4032e236
commit 421832f650
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 22 deletions

View File

@ -4,7 +4,6 @@
using System.Linq; using System.Linq;
using System.Reflection; using System.Reflection;
using UnityEditor; using UnityEditor;
using UnityEngine;
namespace Mirror namespace Mirror
{ {
@ -77,7 +76,15 @@ void OnEnable()
public override void OnInspectorGUI() public override void OnInspectorGUI()
{ {
DrawDefaultInspector(); DrawDefaultInspector();
DrawDefaultSyncLists();
DrawDefaultSyncSettings();
}
/// <summary>
/// Draws Sync Objects that are IEnumerable
/// </summary>
protected void DrawDefaultSyncLists()
{
if (showSyncLists.Length > 0) if (showSyncLists.Length > 0)
{ {
EditorGUILayout.Space(); EditorGUILayout.Space();
@ -112,32 +119,28 @@ public override void OnInspectorGUI()
syncListIndex += 1; syncListIndex += 1;
} }
} }
}
/// <summary>
/// Draws SyncSettings if the NetworkBehaviour has anything to sync
/// </summary>
protected void DrawDefaultSyncSettings()
{
// does it sync anything? then show extra properties // does it sync anything? then show extra properties
// (no need to show it if the class only has Cmds/Rpcs and no sync) // (no need to show it if the class only has Cmds/Rpcs and no sync)
if (syncsAnything) if (!syncsAnything)
{ {
NetworkBehaviour networkBehaviour = target as NetworkBehaviour; return;
if (networkBehaviour != null)
{
EditorGUILayout.Space();
EditorGUILayout.LabelField("Sync Settings", EditorStyles.boldLabel);
// syncMode
serializedObject.FindProperty("syncMode").enumValueIndex = (int)(SyncMode)
EditorGUILayout.EnumPopup("Network Sync Mode", networkBehaviour.syncMode);
// syncInterval
// [0,2] should be enough. anything >2s is too laggy anyway.
serializedObject.FindProperty("syncInterval").floatValue = EditorGUILayout.Slider(
new GUIContent("Network Sync Interval",
"Time in seconds until next change is synchronized to the client. '0' means send immediately if changed. '0.5' means only send changes every 500ms.\n(This is for state synchronization like SyncVars, SyncLists, OnSerialize. Not for Cmds, Rpcs, etc.)"),
networkBehaviour.syncInterval, 0, 2);
// apply
serializedObject.ApplyModifiedProperties();
}
} }
EditorGUILayout.Space();
EditorGUILayout.LabelField("Sync Settings", EditorStyles.boldLabel);
EditorGUILayout.PropertyField(serializedObject.FindProperty("syncMode"));
EditorGUILayout.PropertyField(serializedObject.FindProperty("syncInterval"));
// apply
serializedObject.ApplyModifiedProperties();
} }
} }
} //namespace } //namespace

View File

@ -35,6 +35,8 @@ public class NetworkBehaviour : MonoBehaviour
/// <summary> /// <summary>
/// sync interval for OnSerialize (in seconds) /// sync interval for OnSerialize (in seconds)
/// </summary> /// </summary>
[Tooltip("Time in seconds until next change is synchronized to the client. '0' means send immediately if changed. '0.5' means only send changes every 500ms.\n(This is for state synchronization like SyncVars, SyncLists, OnSerialize. Not for Cmds, Rpcs, etc.)")]
[Range(0, 2)] // [0,2] should be enough. anything >2s is too laggy anyway.
[HideInInspector] public float syncInterval = 0.1f; [HideInInspector] public float syncInterval = 0.1f;
/// <summary> /// <summary>