UnityEditor.BlendTreeInspector.BlendGraph C# (CSharp) Method

BlendGraph() private method

private BlendGraph ( Rect area ) : void
area UnityEngine.Rect
return void
        private void BlendGraph(Rect area)
        {
            area.xMin++;
            area.xMax--;
            int controlID = GUIUtility.GetControlID(this.m_BlendAnimationID, FocusType.Passive);
            int arraySize = this.m_Childs.arraySize;
            float[] values = new float[arraySize];
            for (int i = 0; i < arraySize; i++)
            {
                SerializedProperty property2 = this.m_Childs.GetArrayElementAtIndex(i).FindPropertyRelative("m_Threshold");
                values[i] = property2.floatValue;
            }
            float a = Mathf.Min(values);
            float b = Mathf.Max(values);
            for (int j = 0; j < values.Length; j++)
            {
                values[j] = area.x + (Mathf.InverseLerp(a, b, values[j]) * area.width);
            }
            string blendParameter = this.m_BlendTree.blendParameter;
            float num7 = area.x + (Mathf.InverseLerp(a, b, GetParameterValue(currentAnimator, this.m_BlendTree, blendParameter)) * area.width);
            Rect position = new Rect(num7 - 4f, area.y, 9f, 42f);
            Event current = Event.current;
            switch (current.GetTypeForControl(controlID))
            {
                case EventType.MouseDown:
                {
                    if (!position.Contains(current.mousePosition))
                    {
                        if (area.Contains(current.mousePosition))
                        {
                            current.Use();
                            GUIUtility.hotControl = controlID;
                            GUIUtility.keyboardControl = controlID;
                            float x = current.mousePosition.x;
                            float positiveInfinity = float.PositiveInfinity;
                            for (int k = 0; k < values.Length; k++)
                            {
                                float num15 = (k != 0) ? values[k - 1] : values[k];
                                float num16 = (k != (values.Length - 1)) ? values[k + 1] : values[k];
                                if ((Mathf.Abs((float) (x - values[k])) < positiveInfinity) && ((x < num16) && (x > num15)))
                                {
                                    positiveInfinity = Mathf.Abs((float) (x - values[k]));
                                    this.m_ReorderableList.index = k;
                                }
                            }
                            this.m_UseAutomaticThresholds.boolValue = false;
                        }
                        break;
                    }
                    current.Use();
                    GUIUtility.hotControl = controlID;
                    this.m_ReorderableList.index = -1;
                    this.m_ReorderableList.index = -1;
                    float t = Mathf.InverseLerp(0f, area.width, current.mousePosition.x - 4f);
                    t = Mathf.Lerp(a, b, t);
                    SetParameterValue(currentAnimator, this.m_BlendTree, parentBlendTree, blendParameter, t);
                    break;
                }
                case EventType.MouseUp:
                    if (GUIUtility.hotControl == controlID)
                    {
                        current.Use();
                        GUIUtility.hotControl = 0;
                        this.m_ReorderableList.index = -1;
                    }
                    break;

                case EventType.MouseDrag:
                    if (GUIUtility.hotControl == controlID)
                    {
                        current.Use();
                        if (this.m_ReorderableList.index == -1)
                        {
                            float num17 = Mathf.InverseLerp(0f, area.width, current.mousePosition.x - 4f);
                            num17 = Mathf.Lerp(a, b, num17);
                            SetParameterValue(currentAnimator, this.m_BlendTree, parentBlendTree, blendParameter, num17);
                        }
                        else
                        {
                            float num18 = Mathf.InverseLerp(0f, area.width, current.mousePosition.x);
                            num18 = Mathf.Lerp(a, b, num18);
                            SerializedProperty arrayElementAtIndex = this.m_Childs.GetArrayElementAtIndex(this.m_ReorderableList.index);
                            SerializedProperty property4 = arrayElementAtIndex.FindPropertyRelative("m_Threshold");
                            SerializedProperty property5 = (this.m_ReorderableList.index > 0) ? this.m_Childs.GetArrayElementAtIndex(this.m_ReorderableList.index - 1) : arrayElementAtIndex;
                            SerializedProperty property6 = (this.m_ReorderableList.index != (this.m_Childs.arraySize - 1)) ? this.m_Childs.GetArrayElementAtIndex(this.m_ReorderableList.index + 1) : arrayElementAtIndex;
                            SerializedProperty property7 = property5.FindPropertyRelative("m_Threshold");
                            SerializedProperty property8 = property6.FindPropertyRelative("m_Threshold");
                            float num19 = (b - a) / area.width;
                            float num20 = current.delta.x;
                            property4.floatValue += num20 * num19;
                            if ((property4.floatValue < property7.floatValue) && (this.m_ReorderableList.index != 0))
                            {
                                this.m_Childs.MoveArrayElement(this.m_ReorderableList.index, this.m_ReorderableList.index - 1);
                                this.m_ReorderableList.index--;
                            }
                            if ((property4.floatValue > property8.floatValue) && (this.m_ReorderableList.index < (this.m_Childs.arraySize - 1)))
                            {
                                this.m_Childs.MoveArrayElement(this.m_ReorderableList.index, this.m_ReorderableList.index + 1);
                                this.m_ReorderableList.index++;
                            }
                            float num21 = 3f * ((b - a) / area.width);
                            if ((property4.floatValue - property7.floatValue) <= num21)
                            {
                                property4.floatValue = property7.floatValue;
                            }
                            else if ((property8.floatValue - property4.floatValue) <= num21)
                            {
                                property4.floatValue = property8.floatValue;
                            }
                            this.SetMinMaxThresholds();
                        }
                        break;
                    }
                    break;

                case EventType.Repaint:
                {
                    styles.background.Draw(area, GUIContent.none, false, false, false, false);
                    if (this.m_Childs.arraySize < 2)
                    {
                        GUI.Label(area, EditorGUIUtility.TempContent("Please Add Motion Fields or Blend Trees"), styles.errorStyle);
                        break;
                    }
                    for (int m = 0; m < values.Length; m++)
                    {
                        float min = (m != 0) ? values[m - 1] : values[m];
                        float max = (m != (values.Length - 1)) ? values[m + 1] : values[m];
                        bool selected = this.m_ReorderableList.index == m;
                        this.DrawAnimation(values[m], min, max, selected, area);
                    }
                    Color color = Handles.color;
                    Handles.color = new Color(0f, 0f, 0f, 0.25f);
                    Handles.DrawLine(new Vector3(area.x, area.y + area.height, 0f), new Vector3(area.x + area.width, area.y + area.height, 0f));
                    Handles.color = color;
                    styles.blendPosition.Draw(position, GUIContent.none, false, false, false, false);
                    break;
                }
            }
        }