public void Begin(float duration, GoEaseType easeType = GoEaseType.Linear) { foreach (var system in warpStarSystems) { system.Begin(duration, easeType); } }
public static GoTween localPositionToEasedSafe(this Transform t, GoEaseType easeType, float duration, Vector3 endValue, bool isRelative = false) { if (runningTweens == null) { runningTweens = new Dictionary <Transform, GoTweenTypes>(); } if (false == runningTweens.ContainsKey(t)) { runningTweens.Add(t, new GoTweenTypes()); } if ((runningTweens[t].localPosition == null || runningTweens[t].localPosition.state != GoTweenState.Running) && (runningTweens[t].position == null || runningTweens[t].position.state != GoTweenState.Running)) { var tween = t.localPositionToEased(easeType, duration, endValue, isRelative); runningTweens[t].localPosition = tween; return(tween); } else { #if DEBUG Debug.Log(t.displayName + " new position Tween was ignored \n easeType: " + easeType.ToString() + "\n duration: " + duration + "\n endValue: " + endValue.ToString()); #endif return(null); } }
public static GoTween MakeTween( Transform TheTransform, Vector3 Position, Quaternion Rotation, float MoveTime = 0.5f, bool IsLocal = false, GoEaseType Ease = GoEaseType.Linear, VoidDelegate OnCompleteFunction = null ) { GoTweenConfig Config = new GoTweenConfig(); Config.addTweenProperty(new PositionTweenProperty(Position, false, IsLocal)); //Config.addTweenProperty(new EulerAnglesTweenProperty(Rotation, false, IsLocal)); Config.addTweenProperty(new RotationQuaternionTweenProperty(Rotation, false, IsLocal)); Config.setEaseType(Ease); if(OnCompleteFunction != null){ Config.onComplete(c => { OnCompleteFunction(); }); } GoTween NewTween = new GoTween(TheTransform, MoveTime, Config); Go.addTween(NewTween); return NewTween; }
/// <summary> /// sets the ease curve for the Tween /// </summary> public GoTweenConfig setEaseCurve(AnimationCurve easeCurve) { this.easeCurve = easeCurve; this.easeType = GoEaseType.AnimationCurve; return(this); }
public void Begin(float duration, GoEaseType easeType = GoEaseType.Linear) { var starsMain = _stars.main; starsMain.startSpeed = new ParticleSystem.MinMaxCurve(0f); _stars.Play(); _beginTween = Go.to(_stars, duration, new GoTweenConfig().floatProp("startSpeed", _maxSpeed).setEaseType(easeType)); }
void EmitGoKitPositionFor(Transform t, Vector3 to, float twDuration, GoEaseType ease) { t.position = Vector3.zero; Go.to(t, twDuration, new GoTweenConfig() .addTweenProperty(new PositionTweenProperty(to)) .onComplete(x => EmitGoKitPositionFor(t, to, twDuration, ease)) ); }
void EmitGoKitScaleFor(Transform t, Vector3 to, float twDuration, GoEaseType ease) { t.localScale = Vector3.one; Go.to(t, twDuration, new GoTweenConfig() .addTweenProperty(new ScaleTweenProperty(to)) .onComplete(x => EmitGoKitScaleFor(t, to, twDuration, ease)) ); }
void EmitGoKitRotationFor(Transform t, Vector3 to, float twDuration, GoEaseType ease) { t.rotation = Quaternion.identity; Go.to(t, twDuration, new GoTweenConfig() .addTweenProperty(new RotationTweenProperty(to)) .onComplete(x => EmitGoKitRotationFor(t, to, twDuration, ease)) ); }
/// <summary> /// initializes a new instance and sets up the details according to the config parameter /// </summary> public GoTween(object target, float duration, GoTweenConfig config, Action <AbstractGoTween> onComplete = null) { // default to removing on complete autoRemoveOnComplete = true; this.target = target; this.targetName = target.ToString(); this.duration = duration; // copy the TweenConfig info over id = config.id; delay = config.delay; loopType = config.loopType; iterations = config.iterations; _easeType = config.easeType; updateType = config.propertyUpdateType; isFrom = config.isFrom; timeScale = config.timeScale; _onComplete = config.onCompleteHandler; _onStart = config.onStartHandler; _onIterate = config.onIterateHandler; if (config.isPaused) { state = GoTweenState.Paused; } // if onComplete is passed to the constructor it wins. it is left as the final param to allow an inline Action to be // set and maintain clean code (Actions always try to be the last param of a method) if (onComplete != null) { _onComplete = onComplete; } // add all our properties for (var i = 0; i < config.tweenProperties.Count; i++) { var tweenProp = config.tweenProperties[i]; // if the tween property is initialized already it means it is being reused so we need to clone it if (tweenProp.isInitialized) { tweenProp = tweenProp.clone(); } addTweenProperty(tweenProp); } // calculate total duration if (iterations < 0) { totalDuration = float.PositiveInfinity; } else { totalDuration = iterations * duration; } }
public GoTween(object target, float duration, GoTweenConfig config, Action <AbstractGoTween> onComplete = null) { if (duration <= 0f) { duration = float.Epsilon; UnityEngine.Debug.LogError("tween duration must be greater than 0. coerced to float.Epsilon."); } base.autoRemoveOnComplete = true; base.allowEvents = true; _didInit = false; _didBegin = false; _fireIterationStart = true; this.target = target; targetType = target.GetType(); base.duration = duration; base.id = config.id; delay = config.delay; base.loopType = config.loopType; base.iterations = config.iterations; _easeType = config.easeType; easeCurve = config.easeCurve; base.updateType = config.propertyUpdateType; isFrom = config.isFrom; base.timeScale = config.timeScale; _onInit = config.onInitHandler; _onBegin = config.onBeginHandler; _onIterationStart = config.onIterationStartHandler; _onUpdate = config.onUpdateHandler; _onIterationEnd = config.onIterationEndHandler; _onComplete = config.onCompleteHandler; if (config.isPaused) { base.state = GoTweenState.Paused; } if (onComplete != null) { _onComplete = onComplete; } for (int i = 0; i < config.tweenProperties.Count; i++) { AbstractTweenProperty abstractTweenProperty = config.tweenProperties[i]; if (abstractTweenProperty.isInitialized) { abstractTweenProperty = abstractTweenProperty.clone(); } addTweenProperty(abstractTweenProperty); } if (base.iterations < 0) { base.totalDuration = float.PositiveInfinity; } else { base.totalDuration = (float)base.iterations * duration; } }
public void End(float duration, GoEaseType easeType = GoEaseType.Linear) { if (_beginTween.state == GoTweenState.Running) { _beginTween.pause(); _beginTween.destroy(); } Go.to(_camera, duration, new GoTweenConfig().floatProp("fieldOfView", _originalValue).setEaseType(easeType)); }
public static GoTween positionToEased(this Transform t, GoEaseType easeType, float duration, Vector3 endValue, bool isRelative = false) { var originalEaseType = Go.defaultEaseType; Go.defaultEaseType = easeType; var tween = t.positionTo(duration, endValue, isRelative); Go.defaultEaseType = originalEaseType; return(tween); }
public void End(float duration, GoEaseType easeType = GoEaseType.Linear) { if (_beginTween.state == GoTweenState.Running) { _beginTween.pause(); _beginTween.destroy(); } Go.to(_radialBlur, duration, new GoTweenConfig().floatProp("BlurStrength", 0f).setEaseType(easeType)); }
public void End(float duration, GoEaseType easeType = GoEaseType.Linear) { if (_beginTween.state == GoTweenState.Running) { _beginTween.pause(); _beginTween.destroy(); } Go.to(_stars, duration, new GoTweenConfig().floatProp("startSpeed", 100f).setEaseType(easeType).onComplete(t => Stop())); }
public static GoTween colorToEased(this SpriteRenderer sr, GoEaseType easeType, float duration, Color endValue) { var originalEaseType = Go.defaultEaseType; Go.defaultEaseType = easeType; var tween = sr.material.colorTo(duration, endValue); Go.defaultEaseType = originalEaseType; return(tween); }
public static IEnumerator DoEaseFor(float duration, GoEaseType easeType, Action <float> lerpCallback) { // NOTE (darren): are you serious GoTween... Func <float, float, float, float, float> easeFunction = GoTweenUtils.easeFunctionForType(easeType); for (float time = 0.0f; time <= duration; time += Time.deltaTime) { float percentage = easeFunction.Invoke(time, 0, 1, duration); lerpCallback.Invoke(percentage); yield return(null); } lerpCallback.Invoke(1.0f); }
public static IEnumerator MoveTo(GameObject obj, Vector3 destination, float duration, GoEaseType ease = GoEaseType.Linear, bool waitForCompletion = false) { var tween = Go.to ( obj.transform, duration, new GoTweenConfig() .position( destination ) .setEaseType( ease ) ); if (waitForCompletion) { yield return WaitForTweenComplete( tween ); } else { yield return null; } }
/// <summary> /// initializes a new instance and sets up the details according to the config parameter /// </summary> public GoTween( object target, float duration, GoTweenConfig config, Action<AbstractGoTween> onComplete = null ) { // default to removing on complete autoRemoveOnComplete = true; this.target = target; this.targetName = target.ToString(); this.duration = duration; // copy the TweenConfig info over id = config.id; delay = config.delay; loopType = config.loopType; iterations = config.iterations; _easeType = config.easeType; updateType = config.propertyUpdateType; isFrom = config.isFrom; timeScale = config.timeScale; _onComplete = config.onCompleteHandler; _onStart = config.onStartHandler; _onIterate = config.onIterateHandler; if( config.isPaused ) state = GoTweenState.Paused; // if onComplete is passed to the constructor it wins. it is left as the final param to allow an inline Action to be // set and maintain clean code (Actions always try to be the last param of a method) if( onComplete != null ) _onComplete = onComplete; // add all our properties for( var i = 0; i < config.tweenProperties.Count; i++ ) { var tweenProp = config.tweenProperties[i]; // if the tween property is initialized already it means it is being reused so we need to clone it if( tweenProp.isInitialized ) tweenProp = tweenProp.clone(); addTweenProperty( tweenProp ); } // calculate total duration if( iterations < 0 ) totalDuration = float.PositiveInfinity; else totalDuration = iterations * duration; }
public void TweenTo( float targetOpacity, float duration, float delay= 0, GoEaseType easeType=GoEaseType.Linear, System.Action onComplete=null ) { Activate( opacity ); state = State.Tweening; if ( fadeTween != null ) fadeTween.destroy(); fadeTween = Go.to( this, duration, new GoTweenConfig() .floatProp("opacity", targetOpacity) .setEaseType( easeType ) .setDelay( delay ) .onComplete( t => { fadeTween = null; state = State.Normal; if ( onComplete != null ) onComplete(); })); }
internal GoTween Animate( GameObject target, float duration, GoEaseType ease, bool loopsInfinitely, bool isRelative = false ) { GoTween tween = null; if ( Points.Count > 2 ) { tween = Go.to ( target.transform, duration, new GoTweenConfig ().positionPath ( CreateSpline (), isRelative ) ); tween.eases ( ease ); if ( loopsInfinitely ) tween.loopsInfinitely (); } else if ( Points.Count > 1 ) { target.transform.position = Points[0]; tween = target.transform.positionTo ( duration, Points[1] ); tween.eases ( ease ); if ( loopsInfinitely ) tween.loopsInfinitely ( GoLoopType.PingPong ); } return tween; }
public IEnumerator Transition(string name, GoEaseType type, Vector3 destination, Vector3 scale, Vector3 rotation, float transparency, float duration) { var go = GameObject.Find(name); if (!go) { yield return(null); } else { var ended = false; Go.addTween(new GoTween(ElementHandlerFactory.Instance.CreateHandlerFor(go), duration, new GoTweenConfig() .setEaseType(type) .vector3Prop("Position", destination) .vector3Prop("Scale", scale) .vector3Prop("Rotation", rotation) .floatProp("Transparency", transparency), (tween) => ended = true )); yield return(new WaitUntil(() => ended)); } }
public void TweenTo(float targetOpacity, float duration, float delay = 0, GoEaseType easeType = GoEaseType.Linear, System.Action onComplete = null) { Activate(opacity); state = State.Tweening; if (fadeTween != null) { fadeTween.destroy(); } fadeTween = Go.to(this, duration, new GoTweenConfig() .floatProp("opacity", targetOpacity) .setEaseType(easeType) .setDelay(delay) .onComplete(t => { fadeTween = null; state = State.Normal; if (onComplete != null) { onComplete(); } })); }
internal static GoTween eases( this GoTween tween, GoEaseType ease ) { tween.easeType = ease; return tween; }
/// <summary> /// sets the ease type for the Tween /// </summary> public GoTweenConfig setEaseType( GoEaseType easeType ) { this.easeType = easeType; return this; }
void SetupTweens() { // Ease DG.Tweening.Ease dotweenEase = easing == Easing.Linear ? DG.Tweening.Ease.Linear : DG.Tweening.Ease.InOutQuad; Holoville.HOTween.EaseType hotweenEase = easing == Easing.Linear ? Holoville.HOTween.EaseType.Linear : Holoville.HOTween.EaseType.EaseInOutQuad; LeanTweenType leanEase = easing == Easing.Linear ? LeanTweenType.linear : LeanTweenType.easeInOutQuad; GoEaseType goEase = easing == Easing.Linear ? GoEaseType.Linear : GoEaseType.QuadInOut; iTween.EaseType iTweenEase = easing == Easing.Linear ? iTween.EaseType.linear : iTween.EaseType.easeInOutQuad; // Loop int loops = testSetup == TestSetup.Emit ? 1 : -1; DG.Tweening.LoopType dotweenLoopType = testSetup == TestSetup.YoyoLoop ? DG.Tweening.LoopType.Yoyo : DG.Tweening.LoopType.Restart; Holoville.HOTween.LoopType hotweenLoopType = testSetup == TestSetup.YoyoLoop ? Holoville.HOTween.LoopType.Yoyo : Holoville.HOTween.LoopType.Restart; LeanTweenType leanLoopType = testSetup == TestSetup.YoyoLoop ? LeanTweenType.pingPong : LeanTweenType.clamp; GoLoopType goLoopType = testSetup == TestSetup.YoyoLoop ? GoLoopType.PingPong : GoLoopType.RestartFromBeginning; iTween.LoopType iTweenLoopType = loops != -1 ? iTween.LoopType.none : testSetup == TestSetup.YoyoLoop ? iTween.LoopType.pingPong : iTween.LoopType.loop; // Create tweens switch (testType) { case TestType.Floats: for (int i = 0; i < numTweens; ++i) { TestObjectData data = testObjsData[i]; switch (engine) { case Engine.HOTween: HOTween.To(data, duration, new Holoville.HOTween.TweenParms() .Prop("floatValue", rndFloats[i]) .Ease(hotweenEase) .Loops(loops, hotweenLoopType) ); break; case Engine.LeanTween: LeanTween.value(this.gameObject, x => data.floatValue = x, data.floatValue, rndFloats[i], duration).setEase(leanEase).setRepeat(loops).setLoopType(leanLoopType); break; case Engine.GoKit: Go.to(data, duration, new GoTweenConfig() .floatProp("floatValueProperty", rndFloats[i]) .setEaseType(goEase) .setIterations(loops, goLoopType) ); break; case Engine.iTween: Hashtable hs = new Hashtable(); hs.Add("from", data.floatValue); hs.Add("to", rndFloats[i]); hs.Add("time", duration); hs.Add("onupdate", "UpdateiTweenFloat"); hs.Add("looptype", iTweenLoopType); hs.Add("easetype", iTweenEase); iTween.ValueTo(this.gameObject, hs); break; default: // tCopy is needed to create correct closure object, // otherwise closure will pass the same t to all the loop TestObjectData dataCopy = data; DOTween.To(() => dataCopy.floatValue, x => dataCopy.floatValue = x, rndFloats[i], duration).SetEase(dotweenEase).SetLoops(loops, dotweenLoopType); break; } } break; default: for (int i = 0; i < numTweens; ++i) { float twDuration = testSetup == TestSetup.Emit ? UnityEngine.Random.Range(0.25f, 1f) : duration; Transform t = testObjsTrans[i]; GameObject go = testObjsGos[i]; // Used by LeanTween and iTween switch (engine) { case Engine.HOTween: Holoville.HOTween.TweenParms tp = new Holoville.HOTween.TweenParms() .Ease(hotweenEase) .Loops(loops, hotweenLoopType); if (positionTween) { Vector3 toPos = rndPositions[i]; tp.Prop("position", toPos); if (testSetup == TestSetup.Emit) { tp.OnComplete(() => EmitHOTweenPositionFor(t, toPos, twDuration, hotweenEase)); } } if (rotationTween) { Vector3 toRot = rndRotations[i]; tp.Prop("rotation", toRot); if (testSetup == TestSetup.Emit) { tp.OnComplete(() => EmitHOTweenRotationFor(t, toRot, twDuration, hotweenEase)); } } if (scaleTween) { tp.Prop("localScale", rndScale); if (testSetup == TestSetup.Emit) { tp.OnComplete(() => EmitHOTweenScaleFor(t, rndScale, twDuration, hotweenEase)); } } HOTween.To(t, twDuration, tp); break; case Engine.LeanTween: LTDescr leanTween; if (positionTween) { Vector3 toPos = rndPositions[i]; leanTween = LeanTween.move(go, rndPositions[i], twDuration).setEase(leanEase).setRepeat(loops).setLoopType(leanLoopType); if (testSetup == TestSetup.Emit) { leanTween.setOnComplete(() => EmitLeanTweenPositionFor(t, go, toPos, twDuration, leanEase)); } } if (rotationTween) { Vector3 toRot = rndRotations[i]; leanTween = LeanTween.rotate(go, rndRotations[i], twDuration).setEase(leanEase).setRepeat(loops).setLoopType(leanLoopType); if (testSetup == TestSetup.Emit) { leanTween.setOnComplete(() => EmitLeanTweenRotationFor(t, go, toRot, twDuration, leanEase)); } } if (scaleTween) { leanTween = LeanTween.scale(go, rndScale, twDuration).setEase(leanEase).setRepeat(loops).setLoopType(leanLoopType); if (testSetup == TestSetup.Emit) { leanTween.setOnComplete(() => EmitLeanTweenScaleFor(t, go, rndScale, twDuration, leanEase)); } } break; case Engine.GoKit: GoTweenConfig goConfig = new GoTweenConfig() .setEaseType(goEase) .setIterations(loops, goLoopType); if (positionTween) { Vector3 toPos = rndPositions[i]; goConfig.addTweenProperty(new PositionTweenProperty(toPos)); if (testSetup == TestSetup.Emit) { goConfig.onComplete(x => EmitGoKitPositionFor(t, toPos, twDuration, goEase)); } } if (rotationTween) { Vector3 toRot = rndRotations[i]; goConfig.addTweenProperty(new RotationTweenProperty(toRot)); if (testSetup == TestSetup.Emit) { goConfig.onComplete(x => EmitGoKitRotationFor(t, toRot, twDuration, goEase)); } } if (scaleTween) { goConfig.addTweenProperty(new ScaleTweenProperty(rndScale)); if (testSetup == TestSetup.Emit) { goConfig.onComplete(x => EmitGoKitScaleFor(t, rndScale, twDuration, goEase)); } } Go.to(t, twDuration, goConfig); break; case Engine.iTween: Hashtable hs; if (positionTween) { hs = new Hashtable(); hs.Add("position", rndPositions[i]); hs.Add("time", twDuration); hs.Add("looptype", iTweenLoopType); hs.Add("easetype", iTweenEase); iTween.MoveTo(go, hs); } if (rotationTween) { hs = new Hashtable(); hs.Add("rotation", rndRotations[i]); hs.Add("time", twDuration); hs.Add("looptype", iTweenLoopType); hs.Add("easetype", iTweenEase); iTween.RotateTo(go, hs); } if (scaleTween) { hs = new Hashtable(); hs.Add("scale", rndScale); hs.Add("time", twDuration); hs.Add("looptype", iTweenLoopType); hs.Add("easetype", iTweenEase); iTween.ScaleTo(go, hs); } break; default: // tCopy is needed to create correct closure object, // otherwise closure will pass the same t to all the loop Transform tCopy = t; DG.Tweening.Tween dotween; if (positionTween) { Vector3 toPos = rndPositions[i]; dotween = tCopy.DOMove(toPos, twDuration).SetEase(dotweenEase).SetLoops(loops, dotweenLoopType); if (testSetup == TestSetup.Emit) { dotween.OnComplete(() => EmitDOTweenPositionFor(t, toPos, twDuration, dotweenEase)); } } if (rotationTween) { Vector3 toRot = rndRotations[i]; dotween = tCopy.DORotate(toRot, twDuration).SetEase(dotweenEase).SetLoops(loops, dotweenLoopType); if (testSetup == TestSetup.Emit) { dotween.OnComplete(() => EmitDOTweenRotationFor(t, toRot, twDuration, dotweenEase)); } } if (scaleTween) { dotween = tCopy.DOScale(rndScale, twDuration).SetEase(dotweenEase).SetLoops(loops, dotweenLoopType); if (testSetup == TestSetup.Emit) { dotween.OnComplete(() => EmitDOTweenScaleFor(t, rndScale, twDuration, dotweenEase)); } } break; } } break; } }
public void Begin(float duration, float fOVZoomInValue, GoEaseType easeType = GoEaseType.Linear) { _beginTween = Go.to(_camera, duration, new GoTweenConfig().floatProp("fieldOfView", fOVZoomInValue).setEaseType(easeType)); }
/// <summary> /// sets the ease type for this tween property /// technically, this should be an internal method /// </summary> public void setEaseType( GoEaseType easeType ) { _easeFunction = GoTweenUtils.easeFunctionForType( easeType ); }
/// <summary> /// fetches the actual function for the given ease type /// </summary> public static Func <float, float, float> EaseFunctionForType(GoEaseType easeType) { return(funcs[(int)easeType]); // switch(easeType) // { // case GoEaseType.Linear: // return GoKitLiteEasing.Linear.EaseNone; // // case GoEaseType.BackIn: // return GoKitLiteEasing.Back.EaseIn; // case GoEaseType.BackOut: // return GoKitLiteEasing.Back.EaseOut; // case GoEaseType.BackInOut: // return GoKitLiteEasing.Back.EaseInOut; // // case GoEaseType.BounceIn: // return GoKitLiteEasing.Bounce.EaseIn; // case GoEaseType.BounceOut: // return GoKitLiteEasing.Bounce.EaseOut; // case GoEaseType.BounceInOut: // return GoKitLiteEasing.Bounce.EaseInOut; // // case GoEaseType.CircIn: // return GoKitLiteEasing.Circular.EaseIn; // case GoEaseType.CircOut: // return GoKitLiteEasing.Circular.EaseOut; // case GoEaseType.CircInOut: // return GoKitLiteEasing.Circular.EaseInOut; // // case GoEaseType.CubicIn: // return GoKitLiteEasing.Cubic.EaseIn; // case GoEaseType.CubicOut: // return GoKitLiteEasing.Cubic.EaseOut; // case GoEaseType.CubicInOut: // return GoKitLiteEasing.Cubic.EaseInOut; // // case GoEaseType.ElasticIn: // return GoKitLiteEasing.Elastic.EaseIn; // case GoEaseType.ElasticOut: // return GoKitLiteEasing.Elastic.EaseOut; // case GoEaseType.ElasticInOut: // return GoKitLiteEasing.Elastic.EaseInOut; // case GoEaseType.Punch: // return GoKitLiteEasing.Elastic.Punch; // // case GoEaseType.ExpoIn: // return GoKitLiteEasing.Exponential.EaseIn; // case GoEaseType.ExpoOut: // return GoKitLiteEasing.Exponential.EaseOut; // case GoEaseType.ExpoInOut: // return GoKitLiteEasing.Exponential.EaseInOut; // // case GoEaseType.QuadIn: // return GoKitLiteEasing.Quadratic.EaseIn; // case GoEaseType.QuadOut: // return GoKitLiteEasing.Quadratic.EaseOut; // case GoEaseType.QuadInOut: // return GoKitLiteEasing.Quadratic.EaseInOut; // // case GoEaseType.QuartIn: // return GoKitLiteEasing.Quartic.EaseIn; // case GoEaseType.QuartOut: // return GoKitLiteEasing.Quartic.EaseOut; // case GoEaseType.QuartInOut: // return GoKitLiteEasing.Quartic.EaseInOut; // // case GoEaseType.QuintIn: // return GoKitLiteEasing.Quintic.EaseIn; // case GoEaseType.QuintOut: // return GoKitLiteEasing.Quartic.EaseOut; // case GoEaseType.QuintInOut: // return GoKitLiteEasing.Quartic.EaseInOut; // // case GoEaseType.SineIn: // return GoKitLiteEasing.Sinusoidal.EaseIn; // case GoEaseType.SineOut: // return GoKitLiteEasing.Sinusoidal.EaseOut; // case GoEaseType.SineInOut: // return GoKitLiteEasing.Sinusoidal.EaseInOut; // } // // return GoKitLiteEasing.Linear.EaseNone; }
/// <summary> /// sets the ease type for this tween property /// technically, this should be an internal method /// </summary> public void setEaseType(GoEaseType easeType) { _easeFunction = GoTweenUtils.easeFunctionForType(easeType); }
/// <summary> /// initializes a new instance and sets up the details according to the config parameter /// </summary> public GoTween( object target, float duration, GoTweenConfig config, Action<AbstractGoTween> onComplete = null ) { // default to removing on complete autoRemoveOnComplete = true; // allow events by default allowEvents = true; // setup callback bools _didInit = false; _didBegin = false; // flag the onIterationStart event to fire. // as long as goTo is not called on this tween, the onIterationStart event will fire // as soon as the delay, if any, is completed. _fireIterationStart = true; this.target = target; this.targetTypeString = target.GetType().ToString(); this.duration = duration; // copy the TweenConfig info over id = config.id; delay = config.delay; loopType = config.loopType; iterations = config.iterations; _easeType = config.easeType; updateType = config.propertyUpdateType; isFrom = config.isFrom; timeScale = config.timeScale; _onInit = config.onInitHandler; _onBegin = config.onBeginHandler; _onIterationStart = config.onIterationStartHandler; _onUpdate = config.onUpdateHandler; _onIterationEnd = config.onIterationEndHandler; _onComplete = config.onCompleteHandler; if( config.isPaused ) state = GoTweenState.Paused; // if onComplete is passed to the constructor it wins. it is left as the final param to allow an inline Action to be // set and maintain clean code (Actions always try to be the last param of a method) if( onComplete != null ) _onComplete = onComplete; // add all our properties for( var i = 0; i < config.tweenProperties.Count; ++i ) { var tweenProp = config.tweenProperties[i]; // if the tween property is initialized already it means it is being reused so we need to clone it if( tweenProp.isInitialized ) tweenProp = tweenProp.clone(); addTweenProperty( tweenProp ); } // calculate total duration if( iterations < 0 ) totalDuration = float.PositiveInfinity; else totalDuration = iterations * duration; }
void EmitGoKitRotationFor(Transform t, Vector3 to, float twDuration, GoEaseType ease) { t.rotation = Quaternion.identity; Go.to(t, twDuration, new GoTweenConfig() .addTweenProperty(new RotationTweenProperty(to)) .onComplete(x=> EmitGoKitRotationFor(t, to, twDuration, ease)) ); }
void EmitGoKitScaleFor(Transform t, Vector3 to, float twDuration, GoEaseType ease) { t.localScale = Vector3.one; Go.to(t, twDuration, new GoTweenConfig() .addTweenProperty(new ScaleTweenProperty(to)) .onComplete(x=> EmitGoKitScaleFor(t, to, twDuration, ease)) ); }
void EmitGoKitPositionFor(Transform t, Vector3 to, float twDuration, GoEaseType ease) { t.position = Vector3.zero; Go.to(t, twDuration, new GoTweenConfig() .addTweenProperty(new PositionTweenProperty(to)) .onComplete(x=> EmitGoKitPositionFor(t, to, twDuration, ease)) ); }
/// <summary> /// sets the ease curve for the Tween /// </summary> public GoTweenConfig setEaseCurve( AnimationCurve easeCurve ) { this.easeCurve = easeCurve; this.easeType = GoEaseType.AnimationCurve; return this; }
internal static GoTweenChain animateJelly(this Transform transform, float time, float value, int repeatCount = 1, GoEaseType ease = GoEaseType.QuadInOut) { Vector3 scaleAtStart = transform.localScale; GoTweenChain chain = new GoTweenChain(); for (int i = repeatCount; i > 0; i--) { float factor = ((float)i) / repeatCount; Vector3 target = new Vector3(scaleAtStart.x + (value * factor), scaleAtStart.y - (value * factor), scaleAtStart.z); chain.append(transform.scaleTo(time * factor, target).eases(ease)); target = new Vector3(scaleAtStart.x - (value * factor), scaleAtStart.y + (value * factor), scaleAtStart.z); chain.append(transform.scaleTo(time * factor, target).eases(ease)); } chain.append(transform.scaleTo(time / repeatCount, scaleAtStart).eases(ease)); chain.play(); return(chain); }
/// <summary> /// initializes a new instance and sets up the details according to the config parameter /// </summary> public GoTween(object target, float duration, GoTweenConfig config, Action <AbstractGoTween> onComplete = null) { // all tweens must be intialized to have a duration greater than zero. keep in mind that this will ensure // the tween occurs over two frames: the initialized value, and the final value. if you are looking for a // tween to reach the end of it's tween immediately, be sure to call complete() on it after creation. if (duration <= 0) { duration = float.Epsilon; Debug.LogError("tween duration must be greater than 0. coerced to float.Epsilon."); } // default to removing on complete autoRemoveOnComplete = true; // allow events by default allowEvents = true; // setup callback bools _didInit = false; _didBegin = false; // flag the onIterationStart event to fire. // as long as goTo is not called on this tween, the onIterationStart event will fire // as soon as the delay, if any, is completed. _fireIterationStart = true; this.target = target; this.targetType = target.GetType(); this.duration = duration; // copy the TweenConfig info over id = config.id; delay = config.delay; loopType = config.loopType; iterations = config.iterations; _easeType = config.easeType; easeCurve = config.easeCurve; updateType = config.propertyUpdateType; isFrom = config.isFrom; timeScale = config.timeScale; _onInit = config.onInitHandler; _onBegin = config.onBeginHandler; _onIterationStart = config.onIterationStartHandler; _onUpdate = config.onUpdateHandler; _onIterationEnd = config.onIterationEndHandler; _onComplete = config.onCompleteHandler; if (config.isPaused) { state = GoTweenState.Paused; } // if onComplete is passed to the constructor it wins. it is left as the final param to allow an inline Action to be // set and maintain clean code (Actions always try to be the last param of a method) if (onComplete != null) { _onComplete = onComplete; } // add all our properties for (var i = 0; i < config.tweenProperties.Count; ++i) { var tweenProp = config.tweenProperties[i]; // if the tween property is initialized already it means it is being reused so we need to clone it if (tweenProp.isInitialized) { tweenProp = tweenProp.clone(); } addTweenProperty(tweenProp); } // calculate total duration if (iterations < 0) { totalDuration = float.PositiveInfinity; } else { totalDuration = iterations * duration; } }
/// <summary> /// initializes a new instance and sets up the details according to the config parameter /// </summary> public GoTween(object target, float duration, GoTweenConfig config, Action <AbstractGoTween> onComplete = null) { // default to removing on complete autoRemoveOnComplete = true; // allow events by default allowEvents = true; // setup callback bools _didInit = false; _didBegin = false; // flag the onIterationStart event to fire. // as long as goTo is not called on this tween, the onIterationStart event will fire // as soon as the delay, if any, is completed. _fireIterationStart = true; this.target = target; this.targetTypeString = target.GetType().ToString(); this.duration = duration; // copy the TweenConfig info over id = config.id; delay = config.delay; loopType = config.loopType; iterations = config.iterations; _easeType = config.easeType; updateType = config.propertyUpdateType; isFrom = config.isFrom; timeScale = config.timeScale; _onInit = config.onInitHandler; _onBegin = config.onBeginHandler; _onIterationStart = config.onIterationStartHandler; _onUpdate = config.onUpdateHandler; _onIterationEnd = config.onIterationEndHandler; _onComplete = config.onCompleteHandler; if (config.isPaused) { state = GoTweenState.Paused; } // if onComplete is passed to the constructor it wins. it is left as the final param to allow an inline Action to be // set and maintain clean code (Actions always try to be the last param of a method) if (onComplete != null) { _onComplete = onComplete; } // add all our properties for (var i = 0; i < config.tweenProperties.Count; ++i) { var tweenProp = config.tweenProperties[i]; // if the tween property is initialized already it means it is being reused so we need to clone it if (tweenProp.isInitialized) { tweenProp = tweenProp.clone(); } addTweenProperty(tweenProp); } // calculate total duration if (iterations < 0) { totalDuration = float.PositiveInfinity; } else { totalDuration = iterations * duration; } }
internal static GoTweenChain animateJellyInfinite( this Transform transform, float time, float value, GoEaseType ease = GoEaseType.QuadInOut ) { GoTweenChain chain = new GoTweenChain (); Vector3 scaleAtStart = transform.localScale; Vector3 target = new Vector3 ( scaleAtStart.x - value, scaleAtStart.y + value, scaleAtStart.z ); transform.localScale = target; target = new Vector3 ( scaleAtStart.x + value, scaleAtStart.y - value, scaleAtStart.z ); chain.append ( transform.scaleTo ( time, target ).eases ( ease ) ); target = new Vector3 ( scaleAtStart.x - value, scaleAtStart.y + value, scaleAtStart.z ); chain.append ( transform.scaleTo ( time, target ).eases ( ease ) ); chain.loopCount = -1; chain.play (); return chain; }
public static GoTween MakeTweenScale( Transform TheTransform, Vector3 Scale, float MoveTime, bool IsLocal = false, GoEaseType Ease = GoEaseType.Linear, VoidDelegate OnCompleteFunction = null ) { GoTweenConfig Config = new GoTweenConfig(); Config.addTweenProperty(new ScaleTweenProperty(Scale, false)); Config.setEaseType(Ease); if(OnCompleteFunction != null){ Config.onComplete(c => { OnCompleteFunction(); }); } GoTween NewTween = new GoTween(TheTransform, MoveTime, Config); Go.addTween(NewTween); return NewTween; }
public IEnumerator Flip(string name, bool horizontal = true, bool vertical = false, float duration = 1f, GoEaseType type = GoEaseType.QuadInOut) { var go = GameObject.Find(name); if (!go) { yield return(null); } else { var ended = false; var handler = ElementHandlerFactory.Instance.CreateHandlerFor(go); Go.addTween(new GoTween(handler, duration, new GoTweenConfig() .setEaseType(type) .vector3Prop("Scale", new Vector3( (horizontal ? -1 : 1) * handler.Scale.x, (vertical ? -1 : 1) * handler.Scale.y, transform.localScale.z)), (tween) => ended = true )); yield return(new WaitUntil(() => ended)); } }
internal static GoTweenChain animateJellyInfinite(this Transform transform, float time, float value, GoEaseType ease = GoEaseType.QuadInOut) { GoTweenChain chain = new GoTweenChain(); Vector3 scaleAtStart = transform.localScale; Vector3 target = new Vector3(scaleAtStart.x - value, scaleAtStart.y + value, scaleAtStart.z); transform.localScale = target; target = new Vector3(scaleAtStart.x + value, scaleAtStart.y - value, scaleAtStart.z); chain.append(transform.scaleTo(time, target).eases(ease)); target = new Vector3(scaleAtStart.x - value, scaleAtStart.y + value, scaleAtStart.z); chain.append(transform.scaleTo(time, target).eases(ease)); chain.loopCount = -1; chain.play(); return(chain); }
/// <summary> /// fetches the actual function for the given ease type /// </summary> public static Func <float, float, float, float, float> easeFunctionForType(GoEaseType easeType) { switch (easeType) { case GoEaseType.Linear: return(GoEaseLinear.EaseNone); case GoEaseType.BackIn: return(GoEaseBack.EaseIn); case GoEaseType.BackOut: return(GoEaseBack.EaseOut); case GoEaseType.BackInOut: return(GoEaseBack.EaseInOut); case GoEaseType.BounceIn: return(GoEaseBounce.EaseIn); case GoEaseType.BounceOut: return(GoEaseBounce.EaseOut); case GoEaseType.BounceInOut: return(GoEaseBounce.EaseInOut); case GoEaseType.CircIn: return(GoEaseCircular.EaseIn); case GoEaseType.CircOut: return(GoEaseCircular.EaseOut); case GoEaseType.CircInOut: return(GoEaseCircular.EaseInOut); case GoEaseType.CubicIn: return(GoEaseCubic.EaseIn); case GoEaseType.CubicOut: return(GoEaseCubic.EaseOut); case GoEaseType.CubicInOut: return(GoEaseCubic.EaseInOut); case GoEaseType.ElasticIn: return(GoEaseElastic.EaseIn); case GoEaseType.ElasticOut: return(GoEaseElastic.EaseOut); case GoEaseType.ElasticInOut: return(GoEaseElastic.EaseInOut); case GoEaseType.Punch: return(GoEaseElastic.Punch); case GoEaseType.ExpoIn: return(GoEaseExponential.EaseIn); case GoEaseType.ExpoOut: return(GoEaseExponential.EaseOut); case GoEaseType.ExpoInOut: return(GoEaseExponential.EaseInOut); case GoEaseType.QuadIn: return(GoEaseQuadratic.EaseIn); case GoEaseType.QuadOut: return(GoEaseQuadratic.EaseOut); case GoEaseType.QuadInOut: return(GoEaseQuadratic.EaseInOut); case GoEaseType.QuartIn: return(GoEaseQuartic.EaseIn); case GoEaseType.QuartOut: return(GoEaseQuartic.EaseOut); case GoEaseType.QuartInOut: return(GoEaseQuartic.EaseInOut); case GoEaseType.QuintIn: return(GoEaseQuintic.EaseIn); case GoEaseType.QuintOut: return(GoEaseQuintic.EaseOut); case GoEaseType.QuintInOut: return(GoEaseQuintic.EaseInOut); case GoEaseType.SineIn: return(GoEaseSinusoidal.EaseIn); case GoEaseType.SineOut: return(GoEaseSinusoidal.EaseOut); case GoEaseType.SineInOut: return(GoEaseSinusoidal.EaseInOut); } return(GoEaseLinear.EaseNone); }
public IEnumerator FadeIn(string name, Vector3 movement, Vector3 sizeChange, float duration = 2f, GoEaseType type = GoEaseType.QuintInOut) { var go = GameObject.Find(name); if (!go) { yield return(null); } else { var ended = false; var handler = ElementHandlerFactory.Instance.CreateHandlerFor(go); handler.Position = handler.Position - movement; handler.Scale = handler.Scale - sizeChange; Go.addTween(new GoTween(handler, duration, new GoTweenConfig() .setEaseType(type) .vector3Prop("Position", movement, true) .vector3Prop("Scale", sizeChange, true) .floatProp("Transparency", 1), (tween) => ended = true )); yield return(new WaitUntil(() => ended)); } }
internal static GoTweenChain animateJelly( this Transform transform, float time, float value, int repeatCount = 1, GoEaseType ease = GoEaseType.QuadInOut ) { Vector3 scaleAtStart = transform.localScale; GoTweenChain chain = new GoTweenChain (); for ( int i = repeatCount; i > 0; i-- ) { float factor = ( (float)i ) / repeatCount; Vector3 target = new Vector3 ( scaleAtStart.x + ( value * factor ), scaleAtStart.y - ( value * factor ), scaleAtStart.z ); chain.append ( transform.scaleTo ( time * factor, target ).eases ( ease ) ); target = new Vector3 ( scaleAtStart.x - ( value * factor ), scaleAtStart.y + ( value * factor ), scaleAtStart.z ); chain.append ( transform.scaleTo ( time * factor, target ).eases ( ease ) ); } chain.append ( transform.scaleTo ( time / repeatCount, scaleAtStart ).eases ( ease ) ); chain.play (); return chain; }
/// <summary> /// initializes a new instance and sets up the details according to the config parameter /// </summary> public GoTween( object target, float duration, GoTweenConfig config, Action<AbstractGoTween> onComplete = null ) { // all tweens must be intialized to have a duration greater than zero. keep in mind that this will ensure // the tween occurs over two frames: the initialized value, and the final value. if you are looking for a // tween to reach the end of it's tween immediately, be sure to call complete() on it after creation. if( duration <= 0 ) { duration = float.Epsilon; Debug.LogError( "tween duration must be greater than 0. coerced to float.Epsilon." ); } // default to removing on complete autoRemoveOnComplete = true; // allow events by default allowEvents = true; // setup callback bools _didInit = false; _didBegin = false; // flag the onIterationStart event to fire. // as long as goTo is not called on this tween, the onIterationStart event will fire // as soon as the delay, if any, is completed. _fireIterationStart = true; this.target = target; this.targetType = target.GetType(); this.duration = duration; // copy the TweenConfig info over id = config.id; delay = config.delay; loopType = config.loopType; iterations = config.iterations; _easeType = config.easeType; easeCurve = config.easeCurve; updateType = config.propertyUpdateType; isFrom = config.isFrom; timeScale = config.timeScale; _onInit = config.onInitHandler; _onBegin = config.onBeginHandler; _onIterationStart = config.onIterationStartHandler; _onUpdate = config.onUpdateHandler; _onIterationEnd = config.onIterationEndHandler; _onComplete = config.onCompleteHandler; if( config.isPaused ) state = GoTweenState.Paused; // if onComplete is passed to the constructor it wins. it is left as the final param to allow an inline Action to be // set and maintain clean code (Actions always try to be the last param of a method) if( onComplete != null ) _onComplete = onComplete; // add all our properties for( var i = 0; i < config.tweenProperties.Count; ++i ) { var tweenProp = config.tweenProperties[i]; // if the tween property is initialized already it means it is being reused so we need to clone it if( tweenProp.isInitialized ) tweenProp = tweenProp.clone(); addTweenProperty( tweenProp ); } // calculate total duration if( iterations < 0 ) totalDuration = float.PositiveInfinity; else totalDuration = iterations * duration; }
/// <summary> /// sets the ease type for the Tween /// </summary> public GoTweenConfig setEaseType(GoEaseType easeType) { this.easeType = easeType; return(this); }
internal static GoTween eases(this GoTween tween, GoEaseType ease) { tween.easeType = ease; return(tween); }