unsafe bool DidChangeInternal(World world, IEnumerable <GameObject> targets, IEnumerable <int> selectedComponentTypes) { if (world != m_LastWorld) { m_LastWorld = world; return(true); } if (m_LastConversionData == EntityConversionData.Null) { // @TODO Handle multiple targets correctly. m_LastConversionData = EntityConversionUtility.GetConversionData(targets, world).FirstOrDefault(); if (m_LastConversionData == EntityConversionData.Null) { return(false); } m_LastChunk = world.EntityManager.GetChunk(m_LastConversionData.PrimaryEntity); return(true); } var chunk = world.EntityManager.GetChunk(m_LastConversionData.PrimaryEntity); if (null == chunk.m_Chunk || chunk != m_LastChunk) { m_LastChunk = chunk; return(true); } foreach (var typeIndex in selectedComponentTypes) { var typeIndexInArchetype = ChunkDataUtility.GetIndexInTypeArray(m_LastChunk.m_Chunk->Archetype, typeIndex); if (typeIndexInArchetype == -1) { continue; } var typeChangeVersion = m_LastChunk.m_Chunk->GetChangeVersion(typeIndexInArchetype); if (ChangeVersionUtility.DidChange(typeChangeVersion, m_LastGlobalSystemVersion)) { m_LastGlobalSystemVersion = world.EntityManager.GlobalSystemVersion; return(true); } } return(false); }
static void EditorOnFinishedDefaultHeaderGui(UnityEditor.Editor editor) { var gameObject = editor.target as GameObject; if (!gameObject || gameObject == null || !GameObjectConversionEditorUtility.IsConverted(gameObject)) { return; } var logs = EntityConversionUtility.GetConvertedComponentsInfo(gameObject, EntityConversionPreview.GetCurrentlySelectedWorld()).LogEvents; if (null == logs || logs.Count == 0) { return; } var errors = logs.Where(IsError).ToList(); var pagination = new PaginationField { ItemsPerPage = k_GameObjectHeaderLogEventItemsPerPage, Count = errors.Count, Page = SessionState.GetInt(string.Format(k_SessionStateKeyPage, gameObject.GetInstanceID()), 0) }; var startIndex = pagination.Page * pagination.ItemsPerPage; var endIndex = Math.Min(errors.Count, (pagination.Page + 1) * pagination.ItemsPerPage); for (var i = startIndex; i < endIndex; i++) { EditorGUILayout.HelpBox(errors[i].Message, MessageType.Error, true); } if (pagination.Count > pagination.ItemsPerPage) { pagination.OnGUI(GUILayoutUtility.GetRect(0, 20)); SessionState.SetInt(string.Format(k_SessionStateKeyPage, gameObject.GetInstanceID()), pagination.Page); } }
/// <summary> /// Called to implement custom controls in the preview window. /// </summary> public override void OnPreviewGUI(Rect r, GUIStyle background) { if (Event.current.type == EventType.Repaint) { m_PreviewRect = r; } using (var conversionDataPooledList = EntityConversionUtility.GetConversionData(m_GameObjectTargets, GetCurrentlySelectedWorld()).ToPooledList()) using (new GUILayout.AreaScope(m_PreviewRect, string.Empty, Styles.EntityConversionComponentArea)) using (new EditorGUILayout.VerticalScope()) { const string liveConversion = "Unity.Entities.Streaming.SubScene.LiveLinkEnabledInEditMode"; if (!EditorPrefs.GetBool(liveConversion, false)) { GUILayout.Label(EditorGUIUtility.TrTempContent("Live Conversion is disabled. Enable it in the DOTS file menu to see conversion preview."), Styles.EntityConversionWarningMessage); return; } var conversionData = conversionDataPooledList.List; if (m_GameObjectTargets.Count != conversionData.Count) { GUILayout.Label(EditorGUIUtility.TrTempContent("Entity conversion can only be previewed for GameObjects converted by a SubScene."), Styles.EntityConversionWarningMessage); return; } if (!ValidateGameObjectConversionData(conversionData, out var errorMessage)) { GUILayout.Label(EditorGUIUtility.TrTempContent(errorMessage), Styles.EntityConversionWarningMessage); return; } var primary = conversionData[0]; var isSingleSelection = conversionData.Count == 1; var additionalEntitiesCount = primary.AdditionalEntities.Count - 1; var hasAdditionalEntities = isSingleSelection && additionalEntitiesCount > 0; var entityName = isSingleSelection ? $"{primary.EntityManager.GetName(primary.PrimaryEntity)} (Entity)" : $"{EditorGUIBridge.mixedValueContent.text}({conversionData.Count} entities)"; if (m_State.AdditionalEntityIndex > additionalEntitiesCount) { m_State.AdditionalEntityIndex = additionalEntitiesCount; } if (hasAdditionalEntities) { m_State.ShowAdditionalEntities = EditorGUILayout.Foldout(m_State.ShowAdditionalEntities, EditorGUIUtility.TrTextContentWithIcon($"{entityName} + {additionalEntitiesCount} {(additionalEntitiesCount > 1 ? "Entities" : "Entity")}", EditorIcons.Entity), new GUIStyle(EditorStyles.foldout) { fixedWidth = 650.0f, fontStyle = FontStyle.Bold }); GUILayout.Space(4); if (m_State.ShowAdditionalEntities) { using (var scroll = new EditorGUILayout.ScrollViewScope(m_ScrollHeaderPosition, GUILayout.ExpandWidth(true), GUILayout.Height(56))) { m_ScrollHeaderPosition = scroll.scrollPosition; var additionalEntityLabel = GUILayoutUtility.GetRect(0, EditorGUIUtility.singleLineHeight + 3f); additionalEntityLabel.height -= 3.0f; additionalEntityLabel.x = 4.0f; for (var i = 1; i < primary.AdditionalEntities.Count; ++i) { var entity = primary.AdditionalEntities[i]; if (ShowAdditionalEntityToggle(ref additionalEntityLabel, i == m_State.AdditionalEntityIndex, primary.EntityManager, entity)) { m_State.AdditionalEntityIndex = i; } else if (i == m_State.AdditionalEntityIndex) { m_State.AdditionalEntityIndex = -1; } } } GUILayout.Space(8); } } else { EditorGUILayout.LabelField(EditorGUIUtility.TrTextContentWithIcon(entityName, EditorIcons.Entity), EditorStyles.boldLabel); GUILayout.Space(4); } using (var scroll = new EditorGUILayout.ScrollViewScope(m_ScrollPosition)) using (var inspectorTargets = GetInspectorTargets(conversionData, m_State).ToPooledList()) using (var commonComponentTypes = GetCommonComponentTypes(inspectorTargets.List).ToPooledList()) { m_ScrollPosition = scroll.scrollPosition; var labelRect = GUILayoutUtility.GetRect(0, EditorGUIUtility.singleLineHeight + 3f); labelRect.x = 4f; labelRect.height = EditorGUIUtility.singleLineHeight; for (var i = 0; i < commonComponentTypes.List.Count; i++) { var componentType = commonComponentTypes.List[i]; var isSelected = m_State.SelectedComponentTypes.Contains(componentType.TypeIndex); var isSelectedInUi = ShowComponentTypeToggle(ref labelRect, isSelected, componentType); HandleComponentSelection(commonComponentTypes, componentType, i, isSelected, isSelectedInUi); } GUILayout.Space(6); m_RuntimeComponentsDrawer.SetTargets(inspectorTargets.List); m_RuntimeComponentsDrawer.SetComponentTypes(m_State.SelectedComponentTypes); if (m_State.SelectedComponentTypes.Count > 0 && commonComponentTypes.List.Count(type => m_State.SelectedComponentTypes.Contains(type.TypeIndex)) > 0) { using (new WideModeScope(338)) { m_RuntimeComponentsDrawer.OnGUI(); } } GUILayout.Space(4); if (!isSingleSelection) { GUILayout.Label(EditorGUIUtility.TrTempContent("Components that are only on some of the converted entities are not shown."), Styles.EntityConversionCommonComponentMessage); } } } }