private void OnSceneGUI() { var dungeon = (RuntimeDungeon)target; if (!dungeon.Generator.RestrictDungeonToBounds) { return; } placementBoundsHandle.center = dungeon.Generator.TilePlacementBounds.center; placementBoundsHandle.size = dungeon.Generator.TilePlacementBounds.size; EditorGUI.BeginChangeCheck(); using (new Handles.DrawingScope(dungeon.transform.localToWorldMatrix)) { placementBoundsHandle.DrawHandle(); } if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(dungeon, "Inspector"); dungeon.Generator.TilePlacementBounds = new Bounds(placementBoundsHandle.center, placementBoundsHandle.size); Undo.FlushUndoRecordObjects(); } }
private void OnSceneGUI() { // Make the handle's colour green. Handles.color = Color.green; // Store the default matrix. Matrix4x4 baseMatrix = Handles.matrix; // Make the handles use the object(s)'s matrix. Matrix4x4 rotationMatrix = spawner.transform.localToWorldMatrix; Handles.matrix = rotationMatrix; // Setup the box bounds handle with the spawner's values. handle.center = spawner.centre; handle.size = spawner.size; // Begin listening for changes to the handle, then draw it. EditorGUI.BeginChangeCheck(); handle.DrawHandle(); // Check if any changes were detected. if (EditorGUI.EndChangeCheck()) { // Reset the spawner values to the new handle values. spawner.size = handle.size; spawner.centre = handle.center; } // Reset the hande's matrix back to default. Handles.matrix = baseMatrix; }
// Enables the Editor to handle an event in the scene view private void OnSceneGUI() //Like Update() { //Make the handles colour green Handles.color = Color.green; //Store default Matrix Matrix4x4 baseMatrix = Handles.matrix; //Make gizmos use objects matrix Matrix4x4 rotationMatrix = spawner.transform.localToWorldMatrix; Handles.matrix = rotationMatrix; //Set up box bounds handle with spawner values center and size handle.center = spawner.center; handle.size = spawner.size; //Begin listening for changes to the handle, then draw it EditorGUI.BeginChangeCheck(); handle.DrawHandle(); //Check if any changes have been made if (EditorGUI.EndChangeCheck()) { //Take the data from handle and put back in spawner (reset the spawner values to handle values) spawner.size = handle.size; spawner.center = handle.center; } //Reset Handles.matrix = baseMatrix; }
private void OnSceneGUI() { LightprobeManager component = (LightprobeManager)target; Handles.matrix = component.transform.localToWorldMatrix; // copy the target object's data to the handle m_BoundsHandle.center = component.bounds.center; m_BoundsHandle.size = component.bounds.size; // draw the handle EditorGUI.BeginChangeCheck(); m_BoundsHandle.DrawHandle(); if (EditorGUI.EndChangeCheck()) { // record the target object before setting new values so changes can be undone/redone Undo.RecordObject(component, "Change Bounds"); // copy the handle's updated data back to the target object Bounds newBounds = new Bounds(); newBounds.center = m_BoundsHandle.center; newBounds.size = m_BoundsHandle.size; component.bounds = newBounds; } }
void DoBoxEditing() { // Drawing of the probe box is done from GizmoDrawers.cpp, // here we only want to show the box editing handles when needed. ReflectionProbe p = (ReflectionProbe)target; using (new Handles.DrawingScope(GetLocalSpace(p))) { m_BoundsHandle.center = p.center; m_BoundsHandle.size = p.size; EditorGUI.BeginChangeCheck(); m_BoundsHandle.DrawHandle(); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(p, "Modified Reflection Probe AABB"); Vector3 center = m_BoundsHandle.center; Vector3 size = m_BoundsHandle.size; ValidateAABB(ref center, ref size); p.center = center; p.size = size; EditorUtility.SetDirty(target); } } }
private void OnSceneGUI() { if (!editingCollider) { return; } var navSurface = (NavMeshSurface)target; var color = navSurface.enabled ? s_HandleColor : s_HandleColorDisabled; var localToWorld = Matrix4x4.TRS(navSurface.transform.position, navSurface.transform.rotation, Vector3.one); using (new Handles.DrawingScope(color, localToWorld)) { m_BoundsHandle.center = navSurface.center; m_BoundsHandle.size = navSurface.size; EditorGUI.BeginChangeCheck(); m_BoundsHandle.DrawHandle(); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(navSurface, "Modified NavMesh Surface"); Vector3 center = m_BoundsHandle.center; Vector3 size = m_BoundsHandle.size; navSurface.center = center; navSurface.size = size; EditorUtility.SetDirty(target); } } }
void OnSceneGUI() { Damager damager = (Damager)target; if (!damager.enabled) { return; } Matrix4x4 handleMatrix = damager.transform.localToWorldMatrix; handleMatrix.SetRow(0, Vector4.Scale(handleMatrix.GetRow(0), new Vector4(1f, 1f, 0f, 1f))); handleMatrix.SetRow(1, Vector4.Scale(handleMatrix.GetRow(1), new Vector4(1f, 1f, 0f, 1f))); handleMatrix.SetRow(2, new Vector4(0f, 0f, 1f, damager.transform.position.z)); using (new Handles.DrawingScope(handleMatrix)) { s_BoxBoundsHandle.center = damager.offset; s_BoxBoundsHandle.size = damager.size; s_BoxBoundsHandle.SetColor(s_EnabledColor); EditorGUI.BeginChangeCheck(); s_BoxBoundsHandle.DrawHandle(); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(damager, "Modify Damager"); damager.size = s_BoxBoundsHandle.size; damager.offset = s_BoxBoundsHandle.center; } } }
private void OnSceneGUI() { if (!overrideAutomaticTileBounds.boolValue) { return; } var tile = (Tile)target; overrideBoundsHandle.center = tileBoundsOverride.boundsValue.center; overrideBoundsHandle.size = tileBoundsOverride.boundsValue.size; EditorGUI.BeginChangeCheck(); using (new Handles.DrawingScope(tile.transform.localToWorldMatrix)) { overrideBoundsHandle.DrawHandle(); } if (EditorGUI.EndChangeCheck()) { tileBoundsOverride.boundsValue = new Bounds(overrideBoundsHandle.center, overrideBoundsHandle.size); serializedObject.ApplyModifiedProperties(); } }
private void DrawBoxEditor(BoxSurface surface) { Quaternion rot = surface.Rotation; Vector3 size = surface.Size; Vector3 snapP = surface.transform.position; boxHandle.size = size; float widthPos = Mathf.Lerp(-size.x * 0.5f, size.x * 0.5f, surface.WidthOffset); boxHandle.center = new Vector3(widthPos, 0f, size.z * 0.5f); Matrix4x4 handleMatrix = Matrix4x4.TRS( snapP, rot, Vector3.one ); using (new Handles.DrawingScope(handleMatrix)) { EditorGUI.BeginChangeCheck(); boxHandle.DrawHandle(); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(surface, "Change Box Properties"); surface.Size = boxHandle.size; float width = boxHandle.size.x; surface.WidthOffset = width != 0f ? (boxHandle.center.x + width * 0.5f) / width : 0f; } } }
protected virtual void OnSceneGUI() { var vol = (BakeryVolume)target; boundsHandle.center = vol.transform.position; boundsHandle.size = vol.bounds.size; EditorGUI.BeginChangeCheck(); boundsHandle.DrawHandle(); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(vol, "Change Bounds"); Bounds newBounds = new Bounds(); newBounds.center = boundsHandle.center; newBounds.size = boundsHandle.size; vol.bounds = newBounds; vol.transform.position = boundsHandle.center; } else if ((vol.bounds.center - boundsHandle.center).sqrMagnitude > 0.0001f) { Bounds newBounds = new Bounds(); newBounds.center = boundsHandle.center; newBounds.size = boundsHandle.size; vol.bounds = newBounds; } }
protected virtual void OnSceneGUI() { if (!EGWindow.debugDrawBounds) { return; } EntityGraphProjector projector = (EntityGraphProjector)target; boundsHandles.center = projector.Bounds.center; boundsHandles.size = projector.Bounds.size; EditorGUI.BeginChangeCheck(); boundsHandles.DrawHandle(); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(projector, "Change Bounds"); projector.Bounds = new Bounds { center = boundsHandles.center, size = boundsHandles.size }; projector.transform.position = boundsHandles.center; } }
void OnSceneGUI() { if (!editingCollider || script.colorMap == null) { return; } Bounds bounds = script.colorMap.bounds; Color color = script.enabled ? s_HandleColor : s_HandleColorDisabled; using (new Handles.DrawingScope(color, Matrix4x4.identity)) { m_BoundsHandle.center = bounds.center; m_BoundsHandle.size = bounds.size; EditorGUI.BeginChangeCheck(); m_BoundsHandle.DrawHandle(); //m_BoundsHandle.axes = PrimitiveBoundsHandle.Axes.X | PrimitiveBoundsHandle.Axes.Z; if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(script.colorMap, "Modified Grass color map bounds"); Vector3 center = m_BoundsHandle.center; Vector3 size = m_BoundsHandle.size; script.colorMap.bounds.center = center; script.colorMap.bounds.size = size; EditorUtility.SetDirty(target); } } }
private void OnSceneGUI() { MLPVolume mlpVolume = (MLPVolume)target; EventType currentEvent = Event.current.type; if (currentEvent == EventType.MouseUp) { mlpVolume.parentRootComponent.changed = true; } boxBoundsHandle.axes = PrimitiveBoundsHandle.Axes.X | PrimitiveBoundsHandle.Axes.Y | PrimitiveBoundsHandle.Axes.Z; boxBoundsHandle.wireframeColor = Color.yellow; boxBoundsHandle.center = mlpVolume.transform.position; boxBoundsHandle.size = mlpVolume.transform.localScale; //Handles.matrix = mlpVolume.transform.localToWorldMatrix; EditorGUI.BeginChangeCheck(); boxBoundsHandle.DrawHandle(); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(mlpVolume, "MLP Change Bounds"); mlpVolume.transform.position = boxBoundsHandle.center; mlpVolume.transform.localScale = boxBoundsHandle.size; } }
public void OnSceneGUI() { _bounds = (CameraBounds2D)target; Matrix4x4 handleMatrix = _bounds.transform.localToWorldMatrix; handleMatrix.SetRow(0, Vector4.Scale(handleMatrix.GetRow(0), new Vector4(1f, 1f, 0f, 1f))); handleMatrix.SetRow(1, Vector4.Scale(handleMatrix.GetRow(1), new Vector4(1f, 1f, 0f, 1f))); handleMatrix.SetRow(2, new Vector4(0f, 0f, 1f, _bounds.transform.position.z)); using (new Handles.DrawingScope(handleMatrix)) { m_BoundsHandle.center = _bounds.offset; m_BoundsHandle.size = _bounds.scaleBound; m_BoundsHandle.SetColor(Color.white); EditorGUI.BeginChangeCheck(); m_BoundsHandle.DrawHandle(); Rect rect = new Rect(m_BoundsHandle.center.x - (m_BoundsHandle.size.x / 2), m_BoundsHandle.center.y - (m_BoundsHandle.size.y / 2), m_BoundsHandle.size.x, m_BoundsHandle.size.y); Handles.DrawSolidRectangleWithOutline(rect, new Color(1, 1, 1, 0.1f), Color.yellow); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(_bounds, string.Format("Modify {0}", ObjectNames.NicifyVariableName(_bounds.GetType().Name))); // test for size change after using property setter in case input data was sanitized Vector2 oldSize = _bounds.scaleBound; _bounds.scaleBound = m_BoundsHandle.size; // because projection of offset is a lossy operation, only do it if the size has actually changed // this check prevents drifting while dragging handle when size is zero (case 863949) if (_bounds.scaleBound != oldSize) { _bounds.offset = m_BoundsHandle.center; } } } }
public void OnSceneGUI() { SkinnedMeshRenderer renderer = (SkinnedMeshRenderer)target; if (renderer.updateWhenOffscreen) { Bounds bounds = renderer.bounds; Vector3 center = bounds.center; Vector3 size = bounds.size; Handles.DrawWireCube(center, size); } else { using (new Handles.DrawingScope(renderer.actualRootBone.localToWorldMatrix)) { Bounds bounds = renderer.localBounds; m_BoundsHandle.center = bounds.center; m_BoundsHandle.size = bounds.size; // only display interactive handles if edit mode is active m_BoundsHandle.handleColor = EditMode.editMode == EditMode.SceneViewEditMode.Collider && EditMode.IsOwner(this) ? m_BoundsHandle.wireframeColor : Color.clear; EditorGUI.BeginChangeCheck(); m_BoundsHandle.DrawHandle(); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(renderer, "Resize Bounds"); renderer.localBounds = new Bounds(m_BoundsHandle.center, m_BoundsHandle.size); } } } }
void OnSceneGUI() { if (!editingCollider) { return; } var bounds = script.colorMap.bounds; var color = script.enabled ? s_HandleColor : s_HandleColorDisabled; var localToWorld = Matrix4x4.TRS(script.transform.position, script.transform.rotation, Vector3.one); using (new Handles.DrawingScope(color, localToWorld)) { m_BoundsHandle.center = bounds.center; m_BoundsHandle.size = bounds.size; EditorGUI.BeginChangeCheck(); m_BoundsHandle.DrawHandle(); //m_BoundsHandle.axes = PrimitiveBoundsHandle.Axes.X | PrimitiveBoundsHandle.Axes.Z; if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(script.colorMap, "Modified Grass color map bounds"); Vector3 center = m_BoundsHandle.center; Vector3 size = m_BoundsHandle.size; script.colorMap.bounds.center = center; script.colorMap.bounds.size = size; EditorUtility.SetDirty(target); } } }
protected virtual void OnSceneGUI() { VolumeLight volumeLight = (VolumeLight)target; volumeBoundsHandle.handleColor = Color.yellow; volumeBoundsHandle.wireframeColor = Color.yellow; volumeBoundsHandle.center = Vector3.zero; volumeBoundsHandle.size = volumeLight.extents * 2f; Matrix4x4 tmpMat = Handles.matrix; //Handles.matrix = Matrix4x4.TRS(volumeLight.transform.position, volumeLight.transform.rotation, Vector3.one); Handles.matrix = volumeLight.transform.localToWorldMatrix; EditorGUI.BeginChangeCheck(); volumeBoundsHandle.DrawHandle(); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(volumeLight, "Change Volume Light Bounds"); volumeLight.extents = volumeBoundsHandle.size * 0.5f; } EditorGUI.BeginChangeCheck(); Vector3 lightOrigin = Handles.DoPositionHandle(volumeLight.lightOrigin, Quaternion.identity); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(volumeLight, "Move Volume Light Origin"); volumeLight.lightOrigin = lightOrigin; } Handles.matrix = tmpMat; }
private void OnSceneGUI() { var spriteSkin = target as SpriteSkin; if (!spriteSkin.isValid) { return; } var rootBone = spriteSkin.rootBone; using (new Handles.DrawingScope(rootBone.localToWorldMatrix)) { var bounds = spriteSkin.bounds; m_BoundsHandle.center = bounds.center; m_BoundsHandle.size = bounds.size; EditorGUI.BeginChangeCheck(); m_BoundsHandle.DrawHandle(); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(spriteSkin, "Resize Bounds"); spriteSkin.bounds = new Bounds(m_BoundsHandle.center, m_BoundsHandle.size); } } }
public override void SceneHandle(ObjectInspector inspector, FieldInspector fieldInspector) { if (fieldInspector.Field.FieldType == typeof(Bounds)) { Bounds value = (Bounds)fieldInspector.Field.GetValue(inspector.target); BoundsHandle.center = value.center; BoundsHandle.size = value.size; using (new Handles.DrawingScope(fieldInspector.UseColor)) { EditorGUI.BeginChangeCheck(); BoundsHandle.DrawHandle(); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(inspector.target, "Bounds Handler"); value.center = BoundsHandle.center; value.size = BoundsHandle.size; fieldInspector.Field.SetValue(inspector.target, value); inspector.HasChanged(); } if (BAttribute.Display != null) { Handles.Label(BoundsHandle.center, BAttribute.Display); } } } }
protected virtual void OnSceneGUI() { // keep TextureCreator selected HandleUtility.AddDefaultControl(GUIUtility.GetControlID(FocusType.Passive)); // return if busy if (hudTarget._isBusy) { return; } // update bounds center with position handle EditorGUI.BeginChangeCheck(); Vector3 newCenter = Handles.PositionHandle(hudTarget.MapBounds.center, Quaternion.identity); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(hudTarget, "Move HNS MiniMap Bounds"); hudTarget.MapBounds.center = newCenter; } // update bounds with box handles EditorGUI.BeginChangeCheck(); boxBoundsHandle.center = hudTarget.MapBounds.center; boxBoundsHandle.size = hudTarget.MapBounds.size; boxBoundsHandle.DrawHandle(); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(hudTarget, "Change HNS MiniMap Bounds"); hudTarget.MapBounds = new Bounds(boxBoundsHandle.center, boxBoundsHandle.size); } }
void OnSceneGUI() { if (!editingCollider) { return; } var vol = (NavMeshModifierVolume)target; var color = vol.enabled ? s_HandleColor : s_HandleColorDisabled; using (new Handles.DrawingScope(color, vol.transform.localToWorldMatrix)) { m_BoundsHandle.center = vol.center; m_BoundsHandle.size = vol.size; EditorGUI.BeginChangeCheck(); m_BoundsHandle.DrawHandle(); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(vol, "Modified NavMesh Modifier Volume"); Vector3 center = m_BoundsHandle.center; Vector3 size = m_BoundsHandle.size; vol.center = center; vol.size = size; EditorUtility.SetDirty(target); } } }
void OnSceneGUI() { var worldStamp = target as WorldStamp; if (!_editingMask) { var rotatedMatrix = Handles.matrix * Matrix4x4.TRS(worldStamp.transform.position, worldStamp.transform.rotation, worldStamp.transform.lossyScale); _boxBoundsHandle.center = Vector3.up * (worldStamp.Size.y / 2); _boxBoundsHandle.size = worldStamp.ExplicitSize; using (new Handles.DrawingScope(rotatedMatrix)) { _boxBoundsHandle.DrawHandle(); } if (worldStamp.Size != _boxBoundsHandle.size) { //var scaled = _boxBoundsHandle.size; //scaled.Scale(worldStamp.transform.lossyScale.Inverse()); worldStamp.ExplicitSize = _boxBoundsHandle.size; SceneView.RepaintAll(); } if (_painter != null) { _painter.Destroy(); _painter = null; } return; } if (_painter == null) { _painter = new Common.Painter.Painter(worldStamp.Mask, worldStamp.Data.GridManager); _painter.Ramp = new Gradient() { colorKeys = new[] { new GradientColorKey(Color.red, 0), new GradientColorKey(Color.black, 0.001f), new GradientColorKey(Color.black, 1), }, alphaKeys = new[] { new GradientAlphaKey(1, 0), new GradientAlphaKey(0, 1), } }; } _painter.Canvas = worldStamp.Mask; _painter.MaxValue = 1; _painter.MinValue = 0; _painter.Rect = new Rect(0, 0, worldStamp.Data.Size.x, worldStamp.Data.Size.z); _painter.GridManager = worldStamp.Data.GridManager; _painter.TRS = Matrix4x4.TRS(worldStamp.transform.position - worldStamp.transform.rotation * worldStamp.Size.xz().x0z() / 2, worldStamp.transform.rotation, new Vector3( worldStamp.transform.lossyScale.x * (worldStamp.Size.x / worldStamp.Data.Size.x), worldStamp.transform.lossyScale.y * (worldStamp.Size.y / worldStamp.Data.Size.y), worldStamp.transform.lossyScale.z * (worldStamp.Size.z / worldStamp.Data.Size.z)) ); _painter.PaintingEnabled = true; _painter.OnSceneGUI(); }
void OnSceneGUI() { var dat = target as GameBounds2D; if (dat == null) { return; } using (new Handles.DrawingScope(dat.editRectColor)) { mBoxHandle.axes = PrimitiveBoundsHandle.Axes.X | PrimitiveBoundsHandle.Axes.Y; Bounds b = new Bounds(dat.rect.center, dat.rect.size); mBoxHandle.center = new Vector3(b.center.x, b.center.y, 0f); mBoxHandle.size = new Vector3(b.size.x, b.size.y, 0f); EditorGUI.BeginChangeCheck(); mBoxHandle.DrawHandle(); if (EditorGUI.EndChangeCheck()) { Vector2 min = mBoxHandle.center - mBoxHandle.size * 0.5f; float _minX = Mathf.Round(min.x / dat.editRectSteps.x); float _minY = Mathf.Round(min.y / dat.editRectSteps.y); min.x = _minX * dat.editRectSteps.x; min.y = _minY * dat.editRectSteps.y; Vector2 max = mBoxHandle.center + mBoxHandle.size * 0.5f; float _maxX = Mathf.Round(max.x / dat.editRectSteps.x); float _maxY = Mathf.Round(max.y / dat.editRectSteps.y); max.x = _maxX * dat.editRectSteps.x; max.y = _maxY * dat.editRectSteps.y; b.center = Vector2.Lerp(min, max, 0.5f); b.size = max - min; Undo.RecordObject(dat, "Change GameBounds2D"); dat.rect = new Rect(b.min, b.size); if (dat.editSyncBoxCollider) { BoxCollider2D boxColl = dat.GetComponent <BoxCollider2D>(); if (boxColl) { Undo.RecordObject(boxColl, "Change GameBounds2D"); boxColl.offset = dat.transform.worldToLocalMatrix.MultiplyPoint3x4(dat.rect.center); boxColl.size = dat.rect.size; } } } } }
public void OnSceneGUI() { if (edit) { a = (target as AudioRoom); Handles.color = Color.blue; a.pos = b.center - a.transform.position; a.size = b.size / 2; b.DrawHandle(); } }
private void DrawInnerBoundsHandle(BoxMask boxMask) { boxHandle.handleColor = DeformEditorSettings.SolidHandleColor; boxHandle.wireframeColor = DeformEditorSettings.LightHandleColor; boxHandle.center = boxMask.InnerBounds.center; boxHandle.size = boxMask.InnerBounds.size; using (new Handles.DrawingScope(Matrix4x4.TRS(boxMask.Axis.position, boxMask.Axis.rotation, boxMask.Axis.lossyScale))) { using (var check = new EditorGUI.ChangeCheckScope()) { boxHandle.DrawHandle(); if (check.changed) { Undo.RecordObject(boxMask, "Changed Size"); boxMask.InnerBounds = new Bounds(boxHandle.center, boxHandle.size); boxMask.OuterBounds.Encapsulate(boxMask.InnerBounds); } } } }
protected virtual void OnSceneGUI() { if (!editingCollider) { return; } BoxCollider2D collider = (BoxCollider2D)target; if (Mathf.Approximately(collider.transform.lossyScale.sqrMagnitude, 0f)) { return; } // collider matrix is 2d projection of transform's rotation onto x/y plane about transform's origin Matrix4x4 handleMatrix = collider.transform.localToWorldMatrix; handleMatrix.SetRow(0, Vector4.Scale(handleMatrix.GetRow(0), new Vector4(1f, 1f, 0f, 1f))); handleMatrix.SetRow(1, Vector4.Scale(handleMatrix.GetRow(1), new Vector4(1f, 1f, 0f, 1f))); handleMatrix.SetRow(2, new Vector4(0f, 0f, 1f, collider.transform.position.z)); if (collider.usedByComposite && collider.composite != null) { // composite offset is rotated by composite's transformation matrix and projected back onto 2D plane var compositeOffset = collider.composite.transform.rotation * collider.composite.offset; compositeOffset.z = 0f; handleMatrix = Matrix4x4.TRS(compositeOffset, Quaternion.identity, Vector3.one) * handleMatrix; } using (new Handles.DrawingScope(handleMatrix)) { m_BoundsHandle.center = collider.offset; m_BoundsHandle.size = collider.size; m_BoundsHandle.SetColor(collider.enabled ? Handles.s_ColliderHandleColor : Handles.s_ColliderHandleColorDisabled); EditorGUI.BeginChangeCheck(); m_BoundsHandle.DrawHandle(); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(collider, string.Format("Modify {0}", ObjectNames.NicifyVariableName(target.GetType().Name))); // test for size change after using property setter in case input data was sanitized Vector2 oldSize = collider.size; collider.size = m_BoundsHandle.size; // because projection of offset is a lossy operation, only do it if the size has actually changed // this check prevents drifting while dragging handle when size is zero (case 863949) if (collider.size != oldSize) { collider.offset = m_BoundsHandle.center; } } } }
void DrawBounds() { Handles.color = new Color(1, .5f, 0, 1); boundsHandle.center = (target as LocationTemplate).transform.position; boundsHandle.size = sizeProp.vector3Value; EditorGUI.BeginChangeCheck(); boundsHandle.DrawHandle(); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(target, "Change Bounds"); sizeProp.vector3Value = boundsHandle.size; } }
public static void BoxBoundsHandle(Vector3 center, Quaternion rotation, Vector3 size, ref Vector3 boxSize, PrimitiveBoundsHandle.Axes handleAxes, Color wireframeColor, Color handleColor) { Matrix4x4 trs = Matrix4x4.TRS(center, rotation, size); using (new Handles.DrawingScope(trs)) { boxBoundsHandle.axes = handleAxes; boxBoundsHandle.size = boxSize; boxBoundsHandle.handleColor = handleColor; boxBoundsHandle.wireframeColor = wireframeColor; boxBoundsHandle.DrawHandle(); boxSize = boxBoundsHandle.size; } }
private void DrawMultiSelectionHandle() { var currentEvent = Event.current; var root = (Vector2)Target.transform.position; var points = Target.Points; // multiple selection _multiSelectionHandle.DrawHandle(); var multiSelectionAnchor = _multiSelectionHandle.center - _multiSelectionHandle.size / 2; var bounds = new Bounds(_multiSelectionHandle.center, _multiSelectionHandle.size); var multiSelectionAnchorInitial = multiSelectionAnchor; EditorGUI.BeginChangeCheck(); multiSelectionAnchor = Handles.FreeMoveHandle(_multiSelectionHandleHint, multiSelectionAnchor, Quaternion.identity, GizmoRadius * HandleUtility.GetHandleSize(multiSelectionAnchor), Vector3.zero, Handles.DotHandleCap); if (EditorGUI.EndChangeCheck()) { Vector2 delta = multiSelectionAnchor - multiSelectionAnchorInitial; if (currentEvent.shift) { delta.y = 0; } if (currentEvent.alt) { delta.x = 0; } // move selectionBounds // ReSharper disable once RedundantCast _multiSelectionHandle.center += (Vector3)delta; if (currentEvent.control) { // move points Undo.RecordObject(Target, "Move multiple points "); for (var index = 0; index < points.Count; index++) { if (bounds.Contains(points[index] + root)) { points[index] += delta; } } } } }
private void DrawHandles() { float cellSize = m_Comp.CellSize; Matrix4x4 matrix = Matrix4x4.TRS(m_Comp.transform.position, m_Comp.Rotation, Vector3.one); using (new Handles.DrawingScope(matrix)) { EditorGUI.BeginChangeCheck(); { m_BoundsHandle.center = m_Comp.EditorBounds.center; m_BoundsHandle.size = m_Comp.EditorBounds.size; m_BoundsHandle.DrawHandle(); // Grid lines. Bounds b = m_Comp.DetectionBounds; Handles.color = s_GridColor; Handles.DrawWireCube(b.center, b.size); float y = b.center.y; float xMin = b.min.x; float xMax = b.max.x; float zMin = b.min.z; float zMax = b.max.z; for (float x = xMin + cellSize, max = xMax - cellSize * 0.5f; x < max; x += cellSize) { Handles.DrawLine(new Vector3(x, y, zMin), new Vector3(x, y, zMax)); } for (float z = zMin + cellSize, max = zMax - cellSize * 0.5f; z < max; z += cellSize) { Handles.DrawLine(new Vector3(xMin, y, z), new Vector3(xMax, y, z)); } } if (EditorGUI.EndChangeCheck()) { RecordUpdate(); Bounds b = new Bounds(m_BoundsHandle.center, m_BoundsHandle.size); b.size = new Vector3( Mathf.Max(b.size.x, cellSize), Mathf.Max(b.size.y, 1), Mathf.Max(b.size.z, cellSize)); m_Comp.EditorBounds = b; } } }