NetworkIdentityEditor.cs
4.53 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
#if ENABLE_UNET
using System;
using UnityEngine;
using UnityEngine.Networking;
namespace UnityEditor
{
[CustomEditor(typeof(NetworkIdentity), true)]
[CanEditMultipleObjects]
[Obsolete("The high level API classes are deprecated and will be removed in the future.")]
public class NetworkIdentityEditor : Editor
{
SerializedProperty m_ServerOnlyProperty;
SerializedProperty m_LocalPlayerAuthorityProperty;
GUIContent m_ServerOnlyLabel;
GUIContent m_LocalPlayerAuthorityLabel;
GUIContent m_SpawnLabel;
NetworkIdentity m_NetworkIdentity;
bool m_Initialized;
bool m_ShowObservers;
void Init()
{
if (m_Initialized)
{
return;
}
m_Initialized = true;
m_NetworkIdentity = target as NetworkIdentity;
m_ServerOnlyProperty = serializedObject.FindProperty("m_ServerOnly");
m_LocalPlayerAuthorityProperty = serializedObject.FindProperty("m_LocalPlayerAuthority");
m_ServerOnlyLabel = TextUtility.TextContent("Server Only", "True if the object should only exist on the server.");
m_LocalPlayerAuthorityLabel = TextUtility.TextContent("Local Player Authority", "True if this object will be controlled by a player on a client.");
m_SpawnLabel = TextUtility.TextContent("Spawn Object", "This causes an unspawned server object to be spawned on clients");
}
public override void OnInspectorGUI()
{
if (m_ServerOnlyProperty == null)
{
m_Initialized = false;
}
Init();
serializedObject.Update();
if (m_ServerOnlyProperty.boolValue)
{
EditorGUILayout.PropertyField(m_ServerOnlyProperty, m_ServerOnlyLabel);
EditorGUILayout.LabelField("Local Player Authority cannot be set for server-only objects");
}
else if (m_LocalPlayerAuthorityProperty.boolValue)
{
EditorGUILayout.LabelField("Server Only cannot be set for Local Player Authority objects");
EditorGUILayout.PropertyField(m_LocalPlayerAuthorityProperty, m_LocalPlayerAuthorityLabel);
}
else
{
EditorGUILayout.PropertyField(m_ServerOnlyProperty, m_ServerOnlyLabel);
EditorGUILayout.PropertyField(m_LocalPlayerAuthorityProperty, m_LocalPlayerAuthorityLabel);
}
serializedObject.ApplyModifiedProperties();
if (!Application.isPlaying)
{
return;
}
// Runtime actions below here
EditorGUILayout.Separator();
if (m_NetworkIdentity.observers != null && m_NetworkIdentity.observers.Count > 0)
{
m_ShowObservers = EditorGUILayout.Foldout(m_ShowObservers, "Observers");
if (m_ShowObservers)
{
EditorGUI.indentLevel += 1;
foreach (var o in m_NetworkIdentity.observers)
{
GameObject obj = null;
foreach (var p in o.playerControllers)
{
if (p != null)
{
obj = p.gameObject;
break;
}
}
if (obj)
EditorGUILayout.ObjectField("Connection " + o.connectionId, obj, typeof(GameObject), false);
else
EditorGUILayout.TextField("Connection " + o.connectionId);
}
EditorGUI.indentLevel -= 1;
}
}
if (PrefabUtility.IsPartOfPrefabAsset(m_NetworkIdentity.gameObject))
return;
if (m_NetworkIdentity.gameObject.activeSelf && m_NetworkIdentity.netId.IsEmpty() && NetworkServer.active)
{
EditorGUILayout.BeginHorizontal();
EditorGUILayout.LabelField(m_SpawnLabel);
if (GUILayout.Toggle(false, "Spawn", EditorStyles.miniButtonLeft))
{
NetworkServer.Spawn(m_NetworkIdentity.gameObject);
EditorUtility.SetDirty(target); // preview window STILL doens't update immediately..
}
EditorGUILayout.EndHorizontal();
}
}
}
}
#endif //ENABLE_UNET