Ejemplo n.º 1
0
        void Transition(TransitionSettings transitionSettings, TransitionModeType transitionMode)
        {
            if (transitionMode == TransitionModeType.In && TransitionInConfig.OnTransitionStart != null)
            {
                TransitionInConfig.OnTransitionStart.Invoke();
            }
            else if (transitionMode == TransitionModeType.Out && TransitionOutConfig.OnTransitionStart != null)
            {
                TransitionOutConfig.OnTransitionStart.Invoke();
            }

            // set new transition id to stop all old transitions.
            _activeTransitionId = Guid.NewGuid().ToString();
            _transitionSettings = transitionSettings;
            TransitionMode      = transitionMode;

            // get the easing function - will be null for unsupported types.
            _easingFunction = TweenMethods.GetEasingFunction(_transitionSettings.TransitionType);

            // if delay and duration are both zero then just set end state, otherwise run the transition.
            if (Mathf.Approximately(_transitionSettings.Delay, 0) && Mathf.Approximately(_transitionSettings.Duration, 0))
            {
                SetProgress(1);
                SetAmount(_endFloat);
            }
            else
            {
                SetProgress(0);
                StartCoroutine(TransitionInternal(_activeTransitionId, transitionMode));
            }
        }
Ejemplo n.º 2
0
        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.TransitionType.none)
                {
                    EditorGUI.indentLevel += 1;
                    EditorGUI.HelpBox(EditorGUI.IndentedRect(position), "This transition will be ignored!", MessageType.Info);
                    EditorGUI.indentLevel -= 1;
                }

                else if (transitionSettings.TransitionType == TransitionHelper.TransitionType.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 = TweenMethods.GetEasingFunction(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();
        }