private void RenderProjectionLineRenderingToggle() { bool newBool = EditorGUILayout.ToggleLeft(GetContentForProjectionLineRenderingToggle(), _settings.RenderProjectionLines); if (newBool != _settings.RenderProjectionLines) { UndoEx.RecordForToolAction(_settings); _settings.RenderProjectionLines = newBool; SceneView.RepaintAll(); } }
private void RenderPivotPointConnectionLineColorSelectionField() { Color newColor = EditorGUILayout.ColorField(GetContentForPivotPointConnectionLineColorSelectionField(), _settings.PivotPointConnectionLineColor); if (newColor != _settings.PivotPointConnectionLineColor) { UndoEx.RecordForToolAction(_settings); _settings.PivotPointConnectionLineColor = newColor; SceneView.RepaintAll(); } }
public void RenderView() { bool newBool; newBool = EditorGUILayout.Foldout(_isVisible, "Selection Projection Settings"); if (newBool != _isVisible) { UndoEx.RecordForToolAction(this); _isVisible = newBool; } GUIContent content = new GUIContent(); if (_isVisible) { EditorGUILayoutEx.BeginVerticalBox(); Octave3DWorldBuilder.ActiveInstance.ShowGUIHint("The surface projection object must be a terrain object (with a terrain collider) or mesh (no colliders required). " + "If it is a mesh, it must also be a child of Octave3D."); content.text = "Surface object"; content.tooltip = "The object which acts as a projection surface. Must be a terrain (with a mesh collider attached) or mesh object. If it is a mesh object, it must be a child of Octave3D."; GameObject newSurface = EditorGUILayout.ObjectField(content, ProjectionSurface, typeof(GameObject), true) as GameObject; if (newSurface != _projectionSurface) { UndoEx.RecordForToolAction(this); ProjectionSurface = newSurface; } content.text = "Projection direction"; content.tooltip = "The direction in which the objects will be projected on the projection surface."; ProjectionDirection newProjectionDir = (ProjectionDirection)EditorGUILayout.EnumPopup(content, ProjectionDir); if (newProjectionDir != ProjectionDir) { UndoEx.RecordForToolAction(this); ProjectionDir = newProjectionDir; } content.text = "Project selection"; content.tooltip = "Projects the selected objects onto the projection surface (if one was specified)."; if (GUILayout.Button(content, GUILayout.Width(130.0f))) { if (ProjectionSurface == null) { Debug.LogWarning("Projection not possible. No projection surface was specified!"); } else { ObjectSelection.Get().ProjectSelectionOnProjectionSurface(); } } EditorGUILayoutEx.EndVerticalBox(); } }
public void HandleMouseButtonDownEvent(Event e) { if (_object2ObjectSnapSession.IsActive && AllShortcutCombos.Instance.EndSelectionObject2ObjectSnap.IsActive()) { e.DisableInSceneView(); _object2ObjectSnapSession.End(); return; } if (_selectionGridSnapSession.IsActive || _selectionGrabSession.IsActive || _object2ObjectSnapSession.IsActive || _objectVertexSnapSession.IsActive) { return; } if (AllShortcutCombos.Instance.SnapXZGridToCursorPickPointOnLeftClick_Selection.IsActive() && e.InvolvesLeftMouseButton()) { e.DisableInSceneView(); ObjectSnapping.Get().SnapXZGridToCursorPickPoint(e.clickCount == 2); return; } if (Mirror.IsInteractionSessionActive && e.InvolvesLeftMouseButton()) { e.DisableInSceneView(); Mirror.EndInteractionSession(); return; } if (e.InvolvesLeftMouseButton() && NumberOfSelectedObjects != 0 && !SelectionShape.IsVisible() && AllShortcutCombos.Instance.ReplacePrefabsForSelectedObjects_Scene.IsActive() && !Mirror.IsInteractionSessionActive) { e.DisableInSceneView(); UndoEx.RecordForToolAction(this); List <GameObject> newObjects = ObjectSelectionActions.ReplaceSelectedObjectsPrefabOnMouseClick(); if (newObjects.Count != 0) { AddGameObjectCollectionToSelection(newObjects); } return; } SelectionShape.HandleMouseButtonDownEvent(e); if (CanPerformClickSelectionUpdateOperation()) { var clickSelectionUpdateOperation = ObjectSelectionUpdateOperationFactory.Create(ObjectSelectionUpdateOperationType.Click); clickSelectionUpdateOperation.Perform(); SceneView.RepaintAll(); } }
private void RenderRemovePrefabAssociationButton() { if (GUILayout.Button(GetContentForRemovePrefabAssociationButton(), GUILayout.Width(EditorGUILayoutEx.PreferedActionButtonWidth))) { if (!ObjectPlacementPathTileConnectionSettingsChangeValidation.Validate(true)) { return; } UndoEx.RecordForToolAction(_settings); _settings.Prefab = null; } }
private void RenderSelectionToggleControlsForFilteredTags() { foreach (PrefabTag prefabTag in _filteredTags) { bool isCurrentlySelected = IsTagSelected(prefabTag); bool newBool = EditorGUILayout.ToggleLeft(GetContentForTagSelectionToggle(prefabTag.Name), isCurrentlySelected); if (isCurrentlySelected != newBool) { UndoEx.RecordForToolAction(ViewData); SetTagSelected(prefabTag, newBool); } } }
public T CreateScriptableObject <T>() where T : ScriptableObject { UndoEx.RecordForToolAction(this); T scriptableObject = ScriptableObject.CreateInstance <T>(); if (scriptableObject != null) { UndoEx.RegisterCreatedScriptableObject(scriptableObject); _scriptableObjects.Add(scriptableObject); } return(scriptableObject); }
public void SetHierarchyWorldScaleByPivotPoint(Vector3 scale, Vector3 pivotPoint) { if (IsAnyMouseSessionActive) { return; } UndoEx.RecordForToolAction(_transform); gameObject.SetHierarchyWorldScaleByPivotPoint(scale, pivotPoint); UndoEx.RecordForToolAction(_sourcePrefab.ActivationSettings); _sourcePrefab.ActivationSettings.WorldScale = _transform.lossyScale; }
public void MakeAllNoLongerGroup() { UndoEx.RecordForToolAction(this); var groupsToRemove = _objectGroups.GetAllEntities(); _objectGroups.RemoveAllEntities(); foreach (var group in groupsToRemove) { UndoEx.DestroyObjectImmediate(group); } PrefabManagementWindow.Get().Repaint(); }
public void SetHierarchyWorldRotationAndPreserveHierarchyCenter(Quaternion rotation) { if (IsAnyMouseSessionActive) { return; } UndoEx.RecordForToolAction(_transform); gameObject.SetHierarchyWorldRotationAndPreserveHierarchyCenter(rotation); UndoEx.RecordForToolAction(_sourcePrefab.ActivationSettings); _sourcePrefab.ActivationSettings.WorldRotation = _transform.rotation; }
private void Snap() { Vector3 snapVector = _snapPosition - _sourceVertex; GameObject root = Octave3DWorldBuilder.ActiveInstance.GetRoot(_sourceObject); if (root != null) { Transform parentTransform = root.transform; UndoEx.RecordForToolAction(parentTransform); parentTransform.position += snapVector; _sourceVertex += snapVector; } }
private void RenderSetCommonDownwardsExtrusionAmountButton() { if (GUILayout.Button(GetContentForSetCommonDownwardsExtrusionAmountButton(), GUILayout.Width(_setCommonTilePropertyButtonWidth))) { List <ObjectPlacementPathTileConnectionType> allTileConnectionTypes = ObjectPlacementPathTileConnectionTypes.GetAll(); foreach (ObjectPlacementPathTileConnectionType tileConnectionType in allTileConnectionTypes) { UndoEx.RecordForToolAction(_settings.GetSettingsForTileConnectionType(tileConnectionType)); _settings.GetSettingsForTileConnectionType(tileConnectionType).DownwardsExtrusionAmount = _settings.CommonDownwardsExtrusionAmount; } SceneView.RepaintAll(); } }
private void RenderXZGridRotationField() { XZGrid xzGrid = ObjectSnapping.Get().XZSnapGrid; Vector3 currentRotation = xzGrid.Rotation.eulerAngles; Vector3 newVector = EditorGUILayout.Vector3Field(GetContentForXZGridRotationField(), currentRotation); if (newVector != currentRotation) { UndoEx.RecordForToolAction(xzGrid); xzGrid.SetRotation(Quaternion.Euler(newVector)); SceneView.RepaintAll(); } }
public void UpdateForMouseMovement(Event e) { if (_isActive && _gameObject != null) { UndoEx.RecordForToolAction(_gameObjectTransform); // In order to scale the object, we will calculate a scale factor which we will use to scale the // object's original scale vector (i.e. the one which was established when the session was started). // This scale factor is calculated by constructing a vector which goes from the position of the // mouse cursor as established at the start of the session to the current cursor position. The abs value // of the X component of the resulting vector represents the scale factor (which of course will also be // scaled by the mouse sensitivity value) and the sign of the X component represents the sign of the scale. Vector2 currentCursorPos = MouseCursor.Instance.Position; Vector2 fromPosAtSessionStartToCurrentPos = currentCursorPos - _cursorPosAtSessionStart; float mouseSensitivityScale = CalculateMouseSensitivityScale(); float mouseSensitivity = _uniformScaleSettings.MouseSensitivity * mouseSensitivityScale; // Calculate the amount which needs to be added to the scale factor float addToScale = fromPosAtSessionStartToCurrentPos.x * mouseSensitivity; // Using snapping? if (_uniformScaleSettings.UseSnapping) { // Adjust the accumulated scale _accumulatedScale += addToScale; // Check if the accumulated scaled has reached its destination step value if (HasAccumulatedScaleReachedSnapStep(mouseSensitivityScale)) { float floateNumberOfSteps = Mathf.Abs(_accumulatedScale) / _uniformScaleSettings.SnapStep; int integerNumberOfSteps = (int)floateNumberOfSteps; float scaleFactor = (1.0f + integerNumberOfSteps * _uniformScaleSettings.SnapStep * Mathf.Sign(_accumulatedScale)); ScaleObject(scaleFactor); _accumulatedScale = 0.0f; } } else { // Note: We will set this to 0 whenever we reach this point because the user may be // toggling snapping on/off during the same session and the next time snaping // is activated we want to start with a clean slate. _accumulatedScale = 0.0f; float scaleFactor = 1.0f + addToScale; ScaleObject(scaleFactor); } } }
public void MakeNoLongerGroup(GameObject gameObject) { if (!ContainsObjectGroup(gameObject)) { return; } UndoEx.RecordForToolAction(this); var objectGroup = _objectGroups.GetEntityByPredicate(item => item.GroupObject == gameObject); _objectGroups.RemoveEntity(objectGroup); UndoEx.DestroyObjectImmediate(objectGroup); PrefabManagementWindow.Get().Repaint(); }
private void RenderMaxNumberOfCategoryFolderNamesToggle() { var content = new GUIContent(); content.text = "Max number of folders"; content.tooltip = "If \'Show folder names\' is checked, this controls the maximum number of folder names that will be shown."; int newInt = EditorGUILayout.IntField(content, ViewData.MaxNumberOfCategoryFolderNames); if (newInt != ViewData.MaxNumberOfCategoryFolderNames) { UndoEx.RecordForToolAction(ViewData); ViewData.MaxNumberOfCategoryFolderNames = newInt; } }
public void UpdateForMouseMovement(Event e) { if (_gameObject != null && _isActive) { UndoEx.RecordForToolAction(_gameObjectTransform); if (_rotatingAroundCustomAxis) { RotateObjectAroundCustomAxis(); } else { RotateObjectAroundAxis(); } } }
private void RenderUseTileConnectionsToggle() { bool newBool = EditorGUILayout.ToggleLeft(GetContentForUseTileConnectionsToggle(), _settings.UseTileConnections); if (newBool != _settings.UseTileConnections) { if (!ObjectPlacementPathTileConnectionSettingsChangeValidation.Validate(true)) { return; } UndoEx.RecordForToolAction(_settings); _settings.UseTileConnections = newBool; } }
public void Perform() { if (_dropData != null && _dropData.PrefabFoldersDropDataCollection.Count != 0) { if (_prefabFoldersDropSettings.CreatePrefabCategoriesFromDroppedFolders) { UndoEx.RecordForToolAction(PrefabCategoryDatabase.Get()); } DropPrefabFolders(); if (ShouldActivateLastPrefabCategoryAfterDrop()) { PrefabCategoryDatabase.Get().SetActivePrefabCategory(_lastCreatedCategory); } } }
private void CreateTagsForDroppedFolderIfNecessaryAndAssociate(PrefabFolderDropData prefabFolderDropData) { string lastFolderNameInFoderPath = prefabFolderDropData.FolderNameInPath; if (PrefabTagDatabase.Get().ContainsPrefabTag(lastFolderNameInFoderPath)) { PrefabActions.AssociatePrefabsWithTag(prefabFolderDropData.ValidPrefabs, lastFolderNameInFoderPath); } else { UndoEx.RecordForToolAction(PrefabTagDatabase.Get()); PrefabTag prefabTag = PrefabTagDatabase.Get().CreatePrefabTag(lastFolderNameInFoderPath); PrefabActions.AssociatePrefabsWithTag(prefabFolderDropData.ValidPrefabs, prefabTag); } }
protected override void PerformDrop() { if (_dropDestination == DropDestination.Element) { if (_destinationDecorPaintBrushElement == null) { return; } List <GameObject> validUnityPrefabsInvolvedInDropOperation = PrefabValidator.GetValidPrefabsFromEntityCollection(DragAndDrop.objectReferences, false); if (validUnityPrefabsInvolvedInDropOperation.Count != 0) { PerformDropUsingFirstPrefabInValidUnityPrefabCollection(validUnityPrefabsInvolvedInDropOperation); } } else { if (_destinationBrush == null) { return; } List <GameObject> validUnityPrefabs = PrefabValidator.GetValidPrefabsFromEntityCollection(DragAndDrop.objectReferences, false); if (validUnityPrefabs.Count != 0) { UndoEx.RecordForToolAction(_destinationBrush); foreach (GameObject unityPrefab in validUnityPrefabs) { DecorPaintObjectPlacementBrushElement newElement = _destinationBrush.CreateNewElement(); PrefabCategory categoryWhichContainsPrefab = PrefabCategoryDatabase.Get().GetPrefabCategoryWhichContainsPrefab(unityPrefab); if (categoryWhichContainsPrefab != null) { newElement.Prefab = categoryWhichContainsPrefab.GetPrefabByUnityPrefab(unityPrefab); } else { Prefab prefab = PrefabFactory.Create(unityPrefab); UndoEx.RecordForToolAction(_destinationBrush.DestinationCategoryForElementPrefabs); PrefabWithPrefabCategoryAssociationQueue.Instance.Enqueue(PrefabWithPrefabCategoryAssociationFactory.Create(prefab, _destinationBrush.DestinationCategoryForElementPrefabs)); newElement.Prefab = prefab; } } } } Octave3DWorldBuilder.ActiveInstance.RepaintAllEditorWindows(); }
public void RotateUsingKeyboardSettings(Vector3 customRotationAxis) { if (IsAnyMouseSessionActive) { return; } UndoEx.RecordForToolAction(_transform); ObjectKeyboardRotationSettings keyboardRotationSettings = ObjectPlacementGuideSettings.Get().KeyboardRotationSettings; gameObject.RotateHierarchyBoxAroundPoint(keyboardRotationSettings.CustomAxisRotationSettings.RotationAmountInDegrees, customRotationAxis, gameObject.GetHierarchyWorldOrientedBox().Center); UndoEx.RecordForToolAction(_sourcePrefab.ActivationSettings); _sourcePrefab.ActivationSettings.WorldRotation = _transform.rotation; }
private void RenderIgnoreObjectsWhenSnappingToggle() { var content = new GUIContent(); content.text = "Enable object surface grid"; content.tooltip = "If this is checked, you will be able to snap across the surfaces of other objects using a surface snap grid."; bool newBool = EditorGUILayout.ToggleLeft(content, _settings.EnableObjectSurfaceGrid); if (newBool != _settings.EnableObjectSurfaceGrid) { UndoEx.RecordForToolAction(_settings); _settings.EnableObjectSurfaceGrid = newBool; SceneView.RepaintAll(); } }
private void RenderPrefabDestinationFolderField() { EditorGUILayout.HelpBox("For the prefab destination folder, the full folder name is required. For example: Assets/Abandoned City/Props/Created Prefabs. You can also " + "drag and drop a folder onto the text field area in which case the folder name will automatically appear in the field. ", UnityEditor.MessageType.Info); string newString = EditorGUILayout.TextField(GetContentForPrefabDestinationFolderField(), _settings.DestinationFolder); if (newString != _settings.DestinationFolder) { UndoEx.RecordForToolAction(_settings); _settings.DestinationFolder = newString; } Rect textFieldRect = GUILayoutUtility.GetLastRect(); FolderToPrefabCreationFolderField.Get().Handle(Event.current, textFieldRect); }
private void AdjustBrushShapeSizeForMouseWheelScroll(Event e) { DecorPaintObjectPlacementBrush activeBrush = DecorPaintObjectPlacementBrushDatabase.Get().ActiveBrush; if (activeBrush != null) { BrushDecorPaintModeObjectPlacementSettings brushDecorPaintSettings = ObjectPlacementSettings.Get().DecorPaintObjectPlacementSettings.BrushDecorPaintModeSettings; int sizeAdjustAmount = (int)(-e.delta.y * brushDecorPaintSettings.ScrollWheelCircleRadiusAdjustmentSpeed); UndoEx.RecordForToolAction(activeBrush); activeBrush.Radius += sizeAdjustAmount; Octave3DWorldBuilder.ActiveInstance.Inspector.EditorWindow.Repaint(); SceneView.RepaintAll(); } }
private void RenderShowPrefabCategoryFolderNamesToggle() { var content = new GUIContent(); content.text = "Show folder names (where applicable)"; content.tooltip = "If this is checked, prefab categories which were created from folder drops will have their name adjusted " + "to include the names of the folders which appear in the source/dropped folder path. Folders appear from " + "left to right starting from the bottom most folder in the hierarchy."; bool newBool = EditorGUILayout.ToggleLeft(content, ViewData.ShowPrefabCategoryFolderNames); if (newBool != ViewData.ShowPrefabCategoryFolderNames) { UndoEx.RecordForToolAction(ViewData); ViewData.ShowPrefabCategoryFolderNames = newBool; } }
private void RenderActiveConfigurationSelectionPopup() { ObjectPlacementPathTileConnectionConfigurationDatabase configurationDatabase = ObjectPlacementPathTileConnectionConfigurationDatabase.Get(); string newString = EditorGUILayoutEx.Popup(GetContentForActiveConfigurationSelectionPopup(), configurationDatabase.ActiveConfiguration.Name, configurationDatabase.GetAllConfigurationNames()); if (newString != configurationDatabase.ActiveConfiguration.Name) { ObjectPlacementPathTileConnectionConfiguration newActiveConfiguration = configurationDatabase.GetConfigurationByName(newString); if (newActiveConfiguration != null) { UndoEx.RecordForToolAction(configurationDatabase); PathObjectPlacement.Get().PathSettings.TileConnectionSettings.RecordAllTileConnectionTypeSettingsForUndo(); configurationDatabase.SetActiveConfiguration(newActiveConfiguration); newActiveConfiguration.ApplyConfigurationDataToSettings(PathObjectPlacement.Get().PathSettings.TileConnectionSettings); } } }
public static void LoadConfig(string fileName) { if (string.IsNullOrEmpty(fileName)) { return; } XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(fileName); UndoEx.RecordForToolAction(PrefabTagDatabase.Get()); PrefabTagDatabase.Get().RemoveAndDestroyAllPrefabTags(); XmlNodeList prefabTagsDatabaseNodes = xmlDoc.SelectNodes("//" + PrefabConfigXMLInfo.PrefabTagDatabaseNode); if (prefabTagsDatabaseNodes.Count != 0) { ReadAllPrefabTags(prefabTagsDatabaseNodes[0]); } UndoEx.RecordForToolAction(PrefabCategoryDatabase.Get()); PrefabCategoryDatabase.Get().RemoveAndDestroyAllPrefabCategories(true); XmlNodeList prefabCategoryDatabaseNodes = xmlDoc.SelectNodes("//" + PrefabConfigXMLInfo.PrefabCategoryDatabaseNode); if (prefabCategoryDatabaseNodes.Count != 0) { ReadAllPrefabCategories(prefabCategoryDatabaseNodes[0]); } PrefabPreviewTextureCache.Get().GeneratePreviewForAllPrefabCategories(true); PrefabCategory firstNonEmptyCategory = PrefabCategoryDatabase.Get().GetFirstNonEmptyCategory(); if (firstNonEmptyCategory != null) { PrefabCategoryDatabase.Get().SetActivePrefabCategory(firstNonEmptyCategory); } XmlNodeList prefabScrollViewLookAndFeelNodes = xmlDoc.SelectNodes("//" + PrefabConfigXMLInfo.PrefabScrollViewLookAndFeelNode); if (prefabScrollViewLookAndFeelNodes.Count != 0) { ReadPrefabScrollViewLookAndFeel(prefabScrollViewLookAndFeelNodes[0]); } }
private void RenderInheritPrefabButton() { if (GUILayout.Button(GetContentForInheritPrefabButton(), GUILayout.Width(_setCommonTilePropertyButtonWidth))) { if (!ObjectPlacementPathTileConnectionSettingsChangeValidation.Validate(true)) { return; } Prefab prefabToInherit = _settings.GetSettingsForTileConnectionType(_settings.PrefabInheritTileConnectionType).Prefab; List <ObjectPlacementPathTileConnectionType> allTileConnectionTypes = ObjectPlacementPathTileConnectionTypes.GetAll(); foreach (ObjectPlacementPathTileConnectionType tileConnectionType in allTileConnectionTypes) { UndoEx.RecordForToolAction(_settings.GetSettingsForTileConnectionType(tileConnectionType)); _settings.GetSettingsForTileConnectionType(tileConnectionType).Prefab = prefabToInherit; } } }
private void RenderMinMaxSlopeSlider() { float minSlope = _settings.MinSlopeInDegrees; float maxSlope = _settings.MaxSlopeInDegrees; EditorGUILayoutEx.MinMaxSliderWithFloatFields(GetContentForMinMaxSlopeSlider(), ref minSlope, ref maxSlope, DecorPaintSlopeSettings.MinSlopeValueInDegrees, DecorPaintSlopeSettings.MaxSlopeValueInDegrees); if (minSlope != _settings.MinSlopeInDegrees) { UndoEx.RecordForToolAction(_settings); _settings.MinSlopeInDegrees = minSlope; } if (maxSlope != _settings.MaxSlopeInDegrees) { UndoEx.RecordForToolAction(_settings); _settings.MaxSlopeInDegrees = maxSlope; } }