//============================ // Undo //============================ public static void RecordObject(UnityObject target, string name) { if (target.IsNull()) { return; } UnityUndo.RecordObject(target, name); }
public static void RegisterUndo(UnityObject target, string name) { #if UNITY_3_0 || UNITY_4_0 || UNITY_4_0_1 || UNITY_4_1 || UNITY_4_2 UnityUndo.RegisterUndo(target, name); #else UnityUndo.RecordObject(target, name); #endif }
public void Hide(GameObject[] gameObjects, bool includeDescendants) { Undo.RecordObject(SceneVisibilityState.GetInstance(), "Hide GameObjects"); SceneVisibilityState.SetGameObjectsHidden(gameObjects, true, includeDescendants); }
public void DisablePicking(GameObject gameObject, bool includeDescendants) { Undo.RecordObject(SceneVisibilityState.GetInstance(), "Disable Picking GameObject"); SceneVisibilityState.SetGameObjectPickingDisabled(gameObject, true, includeDescendants); }
public void Show(GameObject gameObject, bool includeDescendants) { Undo.RecordObject(SceneVisibilityState.GetInstance(), "Show GameObject"); SceneVisibilityState.SetGameObjectHidden(gameObject, false, includeDescendants); }
public void DisableAllPicking() { Undo.RecordObject(SceneVisibilityState.GetInstance(), "Disable All Picking"); DisableAllPickingNoUndo(); }
public override void OnInspectorGUI() { bool flag = base.targets.Length > 1; Animator animator = base.target as Animator; base.serializedObject.UpdateIfDirtyOrScript(); this.UpdateShowOptions(); EditorGUI.BeginChangeCheck(); RuntimeAnimatorController runtimeAnimatorController = EditorGUILayout.ObjectField("Controller", animator.runtimeAnimatorController, typeof(RuntimeAnimatorController), false, new GUILayoutOption[0]) as RuntimeAnimatorController; if (EditorGUI.EndChangeCheck()) { UnityEngine.Object[] targets = base.targets; for (int i = 0; i < targets.Length; i++) { Animator animator2 = (Animator)targets[i]; Undo.RecordObject(animator2, "Changed AnimatorController"); animator2.runtimeAnimatorController = runtimeAnimatorController; } AnimationWindowUtility.ControllerChanged(); } EditorGUILayout.PropertyField(this.m_Avatar, new GUILayoutOption[0]); if (animator.supportsOnAnimatorMove && !flag) { EditorGUILayout.LabelField("Apply Root Motion", "Handled by Script", new GUILayoutOption[0]); } else { EditorGUILayout.PropertyField(this.m_ApplyRootMotion, AnimatorInspector.styles.applyRootMotion, new GUILayoutOption[0]); if (Event.current.type == EventType.Layout) { this.m_IsRootPositionOrRotationControlledByCurves = animator.isRootPositionOrRotationControlledByCurves; } if (!this.m_ApplyRootMotion.boolValue && this.m_IsRootPositionOrRotationControlledByCurves) { EditorGUILayout.HelpBox("Root position or rotation are controlled by curves", MessageType.Info, true); } } EditorGUI.BeginChangeCheck(); EditorGUILayout.PropertyField(this.m_UpdateMode, AnimatorInspector.styles.updateMode, new GUILayoutOption[0]); bool flag2 = EditorGUI.EndChangeCheck(); EditorGUI.BeginChangeCheck(); EditorGUILayout.PropertyField(this.m_CullingMode, AnimatorInspector.styles.cullingMode, new GUILayoutOption[0]); bool flag3 = EditorGUI.EndChangeCheck(); if (!flag) { EditorGUILayout.HelpBox(animator.GetStats(), MessageType.Info, true); } if (EditorGUILayout.BeginFadeGroup(this.m_ShowWarningMessage.faded)) { EditorGUILayout.HelpBox(this.WarningMessage, MessageType.Warning, true); } EditorGUILayout.EndFadeGroup(); base.serializedObject.ApplyModifiedProperties(); UnityEngine.Object[] targets2 = base.targets; for (int j = 0; j < targets2.Length; j++) { Animator animator3 = (Animator)targets2[j]; if (flag3) { animator3.OnCullingModeChanged(); } if (flag2) { animator3.OnUpdateModeChanged(); } } }
private static void SetLayoutModeForAxis(SerializedProperty anchorMin, int axis, LayoutDropdownWindow.LayoutMode layoutMode, bool doPivot, bool doPosition, Vector2[,] defaultValues) { anchorMin.serializedObject.ApplyModifiedProperties(); for (int i = 0; i < anchorMin.serializedObject.targetObjects.Length; i++) { RectTransform rectTransform = anchorMin.serializedObject.targetObjects[i] as RectTransform; Undo.RecordObject(rectTransform, "Change Rectangle Anchors"); if (doPosition) { if (defaultValues != null && defaultValues.Length > i) { Vector2 vector = rectTransform.anchorMin; vector[axis] = defaultValues[i, 0][axis]; rectTransform.anchorMin = vector; vector = rectTransform.anchorMax; vector[axis] = defaultValues[i, 1][axis]; rectTransform.anchorMax = vector; vector = rectTransform.anchoredPosition; vector[axis] = defaultValues[i, 2][axis]; rectTransform.anchoredPosition = vector; vector = rectTransform.sizeDelta; vector[axis] = defaultValues[i, 3][axis]; rectTransform.sizeDelta = vector; } } if (doPivot && layoutMode != LayoutDropdownWindow.LayoutMode.Undefined) { RectTransformEditor.SetPivotSmart(rectTransform, LayoutDropdownWindow.kPivotsForModes[(int)layoutMode], axis, true, true); } Vector2 vector2 = Vector2.zero; switch (layoutMode) { case LayoutDropdownWindow.LayoutMode.Min: RectTransformEditor.SetAnchorSmart(rectTransform, 0f, axis, false, true, true); RectTransformEditor.SetAnchorSmart(rectTransform, 0f, axis, true, true, true); vector2 = rectTransform.offsetMin; EditorUtility.SetDirty(rectTransform); break; case LayoutDropdownWindow.LayoutMode.Middle: RectTransformEditor.SetAnchorSmart(rectTransform, 0.5f, axis, false, true, true); RectTransformEditor.SetAnchorSmart(rectTransform, 0.5f, axis, true, true, true); vector2 = (rectTransform.offsetMin + rectTransform.offsetMax) * 0.5f; EditorUtility.SetDirty(rectTransform); break; case LayoutDropdownWindow.LayoutMode.Max: RectTransformEditor.SetAnchorSmart(rectTransform, 1f, axis, false, true, true); RectTransformEditor.SetAnchorSmart(rectTransform, 1f, axis, true, true, true); vector2 = rectTransform.offsetMax; EditorUtility.SetDirty(rectTransform); break; case LayoutDropdownWindow.LayoutMode.Stretch: RectTransformEditor.SetAnchorSmart(rectTransform, 0f, axis, false, true, true); RectTransformEditor.SetAnchorSmart(rectTransform, 1f, axis, true, true, true); vector2 = (rectTransform.offsetMin + rectTransform.offsetMax) * 0.5f; EditorUtility.SetDirty(rectTransform); break; } if (doPosition) { Vector2 anchoredPosition = rectTransform.anchoredPosition; anchoredPosition[axis] -= vector2[axis]; rectTransform.anchoredPosition = anchoredPosition; if (layoutMode == LayoutDropdownWindow.LayoutMode.Stretch) { Vector2 sizeDelta = rectTransform.sizeDelta; sizeDelta[axis] = 0f; rectTransform.sizeDelta = sizeDelta; } } } anchorMin.serializedObject.Update(); }
public void TogglePicking(GameObject gameObject, bool includeDescendants) { Undo.RecordObject(SceneVisibilityState.GetInstance(), "Toggle Picking"); SceneVisibilityState.SetGameObjectPickingDisabled(gameObject, !SceneVisibilityState.IsGameObjectPickingDisabled(gameObject), includeDescendants); }
public override void OnSelectionInspectorGUI() { BoundsInt selection = GridSelection.position; Tilemap tilemap = GridSelection.target.GetComponent <Tilemap>(); int cellCount = selection.size.x * selection.size.y * selection.size.z; if (tilemap != null && cellCount > 0) { base.OnSelectionInspectorGUI(); GUILayout.Space(10f); if (m_SelectionTiles == null || m_SelectionTiles.Length != cellCount) { m_SelectionTiles = new TileBase[cellCount]; m_SelectionColors = new Color[cellCount]; m_SelectionMatrices = new Matrix4x4[cellCount]; m_SelectionFlagsArray = new TileFlags[cellCount]; m_SelectionSprites = new Sprite[cellCount]; m_SelectionColliderTypes = new Tile.ColliderType[cellCount]; } int index = 0; foreach (var p in selection.allPositionsWithin) { m_SelectionTiles[index] = tilemap.GetTile(p); m_SelectionColors[index] = tilemap.GetColor(p); m_SelectionMatrices[index] = tilemap.GetTransformMatrix(p); m_SelectionFlagsArray[index] = tilemap.GetTileFlags(p); m_SelectionSprites[index] = tilemap.GetSprite(p); m_SelectionColliderTypes[index] = tilemap.GetColliderType(p); index++; } EditorGUI.BeginChangeCheck(); EditorGUI.showMixedValue = m_SelectionTiles.Any(tile => tile != m_SelectionTiles.First()); var position = new Vector3Int(selection.xMin, selection.yMin, selection.zMin); TileBase newTile = EditorGUILayout.ObjectField(Styles.tileLabel, tilemap.GetTile(position), typeof(TileBase), false) as TileBase; if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(tilemap, "Edit Tilemap"); foreach (var p in selection.allPositionsWithin) { tilemap.SetTile(p, newTile); } } using (new EditorGUI.DisabledScope(true)) { EditorGUI.showMixedValue = m_SelectionSprites.Any(sprite => sprite != m_SelectionSprites.First()); EditorGUILayout.ObjectField(Styles.spriteLabel, m_SelectionSprites[0], typeof(Sprite), false, GUILayout.Height(EditorGUI.kSingleLineHeight)); } bool colorFlagsAllEqual = m_SelectionFlagsArray.All(flags => (flags & TileFlags.LockColor) == (m_SelectionFlagsArray.First() & TileFlags.LockColor)); using (new EditorGUI.DisabledScope(!colorFlagsAllEqual || (m_SelectionFlagsArray[0] & TileFlags.LockColor) != 0)) { EditorGUI.showMixedValue = m_SelectionColors.Any(color => color != m_SelectionColors.First()); EditorGUI.BeginChangeCheck(); Color newColor = EditorGUILayout.ColorField(Styles.colorLabel, m_SelectionColors[0]); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(tilemap, "Edit Tilemap"); foreach (var p in selection.allPositionsWithin) { tilemap.SetColor(p, newColor); } } } using (new EditorGUI.DisabledScope(true)) { EditorGUI.showMixedValue = m_SelectionColliderTypes.Any(colliderType => colliderType != m_SelectionColliderTypes.First()); EditorGUILayout.EnumPopup(Styles.colliderTypeLabel, m_SelectionColliderTypes[0]); } bool transformFlagsAllEqual = m_SelectionFlagsArray.All(flags => (flags & TileFlags.LockTransform) == (m_SelectionFlagsArray.First() & TileFlags.LockTransform)); using (new EditorGUI.DisabledScope(!transformFlagsAllEqual || (m_SelectionFlagsArray[0] & TileFlags.LockTransform) != 0)) { EditorGUI.showMixedValue = m_SelectionMatrices.Any(matrix => matrix != m_SelectionMatrices.First()); EditorGUI.BeginChangeCheck(); Matrix4x4 newTransformMatrix = TileEditor.TransformMatrixOnGUI(m_SelectionMatrices[0]); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(tilemap, "Edit Tilemap"); foreach (var p in selection.allPositionsWithin) { tilemap.SetTransformMatrix(p, newTransformMatrix); } } } using (new EditorGUI.DisabledScope(true)) { EditorGUI.showMixedValue = !colorFlagsAllEqual; EditorGUILayout.Toggle(Styles.lockColorLabel, (m_SelectionFlagsArray[0] & TileFlags.LockColor) != 0); EditorGUI.showMixedValue = !transformFlagsAllEqual; EditorGUILayout.Toggle(Styles.lockTransformLabel, (m_SelectionFlagsArray[0] & TileFlags.LockTransform) != 0); } EditorGUI.showMixedValue = false; } }
private void CollisionPlanesSceneGUI() { if (m_ScenePlanes.Count == 0) { return; } Event evt = Event.current; Color origCol = Handles.color; Color col = new Color(1, 1, 1, 0.5F); for (int i = 0; i < m_ScenePlanes.Count; ++i) { if (m_ScenePlanes[i] == null) { continue; } Transform transform = m_ScenePlanes[i]; Vector3 position = transform.position; Quaternion rotation = transform.rotation; Vector3 right = rotation * Vector3.right; Vector3 up = rotation * Vector3.up; Vector3 forward = rotation * Vector3.forward; bool isPlayingAndStatic = EditorApplication.isPlaying && transform.gameObject.isStatic; if (editingPlanes) { if (Object.ReferenceEquals(s_SelectedTransform, transform)) { EditorGUI.BeginChangeCheck(); var newPosition = transform.position; var newRotation = transform.rotation; using (new EditorGUI.DisabledScope(isPlayingAndStatic)) { if (isPlayingAndStatic) { Handles.ShowStaticLabel(position); } if (EditMode.editMode == EditMode.SceneViewEditMode.ParticleSystemCollisionModulePlanesMove) { newPosition = Handles.PositionHandle(position, rotation); } else if (EditMode.editMode == EditMode.SceneViewEditMode.ParticleSystemCollisionModulePlanesRotate) { newRotation = Handles.RotationHandle(rotation, position); } } if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(transform, "Modified Collision Plane Transform"); transform.position = newPosition; transform.rotation = newRotation; ParticleSystemEditorUtils.PerformCompleteResimulation(); } } else { float handleSize = HandleUtility.GetHandleSize(position) * 0.6f; EventType oldEventType = evt.type; // we want ignored mouse up events to check for dragging off of scene view if (evt.type == EventType.Ignore && evt.rawType == EventType.MouseUp) { oldEventType = evt.rawType; } Handles.FreeMoveHandle(position, Quaternion.identity, handleSize, Vector3.zero, Handles.RectangleHandleCap); // Detect selected plane (similar to TreeEditor) if (oldEventType == EventType.MouseDown && evt.type == EventType.Used) { s_SelectedTransform = transform; oldEventType = EventType.Used; GUIUtility.hotControl = 0; // Reset hot control or the FreeMoveHandle will prevent input to the new Handles. (case 873514) } } } Handles.color = col; Color color = Handles.s_ColliderHandleColor * 0.9f; if (isPlayingAndStatic) { color.a *= 0.2f; } if (m_PlaneVisualizationType == PlaneVizType.Grid) { DrawGrid(position, right, forward, up, color); } else { DrawSolidPlane(position, rotation, color, Color.yellow); } } Handles.color = origCol; }
public void OnSceneGUI() { bool flag = GUIUtility.hotControl == this.m_HandleControlID; CapsuleCollider capsuleCollider = (CapsuleCollider)base.target; Color color = Handles.color; if (capsuleCollider.enabled) { Handles.color = Handles.s_ColliderHandleColor; } else { Handles.color = Handles.s_ColliderHandleColorDisabled; } bool enabled = GUI.enabled; if (!base.editingCollider && !flag) { GUI.enabled = false; Handles.color = new Color(1f, 0f, 0f, 0.001f); } Vector3 capsuleExtents = ColliderUtil.GetCapsuleExtents(capsuleCollider); float num = capsuleExtents.y + 2f * capsuleExtents.x; float x = capsuleExtents.x; Matrix4x4 matrix = ColliderUtil.CalculateCapsuleTransform(capsuleCollider); int hotControl = GUIUtility.hotControl; float num2 = capsuleCollider.height; Vector3 vector = Vector3.left * num * 0.5f; float num3 = CapsuleColliderEditor.SizeHandle(vector, Vector3.left, matrix, true); if (!GUI.changed) { num3 = CapsuleColliderEditor.SizeHandle(-vector, Vector3.right, matrix, true); } if (GUI.changed) { float num4 = num / capsuleCollider.height; num2 += num3 / num4; } float num5 = capsuleCollider.radius; num3 = CapsuleColliderEditor.SizeHandle(Vector3.forward * x, Vector3.forward, matrix, true); if (!GUI.changed) { num3 = CapsuleColliderEditor.SizeHandle(-Vector3.forward * x, -Vector3.forward, matrix, true); } if (!GUI.changed) { num3 = CapsuleColliderEditor.SizeHandle(Vector3.up * x, Vector3.up, matrix, true); } if (!GUI.changed) { num3 = CapsuleColliderEditor.SizeHandle(-Vector3.up * x, -Vector3.up, matrix, true); } if (GUI.changed) { float num6 = Mathf.Max(capsuleExtents.z / capsuleCollider.radius, capsuleExtents.x / capsuleCollider.radius); num5 += num3 / num6; } if (hotControl != GUIUtility.hotControl && GUIUtility.hotControl != 0) { this.m_HandleControlID = GUIUtility.hotControl; } if (GUI.changed) { Undo.RecordObject(capsuleCollider, "Modify Capsule Collider"); capsuleCollider.radius = Mathf.Max(num5, 1E-05f); capsuleCollider.height = Mathf.Max(num2, 1E-05f); } Handles.color = color; GUI.enabled = enabled; }
public void OnSceneGUI() { bool flag = GUIUtility.hotControl == this.m_HandleControlID; CharacterController target = (CharacterController)this.target; Color color = Handles.color; Handles.color = !target.enabled ? Handles.s_ColliderHandleColorDisabled : Handles.s_ColliderHandleColor; bool enabled = GUI.enabled; if (!Event.current.shift && !flag) { GUI.enabled = false; Handles.color = new Color(1f, 0.0f, 0.0f, 1f / 1000f); } float a = target.height * target.transform.lossyScale.y; float num1 = target.radius * Mathf.Max(target.transform.lossyScale.x, target.transform.lossyScale.z); float num2 = Mathf.Max(a, num1 * 2f); Matrix4x4 matrix = Matrix4x4.TRS(target.transform.TransformPoint(target.center), Quaternion.identity, Vector3.one); int hotControl = GUIUtility.hotControl; Vector3 localPos = Vector3.up * num2 * 0.5f; float num3 = CharacterControllerEditor.SizeHandle(localPos, Vector3.up, matrix, true); if (!GUI.changed) { num3 = CharacterControllerEditor.SizeHandle(-localPos, Vector3.down, matrix, true); } if (GUI.changed) { Undo.RecordObject((Object)target, "Character Controller Resize"); float num4 = num2 / target.height; target.height += num3 / num4; } float num5 = CharacterControllerEditor.SizeHandle(Vector3.left * num1, Vector3.left, matrix, true); if (!GUI.changed) { num5 = CharacterControllerEditor.SizeHandle(-Vector3.left * num1, -Vector3.left, matrix, true); } if (!GUI.changed) { num5 = CharacterControllerEditor.SizeHandle(Vector3.forward * num1, Vector3.forward, matrix, true); } if (!GUI.changed) { num5 = CharacterControllerEditor.SizeHandle(-Vector3.forward * num1, -Vector3.forward, matrix, true); } if (GUI.changed) { Undo.RecordObject((Object)target, "Character Controller Resize"); float num4 = num1 / target.radius; target.radius += num5 / num4; } if (hotControl != GUIUtility.hotControl && GUIUtility.hotControl != 0) { this.m_HandleControlID = GUIUtility.hotControl; } if (GUI.changed) { target.radius = Mathf.Max(target.radius, 1E-05f); target.height = Mathf.Max(target.height, 1E-05f); } Handles.color = color; GUI.enabled = enabled; }
public void OnSceneGUI() { if (m_ActiveCollider == null) { return; } // Fetch the collider offset. var colliderOffset = m_ActiveCollider.offset; Event evt = Event.current; m_DeleteMode = evt.command || evt.control; Transform transform = m_ActiveCollider.transform; // Handles.Slider2D will render active point as yellow if there is keyboardControl set. We don't want that happening. GUIUtility.keyboardControl = 0; HandleUtility.s_CustomPickDistance = k_HandlePickDistance; // Find mouse positions in local and world space Plane plane = new Plane(-transform.forward, new Vector3(0f, 0f, transform.position.z)); Ray mouseRay = HandleUtility.GUIPointToWorldRay(evt.mousePosition); float dist; plane.Raycast(mouseRay, out dist); Vector3 mouseWorldPos = mouseRay.GetPoint(dist); Vector2 mouseLocalPos = transform.InverseTransformPoint(mouseWorldPos); // Select the active vertex and edge if (evt.type == EventType.MouseMove || m_FirstOnSceneGUIAfterReset) { int pathIndex; int pointIndex0, pointIndex1; float distance; if (PolygonEditor.GetNearestPoint(mouseLocalPos - colliderOffset, out pathIndex, out pointIndex0, out distance)) { m_SelectedPath = pathIndex; m_SelectedVertex = pointIndex0; } else { m_SelectedPath = -1; } if (PolygonEditor.GetNearestEdge(mouseLocalPos - colliderOffset, out pathIndex, out pointIndex0, out pointIndex1, out distance, m_LoopingCollider)) { m_SelectedEdgePath = pathIndex; m_SelectedEdgeVertex0 = pointIndex0; m_SelectedEdgeVertex1 = pointIndex1; } else { m_SelectedEdgePath = -1; } if (evt.type == EventType.MouseMove) { evt.Use(); } } else if (evt.type == EventType.MouseUp) { m_LeftIntersect = false; m_RightIntersect = false; } // Do we handle point or line? // TODO: there probably isn't a case when selectedPath is valid and selectedEdge is invalid. This needs a refactor. if (GUIUtility.hotControl == 0) { if (m_SelectedPath != -1 && m_SelectedEdgePath != -1) { // Calculate snapping distance Vector2 point; PolygonEditor.GetPoint(m_SelectedPath, m_SelectedVertex, out point); point += colliderOffset; Vector3 worldPos = transform.TransformPoint(point); m_HandleEdge = (HandleUtility.WorldToGUIPoint(worldPos) - Event.current.mousePosition).sqrMagnitude > k_HandlePointSnap * k_HandlePointSnap; m_HandlePoint = !m_HandleEdge; } else if (m_SelectedPath != -1) { m_HandlePoint = true; } else if (m_SelectedEdgePath != -1) { m_HandleEdge = true; } if (m_DeleteMode && m_HandleEdge) { m_HandleEdge = false; m_HandlePoint = true; } } // If this is a polygon collider being used by a composite then draw the polygon paths. if ((m_ActiveCollider is PolygonCollider2D) && m_ActiveCollider.usedByComposite) { DrawPolygonCollider(transform); } bool applyToCollider = false; // Edge handle if (m_HandleEdge && !m_DeleteMode) { Vector2 p0, p1; PolygonEditor.GetPoint(m_SelectedEdgePath, m_SelectedEdgeVertex0, out p0); PolygonEditor.GetPoint(m_SelectedEdgePath, m_SelectedEdgeVertex1, out p1); p0 += colliderOffset; p1 += colliderOffset; Vector3 worldPosV0 = transform.TransformPoint(p0); Vector3 worldPosV1 = transform.TransformPoint(p1); Handles.color = Color.green; Handles.DrawAAPolyLine(4.0f, new Vector3[] { worldPosV0, worldPosV1 }); Handles.color = Color.white; Vector3 newPoint = GetNearestPointOnEdge(transform.TransformPoint(mouseLocalPos), worldPosV0, worldPosV1); newPoint.z = transform.position.z; EditorGUI.BeginChangeCheck(); float guiSize = HandleUtility.GetHandleSize(newPoint) * 0.04f; Handles.color = Color.green; newPoint = Handles.Slider2D( newPoint, new Vector3(0, 0, 1), new Vector3(1, 0, 0), new Vector3(0, 1, 0), guiSize, Handles.DotHandleCap, Vector3.zero); Handles.color = Color.white; if (EditorGUI.EndChangeCheck()) { PolygonEditor.InsertPoint(m_SelectedEdgePath, m_SelectedEdgeVertex1, ((p0 + p1) / 2) - colliderOffset); m_SelectedPath = m_SelectedEdgePath; m_SelectedVertex = m_SelectedEdgeVertex1; m_HandleEdge = false; m_HandlePoint = true; applyToCollider = true; } } // Point handle if (m_HandlePoint) { Vector2 point; PolygonEditor.GetPoint(m_SelectedPath, m_SelectedVertex, out point); point += colliderOffset; Vector3 worldPos = transform.TransformPoint(point); Vector2 screenPos = HandleUtility.WorldToGUIPoint(worldPos); float guiSize = HandleUtility.GetHandleSize(worldPos) * 0.04f; if (m_DeleteMode && evt.type == EventType.MouseDown && Vector2.Distance(screenPos, Event.current.mousePosition) < k_HandlePickDistance || DeleteCommandEvent(evt)) { if (evt.type != EventType.ValidateCommand) { int pathPointCount = PolygonEditor.GetPointCount(m_SelectedPath); if (pathPointCount > m_MinPathPoints) { PolygonEditor.RemovePoint(m_SelectedPath, m_SelectedVertex); Reset(); applyToCollider = true; } } evt.Use(); } EditorGUI.BeginChangeCheck(); Handles.color = m_DeleteMode ? Color.red : Color.green; Vector3 newWorldPos = Handles.Slider2D( worldPos, new Vector3(0, 0, 1), new Vector3(1, 0, 0), new Vector3(0, 1, 0), guiSize, Handles.DotHandleCap, Vector3.zero); Handles.color = Color.white; if (EditorGUI.EndChangeCheck() && !m_DeleteMode) { point = transform.InverseTransformPoint(newWorldPos); point -= colliderOffset; PolygonEditor.TestPointMove(m_SelectedPath, m_SelectedVertex, point, out m_LeftIntersect, out m_RightIntersect, m_LoopingCollider); PolygonEditor.SetPoint(m_SelectedPath, m_SelectedVertex, point); applyToCollider = true; } if (!applyToCollider) { DrawEdgesForSelectedPoint(newWorldPos, transform, m_LeftIntersect, m_RightIntersect, m_LoopingCollider); } } // Apply changes if (applyToCollider) { Undo.RecordObject(m_ActiveCollider, "Edit Collider"); PolygonEditor.ApplyEditing(m_ActiveCollider); } if (DeleteCommandEvent(evt)) { Event.current.Use(); // If we don't use the delete event in all cases, it sceneview might delete the entire object } m_FirstOnSceneGUIAfterReset = false; }
public void EnablePicking(GameObject[] gameObjects, bool includeDescendants) { Undo.RecordObject(SceneVisibilityState.GetInstance(), "Enable Picking GameObjects"); SceneVisibilityState.SetGameObjectsPickingDisabled(gameObjects, false, includeDescendants); }
public void ToggleVisibility(GameObject gameObject, bool includeDescendants) { Undo.RecordObject(SceneVisibilityState.GetInstance(), "Toggle Visibility"); SceneVisibilityState.SetGameObjectHidden(gameObject, !SceneVisibilityState.IsGameObjectHidden(gameObject), includeDescendants); }
public override void ToolGUI(SceneView view, Vector3 handlePosition, bool isStatic) { Rect handleRect = Tools.handleRect; Quaternion handleRectRotation = Tools.handleRectRotation; Vector3[] corners = new Vector3[4]; for (int i = 0; i < 4; i++) { Vector3 localRectPoint = (Vector3)GetLocalRectPoint(handleRect, i); corners[i] = ((Vector3)(handleRectRotation * localRectPoint)) + handlePosition; } RectHandles.RenderRectWithShadow(false, corners); Color color = GUI.color; float num2 = 1f; if (Camera.current != null) { Vector3 planeNormal = !Camera.current.orthographic ? ((handlePosition + (handleRectRotation * handleRect.center)) - Camera.current.transform.position) : Camera.current.transform.forward; Vector3 vector = (Vector3)((handleRectRotation * Vector3.right) * handleRect.width); Vector3 vector4 = (Vector3)((handleRectRotation * Vector3.up) * handleRect.height); float num3 = Mathf.Sqrt(Vector3.Cross(Vector3.ProjectOnPlane(vector, planeNormal), Vector3.ProjectOnPlane(vector4, planeNormal)).magnitude) / HandleUtility.GetHandleSize(handlePosition); num2 = Mathf.Clamp01(((num3 - 0.2f) / 0.2f) * 2f); Color color2 = color; color2.a *= num2; GUI.color = color2; } Vector3 pivot = Tools.GetHandlePosition(); if (!Tools.vertexDragging) { RectTransform component = Selection.activeTransform.GetComponent <RectTransform>(); bool flag = Selection.transforms.Length > 1; bool flag2 = (!flag && (Tools.pivotMode == PivotMode.Pivot)) && (component != null); EditorGUI.BeginDisabledGroup(!flag && !flag2); EditorGUI.BeginChangeCheck(); Vector3 vector6 = PivotHandleGUI(handleRect, pivot, handleRectRotation); if (EditorGUI.EndChangeCheck() && !isStatic) { if (flag) { Tools.localHandleOffset += Quaternion.Inverse(Tools.handleRotation) * (vector6 - pivot); } else if (flag2) { Transform activeTransform = Selection.activeTransform; Undo.RecordObject(component, "Move Rectangle Pivot"); Transform transform3 = (!Tools.rectBlueprintMode || !InternalEditorUtility.SupportsRectLayout(activeTransform)) ? activeTransform : activeTransform.parent; Vector2 vector7 = transform3.InverseTransformVector(vector6 - pivot); vector7.x /= component.rect.width; vector7.y /= component.rect.height; Vector2 vector8 = component.pivot + vector7; RectTransformEditor.SetPivotSmart(component, vector8.x, 0, true, transform3 != component.transform); RectTransformEditor.SetPivotSmart(component, vector8.y, 1, true, transform3 != component.transform); } } EditorGUI.EndDisabledGroup(); } TransformManipulator.BeginManipulationHandling(true); if (!Tools.vertexDragging) { EditorGUI.BeginChangeCheck(); Vector3 scalePivot = handlePosition; Vector3 scaleDelta = ResizeHandlesGUI(handleRect, handlePosition, handleRectRotation, out scalePivot); if (EditorGUI.EndChangeCheck() && !isStatic) { TransformManipulator.SetResizeDelta(scaleDelta, scalePivot, handleRectRotation); } bool flag3 = true; if (Tools.rectBlueprintMode) { foreach (Transform transform4 in Selection.transforms) { if (transform4.GetComponent <RectTransform>() != null) { flag3 = false; } } } if (flag3) { EditorGUI.BeginChangeCheck(); Quaternion quaternion2 = RotationHandlesGUI(handleRect, handlePosition, handleRectRotation); if (EditorGUI.EndChangeCheck() && !isStatic) { float num5; Vector3 vector11; (Quaternion.Inverse(handleRectRotation) * quaternion2).ToAngleAxis(out num5, out vector11); vector11 = (Vector3)(handleRectRotation * vector11); Undo.RecordObjects(Selection.transforms, "Rotate"); foreach (Transform transform5 in Selection.transforms) { transform5.RotateAround(handlePosition, vector11, num5); if (transform5.parent != null) { transform5.SendTransformChangedScale(); } } Tools.handleRotation = Quaternion.AngleAxis(num5, vector11) * Tools.handleRotation; } } } TransformManipulator.EndManipulationHandling(); TransformManipulator.BeginManipulationHandling(false); EditorGUI.BeginChangeCheck(); Vector3 vector12 = MoveHandlesGUI(handleRect, handlePosition, handleRectRotation); if (EditorGUI.EndChangeCheck() && !isStatic) { Vector3 positionDelta = vector12 - TransformManipulator.mouseDownHandlePosition; TransformManipulator.SetPositionDelta(positionDelta); } TransformManipulator.EndManipulationHandling(); GUI.color = color; }
public void ExitIsolation() { Undo.RecordObject(SceneVisibilityState.GetInstance(), "Exit Isolation"); RevertIsolationCurrentStage(); }
public void HideAll() { Undo.RecordObject(SceneVisibilityState.GetInstance(), "Hide All"); HideAllNoUndo(); }
protected override void ToolGUI(SceneView view, Vector3 handlePosition, bool isStatic) { Rect rect = Tools.handleRect; Quaternion rectRotation = Tools.handleRectRotation; // Draw rect Vector3[] verts = new Vector3[4]; for (int i = 0; i < 4; i++) { Vector3 pos = GetLocalRectPoint(rect, i); verts[i] = rectRotation * pos + handlePosition; } RectHandles.RenderRectWithShadow(false, verts); // Handle fading Color oldColor = GUI.color; float faded = 1; if (Camera.current) { Vector3 viewDir = Camera.current.orthographic ? Camera.current.transform.forward : (handlePosition + rectRotation * rect.center - Camera.current.transform.position); Vector3 rectRight = rectRotation * Vector3.right * rect.width; Vector3 rectUp = rectRotation * Vector3.up * rect.height; float visibleSize = Mathf.Sqrt(Vector3.Cross(Vector3.ProjectOnPlane(rectRight, viewDir), Vector3.ProjectOnPlane(rectUp, viewDir)).magnitude); visibleSize /= HandleUtility.GetHandleSize(handlePosition); faded = Mathf.Clamp01((visibleSize - kMinVisibleSize) / kMinVisibleSize * 2); Color fadedColor = oldColor; fadedColor.a *= faded; GUI.color = fadedColor; } Vector3 oldPivot = Tools.cachedHandlePosition; // Pivot handle if (!Tools.vertexDragging) { RectTransform rectTransform = Selection.activeTransform.GetComponent <RectTransform>(); bool groupPivot = Selection.transforms.Length > 1; bool rectTransformPivot = !groupPivot && Tools.pivotMode == PivotMode.Pivot && rectTransform != null; using (new EditorGUI.DisabledScope(!groupPivot && !rectTransformPivot)) { EditorGUI.BeginChangeCheck(); Vector3 newPivot = PivotHandleGUI(rect, oldPivot, rectRotation); if (EditorGUI.EndChangeCheck() && !isStatic) { if (groupPivot) { Tools.localHandleOffset += Quaternion.Inverse(Tools.handleRotation) * (newPivot - oldPivot); } else if (rectTransformPivot) { Transform tr = Selection.activeTransform; Undo.RecordObject(rectTransform, "Move Rectangle Pivot"); Transform space = Tools.rectBlueprintMode && UnityEditorInternal.InternalEditorUtility.SupportsRectLayout(tr) ? tr.parent : tr; Vector2 offset = space.InverseTransformVector(newPivot - oldPivot); offset.x /= rectTransform.rect.width; offset.y /= rectTransform.rect.height; Vector2 pivot = rectTransform.pivot + offset; RectTransformEditor.SetPivotSmart(rectTransform, pivot.x, 0, true, space != rectTransform.transform); RectTransformEditor.SetPivotSmart(rectTransform, pivot.y, 1, true, space != rectTransform.transform); } } } } TransformManipulator.BeginManipulationHandling(true); if (!Tools.vertexDragging) { // Resize handles EditorGUI.BeginChangeCheck(); Vector3 scalePivot = handlePosition; Vector3 scale = ResizeHandlesGUI(rect, handlePosition, rectRotation, out scalePivot); if (EditorGUI.EndChangeCheck() && !isStatic) { TransformManipulator.SetResizeDelta(scale, scalePivot, rectRotation); } bool enableRotation = true; if (Tools.rectBlueprintMode) { foreach (Transform t in Selection.transforms) { if (t.GetComponent <RectTransform>() != null) { enableRotation = false; } } } if (enableRotation) { // Rotation handles EditorGUI.BeginChangeCheck(); Quaternion after = RotationHandlesGUI(rect, handlePosition, rectRotation); if (EditorGUI.EndChangeCheck() && !isStatic) { Quaternion delta = Quaternion.Inverse(rectRotation) * after; float angle; Vector3 axis; delta.ToAngleAxis(out angle, out axis); axis = rectRotation * axis; Undo.RecordObjects(Selection.transforms, "Rotate"); foreach (Transform t in Selection.transforms) { t.RotateAround(handlePosition, axis, angle); // sync euler hints after a rotate tool update tyo fake continuous rotation t.SetLocalEulerHint(t.GetLocalEulerAngles(t.rotationOrder)); if (t.parent != null) { t.SendTransformChangedScale(); // force scale update, needed if transform has non-uniformly scaled parent. } } Tools.handleRotation = Quaternion.AngleAxis(angle, axis) * Tools.handleRotation; } } } TransformManipulator.EndManipulationHandling(); TransformManipulator.BeginManipulationHandling(false); // Move handle EditorGUI.BeginChangeCheck(); Vector3 newPos = MoveHandlesGUI(rect, handlePosition, rectRotation); if (EditorGUI.EndChangeCheck() && !isStatic) { if (GridSnapping.active) { newPos = GridSnapping.Snap(newPos); } if (TransformManipulator.HandleHasMoved(newPos)) { TransformManipulator.SetPositionDelta(newPos, TransformManipulator.mouseDownHandlePosition); } } TransformManipulator.EndManipulationHandling(); GUI.color = oldColor; }
void SetAsStartupSnapshot(AudioMixerSnapshotController snapshot) { Undo.RecordObject(m_Controller, "Set start snapshot"); m_Controller.startSnapshot = snapshot; }