Button() public static method

public static Button ( Vector3 position, Quaternion direction, float size, float pickSize, CapFunction capFunction ) : bool
position Vector3
direction UnityEngine.Quaternion
size float
pickSize float
capFunction CapFunction
return bool
コード例 #1
0
 internal void OnGUI(SceneView view)
 {
     if (Mathf.Min(view.position.width, view.position.height) >= 100f)
     {
         if (Event.current.type == EventType.Repaint)
         {
             Profiler.BeginSample("SceneView.AxisSelector");
         }
         Camera camera = view.camera;
         HandleUtility.PushCamera(camera);
         if (camera.orthographic)
         {
             camera.orthographicSize = 0.5f;
         }
         camera.cullingMask        = 0;
         camera.transform.position = (Vector3)(camera.transform.rotation * new Vector3(0f, 0f, -5f));
         camera.clearFlags         = CameraClearFlags.Nothing;
         camera.nearClipPlane      = 0.1f;
         camera.farClipPlane       = 10f;
         camera.fieldOfView        = view.m_Ortho.Fade(70f, 0f);
         SceneView.AddCursorRect(new Rect((view.position.width - 100f) + 22f, 22f, 56f, 102f), MouseCursor.Arrow);
         Handles.SetCamera(new Rect(view.position.width - 100f, 0f, 100f, 100f), camera);
         Handles.BeginGUI();
         Rect position = new Rect((view.position.width - 100f) + 17f, 92f, 66f, 16f);
         if (!view.in2DMode && GUI.Button(position, string.Empty, styles.viewLabelStyleLeftAligned))
         {
             if (Event.current.button == 1)
             {
                 this.DisplayContextMenu(position, view);
             }
             else
             {
                 this.ViewSetOrtho(view, !view.orthographic);
             }
         }
         int   index = 8;
         Rect  rect2 = position;
         float num3  = 0f;
         float num4  = 0f;
         for (int i = 0; i < kDirNames.Length; i++)
         {
             if (i != index)
             {
                 num4 += this.dirNameVisible[i].faded;
                 if (this.dirNameVisible[i].faded > 0f)
                 {
                     num3 += styles.viewLabelStyleLeftAligned.CalcSize(EditorGUIUtility.TempContent(kDirNames[i])).x *this.dirNameVisible[i].faded;
                 }
             }
         }
         if (num4 > 0f)
         {
             num3 /= num4;
         }
         rect2.x += 37f - (num3 * 0.5f);
         rect2.x  = Mathf.RoundToInt(rect2.x);
         for (int j = 0; (j < this.dirNameVisible.Length) && (j < kDirNames.Length); j++)
         {
             if (j != index)
             {
                 Color color = Handles.centerColor;
                 color.a *= this.dirNameVisible[j].faded;
                 if (color.a > 0f)
                 {
                     GUI.color = color;
                     GUI.Label(rect2, kDirNames[j], styles.viewLabelStyleLeftAligned);
                 }
             }
         }
         Color centerColor = Handles.centerColor;
         centerColor.a *= this.faded2Dgray * this.m_Visible.faded;
         if (centerColor.a > 0f)
         {
             GUI.color = centerColor;
             GUI.Label(position, kDirNames[index], styles.viewLabelStyleCentered);
         }
         if (this.faded2Dgray < 1f)
         {
             this.DrawIsoStatusSymbol(new Vector3(rect2.x - 8f, rect2.y + 8.5f, 0f), view, 1f - this.faded2Dgray);
         }
         Handles.EndGUI();
         for (int k = 0; k < 3; k++)
         {
             Vector3 rhs = (Vector3)(kDirectionRotations[k] * Vector3.forward);
             this.dirVisible[k].target = Mathf.Abs(Vector3.Dot(camera.transform.forward, rhs)) < 0.9f;
         }
         float size = HandleUtility.GetHandleSize(Vector3.zero) * 0.2f;
         this.AxisSelectors(view, camera, size, -1f, styles.viewAxisLabelStyle);
         Color color3 = Color.Lerp(Handles.centerColor, Color.gray, this.faded2Dgray);
         color3.a *= this.m_Visible.faded;
         if (color3.a <= 0.1f)
         {
             GUI.enabled = false;
         }
         Handles.color = color3;
         if (Handles.Button(Vector3.zero, Quaternion.identity, size * 0.8f, size, new Handles.DrawCapFunction(Handles.CubeCap)) && !view.in2DMode)
         {
             if (Event.current.clickCount == 2)
             {
                 view.FrameSelected();
             }
             else if (Event.current.shift || (Event.current.button == 2))
             {
                 this.ViewFromNiceAngle(view, true);
             }
             else
             {
                 this.ViewSetOrtho(view, !view.orthographic);
             }
         }
         this.AxisSelectors(view, camera, size, 1f, styles.viewAxisLabelStyle);
         GUI.enabled = true;
         if (!view.in2DMode && (Event.current.type == EditorGUIUtility.swipeGestureEventType))
         {
             Vector3 up;
             Event   current = Event.current;
             if (current.delta.y > 0f)
             {
                 up = Vector3.up;
             }
             else if (current.delta.y < 0f)
             {
                 up = -Vector3.up;
             }
             else if (current.delta.x < 0f)
             {
                 up = Vector3.right;
             }
             else
             {
                 up = -Vector3.right;
             }
             Vector3 direction = -up - ((Vector3)(Vector3.forward * 0.9f));
             direction = view.camera.transform.TransformDirection(direction);
             float num9 = 0f;
             int   dir  = 0;
             for (int m = 0; m < 6; m++)
             {
                 float num12 = Vector3.Dot((Vector3)(kDirectionRotations[m] * -Vector3.forward), direction);
                 if (num12 > num9)
                 {
                     num9 = num12;
                     dir  = m;
                 }
             }
             this.ViewAxisDirection(view, dir);
             Event.current.Use();
         }
         HandleUtility.PopCamera(camera);
         Handles.SetCamera(camera);
         if (Event.current.type == EventType.Repaint)
         {
             Profiler.EndSample();
         }
     }
 }
コード例 #2
0
        private void AxisSelectors(SceneView view, Camera cam, float size, float sgn, GUIStyle viewAxisLabelStyle)
        {
            for (int i = kDirectionRotations.Length - 1; i >= 0; i--)
            {
                Quaternion direction = kDirectionRotations[i];
                string[]   strArray  = new string[] { "x", "y", "z" };
                float      faded     = this.dirVisible[i % 3].faded;
                Vector3    rhs       = (Vector3)(kDirectionRotations[i] * Vector3.forward);
                float      num3      = Vector3.Dot(view.camera.transform.forward, rhs);
                if (((num3 > 0.0) || (sgn <= 0f)) && ((num3 <= 0.0) || (sgn >= 0f)))
                {
                    Color xAxisColor;
                    switch (i)
                    {
                    case 0:
                        xAxisColor = Handles.xAxisColor;
                        break;

                    case 1:
                        xAxisColor = Handles.yAxisColor;
                        break;

                    case 2:
                        xAxisColor = Handles.zAxisColor;
                        break;

                    default:
                        xAxisColor = Handles.centerColor;
                        break;
                    }
                    if (view.in2DMode)
                    {
                        xAxisColor = Color.Lerp(xAxisColor, Color.gray, this.faded2Dgray);
                    }
                    xAxisColor.a *= faded * this.m_Visible.faded;
                    Handles.color = xAxisColor;
                    if (xAxisColor.a <= 0.1f)
                    {
                        GUI.enabled = false;
                    }
                    if (((sgn > 0f) && Handles.Button((Vector3)(((direction * Vector3.forward) * size) * -1.2f), direction, size, size * 0.7f, new Handles.DrawCapFunction(Handles.ConeCap))) && !view.in2DMode)
                    {
                        this.ViewAxisDirection(view, i);
                    }
                    if (i < 3)
                    {
                        GUI.color = new Color(1f, 1f, 1f, this.dirVisible[i].faded * this.m_Visible.faded);
                        Vector3 vector2 = rhs;
                        vector2 += (Vector3)((num3 * view.camera.transform.forward) * -0.5f);
                        vector2  = (Vector3)(((vector2 * 0.7f) + (vector2.normalized * 1.5f)) * size);
                        Handles.Label(-vector2, new GUIContent(strArray[i]), styles.viewAxisLabelStyle);
                    }
                    if (((sgn < 0f) && Handles.Button((Vector3)(((direction * Vector3.forward) * size) * -1.2f), direction, size, size * 0.7f, new Handles.DrawCapFunction(Handles.ConeCap))) && !view.in2DMode)
                    {
                        this.ViewAxisDirection(view, i);
                    }
                    Handles.color = Color.white;
                    GUI.color     = Color.white;
                    GUI.enabled   = true;
                }
            }
        }
コード例 #3
0
        private void AxisSelectors(SceneView view, Camera cam, float size, float sgn, GUIStyle viewAxisLabelStyle)
        {
            for (int h = kDirectionRotations.Length - 1; h >= 0; h--)
            {
                Quaternion q1        = kDirectionRotations[h];
                float      a         = dirVisible[h % 3].faded;
                Vector3    direction = kDirectionRotations[h] * Vector3.forward;
                float      dot       = Vector3.Dot(view.camera.transform.forward, direction);

                if (dot <= 0.0 && sgn > 0.0f)
                {
                    continue;
                }

                if (dot > 0.0 && sgn < 0.0f)
                {
                    continue;
                }

                Color c;
                switch (h)
                {
                case 0: c = Handles.xAxisColor; break;

                case 1: c = Handles.yAxisColor; break;

                case 2: c = Handles.zAxisColor; break;

                default: c = Handles.centerColor; break;
                }

                if (view.in2DMode)
                {
                    c = Color.Lerp(c, Color.gray, faded2Dgray);
                }
                c.a *= a * fadedVisibility;

                if (QualitySettings.activeColorSpace == ColorSpace.Linear)
                {
                    c = c.linear;
                }

                Handles.color = c;

                if (c.a <= 0.1f || view.isRotationLocked)
                {
                    GUI.enabled = false;
                }

                // axis widget when drawn behind label
                if (sgn > 0 && Handles.Button(m_ViewDirectionControlIDs[h], q1 * Vector3.forward * size * -1.2f, q1, size, size * 0.7f, Handles.ConeHandleCap))
                {
                    if (!view.in2DMode && !view.isRotationLocked)
                    {
                        ViewAxisDirection(view, h);
                    }
                }

                // primary axes have text labels
                if (h < 3)
                {
                    GUI.color = new Color(1, 1, 1, dirVisible[h].faded * fadedVisibility);

                    // Label pos is a bit further out than the end of the cone
                    Vector3 pos = direction;
                    // Remove some of the perspective to avoid labels in front
                    // being much further away from the gizmo due to perspective
                    pos += dot * view.camera.transform.forward * -0.5f;
                    // Also remove some of the spacing difference caused by rotation
                    pos = (pos * 0.7f + pos.normalized * 1.5f) * size;
                    Handles.Label(-pos, s_HandleAxisLabels[h], styles.viewAxisLabelStyle);
                }

                // axis widget when drawn in front of label
                if (sgn < 0 && Handles.Button(m_ViewDirectionControlIDs[h], q1 * Vector3.forward * size * -1.2f, q1, size, size * 0.7f, Handles.ConeHandleCap))
                {
                    if (!view.in2DMode && !view.isRotationLocked)
                    {
                        ViewAxisDirection(view, h);
                    }
                }


                Handles.color = Color.white;
                GUI.color     = Color.white;
                GUI.enabled   = true;
            }
        }
コード例 #4
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)
        {
            float screenSize = Mathf.Min(view.position.width, view.position.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(view.position.width - kRotationSize + kRotationMenuInset, kRotationMenuInset, kRotationSize - 2 * kRotationMenuInset, kRotationSize + 24 - kRotationMenuInset), MouseCursor.Arrow);

            Handles.SetCamera(new Rect(view.position.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();
            }
        }
コード例 #5
0
        private void AxisSelectors(SceneView view, Camera cam, float size, float sgn, GUIStyle viewAxisLabelStyle)
        {
            for (int i = SceneViewRotation.kDirectionRotations.Length - 1; i >= 0; i--)
            {
                Quaternion quaternion = SceneViewRotation.kDirectionRotations[i];
                string[]   array      = new string[]
                {
                    "x",
                    "y",
                    "z"
                };
                float   faded  = this.dirVisible[i % 3].faded;
                Vector3 vector = SceneViewRotation.kDirectionRotations[i] * Vector3.forward;
                float   num    = Vector3.Dot(view.camera.transform.forward, vector);
                if ((double)num > 0.0 || sgn <= 0f)
                {
                    if ((double)num <= 0.0 || sgn >= 0f)
                    {
                        Color color;
                        switch (i)
                        {
                        case 0:
                            color = Handles.xAxisColor;
                            break;

                        case 1:
                            color = Handles.yAxisColor;
                            break;

                        case 2:
                            color = Handles.zAxisColor;
                            break;

                        default:
                            color = Handles.centerColor;
                            break;
                        }
                        if (view.in2DMode)
                        {
                            color = Color.Lerp(color, Color.gray, this.faded2Dgray);
                        }
                        color.a      *= faded * this.m_Visible.faded;
                        Handles.color = color;
                        if (color.a <= 0.1f)
                        {
                            GUI.enabled = false;
                        }
                        if (sgn > 0f && Handles.Button(this.m_ViewDirectionControlIDs[i], quaternion * Vector3.forward * size * -1.2f, quaternion, size, size * 0.7f, new Handles.DrawCapFunction(Handles.ConeCap)) && !view.in2DMode)
                        {
                            this.ViewAxisDirection(view, i);
                        }
                        if (i < 3)
                        {
                            GUI.color = new Color(1f, 1f, 1f, this.dirVisible[i].faded * this.m_Visible.faded);
                            Vector3 a = vector;
                            a += num * view.camera.transform.forward * -0.5f;
                            a  = (a * 0.7f + a.normalized * 1.5f) * size;
                            Handles.Label(-a, new GUIContent(array[i]), SceneViewRotation.styles.viewAxisLabelStyle);
                        }
                        if (sgn < 0f && Handles.Button(this.m_ViewDirectionControlIDs[i], quaternion * Vector3.forward * size * -1.2f, quaternion, size, size * 0.7f, new Handles.DrawCapFunction(Handles.ConeCap)) && !view.in2DMode)
                        {
                            this.ViewAxisDirection(view, i);
                        }
                        Handles.color = Color.white;
                        GUI.color     = Color.white;
                        GUI.enabled   = true;
                    }
                }
            }
        }
コード例 #6
0
        internal void OnGUI(SceneView view)
        {
            float num = Mathf.Min(view.position.width, view.position.height);

            if (num < 100f)
            {
                return;
            }
            if (Event.current.type == EventType.Repaint)
            {
                Profiler.BeginSample("SceneView.AxisSelector");
            }
            this.HandleContextClick(view);
            Camera camera = view.camera;

            HandleUtility.PushCamera(camera);
            if (camera.orthographic)
            {
                camera.orthographicSize = 0.5f;
            }
            camera.cullingMask        = 0;
            camera.transform.position = camera.transform.rotation * new Vector3(0f, 0f, -5f);
            camera.clearFlags         = CameraClearFlags.Nothing;
            camera.nearClipPlane      = 0.1f;
            camera.farClipPlane       = 10f;
            camera.fieldOfView        = view.m_Ortho.Fade(70f, 0f);
            SceneView.AddCursorRect(new Rect(view.position.width - 100f + 22f, 22f, 56f, 102f), MouseCursor.Arrow);
            Handles.SetCamera(new Rect(view.position.width - 100f, 0f, 100f, 100f), camera);
            Handles.BeginGUI();
            this.DrawLabels(view);
            Handles.EndGUI();
            for (int i = 0; i < 3; i++)
            {
                Vector3 rhs = SceneViewRotation.kDirectionRotations[i] * Vector3.forward;
                this.dirVisible[i].target = (Mathf.Abs(Vector3.Dot(camera.transform.forward, rhs)) < 0.9f);
            }
            float num2 = HandleUtility.GetHandleSize(Vector3.zero) * 0.2f;

            this.AxisSelectors(view, camera, num2, -1f, SceneViewRotation.styles.viewAxisLabelStyle);
            Color color = Handles.centerColor;

            color    = Color.Lerp(color, Color.gray, this.faded2Dgray);
            color.a *= this.m_Visible.faded;
            if (color.a <= 0.1f)
            {
                GUI.enabled = false;
            }
            Handles.color = color;
            if (Handles.Button(this.m_CenterButtonControlID, Vector3.zero, Quaternion.identity, num2 * 0.8f, num2, new Handles.DrawCapFunction(Handles.CubeCap)) && !view.in2DMode)
            {
                if (Event.current.clickCount == 2)
                {
                    view.FrameSelected();
                }
                else if (Event.current.shift || Event.current.button == 2)
                {
                    this.ViewFromNiceAngle(view, true);
                }
                else
                {
                    this.ViewSetOrtho(view, !view.orthographic);
                }
            }
            this.AxisSelectors(view, camera, num2, 1f, SceneViewRotation.styles.viewAxisLabelStyle);
            GUI.enabled = true;
            if (!view.in2DMode && Event.current.type == EditorGUIUtility.swipeGestureEventType)
            {
                Event   current = Event.current;
                Vector3 a;
                if (current.delta.y > 0f)
                {
                    a = Vector3.up;
                }
                else if (current.delta.y < 0f)
                {
                    a = -Vector3.up;
                }
                else if (current.delta.x < 0f)
                {
                    a = Vector3.right;
                }
                else
                {
                    a = -Vector3.right;
                }
                Vector3 vector = -a - Vector3.forward * 0.9f;
                vector = view.camera.transform.TransformDirection(vector);
                float num3 = 0f;
                int   dir  = 0;
                for (int j = 0; j < 6; j++)
                {
                    float num4 = Vector3.Dot(SceneViewRotation.kDirectionRotations[j] * -Vector3.forward, vector);
                    if (num4 > num3)
                    {
                        num3 = num4;
                        dir  = j;
                    }
                }
                this.ViewAxisDirection(view, dir);
                Event.current.Use();
            }
            HandleUtility.PopCamera(camera);
            Handles.SetCamera(camera);
            if (Event.current.type == EventType.Repaint)
            {
                Profiler.EndSample();
            }
        }
コード例 #7
0
        private void AxisSelectors(SceneView view, Camera cam, float size, float sgn, GUIStyle viewAxisLabelStyle)
        {
            for (int i = SceneViewRotation.kDirectionRotations.Length - 1; i >= 0; i--)
            {
                Quaternion quaternion = SceneViewRotation.kDirectionRotations[i];
                float      faded      = this.dirVisible[i % 3].faded;
                Vector3    vector     = SceneViewRotation.kDirectionRotations[i] * Vector3.forward;
                float      num        = Vector3.Dot(view.camera.transform.forward, vector);
                if ((double)num > 0.0 || sgn <= 0f)
                {
                    if ((double)num <= 0.0 || sgn >= 0f)
                    {
                        Color color;
                        switch (i)
                        {
                        case 0:
                            color = Handles.xAxisColor;
                            break;

                        case 1:
                            color = Handles.yAxisColor;
                            break;

                        case 2:
                            color = Handles.zAxisColor;
                            break;

                        default:
                            color = Handles.centerColor;
                            break;
                        }
                        if (view.in2DMode)
                        {
                            color = Color.Lerp(color, Color.gray, this.faded2Dgray);
                        }
                        color.a *= faded * this.fadedVisibility;
                        if (QualitySettings.activeColorSpace == ColorSpace.Linear)
                        {
                            color = color.linear;
                        }
                        Handles.color = color;
                        if (color.a <= 0.1f || view.isRotationLocked)
                        {
                            GUI.enabled = false;
                        }
                        if (sgn > 0f)
                        {
                            int        arg_1B9_0 = this.m_ViewDirectionControlIDs[i];
                            Vector3    arg_1B9_1 = quaternion * Vector3.forward * size * -1.2f;
                            Quaternion arg_1B9_2 = quaternion;
                            float      arg_1B9_4 = size * 0.7f;
                            if (SceneViewRotation.< > f__mg$cache0 == null)
                            {
                                SceneViewRotation.< > f__mg$cache0 = new Handles.CapFunction(Handles.ConeHandleCap);
                            }
                            if (Handles.Button(arg_1B9_0, arg_1B9_1, arg_1B9_2, size, arg_1B9_4, SceneViewRotation.< > f__mg$cache0))
                            {
                                if (!view.in2DMode && !view.isRotationLocked)
                                {
                                    this.ViewAxisDirection(view, i);
                                }
                            }
                        }
                        if (i < 3)
                        {
                            GUI.color = new Color(1f, 1f, 1f, this.dirVisible[i].faded * this.fadedVisibility);
                            Vector3 a = vector;
                            a += num * view.camera.transform.forward * -0.5f;
                            a  = (a * 0.7f + a.normalized * 1.5f) * size;
                            Handles.Label(-a, SceneViewRotation.s_HandleAxisLabels[i], SceneViewRotation.styles.viewAxisLabelStyle);
                        }
                        if (sgn < 0f)
                        {
                            int        arg_2E2_0 = this.m_ViewDirectionControlIDs[i];
                            Vector3    arg_2E2_1 = quaternion * Vector3.forward * size * -1.2f;
                            Quaternion arg_2E2_2 = quaternion;
                            float      arg_2E2_4 = size * 0.7f;
                            if (SceneViewRotation.< > f__mg$cache1 == null)
                            {
                                SceneViewRotation.< > f__mg$cache1 = new Handles.CapFunction(Handles.ConeHandleCap);
                            }
                            if (Handles.Button(arg_2E2_0, arg_2E2_1, arg_2E2_2, size, arg_2E2_4, SceneViewRotation.< > f__mg$cache1))
                            {
                                if (!view.in2DMode && !view.isRotationLocked)
                                {
                                    this.ViewAxisDirection(view, i);
                                }
                            }
                        }
                        Handles.color = Color.white;
                        GUI.color     = Color.white;
                        GUI.enabled   = true;
                    }
                }
            }
        }
コード例 #8
0
        void OnSceneGUI()
        {
            var spline = target as SplineComponent;

            var e = Event.current;

            GUIUtility.GetControlID(FocusType.Passive);

            var mousePos       = (Vector2)Event.current.mousePosition;
            var view           = SceneView.currentDrawingSceneView.camera.ScreenToViewportPoint(Event.current.mousePosition);
            var mouseIsOutside = view.x < 0 || view.x > 1 || view.y < 0 || view.y > 1;

            if (mouseIsOutside)
            {
                return;
            }

            var points = serializedObject.FindProperty("points");

            if (Event.current.shift)
            {
                if (spline.closed)
                {
                    ShowClosestPointOnClosedSpline(points);
                }
                else
                {
                    ShowClosestPointOnOpenSpline(points);
                }
            }

            for (int i = 0; i < spline.points.Count; i++)
            {
                var prop  = points.GetArrayElementAtIndex(i);
                var point = prop.vector3Value;
                var wp    = spline.transform.TransformPoint(point);

                if (hotIndex == i)
                {
                    var newWp = Handles.PositionHandle(wp, Tools.pivotRotation == PivotRotation.Global ? Quaternion.identity : spline.transform.rotation);
                    var delta = spline.transform.InverseTransformDirection(newWp - wp);
                    if (delta.sqrMagnitude > 0)
                    {
                        prop.vector3Value = point + delta;
                        spline.ResetIndex();
                    }
                    HandleCommands(wp);
                }

                Handles.color = i == 0 | i == spline.points.Count - 1 ? Color.red : Color.white;
                var buttonSize = HandleUtility.GetHandleSize(wp) * 0.1f;
                if (Handles.Button(wp, Quaternion.identity, buttonSize, buttonSize, Handles.SphereHandleCap))
                {
                    hotIndex = i;
                }

                var v = SceneView.currentDrawingSceneView.camera.transform.InverseTransformPoint(wp);
                var labelIsOutside = v.z < 0;
                if (!labelIsOutside)
                {
                    Handles.Label(wp, i.ToString());
                }
            }

            if (removeIndex >= 0 && points.arraySize > 4)
            {
                points.DeleteArrayElementAtIndex(removeIndex);
                spline.ResetIndex();
            }

            removeIndex = -1;
            serializedObject.ApplyModifiedProperties();
        }
コード例 #9
0
        private void AxisSelectors(SceneView view, Camera cam, float size, float sgn, GUIStyle viewAxisLabelStyle)
        {
            for (int dir = SceneViewRotation.kDirectionRotations.Length - 1; dir >= 0; --dir)
            {
                Quaternion directionRotation = SceneViewRotation.kDirectionRotations[dir];
                string[]   strArray          = new string[3] {
                    "x", "y", "z"
                };
                float   faded = this.dirVisible[dir % 3].faded;
                Vector3 rhs   = SceneViewRotation.kDirectionRotations[dir] * Vector3.forward;
                float   num   = Vector3.Dot(view.camera.transform.forward, rhs);
                if (((double)num > 0.0 || (double)sgn <= 0.0) && ((double)num <= 0.0 || (double)sgn >= 0.0))
                {
                    Color a;
                    switch (dir)
                    {
                    case 0:
                        a = Handles.xAxisColor;
                        break;

                    case 1:
                        a = Handles.yAxisColor;
                        break;

                    case 2:
                        a = Handles.zAxisColor;
                        break;

                    default:
                        a = Handles.centerColor;
                        break;
                    }
                    if (view.in2DMode)
                    {
                        a = Color.Lerp(a, Color.gray, this.faded2Dgray);
                    }
                    a.a          *= faded * this.m_Visible.faded;
                    Handles.color = a;
                    if ((double)a.a <= 0.100000001490116)
                    {
                        GUI.enabled = false;
                    }
                    if ((double)sgn > 0.0 && Handles.Button(this.m_ViewDirectionControlIDs[dir], directionRotation * Vector3.forward * size * -1.2f, directionRotation, size, size * 0.7f, new Handles.DrawCapFunction(Handles.ConeCap)) && !view.in2DMode)
                    {
                        this.ViewAxisDirection(view, dir);
                    }
                    if (dir < 3)
                    {
                        GUI.color = new Color(1f, 1f, 1f, this.dirVisible[dir].faded * this.m_Visible.faded);
                        Vector3 vector3 = rhs + num * view.camera.transform.forward * -0.5f;
                        Handles.Label(-((vector3 * 0.7f + vector3.normalized * 1.5f) * size), new GUIContent(strArray[dir]), SceneViewRotation.styles.viewAxisLabelStyle);
                    }
                    if ((double)sgn < 0.0 && Handles.Button(this.m_ViewDirectionControlIDs[dir], directionRotation * Vector3.forward * size * -1.2f, directionRotation, size, size * 0.7f, new Handles.DrawCapFunction(Handles.ConeCap)) && !view.in2DMode)
                    {
                        this.ViewAxisDirection(view, dir);
                    }
                    Handles.color = Color.white;
                    GUI.color     = Color.white;
                    GUI.enabled   = true;
                }
            }
        }
コード例 #10
0
        internal void OnGUI(SceneView view)
        {
            if ((double)Mathf.Min(view.position.width, view.position.height) < 100.0)
            {
                return;
            }
            if (Event.current.type == EventType.Repaint)
            {
                Profiler.BeginSample("SceneView.AxisSelector");
            }
            this.HandleContextClick(view);
            Camera camera = view.camera;

            HandleUtility.PushCamera(camera);
            if (camera.orthographic)
            {
                camera.orthographicSize = 0.5f;
            }
            camera.cullingMask        = 0;
            camera.transform.position = camera.transform.rotation * new Vector3(0.0f, 0.0f, -5f);
            camera.clearFlags         = CameraClearFlags.Nothing;
            camera.nearClipPlane      = 0.1f;
            camera.farClipPlane       = 10f;
            camera.fieldOfView        = view.m_Ortho.Fade(70f, 0.0f);
            SceneView.AddCursorRect(new Rect((float)((double)view.position.width - 100.0 + 22.0), 22f, 56f, 102f), MouseCursor.Arrow);
            Handles.SetCamera(new Rect(view.position.width - 100f, 0.0f, 100f, 100f), camera);
            Handles.BeginGUI();
            this.DrawLabels(view);
            Handles.EndGUI();
            for (int index = 0; index < 3; ++index)
            {
                Vector3 rhs = SceneViewRotation.kDirectionRotations[index] * Vector3.forward;
                this.dirVisible[index].target = (double)Mathf.Abs(Vector3.Dot(camera.transform.forward, rhs)) < 0.899999976158142;
            }
            float num1 = HandleUtility.GetHandleSize(Vector3.zero) * 0.2f;

            this.AxisSelectors(view, camera, num1, -1f, SceneViewRotation.styles.viewAxisLabelStyle);
            Color color = Color.Lerp(Handles.centerColor, Color.gray, this.faded2Dgray);

            color.a *= this.m_Visible.faded;
            if ((double)color.a <= 0.100000001490116)
            {
                GUI.enabled = false;
            }
            Handles.color = color;
            if (Handles.Button(this.m_CenterButtonControlID, Vector3.zero, Quaternion.identity, num1 * 0.8f, num1, new Handles.DrawCapFunction(Handles.CubeCap)) && !view.in2DMode)
            {
                if (Event.current.clickCount == 2)
                {
                    view.FrameSelected();
                }
                else if (Event.current.shift || Event.current.button == 2)
                {
                    this.ViewFromNiceAngle(view, true);
                }
                else
                {
                    this.ViewSetOrtho(view, !view.orthographic);
                }
            }
            this.AxisSelectors(view, camera, num1, 1f, SceneViewRotation.styles.viewAxisLabelStyle);
            GUI.enabled = true;
            if (!view.in2DMode && Event.current.type == EditorGUIUtility.swipeGestureEventType)
            {
                Event   current   = Event.current;
                Vector3 direction = -((double)current.delta.y <= 0.0 ? ((double)current.delta.y >= 0.0 ? ((double)current.delta.x >= 0.0 ? -Vector3.right : Vector3.right) : -Vector3.up) : Vector3.up) - Vector3.forward * 0.9f;
                Vector3 rhs       = view.camera.transform.TransformDirection(direction);
                float   num2      = 0.0f;
                int     dir       = 0;
                for (int index = 0; index < 6; ++index)
                {
                    float num3 = Vector3.Dot(SceneViewRotation.kDirectionRotations[index] * -Vector3.forward, rhs);
                    if ((double)num3 > (double)num2)
                    {
                        num2 = num3;
                        dir  = index;
                    }
                }
                this.ViewAxisDirection(view, dir);
                Event.current.Use();
            }
            HandleUtility.PopCamera(camera);
            Handles.SetCamera(camera);
            if (Event.current.type != EventType.Repaint)
            {
                return;
            }
            Profiler.EndSample();
        }
コード例 #11
0
        internal void OnGUI(SceneView view)
        {
            int num = Mathf.Min(Screen.width, Screen.height);

            if (num < 100)
            {
                return;
            }
            if (Event.current.type == EventType.Repaint)
            {
                Profiler.BeginSample("SceneView.AxisSelector");
            }
            Camera camera = view.camera;

            HandleUtility.PushCamera(camera);
            if (camera.orthographic)
            {
                camera.orthographicSize = 0.5f;
            }
            camera.cullingMask        = 0;
            camera.transform.position = camera.transform.rotation * new Vector3(0f, 0f, -5f);
            camera.clearFlags         = CameraClearFlags.Nothing;
            camera.nearClipPlane      = 0.1f;
            camera.farClipPlane       = 10f;
            camera.fieldOfView        = view.m_Ortho.Fade(70f, 0f);
            SceneView.AddCursorRect(new Rect((float)(Screen.width - 100 + 22), 22f, 56f, 102f), MouseCursor.Arrow);
            Handles.SetCamera(new Rect((float)(Screen.width - 100), 0f, 100f, 100f), camera);
            Handles.BeginGUI();
            Rect rect = new Rect((float)(Screen.width - 100 + 17), 92f, 66f, 16f);

            if (!view.in2DMode && GUI.Button(rect, string.Empty, SceneViewRotation.styles.viewLabelStyleLeftAligned))
            {
                if (Event.current.button == 1)
                {
                    this.DisplayContextMenu(rect, view);
                }
                else
                {
                    this.ViewSetOrtho(view, !view.orthographic);
                }
            }
            int   num2     = 8;
            Rect  position = rect;
            float num3     = 0f;
            float num4     = 0f;

            for (int i = 0; i < SceneViewRotation.kDirNames.Length; i++)
            {
                if (i != num2)
                {
                    num4 += this.dirNameVisible[i].faded;
                    if (this.dirNameVisible[i].faded > 0f)
                    {
                        num3 += SceneViewRotation.styles.viewLabelStyleLeftAligned.CalcSize(EditorGUIUtility.TempContent(SceneViewRotation.kDirNames[i])).x *this.dirNameVisible[i].faded;
                    }
                }
            }
            if (num4 > 0f)
            {
                num3 /= num4;
            }
            position.x += 37f - num3 * 0.5f;
            position.x  = (float)Mathf.RoundToInt(position.x);
            int num5 = 0;

            while (num5 < this.dirNameVisible.Length && num5 < SceneViewRotation.kDirNames.Length)
            {
                if (num5 != num2)
                {
                    Color centerColor = Handles.centerColor;
                    centerColor.a *= this.dirNameVisible[num5].faded;
                    if (centerColor.a > 0f)
                    {
                        GUI.color = centerColor;
                        GUI.Label(position, SceneViewRotation.kDirNames[num5], SceneViewRotation.styles.viewLabelStyleLeftAligned);
                    }
                }
                num5++;
            }
            Color centerColor2 = Handles.centerColor;

            centerColor2.a *= this.faded2Dgray * this.m_Visible.faded;
            if (centerColor2.a > 0f)
            {
                GUI.color = centerColor2;
                GUI.Label(rect, SceneViewRotation.kDirNames[num2], SceneViewRotation.styles.viewLabelStyleCentered);
            }
            if (this.faded2Dgray < 1f)
            {
                this.DrawIsoStatusSymbol(new Vector3(position.x - 8f, position.y + 8.5f, 0f), view, 1f - this.faded2Dgray);
            }
            Handles.EndGUI();
            for (int j = 0; j < 3; j++)
            {
                Vector3 rhs = SceneViewRotation.kDirectionRotations[j] * Vector3.forward;
                this.dirVisible[j].target = (Mathf.Abs(Vector3.Dot(camera.transform.forward, rhs)) < 0.9f);
            }
            float num6 = HandleUtility.GetHandleSize(Vector3.zero) * 0.2f;

            this.AxisSelectors(view, camera, num6, -1f, SceneViewRotation.styles.viewAxisLabelStyle);
            Color color = Handles.centerColor;

            color    = Color.Lerp(color, Color.gray, this.faded2Dgray);
            color.a *= this.m_Visible.faded;
            if (color.a <= 0.1f)
            {
                GUI.enabled = false;
            }
            Handles.color = color;
            if (Handles.Button(Vector3.zero, Quaternion.identity, num6 * 0.8f, num6, new Handles.DrawCapFunction(Handles.CubeCap)) && !view.in2DMode)
            {
                if (Event.current.clickCount == 2)
                {
                    view.FrameSelected();
                }
                else
                {
                    if (Event.current.shift || Event.current.button == 2)
                    {
                        this.ViewFromNiceAngle(view, true);
                    }
                    else
                    {
                        this.ViewSetOrtho(view, !view.orthographic);
                    }
                }
            }
            this.AxisSelectors(view, camera, num6, 1f, SceneViewRotation.styles.viewAxisLabelStyle);
            GUI.enabled = true;
            if (!view.in2DMode && Event.current.type == EditorGUIUtility.swipeGestureEventType)
            {
                Event   current = Event.current;
                Vector3 a;
                if (current.delta.y > 0f)
                {
                    a = Vector3.up;
                }
                else
                {
                    if (current.delta.y < 0f)
                    {
                        a = -Vector3.up;
                    }
                    else
                    {
                        if (current.delta.x < 0f)
                        {
                            a = Vector3.right;
                        }
                        else
                        {
                            a = -Vector3.right;
                        }
                    }
                }
                Vector3 vector = -a - Vector3.forward * 0.9f;
                vector = view.camera.transform.TransformDirection(vector);
                float num7 = 0f;
                int   dir  = 0;
                for (int k = 0; k < 6; k++)
                {
                    float num8 = Vector3.Dot(SceneViewRotation.kDirectionRotations[k] * -Vector3.forward, vector);
                    if (num8 > num7)
                    {
                        num7 = num8;
                        dir  = k;
                    }
                }
                this.ViewAxisDirection(view, dir);
                Event.current.Use();
            }
            HandleUtility.PopCamera(camera);
            Handles.SetCamera(camera);
            if (Event.current.type == EventType.Repaint)
            {
                Profiler.EndSample();
            }
        }