示例#1
0
        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();
                    }
                }
            }
        }
示例#2
0
 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();
        }
示例#4
0
 public override void OnEnable()
 {
     base.titleContent = base.GetLocalizedTitleContent();
     this.m_RectSelection = new RectSelection(this);
     if (this.grid == null)
     {
         this.grid = new SceneViewGrid();
     }
     this.grid.Register(this);
     if (this.svRot == null)
     {
         this.svRot = new SceneViewRotation();
     }
     this.svRot.Register(this);
     base.autoRepaintOnSceneChange = true;
     this.m_Rotation.valueChanged.AddListener(new UnityAction(this.Repaint));
     this.m_Position.valueChanged.AddListener(new UnityAction(this.Repaint));
     this.m_Size.valueChanged.AddListener(new UnityAction(this.Repaint));
     this.m_Ortho.valueChanged.AddListener(new UnityAction(this.Repaint));
     base.wantsMouseMove = true;
     base.dontClearBackground = true;
     s_SceneViews.Add(this);
     this.m_Lighting = EditorGUIUtility.IconContent("SceneviewLighting", "Lighting|The scene lighting is used when toggled on. When toggled off a light attached to the scene view camera is used.");
     this.m_Fx = EditorGUIUtility.IconContent("SceneviewFx", "Fx|Toggles skybox, fog and lens flare effects.");
     this.m_AudioPlayContent = EditorGUIUtility.IconContent("SceneviewAudio", "AudioPlay|Toggles audio on or off.");
     this.m_GizmosContent = new GUIContent("Gizmos");
     this.m_2DModeContent = new GUIContent("2D");
     this.m_SceneViewOverlay = new SceneViewOverlay(this);
     EditorApplication.modifierKeysChanged = (EditorApplication.CallbackFunction) Delegate.Combine(EditorApplication.modifierKeysChanged, new EditorApplication.CallbackFunction(SceneView.RepaintAll));
     this.m_DraggingLockedState = DraggingLockedState.NotDragging;
     this.CreateSceneCameraAndLights();
     if (this.m_2DMode)
     {
         this.LookAt(this.pivot, Quaternion.identity, this.size, true, true);
     }
     base.OnEnable();
 }
 private static void UpdateSelection(UnityEngine.Object[] existingSelection, UnityEngine.Object[] newObjects, RectSelection.SelectionType type, bool isRectSelection)
 {
   switch (type)
   {
     case RectSelection.SelectionType.Additive:
       if (newObjects.Length > 0)
       {
         UnityEngine.Object[] objectArray = new UnityEngine.Object[existingSelection.Length + newObjects.Length];
         Array.Copy((Array) existingSelection, (Array) objectArray, existingSelection.Length);
         for (int index = 0; index < newObjects.Length; ++index)
           objectArray[existingSelection.Length + index] = newObjects[index];
         Selection.activeObject = isRectSelection ? objectArray[0] : newObjects[0];
         Selection.objects = objectArray;
         break;
       }
       Selection.objects = existingSelection;
       break;
     case RectSelection.SelectionType.Subtractive:
       Dictionary<UnityEngine.Object, bool> dictionary = new Dictionary<UnityEngine.Object, bool>(existingSelection.Length);
       foreach (UnityEngine.Object key in existingSelection)
         dictionary.Add(key, false);
       foreach (UnityEngine.Object newObject in newObjects)
       {
         if (dictionary.ContainsKey(newObject))
           dictionary.Remove(newObject);
       }
       UnityEngine.Object[] array = new UnityEngine.Object[dictionary.Keys.Count];
       dictionary.Keys.CopyTo(array, 0);
       Selection.objects = array;
       break;
     default:
       Selection.objects = newObjects;
       break;
   }
 }
 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);
 }
示例#7
0
        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();
        }
示例#8
0
		public override void OnEnable()
		{
			this.m_RectSelection = new RectSelection(this);
			if (this.grid == null)
			{
				this.grid = new SceneViewGrid();
			}
			this.grid.Register(this);
			if (this.svRot == null)
			{
				this.svRot = new SceneViewRotation();
			}
			this.svRot.Register(this);
			base.autoRepaintOnSceneChange = true;
			this.m_Rotation.valueChanged.AddListener(new UnityAction(base.Repaint));
			this.m_Position.valueChanged.AddListener(new UnityAction(base.Repaint));
			this.m_Size.valueChanged.AddListener(new UnityAction(base.Repaint));
			this.m_Ortho.valueChanged.AddListener(new UnityAction(base.Repaint));
			base.wantsMouseMove = true;
			base.dontClearBackground = true;
			SceneView.s_SceneViews.Add(this);
			this.m_Lighting = EditorGUIUtility.IconContent("SceneviewLighting");
			this.m_Fx = EditorGUIUtility.IconContent("SceneviewFx");
			this.m_AudioPlayContent = EditorGUIUtility.IconContent("SceneviewAudio");
			this.m_GizmosContent = new GUIContent("Gizmos");
			this.m_2DModeContent = new GUIContent("2D");
			this.m_SceneViewOverlay = new SceneViewOverlay(this);
			EditorApplication.modifierKeysChanged = (EditorApplication.CallbackFunction)Delegate.Combine(EditorApplication.modifierKeysChanged, new EditorApplication.CallbackFunction(SceneView.RepaintAll));
			this.m_DraggingLockedState = SceneView.DraggingLockedState.NotDragging;
			this.CreateSceneCameraAndLights();
			base.OnEnable();
		}
		private static void UpdateSelection(UnityEngine.Object[] existingSelection, UnityEngine.Object[] newObjects, RectSelection.SelectionType type, bool isRectSelection)
		{
			switch (type)
			{
			case RectSelection.SelectionType.Additive:
				if (newObjects.Length > 0)
				{
					UnityEngine.Object[] array = new UnityEngine.Object[existingSelection.Length + newObjects.Length];
					Array.Copy(existingSelection, array, existingSelection.Length);
					for (int i = 0; i < newObjects.Length; i++)
					{
						array[existingSelection.Length + i] = newObjects[i];
					}
					if (!isRectSelection)
					{
						Selection.activeObject = newObjects[0];
					}
					else
					{
						Selection.activeObject = array[0];
					}
					Selection.objects = array;
				}
				else
				{
					Selection.objects = existingSelection;
				}
				return;
			case RectSelection.SelectionType.Subtractive:
			{
				Dictionary<UnityEngine.Object, bool> dictionary = new Dictionary<UnityEngine.Object, bool>(existingSelection.Length);
				for (int j = 0; j < existingSelection.Length; j++)
				{
					UnityEngine.Object key = existingSelection[j];
					dictionary.Add(key, false);
				}
				for (int k = 0; k < newObjects.Length; k++)
				{
					UnityEngine.Object key2 = newObjects[k];
					if (dictionary.ContainsKey(key2))
					{
						dictionary.Remove(key2);
					}
				}
				UnityEngine.Object[] array = new UnityEngine.Object[dictionary.Keys.Count];
				dictionary.Keys.CopyTo(array, 0);
				Selection.objects = array;
				return;
			}
			}
			Selection.objects = newObjects;
		}