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); } }
static void DisplayConvertToEntityHeaderCallBack(UnityEditor.Editor editor) { var selectedGameObject = editor.target as GameObject; if (selectedGameObject == null) { return; } using (new EditorGUILayout.HorizontalScope(EditorStyles.largeLabel)) { EditorGUILayout.LabelField(EditorGUIUtility.TrTextContentWithIcon(ConvertToEntityHeaderTextStrings.ConvertToEntity, EditorIcons.Convert), EditorStyles.label, GUILayout.MaxWidth(130)); // Multi-selection List <GameObject> TargetsList = new List <GameObject>(); TargetsList.Clear(); TargetsList.AddRange(editor.targets.OfType <GameObject>()); List <Component> componentToRemoveFromGOList = new List <Component>(); List <GameObject> gameObjectToAddComponentList = new List <GameObject>(); if (TargetsList.Count > 1) { foreach (var gameObject in TargetsList) { var convertToEntityComponent = gameObject.GetComponent <ConvertToEntity>(); if (convertToEntityComponent == null) { gameObjectToAddComponentList.Add(gameObject); } else { componentToRemoveFromGOList.Add(convertToEntityComponent); } } using (var changeScope = new EditorGUI.ChangeCheckScope()) { var componentToRemoveFromGOListLength = componentToRemoveFromGOList.Count; var gameObjectToAddComponentListLength = gameObjectToAddComponentList.Count; var toggleState = ToggleState.AllOn; if (componentToRemoveFromGOListLength > 0 && gameObjectToAddComponentListLength > 0) { toggleState = ToggleState.Mixed; } else if (componentToRemoveFromGOListLength == 0 && gameObjectToAddComponentListLength > 0) { toggleState = ToggleState.AllOff; } var oldShowMixedValue = EditorGUI.showMixedValue; EditorGUI.showMixedValue = toggleState == ToggleState.Mixed; EditorGUILayout.Toggle(toggleState == ToggleState.AllOn); EditorGUI.showMixedValue = oldShowMixedValue; if (changeScope.changed) { switch (toggleState) { case ToggleState.AllOn: { foreach (var component in componentToRemoveFromGOList) { Undo.DestroyObjectImmediate(component); } return; } case ToggleState.Mixed: { foreach (var gameObject in gameObjectToAddComponentList) { Undo.AddComponent <ConvertToEntity>(gameObject); } return; } case ToggleState.AllOff: { foreach (var gameObject in gameObjectToAddComponentList) { Undo.AddComponent <ConvertToEntity>(gameObject); } return; } } } } return; } else { var conversionStatus = GameObjectConversionEditorUtility.GetGameObjectConversionResultStatus(selectedGameObject); using (new EditorGUI.DisabledGroupScope(true)) { switch (conversionStatus) { case GameObjectConversionResultStatus.ConvertedBySubScene: { EditorGUILayout.ToggleLeft(EditorGUIUtility.TrTempContent(ConvertToEntityHeaderTextStrings.ConvertByScene), true); return; } case GameObjectConversionResultStatus.NotConvertedByStopConvertToEntityComponent: { EditorGUILayout.ToggleLeft(EditorGUIUtility.TrTempContent(ConvertToEntityHeaderTextStrings.StopConvertToEntityInHierarchy), false); return; } case GameObjectConversionResultStatus.NotConvertedByConvertAndInjectMode: { EditorGUILayout.ToggleLeft(EditorGUIUtility.TrTempContent(ConvertToEntityHeaderTextStrings.ConvertAndInjectInParents), false); return; } case GameObjectConversionResultStatus.ConvertedByAncestor: { EditorGUILayout.ToggleLeft(EditorGUIUtility.TrTempContent(ConvertToEntityHeaderTextStrings.ConvertByAncestor), true); return; } } } } // Converted by ConvertToEntity. using (var changeScope = new EditorGUI.ChangeCheckScope()) { EditorGUILayout.ToggleLeft(EditorGUIUtility.TrTempContent(""), GameObjectConversionEditorUtility.IsConverted(GameObjectConversionEditorUtility.GetGameObjectConversionResultStatus(selectedGameObject))); if (changeScope.changed) { if (selectedGameObject.GetComponent <ConvertToEntity>() == null) { Undo.AddComponent <ConvertToEntity>(selectedGameObject); } else { Undo.DestroyObjectImmediate(selectedGameObject.GetComponent <ConvertToEntity>()); } } } } }
public static bool IsGameObjectConverted(GameObject gameObject) { return(GameObjectConversionEditorUtility.GetGameObjectConversionResultStatus(gameObject).IsConverted()); }