/// <summary> /// This function is called to change the type of work gizmo. This is /// used in the 'Update' function in response to the user pressing the /// W,E,R,T keys to switch between different gizmo types. /// </summary> private void SetWorkGizmoId(GizmoId gizmoId) { // If the specified gizmo id is the same as the current id, there is nothing left to do if (gizmoId == _workGizmoId) { return; } // Start with a clean slate and disable all gizmos _objectMoveGizmo.Gizmo.SetEnabled(false); _objectRotationGizmo.Gizmo.SetEnabled(false); _objectScaleGizmo.Gizmo.SetEnabled(false); _objectUniversalGizmo.Gizmo.SetEnabled(false); // At this point all gizmos are disabled. Now we need to check the gizmo id // and adjust the '_workGizmo' variable. _workGizmoId = gizmoId; if (gizmoId == GizmoId.Move) { _workGizmo = _objectMoveGizmo; } else if (gizmoId == GizmoId.Rotate) { _workGizmo = _objectRotationGizmo; } else if (gizmoId == GizmoId.Scale) { _workGizmo = _objectScaleGizmo; } else if (gizmoId == GizmoId.Universal) { _workGizmo = _objectUniversalGizmo; } // If we have any selected objects, we need to make sure the work gizmo is enabled if (_selectedObjects.Count != 0) { // Make sure the work gizmo is enabled. There is no need to check if the gizmo is already // enabled. The 'SetEnabled' call will simply be ignored if that is the case. _workGizmo.Gizmo.SetEnabled(true); // The last step we need to perform is to make sure that the work gizmo is positioned // and rotated correctly. This is because the gizmos (as will become more clear in // later tutorials) have 2 properties such as transform space and transform pivot and // when the selected objects change, these 2 properties will dictate how the gizmo should // be positioned and rotated. In order to ensure that the correct position and rotation // are used, we need to call 'RefreshPositionAndRotation'. _workGizmo.RefreshPositionAndRotation(); } }
/// <summary> /// Called from the 'Update' function whenever the '_selectedObjects' list /// changes. It is responsible for updating the gizmos accordingly. /// </summary> private void OnSelectionChanged() { // If we have any selected objects, we need to make sure the work gizmo is enabled if (_selectedObjects.Count != 0) { // Make sure the work gizmo is enabled. There is no need to check if the gizmo is already // enabled. The 'SetEnabled' call will simply be ignored if that is the case. _workGizmo.Gizmo.SetEnabled(true); // When working with transform spaces, the gizmos need to know about the pivot object. This piece // of information is necessary when the transform space is set to local because in that case the // gizmo will have its rotation synchronized with the target objects rotation. But because there // is more than one target object, we need to tell the gizmo which object to use. This is the role // if the pivot object in this case. _workGizmo.SetTargetPivotObject(_selectedObjects[_selectedObjects.Count - 1]); // The last step we need to perform is to make sure that the work gizmo is positioned // and rotated correctly. This is because the gizmos (as will become more clear in // later tutorials) have 2 properties such as transform space and transform pivot and // when the selected objects change, these 2 properties will dictate how the gizmo should // be positioned and rotated. In order to ensure that the correct position and rotation // are used, we need to call 'RefreshPositionAndRotation'. _workGizmo.RefreshPositionAndRotation(); } else { // The target object is null. In this case, we don't want any gizmos to be visible // in the scene, so we disable all of them. _objectMoveGizmo.Gizmo.SetEnabled(false); _objectRotationGizmo.Gizmo.SetEnabled(false); _objectScaleGizmo.Gizmo.SetEnabled(false); _objectUniversalGizmo.Gizmo.SetEnabled(false); } }
/// <summary> /// Called from the 'Update' function whenever the '_selectedObjects' list /// changes. It is responsible for updating the gizmos. /// </summary> private void OnSelectionChanged() { // If we have any selected objects, we need to make sure the work gizmo is enabled if (_selectedObjects.Count != 0) { SetHighlights(_selectedObjects); // Make sure the work gizmo is enabled. There is no need to check if the gizmo is already // enabled. The 'SetEnabled' call will simply be ignored if that is the case. _workGizmo.Gizmo.SetEnabled(true); // Last object that is selected will be used as the pivot object _workGizmo.SetTargetPivotObject(_selectedObjects[_selectedObjects.Count - 1]); // In order to ensure that the correct position and rotation // are used, we need to call 'RefreshPositionAndRotation'. _workGizmo.RefreshPositionAndRotation(); } else { // The target object is null. In this case, we don't want any gizmos to be visible // in the scene, so we disable all of them. _objectMoveGizmo.Gizmo.SetEnabled(false); _objectRotationGizmo.Gizmo.SetEnabled(false); _objectScaleGizmo.Gizmo.SetEnabled(false); _objectUniversalGizmo.Gizmo.SetEnabled(false); } }
void SetWorkGizmoId(GizmoId gizmoId) { if (gizmoId == _workGizmoId) { return; } _objectMoveGizmo.Gizmo.SetEnabled(false); _objectRotateionGizmo.Gizmo.SetEnabled(false); _objectScaleGizmo.Gizmo.SetEnabled(false); _objectUniversalGizmo.Gizmo.SetEnabled(false); _workGizmoId = gizmoId; if (gizmoId == GizmoId.move) { _workGizmo = _objectMoveGizmo; } else if (gizmoId == GizmoId.Rotate) { _workGizmo = _objectRotateionGizmo; } else if (gizmoId == GizmoId.Scale) { _workGizmo = _objectScaleGizmo; } else if (gizmoId == GizmoId.Universal) { _workGizmo = _objectUniversalGizmo; } if (_selectObjects.Count != 0) { _workGizmo.Gizmo.SetEnabled(true); _workGizmo.RefreshPositionAndRotation(); } }