Helper functions for Scene View style 3D GUI.

Esempio n. 1
0
        private static void PickAllHandlesNonAlloc(HashSet <GameObject> results, Vector2 position, int limit = DefaultLimit)
        {
            if (!canPickHandles)
            {
                // HandleUtility.PickGameObject is not supported in those contexts
                Debug.LogWarning($"Cannot pick game objects in the current event: {e?.ToString() ?? "null"}");
                return;
            }

            GameObject result = null;

            var count = 0;

            do
            {
                var ignored = results.ToArray();

                result = HandleUtility.PickGameObject(position, false, ignored);

                // Ignored doesn't seem very reliable. Sometimes, an item included
                // in ignored will still be returned. That's a sign we should stop.
                if (results.Contains(result))
                {
                    result = null;
                }

                if (result != null)
                {
                    results.Add(result);
                }
            } while (result != null && count++ < limit);
        }
Esempio n. 2
0
        private static Vector3 DefaultPoint(SceneView sceneView, Vector2 guiPosition)
        {
            var screenPosition = (Vector3)HandleUtility.GUIPointToScreenPixelCoordinate(guiPosition);

            screenPosition.z = sceneView.cameraDistance;
            return(sceneView.camera.ScreenToWorldPoint(screenPosition));
        }
Esempio n. 3
0
 internal static GameObject Internal_PickClosestGO(Camera cam, int layers, Vector2 position, GameObject[] ignore, GameObject[] filter, out int materialIndex)
 {
     return(HandleUtility.INTERNAL_CALL_Internal_PickClosestGO(cam, layers, ref position, ignore, filter, out materialIndex));
 }
Esempio n. 4
0
        private static void PickProBuilderElementsNonAlloc(List <ProbeHit> hits, List <ProBuilderMesh> meshes, SceneView sceneView, Vector2 guiPosition)
        {
            var screenPosition = HandleUtility.GUIPointToScreenPixelCoordinate(guiPosition);
            var worldPosition  = sceneView.camera.ScreenToWorldPoint(screenPosition);

            var pickRadius = PeekPlugin.Configuration.probeProBuilderRadius;

            var pickerOptions = PickerOptions.Default;

            pickerOptions.depthTest = PeekPlugin.Configuration.probeProBuilderDepthTest;

            var pickRect = new Rect
                           (
                guiPosition.x - pickRadius,
                guiPosition.y - pickRadius,
                2 * pickRadius,
                2 * pickRadius
                           );

            var verticesByMeshes = SelectionPicker.PickVerticesInRect(sceneView.camera, pickRect, meshes, pickerOptions, EditorGUIUtility.pixelsPerPoint);

            var edgesByMeshes = SelectionPicker.PickEdgesInRect(sceneView.camera, pickRect, meshes, pickerOptions, EditorGUIUtility.pixelsPerPoint);

            var facesByMeshes = SelectionPicker.PickFacesInRect(sceneView.camera, pickRect, meshes, pickerOptions, EditorGUIUtility.pixelsPerPoint);

            foreach (var verticesByMesh in verticesByMeshes)
            {
                var mesh           = verticesByMesh.Key;
                var gameObject     = mesh.gameObject;
                var vertices       = verticesByMesh.Value;
                var meshVertices   = mesh.GetVertices();
                var sharedVertices = mesh.sharedVertices;

                foreach (var vertexIndex in vertices)
                {
                    var hit = new ProbeHit(gameObject);

                    var vertex            = meshVertices[vertexIndex];
                    var sharedVertex      = sharedVertices[vertexIndex];
                    var sharedVertexIndex = sharedVertex[0];
                    hit.point    = vertex.position;
                    hit.distance = Vector3.Distance(vertex.position, worldPosition);

                    hit.label      = $"{mesh.name}: Vertex {vertexIndex}";
                    hit.icon       = PeekProBuilderIntegration.Icons.vertex;
                    hit.groupOrder = 1;

                    hit.selectHandler = (add) =>
                    {
                        Selection.activeGameObject = gameObject;

                        ProBuilderEditor.selectMode = SelectMode.Vertex;

                        Undo.RecordObject(mesh, "Selection Change");

                        if (add)
                        {
                            mesh.SetSelectedVertices(mesh.selectedVertices.Concat(sharedVertex));
                        }
                        else
                        {
                            mesh.SetSelectedVertices(sharedVertex);
                        }

                        PeekProBuilderIntegration.UpdateSelection();
                    };

                    hit.focusHandler     = () => ProBuilderHighlight(new SceneSelection(mesh, sharedVertexIndex));
                    hit.lostFocusHandler = ClearProBuilderHighlight;

                    hits.Add(hit);
                }
            }

            foreach (var edgesByMesh in edgesByMeshes)
            {
                var mesh           = edgesByMesh.Key;
                var gameObject     = mesh.gameObject;
                var edges          = edgesByMesh.Value;
                var meshVertices   = mesh.GetVertices();
                var sharedVertices = mesh.sharedVertices;

                var visited = HashSetPool <(int, int)> .New();

                foreach (var edge in edges)
                {
                    var hit = new ProbeHit(gameObject);

                    var vertexA = meshVertices[edge.a];
                    var vertexB = meshVertices[edge.b];
                    var center  = (vertexA.position + vertexB.position) / 2;

                    var sharedVertexIndexA = -1;
                    var sharedVertexIndexB = -1;

                    for (var currentSharedIndex = 0; currentSharedIndex < sharedVertices.Count; currentSharedIndex++)
                    {
                        var sharedVertex = sharedVertices[currentSharedIndex];

                        if (sharedVertex.Contains(edge.a))
                        {
                            sharedVertexIndexA = currentSharedIndex;
                        }

                        if (sharedVertex.Contains(edge.b))
                        {
                            sharedVertexIndexB = currentSharedIndex;
                        }
                    }

                    var sharedVertexIndexMin = Mathf.Min(sharedVertexIndexA, sharedVertexIndexB);
                    var sharedVertexIndexMax = Mathf.Max(sharedVertexIndexA, sharedVertexIndexB);

                    if (visited.Contains((sharedVertexIndexMin, sharedVertexIndexMax)))
                    {
                        continue;
                    }

                    hit.point      = center;
                    hit.distance   = Vector3.Distance(center, worldPosition);
                    hit.label      = $"{mesh.name}: Edge [{sharedVertexIndexMin}, {sharedVertexIndexMax}]";
                    hit.icon       = PeekProBuilderIntegration.Icons.edge;
                    hit.groupOrder = 2;

                    hit.selectHandler = (add) =>
                    {
                        Selection.activeGameObject = gameObject;

                        ProBuilderEditor.selectMode = SelectMode.Edge;

                        Undo.RecordObject(mesh, "Selection Change");

                        if (add)
                        {
                            mesh.SetSelectedEdges(mesh.selectedEdges.Append(edge));
                        }
                        else
                        {
                            mesh.SetSelectedEdges(edge.Yield());
                        }

                        PeekProBuilderIntegration.UpdateSelection();
                    };

                    hit.focusHandler     = () => ProBuilderHighlight(new SceneSelection(mesh, edge));
                    hit.lostFocusHandler = ClearProBuilderHighlight;

                    hits.Add(hit);

                    visited.Add((sharedVertexIndexMin, sharedVertexIndexMax));
                }

                visited.Free();
            }

            foreach (var facesByMesh in facesByMeshes)
            {
                var mesh         = facesByMesh.Key;
                var gameObject   = mesh.gameObject;
                var faces        = facesByMesh.Value;
                var meshVertices = mesh.GetVertices();
                var meshFaces    = mesh.faces;

                foreach (var face in faces)
                {
                    var faceIndex = meshFaces.IndexOf(face);

                    var hit = new ProbeHit(gameObject);

                    var center = Vector3.zero;

                    foreach (var vertexIndex in face.distinctIndexes)
                    {
                        var vertex = meshVertices[vertexIndex];
                        center += vertex.position;
                    }

                    center /= face.distinctIndexes.Count;

                    hit.point    = center;
                    hit.distance = Vector3.Distance(center, worldPosition);

                    hit.label      = $"{mesh.name}: Face {faceIndex}";
                    hit.icon       = PeekProBuilderIntegration.Icons.face;
                    hit.groupOrder = 3;

                    hit.selectHandler = (add) =>
                    {
                        Selection.activeGameObject = gameObject;

                        ProBuilderEditor.selectMode = SelectMode.Face;

                        Undo.RecordObject(mesh, "Selection Change");

                        if (add)
                        {
                            mesh.SetSelectedFaces(mesh.GetSelectedFaces().Append(face));
                        }
                        else
                        {
                            mesh.SetSelectedFaces(null);
                            mesh.SetSelectedFaces(face.Yield());
                        }

                        PeekProBuilderIntegration.UpdateSelection();
                    };

                    hit.focusHandler     = () => ProBuilderHighlight(new SceneSelection(mesh, face));
                    hit.lostFocusHandler = ClearProBuilderHighlight;

                    hits.Add(hit);
                }
            }
        }
Esempio n. 5
0
        private static Vector3 MoveHandlesGUI(Rect rect, Vector3 pivot, Quaternion rotation)
        {
            int     controlID = GUIUtility.GetControlID(RectTool.s_MoveHandleHash, FocusType.Passive);
            Vector3 vector    = pivot;
            float   num       = HandleUtility.GetHandleSize(pivot) * 0.2f;
            float   num2      = 1f - GUI.color.a;

            Vector3[] array = new Vector3[]
            {
                rotation *new Vector2(rect.x, rect.y) + pivot,
                rotation *new Vector2(rect.xMax, rect.y) + pivot,
                rotation *new Vector2(rect.xMax, rect.yMax) + pivot,
                rotation *new Vector2(rect.x, rect.yMax) + pivot
            };
            VertexSnapping.HandleKeyAndMouseMove(controlID);
            bool      flag           = Selection.transforms.Length == 1 && InternalEditorUtility.SupportsRectLayout(Selection.activeTransform) && Selection.activeTransform.parent.rotation == rotation;
            Event     current        = Event.current;
            EventType typeForControl = current.GetTypeForControl(controlID);
            Plane     plane          = new Plane(array[0], array[1], array[2]);

            switch (typeForControl)
            {
            case EventType.MouseDown:
            {
                bool flag2 = Tools.vertexDragging || (current.button == 0 && current.modifiers == EventModifiers.None && RectHandles.RaycastGUIPointToWorldHit(current.mousePosition, plane, out RectTool.s_StartMouseWorldPos) && (RectTool.SceneViewDistanceToRectangle(array, current.mousePosition) == 0f || (num2 > 0f && RectTool.SceneViewDistanceToDisc(pivot, rotation * Vector3.forward, num, current.mousePosition) == 0f)));
                if (flag2)
                {
                    RectTool.s_StartPosition = pivot;
                    RectTool.s_StartMousePos = (RectTool.s_CurrentMousePos = current.mousePosition);
                    RectTool.s_Moving        = false;
                    RectTool.s_LockAxis      = -1;
                    int num3 = controlID;
                    GUIUtility.keyboardControl = num3;
                    GUIUtility.hotControl      = num3;
                    EditorGUIUtility.SetWantsMouseJumping(1);
                    HandleUtility.ignoreRaySnapObjects = null;
                    current.Use();
                    if (flag)
                    {
                        Transform     activeTransform = Selection.activeTransform;
                        RectTransform component       = activeTransform.GetComponent <RectTransform>();
                        Transform     parent          = activeTransform.parent;
                        RectTransform component2      = parent.GetComponent <RectTransform>();
                        RectTool.s_StartRectPosition = component.anchoredPosition;
                        RectTransformSnapping.CalculatePositionSnapValues(parent, activeTransform, component2, component);
                    }
                }
                break;
            }

            case EventType.MouseUp:
                if (GUIUtility.hotControl == controlID)
                {
                    if (!RectTool.s_Moving)
                    {
                        Selection.activeGameObject = SceneViewPicking.PickGameObject(current.mousePosition);
                    }
                    GUIUtility.hotControl = 0;
                    EditorGUIUtility.SetWantsMouseJumping(0);
                    HandleUtility.ignoreRaySnapObjects = null;
                    current.Use();
                }
                break;

            case EventType.MouseDrag:
                if (GUIUtility.hotControl == controlID)
                {
                    RectTool.s_CurrentMousePos += current.delta;
                    if (!RectTool.s_Moving && (RectTool.s_CurrentMousePos - RectTool.s_StartMousePos).magnitude > 3f)
                    {
                        RectTool.s_Moving = true;
                        RectHandles.RaycastGUIPointToWorldHit(RectTool.s_CurrentMousePos, plane, out RectTool.s_StartMouseWorldPos);
                    }
                    if (RectTool.s_Moving)
                    {
                        if (Tools.vertexDragging)
                        {
                            if (HandleUtility.ignoreRaySnapObjects == null)
                            {
                                Handles.SetupIgnoreRaySnapObjects();
                            }
                            Vector3 vector2;
                            if (HandleUtility.FindNearestVertex(RectTool.s_CurrentMousePos, null, out vector2))
                            {
                                vector      = vector2;
                                GUI.changed = true;
                            }
                            ManipulationToolUtility.minDragDifference = Vector2.zero;
                        }
                        else
                        {
                            ManipulationToolUtility.SetMinDragDifferenceForPos(pivot);
                            Vector3 a;
                            if (RectHandles.RaycastGUIPointToWorldHit(RectTool.s_CurrentMousePos, plane, out a))
                            {
                                Vector3 vector3 = a - RectTool.s_StartMouseWorldPos;
                                if (current.shift)
                                {
                                    vector3 = Quaternion.Inverse(rotation) * vector3;
                                    if (RectTool.s_LockAxis == -1)
                                    {
                                        RectTool.s_LockAxis = ((Mathf.Abs(vector3.x) <= Mathf.Abs(vector3.y)) ? 1 : 0);
                                    }
                                    vector3[1 - RectTool.s_LockAxis] = 0f;
                                    vector3 = rotation * vector3;
                                }
                                else
                                {
                                    RectTool.s_LockAxis = -1;
                                }
                                if (flag)
                                {
                                    Transform parent2 = Selection.activeTransform.parent;
                                    Vector3   vector4 = RectTool.s_StartRectPosition + parent2.InverseTransformVector(vector3);
                                    vector4.z = 0f;
                                    Quaternion rotation2    = Quaternion.Inverse(rotation);
                                    Vector2    snapDistance = Vector2.one * HandleUtility.GetHandleSize(vector) * 0.05f;
                                    snapDistance.x /= (rotation2 * parent2.TransformVector(Vector3.right)).x;
                                    snapDistance.y /= (rotation2 * parent2.TransformVector(Vector3.up)).y;
                                    Vector3 vector5 = RectTransformSnapping.SnapToGuides(vector4, snapDistance);
                                    ManipulationToolUtility.DisableMinDragDifferenceBasedOnSnapping(vector4, vector5);
                                    vector3 = parent2.TransformVector(vector5 - RectTool.s_StartRectPosition);
                                }
                                vector      = RectTool.s_StartPosition + vector3;
                                GUI.changed = true;
                            }
                        }
                    }
                    current.Use();
                }
                break;

            case EventType.Repaint:
                if (Tools.vertexDragging)
                {
                    RectHandles.RectScalingHandleCap(controlID, pivot, rotation, 1f, EventType.Repaint);
                }
                else
                {
                    Handles.color = Handles.secondaryColor * new Color(1f, 1f, 1f, 1.5f * num2);
                    Handles.CircleHandleCap(controlID, pivot, rotation, num, EventType.Repaint);
                    Handles.color = Handles.secondaryColor * new Color(1f, 1f, 1f, 0.3f * num2);
                    Handles.DrawSolidDisc(pivot, rotation * Vector3.forward, num);
                }
                break;
            }
            ManipulationToolUtility.DetectDraggingBasedOnMouseDownUp("ChangingPosX", typeForControl);
            ManipulationToolUtility.DetectDraggingBasedOnMouseDownUp("ChangingLeft", typeForControl);
            ManipulationToolUtility.DetectDraggingBasedOnMouseDownUp("ChangingRight", typeForControl);
            ManipulationToolUtility.DetectDraggingBasedOnMouseDownUp("ChangingPosY", typeForControl);
            ManipulationToolUtility.DetectDraggingBasedOnMouseDownUp("ChangingTop", typeForControl);
            ManipulationToolUtility.DetectDraggingBasedOnMouseDownUp("ChangingBottom", typeForControl);
            return(vector);
        }
Esempio n. 6
0
 public static void SetMinDragDifferenceForPos(Vector3 position)
 {
     minDragDifference = (Vector3)(Vector3.one * (HandleUtility.GetHandleSize(position) / 80f));
 }
Esempio n. 7
0
        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  result  = 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();
                        result = 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;
                        result      = 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;
            }
            selection = selection.Distinct <int>().ToList <int>();
            return(result);
        }
        public static GameObject PickGameObject(Vector2 mousePosition)
        {
            s_RetainHashes = true;

            var enumerator = GetAllOverlapping(mousePosition).GetEnumerator();

            if (!enumerator.MoveNext())
            {
                return(null);
            }

            var topmost       = enumerator.Current;
            var selectionBase = HandleUtility.FindSelectionBase(topmost);
            var first         = (selectionBase == null ? topmost : selectionBase);
            int topmostHash   = topmost.GetHashCode();
            int prefixHash    = topmostHash;

            if (Selection.activeGameObject == null)
            {
                // Nothing selected
                // Return selection base if it exists, otherwise topmost game object
                s_PreviousTopmostHash = topmostHash;
                s_PreviousPrefixHash  = prefixHash;
                return(first);
            }

            if (topmostHash != s_PreviousTopmostHash)
            {
                // Topmost game object changed
                // Return selection base if exists and is not already selected, otherwise topmost game object
                s_PreviousTopmostHash = topmostHash;
                s_PreviousPrefixHash  = prefixHash;
                return(Selection.activeGameObject == selectionBase ? topmost : first);
            }

            s_PreviousTopmostHash = topmostHash;

            // Pick potential selection base before topmost game object
            if (Selection.activeGameObject == selectionBase)
            {
                if (prefixHash == s_PreviousPrefixHash)
                {
                    return(topmost);
                }
                else
                {
                    s_PreviousPrefixHash = prefixHash;
                    return(selectionBase);
                }
            }

            // Check if active game object will appear in selection stack
            var picked = HandleUtility.PickGameObject(mousePosition, false, null, new GameObject[] { Selection.activeGameObject });

            if (picked == Selection.activeGameObject)
            {
                // Advance enumerator to active game object
                while (enumerator.Current != Selection.activeGameObject)
                {
                    if (!enumerator.MoveNext())
                    {
                        s_PreviousPrefixHash = topmostHash;
                        return(first); // Should not occur
                    }

                    UpdateHash(ref prefixHash, enumerator.Current);
                }
            }

            if (prefixHash != s_PreviousPrefixHash)
            {
                // Prefix hash changed, start over
                s_PreviousPrefixHash = topmostHash;
                return(first);
            }

            // Move on to next game object
            if (!enumerator.MoveNext())
            {
                s_PreviousPrefixHash = topmostHash;
                return(first); // End reached, start over
            }

            UpdateHash(ref prefixHash, enumerator.Current);

            if (enumerator.Current == selectionBase)
            {
                // Skip selection base
                if (!enumerator.MoveNext())
                {
                    s_PreviousPrefixHash = topmostHash;
                    return(first); // End reached, start over
                }

                UpdateHash(ref prefixHash, enumerator.Current);
            }

            s_PreviousPrefixHash = prefixHash;
            return(enumerator.Current);
        }
Esempio n. 9
0
        private Vector3 EdgeHandle(Vector3 handlePos, Vector3 handleDir, Vector3 slideDir1, Vector3 slideDir2, Matrix4x4 transform)
        {
            Color color = Handles.color;
            bool  flag  = true;

            if (Camera.current)
            {
                Vector3 b          = Handles.matrix.inverse.MultiplyPoint(Camera.current.transform.position);
                Vector3 normalized = (handlePos - b).normalized;
                Vector3 lhs        = Vector3.Cross(slideDir1, slideDir2);
                float   f          = Vector3.Dot(lhs, normalized);
                if (Mathf.Acos(Mathf.Abs(f)) > 1.51843643f)
                {
                    flag = false;
                }
            }
            float num = (!flag) ? 0f : 1f;

            this.AdjustEdgeHandleColor(handlePos, slideDir1, slideDir2, transform, num);
            int controlID = GUIUtility.GetControlID(this.m_ControlIdHint, FocusType.Keyboard);

            if (num > 0f)
            {
                handlePos = Slider2D.Do(controlID, handlePos, handleDir, slideDir1, slideDir2, HandleUtility.GetHandleSize(handlePos) * 0.03f, new Handles.DrawCapFunction(Handles.DotCap), SnapSettings.scale, true);
            }
            Handles.color = color;
            return(handlePos);
        }
Esempio n. 10
0
 private static float DefaultMidpointGetSizeFunc(Vector3 localPos)
 {
     return(HandleUtility.GetHandleSize(localPos) * 0.03f);
 }
Esempio n. 11
0
        internal static Quaternion DoRotationHandle(RotationHandleIds ids, Quaternion rotation, Vector3 position, RotationHandleParam param)
        {
            var evt        = Event.current;
            var camForward = Handles.inverseMatrix.MultiplyVector(Camera.current.transform.forward);

            var size     = HandleUtility.GetHandleSize(position);
            var temp     = color;
            var isStatic = (!Tools.s_Hidden && EditorApplication.isPlaying && GameObjectUtility.ContainsStatic(Selection.gameObjects));

            var isHot = ids.Has(GUIUtility.hotControl);

            // Draw freerotation first to give it the lowest priority
            if (!isStatic &&
                param.ShouldShow(RotationHandleParam.Handle.XYZ) &&
                (isHot && ids.xyz == GUIUtility.hotControl || !isHot))
            {
                color    = centerColor;
                rotation = UnityEditorInternal.FreeRotate.Do(ids.xyz, rotation, position, size * param.xyzSize, param.displayXYZCircle);
            }

            var radiusOfAxesHandles = -1f;

            for (var i = 0; i < 3; ++i)
            {
                if (!param.ShouldShow(i))
                {
                    continue;
                }

                var axisColor = GetColorByAxis(i);
                color = isStatic ? Color.Lerp(axisColor, staticColor, staticBlend) : axisColor;
                color = ToActiveColorSpace(color);
                var axisDir = GetAxisVector(i);

                var radius = size * param.axisSize[i];
                radiusOfAxesHandles = Mathf.Max(radius, radiusOfAxesHandles);

                rotation = UnityEditorInternal.Disc.Do(ids[i], rotation, position, rotation * axisDir, radius, true, SnapSettings.rotation, param.enableRayDrag, true, k_RotationPieColor);
            }

            if (radiusOfAxesHandles > 0 && evt.type == EventType.Repaint)
            {
                Handles.color = new Color(0, 0, 0, 0.2f);
                Handles.DrawWireDisc(position, camForward, radiusOfAxesHandles);
            }

            if (isHot && evt.type == EventType.Repaint)
            {
                color = ToActiveColorSpace(s_DisabledHandleColor);
                Handles.DrawWireDisc(position, camForward, size * param.axisSize[0]);
            }

            if (!isStatic &&
                param.ShouldShow(RotationHandleParam.Handle.CameraAxis) &&
                (isHot && ids.cameraAxis == GUIUtility.hotControl || !isHot))
            {
                color    = ToActiveColorSpace(centerColor);
                rotation = UnityEditorInternal.Disc.Do(ids.cameraAxis, rotation, position, camForward, size * param.cameraAxisSize, false, 0, param.enableRayDrag, true, k_RotationPieColor);
            }

            color = temp;
            return(rotation);
        }
Esempio n. 12
0
        // Ensure all controlIDs used in this OnGUI are permanent controlIDs so this method can be called
        // in different places for handling input early and rendering late.
        internal void OnGUI(SceneView view)
        {
            Rect  cameraGUIRect = view.cameraRect;
            float screenSize    = Mathf.Min(cameraGUIRect.width, cameraGUIRect.height);

            if (screenSize < kRotationSize)
            {
                return;
            }

            if (Event.current.type == EventType.Repaint)
            {
                Profiler.BeginSample("SceneView.AxisSelector");
            }

            HandleContextClick(view);

            // This is a pretty weird way of doing things, but it works, so...
            Camera cam = view.camera;

            HandleUtility.PushCamera(cam);
            if (cam.orthographic)
            {
                cam.orthographicSize = .5f;
            }

            cam.cullingMask        = 0;
            cam.transform.position = cam.transform.rotation * new Vector3(0, 0, -5);
            cam.clearFlags         = CameraClearFlags.Nothing;
            cam.nearClipPlane      = .1f;
            cam.farClipPlane       = 10;
            cam.fieldOfView        = view.m_Ortho.Fade(70, 0);

            SceneView.AddCursorRect(new Rect(cameraGUIRect.width - kRotationSize + kRotationMenuInset, kRotationMenuInset, kRotationSize - 2 * kRotationMenuInset, kRotationSize + 24 - kRotationMenuInset), MouseCursor.Arrow);

            Handles.SetCamera(new Rect(cameraGUIRect.width - kRotationSize, 0, kRotationSize, kRotationSize), cam);

            Handles.BeginGUI();

            DrawRotationLock(view);
            DrawLabels(view);

            Handles.EndGUI();

            // animate visibility of three axis widgets
            for (int i = 0; i < 3; ++i)
            {
                Vector3 direction = kDirectionRotations[i] * Vector3.forward;
                dirVisible[i].target = Mathf.Abs(Vector3.Dot(cam.transform.forward, direction)) < 0.9f;
            }

            float size = HandleUtility.GetHandleSize(Vector3.zero) * .2f;

            // Do axes behind the center one
            AxisSelectors(view, cam, size, -1.0f, styles.viewAxisLabelStyle);

            // Do center handle

            Color centerColor = Handles.centerColor;

            centerColor    = Color.Lerp(centerColor, Color.gray, faded2Dgray);
            centerColor.a *= fadedVisibility;
            if (centerColor.a <= 0.1f || view.isRotationLocked)
            {
                GUI.enabled = false;
            }

            Handles.color = centerColor;
            if (Handles.Button(m_CenterButtonControlID, Vector3.zero, Quaternion.identity, size * 0.8f, size, Handles.CubeHandleCap) && !view.in2DMode && !view.isRotationLocked)
            {
                if (Event.current.clickCount == 2)
                {
                    view.FrameSelected();
                }
                else
                {
                    // If middle-click or shift-click, choose a perspective view from a nice angle,
                    // similar to in Unity 3.5.
                    if (Event.current.shift || Event.current.button == 2)
                    {
                        ViewFromNiceAngle(view, true);
                    }
                    // Else, toggle perspective
                    else
                    {
                        ViewSetOrtho(view, !view.orthographic);
                    }
                }
            }

            // Do axes in front of the center one
            AxisSelectors(view, cam, size, 1.0f, styles.viewAxisLabelStyle);

            GUI.enabled = true;

            if (!view.in2DMode && !view.isRotationLocked)
            {
                // Swipe handling
                if (Event.current.type == EditorGUIUtility.swipeGestureEventType)
                {
                    // Get swipe dir as Vector3
                    Event   evt = Event.current;
                    Vector3 swipeDir;
                    if (evt.delta.y > 0)
                    {
                        swipeDir = Vector3.up;
                    }
                    else if (evt.delta.y < 0)
                    {
                        swipeDir = -Vector3.up;
                    }
                    else if (evt.delta.x < 0) // delta x inverted for some reason
                    {
                        swipeDir = Vector3.right;
                    }
                    else
                    {
                        swipeDir = -Vector3.right;
                    }

                    // Inverse swipe dir, so swiping down will go to top view etc.
                    // This is consistent with how we do orbiting, where moving the mouse down sees the object more from above etc.
                    // Also, make swipe dir point almost 45 degrees in towards the camera.
                    // This means the swipe will pick the closest axis in the swiped direction,
                    // instead of picking the one closest to being 90 degrees away.
                    Vector3 goalVector = -swipeDir - Vector3.forward * 0.9f;

                    // Transform swipe dir by camera transform, so up is camera's local up, etc.
                    goalVector = view.camera.transform.TransformDirection(goalVector);

                    // Get global axis that's closest to the swipe dir vector
                    float bestDotProduct = 0;
                    int   dir            = 0;
                    for (int i = 0; i < 6; i++)
                    {
                        // Note that kDirectionRotations are not the forward direction of each dir;
                        // it's the back direction *towards* the camera.
                        float dotProduct = Vector3.Dot(kDirectionRotations[i] * -Vector3.forward, goalVector);
                        if (dotProduct > bestDotProduct)
                        {
                            bestDotProduct = dotProduct;
                            dir            = i;
                        }
                    }

                    // Look along chosen axis
                    ViewAxisDirection(view, dir);
                    Event.current.Use();
                }
            }

            HandleUtility.PopCamera(cam);
            Handles.SetCamera(cam);

            if (Event.current.type == EventType.Repaint)
            {
                Profiler.EndSample();
            }
        }
        public override void OnPreviewGUI(Rect r, GUIStyle background)
        {
            if (Event.current.type == EventType.Repaint)
            {
                background.Draw(r, false, false, false, false);
            }

            // show texture
            Texture t = target as Texture;

            if (t == null) // texture might be gone by now, in case this code is used for floating texture preview
            {
                return;
            }

            // Render target must be created before we can display it (case 491797)
            RenderTexture rt = t as RenderTexture;

            if (rt != null)
            {
                if (!SystemInfo.IsFormatSupported(rt.graphicsFormat, FormatUsage.Render))
                {
                    return; // can't do this RT format
                }
                rt.Create();
            }

            if (IsCubemap())
            {
                m_CubemapPreview.OnPreviewGUI(t, r, background);
                return;
            }

            // target can report zero sizes in some cases just after a parameter change;
            // guard against that.
            int texWidth  = Mathf.Max(t.width, 1);
            int texHeight = Mathf.Max(t.height, 1);

            float mipLevel   = GetMipLevelForRendering();
            float zoomLevel  = Mathf.Min(Mathf.Min(r.width / texWidth, r.height / texHeight), 1);
            Rect  wantedRect = new Rect(r.x, r.y, texWidth * zoomLevel, texHeight * zoomLevel);

            PreviewGUI.BeginScrollView(r, m_Pos, wantedRect, "PreHorizontalScrollbar", "PreHorizontalScrollbarThumb");
            FilterMode oldFilter = t.filterMode;

            TextureUtil.SetFilterModeNoDirty(t, FilterMode.Point);
            Texture2D      t2d            = t as Texture2D;
            ColorWriteMask colorWriteMask = ColorWriteMask.All;

            switch (m_PreviewMode)
            {
            case PreviewMode.R:
                colorWriteMask = ColorWriteMask.Red | ColorWriteMask.Alpha;
                break;

            case PreviewMode.G:
                colorWriteMask = ColorWriteMask.Green | ColorWriteMask.Alpha;
                break;

            case PreviewMode.B:
                colorWriteMask = ColorWriteMask.Blue | ColorWriteMask.Alpha;
                break;
            }

            if (m_PreviewMode == PreviewMode.A)
            {
                EditorGUI.DrawTextureAlpha(wantedRect, t, ScaleMode.StretchToFill, 0, mipLevel);
            }
            else
            {
                if (t2d != null && t2d.alphaIsTransparency)
                {
                    EditorGUI.DrawTextureTransparent(wantedRect, t, ScaleMode.StretchToFill, 0, mipLevel, colorWriteMask);
                }
                else
                {
                    EditorGUI.DrawPreviewTexture(wantedRect, t, null, ScaleMode.StretchToFill, 0, mipLevel, colorWriteMask);
                }
            }

            // TODO: Less hacky way to prevent sprite rects to not appear in smaller previews like icons.
            if ((wantedRect.width > 32 && wantedRect.height > 32) && Event.current.type == EventType.Repaint)
            {
                string           path            = AssetDatabase.GetAssetPath(t);
                TextureImporter  textureImporter = AssetImporter.GetAtPath(path) as TextureImporter;
                SpriteMetaData[] spritesheet     = textureImporter != null ? textureImporter.spritesheet : null;

                if (spritesheet != null && textureImporter.spriteImportMode == SpriteImportMode.Multiple)
                {
                    Rect screenRect = new Rect();
                    Rect sourceRect = new Rect();
                    GUI.CalculateScaledTextureRects(wantedRect, ScaleMode.StretchToFill, (float)t.width / (float)t.height, ref screenRect, ref sourceRect);

                    int origWidth  = t.width;
                    int origHeight = t.height;
                    textureImporter.GetWidthAndHeight(ref origWidth, ref origHeight);
                    float definitionScale = (float)t.width / (float)origWidth;

                    HandleUtility.ApplyWireMaterial();
                    GL.PushMatrix();
                    GL.MultMatrix(Handles.matrix);
                    GL.Begin(GL.LINES);
                    GL.Color(new Color(1f, 1f, 1f, 0.5f));
                    foreach (SpriteMetaData sprite in spritesheet)
                    {
                        Rect spriteRect       = sprite.rect;
                        Rect spriteScreenRect = new Rect();
                        spriteScreenRect.xMin = screenRect.xMin + screenRect.width * (spriteRect.xMin / t.width * definitionScale);
                        spriteScreenRect.xMax = screenRect.xMin + screenRect.width * (spriteRect.xMax / t.width * definitionScale);
                        spriteScreenRect.yMin = screenRect.yMin + screenRect.height * (1f - spriteRect.yMin / t.height * definitionScale);
                        spriteScreenRect.yMax = screenRect.yMin + screenRect.height * (1f - spriteRect.yMax / t.height * definitionScale);
                        DrawRect(spriteScreenRect);
                    }
                    GL.End();
                    GL.PopMatrix();
                }
            }

            TextureUtil.SetFilterModeNoDirty(t, oldFilter);

            m_Pos = PreviewGUI.EndScrollView();
            if (mipLevel != 0)
            {
                EditorGUI.DropShadowLabel(new Rect(r.x, r.y, r.width, 20), "Mip " + mipLevel);
            }
        }
Esempio n. 14
0
 protected static float GetAngularLimitHandleSize(Vector3 position)
 {
     return(HandleUtility.GetHandleSize(position));
 }
Esempio n. 15
0
        internal static void ApplyDottedWireMaterial()
        {
            CompareFunction zTest = CompareFunction.Always;

            HandleUtility.ApplyDottedWireMaterial(zTest);
        }
Esempio n. 16
0
        public override void OnPreviewGUI(Rect r, GUIStyle background)
        {
            if (Event.current.type == EventType.Repaint)
            {
                background.Draw(r, false, false, false, false);
            }
            Texture texture = base.target as Texture;

            if (!(texture == null))
            {
                RenderTexture renderTexture = texture as RenderTexture;
                if (renderTexture != null)
                {
                    if (!SystemInfo.SupportsRenderTextureFormat(renderTexture.format))
                    {
                        return;
                    }
                    renderTexture.Create();
                }
                if (this.IsCubemap())
                {
                    this.m_CubemapPreview.OnPreviewGUI(texture, r, background);
                }
                else
                {
                    int   num  = Mathf.Max(texture.width, 1);
                    int   num2 = Mathf.Max(texture.height, 1);
                    float mipLevelForRendering = this.GetMipLevelForRendering();
                    float num3 = Mathf.Min(Mathf.Min(r.width / (float)num, r.height / (float)num2), 1f);
                    Rect  rect = new Rect(r.x, r.y, (float)num * num3, (float)num2 * num3);
                    PreviewGUI.BeginScrollView(r, this.m_Pos, rect, "PreHorizontalScrollbar", "PreHorizontalScrollbarThumb");
                    FilterMode filterMode = texture.filterMode;
                    TextureUtil.SetFilterModeNoDirty(texture, FilterMode.Point);
                    Texture2D texture2D = texture as Texture2D;
                    if (this.m_ShowAlpha)
                    {
                        EditorGUI.DrawTextureAlpha(rect, texture, ScaleMode.StretchToFill, 0f, mipLevelForRendering);
                    }
                    else if (texture2D != null && texture2D.alphaIsTransparency)
                    {
                        EditorGUI.DrawTextureTransparent(rect, texture, ScaleMode.StretchToFill, 0f, mipLevelForRendering);
                    }
                    else
                    {
                        EditorGUI.DrawPreviewTexture(rect, texture, null, ScaleMode.StretchToFill, 0f, mipLevelForRendering);
                    }
                    if (rect.width > 32f && rect.height > 32f)
                    {
                        string           assetPath       = AssetDatabase.GetAssetPath(texture);
                        TextureImporter  textureImporter = AssetImporter.GetAtPath(assetPath) as TextureImporter;
                        SpriteMetaData[] array           = (!(textureImporter != null)) ? null : textureImporter.spritesheet;
                        if (array != null && textureImporter.spriteImportMode == SpriteImportMode.Multiple)
                        {
                            Rect rect2 = default(Rect);
                            Rect rect3 = default(Rect);
                            GUI.CalculateScaledTextureRects(rect, ScaleMode.StretchToFill, (float)texture.width / (float)texture.height, ref rect2, ref rect3);
                            int width  = texture.width;
                            int height = texture.height;
                            textureImporter.GetWidthAndHeight(ref width, ref height);
                            float num4 = (float)texture.width / (float)width;
                            HandleUtility.ApplyWireMaterial();
                            GL.PushMatrix();
                            GL.MultMatrix(Handles.matrix);
                            GL.Begin(1);
                            GL.Color(new Color(1f, 1f, 1f, 0.5f));
                            SpriteMetaData[] array2 = array;
                            for (int i = 0; i < array2.Length; i++)
                            {
                                SpriteMetaData spriteMetaData = array2[i];
                                Rect           rect4          = spriteMetaData.rect;
                                this.DrawRect(new Rect
                                {
                                    xMin = rect2.xMin + rect2.width * (rect4.xMin / (float)texture.width * num4),
                                    xMax = rect2.xMin + rect2.width * (rect4.xMax / (float)texture.width * num4),
                                    yMin = rect2.yMin + rect2.height * (1f - rect4.yMin / (float)texture.height * num4),
                                    yMax = rect2.yMin + rect2.height * (1f - rect4.yMax / (float)texture.height * num4)
                                });
                            }
                            GL.End();
                            GL.PopMatrix();
                        }
                    }
                    TextureUtil.SetFilterModeNoDirty(texture, filterMode);
                    this.m_Pos = PreviewGUI.EndScrollView();
                    if (mipLevelForRendering != 0f)
                    {
                        EditorGUI.DropShadowLabel(new Rect(r.x, r.y, r.width, 20f), "Mip " + mipLevelForRendering);
                    }
                }
            }
        }
Esempio n. 17
0
        public void TimeRuler(Rect position, float frameRate, bool labels, bool useEntireHeight, float alpha,
                              TimeFormat timeFormat)
        {
            Color backupCol = GUI.color;

            GUI.BeginGroup(position);
            InitStyles();

            HandleUtility.ApplyWireMaterial();

            Color tempBackgroundColor = GUI.backgroundColor;

            SetTickMarkerRanges();
            hTicks.SetTickStrengths(kTickRulerDistMin, kTickRulerDistFull, true);

            Color baseColor = timeAreaStyles.timelineTick.normal.textColor;

            baseColor.a = 0.75f * alpha;

            if (Event.current.type == EventType.Repaint)
            {
                if (Application.platform == RuntimePlatform.WindowsEditor)
                {
                    GL.Begin(GL.QUADS);
                }
                else
                {
                    GL.Begin(GL.LINES);
                }

                // Draw tick markers of various sizes

                Rect cachedShowArea = shownArea;
                for (int l = 0; l < hTicks.tickLevels; l++)
                {
                    float strength = hTicks.GetStrengthOfLevel(l) * .9f;
                    m_TickCache.Clear();
                    hTicks.GetTicksAtLevel(l, true, m_TickCache);
                    for (int i = 0; i < m_TickCache.Count; i++)
                    {
                        if (m_TickCache[i] < hRangeMin || m_TickCache[i] > hRangeMax)
                        {
                            continue;
                        }
                        int frame = Mathf.RoundToInt(m_TickCache[i] * frameRate);

                        float height = useEntireHeight
                            ? position.height
                            : position.height * Mathf.Min(1, strength) * kTickRulerHeightMax;
                        float x = FrameToPixel(frame, frameRate, position, cachedShowArea);

                        // Draw line
                        DrawVerticalLineFast(x, position.height - height + 0.5f, position.height - 0.5f,
                                             new Color(1, 1, 1, strength / kTickRulerFatThreshold) * baseColor);
                    }
                }

                GL.End();
            }

            if (labels)
            {
                // Draw tick labels
                int labelLevel = hTicks.GetLevelWithMinSeparation(kTickRulerDistLabel);
                m_TickCache.Clear();
                hTicks.GetTicksAtLevel(labelLevel, false, m_TickCache);
                for (int i = 0; i < m_TickCache.Count; i++)
                {
                    if (m_TickCache[i] < hRangeMin || m_TickCache[i] > hRangeMax)
                    {
                        continue;
                    }

                    int frame = Mathf.RoundToInt(m_TickCache[i] * frameRate);
                    // Important to take floor of positions of GUI stuff to get pixel correct alignment of
                    // stuff drawn with both GUI and Handles/GL. Otherwise things are off by one pixel half the time.

                    float  labelpos = Mathf.Floor(FrameToPixel(frame, frameRate, position));
                    string label    = FormatTickTime(m_TickCache[i], frameRate, timeFormat);
                    GUI.Label(new Rect(labelpos + 3, -3, 40, 20), label, timeAreaStyles.timelineTick);
                }
            }
            GUI.EndGroup();

            GUI.backgroundColor = tempBackgroundColor;
            GUI.color           = backupCol;
        }
Esempio n. 18
0
        public static void OnSceneDrag(SceneView sceneView)
        {
            Event current1 = Event.current;

            if (current1.type != EventType.DragUpdated && current1.type != EventType.DragPerform && current1.type != EventType.DragExited)
            {
                return;
            }
            if (!sceneView.in2DMode)
            {
                GameObject gameObject = HandleUtility.PickGameObject(Event.current.mousePosition, true);
                if ((UnityEngine.Object)gameObject != (UnityEngine.Object)null && DragAndDrop.objectReferences.Length == 1 && ((UnityEngine.Object)(DragAndDrop.objectReferences[0] as Texture) != (UnityEngine.Object)null && (UnityEngine.Object)gameObject.GetComponent <Renderer>() != (UnityEngine.Object)null))
                {
                    return;
                }
            }
            switch (current1.type)
            {
            case EventType.DragUpdated:
                SpriteUtility.DragType dragType = !current1.alt ? SpriteUtility.DragType.SpriteAnimation : SpriteUtility.DragType.CreateMultiple;
                if (SpriteUtility.s_DragType != dragType || SpriteUtility.s_SceneDragObjects == null)
                {
                    Sprite[] draggedPathsOrObjects = SpriteUtility.GetSpriteFromDraggedPathsOrObjects();
                    if (draggedPathsOrObjects == null || draggedPathsOrObjects.Length == 0 || (UnityEngine.Object)draggedPathsOrObjects[0] == (UnityEngine.Object)null)
                    {
                        break;
                    }
                    if (SpriteUtility.s_DragType != SpriteUtility.DragType.NotInitialized)
                    {
                        SpriteUtility.CleanUp();
                    }
                    SpriteUtility.s_DragType         = dragType;
                    SpriteUtility.s_SceneDragObjects = new List <UnityEngine.Object>();
                    if (SpriteUtility.s_DragType == SpriteUtility.DragType.CreateMultiple)
                    {
                        foreach (Sprite frame in draggedPathsOrObjects)
                        {
                            SpriteUtility.s_SceneDragObjects.Add((UnityEngine.Object)SpriteUtility.CreateDragGO(frame, Vector3.zero));
                        }
                    }
                    else
                    {
                        SpriteUtility.s_SceneDragObjects.Add((UnityEngine.Object)SpriteUtility.CreateDragGO(draggedPathsOrObjects[0], Vector3.zero));
                    }
                    List <Transform> transformList = new List <Transform>();
                    using (List <UnityEngine.Object> .Enumerator enumerator = SpriteUtility.s_SceneDragObjects.GetEnumerator())
                    {
                        while (enumerator.MoveNext())
                        {
                            GameObject current2 = (GameObject)enumerator.Current;
                            transformList.AddRange((IEnumerable <Transform>)current2.GetComponentsInChildren <Transform>());
                            current2.hideFlags = HideFlags.HideInHierarchy;
                        }
                    }
                    HandleUtility.ignoreRaySnapObjects = transformList.ToArray();
                }
                Vector3 zero  = Vector3.zero;
                Vector3 point = HandleUtility.GUIPointToWorldRay(current1.mousePosition).GetPoint(10f);
                if (sceneView.in2DMode)
                {
                    point.z = 0.0f;
                }
                else
                {
                    DragAndDrop.visualMode = DragAndDropVisualMode.Copy;
                    object obj = HandleUtility.RaySnap(HandleUtility.GUIPointToWorldRay(current1.mousePosition));
                    if (obj != null)
                    {
                        point = ((RaycastHit)obj).point;
                    }
                }
                using (List <UnityEngine.Object> .Enumerator enumerator = SpriteUtility.s_SceneDragObjects.GetEnumerator())
                {
                    while (enumerator.MoveNext())
                    {
                        ((GameObject)enumerator.Current).transform.position = point;
                    }
                }
                DragAndDrop.visualMode = DragAndDropVisualMode.Copy;
                current1.Use();
                break;

            case EventType.DragPerform:
                Sprite[] draggedPathsOrObjects1 = SpriteUtility.GetSpriteFromDraggedPathsOrObjects();
                if (draggedPathsOrObjects1 == null || SpriteUtility.s_SceneDragObjects == null)
                {
                    break;
                }
                if (SpriteUtility.s_DragType == SpriteUtility.DragType.SpriteAnimation)
                {
                    SpriteUtility.AddAnimationToGO((GameObject)SpriteUtility.s_SceneDragObjects[0], draggedPathsOrObjects1);
                }
                using (List <UnityEngine.Object> .Enumerator enumerator = SpriteUtility.s_SceneDragObjects.GetEnumerator())
                {
                    while (enumerator.MoveNext())
                    {
                        GameObject current2 = (GameObject)enumerator.Current;
                        Undo.RegisterCreatedObjectUndo((UnityEngine.Object)current2, "Create Sprite");
                        current2.hideFlags = HideFlags.None;
                    }
                }
                Selection.objects = SpriteUtility.s_SceneDragObjects.ToArray();
                SpriteUtility.CleanUp();
                current1.Use();
                break;

            case EventType.DragExited:
                if (SpriteUtility.s_SceneDragObjects == null || SpriteUtility.s_SceneDragObjects == null)
                {
                    break;
                }
                using (List <UnityEngine.Object> .Enumerator enumerator = SpriteUtility.s_SceneDragObjects.GetEnumerator())
                {
                    while (enumerator.MoveNext())
                    {
                        UnityEngine.Object.DestroyImmediate(enumerator.Current, false);
                    }
                }
                SpriteUtility.CleanUp();
                current1.Use();
                break;
            }
        }
Esempio n. 19
0
 static void OnEndContainer(IMGUIContainer c)
 {
     HandleUtility.EndHandles();
 }
        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;
        }
Esempio n. 21
0
        public static void HandleSpriteSceneDrag(SceneView sceneView, IEvent evt, Object[] objectReferences, string[] paths, ShowFileDialogDelegate saveFileDialog)
        {
            if (evt.type != EventType.DragUpdated && evt.type != EventType.DragPerform && evt.type != EventType.DragExited)
            {
                return;
            }

            // Return if any of the dragged objects are null, e.g. a MonoBehaviour without a managed instance
            if (objectReferences.Any(obj => obj == null))
            {
                return;
            }

            // Regardless of EditorBehaviorMode or SceneView mode we don't handle if texture is dragged over a GO with renderer
            if (objectReferences.Length == 1 && objectReferences[0] as UnityTexture2D != null)
            {
                GameObject go = HandleUtility.PickGameObject(evt.mousePosition, true);
                if (go != null)
                {
                    var renderer = go.GetComponent <Renderer>();
                    if (renderer != null && !(renderer is SpriteRenderer))
                    {
                        // There is an object where the cursor is
                        // and we are dragging a texture. Most likely user wants to
                        // assign texture to the GO
                        // Case 730444: Proceed only if the go has a renderer
                        CleanUp(true);
                        return;
                    }
                }
            }

            switch (evt.type)
            {
            case (EventType.DragUpdated):
                DragType newDragType = evt.alt ? DragType.CreateMultiple : DragType.SpriteAnimation;

                if (s_DragType != newDragType || s_SceneDragObjects == null)               // Either this is first time we are here OR evt.alt changed during drag
                {
                    if (!ExistingAssets(objectReferences) && PathsAreValidTextures(paths)) // External drag with images that are not in the project
                    {
                        DragAndDrop.visualMode = DragAndDropVisualMode.Copy;
                        s_SceneDragObjects     = new List <Object>();
                        s_DragType             = newDragType;
                    }
                    else     // Internal drag with assets from project
                    {
                        List <Sprite> assets = GetSpriteFromPathsOrObjects(objectReferences, paths, evt.type);

                        if (assets.Count == 0)
                        {
                            return;
                        }

                        if (s_DragType != DragType.NotInitialized)     // evt.alt changed during drag, so we need to cleanup and start over
                        {
                            CleanUp(true);
                        }

                        s_DragType = newDragType;
                        CreateSceneDragObjects(assets);
                        IgnoreForRaycasts(s_SceneDragObjects);
                    }
                }

                PositionSceneDragObjects(s_SceneDragObjects, sceneView, evt.mousePosition);

                DragAndDrop.visualMode = DragAndDropVisualMode.Copy;
                evt.Use();
                break;

            case (EventType.DragPerform):
                List <Sprite> sprites = GetSpriteFromPathsOrObjects(objectReferences, paths, evt.type);

                if (sprites.Count > 0 && s_SceneDragObjects != null)
                {
                    // Store current undoIndex to undo all operations done if any part of sprite creation fails
                    int undoIndex = Undo.GetCurrentGroup();

                    // For external drags, we have delayed all creation to DragPerform because only now we have the imported sprite assets
                    if (s_SceneDragObjects.Count == 0)
                    {
                        CreateSceneDragObjects(sprites);
                        PositionSceneDragObjects(s_SceneDragObjects, sceneView, evt.mousePosition);
                    }

                    foreach (GameObject dragGO in s_SceneDragObjects)
                    {
                        dragGO.hideFlags = HideFlags.None;
                        Undo.RegisterCreatedObjectUndo(dragGO, "Create Sprite");
                        EditorUtility.SetDirty(dragGO);
                    }

                    bool createGameObject = true;
                    if (s_DragType == DragType.SpriteAnimation && sprites.Count > 1)
                    {
                        UsabilityAnalytics.Event("Sprite Drag and Drop", "Drop multiple sprites to scene", "null", 1);
                        createGameObject = AddAnimationToGO((GameObject)s_SceneDragObjects[0], sprites.ToArray(), saveFileDialog);
                    }
                    else
                    {
                        UsabilityAnalytics.Event("Sprite Drag and Drop", "Drop single sprite to scene", "null", 1);
                    }

                    if (createGameObject)
                    {
                        Selection.objects = s_SceneDragObjects.ToArray();
                    }
                    else
                    {
                        // Revert all Create Sprite actions if animation failed to be created or was cancelled
                        Undo.RevertAllDownToGroup(undoIndex);
                    }
                    CleanUp(!createGameObject);
                    evt.Use();
                }
                break;

            case EventType.DragExited:
                if (s_SceneDragObjects != null)
                {
                    CleanUp(true);
                    evt.Use();
                }
                break;
            }
        }
        private static void DrawGrid(Vector3 pos, Vector3 axis1, Vector3 axis2, Vector3 normal, Color color)
        {
            if (Event.current.type != EventType.Repaint)
            {
                return;
            }

            HandleUtility.ApplyWireMaterial();

            if (color.a > 0)
            {
                GL.Begin(GL.LINES);

                float lineLength = 10f;
                int   numLines   = 11;

                lineLength *= m_ScaleGrid;
                numLines    = (int)lineLength;
                numLines    = Mathf.Clamp(numLines, 10, 40);
                if (numLines % 2 == 0)
                {
                    numLines++;
                }

                float halfLength = lineLength * 0.5f;

                float   distBetweenLines = lineLength / (numLines - 1);
                Vector3 v1       = axis1 * lineLength;
                Vector3 v2       = axis2 * lineLength;
                Vector3 dist1    = axis1 * distBetweenLines;
                Vector3 dist2    = axis2 * distBetweenLines;
                Vector3 startPos = pos - axis1 * halfLength - axis2 * halfLength;

                for (int i = 0; i < numLines; i++)
                {
                    if (i % 2 == 0)
                    {
                        GL.Color(color * 0.7f);
                    }
                    else
                    {
                        GL.Color(color);
                    }

                    // Axis1
                    GL.Vertex(startPos + i * dist1);
                    GL.Vertex(startPos + i * dist1 + v2);

                    // Axis2
                    GL.Vertex(startPos + i * dist2);
                    GL.Vertex(startPos + i * dist2 + v1);
                }

                GL.Color(color);
                GL.Vertex(pos);
                GL.Vertex(pos + normal);


                GL.End();
            }
        }
Esempio n. 23
0
        private static Vector3 ResizeHandlesGUI(Rect rect, Vector3 pivot, Quaternion rotation, out Vector3 scalePivot)
        {
            if (Event.current.type == EventType.MouseDown)
            {
                RectTool.s_StartRect = rect;
            }
            scalePivot = pivot;
            Vector3    result    = Vector3.one;
            Quaternion rotation2 = Quaternion.Inverse(rotation);

            for (int i = 0; i <= 2; i++)
            {
                for (int j = 0; j <= 2; j++)
                {
                    if (i != 1 || j != 1)
                    {
                        Vector3 rectPointInWorld  = RectTool.GetRectPointInWorld(RectTool.s_StartRect, pivot, rotation, i, j);
                        Vector3 rectPointInWorld2 = RectTool.GetRectPointInWorld(rect, pivot, rotation, i, j);
                        float   num       = 0.05f * HandleUtility.GetHandleSize(rectPointInWorld2);
                        int     controlID = GUIUtility.GetControlID(RectTool.s_ResizeHandlesHash, FocusType.Passive);
                        if (GUI.color.a > 0f || GUIUtility.hotControl == controlID)
                        {
                            EditorGUI.BeginChangeCheck();
                            EventType type = Event.current.type;
                            Vector3   vector;
                            if (i == 1 || j == 1)
                            {
                                Vector3 sideVector = (i != 1) ? (rotation * Vector3.up * rect.height) : (rotation * Vector3.right * rect.width);
                                Vector3 direction  = (i != 1) ? (rotation * Vector3.right) : (rotation * Vector3.up);
                                vector = RectHandles.SideSlider(controlID, rectPointInWorld2, sideVector, direction, num, null, 0f);
                            }
                            else
                            {
                                Vector3 vector2   = rotation * Vector3.right * (float)(i - 1);
                                Vector3 vector3   = rotation * Vector3.up * (float)(j - 1);
                                int     arg_1AB_0 = controlID;
                                Vector3 arg_1AB_1 = rectPointInWorld2;
                                Vector3 arg_1AB_2 = rotation * Vector3.forward;
                                Vector3 arg_1AB_3 = vector2;
                                Vector3 arg_1AB_4 = vector3;
                                float   arg_1AB_5 = num;
                                if (RectTool.< > f__mg$cache0 == null)
                                {
                                    RectTool.< > f__mg$cache0 = new Handles.CapFunction(RectHandles.RectScalingHandleCap);
                                }
                                vector = RectHandles.CornerSlider(arg_1AB_0, arg_1AB_1, arg_1AB_2, arg_1AB_3, arg_1AB_4, arg_1AB_5, RectTool.< > f__mg$cache0, Vector2.zero);
                            }
                            bool flag = Selection.transforms.Length == 1 && InternalEditorUtility.SupportsRectLayout(Selection.activeTransform) && Selection.activeTransform.parent.rotation == rotation;
                            if (flag)
                            {
                                Transform     activeTransform = Selection.activeTransform;
                                RectTransform component       = activeTransform.GetComponent <RectTransform>();
                                Transform     parent          = activeTransform.parent;
                                RectTransform component2      = parent.GetComponent <RectTransform>();
                                if (type == EventType.MouseDown && Event.current.type != EventType.MouseDown)
                                {
                                    RectTransformSnapping.CalculateOffsetSnapValues(parent, activeTransform, component2, component, i, j);
                                }
                            }
                            if (EditorGUI.EndChangeCheck())
                            {
                                ManipulationToolUtility.SetMinDragDifferenceForPos(rectPointInWorld2, 0.1f);
                                if (flag)
                                {
                                    Transform     parent2      = Selection.activeTransform.parent;
                                    RectTransform component3   = parent2.GetComponent <RectTransform>();
                                    Vector2       snapDistance = Vector2.one * HandleUtility.GetHandleSize(vector) * 0.05f;
                                    snapDistance.x /= (rotation2 * parent2.TransformVector(Vector3.right)).x;
                                    snapDistance.y /= (rotation2 * parent2.TransformVector(Vector3.up)).y;
                                    Vector3 vector4 = parent2.InverseTransformPoint(vector) - component3.rect.min;
                                    Vector3 vector5 = RectTransformSnapping.SnapToGuides(vector4, snapDistance) + Vector3.forward * vector4.z;
                                    ManipulationToolUtility.DisableMinDragDifferenceBasedOnSnapping(vector4, vector5);
                                    vector = parent2.TransformPoint(vector5 + component3.rect.min);
                                }
                                bool alt       = Event.current.alt;
                                bool actionKey = EditorGUI.actionKey;
                                bool flag2     = Event.current.shift && !actionKey;
                                if (!alt)
                                {
                                    scalePivot = RectTool.GetRectPointInWorld(RectTool.s_StartRect, pivot, rotation, 2 - i, 2 - j);
                                }
                                if (flag2)
                                {
                                    vector = Vector3.Project(vector - scalePivot, rectPointInWorld - scalePivot) + scalePivot;
                                }
                                Vector3 vector6 = rotation2 * (rectPointInWorld - scalePivot);
                                Vector3 vector7 = rotation2 * (vector - scalePivot);
                                if (i != 1)
                                {
                                    result.x = vector7.x / vector6.x;
                                }
                                if (j != 1)
                                {
                                    result.y = vector7.y / vector6.y;
                                }
                                if (flag2)
                                {
                                    float d = (i != 1) ? result.x : result.y;
                                    result = Vector3.one * d;
                                }
                                if (actionKey && i == 1)
                                {
                                    if (Event.current.shift)
                                    {
                                        result.x = (result.z = 1f / Mathf.Sqrt(Mathf.Max(result.y, 0.0001f)));
                                    }
                                    else
                                    {
                                        result.x = 1f / Mathf.Max(result.y, 0.0001f);
                                    }
                                }
                                if (flag2)
                                {
                                    float d2 = (i != 1) ? result.x : result.y;
                                    result = Vector3.one * d2;
                                }
                                if (actionKey && i == 1)
                                {
                                    if (Event.current.shift)
                                    {
                                        result.x = (result.z = 1f / Mathf.Sqrt(Mathf.Max(result.y, 0.0001f)));
                                    }
                                    else
                                    {
                                        result.x = 1f / Mathf.Max(result.y, 0.0001f);
                                    }
                                }
                                if (actionKey && j == 1)
                                {
                                    if (Event.current.shift)
                                    {
                                        result.y = (result.z = 1f / Mathf.Sqrt(Mathf.Max(result.x, 0.0001f)));
                                    }
                                    else
                                    {
                                        result.y = 1f / Mathf.Max(result.x, 0.0001f);
                                    }
                                }
                            }
                            if (i == 0)
                            {
                                ManipulationToolUtility.DetectDraggingBasedOnMouseDownUp("ChangingLeft", type);
                            }
                            if (i == 2)
                            {
                                ManipulationToolUtility.DetectDraggingBasedOnMouseDownUp("ChangingRight", type);
                            }
                            if (i != 1)
                            {
                                ManipulationToolUtility.DetectDraggingBasedOnMouseDownUp("ChangingWidth", type);
                            }
                            if (j == 0)
                            {
                                ManipulationToolUtility.DetectDraggingBasedOnMouseDownUp("ChangingBottom", type);
                            }
                            if (j == 2)
                            {
                                ManipulationToolUtility.DetectDraggingBasedOnMouseDownUp("ChangingTop", type);
                            }
                            if (j != 1)
                            {
                                ManipulationToolUtility.DetectDraggingBasedOnMouseDownUp("ChangingHeight", type);
                            }
                        }
                    }
                }
            }
            return(result);
        }
Esempio n. 24
0
        public void TimeRuler(Rect position, float frameRate, bool labels, bool useEntireHeight, float alpha, bool showTimeAsFrames)
        {
            Color color = GUI.color;

            GUI.BeginGroup(position);
            TimeArea.InitStyles();
            HandleUtility.ApplyWireMaterial();
            Color backgroundColor = GUI.backgroundColor;

            this.SetTickMarkerRanges();
            this.hTicks.SetTickStrengths(3f, 80f, true);
            Color textColor = TimeArea.styles.TimelineTick.normal.textColor;

            textColor.a = 0.75f * alpha;
            if (Event.current.type == EventType.Repaint)
            {
                if (Application.platform == RuntimePlatform.WindowsEditor)
                {
                    GL.Begin(7);
                }
                else
                {
                    GL.Begin(1);
                }
                Rect shownArea = base.shownArea;
                for (int i = 0; i < this.hTicks.tickLevels; i++)
                {
                    float   num          = this.hTicks.GetStrengthOfLevel(i) * 0.9f;
                    float[] ticksAtLevel = this.hTicks.GetTicksAtLevel(i, true);
                    for (int j = 0; j < ticksAtLevel.Length; j++)
                    {
                        if (ticksAtLevel[j] >= base.hRangeMin && ticksAtLevel[j] <= base.hRangeMax)
                        {
                            int   num2 = Mathf.RoundToInt(ticksAtLevel[j] * frameRate);
                            float num3 = (!useEntireHeight) ? (position.height * Mathf.Min(1f, num) * 0.7f) : position.height;
                            float x    = this.FrameToPixel((float)num2, frameRate, position, shownArea);
                            TimeArea.DrawVerticalLineFast(x, position.height - num3 + 0.5f, position.height - 0.5f, new Color(1f, 1f, 1f, num / 0.5f) * textColor);
                        }
                    }
                }
                GL.End();
            }
            if (labels)
            {
                int     levelWithMinSeparation = this.hTicks.GetLevelWithMinSeparation(40f);
                float[] ticksAtLevel2          = this.hTicks.GetTicksAtLevel(levelWithMinSeparation, false);
                for (int k = 0; k < ticksAtLevel2.Length; k++)
                {
                    if (ticksAtLevel2[k] >= base.hRangeMin && ticksAtLevel2[k] <= base.hRangeMax)
                    {
                        int    num4 = Mathf.RoundToInt(ticksAtLevel2[k] * frameRate);
                        float  num5 = Mathf.Floor(this.FrameToPixel((float)num4, frameRate, position));
                        string text = (!showTimeAsFrames) ? this.FormatFrame(num4, frameRate) : num4.ToString();
                        GUI.Label(new Rect(num5 + 3f, -3f, 40f, 20f), text, TimeArea.styles.TimelineTick);
                    }
                }
            }
            GUI.EndGroup();
            GUI.backgroundColor = backgroundColor;
            GUI.color           = color;
        }
Esempio n. 25
0
        public override void ToolGUI(SceneView view, Vector3 handlePosition, bool isStatic)
        {
            Rect       handleRect         = Tools.handleRect;
            Quaternion handleRectRotation = Tools.handleRectRotation;

            Vector3[] array = new Vector3[4];
            for (int i = 0; i < 4; i++)
            {
                Vector3 point = RectTool.GetLocalRectPoint(handleRect, i);
                array[i] = handleRectRotation * point + handlePosition;
            }
            RectHandles.RenderRectWithShadow(false, array);
            Color color = GUI.color;

            if (Camera.current)
            {
                Vector3 planeNormal = (!Camera.current.orthographic) ? (handlePosition + handleRectRotation * handleRect.center - Camera.current.transform.position) : Camera.current.transform.forward;
                Vector3 vector      = handleRectRotation * Vector3.right * handleRect.width;
                Vector3 vector2     = handleRectRotation * Vector3.up * handleRect.height;
                float   num         = Mathf.Sqrt(Vector3.Cross(Vector3.ProjectOnPlane(vector, planeNormal), Vector3.ProjectOnPlane(vector2, planeNormal)).magnitude);
                num /= HandleUtility.GetHandleSize(handlePosition);
                float num2   = Mathf.Clamp01((num - 0.2f) / 0.2f * 2f);
                Color color2 = color;
                color2.a *= num2;
                GUI.color = color2;
            }
            Vector3 handlePosition2 = 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;
                using (new EditorGUI.DisabledScope(!flag && !flag2))
                {
                    EditorGUI.BeginChangeCheck();
                    Vector3 a = RectTool.PivotHandleGUI(handleRect, handlePosition2, handleRectRotation);
                    if (EditorGUI.EndChangeCheck() && !isStatic)
                    {
                        if (flag)
                        {
                            Tools.localHandleOffset += Quaternion.Inverse(Tools.handleRotation) * (a - handlePosition2);
                        }
                        else if (flag2)
                        {
                            Transform activeTransform = Selection.activeTransform;
                            Undo.RecordObject(component, "Move Rectangle Pivot");
                            Transform transform = (!Tools.rectBlueprintMode || !InternalEditorUtility.SupportsRectLayout(activeTransform)) ? activeTransform : activeTransform.parent;
                            Vector2   b         = transform.InverseTransformVector(a - handlePosition2);
                            b.x /= component.rect.width;
                            b.y /= component.rect.height;
                            Vector2 vector3 = component.pivot + b;
                            RectTransformEditor.SetPivotSmart(component, vector3.x, 0, true, transform != component.transform);
                            RectTransformEditor.SetPivotSmart(component, vector3.y, 1, true, transform != component.transform);
                        }
                    }
                }
            }
            TransformManipulator.BeginManipulationHandling(true);
            if (!Tools.vertexDragging)
            {
                EditorGUI.BeginChangeCheck();
                Vector3 pivotPosition = handlePosition;
                Vector3 scaleDelta    = RectTool.ResizeHandlesGUI(handleRect, handlePosition, handleRectRotation, out pivotPosition);
                if (EditorGUI.EndChangeCheck() && !isStatic)
                {
                    TransformManipulator.SetResizeDelta(scaleDelta, pivotPosition, handleRectRotation);
                }
                bool flag3 = true;
                if (Tools.rectBlueprintMode)
                {
                    Transform[] transforms = Selection.transforms;
                    for (int j = 0; j < transforms.Length; j++)
                    {
                        Transform transform2 = transforms[j];
                        if (transform2.GetComponent <RectTransform>() != null)
                        {
                            flag3 = false;
                        }
                    }
                }
                if (flag3)
                {
                    EditorGUI.BeginChangeCheck();
                    Quaternion rhs = RectTool.RotationHandlesGUI(handleRect, handlePosition, handleRectRotation);
                    if (EditorGUI.EndChangeCheck() && !isStatic)
                    {
                        float   angle;
                        Vector3 vector4;
                        (Quaternion.Inverse(handleRectRotation) * rhs).ToAngleAxis(out angle, out vector4);
                        vector4 = handleRectRotation * vector4;
                        Undo.RecordObjects(Selection.transforms, "Rotate");
                        Transform[] transforms2 = Selection.transforms;
                        for (int k = 0; k < transforms2.Length; k++)
                        {
                            Transform transform3 = transforms2[k];
                            transform3.RotateAround(handlePosition, vector4, angle);
                            transform3.SetLocalEulerHint(transform3.GetLocalEulerAngles(transform3.rotationOrder));
                            if (transform3.parent != null)
                            {
                                transform3.SendTransformChangedScale();
                            }
                        }
                        Tools.handleRotation = Quaternion.AngleAxis(angle, vector4) * Tools.handleRotation;
                    }
                }
            }
            TransformManipulator.EndManipulationHandling();
            TransformManipulator.BeginManipulationHandling(false);
            EditorGUI.BeginChangeCheck();
            Vector3 a2 = RectTool.MoveHandlesGUI(handleRect, handlePosition, handleRectRotation);

            if (EditorGUI.EndChangeCheck() && !isStatic)
            {
                Vector3 positionDelta = a2 - TransformManipulator.mouseDownHandlePosition;
                TransformManipulator.SetPositionDelta(positionDelta);
            }
            TransformManipulator.EndManipulationHandling();
            GUI.color = color;
        }
Esempio n. 26
0
        static bool CurveDisplay(IAudioEffectPlugin plugin, Rect r0, ref float threshold, ref float ratio, ref float makeupGain, ref float attackTime, ref float releaseTime, ref float knee, float sidechainLevel, float outputLevel, float blend)
        {
            Event evt       = Event.current;
            int   controlID = GUIUtility.GetControlID(FocusType.Passive);

            Rect r = AudioCurveRendering.BeginCurveFrame(r0);

            const float thresholdActiveWidth = 10f;
            float       vuWidth = 10f;

            float minThreshold, maxThreshold, defThreshold; plugin.GetFloatParameterInfo(kThresholdName, out minThreshold, out maxThreshold, out defThreshold);
            float minRatio, maxRatio, defRatio; plugin.GetFloatParameterInfo(kRatioName, out minRatio, out maxRatio, out defRatio);
            float minMakeupGain, maxMakeupGain, defMakeupGain; plugin.GetFloatParameterInfo(kMakeupGainName, out minMakeupGain, out maxMakeupGain, out defMakeupGain);
            float minKnee, maxKnee, defKnee; plugin.GetFloatParameterInfo(kKneeName, out minKnee, out maxKnee, out defKnee);

            float dbRange = 100.0f, dbMin = -80.0f;
            float thresholdPosX = r.width * (threshold - dbMin) / dbRange;

            bool modifiedValue = false;

            switch (evt.GetTypeForControl(controlID))
            {
            case EventType.MouseDown:
                if (r.Contains(Event.current.mousePosition) && evt.button == 0)
                {
                    dragtype = DragType.None;
                    GUIUtility.hotControl = controlID;
                    EditorGUIUtility.SetWantsMouseJumping(1);
                    evt.Use();

                    // Ensure visible state change on mousedown to make it clear that interaction is possible
                    if ((Mathf.Abs(r.x + thresholdPosX - evt.mousePosition.x) >= thresholdActiveWidth))
                    {
                        dragtype = (evt.mousePosition.x < r.x + thresholdPosX) ? DragType.MakeupGain : DragType.Ratio;
                    }
                    else
                    {
                        dragtype = DragType.ThresholdAndKnee;
                    }
                }
                break;

            case EventType.MouseUp:
                if (GUIUtility.hotControl == controlID && evt.button == 0)
                {
                    dragtype = DragType.None;
                    GUIUtility.hotControl = 0;
                    EditorGUIUtility.SetWantsMouseJumping(0);
                    evt.Use();
                }
                break;

            case EventType.MouseDrag:
                if (GUIUtility.hotControl == controlID)
                {
                    float dragAcceleration = evt.alt ? .25f : 1f;
                    if (dragtype == DragType.ThresholdAndKnee)
                    {
                        bool dragKnee = Mathf.Abs(evt.delta.x) < Mathf.Abs(evt.delta.y);
                        if (dragKnee)
                        {
                            knee = Mathf.Clamp(knee + evt.delta.y * 0.5f * dragAcceleration, minKnee, maxKnee);
                        }
                        else
                        {
                            threshold = Mathf.Clamp(threshold + evt.delta.x * 0.1f * dragAcceleration, minThreshold, maxThreshold);
                        }
                    }
                    else if (dragtype == DragType.Ratio)
                    {
                        ratio = Mathf.Clamp(ratio + evt.delta.y * (ratio > 1.0f ? 0.05f : 0.003f) * dragAcceleration, minRatio, maxRatio);
                    }
                    else if (dragtype == DragType.MakeupGain)
                    {
                        makeupGain = Mathf.Clamp(makeupGain - evt.delta.y * 0.5f * dragAcceleration, minMakeupGain, maxMakeupGain);
                    }
                    else
                    {
                        Debug.LogError("Drag: Unhandled enum");
                    }

                    modifiedValue = true;
                    evt.Use();
                }
                break;
            }

            if (evt.type == EventType.Repaint)
            {
                // Curve
                HandleUtility.ApplyWireMaterial();

                //float sidechainPosX = r.width * (sidechainLevel - dbMin) / dbRange;
                float thresholdPosY  = r.height * (1.0f - ((threshold - dbMin + makeupGain) / dbRange));
                Color thresholdColor = new Color(0.7f, 0.7f, 0.7f);
                Color sidechainColor = Color.black;


                float duckGradient       = 1.0f / ratio;
                float duckThreshold      = threshold;
                float duckSidechainLevel = sidechainLevel;
                float duckMakeupGain     = makeupGain;
                float duckKnee           = knee;
                float duckKneeC1         = (knee > 0.0f) ? ((duckGradient - 1.0f) / (4.0f * knee)) : 0.0f;
                float duckKneeC2         = duckThreshold - knee;

                // Main filled curve
                AudioCurveRendering.DrawFilledCurve(
                    r,
                    delegate(float x, out Color col)
                {
                    float level = x * dbRange + dbMin;
                    float gain  = level;
                    float t     = level - duckThreshold;
                    col         = ScaleAlpha(duckSidechainLevel > level ? AudioCurveRendering.kAudioOrange : Color.grey, blend);
                    if (t > -duckKnee && t < duckKnee)
                    {
                        t   += duckKnee;
                        gain = t * (duckKneeC1 * t + 1.0f) + duckKneeC2;

                        if (dragtype == DragType.ThresholdAndKnee)
                        {
                            const float mult = 1.2f;
                            col = new Color(col.r * mult, col.g * mult, col.b * mult);
                        }
                    }
                    else if (t > 0.0f)
                    {
                        gain = duckThreshold + duckGradient * t;
                    }
                    return((2.0f * (gain + duckMakeupGain - dbMin) / dbRange) - 1.0f);
                }
                    );

                // Curve shown when modifying MakeupGain
                if (dragtype == DragType.MakeupGain)
                {
                    AudioCurveRendering.DrawCurve(
                        r,
                        delegate(float x)
                    {
                        float level = x * dbRange + dbMin;
                        float gain  = level;
                        float t     = level - duckThreshold;
                        if (t > -duckKnee && t < duckKnee)
                        {
                            t   += duckKnee;
                            gain = t * (duckKneeC1 * t + 1.0f) + duckKneeC2;
                        }
                        else if (t > 0.0f)
                        {
                            gain = duckThreshold + duckGradient * t;
                        }
                        return((2.0f * (gain + duckMakeupGain - dbMin) / dbRange) - 1.0f);
                    },
                        Color.white
                        );
                }


                // Threshold text and line
                textStyle10.normal.textColor = ScaleAlpha(thresholdColor, blend);
                EditorGUI.DrawRect(new Rect(r.x + thresholdPosX, r.y, 1, r.height), textStyle10.normal.textColor);
                DrawText(r.x + thresholdPosX + 4, r.y + 6, string.Format(CultureInfo.InvariantCulture.NumberFormat, "Threshold: {0:F1} dB", threshold));

                // Sidechain text and line
                textStyle10.normal.textColor = ScaleAlpha(sidechainColor, blend);
                DrawText(r.x + 4, r.y + r.height - 10, sidechainLevel < -80 ? "Input: None" : string.Format(CultureInfo.InvariantCulture.NumberFormat, "Input: {0:F1} dB", sidechainLevel));

                if (dragtype == DragType.Ratio)
                {
                    float aspect = (float)r.height / (float)r.width;
                    Handles.DrawAAPolyLine(2.0f,
                                           new Color[] { Color.black, Color.black },
                                           new Vector3[]
                    {
                        new Vector3(r.x + thresholdPosX + r.width, r.y + thresholdPosY - aspect * r.width, 0.0f),
                        new Vector3(r.x + thresholdPosX - r.width, r.y + thresholdPosY + aspect * r.width, 0.0f)
                    });
                    Handles.DrawAAPolyLine(3.0f,
                                           new Color[] { Color.white, Color.white },
                                           new Vector3[]
                    {
                        new Vector3(r.x + thresholdPosX + r.width, r.y + thresholdPosY - aspect * duckGradient * r.width, 0.0f),
                        new Vector3(r.x + thresholdPosX - r.width, r.y + thresholdPosY + aspect * duckGradient * r.width, 0.0f)
                    });
                }
                else if (dragtype == DragType.ThresholdAndKnee)
                {
                    // Knee min and max lines
                    float normalizedKnee1 = (threshold - knee - dbMin) / dbRange;
                    float normalizedKnee2 = (threshold + knee - dbMin) / dbRange;
                    float y1        = EvaluateDuckingVolume(normalizedKnee1, ratio, threshold, makeupGain, knee, dbRange, dbMin);
                    float y2        = EvaluateDuckingVolume(normalizedKnee2, ratio, threshold, makeupGain, knee, dbRange, dbMin);
                    float knee1PosY = r.yMax - (y1 + 1f) * 0.5f * r.height;
                    float knee2PosY = r.yMax - (y2 + 1f) * 0.5f * r.height;
                    EditorGUI.DrawRect(new Rect(r.x + normalizedKnee1 * r.width, knee1PosY, 1, r.height - knee1PosY), new Color(0, 0, 0, 0.5f));
                    EditorGUI.DrawRect(new Rect(r.x + normalizedKnee2 * r.width - 1, knee2PosY, 1, r.height - knee2PosY), new Color(0, 0, 0, 0.5f));

                    // Enhanced threshold
                    EditorGUI.DrawRect(new Rect(r.x + thresholdPosX - 1, r.y, 3, r.height), Color.white);
                }

                outputLevel = (Mathf.Clamp(outputLevel - makeupGain, dbMin, dbMin + dbRange) - dbMin) / dbRange;
                if (EditorApplication.isPlaying)
                {
                    const int margin = 2;
                    Rect      vuRect = new Rect(r.x + r.width - vuWidth + margin, r.y + margin, vuWidth - 2 * margin, r.height - 2 * margin);
                    DrawVU(vuRect, outputLevel, blend, true);
                }
            }

            AudioCurveRendering.EndCurveFrame();

            return(modifiedValue);
        }
Esempio n. 27
0
        public void OnGUI(Rect position)
        {
            if (GradientEditor.s_Styles == null)
            {
                GradientEditor.s_Styles = new GradientEditor.Styles();
            }
            float num  = 16f;
            float num2 = 30f;
            float num3 = position.height - 2f * num - num2;

            position.height = num;
            this.ShowSwatchArray(position, this.m_AlphaSwatches, true);
            position.y += num;
            if (Event.current.type == EventType.Repaint)
            {
                position.height = num3;
                if (this.m_TextureDirty)
                {
                    this.BuildTexture();
                }
                GradientEditor.DrawGradientWithBackground(position, this.m_PreviewTex);
            }
            position.y     += num3;
            position.height = num;
            this.ShowSwatchArray(position, this.m_RGBSwatches, false);
            if (this.m_SelectedSwatch != null)
            {
                position.y     += num;
                position.height = num2;
                position.y     += 10f;
                float num4       = 45f;
                float num5       = 60f;
                float num6       = 20f;
                float labelWidth = 50f;
                float num7       = num5 + num6 + num5 + num4;
                Rect  position2  = position;
                position2.height            = 18f;
                position2.x                += 17f;
                position2.width            -= num7;
                EditorGUIUtility.labelWidth = labelWidth;
                if (this.m_SelectedSwatch.m_IsAlpha)
                {
                    EditorGUIUtility.fieldWidth = 30f;
                    EditorGUI.BeginChangeCheck();
                    float num8 = (float)EditorGUI.IntSlider(position2, GradientEditor.s_Styles.alphaText, (int)(this.m_SelectedSwatch.m_Value.r * 255f), 0, 255) / 255f;
                    if (EditorGUI.EndChangeCheck())
                    {
                        num8 = Mathf.Clamp01(num8);
                        this.m_SelectedSwatch.m_Value.r = (this.m_SelectedSwatch.m_Value.g = (this.m_SelectedSwatch.m_Value.b = num8));
                        this.AssignBack();
                        HandleUtility.Repaint();
                    }
                }
                else
                {
                    EditorGUI.BeginChangeCheck();
                    this.m_SelectedSwatch.m_Value = EditorGUI.ColorField(position2, GradientEditor.s_Styles.colorText, this.m_SelectedSwatch.m_Value, true, false);
                    if (EditorGUI.EndChangeCheck())
                    {
                        this.AssignBack();
                        HandleUtility.Repaint();
                    }
                }
                position2.x                += position2.width + num6;
                position2.width             = num4 + num5;
                EditorGUIUtility.labelWidth = num5;
                string kFloatFieldFormatString = EditorGUI.kFloatFieldFormatString;
                EditorGUI.kFloatFieldFormatString = "f1";
                EditorGUI.BeginChangeCheck();
                float value = EditorGUI.FloatField(position2, GradientEditor.s_Styles.locationText, this.m_SelectedSwatch.m_Time * 100f) / 100f;
                if (EditorGUI.EndChangeCheck())
                {
                    this.m_SelectedSwatch.m_Time = Mathf.Clamp(value, 0f, 1f);
                    this.AssignBack();
                }
                EditorGUI.kFloatFieldFormatString = kFloatFieldFormatString;
                position2.x    += position2.width;
                position2.width = 20f;
                GUI.Label(position2, GradientEditor.s_Styles.percentText);
            }
        }
Esempio n. 28
0
        private void ShowSwatchArray(Rect position, List <GradientEditor.Swatch> swatches, bool isAlpha)
        {
            int       controlID      = GUIUtility.GetControlID(652347689, FocusType.Passive);
            Event     current        = Event.current;
            float     time           = this.GetTime((Event.current.mousePosition.x - position.x) / position.width);
            Vector2   point          = new Vector3(position.x + time * position.width, Event.current.mousePosition.y);
            EventType typeForControl = current.GetTypeForControl(controlID);

            switch (typeForControl)
            {
            case EventType.MouseDown:
            {
                Rect rect = position;
                rect.xMin -= 10f;
                rect.xMax += 10f;
                if (rect.Contains(current.mousePosition))
                {
                    GUIUtility.hotControl = controlID;
                    current.Use();
                    if (swatches.Contains(this.m_SelectedSwatch) && !this.m_SelectedSwatch.m_IsAlpha && this.CalcSwatchRect(position, this.m_SelectedSwatch).Contains(current.mousePosition))
                    {
                        if (current.clickCount == 2)
                        {
                            GUIUtility.keyboardControl = controlID;
                            ColorPicker.Show(GUIView.current, this.m_SelectedSwatch.m_Value, false, false, null);
                            GUIUtility.ExitGUI();
                        }
                    }
                    else
                    {
                        bool flag = false;
                        foreach (GradientEditor.Swatch current2 in swatches)
                        {
                            if (this.CalcSwatchRect(position, current2).Contains(point))
                            {
                                flag = true;
                                this.m_SelectedSwatch = current2;
                                break;
                            }
                        }
                        if (!flag)
                        {
                            if (swatches.Count < 8)
                            {
                                Color value = this.m_Gradient.Evaluate(time);
                                if (isAlpha)
                                {
                                    value = new Color(value.a, value.a, value.a, 1f);
                                }
                                else
                                {
                                    value.a = 1f;
                                }
                                this.m_SelectedSwatch = new GradientEditor.Swatch(time, value, isAlpha);
                                swatches.Add(this.m_SelectedSwatch);
                                this.AssignBack();
                            }
                            else
                            {
                                Debug.LogWarning(string.Concat(new object[]
                                    {
                                        "Max ",
                                        8,
                                        " color keys and ",
                                        8,
                                        " alpha keys are allowed in a gradient."
                                    }));
                            }
                        }
                    }
                }
                return;
            }

            case EventType.MouseUp:
                if (GUIUtility.hotControl == controlID)
                {
                    GUIUtility.hotControl = 0;
                    current.Use();
                    if (!swatches.Contains(this.m_SelectedSwatch))
                    {
                        this.m_SelectedSwatch = null;
                    }
                    this.RemoveDuplicateOverlappingSwatches();
                }
                return;

            case EventType.MouseMove:
            case EventType.KeyUp:
            case EventType.ScrollWheel:
IL_9B:
                if (typeForControl == EventType.ValidateCommand)
                {
                    if (current.commandName == "Delete")
                    {
                        Event.current.Use();
                    }
                    return;
                }
                if (typeForControl != EventType.ExecuteCommand)
                {
                    return;
                }
                if (current.commandName == "ColorPickerChanged")
                {
                    GUI.changed = true;
                    this.m_SelectedSwatch.m_Value = ColorPicker.color;
                    this.AssignBack();
                    HandleUtility.Repaint();
                }
                else if (current.commandName == "Delete" && swatches.Count > 1)
                {
                    swatches.Remove(this.m_SelectedSwatch);
                    this.AssignBack();
                    HandleUtility.Repaint();
                }
                return;

            case EventType.MouseDrag:
                if (GUIUtility.hotControl == controlID && this.m_SelectedSwatch != null)
                {
                    current.Use();
                    if (current.mousePosition.y + 5f < position.y || current.mousePosition.y - 5f > position.yMax)
                    {
                        if (swatches.Count > 1)
                        {
                            swatches.Remove(this.m_SelectedSwatch);
                            this.AssignBack();
                            return;
                        }
                    }
                    else if (!swatches.Contains(this.m_SelectedSwatch))
                    {
                        swatches.Add(this.m_SelectedSwatch);
                    }
                    this.m_SelectedSwatch.m_Time = time;
                    this.AssignBack();
                }
                return;

            case EventType.KeyDown:
                if (current.keyCode == KeyCode.Delete)
                {
                    if (this.m_SelectedSwatch != null)
                    {
                        List <GradientEditor.Swatch> list;
                        if (this.m_SelectedSwatch.m_IsAlpha)
                        {
                            list = this.m_AlphaSwatches;
                        }
                        else
                        {
                            list = this.m_RGBSwatches;
                        }
                        if (list.Count > 1)
                        {
                            list.Remove(this.m_SelectedSwatch);
                            this.AssignBack();
                            HandleUtility.Repaint();
                        }
                    }
                    current.Use();
                }
                return;

            case EventType.Repaint:
            {
                bool flag2 = false;
                foreach (GradientEditor.Swatch current3 in swatches)
                {
                    if (this.m_SelectedSwatch == current3)
                    {
                        flag2 = true;
                    }
                    else
                    {
                        this.DrawSwatch(position, current3, !isAlpha);
                    }
                }
                if (flag2 && this.m_SelectedSwatch != null)
                {
                    this.DrawSwatch(position, this.m_SelectedSwatch, !isAlpha);
                }
                return;
            }
            }
            goto IL_9B;
        }
Esempio n. 29
0
        public static void PickAllNonAlloc(List <ProbeHit> hits, ProbeFilter filter, SceneView sceneView, Vector2 guiPosition, int limit = DefaultLimit)
        {
            var screenPosition = HandleUtility.GUIPointToScreenPixelCoordinate(guiPosition);
            var ray3D          = HandleUtility.GUIPointToWorldRay(guiPosition);
            var worldPosition  = sceneView.camera.ScreenToWorldPoint(screenPosition);
            var layerMask      = PeekPlugin.Configuration.probeLayerMask;

            var raycastHits = ArrayPool <RaycastHit> .New(limit);

            var overlapHits = ArrayPool <Collider2D> .New(limit);

            var handleHits = HashSetPool <GameObject> .New();

            var ancestorHits = HashSetPool <ProbeHit> .New();

#if PROBUILDER_4_OR_NEWER
            var proBuilderHits = ListPool <ProbeHit> .New();
#endif

            var gameObjectHits = DictionaryPool <GameObject, ProbeHit> .New();

            try
            {
                // Raycast (3D)
                if (filter.raycast)
                {
                    var raycastHitCount = Physics.RaycastNonAlloc(ray3D, raycastHits, Mathf.Infinity, layerMask);

                    for (var i = 0; i < raycastHitCount; i++)
                    {
                        var raycastHit = raycastHits[i];

#if UNITY_2019_2_OR_NEWER
                        if (SceneVisibilityManager.instance.IsHidden(raycastHit.transform.gameObject))
                        {
                            continue;
                        }
#endif

                        var gameObject = raycastHit.transform.gameObject;

                        if (!gameObjectHits.TryGetValue(gameObject, out var hit))
                        {
                            hit = new ProbeHit(gameObject);
                        }

                        hit.point    = raycastHit.point;
                        hit.distance = raycastHit.distance;

                        gameObjectHits[gameObject] = hit;
                    }
                }

                // Overlap (2D)
                if (filter.overlap)
                {
                    var overlapHitCount = Physics2D.OverlapPointNonAlloc(worldPosition, overlapHits, layerMask);

                    for (var i = 0; i < overlapHitCount; i++)
                    {
                        var overlapHit = overlapHits[i];

#if UNITY_2019_2_OR_NEWER
                        if (SceneVisibilityManager.instance.IsHidden(overlapHit.transform.gameObject))
                        {
                            continue;
                        }
#endif

                        var gameObject = overlapHit.transform.gameObject;

                        if (!gameObjectHits.TryGetValue(gameObject, out var hit))
                        {
                            hit = new ProbeHit(gameObject);
                        }

                        hit.distance = hit.distance ?? Vector3.Distance(overlapHit.transform.position, worldPosition);

                        gameObjectHits[gameObject] = hit;
                    }
                }

                // Handles (Editor Default)
                if (filter.handles && canPickHandles)
                {
                    PickAllHandlesNonAlloc(handleHits, guiPosition, limit);

                    foreach (var handleHit in handleHits)
                    {
                        var gameObject = handleHit;

                        if (!gameObjectHits.TryGetValue(gameObject, out var hit))
                        {
                            hit = new ProbeHit(gameObject);
                        }

                        hit.distance = hit.distance ?? Vector3.Distance(handleHit.transform.position, worldPosition);

                        gameObjectHits[gameObject] = hit;
                    }
                }

                // Ancestors
                foreach (var gameObjectHit in gameObjectHits)
                {
                    var gameObject = gameObjectHit.Key;
                    var hit        = gameObjectHit.Value;

                    var parent = gameObject.transform.parent;

                    int depth = 0;

                    while (parent != null)
                    {
                        var parentGameObject = parent.gameObject;

                        var parentHit = new ProbeHit(parentGameObject);
                        parentHit.groupGameObject = gameObject;
                        parentHit.distance        = hit.distance ?? Vector3.Distance(parentHit.transform.position, worldPosition);
                        parentHit.groupOrder      = 1000 + depth;

                        ancestorHits.Add(parentHit);

                        parent = parent.parent;
                        depth++;
                    }
                }

#if PROBUILDER_4_OR_NEWER
                // ProBuilder
                if (filter.proBuilder && ProBuilderEditor.instance != null)
                {
                    var proBuilderMeshes = ListPool <ProBuilderMesh> .New();

                    try
                    {
                        foreach (var gameObjectHit in gameObjectHits.Values)
                        {
                            var proBuilderMesh = gameObjectHit.gameObject.GetComponent <ProBuilderMesh>();

                            if (proBuilderMesh != null)
                            {
                                proBuilderMeshes.Add(proBuilderMesh);
                            }
                        }

                        PickProBuilderElementsNonAlloc(proBuilderHits, proBuilderMeshes, sceneView, guiPosition);
                    }
                    finally
                    {
                        proBuilderMeshes.Free();
                    }
                }
#endif

                // Prepare final hits
                hits.Clear();

                // Add hits
                foreach (var gameObjectHit in gameObjectHits.Values)
                {
                    hits.Add(gameObjectHit);
                }

                foreach (var ancestorHit in ancestorHits)
                {
                    hits.Add(ancestorHit);
                }

#if PROBUILDER_4_OR_NEWER
                foreach (var proBuilderHit in proBuilderHits)
                {
                    hits.Add(proBuilderHit);
                }
#endif

                // Sort by distance
                hits.Sort(compareHits);
            }
            finally
            {
                raycastHits.Free();
                overlapHits.Free();
                handleHits.Free();
                ancestorHits.Free();

#if PROBUILDER_4_OR_NEWER
                proBuilderHits.Free();
#endif

                gameObjectHits.Free();
            }
        }
Esempio n. 30
0
 public static GameObject PickGameObject(Vector2 position, bool selectPrefabRoot, GameObject[] ignore)
 {
     return(HandleUtility.PickGameObject(position, selectPrefabRoot, ignore, null));
 }