public static void ActivatePreviousPrefabInPrefabCategory(PrefabCategory prefabCategory) { List <Prefab> filteredPrefabs = prefabCategory.GetFilteredPrefabs(); int prefabIndex = prefabCategory.GetPrefabIndex(prefabCategory.ActivePrefab) - 1; if (prefabIndex < 0) { prefabIndex = prefabCategory.NumberOfPrefabs - 1; } while (prefabIndex >= 0) { Prefab newActivePrefab = prefabCategory.GetPrefabByIndex(prefabIndex); if (filteredPrefabs.Contains(newActivePrefab)) { prefabCategory.SetActivePrefab(newActivePrefab); return; } --prefabIndex; } prefabCategory.SetActivePrefab(null); }
private static void EnsureGuideUsesBeginTileConnectionPrefab() { ObjectPlacementPathTileConnectionSettings tileConnectionSettings = ObjectPlacement.Get().PathObjectPlacement.PathSettings.TileConnectionSettings; ObjectPlacementPathTileConnectionTypeSettings beginTileConnectionSettings = tileConnectionSettings.GetSettingsForTileConnectionType(ObjectPlacementPathTileConnectionType.Begin); if (CanRefreshGuideToUseBeginTileConnectionPrefab(beginTileConnectionSettings)) { PrefabCategory categoryWhichContainsBeginPrefab = PrefabCategoryDatabase.Get().GetPrefabCategoryWhichContainsPrefab(beginTileConnectionSettings.Prefab); if (categoryWhichContainsBeginPrefab == null) { return; } PrefabCategoryDatabase.Get().SetActivePrefabCategory(categoryWhichContainsBeginPrefab); categoryWhichContainsBeginPrefab.SetActivePrefab(beginTileConnectionSettings.Prefab); ObjectPlacement.Get().DestroyPlacementGuide(); ObjectPlacementGuide.CreateFromActivePrefabIfNotExists(); } // Note: When using tile connections, we will always use the original prefab scale if (ObjectPlacementGuide.ExistsInScene) { ObjectPlacementGuide.Instance.WorldScale = beginTileConnectionSettings.Prefab.InitialWorldScale; } }
private void RenderPrefabPreviewRows() { for (int prefabIndex = 0; prefabIndex < _filteredPrefabs.Count; ++prefabIndex) { // Start a new row? if (prefabIndex % ViewData.NumberOfPrefabsPerRow == 0) { if (prefabIndex != 0) { EditorGUILayout.EndHorizontal(); } EditorGUILayout.BeginHorizontal(); } // Render the prefab entry Prefab prefab = _filteredPrefabs[prefabIndex]; var previewButtonRenderData = new PrefabPreviewButtonRenderData(); previewButtonRenderData.ExtractFromPrefab(prefab, ViewData.PrefabPreviewScale); EditorGUILayout.BeginVertical(GUILayout.Width(previewButtonRenderData.ButtonWidth)); // Render the prefab preview button EditorGUIColor.Push(prefab == _prefabCategory.ActivePrefab ? ViewData.ActivePrefabTint : Color.white); if (EditorGUILayoutEx.PrefabPreview(prefab, true, previewButtonRenderData)) { ObjectPlacementSettings placementSettings = ObjectPlacementSettings.Get(); if (placementSettings.ObjectPlacementMode == ObjectPlacementMode.DecorPaint && placementSettings.DecorPaintObjectPlacementSettings.DecorPaintMode == DecorPaintMode.Brush && DecorPaintObjectPlacementBrushDatabase.Get().ActiveBrush != null && Event.current.button == (int)MouseButton.Right) { UndoEx.RecordForToolAction(DecorPaintObjectPlacementBrushDatabase.Get().ActiveBrush); DecorPaintObjectPlacementBrushElement brushElement = DecorPaintObjectPlacementBrushDatabase.Get().ActiveBrush.CreateNewElement(); brushElement.Prefab = prefab; Octave3DWorldBuilder.ActiveInstance.RepaintAllEditorWindows(); Octave3DWorldBuilder.ActiveInstance.Inspector.Repaint(); } else if (Octave3DWorldBuilder.ActiveInstance.Inspector.ActiveInspectorGUIIdentifier == InspectorGUIIdentifier.ObjectSelection && AllShortcutCombos.Instance.ReplacePrefabsForSelectedObjects.IsActive()) { ObjectSelection.Get().ReplaceSelectedObjectsWithPrefab(prefab); } else { UndoEx.RecordForToolAction(_prefabCategory); _prefabCategory.SetActivePrefab(prefab); } } EditorGUIColor.Pop(); // Render the prefab name labels if necessary if (ViewData.ShowPrefabNames) { Rect previewRectangle = GUILayoutUtility.GetLastRect(); EditorGUILayoutEx.LabelInMiddleOfControlRect(previewRectangle, prefab.Name, previewButtonRenderData.ButtonHeight, GetStyleForPrefabNameLabel()); } // Render the remove prefab button if (GUILayout.Button(GetRemovePrefabButtonContent())) { UndoEx.RecordForToolAction(_prefabCategory); _prefabCategory.RemoveAndDestroyPrefab(prefab); Octave3DWorldBuilder.ActiveInstance.Inspector.Repaint(); } EditorGUILayout.EndVertical(); } // End the last row (if any) if (_filteredPrefabs.Count != 0) { EditorGUILayout.EndHorizontal(); } }
private void RenderActionsView() { EditorGUILayout.BeginHorizontal(); var content = new GUIContent(); content.text = "Move"; content.tooltip = "Allows you to move prefabs to a destination category. The popup controls to the right allow you to choose what prefabs will be moved and to which category."; if (GUILayout.Button(content, GUILayout.Width(100.0f))) { if (ViewData.PrefabMoveType == PrefabMoveType.AllPrefabs) { PrefabCategory destinationCategory = ViewData.DestinationCategoryForPrefabMove; if (destinationCategory != null) { UndoEx.RecordForToolAction(destinationCategory); UndoEx.RecordForToolAction(PrefabCategoryDatabase.Get().ActivePrefabCategory); PrefabCategoryDatabase.Get().ActivePrefabCategory.TransferAllPrefabsToCategory(destinationCategory); } } else if (ViewData.PrefabMoveType == PrefabMoveType.FilteredPrefabs) { PrefabCategory destinationCategory = ViewData.DestinationCategoryForPrefabMove; if (destinationCategory != null) { PrefabCategory activePrefabCategory = PrefabCategoryDatabase.Get().ActivePrefabCategory; UndoEx.RecordForToolAction(destinationCategory); UndoEx.RecordForToolAction(activePrefabCategory); activePrefabCategory.TransferPrefabCollectionToCategory(activePrefabCategory.GetFilteredPrefabs(), destinationCategory); } } else if (ViewData.PrefabMoveType == PrefabMoveType.ActivePrefab) { Prefab activePrefab = PrefabCategoryDatabase.Get().ActivePrefabCategory.ActivePrefab; if (activePrefab != null) { PrefabCategory destinationCategory = ViewData.DestinationCategoryForPrefabMove; if (destinationCategory != null) { PrefabCategory activePrefabCategory = PrefabCategoryDatabase.Get().ActivePrefabCategory; UndoEx.RecordForToolAction(PrefabCategoryDatabase.Get()); UndoEx.RecordForToolAction(destinationCategory); UndoEx.RecordForToolAction(activePrefabCategory); activePrefabCategory.TransferPrefabToCategory(activePrefab, destinationCategory); PrefabCategoryDatabase.Get().SetActivePrefabCategory(destinationCategory); destinationCategory.SetActivePrefab(activePrefab); } } } } PrefabMoveType newPrefabMoveType = (PrefabMoveType)EditorGUILayout.EnumPopup(ViewData.PrefabMoveType); if (newPrefabMoveType != ViewData.PrefabMoveType) { UndoEx.RecordForToolAction(ViewData); ViewData.PrefabMoveType = newPrefabMoveType; } List <string> allPrefabCategoryNames = PrefabCategoryDatabase.Get().GetAllPrefabCategoryNames(); string newString = EditorGUILayoutEx.Popup(new GUIContent(), ViewData.DestinationCategoryForPrefabMove.Name, allPrefabCategoryNames); if (newString != ViewData.DestinationCategoryForPrefabMove.Name) { UndoEx.RecordForToolAction(ViewData); ViewData.DestinationCategoryForPrefabMove = PrefabCategoryDatabase.Get().GetPrefabCategoryByName(newString); } EditorGUILayout.EndHorizontal(); EditorGUILayout.Separator(); EditorGUILayout.BeginHorizontal(); RenderSetPrefabOffsetFromGridSurfaceInActiveCategoryButton(); RenderPrefabOffsetFromGridSurfaceField(); EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); RenderSetPrefabOffsetFromObjectSurfaceInActiveCategoryButton(); RenderPrefabOffsetFromObjectSurfaceField(); EditorGUILayout.EndHorizontal(); }