UnityEditor.BlendTreeInspector.BlendGraph2D C# (CSharp) Method

BlendGraph2D() private method

private BlendGraph2D ( Rect area ) : void
area UnityEngine.Rect
return void
        private void BlendGraph2D(Rect area)
        {
            if (this.m_VisBlendTree.controllerDirty)
            {
                this.UpdateBlendVisualization();
                this.ValidatePositions();
            }
            Vector2[] motionPositions = this.GetMotionPositions();
            int[] motionToActiveMotionIndices = this.GetMotionToActiveMotionIndices();
            Vector2 vector = new Vector2(this.m_BlendRect.xMin, this.m_BlendRect.yMin);
            Vector2 vector2 = new Vector2(this.m_BlendRect.xMax, this.m_BlendRect.yMax);
            for (int i = 0; i < motionPositions.Length; i++)
            {
                motionPositions[i].x = this.ConvertFloat(motionPositions[i].x, vector.x, vector2.x, area.xMin, area.xMax);
                motionPositions[i].y = this.ConvertFloat(motionPositions[i].y, vector.y, vector2.y, area.yMax, area.yMin);
            }
            string blendParameter = this.m_BlendTree.blendParameter;
            string blendParameterY = this.m_BlendTree.blendParameterY;
            float blendX = GetParameterValue(currentAnimator, this.m_BlendTree, blendParameter);
            float blendY = GetParameterValue(currentAnimator, this.m_BlendTree, blendParameterY);
            int length = this.GetActiveMotionPositions().Length;
            if ((this.m_Weights == null) || (length != this.m_Weights.Length))
            {
                this.m_Weights = new float[length];
            }
            BlendTreePreviewUtility.CalculateRootBlendTreeChildWeights(this.m_VisBlendTree.animator, 0, this.m_VisBlendTree.animator.GetCurrentAnimatorStateInfo(0).fullPathHash, this.m_Weights, blendX, blendY);
            blendX = area.x + (Mathf.InverseLerp(vector.x, vector2.x, blendX) * area.width);
            blendY = area.y + ((1f - Mathf.InverseLerp(vector.y, vector2.y, blendY)) * area.height);
            Rect position = new Rect(blendX - 5f, blendY - 5f, 11f, 11f);
            int controlID = GUIUtility.GetControlID(this.m_BlendAnimationID, FocusType.Passive);
            Event current = Event.current;
            switch (current.GetTypeForControl(controlID))
            {
                case EventType.MouseDown:
                    if (!position.Contains(current.mousePosition))
                    {
                        if (area.Contains(current.mousePosition))
                        {
                            this.m_ReorderableList.index = -1;
                            for (int k = 0; k < motionPositions.Length; k++)
                            {
                                Rect rect3 = new Rect(motionPositions[k].x - 4f, motionPositions[k].y - 4f, 9f, 9f);
                                if (rect3.Contains(current.mousePosition))
                                {
                                    current.Use();
                                    GUIUtility.hotControl = controlID;
                                    this.m_SelectedPoint = k;
                                    this.m_ReorderableList.index = k;
                                }
                            }
                            current.Use();
                        }
                    }
                    else
                    {
                        current.Use();
                        GUIUtility.hotControl = controlID;
                        this.m_SelectedPoint = -1;
                    }
                    goto Label_0801;

                case EventType.MouseUp:
                    if (GUIUtility.hotControl == controlID)
                    {
                        current.Use();
                        GUIUtility.hotControl = 0;
                        this.s_DraggingPoint = false;
                    }
                    goto Label_0801;

                case EventType.MouseDrag:
                    if (GUIUtility.hotControl == controlID)
                    {
                        if (this.m_SelectedPoint == -1)
                        {
                            Vector2 vector3;
                            vector3.x = this.ConvertFloat(current.mousePosition.x, area.xMin, area.xMax, vector.x, vector2.x);
                            vector3.y = this.ConvertFloat(current.mousePosition.y, area.yMax, area.yMin, vector.y, vector2.y);
                            SetParameterValue(currentAnimator, this.m_BlendTree, parentBlendTree, blendParameter, vector3.x);
                            SetParameterValue(currentAnimator, this.m_BlendTree, parentBlendTree, blendParameterY, vector3.y);
                            current.Use();
                        }
                        else
                        {
                            for (int m = 0; m < motionPositions.Length; m++)
                            {
                                if (this.m_SelectedPoint == m)
                                {
                                    Vector2 vector6;
                                    vector6.x = this.ConvertFloat(current.mousePosition.x, area.xMin, area.xMax, vector.x, vector2.x);
                                    vector6.y = this.ConvertFloat(current.mousePosition.y, area.yMax, area.yMin, vector.y, vector2.y);
                                    float minDifference = (vector2.x - vector.x) / area.width;
                                    vector6.x = MathUtils.RoundBasedOnMinimumDifference(vector6.x, minDifference);
                                    vector6.y = MathUtils.RoundBasedOnMinimumDifference(vector6.y, minDifference);
                                    vector6.x = Mathf.Clamp(vector6.x, -10000f, 10000f);
                                    vector6.y = Mathf.Clamp(vector6.y, -10000f, 10000f);
                                    this.m_Childs.GetArrayElementAtIndex(m).FindPropertyRelative("m_Position").vector2Value = vector6;
                                    current.Use();
                                    this.s_DraggingPoint = true;
                                }
                            }
                        }
                    }
                    goto Label_0801;

                case EventType.Repaint:
                {
                    GUI.color = styles.visBgColor;
                    GUI.DrawTexture(area, EditorGUIUtility.whiteTexture);
                    if (this.m_ReorderableList.index >= 0)
                    {
                        if (motionToActiveMotionIndices[this.m_ReorderableList.index] >= 0)
                        {
                            GUI.color = styles.visWeightColor;
                            GUI.DrawTexture(area, this.m_WeightTexs[motionToActiveMotionIndices[this.m_ReorderableList.index]]);
                        }
                        break;
                    }
                    Color visWeightColor = styles.visWeightColor;
                    visWeightColor.a *= 0.75f;
                    GUI.color = visWeightColor;
                    GUI.DrawTexture(area, this.m_BlendTex);
                    break;
                }
                default:
                    goto Label_0801;
            }
            GUI.color = Color.white;
            if (!this.s_DraggingPoint)
            {
                for (int n = 0; n < motionPositions.Length; n++)
                {
                    if (motionToActiveMotionIndices[n] >= 0)
                    {
                        this.DrawWeightShape(motionPositions[n], this.m_Weights[motionToActiveMotionIndices[n]], 0);
                    }
                }
                for (int num7 = 0; num7 < motionPositions.Length; num7++)
                {
                    if (motionToActiveMotionIndices[num7] >= 0)
                    {
                        this.DrawWeightShape(motionPositions[num7], this.m_Weights[motionToActiveMotionIndices[num7]], 1);
                    }
                }
            }
            for (int j = 0; j < motionPositions.Length; j++)
            {
                Rect rect2 = new Rect(motionPositions[j].x - 6f, motionPositions[j].y - 6f, 13f, 13f);
                bool flag = this.m_ReorderableList.index == j;
                if (motionToActiveMotionIndices[j] < 0)
                {
                    GUI.color = styles.visPointEmptyColor;
                }
                else
                {
                    GUI.color = styles.visPointColor;
                }
                GUI.DrawTexture(rect2, !flag ? styles.pointIcon : styles.pointIconSelected);
                if (flag)
                {
                    GUI.color = styles.visPointOverlayColor;
                    GUI.DrawTexture(rect2, styles.pointIconOverlay);
                }
            }
            if (!this.s_DraggingPoint)
            {
                GUI.color = styles.visSamplerColor;
                GUI.DrawTexture(position, styles.samplerIcon);
            }
            GUI.color = Color.white;
        Label_0801:
            if ((this.m_ReorderableList.index >= 0) && (motionToActiveMotionIndices[this.m_ReorderableList.index] < 0))
            {
                this.ShowHelp(area, EditorGUIUtility.TempContent("The selected child has no Motion assigned."));
            }
            else if (this.m_WarningMessage != null)
            {
                this.ShowHelp(area, EditorGUIUtility.TempContent(this.m_WarningMessage));
            }
        }