private void DrawComponentList(GameObjectNetworkEntityBase entity) { if (entity.Components != null && entity.Components.Count > 0) { _showComponents = EditorGUILayout.Foldout(_showComponents, _componentsContent); if (_showComponents) { EditorGUI.indentLevel++; foreach (var component in entity.Components) { if (component is MonoNetworkComponent) { GUI.enabled = false; EditorGUILayout.ObjectField((MonoNetworkComponent)component, typeof(MonoNetworkComponent), true); GUI.enabled = true; } else { EditorGUILayout.LabelField($"{component.GetType().FullName}: {component}"); } } EditorGUI.indentLevel--; } } else { EditorGUILayout.LabelField(_noComponentsContent); } }
private void DrawOwnerInfo(GameObjectNetworkEntityBase entity) { if (!IsPrefab(entity.gameObject)) { if (Application.isPlaying) { if (entity.OwnerId == -1) { var serverPlayer = entity.Manager?.GetServerPlayer(); EditorGUILayout.LabelField(_ownerIdContent, new GUIContent($"Scene - controlled by server: " + $"{FormatPlayer(serverPlayer)}")); } else { var player = entity.Manager?.GetPlayer(entity.OwnerId); EditorGUILayout.LabelField(_ownerIdContent, new GUIContent(FormatPlayer(player))); } } else { EditorGUILayout.LabelField(_ownerIdContent, new GUIContent("Scene (controlled by server at runtime)")); } } else { EditorGUILayout.LabelField(_ownerIdContent, _setAtRuntimeContent); } }
private void DrawPrefabCacheInfo(GameObjectNetworkEntityBase entity) { if (!IsInCache(entity.gameObject)) { EditorGUILayout.BeginHorizontal(); EditorGUILayout.HelpBox( "This entity is not registered in the prefab cache, so it cannot be instantiated over the network.", MessageType.Warning); EditorGUILayout.BeginVertical(); GUILayout.Space(16); if (GUILayout.Button("Add to Cache", EditorStyles.miniButton)) { // Try to find an empty space bool insertedInFreeSpace = false; for (int i = 0; i < _cacheArray.arraySize && !insertedInFreeSpace; i++) { var elem = _cacheArray.GetArrayElementAtIndex(i); if (elem.objectReferenceInstanceIDValue == 0) { elem.objectReferenceInstanceIDValue = entity.gameObject.GetInstanceID(); insertedInFreeSpace = true; } } if (!insertedInFreeSpace) { // If no empty space was found, insert at the end _cacheArray.arraySize++; var lastElem = _cacheArray.GetArrayElementAtIndex(_cacheArray.arraySize - 1); lastElem.objectReferenceInstanceIDValue = entity.gameObject.GetInstanceID(); } _cacheObj.ApplyModifiedProperties(); } EditorGUILayout.EndVertical(); EditorGUILayout.EndHorizontal(); EditorGUILayout.Space(); } else { EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("(Registered in Prefab Cache)", EditorStyles.miniBoldLabel); if (GUILayout.Button("View Cache", EditorStyles.miniButton, GUILayout.Width(80f))) { Selection.activeObject = _cacheObj.targetObject; } EditorGUILayout.EndHorizontal(); GUILayout.Space(2); } }
private void DrawIdInfo(GameObjectNetworkEntityBase entity) { var duplicateIdEntities = Resources.FindObjectsOfTypeAll <GameObjectNetworkEntityBase>() .Where(e => e != entity && !IsPrefab(e.gameObject)) .ToArray(); bool duplicate = duplicateIdEntities.Any(e => e.Id == entity.Id); EditorGUI.BeginChangeCheck(); if (duplicate) { EditorGUILayout.BeginHorizontal(); EditorGUILayout.HelpBox("Duplicate Entity ID", MessageType.Warning); EditorGUILayout.BeginVertical(GUILayout.Width(100f)); GUILayout.Space(6f); if (GUILayout.Button("Fix")) { GUI.FocusControl(null); entity.Reset(); EditorUtility.SetDirty(entity); } if (GUILayout.Button("Select other entities", EditorStyles.miniButton)) { // ReSharper disable once CoVariantArrayConversion Selection.objects = duplicateIdEntities.Select(e => e.gameObject).ToArray(); } EditorGUILayout.EndVertical(); EditorGUILayout.EndHorizontal(); EditorGUILayout.Space(); EditorGUILayout.PropertyField(_idProp, _duplicateIdContent, EditorStyles.boldFont); } else { EditorGUILayout.PropertyField(_idProp, _idContent); } if (EditorGUI.EndChangeCheck()) { serializedObject.ApplyModifiedProperties(); } }