internal static void ShowTransitionType(SerializedProperty transitionTypeProperty, SerializedProperty animationCurveProperty)
        {
            var transitionType = (TransitionHelper.TweenType)System.Enum.GetValues(typeof(TransitionHelper.TweenType)).GetValue(transitionTypeProperty.enumValueIndex);

            EditorGUILayout.PropertyField(transitionTypeProperty);

            if (transitionType == TransitionHelper.TweenType.none)
            {
                EditorGUI.indentLevel += 1;
                EditorGUILayout.HelpBox("This transition will be ignored!", MessageType.Info);
                EditorGUI.indentLevel -= 1;
            }

            else if (transitionType == TransitionHelper.TweenType.AnimationCurve)
            {
                EditorGUI.indentLevel += 1;
                EditorGUILayout.HelpBox("Custom animation curve with absolute values.\nClick the curve below to edit.", MessageType.None);
                EditorGUILayout.PropertyField(animationCurveProperty, GUIContent.none, GUILayout.MinHeight(EditorGUIUtility.singleLineHeight * 4));
                EditorGUI.indentLevel -= 1;
            }

            else
            {
                EditorGUI.indentLevel += 1;

                var easingFunction = TransitionHelper.GetTweenFunction(transitionType);
                if (easingFunction == null)
                {
                    // should never happen, but worth checking
                    EditorGUILayout.HelpBox("Curve not found! Please report this error.", MessageType.Error);
                }
                else
                {
                    EditorGUILayout.HelpBox("Fixed Transition Curve.", MessageType.None);

                    DrawTweenPreview(easingFunction);
                    EditorGUI.indentLevel -= 1;
                }
            }
        }
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            var transitionSettings = fieldInfo.GetValue(property.serializedObject.targetObject) as TransitionBase.TransitionSettings;

            // Using BeginProperty / EndProperty on the parent property means that
            // prefab override logic works on the entire property.
            EditorGUI.BeginProperty(position, label, property);

            position.height     = EditorGUIUtility.singleLineHeight;
            property.isExpanded = EditorGUI.Foldout(position, property.isExpanded, label);
            if (property.isExpanded)
            {
                EditorGUI.indentLevel = 1;

                position.y += position.height + EditorGUIUtility.standardVerticalSpacing;
                EditorGUI.PropertyField(position, property.FindPropertyRelative("Delay"));
                position.y += position.height + EditorGUIUtility.standardVerticalSpacing;
                EditorGUI.PropertyField(position, property.FindPropertyRelative("Duration"));
                position.y += position.height + EditorGUIUtility.standardVerticalSpacing;
                EditorGUI.PropertyField(position, property.FindPropertyRelative("TransitionType"));
                position.y += position.height + EditorGUIUtility.standardVerticalSpacing;

                if (transitionSettings.TransitionType == TransitionHelper.TweenType.none)
                {
                    EditorGUI.indentLevel += 1;
                    EditorGUI.HelpBox(EditorGUI.IndentedRect(position), "This transition will be ignored!", MessageType.Info);
                    EditorGUI.indentLevel -= 1;
                }

                else if (transitionSettings.TransitionType == TransitionHelper.TweenType.AnimationCurve)
                {
                    EditorGUI.indentLevel += 1;
                    Rect helpPosition = EditorGUI.IndentedRect(position);
                    helpPosition.height *= 2;
                    EditorGUI.HelpBox(helpPosition, "Custom animation curve with absolute values.\nClick the curve below to edit.", MessageType.Info);
                    position.y     += helpPosition.height + EditorGUIUtility.standardVerticalSpacing;
                    position.height = EditorGUIUtility.singleLineHeight * 4;
                    EditorGUI.PropertyField(position, property.FindPropertyRelative("AnimationCurve"), GUIContent.none);
                    EditorGUI.indentLevel -= 1;
                }

                else
                {
                    EditorGUI.indentLevel += 1;

                    var easingFunction = TransitionHelper.GetTweenFunction(transitionSettings.TransitionType);
                    if (easingFunction == null)
                    {
                        // should never happen, but worth checking
                        EditorGUI.HelpBox(EditorGUI.IndentedRect(position), "Curve not found! Please report this error.", MessageType.Error);
                    }
                    else
                    {
                        EditorGUI.HelpBox(EditorGUI.IndentedRect(position), "Fixed Transition Curve.", MessageType.Info);
                        position.y     += position.height + EditorGUIUtility.standardVerticalSpacing;
                        position.height = EditorGUIUtility.singleLineHeight * 5;

                        // set default texture color
                        var texture = new Texture2D((int)position.width, (int)position.height, TextureFormat.ARGB32,
                                                    false);
                        var colors = new Color[texture.width * texture.height];
                        for (var i = 0; i < colors.Length; i++)
                        {
                            colors[i] = Color.black;
                        }

                        // First calculate min / max y as function might send values below 0 or above 1
                        var normalisedWidth = 1f / texture.width;
                        var minValue        = float.MaxValue;
                        var maxValue        = float.MinValue;
                        for (var i = 0; i < texture.width; i++)
                        {
                            var normalisedX = normalisedWidth * i;
                            var y           = easingFunction(0, 1, normalisedX);
                            if (y < minValue)
                            {
                                minValue = y;
                            }
                            if (y > maxValue)
                            {
                                maxValue = y;
                            }
                        }

                        // plot values for all columns. graph, 0 and 1
                        var zeroRow = GetGraphRow(minValue, maxValue, 0, texture.height);
                        var oneRow  = GetGraphRow(minValue, maxValue, 1, texture.height);
                        for (var i = 0; i < position.width; i++)
                        {
                            // lines at 0 and 1
                            PlotGraphPoint(i, zeroRow, texture.width, texture.height, colors, Color.gray);
                            PlotGraphPoint(i, oneRow, texture.width, texture.height, colors, Color.gray);

                            // graph value
                            var normalisedX = normalisedWidth * i;
                            var value       = easingFunction(0, 1, normalisedX);
                            PlotGraphPosition(i, texture.width, minValue, maxValue, value, texture.height, colors, Color.green);
                        }
                        // Set and apply pixels
                        texture.SetPixels(colors);
                        texture.Apply();

                        // workaround given DrawPreviewTexture doesn't seem to work properly (disappears after a short while)!
                        GUIStyle style = new GUIStyle();
                        style.normal.background = texture;
                        EditorGUI.LabelField(position, GUIContent.none, style);

                        //EditorGUI.DrawPreviewTexture(position, texture);
                        EditorGUI.indentLevel -= 1;
                    }
                }

                position.y     += position.height + EditorGUIUtility.standardVerticalSpacing;
                position.height = EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
                showAdvanced    = EditorGUI.Foldout(position, showAdvanced, new GUIContent("Advanced"));
                if (showAdvanced)
                {
                    position.y += position.height + EditorGUIUtility.standardVerticalSpacing;
                    EditorGUI.PropertyField(position, property.FindPropertyRelative("TransitionChildren"));
                    position.y += position.height + EditorGUIUtility.standardVerticalSpacing;
                    EditorGUI.PropertyField(position, property.FindPropertyRelative("MustTriggerDirect"));
                }

                position.y     += position.height + EditorGUIUtility.standardVerticalSpacing;
                position.height = EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
                showEvents      = EditorGUI.Foldout(position, showEvents, new GUIContent("Events"));
                if (showEvents)
                {
                    position.y     += position.height + EditorGUIUtility.standardVerticalSpacing;
                    position.height = EditorGUI.GetPropertyHeight(property.FindPropertyRelative("OnTransitionStart"));
                    Rect eventsPosition = EditorGUI.IndentedRect(position);
                    EditorGUI.PropertyField(eventsPosition, property.FindPropertyRelative("OnTransitionStart"));

                    position.y     += position.height + EditorGUIUtility.standardVerticalSpacing;
                    position.height = EditorGUI.GetPropertyHeight(property.FindPropertyRelative("OnTransitionComplete"));
                    eventsPosition  = EditorGUI.IndentedRect(position);
                    EditorGUI.PropertyField(eventsPosition, property.FindPropertyRelative("OnTransitionComplete"));
                }
            }
            EditorGUI.EndProperty();
        }
Exemplo n.º 3
0
        /// <summary>
        /// Draw the Editor GUI
        /// </summary>
        public override bool OnGUI()
        {
            var playMakerTransitionBase = target as PlayMakerTransitionBase;

            ShowHeaderGUI();

            //EditorHelper.DrawDefaultInspector(serializedObject, new List<string>() { "m_Script", "_animateChanges" });
            EditField("Delay");
            EditField("Duration");
            EditField("TransitionType");

            if ((TransitionHelper.TweenType)playMakerTransitionBase.TransitionType.Value == TransitionHelper.TweenType.none)
            {
                EditorGUI.indentLevel += 1;
                EditorGUILayout.HelpBox("This transition will be ignored!", MessageType.Info);
                EditorGUI.indentLevel -= 1;
            }

            else if ((TransitionHelper.TweenType)playMakerTransitionBase.TransitionType.Value == TransitionHelper.TweenType.AnimationCurve)
            {
                EditorGUI.indentLevel += 1;
                EditorGUILayout.HelpBox("Custom animation curve with absolute values.\nClick the curve below to edit.", MessageType.None);
                EditField("AnimationCurve");
                //EditorGUILayout.PropertyField(animationCurveProperty, GUIContent.none, GUILayout.MinHeight(EditorGUIUtility.singleLineHeight * 4));
                EditorGUI.indentLevel -= 1;
            }

            else
            {
                EditorGUI.indentLevel += 1;

                var easingFunction = TransitionHelper.GetTweenFunction((TransitionHelper.TweenType)playMakerTransitionBase.TransitionType.Value);
                if (easingFunction == null)
                {
                    // should never happen, but worth checking
                    EditorGUILayout.HelpBox("Curve not found! Please report this error.", MessageType.Error);
                }
                else
                {
                    EditorGUILayout.HelpBox("Fixed Transition Curve.", MessageType.None);

                    TransitionBaseEditor.DrawTweenPreview(easingFunction);
                    EditorGUI.indentLevel -= 1;
                }
            }

            GUILayout.Space(5);
            _showAdvancedSettings = EditorGUILayout.Foldout(_showAdvancedSettings, new GUIContent("Advanced"));
            if (_showAdvancedSettings)
            {
                EditorGUI.indentLevel += 1;
                EditField("TimeUpdateMethod");
                EditorGUI.indentLevel -= 1;
            }

            _showEvents = EditorGUILayout.Foldout(_showEvents, new GUIContent("Events"));
            if (_showEvents)
            {
                EditorGUILayout.BeginHorizontal();
                GUILayout.Space(15f);
                EditorGUILayout.BeginVertical();
                // Below doesn't seem to work in PlayMaker Action Editor
                //EditField("OnTransitionStart");
                //EditField("OnTransitionUpdate");
                //EditField("OnTransitionComplete");
                EditField("TransitionStartEvent");
                EditField("TransitionCompleteEvent");
                EditorGUILayout.EndVertical();
                EditorGUILayout.EndHorizontal();
            }

            GUILayout.Space(3f);
            ShowFooterGUI();
            return(GUI.changed);
        }