Categorieën: Alle - duration - animation

door Mike Ton 10 jaren geleden

1054

HoTween

The document describes the functionality and usage of HOTween's OverwriteManager, which manages the overwriting of running animations with new ones. This feature is not active by default and requires explicit activation and enabling through specific HOTween methods.

HoTween

HoTween

API

HOTween
HOTween.To (From)

HOTween.To will return a Tweener. You can either store it for direct use (or to add it to a Sequence), or you can ignore it and just let it run. Unless you expressly choose otherwise, once an animation is complete the Tweener will be destroyed.

HOTween.To(target, duration, parameters)

HOTween.To(target, duration, propName, endValue, isRelative, easeType, delay)

HOTween.To(target, duration, propName, endValue, isRelative)

HOTween.To(target, duration, propName, endValue)

OverwriteManager

HOTween's OverwriteManager works in the background, and automatically checks if a running tween needs to be overwritten by a newly started one. It's awesome and you should use it :)

OverwriteManager is deactivated and disabled by default. You have to activate it via HOTween.Init, and enable it via HOTween.EnableOverwriteManager().

disable

You can disable it again by calling: HOTween.DisableOverwriteManager().

Even when disabled, a small part of the OverwriteManager will still run in the background (if it was activated), so that when you enable it it's ready to take control.

HOTween.DisableOverwriteManager();

enable

HOTween.EnableOverwriteManager();

HOTween.Init(false, false, true);

HOTween.Init(permanentInstance,renameInstanceToCountTweens,allowOverwriteManager)

Example

HOTweenDemoBrain.cs
void Cube2StepComplete(){}

Debug.Log("HOTween: Cube 2 Step Complete");

void OnGUI(){}

GUILayout.Label("Float tween: " + SampleFloat);

GUILayout.Label("String tween: " + SampleString);

// Here we show the sample string and float being tweened

void Start(){}

// SEQUENCE CREATION

// Here you'll see how to create a Sequence,

// which stores your tweens in a timeline-like way

// Create a Sequence with cube3, which will rotate it,

// then move it upwards, the rotate it again,

// all the while changing the alpha of its material's color

// (which can be done since the cube uses a transparent material).

// The Sequence will also be set to loop.

// Note that Sequences don't start automatically, so you'll have to call Play().

(sequence)

(play)

sequence.Play();

// Start the sequence animation

(insert)

sequence.Insert(sequence.duration * 0.5f, HOTween.To(CubeTrans3.renderer.material, sequence.duration * 0.5f, new TweenParms().Prop("color", colorTo)));

// "Insert" lets you insert a tween where you want

// (in this case we're having it start at half the sequence and last until the end)

(append)

sequence.Append(HOTween.To(CubeTrans3, 1, new TweenParms().Prop("rotation", new Vector3(0, 360, 0))));

sequence.Append(HOTween.To(CubeTrans3, 1, new TweenParms().Prop("position", new Vector3(0, 6, 0), true)));

sequence.Append(HOTween.To(CubeTrans3, 1, new TweenParms().Prop("rotation", new Vector3(360, 0, 0))));

// "Append" will add a tween after the previous one/s have completed

Sequence sequence = new Sequence(new SequenceParms().Loops(-1, LoopType.Yoyo));

Color colorTo = CubeTrans3.renderer.material.color;

colorTo.a = 0;

(TweenParms)

// Tween the sample floating point number while creating TweenParms first,

// and then assigning it to HOTween.

HOTween.To(this, 3, tweenParms);

TweenParms tweenParms = new TweenParms().Prop("SampleFloat", 27.5f).Ease(EaseType.Linear).Loops(-1, LoopType.Yoyo);

HOTween.To(this, 3, new TweenParms().Prop("SampleString", "Hello I'm a sample tweened string").Ease(EaseType.Linear).Loops(-1, LoopType.Yoyo));

// The result will be shown using OnGUI

// Tween the sample string using full mode with parameters and without linebreaks.

HOTween.To(CubeTrans2, 3, new TweenParms()

);

.OnStepComplete(Cube2StepComplete)

// OnComplete callback

.Ease(EaseType.EaseInOutQuad)

// Ease

.Loops(-1, LoopType.Yoyo)

//-1 === Infinite, yoyo loops

.Prop("rotation", new Vector3(0, 1024, 0), true)

// Relative rotation tween (this way rotations higher than 360 can be applied)

.Prop("position", new Vector3(0, 6, 0), true)

// Position tween (set as relative)

HOTween.To(CubeTrans1, 4, "position", new Vector3(-3, 6, 0));

// Tween transform with anim over 4 seconds

HOTween.Init(true, true, true);

// HOTWEEN INITIALIZATION

// Must be done only once, before the creation of your first tween

// (you can skip this if you want, and HOTween will be initialized automatically

// when you create your first tween - using default values)

var

public

float

SampleFloat = 0.0f;

string

SampleString

Transform

CubeTrans3

CubeTrans2

CubeTrans1