public void FadeColor(Color color, float duration, bool ignoreTimeScale) { if (debug) { Trace.Script("Fading to " + color, this); } previousColor = currentColor; currentColor = color; //image.CrossFadeColor(color, duration, ignoreTimeScale, useAlpha); this.StartCoroutine(Routines.Lerp(image.color, color, duration, (Color val) => { image.color = val; }, Color.Lerp), "Fade Color"); }
//--------------------------------------------------------------------------------------------/ // Methods //--------------------------------------------------------------------------------------------/ public void Fade(float alpha, float duration, bool ignoreTimeScale) { if (debug) { Trace.Script("Fading to " + alpha, this); } previousAlpha = currentAlpha; currentAlpha = alpha; //image.CrossFadeAlpha(alpha, duration, ignoreTimeScale); this.StartCoroutine(Routines.Lerp(image.color.a, alpha, duration, (float val) => { image.color = image.color.ToAlpha(val); }, Routines.Lerp), "Fade"); }
//--------------------------------------------------------------------------------------------/ // Methods //--------------------------------------------------------------------------------------------/ /// <summary> /// Interpolates to the specified transformation. /// </summary> public void Apply(Vector3 value) { currentAction = Actions.Sequence(this); if (debug) { Trace.Script($"The {eventType} operation was applied on {target.name}", this); } switch (eventType) { case EventType.Translate: transformationType = TransformationType.Translate; if (valueType == ValueType.Static) { if (local) { previousValue = target.localPosition; currentCoroutine = Routines.Interpolate(previousValue, currentValue, duration, (Vector3 val) => { target.localPosition = val; }, ease); //Actions.Property(currentAction, () => target.localPosition, currentValue, this.duration, this.ease); } else { previousValue = target.position; currentCoroutine = Routines.Interpolate(previousValue, currentValue, duration, (Vector3 val) => { target.position = val; }, ease); //Actions.Property(currentAction, () => target.position, currentValue, this.duration, this.ease); } } else if (valueType == ValueType.Mirror) { previousValue = target.position; currentCoroutine = Routines.Interpolate(previousValue, source.position, duration, (Vector3 val) => { target.position = val; }, ease); //Actions.Property(currentAction, () => target.position, source.position, this.duration, this.ease); } target.StartCoroutine(currentCoroutine, transformationType); break; case EventType.Rotate: transformationType = TransformationType.Rotate; previousValue = target.rotation.eulerAngles; currentCoroutine = Routines.Rotate(target, isMirror ? source.rotation.eulerAngles : currentValue, duration); target.StartCoroutine(currentCoroutine, transformationType); //Actions.Property(currentAction, () => target.rotation.eulerAngles, isMirror ? source.localRotation.eulerAngles : currentValue, this.duration, this.ease); break; case EventType.RotateAround: transformationType = TransformationType.Translate | TransformationType.Rotate; previousValue = target.rotation.eulerAngles; currentCoroutine = Routines.RotateAround(target, isMirror ? source.position : currentValue, axis, angleAroundTarget, duration); target.StartCoroutine(currentCoroutine, transformationType); break; case EventType.Scale: previousValue = target.localScale; transformationType = TransformationType.Scale; currentCoroutine = Routines.Interpolate(previousValue, isMirror ? source.localScale : currentValue, duration, (Vector3 val) => { target.localScale = val; }, ease);; //Routines.Scale(target, isMirror ? source.localScale : currentValue, this.duration); target.StartCoroutine(currentCoroutine, transformationType); //Actions.Property(currentAction, () => target.localScale, isMirror ? source.localScale : currentValue, this.duration, this.ease); break; case EventType.Parent: Actions.Delay(currentAction, duration); Actions.Call(currentAction, () => { target.SetParent(source); }); break; case EventType.Reset: Actions.Delay(currentAction, duration); Actions.Call(currentAction, () => { target.Reset(); }); break; } }
//--------------------------------------------------------------------------------------------/ // Methods //--------------------------------------------------------------------------------------------/ public IEnumerator MakeInterpolateRoutine() { IEnumerator interpolator = null; switch (memberType) { case ActionProperty.Types.Integer: { int currentValue = member.Get <int>(); bool shouldToggle = (toggle && currentValue == intValue); int nextValue = shouldToggle ? (int)previousValue : intValue; //interpolator = Routines.Lerp(currentValue, nextValue, duration, (float val) => { property.Set(Mathf.CeilToInt(val)); }, Routines.Lerp); interpolator = Routines.Interpolate(currentValue, nextValue, duration, (float val) => { member.Set(Mathf.CeilToInt(val)); }, ease); previousValue = currentValue; } break; case ActionProperty.Types.Float: { float currentValue = member.Get <float>(); bool shouldToggle = (toggle && currentValue == floatValue); Trace.Script("Previous float " + previousValue + ", Current Float = " + currentValue + ", Float Value = " + floatValue + ", shouldToggle = " + shouldToggle); float nextValue = shouldToggle ? (float)previousValue : floatValue; //interpolator = Routines.Lerp(currentValue, nextValue, duration, (float val) => { property.Set(val); }, Routines.Lerp); interpolator = Routines.Interpolate(currentValue, nextValue, duration, (float val) => { member.Set(val); }, ease); previousValue = currentValue; } break; case ActionProperty.Types.Boolean: { bool currentValue = member.Get <bool>(); bool shouldToggle = (toggle && currentValue == boolValue); bool nextValue = shouldToggle ? (bool)previousValue : boolValue; interpolator = Routines.Call(() => { member.Set(nextValue); }, duration); previousValue = currentValue; } break; case ActionProperty.Types.Vector2: { Vector2 currentValue = member.Get <Vector2>(); bool shouldToggle = (toggle && currentValue == vector2Value); Vector2 nextValue = shouldToggle ? (Vector2)previousValue : vector2Value; //interpolator = Routines.Lerp(currentValue, nextValue, duration, (Vector2 val) => { property.Set(val); }, Vector2.Lerp); interpolator = Routines.Interpolate(currentValue, nextValue, duration, (Vector2 val) => { member.Set(val); }, ease); previousValue = currentValue; } break; case ActionProperty.Types.Vector3: { Vector3 currentValue = member.Get <Vector3>(); bool shouldToggle = (toggle && currentValue == vector3Value); Vector3 nextValue = shouldToggle ? (Vector3)previousValue : vector3Value; //interpolator = Routines.Lerp(currentValue, nextValue, duration, (Vector3 val) => { property.Set(val); }, Vector3.Lerp); interpolator = Routines.Interpolate(currentValue, nextValue, duration, (Vector3 val) => { member.Set(val); }, ease); previousValue = currentValue; } break; case ActionProperty.Types.Vector4: { Vector4 currentValue = member.Get <Vector4>(); bool shouldToggle = (toggle && currentValue == vector4Value); Vector4 nextValue = shouldToggle ? (Vector4)previousValue : vector4Value; //interpolator = Routines.Lerp(currentValue, nextValue, duration, (Vector4 val) => { property.Set(val); }, Vector4.Lerp); interpolator = Routines.Interpolate(currentValue, nextValue, duration, (Vector4 val) => { member.Set(val); }, ease); previousValue = currentValue; } break; case ActionProperty.Types.Color: { Color currentValue = member.Get <Color>(); bool shouldToggle = (toggle && currentValue == colorValue); Color nextValue = shouldToggle ? (Color)previousValue : colorValue; //interpolator = Routines.Lerp(currentValue, nextValue, duration, (Color val) => { property.Set(val); }, Color.Lerp); interpolator = Routines.Interpolate(currentValue, nextValue, duration, (Color val) => { member.Set(val); }, ease); previousValue = currentValue; } break; default: break; } return(interpolator); }
//------------------------------------------------------------------------/ // Methods: Private //------------------------------------------------------------------------/ private void ApplyCrossFade(float alpha, float duration, System.Action onFinished) { this.StartCoroutine(Routines.CrossFadeAlpha(screen, alpha, duration), "CrossFade", onFinished); }