Exemplo n.º 1
0
        protected override void Render()
        {
            if (_Changed)
            {
                UpdatePreview();
            }

            Rect ra = RenderArea;

            if (ra.width >= 1)
            {
                if (PreviewBackground)
                {
                    GUI.Box(ra, string.Empty, Skill.Editor.Resources.Styles.PreviewBackground);
                }
                if (_Data.MinCurve != null)
                {
                    EditorGUIUtility.DrawRegionSwatch(ra, _Data.MinCurve, _Data.MaxCurve, Color, BackgroundColor, Ranges);
                }
            }
        }
        static void DoMinMaxCurvesField(Rect position, int id, SerializedProperty propertyMax, SerializedProperty propertyMin, SerializedProperty scalar, Color color, Color backgroundColor)
        {
            var evt = Event.current;

            if (MinMaxCurveEditorWindow.visible && Event.current.type != EventType.Layout && GUIUtility.keyboardControl == id)
            {
                if (s_CurveId != id)
                {
                    s_CurveId = id;
                    if (MinMaxCurveEditorWindow.visible)
                    {
                        MinMaxCurveEditorWindow.SetCurves(propertyMax, propertyMin, scalar, color);
                        MinMaxCurveEditorWindow.ShowPopup(GUIView.current);
                    }
                }
                else
                {
                    if (MinMaxCurveEditorWindow.visible && Event.current.type == EventType.Repaint)
                    {
                        MinMaxCurveEditorWindow.SetCurves(propertyMax, propertyMin, scalar, color);
                        MinMaxCurveEditorWindow.instance.Repaint();
                    }
                }
            }

            switch (evt.GetTypeForControl(id))
            {
            case EventType.MouseDown:
                if (position.Contains(evt.mousePosition))
                {
                    s_CurveId = id;
                    GUIUtility.keyboardControl = id;
                    MinMaxCurveEditorWindow.SetCurves(propertyMax, propertyMin, scalar, color);
                    MinMaxCurveEditorWindow.ShowPopup(GUIView.current);
                    evt.Use();
                    GUIUtility.ExitGUI();
                }
                break;

            case EventType.Repaint:
                if (propertyMin != null)
                {
                    EditorGUIUtility.DrawRegionSwatch(position, propertyMax, propertyMin, color, backgroundColor);
                }
                else
                {
                    EditorGUIUtility.DrawCurveSwatch(position, null, propertyMax, color, backgroundColor);
                }
                EditorStyles.colorPickerBox.Draw(position, GUIContent.none, id, false);
                break;

            case EventType.ExecuteCommand:

                if (s_CurveId == id && evt.commandName == "CurveChanged")
                {
                    GUI.changed = true;
                    AnimationCurvePreviewCache.ClearCache();
                    HandleUtility.Repaint();
                    if (propertyMax != null && MinMaxCurveEditorWindow.instance.maxCurve != null)
                    {
                        propertyMax.animationCurveValue = MinMaxCurveEditorWindow.instance.maxCurve;
                    }
                    if (propertyMin != null)
                    {
                        propertyMin.animationCurveValue = MinMaxCurveEditorWindow.instance.minCurve;
                    }
                }
                break;

            case EventType.KeyDown:
                if (evt.MainActionKeyForControl(id))
                {
                    s_CurveId = id;
                    MinMaxCurveEditorWindow.SetCurves(propertyMax, propertyMin, scalar, color);
                    MinMaxCurveEditorWindow.ShowPopup(GUIView.current);
                    evt.Use();
                    GUIUtility.ExitGUI();
                }
                break;
            }
        }
Exemplo n.º 3
0
 public static void DrawRegionSwatch(Rect position, SerializedProperty property, SerializedProperty property2, Color color, Color bgColor, Rect curveRanges)
 {
     EditorGUIUtility.DrawRegionSwatch(position, property, property2, color, bgColor, curveRanges);
 }
Exemplo n.º 4
0
 public static void DrawRegionSwatch(Rect position, AnimationCurve curve, AnimationCurve curve2, Color color, Color bgColor, Rect curveRanges)
 {
     EditorGUIUtility.DrawRegionSwatch(position, curve, curve2, color, bgColor, curveRanges);
 }
Exemplo n.º 5
0
        public override void OnInspectorGUI()
        {
            EditorGUILayout.Space();

            Rect weightCurveRect = GUILayoutUtility.GetAspectRect(2.0f);

            Color previousGUIColor = GUI.color;

            GUI.color = Color.black;

            GUI.DrawTexture(
                new Rect(
                    weightCurveRect.x - 1.0f,
                    weightCurveRect.y - 1.0f,
                    weightCurveRect.width + 2.0f,
                    weightCurveRect.height + 2.0f),
                this.lineTexture);

            GUI.color = Color.grey;

            GUI.Box(weightCurveRect, "");

            GUI.color = previousGUIColor;

            string error = null;

            if (this.targets.Length <= 1)
            {
                Effect targetEffect = (Effect)this.target;

                if (targetEffect.Duration != 0.0f)
                {
                    Keyframe[] weightCurveKeyframes = new Keyframe[(int)(weightCurveRect.width * 0.4f)];

                    for (int i = 0; i < weightCurveKeyframes.Length; ++i)
                    {
                        float time = targetEffect.SimulatedTime - targetEffect.Duration + (i / (float)weightCurveKeyframes.Length) * targetEffect.Duration * 2.0f;

                        weightCurveKeyframes[i] = new Keyframe(time, targetEffect.CalculateWeight(time));
                    }

                    for (int i = 0; i < weightCurveKeyframes.Length - 1; ++i)
                    {
                        weightCurveKeyframes[i].outTangent =
                            (weightCurveKeyframes[i + 1].value - weightCurveKeyframes[i].value)
                            / (weightCurveKeyframes[i + 1].time - weightCurveKeyframes[i].time);
                        weightCurveKeyframes[i + 1].inTangent =
                            (weightCurveKeyframes[i].value - weightCurveKeyframes[i + 1].value)
                            / (weightCurveKeyframes[i].time - weightCurveKeyframes[i + 1].time);
                    }

                    AnimationCurve weightCurve = new AnimationCurve(weightCurveKeyframes);

                    EditorGUIUtility.DrawRegionSwatch(
                        weightCurveRect,
                        weightCurve,
                        AnimationCurve.Linear(
                            targetEffect.SimulatedTime - targetEffect.Duration,
                            0.0f,
                            targetEffect.SimulatedTime + targetEffect.Duration,
                            0.0f),
                        Color.cyan,
                        Color.grey,
                        new Rect(
                            targetEffect.SimulatedTime - targetEffect.Duration,
                            -MAX_WEIGHT,
                            targetEffect.Duration * 2.0f,
                            MAX_WEIGHT * 2.0f));

                    GUI.color = new Color(0.0f, 0.0f, 0.0f, 0.3f);

                    float topLineY = weightCurveRect.y + weightCurveRect.height * ((MAX_WEIGHT - 1.0f) / (MAX_WEIGHT * 2.0f));

                    // Top Line
                    GUI.DrawTexture(
                        new Rect(
                            weightCurveRect.x,
                            topLineY,
                            weightCurveRect.width,
                            1.0f),
                        this.lineTexture);

                    float bottomLineY = weightCurveRect.y + weightCurveRect.height * ((2.0f + MAX_WEIGHT - 1.0f) / (MAX_WEIGHT * 2.0f));

                    // Bottom Line
                    GUI.DrawTexture(
                        new Rect(
                            weightCurveRect.x,
                            bottomLineY,
                            weightCurveRect.width,
                            1.0f),
                        this.lineTexture);

                    GUI.color = new Color(0.0f, 0.0f, 0.0f, 1.0f);

                    // Middle Horizontal Line
                    float middleLineThickness = 1.0f + (weightCurveRect.height % 2.0f == 1.0f ? 0.0f : 1.0f);
                    GUI.DrawTexture(
                        new Rect(
                            weightCurveRect.x,
                            weightCurveRect.y + weightCurveRect.height * 0.5f - (int)(middleLineThickness / 2.0f),
                            weightCurveRect.width,
                            middleLineThickness),
                        this.lineTexture);

                    //Middle Vertical Line
                    middleLineThickness = 1.0f + (weightCurveRect.width % 2.0f == 1.0f ? 0.0f : 1.0f);
                    GUI.DrawTexture(
                        new Rect(
                            weightCurveRect.x + weightCurveRect.width * 0.5f - (int)(middleLineThickness / 2.0f),
                            weightCurveRect.y,
                            middleLineThickness,
                            weightCurveRect.height),
                        this.lineTexture);

                    if (targetEffect.IsSleeping)
                    {
                        GUI.color = new Color(1.0f, 0.3f, 0.3f, 0.6f);

                        // Time Text
                        GUI.Box(
                            new Rect(
                                weightCurveRect.x + weightCurveRect.width - 5.0f - 40.0f,
                                bottomLineY - 5.0f - 20.0f,
                                40.0f,
                                20.0f),
                            "Zzz");
                    }

                    GUI.color = new Color(0.0f, 0.0f, 0.0f, 0.5f);

                    // Time Text
                    EditorGUI.LabelField(
                        new Rect(
                            weightCurveRect.x + 5.0f,
                            topLineY + 5.0f,
                            95.0f,
                            16.0f),
                        "Time: " + targetEffect.SimulatedTime.ToString("0.00"));

                    // Weight Text
                    EditorGUI.LabelField(
                        new Rect(
                            weightCurveRect.x + 5.0f,
                            topLineY + 21.0f,
                            95.0f,
                            16.0f),
                        "Weight: " + targetEffect.CalculateWeight().ToString("0.00"));
                }
                else
                {
                    error = "zero duration";
                }
            }
            else
            {
                error = "multiple objects selected";
            }

            if (error != null)
            {
                if (this.errorStyle == null)
                {
                    this.errorStyle = new GUIStyle(GUI.skin.label);

                    this.errorStyle.alignment = TextAnchor.MiddleCenter;
                }

                GUI.color = Color.black;

                this.errorStyle.fontSize = 72;
                EditorGUI.LabelField(weightCurveRect, "X", this.errorStyle);

                GUI.color = new Color(1.0f, 1.0f, 1.0f, 0.5f);

                this.errorStyle.fontSize = 16;
                EditorGUI.LabelField(
                    new Rect(
                        weightCurveRect.x,
                        weightCurveRect.y + weightCurveRect.height * 0.5f,
                        weightCurveRect.width,
                        weightCurveRect.height * 0.5f),
                    error,
                    this.errorStyle);
            }

            EditorGUILayout.Space();

            GUI.color = previousGUIColor;

            base.OnInspectorGUI();
        }