Basic animation iTween

It can be obtained on the official website: http://itween.pixelplacement.com/index.php

Let's try to simulate a small area for our tests.

First of all, connect iTween-package from the Asset store:  https://www.assetstore.unity3d.com/en/ , we should see something something like that:

Create a new scene with such content:

Cube - is the object that we are going to animate. Now we move on iTween. Create a new script component type C # at our facility. Fill method Start:

void Start()
{
        iTween.RotateFrom(gameObject, iTween.Hash("y", 90.0f, "time", 2.0f, "easetype", iTween.EaseType.easeInExpo));
        iTween.MoveFrom(gameObject, iTween.Hash("y", 3.5f, "time", 2.0f, "easetype", iTween.EaseType.easeInExpo));
        iTween.ShakePosition(Camera.main.gameObject, iTween.Hash("y", 0.3f, "time", 0.8f, "delay", 2.0f));
        iTween.ColorTo(gameObject, iTween.Hash("r", 1.0f, "g", 0.5f, "b", 0.4f, "delay", 1.5f, "time", 0.3f));
        iTween.ScaleTo(gameObject, iTween.Hash("y", 1.75f, "delay", 2.8f, "time", 2.0f));
        iTween.RotateBy(gameObject, iTween.Hash("x", 0.5f, "delay", 4.4f));
        iTween.MoveTo(gameObject, iTween.Hash("y", 1.5f, "delay", 5.8f));
        iTween.MoveTo(gameObject, iTween.Hash("y", 0.5f, "delay", 7.0f, "easetype", iTween.EaseType.easeInExpo));
        iTween.ScaleTo(gameObject, iTween.Hash("y", 1.0f, "delay", 7.0f));
        iTween.ShakePosition(Camera.main.gameObject, iTween.Hash("y", 0.3f, "time", 0.8f, "delay", 8.0f));
        iTween.ColorTo(gameObject, iTween.Hash("r", 0.165f, "g", 0.498f, "b", 0.729f, "delay", 8.5f, "time", 0.5f));

        iTween.CameraFadeAdd();
        iTween.CameraFadeTo(iTween.Hash("amount", 1.0f, "time", 2.0f, "delay", 10.0f));
}

Run and see the result.

Let's Let us examine the script line by line.

iTween.RotateFrom(gameObject, iTween.Hash("y", 90.0f, "time", 2.0f, "easetype", iTween.EaseType.easeInExpo));

Method RotateFrom used to rotate an object. Unlike RotateTo and RotateBy, RotateFrom used to initialize the specified rotation angle and rotate to their original condition. Method, like most others, has an overload. You can use a short or long version:

RotateFrom(GameObject target, Vector3 rotation, float time);
RotateFrom(GameObject target, Hashtable args);

We pass gameObject - an object that is the current script. In order not to write something like:

Hashtable args = new Hashtable();
args.Add(ââ¬Åyââ¬Â, 90.0f);
args.Add(ââ¬Åtimeââ¬Â, 2.0f);
args.Add(ââ¬Åeasetypeââ¬Â, iTween.EaseType.easeInExpo);

We use iTween.Hash - Express version of Hashtable. As we pointed arguments y = 90.0f, is equivalent (if x and z are zero, of course)

Quaternion.Euler( new Vector3(0f, 90.0f, 0f) )

The rotation, which begins our rotation.

time=2.0f

Time that should be spent for animation. There are similar argument called "speed", in his case does not indicate the time,  but
  the rate at which the animation will be held. The last argument, which we pointed it easetype = iTween.EaseType.easeInExpo. easetype waveform is to be used for interpolation. Here is a graphical representation of curves:

iTween.MoveFrom(gameObject, iTween.Hash("y", 3.5f, "time", 2.0f, "easetype", iTween.EaseType.easeInExpo)); 

Move From similar to the previous one, it should be understood simply used instead of the rotation movement.

iTween.ShakePosition(Camera.main.gameObject, iTween.Hash("y", 0.3f, "time", 0.8f, "delay", 2.0f));

ShakePosition used in this case in order to implement the "shaking" the camera. This method makes you move an object by decreasing amplitude, does not use interpolation, the object will appear at random points in the designated part of him. There is a new argument called "delay", it is quite important option animation is used to specify the number of seconds that must elapse before the start of the animation.

iTween.ColorTo(gameObject, iTween.Hash("r", 1.0f, "g", 0.5f, "b", 0.4f, "delay", 1.5f, "time", 0.3f));

Color To smoothly change the color of an object over time.

iTween.ScaleTo(gameObject, iTween.Hash("y", 1.75f, "delay", 2.8f, "time", 2.0f));

ScaleTo, changes the size of the object.

iTween.RotateBy(gameObject, iTween.Hash("x", 0.5f, "delay", 4.4f));

RotateBy reminds RotateFrom, necessary in cases where the object you want to deploy more than 360 degrees (although in this case we could have done by RotateTo). Suppose we have indicated z = 2.0f, it would mean that the object must turn twice around the Z axis for a certain period of time.

iTween.MoveTo(gameObject, iTween.Hash("y", 1.5f, "delay", 5.8f));
iTween.MoveTo(gameObject, iTween.Hash("y", 0.5f, "delay", 7.0f, "easetype", iTween.EaseType.easeInExpo));

MoveTo, probably, the main method of the whole class iTween. He moves the object to the specified coordinates in the allotted time. The interpolation is based on all the same easetype, which you already know.

iTween.CameraFadeAdd();
iTween.CameraFadeTo(iTween.Hash("amount", 1.0f, "time", 2.0f, "delay", 10.0f));

CameraFadeAdd creates a new object that is used to simulate the blackout. The depth varies from the current value of the specified arguments. The following overload:

CameraFadeAdd()
CameraFadeAdd(Texture2D texture)
CameraFadeAdd(Texture2D texture, int depth)

If no Texture2D, will be used black color.
From what I have described, there are few more important things. For example, in the arguments, you can specify the method that will be invoked upon the occurrence of some event. Let's say:

public class iTweenController : MonoBehaviour
{
    int clbkN = 0;
    GUIStyle style;

    void Awake()
    {
        style = new GUIStyle();
        style.fontSize = 60;
    }

    void Start()
    {
        iTween.MoveTo(gameObject, iTween.Hash("position", new Vector3(5.0f, 1.0f, 0.0f), "oncomplete", "myClbk",
            "loopType", iTween.LoopType.loop, "speed", 2.0f));
    }

    void myClbk()
    {
        clbkN++;
    }

    void OnGUI()
    {
        GUI.Label(new Rect(10, 10, 0, 0), "Callback # "+clbkN, style);
    }
}

We used a new method arguments MoveTo:

position = new Vector3(5.0f, 1.0f, 0.0f)

shorthand, relevant "x", 5.0f, "y", 1.0f, "z", 0.0f

oncomplete = "myClbk"

At the end of the animation (or iteration of the loop animation) method is called with the specified name.

loopType = iTween.LoopType.loop

Type animation. In this case, indicate the normal cycle, the animation will be played endlessly, at the beginning of each animation object will be moved to the starting position.

On this, perhaps, done. Thank you for your attention.

All data posted on the site represents accessible information that can be browsed and downloaded for free from the web.

http://habrahabr.ru/post/220837/

 

User replies

No replies yet