Code Monkey home page Code Monkey logo

Comments (6)

prime31 avatar prime31 commented on July 21, 2024 1

@sathyarajshetigar there will a small allocation each time you call that method. If you are calling it every frame definitely cache the tween. If you are only calling it every so often no need to bother caching it.

from gokit.

prime31 avatar prime31 commented on July 21, 2024

GoKit is pretty extensible so you can add in pretty much anything you want the fits into the idea of tweening or even just having a tick method called. For example, below is a quick and dirty implementation of an Action tween that can be called like this:

Go.to( cube, 4, new GoTweenConfig() )
    .addTweenProperty( new ActionProperty( val => Debug.Log( val ) ) );
public class ActionProperty : AbstractTweenProperty
{
	System.Action<float> _setter;
	
	float _startValue;
	float _endValue;


	public ActionProperty( System.Action<float> setter, float startValue = 0, float endValue = 1 )
	{
		_setter = setter;
		_startValue = startValue;
		_endValue = endValue;
	}


	public override void prepareForUse()
	{}


	public override void tick( float totalElapsedTime )
	{
		var easedValue = _easeFunction( totalElapsedTime, _startValue, _endValue, _ownerTween.duration );
		_setter( easedValue );
	}
}

from gokit.

sathyarajshetigar avatar sathyarajshetigar commented on July 21, 2024

Hi,
I tried using the code and it does not work as expected. Here is the code. All I get is the start value

public class GoFloatProperty : AbstractTweenProperty
{
private Action _setter;

private float _startValue;
private float _endValue;

public GoFloatProperty(float startValue, float endValue, Action<float> setter)
{
    _setter = setter;
    _startValue = startValue;
    _endValue = endValue;
}

public override void prepareForUse()
{
}

public override void tick(float totalElapsedTime)
{
    float easedValue = _easeFunction(totalElapsedTime, _startValue, _endValue, _ownerTween.duration);
    _setter(easedValue);

    UnityEngine.Debug.Log("Tick " + easedValue + " totalElapsedTime " + totalElapsedTime +
        " _ownerTween.duration " + _ownerTween.duration + " _startValue " + _startValue + " _endValue " + _endValue);
}

}

//and used it like this
Go.to(this, 1, new GoTweenConfig().addTweenProperty(new GoFloatProperty(100.0f, 0.0f, val => Debug.Log(val))));
//It prints only 100,100,100.........
Did I miss anything?

from gokit.

prime31 avatar prime31 commented on July 21, 2024

Try out the ActionTweenProperty class that I just pushed to the repo. It will work for both forwards and backwards tweens.

from gokit.

sathyarajshetigar avatar sathyarajshetigar commented on July 21, 2024

Awesome. That did work. Thanks a ton

from gokit.

sathyarajshetigar avatar sathyarajshetigar commented on July 21, 2024

Quick question. Does AbstractTweenProperty instance allocate memory?

I use the following code every time "ShowToast" Method is called

Go.to(this, TWEENSPEED, new GoTweenConfig().addTweenProperty(new FloatActionTweenProperty(1, 0, val =>
{
toastScreenCanvasGroup.alpha = val;
}))).setOnCompleteHandler((bt) =>
{
toastScreen.SetActive(false);
});

Is it fine this way or should I assign it a variable and use it to play the next time? Is there any performance difference?

from gokit.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.