示例#1
0
        private void DrawAgentDiagram(Rect rect, float agentRadius, float agentHeight, float agentClimb, float agentSlope)
        {
            if (Event.current.type != EventType.Repaint)
            {
                return;
            }
            float num1  = agentRadius;
            float num2  = agentHeight;
            float num3  = agentClimb;
            float num4  = 0.35f;
            float num5  = 15f;
            float num6  = rect.height - num5 * 2f;
            float num7  = Mathf.Min(num6 / (num2 + num1 * 2f * num4), num6 / (num1 * 2f));
            float num8  = num2 * num7;
            float num9  = num1 * num7;
            float num10 = num3 * num7;
            float x1    = rect.xMin + rect.width * 0.5f;
            float y1    = (float)((double)rect.yMax - (double)num5 - (double)num9 * (double)num4);

            Vector3[] vector3Array1 = new Vector3[40];
            Vector3[] vector3Array2 = new Vector3[20];
            Vector3[] vector3Array3 = new Vector3[20];
            for (int index = 0; index < 20; ++index)
            {
                float f     = (float)((double)index / 19.0 * 3.14159274101257);
                float num11 = Mathf.Cos(f);
                float num12 = Mathf.Sin(f);
                vector3Array1[index]      = new Vector3(x1 + num11 * num9, (float)((double)y1 - (double)num8 - (double)num12 * (double)num9 * (double)num4), 0.0f);
                vector3Array1[index + 20] = new Vector3(x1 - num11 * num9, y1 + num12 * num9 * num4, 0.0f);
                vector3Array2[index]      = new Vector3(x1 - num11 * num9, (float)((double)y1 - (double)num8 + (double)num12 * (double)num9 * (double)num4), 0.0f);
                vector3Array3[index]      = new Vector3(x1 - num11 * num9, (float)((double)y1 - (double)num10 + (double)num12 * (double)num9 * (double)num4), 0.0f);
            }
            Color color = Handles.color;
            float xMin  = rect.xMin;
            float y2    = y1 - num10;
            float x2    = x1 - num6 * 0.75f;
            float y3    = y1;
            float x3    = x1 + num6 * 0.75f;
            float y4    = y1;
            float num13 = x3;
            float num14 = y4;
            float num15 = rect.xMax - x3;
            float x4    = num13 + Mathf.Cos(agentSlope * ((float)Math.PI / 180f)) * num15;
            float y5    = num14 - Mathf.Sin(agentSlope * ((float)Math.PI / 180f)) * num15;

            Vector3[] vector3Array4 = new Vector3[2] {
                new Vector3(xMin, y1, 0.0f), new Vector3(x4, y1, 0.0f)
            };
            Vector3[] vector3Array5 = new Vector3[5] {
                new Vector3(xMin, y2, 0.0f), new Vector3(x2, y2, 0.0f), new Vector3(x2, y3, 0.0f), new Vector3(x3, y4, 0.0f), new Vector3(x4, y5, 0.0f)
            };
            Handles.color = !EditorGUIUtility.isProSkin ? new Color(1f, 1f, 1f, 0.5f) : new Color(0.0f, 0.0f, 0.0f, 0.5f);
            Handles.DrawAAPolyLine(2f, vector3Array4);
            Handles.color = !EditorGUIUtility.isProSkin ? new Color(0.0f, 0.0f, 0.0f, 0.5f) : new Color(1f, 1f, 1f, 0.5f);
            Handles.DrawAAPolyLine(3f, vector3Array5);
            Handles.color = Color.Lerp(new Color(0.0f, 0.75f, 1f, 1f), new Color(0.5f, 0.5f, 0.5f, 0.5f), 0.2f);
            Handles.DrawAAConvexPolygon(vector3Array1);
            Handles.color = new Color(0.0f, 0.0f, 0.0f, 0.5f);
            Handles.DrawAAPolyLine(2f, vector3Array3);
            Handles.color = new Color(1f, 1f, 1f, 0.4f);
            Handles.DrawAAPolyLine(2f, vector3Array2);
            Vector3[] vector3Array6 = new Vector3[2] {
                new Vector3(x1, y1 - num8, 0.0f), new Vector3(x1 + num9, y1 - num8, 0.0f)
            };
            Handles.color = new Color(0.0f, 0.0f, 0.0f, 0.5f);
            Handles.DrawAAPolyLine(2f, vector3Array6);
            GUI.Label(new Rect((float)((double)x1 + (double)num9 + 5.0), (float)((double)y1 - (double)num8 * 0.5 - 10.0), 150f, 20f), string.Format("H = {0}", (object)agentHeight));
            GUI.Label(new Rect(x1, (float)((double)y1 - (double)num8 - (double)num9 * (double)num4 - 15.0), 150f, 20f), string.Format("R = {0}", (object)agentRadius));
            GUI.Label(new Rect((float)(((double)xMin + (double)x2) * 0.5 - 20.0), y2 - 15f, 150f, 20f), string.Format("{0}", (object)agentClimb));
            GUI.Label(new Rect(x3 + 20f, y4 - 15f, 150f, 20f), string.Format("{0}°", (object)agentSlope));
            Handles.color = color;
        }
        public void OnSceneGUI()
        {
            if (m_ActiveCollider == null)
            {
                return;
            }

            // Skip editing of polygon if view tool is active i.e. while panning the scene view
            if (Tools.viewToolActive)
            {
                return;
            }

            // Fetch the collider offset.
            var colliderOffset = m_ActiveCollider.offset;

            Event evt = Event.current;

            m_DeleteMode = evt.command || evt.control;
            Transform transform = m_ActiveCollider.transform;

            // Handles.Slider2D will render active point as yellow if there is keyboardControl set. We don't want that happening.
            GUIUtility.keyboardControl = 0;

            HandleUtility.s_CustomPickDistance = k_HandlePickDistance;

            // Find mouse positions in local and world space
            Plane plane    = new Plane(-transform.forward, Vector3.zero);
            Ray   mouseRay = HandleUtility.GUIPointToWorldRay(evt.mousePosition);
            float dist;

            plane.Raycast(mouseRay, out dist);

            Vector3 mouseWorldPos = mouseRay.GetPoint(dist);
            Vector2 mouseLocalPos = transform.InverseTransformPoint(mouseWorldPos);

            // Select the active vertex and edge
            if (evt.type == EventType.MouseMove || m_FirstOnSceneGUIAfterReset)
            {
                int   pathIndex;
                int   pointIndex0, pointIndex1;
                float distance;
                if (PolygonEditor.GetNearestPoint(mouseLocalPos - colliderOffset, out pathIndex, out pointIndex0, out distance))
                {
                    m_SelectedPath   = pathIndex;
                    m_SelectedVertex = pointIndex0;
                }
                else
                {
                    m_SelectedPath = -1;
                }

                if (PolygonEditor.GetNearestEdge(mouseLocalPos - colliderOffset, out pathIndex, out pointIndex0, out pointIndex1, out distance, m_LoopingCollider))
                {
                    m_SelectedEdgePath    = pathIndex;
                    m_SelectedEdgeVertex0 = pointIndex0;
                    m_SelectedEdgeVertex1 = pointIndex1;
                }
                else
                {
                    m_SelectedEdgePath = -1;
                }

                if (evt.type == EventType.MouseMove)
                {
                    evt.Use();
                }
            }
            else if (evt.type == EventType.MouseUp)
            {
                m_LeftIntersect  = false;
                m_RightIntersect = false;
            }

            // Do we handle point or line?
            // TODO: there probably isn't a case when selectedPath is valid and selectedEdge is invalid. This needs a refactor.


            if (GUIUtility.hotControl == 0)
            {
                if (m_SelectedPath != -1 && m_SelectedEdgePath != -1)
                {
                    // Calculate snapping distance
                    Vector2 point;
                    PolygonEditor.GetPoint(m_SelectedPath, m_SelectedVertex, out point);
                    point += colliderOffset;
                    Vector3 worldPos = transform.TransformPoint(point);
                    m_HandleEdge  = (HandleUtility.WorldToGUIPoint(worldPos) - Event.current.mousePosition).sqrMagnitude > k_HandlePointSnap * k_HandlePointSnap;
                    m_HandlePoint = !m_HandleEdge;
                }
                else if (m_SelectedPath != -1)
                {
                    m_HandlePoint = true;
                }
                else if (m_SelectedEdgePath != -1)
                {
                    m_HandleEdge = true;
                }

                if (m_DeleteMode && m_HandleEdge)
                {
                    m_HandleEdge  = false;
                    m_HandlePoint = true;
                }
            }

            // If this is a polygon collider being used by a composite then draw the polygon paths.
            if ((m_ActiveCollider is PolygonCollider2D) && m_ActiveCollider.usedByComposite)
            {
                DrawPolygonCollider(transform);
            }

            bool applyToCollider = false;

            // Edge handle
            if (m_HandleEdge && !m_DeleteMode)
            {
                Vector2 p0, p1;
                PolygonEditor.GetPoint(m_SelectedEdgePath, m_SelectedEdgeVertex0, out p0);
                PolygonEditor.GetPoint(m_SelectedEdgePath, m_SelectedEdgeVertex1, out p1);
                p0 += colliderOffset;
                p1 += colliderOffset;
                Vector3 worldPosV0 = transform.TransformPoint(p0);
                Vector3 worldPosV1 = transform.TransformPoint(p1);
                worldPosV0.z = worldPosV1.z = 0;

                Handles.color = Color.green;
                Handles.DrawAAPolyLine(4.0f, new Vector3[] { worldPosV0, worldPosV1 });
                Handles.color = Color.white;

                Vector2 newPoint = GetNearestPointOnEdge(transform.TransformPoint(mouseLocalPos), worldPosV0, worldPosV1);

                EditorGUI.BeginChangeCheck();
                float guiSize = HandleUtility.GetHandleSize(newPoint) * 0.04f;
                Handles.color = Color.green;

                newPoint = Handles.Slider2D(
                    newPoint,
                    new Vector3(0, 0, 1),
                    new Vector3(1, 0, 0),
                    new Vector3(0, 1, 0),
                    guiSize,
                    Handles.DotHandleCap,
                    Vector3.zero);
                Handles.color = Color.white;
                if (EditorGUI.EndChangeCheck())
                {
                    PolygonEditor.InsertPoint(m_SelectedEdgePath, m_SelectedEdgeVertex1, ((p0 + p1) / 2) - colliderOffset);
                    m_SelectedPath   = m_SelectedEdgePath;
                    m_SelectedVertex = m_SelectedEdgeVertex1;
                    m_HandleEdge     = false;
                    m_HandlePoint    = true;
                    applyToCollider  = true;
                }
            }

            // Point handle
            if (m_HandlePoint)
            {
                Vector2 point;
                PolygonEditor.GetPoint(m_SelectedPath, m_SelectedVertex, out point);
                point += colliderOffset;
                Vector3 worldPos = transform.TransformPoint(point);
                worldPos.z = 0;
                Vector2 screenPos = HandleUtility.WorldToGUIPoint(worldPos);

                float guiSize = HandleUtility.GetHandleSize(worldPos) * 0.04f;

                if (m_DeleteMode && evt.type == EventType.MouseDown &&
                    Vector2.Distance(screenPos, Event.current.mousePosition) < k_HandlePickDistance ||
                    DeleteCommandEvent(evt))
                {
                    if (evt.type != EventType.ValidateCommand)
                    {
                        int pathPointCount = PolygonEditor.GetPointCount(m_SelectedPath);
                        if (pathPointCount > m_MinPathPoints)
                        {
                            PolygonEditor.RemovePoint(m_SelectedPath, m_SelectedVertex);
                            Reset();
                            applyToCollider = true;
                        }
                    }
                    evt.Use();
                }

                EditorGUI.BeginChangeCheck();
                Handles.color = m_DeleteMode ? Color.red : Color.green;
                Vector3 newWorldPos = Handles.Slider2D(
                    worldPos,
                    new Vector3(0, 0, 1),
                    new Vector3(1, 0, 0),
                    new Vector3(0, 1, 0),
                    guiSize,
                    Handles.DotHandleCap,
                    Vector3.zero);
                Handles.color = Color.white;
                if (EditorGUI.EndChangeCheck() && !m_DeleteMode)
                {
                    point  = transform.InverseTransformPoint(newWorldPos);
                    point -= colliderOffset;
                    PolygonEditor.TestPointMove(m_SelectedPath, m_SelectedVertex, point, out m_LeftIntersect, out m_RightIntersect, m_LoopingCollider);
                    PolygonEditor.SetPoint(m_SelectedPath, m_SelectedVertex, point);
                    applyToCollider = true;
                }

                if (!applyToCollider)
                {
                    DrawEdgesForSelectedPoint(newWorldPos, transform, m_LeftIntersect, m_RightIntersect, m_LoopingCollider);
                }
            }

            // Apply changes
            if (applyToCollider)
            {
                Undo.RecordObject(m_ActiveCollider, "Edit Collider");
                PolygonEditor.ApplyEditing(m_ActiveCollider);
            }

            if (DeleteCommandEvent(evt))
            {
                Event.current.Use();  // If we don't use the delete event in all cases, it sceneview might delete the entire object
            }
            m_FirstOnSceneGUIAfterReset = false;
        }
示例#3
0
        private void DrawAgentDiagram(Rect rect, float agentRadius, float agentHeight, float agentClimb, float agentSlope)
        {
            if (Event.current.type != EventType.Repaint)
            {
                return;
            }
            float num  = 0.35f;
            float num2 = 15f;
            float num3 = rect.height - num2 * 2f;
            float num4 = Mathf.Min(num3 / (agentHeight + agentRadius * 2f * num), num3 / (agentRadius * 2f));
            float num5 = agentHeight * num4;
            float num6 = agentRadius * num4;
            float num7 = agentClimb * num4;
            float num8 = rect.xMin + rect.width * 0.5f;
            float num9 = rect.yMax - num2 - num6 * num;

            Vector3[] array  = new Vector3[40];
            Vector3[] array2 = new Vector3[20];
            Vector3[] array3 = new Vector3[20];
            for (int i = 0; i < 20; i++)
            {
                float f     = (float)i / 19f * 3.14159274f;
                float num10 = Mathf.Cos(f);
                float num11 = Mathf.Sin(f);
                array[i]      = new Vector3(num8 + num10 * num6, num9 - num5 - num11 * num6 * num, 0f);
                array[i + 20] = new Vector3(num8 - num10 * num6, num9 + num11 * num6 * num, 0f);
                array2[i]     = new Vector3(num8 - num10 * num6, num9 - num5 + num11 * num6 * num, 0f);
                array3[i]     = new Vector3(num8 - num10 * num6, num9 - num7 + num11 * num6 * num, 0f);
            }
            Color color = Handles.color;
            float xMin  = rect.xMin;
            float num12 = num9 - num7;
            float num13 = num8 - num3 * 0.75f;
            float y     = num9;
            float num14 = num8 + num3 * 0.75f;
            float num15 = num9;
            float num16 = num14;
            float num17 = num15;
            float num18 = rect.xMax - num14;

            num16 += Mathf.Cos(agentSlope * 0.0174532924f) * num18;
            num17 -= Mathf.Sin(agentSlope * 0.0174532924f) * num18;
            Vector3[] points = new Vector3[]
            {
                new Vector3(xMin, num9, 0f),
                new Vector3(num16, num9, 0f)
            };
            Vector3[] points2 = new Vector3[]
            {
                new Vector3(xMin, num12, 0f),
                new Vector3(num13, num12, 0f),
                new Vector3(num13, y, 0f),
                new Vector3(num14, num15, 0f),
                new Vector3(num16, num17, 0f)
            };
            Handles.color = ((!EditorGUIUtility.isProSkin) ? new Color(1f, 1f, 1f, 0.5f) : new Color(0f, 0f, 0f, 0.5f));
            Handles.DrawAAPolyLine(2f, points);
            Handles.color = ((!EditorGUIUtility.isProSkin) ? new Color(0f, 0f, 0f, 0.5f) : new Color(1f, 1f, 1f, 0.5f));
            Handles.DrawAAPolyLine(3f, points2);
            Handles.color = Color.Lerp(new Color(0f, 0.75f, 1f, 1f), new Color(0.5f, 0.5f, 0.5f, 0.5f), 0.2f);
            Handles.DrawAAConvexPolygon(array);
            Handles.color = new Color(0f, 0f, 0f, 0.5f);
            Handles.DrawAAPolyLine(2f, array3);
            Handles.color = new Color(1f, 1f, 1f, 0.4f);
            Handles.DrawAAPolyLine(2f, array2);
            Vector3[] points3 = new Vector3[]
            {
                new Vector3(num8, num9 - num5, 0f),
                new Vector3(num8 + num6, num9 - num5, 0f)
            };
            Handles.color = new Color(0f, 0f, 0f, 0.5f);
            Handles.DrawAAPolyLine(2f, points3);
            GUI.Label(new Rect(num8 + num6 + 5f, num9 - num5 * 0.5f - 10f, 150f, 20f), string.Format("H = {0}", agentHeight));
            GUI.Label(new Rect(num8, num9 - num5 - num6 * num - 15f, 150f, 20f), string.Format("R = {0}", agentRadius));
            GUI.Label(new Rect((xMin + num13) * 0.5f - 20f, num12 - 15f, 150f, 20f), string.Format("{0}", agentClimb));
            GUI.Label(new Rect(num14 + 20f, num15 - 15f, 150f, 20f), string.Format("{0}°", agentSlope));
            Handles.color = color;
        }
        public void OnSceneGUI()
        {
            if (!target)
            {
                return;
            }
            var effector = (BuoyancyEffector2D)target;

            // Ignore disabled effector.
            if (!effector.enabled)
            {
                return;
            }


            var effectorPosition = effector.transform.position;
            var surfaceY         = effectorPosition.y + (effector.transform.lossyScale.y * effector.surfaceLevel);

            var intersections = new List <Vector3>();
            var farLeft       = float.NegativeInfinity;
            var farRight      = farLeft;

            // Fetch all the effector-collider bounds.
            foreach (var c in effector.gameObject.GetComponents <Collider2D>().Where(c => c.enabled && c.usedByEffector))
            {
                var b     = c.bounds;
                var left  = b.min.x;
                var right = b.max.x;
                if (float.IsNegativeInfinity(farLeft))
                {
                    farLeft  = left;
                    farRight = right;
                }
                else
                {
                    if (left < farLeft)
                    {
                        farLeft = left;
                    }

                    if (right > farRight)
                    {
                        farRight = right;
                    }
                }

                var start = new Vector3(left, surfaceY, 0.0f);
                var end   = new Vector3(right, surfaceY, 0.0f);

                intersections.Add(start);
                intersections.Add(end);
            }

            // Draw the overall surface.
            Handles.color = Color.red;
            Handles.DrawAAPolyLine(new Vector3[] { new Vector3(farLeft, surfaceY, 0.0f), new Vector3(farRight, surfaceY, 0.0f) });

            // Draw the collider intersections.
            Handles.color = Color.cyan;
            for (var i = 0; i < intersections.Count - 1; i = i + 2)
            {
                Handles.DrawAAPolyLine(intersections[i], intersections[i + 1]);
            }
        }
 private void DrawAgentDiagram(Rect rect, float agentRadius, float agentHeight, float agentClimb, float agentSlope)
 {
     if (Event.current.type == EventType.Repaint)
     {
         float num  = agentRadius;
         float num2 = agentHeight;
         float num3 = agentClimb;
         float num4 = 1f;
         float num5 = 0.35f;
         float num6 = 15f;
         float num7 = rect.height - (num6 * 2f);
         num4  = Mathf.Min((float)(num7 / (num2 + ((num * 2f) * num5))), (float)(num7 / (num * 2f)));
         num2 *= num4;
         num  *= num4;
         num3 *= num4;
         float     x            = rect.xMin + (rect.width * 0.5f);
         float     y            = (rect.yMax - num6) - (num * num5);
         Vector3[] points       = new Vector3[40];
         Vector3[] vectorArray2 = new Vector3[20];
         Vector3[] vectorArray3 = new Vector3[20];
         for (int i = 0; i < 20; i++)
         {
             float f     = (((float)i) / 19f) * 3.141593f;
             float num13 = Mathf.Cos(f);
             float num14 = Mathf.Sin(f);
             points[i]       = new Vector3(x + (num13 * num), (y - num2) - ((num14 * num) * num5), 0f);
             points[i + 20]  = new Vector3(x - (num13 * num), y + ((num14 * num) * num5), 0f);
             vectorArray2[i] = new Vector3(x - (num13 * num), (y - num2) + ((num14 * num) * num5), 0f);
             vectorArray3[i] = new Vector3(x - (num13 * num), (y - num3) + ((num14 * num) * num5), 0f);
         }
         Color color = Handles.color;
         float xMin  = rect.xMin;
         float num16 = y - num3;
         float num17 = x - (num7 * 0.75f);
         float num18 = y;
         float num19 = x + (num7 * 0.75f);
         float num20 = y;
         float num21 = num19;
         float num22 = num20;
         float num23 = rect.xMax - num19;
         num21 += Mathf.Cos(agentSlope * 0.01745329f) * num23;
         num22 -= Mathf.Sin(agentSlope * 0.01745329f) * num23;
         Vector3[] vectorArray4 = new Vector3[] { new Vector3(xMin, y, 0f), new Vector3(num21, y, 0f) };
         Vector3[] vectorArray5 = new Vector3[] { new Vector3(xMin, num16, 0f), new Vector3(num17, num16, 0f), new Vector3(num17, num18, 0f), new Vector3(num19, num20, 0f), new Vector3(num21, num22, 0f) };
         Handles.color = !EditorGUIUtility.isProSkin ? new Color(1f, 1f, 1f, 0.5f) : new Color(0f, 0f, 0f, 0.5f);
         Handles.DrawAAPolyLine((float)2f, vectorArray4);
         Handles.color = !EditorGUIUtility.isProSkin ? new Color(0f, 0f, 0f, 0.5f) : new Color(1f, 1f, 1f, 0.5f);
         Handles.DrawAAPolyLine((float)3f, vectorArray5);
         Handles.color = Color.Lerp(new Color(0f, 0.75f, 1f, 1f), new Color(0.5f, 0.5f, 0.5f, 0.5f), 0.2f);
         Handles.DrawAAConvexPolygon(points);
         Handles.color = new Color(0f, 0f, 0f, 0.5f);
         Handles.DrawAAPolyLine((float)2f, vectorArray3);
         Handles.color = new Color(1f, 1f, 1f, 0.4f);
         Handles.DrawAAPolyLine((float)2f, vectorArray2);
         Vector3[] vectorArray6 = new Vector3[] { new Vector3(x, y - num2, 0f), new Vector3(x + num, y - num2, 0f) };
         Handles.color = new Color(0f, 0f, 0f, 0.5f);
         Handles.DrawAAPolyLine((float)2f, vectorArray6);
         GUI.Label(new Rect((x + num) + 5f, (y - (num2 * 0.5f)) - 10f, 150f, 20f), string.Format("H = {0}", agentHeight));
         GUI.Label(new Rect(x, ((y - num2) - (num * num5)) - 15f, 150f, 20f), string.Format("R = {0}", agentRadius));
         GUI.Label(new Rect(((xMin + num17) * 0.5f) - 20f, num16 - 15f, 150f, 20f), string.Format("{0}", agentClimb));
         GUI.Label(new Rect(num19 + 20f, num20 - 15f, 150f, 20f), string.Format("{0}\x00b0", agentSlope));
         Handles.color = color;
     }
 }
 public static void DrawAALine(Vector3 start, Vector3 end)
 {
     Handles.DrawAAPolyLine(new Vector3[] { start, end });
 }
        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("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("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);
        }
示例#8
0
 public static void DrawAALine(Vector3 start, Vector3 end)
 {
     Vector3[] points = new Vector3[] { start, end };
     Handles.DrawAAPolyLine(points);
 }
示例#9
0
 public static void DrawAgentDiagram(Rect rect, float agentRadius, float agentHeight, float agentClimb, float agentSlope)
 {
     if (Event.current.type == EventType.Repaint)
     {
         float     num    = 0.35f;
         float     num2   = 20f;
         float     num3   = 10f;
         float     num4   = rect.height - (num2 + num3);
         float     num5   = Mathf.Min(num4 / (agentHeight + agentRadius * 2f * num), num4 / (agentRadius * 2f));
         float     num6   = agentHeight * num5;
         float     num7   = agentRadius * num5;
         float     num8   = agentClimb * num5;
         float     num9   = rect.xMin + rect.width * 0.5f;
         float     num10  = rect.yMax - num3 - num7 * num;
         Vector3[] array  = new Vector3[40];
         Vector3[] array2 = new Vector3[20];
         Vector3[] array3 = new Vector3[20];
         for (int i = 0; i < 20; i++)
         {
             float f     = (float)i / 19f * 3.14159274f;
             float num11 = Mathf.Cos(f);
             float num12 = Mathf.Sin(f);
             array[i]      = new Vector3(num9 + num11 * num7, num10 - num6 - num12 * num7 * num, 0f);
             array[i + 20] = new Vector3(num9 - num11 * num7, num10 + num12 * num7 * num, 0f);
             array2[i]     = new Vector3(num9 - num11 * num7, num10 - num6 + num12 * num7 * num, 0f);
             array3[i]     = new Vector3(num9 - num11 * num7, num10 - num8 + num12 * num7 * num, 0f);
         }
         Color color = Handles.color;
         float xMin  = rect.xMin;
         float num13 = num10 - num8;
         float num14 = num9 - num4 * 0.75f;
         float y     = num10;
         float num15 = num9 + num4 * 0.75f;
         float num16 = num10;
         float num17 = num15;
         float num18 = num16;
         float num19 = Mathf.Min(rect.xMax - num15, num6);
         num17 += Mathf.Cos(agentSlope * 0.0174532924f) * num19;
         num18 -= Mathf.Sin(agentSlope * 0.0174532924f) * num19;
         Vector3[] points = new Vector3[]
         {
             new Vector3(xMin, num10, 0f),
             new Vector3(num17, num10, 0f)
         };
         Vector3[] points2 = new Vector3[]
         {
             new Vector3(xMin, num13, 0f),
             new Vector3(num14, num13, 0f),
             new Vector3(num14, y, 0f),
             new Vector3(num15, num16, 0f),
             new Vector3(num17, num18, 0f)
         };
         Handles.color = ((!EditorGUIUtility.isProSkin) ? new Color(1f, 1f, 1f, 0.5f) : new Color(0f, 0f, 0f, 0.5f));
         Handles.DrawAAPolyLine(2f, points);
         Handles.color = ((!EditorGUIUtility.isProSkin) ? new Color(0f, 0f, 0f, 0.5f) : new Color(1f, 1f, 1f, 0.5f));
         Handles.DrawAAPolyLine(3f, points2);
         Handles.color = Color.Lerp(new Color(0f, 0.75f, 1f, 1f), new Color(0.5f, 0.5f, 0.5f, 0.5f), 0.2f);
         Handles.DrawAAConvexPolygon(array);
         Handles.color = new Color(0f, 0f, 0f, 0.5f);
         Handles.DrawAAPolyLine(2f, array3);
         Handles.color = new Color(1f, 1f, 1f, 0.4f);
         Handles.DrawAAPolyLine(2f, array2);
         Vector3[] points3 = new Vector3[]
         {
             new Vector3(num9, num10 - num6, 0f),
             new Vector3(num9 + num7, num10 - num6, 0f)
         };
         Handles.color = new Color(0f, 0f, 0f, 0.5f);
         Handles.DrawAAPolyLine(2f, points3);
         GUI.Label(new Rect(num9 + num7 + 5f, num10 - num6 * 0.5f - 10f, 150f, 20f), string.Format("H = {0}", agentHeight));
         GUI.Label(new Rect(num9, num10 - num6 - num7 * num - 15f, 150f, 20f), string.Format("R = {0}", agentRadius));
         GUI.Label(new Rect((xMin + num14) * 0.5f - 20f, num13 - 15f, 150f, 20f), string.Format("{0}", agentClimb));
         GUI.Label(new Rect(num15 + 20f, num16 - 15f, 150f, 20f), string.Format("{0}°", agentSlope));
         Handles.color = color;
     }
 }
示例#10
0
        private 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 current   = Event.current;
            int   controlID = GUIUtility.GetControlID(FocusType.Passive);
            Rect  r         = AudioCurveRendering.BeginCurveFrame(r0);
            float num       = 10f;
            float min;
            float max;
            float num2;

            plugin.GetFloatParameterInfo(DuckVolumeGUI.kThresholdName, out min, out max, out num2);
            float min2;
            float max2;
            float num3;

            plugin.GetFloatParameterInfo(DuckVolumeGUI.kRatioName, out min2, out max2, out num3);
            float min3;
            float max3;
            float num4;

            plugin.GetFloatParameterInfo(DuckVolumeGUI.kMakeupGainName, out min3, out max3, out num4);
            float min4;
            float max4;
            float num5;

            plugin.GetFloatParameterInfo(DuckVolumeGUI.kKneeName, out min4, out max4, out num5);
            float dbRange = 100f;
            float dbMin   = -80f;
            float num6    = r.width * (threshold - dbMin) / dbRange;
            bool  result  = false;

            switch (current.GetTypeForControl(controlID))
            {
            case EventType.MouseDown:
                if (r.Contains(Event.current.mousePosition) && current.button == 0)
                {
                    DuckVolumeGUI.dragtype = DuckVolumeGUI.DragType.None;
                    GUIUtility.hotControl  = controlID;
                    EditorGUIUtility.SetWantsMouseJumping(1);
                    current.Use();
                    if (Mathf.Abs(r.x + num6 - current.mousePosition.x) >= 10f)
                    {
                        DuckVolumeGUI.dragtype = ((current.mousePosition.x >= r.x + num6) ? DuckVolumeGUI.DragType.Ratio : DuckVolumeGUI.DragType.MakeupGain);
                    }
                    else
                    {
                        DuckVolumeGUI.dragtype = DuckVolumeGUI.DragType.ThresholdAndKnee;
                    }
                }
                break;

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

            case EventType.MouseDrag:
                if (GUIUtility.hotControl == controlID)
                {
                    float num7 = (!current.alt) ? 1f : 0.25f;
                    if (DuckVolumeGUI.dragtype == DuckVolumeGUI.DragType.ThresholdAndKnee)
                    {
                        bool flag = Mathf.Abs(current.delta.x) < Mathf.Abs(current.delta.y);
                        if (flag)
                        {
                            knee = Mathf.Clamp(knee + current.delta.y * 0.5f * num7, min4, max4);
                        }
                        else
                        {
                            threshold = Mathf.Clamp(threshold + current.delta.x * 0.1f * num7, min, max);
                        }
                    }
                    else if (DuckVolumeGUI.dragtype == DuckVolumeGUI.DragType.Ratio)
                    {
                        ratio = Mathf.Clamp(ratio + current.delta.y * ((ratio <= 1f) ? 0.003f : 0.05f) * num7, min2, max2);
                    }
                    else if (DuckVolumeGUI.dragtype == DuckVolumeGUI.DragType.MakeupGain)
                    {
                        makeupGain = Mathf.Clamp(makeupGain - current.delta.y * 0.5f * num7, min3, max3);
                    }
                    else
                    {
                        Debug.LogError("Drag: Unhandled enum");
                    }
                    result = true;
                    current.Use();
                }
                break;
            }
            if (current.type == EventType.Repaint)
            {
                HandleUtility.ApplyWireMaterial();
                float num8               = r.height * (1f - (threshold - dbMin + makeupGain) / dbRange);
                Color col2               = new Color(0.7f, 0.7f, 0.7f);
                Color black              = Color.black;
                float duckGradient       = 1f / ratio;
                float duckThreshold      = threshold;
                float duckSidechainLevel = sidechainLevel;
                float duckMakeupGain     = makeupGain;
                float duckKnee           = knee;
                float duckKneeC1         = (knee <= 0f) ? 0f : ((duckGradient - 1f) / (4f * knee));
                float duckKneeC2         = duckThreshold - knee;
                AudioCurveRendering.DrawFilledCurve(r, delegate(float x, out Color col)
                {
                    float num16 = x * dbRange + dbMin;
                    float num17 = num16;
                    float num18 = num16 - duckThreshold;
                    col         = DuckVolumeGUI.ScaleAlpha((duckSidechainLevel <= num16) ? Color.grey : AudioCurveRendering.kAudioOrange, blend);
                    if (num18 > -duckKnee && num18 < duckKnee)
                    {
                        num18 += duckKnee;
                        num17  = num18 * (duckKneeC1 * num18 + 1f) + duckKneeC2;
                        if (DuckVolumeGUI.dragtype == DuckVolumeGUI.DragType.ThresholdAndKnee)
                        {
                            col = new Color(col.r * 1.2f, col.g * 1.2f, col.b * 1.2f);
                        }
                    }
                    else if (num18 > 0f)
                    {
                        num17 = duckThreshold + duckGradient * num18;
                    }
                    return(2f * (num17 + duckMakeupGain - dbMin) / dbRange - 1f);
                });
                if (DuckVolumeGUI.dragtype == DuckVolumeGUI.DragType.MakeupGain)
                {
                    AudioCurveRendering.DrawCurve(r, delegate(float x)
                    {
                        float num16 = x * dbRange + dbMin;
                        float num17 = num16;
                        float num18 = num16 - duckThreshold;
                        if (num18 > -duckKnee && num18 < duckKnee)
                        {
                            num18 += duckKnee;
                            num17  = num18 * (duckKneeC1 * num18 + 1f) + duckKneeC2;
                        }
                        else if (num18 > 0f)
                        {
                            num17 = duckThreshold + duckGradient * num18;
                        }
                        return(2f * (num17 + duckMakeupGain - dbMin) / dbRange - 1f);
                    }, Color.white);
                }
                DuckVolumeGUI.textStyle10.normal.textColor = DuckVolumeGUI.ScaleAlpha(col2, blend);
                EditorGUI.DrawRect(new Rect(r.x + num6, r.y, 1f, r.height), DuckVolumeGUI.textStyle10.normal.textColor);
                DuckVolumeGUI.DrawText(r.x + num6 + 4f, r.y + 6f, string.Format("Threshold: {0:F1} dB", threshold));
                DuckVolumeGUI.textStyle10.normal.textColor = DuckVolumeGUI.ScaleAlpha(black, blend);
                DuckVolumeGUI.DrawText(r.x + 4f, r.y + r.height - 10f, (sidechainLevel >= -80f) ? string.Format("Input: {0:F1} dB", sidechainLevel) : "Input: None");
                if (DuckVolumeGUI.dragtype == DuckVolumeGUI.DragType.Ratio)
                {
                    float num9 = r.height / r.width;
                    Handles.DrawAAPolyLine(2f, new Color[]
                    {
                        Color.black,
                        Color.black
                    }, new Vector3[]
                    {
                        new Vector3(r.x + num6 + r.width, r.y + num8 - num9 * r.width, 0f),
                        new Vector3(r.x + num6 - r.width, r.y + num8 + num9 * r.width, 0f)
                    });
                    Handles.DrawAAPolyLine(3f, new Color[]
                    {
                        Color.white,
                        Color.white
                    }, new Vector3[]
                    {
                        new Vector3(r.x + num6 + r.width, r.y + num8 - num9 * duckGradient * r.width, 0f),
                        new Vector3(r.x + num6 - r.width, r.y + num8 + num9 * duckGradient * r.width, 0f)
                    });
                }
                else if (DuckVolumeGUI.dragtype == DuckVolumeGUI.DragType.ThresholdAndKnee)
                {
                    float num10 = (threshold - knee - dbMin) / dbRange;
                    float num11 = (threshold + knee - dbMin) / dbRange;
                    float num12 = DuckVolumeGUI.EvaluateDuckingVolume(num10, ratio, threshold, makeupGain, knee, dbRange, dbMin);
                    float num13 = DuckVolumeGUI.EvaluateDuckingVolume(num11, ratio, threshold, makeupGain, knee, dbRange, dbMin);
                    float num14 = r.yMax - (num12 + 1f) * 0.5f * r.height;
                    float num15 = r.yMax - (num13 + 1f) * 0.5f * r.height;
                    EditorGUI.DrawRect(new Rect(r.x + num10 * r.width, num14, 1f, r.height - num14), new Color(0f, 0f, 0f, 0.5f));
                    EditorGUI.DrawRect(new Rect(r.x + num11 * r.width - 1f, num15, 1f, r.height - num15), new Color(0f, 0f, 0f, 0.5f));
                    EditorGUI.DrawRect(new Rect(r.x + num6 - 1f, r.y, 3f, r.height), Color.white);
                }
                outputLevel = (Mathf.Clamp(outputLevel - makeupGain, dbMin, dbMin + dbRange) - dbMin) / dbRange;
                if (EditorApplication.isPlaying)
                {
                    Rect r2 = new Rect(r.x + r.width - num + 2f, r.y + 2f, num - 4f, r.height - 4f);
                    DuckVolumeGUI.DrawVU(r2, outputLevel, blend, true);
                }
            }
            AudioCurveRendering.EndCurveFrame();
            return(result);
        }