public static bool SelectPoints(IEditablePoint points, Transform cloudTransform, ref List <int> selection, bool firstSelect) { int controlID = GUIUtility.GetControlID(FocusType.Passive); bool result; if (Event.current.alt && Event.current.type != EventType.Repaint) { result = false; } else { bool flag = false; Event current = Event.current; switch (current.GetTypeForControl(controlID)) { case EventType.MouseDown: if ((HandleUtility.nearestControl == controlID || firstSelect) && current.button == 0) { if (!current.shift && !EditorGUI.actionKey) { selection.Clear(); flag = true; } PointEditor.s_SelectionStart = new List <int>(selection); GUIUtility.hotControl = controlID; PointEditor.s_StartMouseDragPosition = current.mousePosition; PointEditor.s_StartDragSelection = new List <int>(selection); current.Use(); } break; case EventType.MouseUp: if (GUIUtility.hotControl == controlID && current.button == 0) { if (!PointEditor.s_DidDrag) { int num = PointEditor.FindNearest(PointEditor.s_StartMouseDragPosition, cloudTransform, points); if (num != -1) { if (!current.shift && !EditorGUI.actionKey) { selection.Add(num); } else { int num2 = selection.IndexOf(num); if (num2 != -1) { selection.RemoveAt(num2); } else { selection.Add(num); } } } GUI.changed = true; flag = true; } PointEditor.s_StartDragSelection = null; PointEditor.s_StartMouseDragPosition = Vector2.zero; PointEditor.s_DidDrag = false; GUIUtility.hotControl = 0; current.Use(); } break; case EventType.MouseDrag: if (GUIUtility.hotControl == controlID && current.button == 0) { PointEditor.s_DidDrag = true; selection.Clear(); selection.AddRange(PointEditor.s_StartDragSelection); Rect rect = PointEditor.FromToRect(PointEditor.s_StartMouseDragPosition, current.mousePosition); Matrix4x4 matrix = Handles.matrix; Handles.matrix = cloudTransform.localToWorldMatrix; for (int i = 0; i < points.Count; i++) { Vector2 point = HandleUtility.WorldToGUIPoint(points.GetPosition(i)); if (rect.Contains(point)) { if (EditorGUI.actionKey) { if (PointEditor.s_SelectionStart.Contains(i)) { selection.Remove(i); } } else if (!PointEditor.s_SelectionStart.Contains(i)) { selection.Add(i); } } } Handles.matrix = matrix; GUI.changed = true; current.Use(); } break; case EventType.Repaint: if (GUIUtility.hotControl == controlID && current.mousePosition != PointEditor.s_StartMouseDragPosition) { GUIStyle gUIStyle = "SelectionRect"; Handles.BeginGUI(); gUIStyle.Draw(PointEditor.FromToRect(PointEditor.s_StartMouseDragPosition, current.mousePosition), false, false, false, false); Handles.EndGUI(); } break; case EventType.Layout: HandleUtility.AddDefaultControl(controlID); break; } if (flag) { selection = selection.Distinct <int>().ToList <int>(); } result = flag; } return(result); }
public static bool SelectPoints(IEditablePoint points, Transform cloudTransform, ref List <int> selection, bool firstSelect) { int controlId = GUIUtility.GetControlID(FocusType.Passive); if (Event.current.alt && Event.current.type != EventType.Repaint) { return(false); } bool flag = false; Event current = Event.current; switch (current.GetTypeForControl(controlId)) { case EventType.MouseDown: if ((HandleUtility.nearestControl == controlId || firstSelect) && current.button == 0) { if (!current.shift && !EditorGUI.actionKey) { selection.Clear(); flag = true; } GUIUtility.hotControl = controlId; PointEditor.s_StartMouseDragPosition = current.mousePosition; PointEditor.s_StartDragSelection = new List <int>((IEnumerable <int>)selection); current.Use(); break; } break; case EventType.MouseUp: if (GUIUtility.hotControl == controlId && current.button == 0) { if (!PointEditor.s_DidDrag) { int nearest = PointEditor.FindNearest(PointEditor.s_StartMouseDragPosition, cloudTransform, points); if (nearest != -1) { if (!current.shift && !EditorGUI.actionKey) { selection.Add(nearest); } else { int index = selection.IndexOf(nearest); if (index != -1) { selection.RemoveAt(index); } else { selection.Add(nearest); } } } GUI.changed = true; flag = true; } PointEditor.s_StartDragSelection = (List <int>)null; PointEditor.s_StartMouseDragPosition = Vector2.zero; PointEditor.s_DidDrag = false; GUIUtility.hotControl = 0; current.Use(); break; } break; case EventType.MouseDrag: if (GUIUtility.hotControl == controlId && current.button == 0) { PointEditor.s_DidDrag = true; selection.Clear(); selection.AddRange((IEnumerable <int>)PointEditor.s_StartDragSelection); Rect rect = PointEditor.FromToRect(PointEditor.s_StartMouseDragPosition, current.mousePosition); Matrix4x4 matrix = Handles.matrix; Handles.matrix = cloudTransform.localToWorldMatrix; for (int idx = 0; idx < points.Count; ++idx) { Vector2 guiPoint = HandleUtility.WorldToGUIPoint(points.GetPosition(idx)); if (rect.Contains(guiPoint)) { selection.Add(idx); } } Handles.matrix = matrix; GUI.changed = true; current.Use(); break; } break; case EventType.Repaint: if (GUIUtility.hotControl == controlId && current.mousePosition != PointEditor.s_StartMouseDragPosition) { GUIStyle guiStyle = (GUIStyle)"SelectionRect"; Handles.BeginGUI(); guiStyle.Draw(PointEditor.FromToRect(PointEditor.s_StartMouseDragPosition, current.mousePosition), false, false, false, false); Handles.EndGUI(); break; } break; case EventType.Layout: HandleUtility.AddDefaultControl(controlId); break; } selection = selection.Distinct <int>().ToList <int>(); return(flag); }