private static UpdateSelection ( Object existingSelection, Object newObject, SelectionType type, bool isRectSelection ) : void | ||
existingSelection | Object | |
newObject | Object | |
type | SelectionType | |
isRectSelection | bool | |
return | void |
private void TryOneClickDrag() { EventType type = Event.current.type; if (type == EventType.MouseDown) { UnityEngine.Object @object = HandleUtility.PickGameObject(Event.current.mousePosition, true); if (@object) { GameObject gameObject = @object as GameObject; bool flag = false; GameObject[] gameObjects = Selection.gameObjects; for (int i = 0; i < gameObjects.Length; i++) { GameObject y = gameObjects[i]; if (gameObject == y) { flag = true; break; } } if (!flag && gameObject.GetComponent <SpriteRenderer>() != null) { RectSelection.UpdateSelection(this.m_SelectionStart, @object, RectSelection.SelectionType.Normal, this.m_RectSelecting); SceneView.lastActiveSceneView.m_OneClickDragObject = @object; Event.current.Use(); } } } }
private static void UpdateSelection(UnityEngine.Object[] existingSelection, UnityEngine.Object newObject, RectSelection.SelectionType type, bool isRectSelection) { UnityEngine.Object[] newObjects; if (newObject == (UnityEngine.Object)null) { newObjects = new UnityEngine.Object[0]; } else { newObjects = new UnityEngine.Object[1] { newObject } }; RectSelection.UpdateSelection(existingSelection, newObjects, type, isRectSelection); }
public void OnGUI() { Event current = Event.current; Handles.BeginGUI(); Vector2 mousePosition = current.mousePosition; int num = RectSelection.s_RectSelectionID; EventType typeForControl = current.GetTypeForControl(num); switch (typeForControl) { case EventType.MouseDown: if (HandleUtility.nearestControl == num && current.button == 0) { GUIUtility.hotControl = num; this.m_SelectStartPoint = mousePosition; this.m_SelectionStart = Selection.objects; this.m_RectSelecting = false; } goto IL_4F7; case EventType.MouseUp: if (GUIUtility.hotControl == num && current.button == 0) { GUIUtility.hotControl = 0; if (this.m_RectSelecting) { EditorApplication.modifierKeysChanged = (EditorApplication.CallbackFunction)Delegate.Remove(EditorApplication.modifierKeysChanged, new EditorApplication.CallbackFunction(this.SendCommandsOnModifierKeys)); this.m_RectSelecting = false; this.m_SelectionStart = new UnityEngine.Object[0]; current.Use(); } else { if (current.shift || EditorGUI.actionKey) { GameObject gameObject = HandleUtility.PickGameObject(current.mousePosition, false); if ((!EditorGUI.actionKey) ? (Selection.activeGameObject == gameObject) : Selection.gameObjects.Contains(gameObject)) { RectSelection.UpdateSelection(this.m_SelectionStart, gameObject, RectSelection.SelectionType.Subtractive, this.m_RectSelecting); } else { RectSelection.UpdateSelection(this.m_SelectionStart, HandleUtility.PickGameObject(current.mousePosition, true), RectSelection.SelectionType.Additive, this.m_RectSelecting); } } else { GameObject newObject = SceneViewPicking.PickGameObject(current.mousePosition); RectSelection.UpdateSelection(this.m_SelectionStart, newObject, RectSelection.SelectionType.Normal, this.m_RectSelecting); } current.Use(); } } goto IL_4F7; case EventType.MouseMove: case EventType.KeyDown: case EventType.KeyUp: case EventType.ScrollWheel: IL_4B: if (typeForControl != EventType.ExecuteCommand) { goto IL_4F7; } if (num == GUIUtility.hotControl && current.commandName == "ModifierKeysChanged") { if (current.shift) { RectSelection.UpdateSelection(this.m_SelectionStart, this.m_CurrentSelection, RectSelection.SelectionType.Additive, this.m_RectSelecting); } else if (EditorGUI.actionKey) { RectSelection.UpdateSelection(this.m_SelectionStart, this.m_CurrentSelection, RectSelection.SelectionType.Subtractive, this.m_RectSelecting); } else { RectSelection.UpdateSelection(this.m_SelectionStart, this.m_CurrentSelection, RectSelection.SelectionType.Normal, this.m_RectSelecting); } current.Use(); } goto IL_4F7; case EventType.MouseDrag: if (GUIUtility.hotControl == num) { if (!this.m_RectSelecting && (mousePosition - this.m_SelectStartPoint).magnitude > 6f) { EditorApplication.modifierKeysChanged = (EditorApplication.CallbackFunction)Delegate.Combine(EditorApplication.modifierKeysChanged, new EditorApplication.CallbackFunction(this.SendCommandsOnModifierKeys)); this.m_RectSelecting = true; this.m_LastSelection = null; this.m_CurrentSelection = null; } if (this.m_RectSelecting) { this.m_SelectMousePoint = new Vector2(Mathf.Max(mousePosition.x, 0f), Mathf.Max(mousePosition.y, 0f)); GameObject[] array = HandleUtility.PickRectObjects(EditorGUIExt.FromToRect(this.m_SelectStartPoint, this.m_SelectMousePoint)); this.m_CurrentSelection = array; bool flag = false; if (this.m_LastSelection == null) { this.m_LastSelection = new Dictionary <GameObject, bool>(); flag = true; } flag |= (this.m_LastSelection.Count != array.Length); if (!flag) { Dictionary <GameObject, bool> dictionary = new Dictionary <GameObject, bool>(array.Length); GameObject[] array2 = array; for (int i = 0; i < array2.Length; i++) { GameObject key = array2[i]; dictionary.Add(key, false); } foreach (GameObject current2 in this.m_LastSelection.Keys) { if (!dictionary.ContainsKey(current2)) { flag = true; break; } } } if (flag) { this.m_LastSelection = new Dictionary <GameObject, bool>(array.Length); GameObject[] array3 = array; for (int j = 0; j < array3.Length; j++) { GameObject key2 = array3[j]; this.m_LastSelection.Add(key2, false); } if (array != null) { if (current.shift) { RectSelection.UpdateSelection(this.m_SelectionStart, array, RectSelection.SelectionType.Additive, this.m_RectSelecting); } else if (EditorGUI.actionKey) { RectSelection.UpdateSelection(this.m_SelectionStart, array, RectSelection.SelectionType.Subtractive, this.m_RectSelecting); } else { RectSelection.UpdateSelection(this.m_SelectionStart, array, RectSelection.SelectionType.Normal, this.m_RectSelecting); } } } } current.Use(); } goto IL_4F7; case EventType.Repaint: if (GUIUtility.hotControl == num && this.m_RectSelecting) { EditorStyles.selectionRect.Draw(EditorGUIExt.FromToRect(this.m_SelectStartPoint, this.m_SelectMousePoint), GUIContent.none, false, false, false, false); } goto IL_4F7; case EventType.Layout: if (!Tools.viewToolActive) { HandleUtility.AddDefaultControl(num); } goto IL_4F7; } goto IL_4B; IL_4F7: Handles.EndGUI(); }
public void OnGUI() { Event current1 = Event.current; Handles.BeginGUI(); Vector2 mousePosition = current1.mousePosition; int rectSelectionId = RectSelection.s_RectSelectionID; EventType typeForControl = current1.GetTypeForControl(rectSelectionId); switch (typeForControl) { case EventType.MouseDown: if (HandleUtility.nearestControl == rectSelectionId && current1.button == 0) { GUIUtility.hotControl = rectSelectionId; this.m_SelectStartPoint = mousePosition; this.m_SelectionStart = Selection.objects; this.m_RectSelecting = false; break; } break; case EventType.MouseUp: if (GUIUtility.hotControl == rectSelectionId && current1.button == 0) { GUIUtility.hotControl = 0; if (this.m_RectSelecting) { EditorApplication.modifierKeysChanged -= new EditorApplication.CallbackFunction(this.SendCommandsOnModifierKeys); this.m_RectSelecting = false; this.m_SelectionStart = new UnityEngine.Object[0]; current1.Use(); break; } if (current1.shift || EditorGUI.actionKey) { GameObject[] gameObjectArray; if (current1.shift) { gameObjectArray = new GameObject[1] { Selection.activeGameObject } } ; else { gameObjectArray = Selection.gameObjects; } GameObject[] gameObjects = gameObjectArray; GameObject hovered = SceneViewPicking.GetHovered(current1.mousePosition, gameObjects); if ((UnityEngine.Object)hovered != (UnityEngine.Object)null) { RectSelection.UpdateSelection(this.m_SelectionStart, (UnityEngine.Object)hovered, RectSelection.SelectionType.Subtractive, this.m_RectSelecting); } else { RectSelection.UpdateSelection(this.m_SelectionStart, (UnityEngine.Object)HandleUtility.PickGameObject(current1.mousePosition, true), RectSelection.SelectionType.Additive, this.m_RectSelecting); } } else { RectSelection.UpdateSelection(this.m_SelectionStart, (UnityEngine.Object)SceneViewPicking.PickGameObject(current1.mousePosition), RectSelection.SelectionType.Normal, this.m_RectSelecting); } current1.Use(); break; } break; case EventType.MouseDrag: if (GUIUtility.hotControl == rectSelectionId) { if (!this.m_RectSelecting && (double)(mousePosition - this.m_SelectStartPoint).magnitude > 6.0) { EditorApplication.modifierKeysChanged += new EditorApplication.CallbackFunction(this.SendCommandsOnModifierKeys); this.m_RectSelecting = true; this.m_LastSelection = (Dictionary <GameObject, bool>)null; this.m_CurrentSelection = (UnityEngine.Object[])null; } if (this.m_RectSelecting) { this.m_SelectMousePoint = new Vector2(Mathf.Max(mousePosition.x, 0.0f), Mathf.Max(mousePosition.y, 0.0f)); GameObject[] gameObjectArray = HandleUtility.PickRectObjects(EditorGUIExt.FromToRect(this.m_SelectStartPoint, this.m_SelectMousePoint)); this.m_CurrentSelection = (UnityEngine.Object[])gameObjectArray; bool flag1 = false; if (this.m_LastSelection == null) { this.m_LastSelection = new Dictionary <GameObject, bool>(); flag1 = true; } bool flag2 = flag1 | this.m_LastSelection.Count != gameObjectArray.Length; if (!flag2) { Dictionary <GameObject, bool> dictionary = new Dictionary <GameObject, bool>(gameObjectArray.Length); foreach (GameObject key in gameObjectArray) { dictionary.Add(key, false); } using (Dictionary <GameObject, bool> .KeyCollection.Enumerator enumerator = this.m_LastSelection.Keys.GetEnumerator()) { while (enumerator.MoveNext()) { GameObject current2 = enumerator.Current; if (!dictionary.ContainsKey(current2)) { flag2 = true; break; } } } } if (flag2) { this.m_LastSelection = new Dictionary <GameObject, bool>(gameObjectArray.Length); foreach (GameObject key in gameObjectArray) { this.m_LastSelection.Add(key, false); } if (gameObjectArray != null) { if (current1.shift) { RectSelection.UpdateSelection(this.m_SelectionStart, (UnityEngine.Object[])gameObjectArray, RectSelection.SelectionType.Additive, this.m_RectSelecting); } else if (EditorGUI.actionKey) { RectSelection.UpdateSelection(this.m_SelectionStart, (UnityEngine.Object[])gameObjectArray, RectSelection.SelectionType.Subtractive, this.m_RectSelecting); } else { RectSelection.UpdateSelection(this.m_SelectionStart, (UnityEngine.Object[])gameObjectArray, RectSelection.SelectionType.Normal, this.m_RectSelecting); } } } } current1.Use(); break; } break; case EventType.Repaint: if (GUIUtility.hotControl == rectSelectionId && this.m_RectSelecting) { EditorStyles.selectionRect.Draw(EditorGUIExt.FromToRect(this.m_SelectStartPoint, this.m_SelectMousePoint), GUIContent.none, false, false, false, false); break; } break; case EventType.Layout: if (!Tools.viewToolActive) { HandleUtility.AddDefaultControl(rectSelectionId); break; } break; default: if (typeForControl == EventType.ExecuteCommand && rectSelectionId == GUIUtility.hotControl && current1.commandName == "ModifierKeysChanged") { if (current1.shift) { RectSelection.UpdateSelection(this.m_SelectionStart, this.m_CurrentSelection, RectSelection.SelectionType.Additive, this.m_RectSelecting); } else if (EditorGUI.actionKey) { RectSelection.UpdateSelection(this.m_SelectionStart, this.m_CurrentSelection, RectSelection.SelectionType.Subtractive, this.m_RectSelecting); } else { RectSelection.UpdateSelection(this.m_SelectionStart, this.m_CurrentSelection, RectSelection.SelectionType.Normal, this.m_RectSelecting); } current1.Use(); break; } break; } Handles.EndGUI(); }