Example #1
0
    private void transition(int step)
    {
        // TODO: remap step from 0-steps into 0-1
        float linearStep = (float)step / (steps - 1);
        float e = EasingFX.Ease(linearStep, acceleration, easingType);
        float newX = 0f, newY = 0f;

        switch (direction)
        {
        case Direction.Up:
            newX = startPos.x + offsetX; newY = startPos.y + offsetY + e;
            // don't exceed the final position
            if (newY > finalPos.y)
            {
                newY = finalPos.y;
            }
            break;

        case Direction.Down:
            newX = startPos.x + offsetX; newY = startPos.y + offsetY - e;
            // don't exceed the final position
            if (newY < finalPos.y)
            {
                newY = finalPos.y;
            }
            break;

        case Direction.Left:
            newX = startPos.x + offsetX - e; newY = startPos.y + offsetY;
            // don't exceed the final position
            if (newX < finalPos.x)
            {
                newX = finalPos.x;
            }
            break;

        case Direction.Right:
            newX = startPos.x + offsetX + e; newY = startPos.y + offsetY;
            // don't exceed the final position
            if (newX > finalPos.x)
            {
                newX = finalPos.x;
            }
            break;
        }

        switch (elem)
        {
        case Element.TRANSFORM:
            Vector3 pos = transform.localPosition;
            pos.x = newX;
            pos.y = newY;
            transform.localPosition = pos;
            break;

            /*case Element.GUI_TEXT:
             *      Vector2 pOffset = guiText.pixelOffset;
             *      pOffset.x = newX;
             *      pOffset.y = newY;
             *      guiText.pixelOffset = pOffset;
             *      break;
             * case Element.GUI_TEXTURE:
             *      Rect pInset = guiTexture.pixelInset;
             *      pInset.x = newX;
             *      pInset.y = newY;
             *      guiTexture.pixelInset = pInset;
             *      break;*/
        }
    }
Example #2
0
    private void prepareTransition()
    {
        if (Mathf.Abs(steps) < 2)
        {
            steps = (int)Mathf.Sign(steps) * 2;
        }

        // the final position is the current one
        finalPos.Set(transform.localPosition.x, transform.localPosition.y);

        if (elem == Element.TRANSFORM)
        {
            startPos.Set(transform.localPosition.x + startOffsetTransform.x, transform.localPosition.y + startOffsetTransform.y);
        }

        /*else if (elem == Element.GUI_TEXT)
         *      startPos.Set(guiText.pixelOffset.x + startOffsetTransform.x, guiText.pixelOffset.y + startOffsetTransform.y);
         * else if (elem == Element.GUI_TEXTURE)
         *      startPos.Set(guiTexture.pixelInset.x + startOffsetTransform.x, guiTexture.pixelInset.y + startOffsetTransform.y);*/

        // calculate automatic offsets
        switch (_transition)
        {
        case Transition.FromCurrentPosition:
            offsetX = -EasingFX.Ease(0, acceleration, easingType);
            offsetY = -EasingFX.Ease(0, acceleration, easingType);
            break;

        case Transition.ToCurrentPosition:
            offsetX = -EasingFX.Ease(1, acceleration, easingType);
            offsetY = -EasingFX.Ease(1, acceleration, easingType);
            break;
        }

        // fix offsets
        switch (direction)
        {
        case Direction.Up:
            offsetX = 0;
            break;

        case Direction.Down:
            offsetX = 0;
            offsetY = -offsetY;
            break;

        case Direction.Left:
            offsetX = -offsetX;
            offsetY = 0;
            break;

        case Direction.Right:
            offsetY = 0;
            break;
        }

        // set initial object position
        switch (elem)
        {
        case Element.TRANSFORM:
            Vector3 pos = transform.localPosition;
            pos.x = startPos.x + offsetX;
            pos.y = startPos.y + offsetY;
            transform.localPosition = pos;
            break;

            /*case Element.GUI_TEXT:
             *      Vector2 pOffset = guiText.pixelOffset;
             *      pOffset.x = startPos.x + offsetX;
             *      pOffset.y = startPos.y + offsetY;
             *      guiText.pixelOffset = pOffset;
             *      break;
             * case Element.GUI_TEXTURE:
             *      Rect pInset = guiTexture.pixelInset;
             *      pInset.x = startPos.x + offsetX;
             *      pInset.y = startPos.y + offsetY;
             *      guiTexture.pixelInset = pInset;
             *      break;*/
        }
    }