Exemple #1
0
    protected override void createAnimations()
    {
        // Set up left animation
        leftAnim            = new UVAnimation();
        leftAnim.name       = "EighthRest Left Animation";
        leftAnim.loopCycles = -1;
        leftAnim.framerate  = 24;

        leftAnim.BuildUVAnim(new Vector2(0f, 12f / numRows), cellSize, 18, 1, 18, 24);
        sprite.AddAnimation(leftAnim);


        // Set up right animation
        rightAnim            = new UVAnimation();
        rightAnim.name       = "EighthRest Right Animation";
        rightAnim.loopCycles = -1;
        rightAnim.framerate  = 24;

        rightAnim.BuildUVAnim(new Vector2(0f, 11f / numRows), cellSize, 18, 1, 18, 24);
        sprite.AddAnimation(rightAnim);

        // Starting direction
        EighthRest er = this.gameObject.GetComponent(typeof(EighthRest)) as EighthRest;

        if (er.isMovingRight)
        {
            sprite.PlayAnim(rightAnim);
        }
        else
        {
            sprite.PlayAnim(leftAnim);
        }
    }
    void Start()
    {
        var transTest = new GameObject("MaterialTransform_"+ this.name);

        transTest.transform.position = transform.TransformPoint(transTest.transform.position);
        transTest.transform.position += new Vector3(0, 0, _depthLayer) * _depthScaleFactor;

        transTest.transform.localScale = new Vector3(_scaleX, _scaleY, 0.5f);

        _sprite = _spriteManager.AddSprite(transTest, _width, _height, 0, (int)_cellSize.x-1, (int)_cellSize.x, (int)_cellSize.x, false);

        for (var i = 0; i < _anims.Length; i++)
        {
            var anim = new UVAnimation();

            var firstFrameCoords = new Vector2(
                //_anims[i].firstFrame.x * _cellSize.x,
                0,
                _anims[i].firstFrame.y * _cellSize.y);

            var firstFrame = _spriteManager.PixelCoordToUVCoord(firstFrameCoords);
            var cellSize = _spriteManager.PixelSpaceToUVSpace(_cellSize);
            anim.BuildUVAnim(firstFrame, cellSize, _anims[i].columns, _anims[i].rows, _anims[i].totalCells, _anims[i].fps, (int)(_anims[i].firstFrame.x));
            anim.name = _anims[i].name;
            anim.loopCycles = _anims[i].loopCycles;
            _sprite.AddAnimation(anim);
        }

        _currentAnimation = _defaultAnimation;
        _sprite.PlayAnim(_defaultAnimation);
    }
Exemple #3
0
    public void Init()
    {
        bool wasDeactivated = false;

        if (sprite != null)
        {
            // See if we need to activate our sprite
            // to work with it:
            if (!sprite.gameObject.active)
            {
                wasDeactivated           = true;
                sprite.gameObject.active = true;
            }

            anim = sprite.GetAnim(animName);

            if (anim == null)
            {
                Debug.LogError("SuperSprite error: No animation by the name of \"" + animName + "\" was found on sprite \"" + sprite.name + "\". Please verify the spelling and capitalization of the name, including any extra spaces, etc.");
            }

            if (wasDeactivated)
            {
                sprite.gameObject.active = false;
            }
        }
    }
    // Use this for initialization
    void Start()
    {
        sprite = spriteManager.AddSprite(gameObject, width, height, 0, 127, 128, 128, false);

        // Create and setup anims
        UVAnimation anim       = new UVAnimation();
        var         firstFrame = spriteManager.PixelCoordToUVCoord(new Vector2(0, 127));
        var         cellSize   = spriteManager.PixelSpaceToUVSpace(new Vector2(128, 128));

        anim.BuildUVAnim(firstFrame, cellSize, 8, 8, 13, 15);
        anim.name       = "Idle";
        anim.loopCycles = -1;

        sprite.AddAnimation(anim);

        anim       = new UVAnimation();
        firstFrame = spriteManager.PixelCoordToUVCoord(new Vector2(0, 127));
        cellSize   = spriteManager.PixelSpaceToUVSpace(new Vector2(128, 128));
        anim.BuildUVAnim(firstFrame, cellSize, 8, 8, 13, 30);
        anim.name       = "Arm";
        anim.loopCycles = -1;

        sprite.AddAnimation(anim);

        anim       = new UVAnimation();
        firstFrame = spriteManager.PixelCoordToUVCoord(new Vector2(256, 383));
        cellSize   = spriteManager.PixelSpaceToUVSpace(new Vector2(128, 128));
        anim.BuildUVAnim(firstFrame, cellSize, 8, 8, 8, 30);
        anim.name       = "Explode";
        anim.loopCycles = 1;

        sprite.AddAnimation(anim);

        sprite.PlayAnim("Idle");
    }
    public override void Start()
    {
        base.Start();

        sprite = spriteManager.AddSprite(gameObject, width, height, 0, 127, 128, 128, false);

        // Create and setup anims
        UVAnimation anim       = new UVAnimation();
        var         firstFrame = spriteManager.PixelCoordToUVCoord(new Vector2(0, 127));
        var         cellSize   = spriteManager.PixelSpaceToUVSpace(new Vector2(128, 128));

        anim.BuildUVAnim(firstFrame, cellSize, 8, 8, 14, 15);
        anim.name       = "Idle";
        anim.loopCycles = -1;

        sprite.AddAnimation(anim);

        anim       = new UVAnimation();
        firstFrame = spriteManager.PixelCoordToUVCoord(new Vector2(0, 383));
        cellSize   = spriteManager.PixelSpaceToUVSpace(new Vector2(128, 128));
        anim.BuildUVAnim(firstFrame, cellSize, 8, 8, 16, 15);
        anim.name       = "Die";
        anim.loopCycles = 0;

        sprite.AddAnimation(anim);

        sprite.PlayAnim("Idle");

        dolphin = GameObject.Find("DolphinSprite");
        Util.Assert(dolphin != null);
    }
    private IEnumerator SetUVanimationState(UVAnimation uva, float delay, float speedX, float speedY)
    {
        yield return(new WaitForSeconds(delay));

        uva.SpeedX = speedX;
        uva.SpeedY = speedY;
    }
Exemple #7
0
	public void Init()
	{
		bool wasDeactivated = false;

		if (sprite != null)
		{
			// See if we need to activate our sprite
			// to work with it:
#if UNITY_4_0 || UNITY_4_1 || UNITY_4_2 || UNITY_4_3 || UNITY_4_4 || UNITY_4_5 || UNITY_4_6 || UNITY_4_7 || UNITY_4_8 || UNITY_4_9
			if (!sprite.gameObject.activeInHierarchy)
			{
				wasDeactivated = true;
				sprite.gameObject.SetActive(true);
			}
#else
			if (!sprite.gameObject.active)
			{
				wasDeactivated = true;
				sprite.gameObject.active = true;
			}
#endif

			anim = sprite.GetAnim(animName);

			if (anim == null)
				Debug.LogError("SuperSprite error: No animation by the name of \"" + animName + "\" was found on sprite \"" + sprite.name + "\". Please verify the spelling and capitalization of the name, including any extra spaces, etc.");

			if (wasDeactivated)
#if UNITY_4_0 || UNITY_4_1 || UNITY_4_2 || UNITY_4_3 || UNITY_4_4 || UNITY_4_5 || UNITY_4_6 || UNITY_4_7 || UNITY_4_8 || UNITY_4_9
				sprite.gameObject.SetActive(false);
#else
				sprite.gameObject.active = false;
#endif
		}
	}
    // Use this for initialization
    void Start()
    {
        sprite = spriteManager.AddSprite(gameObject, width, height, 0, 511, 512, 512, false);

        // Create and setup anims
        UVAnimation anim = new UVAnimation();
        var firstFrame = spriteManager.PixelCoordToUVCoord(new Vector2(0, 511));
        var cellSize = spriteManager.PixelSpaceToUVSpace(new Vector2(512, 512));
        anim.BuildUVAnim(firstFrame, cellSize, 8, 8, 16, 15);
        anim.name = "Idle";
        anim.loopCycles = -1;

        sprite.AddAnimation(anim);

        anim = new UVAnimation();
        firstFrame = spriteManager.PixelCoordToUVCoord(new Vector2(0, 1023));
        cellSize = spriteManager.PixelSpaceToUVSpace(new Vector2(512, 512));
        anim.BuildUVAnim(firstFrame, cellSize, 8, 8, 19, 15);
        anim.name = "Surprise";
        anim.loopCycles = 0;

        sprite.AddAnimation(anim);

        sprite.PlayAnim("Idle");
    }
 public void PlayAnimInReverse(UVAnimation anim, int frame)
 {
     this.curAnim = anim;
     this.curAnim.Reset();
     this.curAnim.PlayInReverse();
     this.curAnim.SetCurrentFrame(frame + 1);
     anim.framerate             = Mathf.Max(0.0001f, anim.framerate);
     this.timeBetweenAnimFrames = 1f / anim.framerate;
     this.timeSinceLastFrame    = this.timeBetweenAnimFrames;
     if (anim.GetFrameCount() > 1)
     {
         this.StepAnim(0f);
         if (!this.animating)
         {
             base.AddToAnimatedList();
         }
     }
     else
     {
         if (this.animCompleteDelegate != null)
         {
             this.animCompleteDelegate(this);
         }
         this.StepAnim(0f);
     }
 }
Exemple #10
0
 public void setData(UVAnimation e)
 {
     bInitialized = false;
     data         = e;
     getStoredData();
     bInitialized = true;
 }
Exemple #11
0
    //Plays the animation.
    void Play()
    {
        animationTimer -= Time.deltaTime;                                                                     // First off, reduce animationTimer to check if we should switch frames.

        if (animationTimer < 0)                                                                               // If this timer gets under 0 secs
        {
            currentFrame += 1;                                                                                // Start by increasing currentFrame value
            if (currentFrame < currentAnimation.frames)                                                       // Check if there are more frames after current one
            {
                SetFramedImage();                                                                             // If yes, set the next frame image
                animationTimer = currentAnimation.frameDuration;                                              // and reset animationTimer to wait for next frame
            }
            else                                                                                              // If the current frame was the last one
            {
                if (currentAnimation.nextAnimation == "starting" || currentAnimation.nextAnimation == "none") // Reset to starting frame
                {
                    SetSingleImage(startingHorizontalCell, startingVerticalCell);
                }
                else if (string.IsNullOrEmpty(currentAnimation.nextAnimation) || currentAnimation.nextAnimation == "stop")                              // Stop the animation and keep it's last frame
                {
                    currentAnimation = null;
                }
                else if (currentAnimation.nextAnimation == currentAnimation.name || currentAnimation.nextAnimation == "loop")                   // Loop the same animation
                {
                    ResetAnimation();
                }
                else                                                                                                                                                                                                                                    // Start another animation
                {
                    SetAnimation(currentAnimation.nextAnimation);
                }
            }
        }
    }
Exemple #12
0
    // Use this for initialization
    public override void Start()
    {
        base.Start();

        GetComponent <SimpleFollow>().enabled = false;
        sprite = spriteManager.AddSprite(gameObject, width, height, 0, 127, 128, 128, false);

        // Create and setup anims
        UVAnimation anim       = new UVAnimation();
        var         firstFrame = spriteManager.PixelCoordToUVCoord(new Vector2(0, 127));
        var         cellSize   = spriteManager.PixelSpaceToUVSpace(new Vector2(128, 128));

        anim.BuildUVAnim(firstFrame, cellSize, 8, 8, 14, 15);
        anim.name       = "Idle";
        anim.loopCycles = -1;

        sprite.AddAnimation(anim);

        anim       = new UVAnimation();
        firstFrame = spriteManager.PixelCoordToUVCoord(new Vector2(0, 383));
        cellSize   = spriteManager.PixelSpaceToUVSpace(new Vector2(128, 128));
        anim.BuildUVAnim(firstFrame, cellSize, 8, 8, 16, 15);
        anim.name       = "Die";
        anim.loopCycles = 0;

        sprite.AddAnimation(anim);

        sprite.PlayAnim("Idle");
    }
    // Use this for initialization
    public override void Start()
    {
        base.Start();

        GetComponent<SimpleFollow>().enabled = false;
        sprite = spriteManager.AddSprite(gameObject, width, height, 0, 127, 128, 128, false);

        // Create and setup anims
        UVAnimation anim = new UVAnimation();
        var firstFrame = spriteManager.PixelCoordToUVCoord(new Vector2(0, 127));
        var cellSize = spriteManager.PixelSpaceToUVSpace(new Vector2(128, 128));
        anim.BuildUVAnim(firstFrame, cellSize, 8, 8, 14, 15);
        anim.name = "Idle";
        anim.loopCycles = -1;

        sprite.AddAnimation(anim);

        anim = new UVAnimation();
        firstFrame = spriteManager.PixelCoordToUVCoord(new Vector2(0, 383));
        cellSize = spriteManager.PixelSpaceToUVSpace(new Vector2(128, 128));
        anim.BuildUVAnim(firstFrame, cellSize, 8, 8, 16, 15);
        anim.name = "Die";
        anim.loopCycles = 0;

        sprite.AddAnimation(anim);

        sprite.PlayAnim("Idle");
    }
    public override void Start()
    {
        base.Start();

        sprite = spriteManager.AddSprite(gameObject, width, height, 0, 127, 128, 128, false);

        // Create and setup anims
        UVAnimation anim = new UVAnimation();
        var firstFrame = spriteManager.PixelCoordToUVCoord(new Vector2(0, 127));
        var cellSize = spriteManager.PixelSpaceToUVSpace(new Vector2(128, 128));
        anim.BuildUVAnim(firstFrame, cellSize, 8, 8, 14, 15);
        anim.name = "Idle";
        anim.loopCycles = -1;

        sprite.AddAnimation(anim);

        anim = new UVAnimation();
        firstFrame = spriteManager.PixelCoordToUVCoord(new Vector2(0, 383));
        cellSize = spriteManager.PixelSpaceToUVSpace(new Vector2(128, 128));
        anim.BuildUVAnim(firstFrame, cellSize, 8, 8, 16, 15);
        anim.name = "Die";
        anim.loopCycles = 0;

        sprite.AddAnimation(anim);

        sprite.PlayAnim("Idle");

        dolphin = GameObject.Find("DolphinSprite");
        Util.Assert(dolphin != null);
    }
 public void DoAnim(UVAnimation anim)
 {
     if (this.curAnim != anim || !this.animating)
     {
         this.PlayAnim(anim);
     }
 }
Exemple #16
0
 /// <summary>
 /// Plays the specified animation only if it
 /// is not already playing.
 /// </summary>
 /// <param name="anim">Reference to the animation to play.</param>
 public void DoAnim(UVAnimation anim)
 {
     if (curAnim != anim || !animating)
     {
         PlayAnim(anim);
     }
 }
Exemple #17
0
    // Use this for initialization
    void Start()
    {
        agent      = gameObject.GetComponent <Seeker>();
        controller = gameObject.GetComponent <CharacterController>();


        spriteManager = gameObject.GetComponent <SpriteManager>() as SpriteManager;

        evilSprite = spriteManager.AddSprite(gameObject, 2.0f, 2.0f, spriteManager.PixelSpaceToUVSpace(256, 256), spriteManager.PixelSpaceToUVSpace(50, 50), false);
        evilSprite.SetAnimCompleteDelegate(OnAnimateComplete);

        Vector2 spriteSize = spriteManager.PixelSpaceToUVSpace(50, 50);

        //Idle animation
        UVAnimation idleAnimation  = new UVAnimation();
        Vector2     idleStartPosUV = spriteManager.PixelCoordToUVCoord(0, 50);

        idleAnimation.BuildUVAnim(idleStartPosUV, spriteSize, 3, 2, 6, 15);
        idleAnimation.loopCycles = -1;
        idleAnimation.name       = "idle";
        evilSprite.AddAnimation(idleAnimation);

        evilSprite.PlayAnim("idle");
        gameObject.transform.position = startPos;
    }
Exemple #18
0
    /// <summary>
    /// Copies all the attributes of another sprite,
    /// including its edit-time TextureAnimations.
    /// </summary>
    /// <param name="s">A reference to the sprite to be copied.</param>
    public virtual void CopyAll(SpriteRoot s)
    {
        AutoSpriteBase sp;

        base.Copy(s);

        // Check the type:
        if (!(s is AutoSpriteBase))
        {
            return;
        }

        sp = (AutoSpriteBase)s;

        States = new TextureAnim[sp.States.Length];

        for (int i = 0; i < States.Length; ++i)
        {
            States[i] = new TextureAnim();
            States[i].Copy(sp.States[i]);
        }

        animations = new UVAnimation[States.Length];

        for (int i = 0; i < States.Length; ++i)
        {
            animations[i] = new UVAnimation();
            animations[i].SetAnim(States[i], i);
        }
    }
Exemple #19
0
    // Use this for initialization
    void Start()
    {
        spriteManager = gameObject.GetComponent <SpriteManager>() as SpriteManager;

        weaponSprite = spriteManager.AddSprite(gameObject, 1.0f, 1.0f, spriteManager.PixelSpaceToUVSpace(512, 512), spriteManager.PixelSpaceToUVSpace(72, 78), false);
        weaponSprite.SetAnimCompleteDelegate(OnAnimateComplete);

        Vector2 spriteSize = spriteManager.PixelSpaceToUVSpace(72, 78);

        //Idle animation
        UVAnimation idleAnimation  = new UVAnimation();
        Vector2     idleStartPosUV = spriteManager.PixelCoordToUVCoord(0, 78);

        idleAnimation.BuildUVAnim(idleStartPosUV, spriteSize, 1, 1, 1, 15);
        idleAnimation.loopCycles = -1;
        idleAnimation.name       = "idle";
        weaponSprite.AddAnimation(idleAnimation);

        UVAnimation shootAnimation  = new UVAnimation();
        Vector2     shootStartPosUV = spriteManager.PixelCoordToUVCoord(0, 78);

        shootAnimation.BuildUVAnim(shootStartPosUV, spriteSize, 3, 2, 5, 15);
        shootAnimation.loopCycles = 0;
        shootAnimation.name       = "shoot";
        weaponSprite.AddAnimation(shootAnimation);

        transform.parent = GameObject.Find("Main Camera").transform;

        transform.localPosition = localPos;
        transform.rotation      = GameObject.Find("Main Camera").transform.rotation;
    }
    // Use this for initialization
    void Start()
    {
        sprite = spriteManager.AddSprite(gameObject, width, height, 0, 127, 128, 128, false);

        // Create and setup anims
        UVAnimation anim = new UVAnimation();
        var firstFrame = spriteManager.PixelCoordToUVCoord(new Vector2(0, 127));
        var cellSize = spriteManager.PixelSpaceToUVSpace(new Vector2(128, 128));
        anim.BuildUVAnim(firstFrame, cellSize, 8, 8, 13, 15);
        anim.name = "Idle";
        anim.loopCycles = -1;

        sprite.AddAnimation(anim);

        anim = new UVAnimation();
        firstFrame = spriteManager.PixelCoordToUVCoord(new Vector2(0, 127));
        cellSize = spriteManager.PixelSpaceToUVSpace(new Vector2(128, 128));
        anim.BuildUVAnim(firstFrame, cellSize, 8, 8, 13, 30);
        anim.name = "Arm";
        anim.loopCycles = -1;

        sprite.AddAnimation(anim);

        anim = new UVAnimation();
        firstFrame = spriteManager.PixelCoordToUVCoord(new Vector2(256, 383));
        cellSize = spriteManager.PixelSpaceToUVSpace(new Vector2(128, 128));
        anim.BuildUVAnim(firstFrame, cellSize, 8, 8, 8, 30);
        anim.name = "Explode";
        anim.loopCycles = 1;

        sprite.AddAnimation(anim);

        sprite.PlayAnim("Idle");
    }
    // Use this for initialization
    void Start()
    {
        sprite = spriteManager.AddSprite(gameObject, width, height, 0, 511, 512, 512, false);

        // Create and setup anims
        UVAnimation anim       = new UVAnimation();
        var         firstFrame = spriteManager.PixelCoordToUVCoord(new Vector2(0, 511));
        var         cellSize   = spriteManager.PixelSpaceToUVSpace(new Vector2(512, 512));

        anim.BuildUVAnim(firstFrame, cellSize, 8, 8, 16, 15);
        anim.name       = "Idle";
        anim.loopCycles = -1;

        sprite.AddAnimation(anim);

        anim       = new UVAnimation();
        firstFrame = spriteManager.PixelCoordToUVCoord(new Vector2(0, 1535));
        cellSize   = spriteManager.PixelSpaceToUVSpace(new Vector2(512, 512));
        anim.BuildUVAnim(firstFrame, cellSize, 8, 8, 19, 15);
        anim.name       = "Surprise";
        anim.loopCycles = 0;

        sprite.AddAnimation(anim);

        sprite.PlayAnim("Idle");
    }
Exemple #22
0
 public void AppendClip(UVAnimation clip)
 {
     UVAnimation[] array = this.clips;
     this.clips = new UVAnimation_Auto[this.clips.Length + 1];
     array.CopyTo(this.clips, 0);
     this.clips[this.clips.Length - 1] = (UVAnimation_Auto)clip;
     this.CalcDuration();
 }
Exemple #23
0
 /// <summary>
 /// Sets the sprite to display the given frame of the
 /// specified animation.
 /// </summary>
 /// <param name="anim">The animation containing the desired frame.</param>
 /// <param name="frameNum">The 0-based index of the frame to be displayed.</param>
 public void SetFrame(UVAnimation anim, int frameNum)
 {
     PlayAnim(anim);
     if (IsAnimating())
     {
         PauseAnim();
     }
     SetCurFrame(frameNum);
 }
 public override void Clear()
 {
     base.Clear();
     if (this.curAnim != null)
     {
         base.PauseAnim();
         this.curAnim = null;
     }
 }
Exemple #25
0
    /// <summary>
    /// Like PlayAnim, but plays the animation in reverse.
    /// See <see cref="PlayAnim"/>.
    /// </summary>
    /// <param name="anim">Reference to the animation to play in reverse.</param>
    public void PlayAnimInReverse(UVAnimation anim)
    {
#if UNITY_4_0 || UNITY_4_1 || UNITY_4_2 || UNITY_4_3 || UNITY_4_4 || UNITY_4_5 || UNITY_4_6 || UNITY_4_7 || UNITY_4_8 || UNITY_4_9
        if (deleted || !gameObject.activeInHierarchy)
#else
        if (deleted || !gameObject.active)
#endif
        { return; }

        curAnim = anim;
        curAnim.Reset();
        curAnim.PlayInReverse();

        // Ensure the framerate is not 0 so we don't
        // divide by zero:
        if (anim.framerate != 0.0f)
        {
            timeBetweenAnimFrames = 1f / anim.framerate;
        }
        else
        {
            timeBetweenAnimFrames = 1f;             // Just some dummy value since it won't be used
        }

        timeSinceLastFrame = timeBetweenAnimFrames;

        // Only add to the animated list if
        // the animation has more than 1 frame:
        if ((anim.GetFrameCount() > 1 || anim.onAnimEnd != UVAnimation.ANIM_END_ACTION.Do_Nothing) && anim.framerate != 0.0f)
        {
            StepAnim(0);
            // Start coroutine
            if (!animating)
            {
                //animating = true;
                AddToAnimatedList();
                //StartCoroutine(AnimationPump());
            }
        }
        else
        {
            // Make sure we are no longer in the animation pump:
            PauseAnim();

            // Since this is a single-frame anim,
            // call our delegate before setting
            // the frame so that our behavior is
            // consistent with multi-frame anims:
            if (animCompleteDelegate != null)
            {
                animCompleteDelegate(this);
            }

            StepAnim(0);
        }
    }
Exemple #26
0
    //-----------------------------------------------------------------
    // Animation-related routines:
    //-----------------------------------------------------------------


    /// <summary>
    /// Adds an animation to the sprite for its use.
    /// </summary>
    /// <param name="anim">The animation to add</param>
    public void AddAnimation(UVAnimation anim)
    {
        UVAnimation[] temp;
        temp = animations;

        animations = new UVAnimation[temp.Length + 1];
        temp.CopyTo(animations, 0);

        animations[animations.Length - 1] = anim;
    }
Exemple #27
0
    // Resets all sprite values to defaults for reuse:
    public override void Clear()
    {
        base.Clear();

        if (curAnim != null)
        {
            PauseAnim();
            curAnim = null;
        }
    }
 // Use this for initialization
 void Start()
 {
     sprite = spriteManager.AddSprite(this.gameObject,2,2,new Vector2(.5f,.5f), new Vector2(.25f, .5f), new Vector3(0,0,0), true);
     stabbing = new UVAnimation();
     stabbing.name="stabbing";
     stabbing.SetAnim(stabbing.BuildUVAnim(new Vector2(.5f,.5f),new Vector2(.25f,.5f),2,2,3,2));
     stabbing.loopCycles=-1; // makes animation loop infinitely
     stabbing.loopReverse = true; // makes animation go in reverse after it's completed
     sprite.AddAnimation(stabbing);
     sprite.PlayAnim("stabbing");
 }
Exemple #29
0
        private UVAnimation[] ReadUVAnimation(uint nUVAnimation, uint ofsUVAnimation, BinaryReader bin)
        {
            bin.BaseStream.Position = ofsUVAnimation;
            var uvanimations = new UVAnimation[nUVAnimation];

            for (var i = 0; i < nUVAnimation; i++)
            {
                uvanimations[i] = bin.Read <UVAnimation>();
            }
            return(uvanimations);
        }
Exemple #30
0
	protected UVAnimation CreateAnimation(string animName, Vector2 startUVPos, Vector2 UVSize, int animCells, int loopCycles, bool pingPongAnim, float framerate){
		UVAnimation anim = new UVAnimation();
		anim.name = animName;
		anim.loopCycles = loopCycles;
		anim.framerate = framerate;
		if(pingPongAnim)
			anim.loopReverse = true;
		
		anim.BuildUVAnim(startUVPos, UVSize, spriteSheetCols, spriteSheetRows, animCells, framerate);		
		return anim;
	}
Exemple #31
0
    // Starts playing the specified animation
    // (Note: this doesn't resume from a pause,
    // it completely restarts the animation. To
    // unpause, use UnpauseAnim):
    public void PlayAnim(UVAnimation anim)
    {
        // Cancel any previously playing anim:
        CancelInvoke("StepAnim");

        curAnim = anim;
        curAnim.Reset();

        StepAnim();
        InvokeRepeating("StepAnim", 1f / anim.framerate, 1f / anim.framerate);
    }
Exemple #32
0
    protected override void Awake()
    {
        base.Awake();

        animations = new UVAnimation[States.Length];

        for (int i = 0; i < States.Length; ++i)
        {
            animations[i] = new UVAnimation();
            animations[i].SetAnim(States[i], i);
        }
    }
Exemple #33
0
    /// <summary>
    /// Starts playing the specified animation
    /// Note: this doesn't resume from a pause,
    /// it completely restarts the animation. To
    /// unpause, use <see cref="UnpauseAnim"/>.
    /// </summary>
    /// <param name="anim">A reference to the animation to play.</param>
    /// <param name="frame">The zero-based index of the frame at which to start playing.</param>
    public void PlayAnim(UVAnimation anim, int frame)
    {
        if (deleted || !gameObject.active)
        {
            return;
        }

        curAnim      = anim;
        curAnimIndex = curAnim.index;
        curAnim.Reset();
        curAnim.SetCurrentFrame(frame - 1);             // curFrame inside UVAnimation will be incremented before it is used, so anticipate this by decrementing by 1

        // Ensure the framerate is not 0 so we don't
        // divide by zero:
        if (anim.framerate != 0.0f)
        {
            timeBetweenAnimFrames = 1f / anim.framerate;
        }
        else
        {
            timeBetweenAnimFrames = 1f;             // Just some dummy value since it won't be used
        }

        timeSinceLastFrame = timeBetweenAnimFrames;

        // Only add to the animated list if
        // the animation has more than 1 frame
        // or the framerate is non-zero:
        if ((anim.GetFrameCount() > 1 || anim.onAnimEnd != UVAnimation.ANIM_END_ACTION.Do_Nothing) && anim.framerate != 0.0f)
        {
            StepAnim(0);
            // Start coroutine
            if (!animating)
            {
                //animating = true;
                AddToAnimatedList();
                //StartCoroutine(AnimationPump());
            }
        }
        else
        {
            // Since this is a single-frame anim,
            // call our delegate before setting
            // the frame so that our behavior is
            // consistent with multi-frame anims:
            if (animCompleteDelegate != null)
            {
                animCompleteDelegate(this);
            }

            StepAnim(0);
        }
    }
Exemple #34
0
    /// <summary>
    /// Like PlayAnim, but plays the animation in reverse.
    /// See <see cref="PlayAnim"/>.
    /// </summary>
    /// <param name="anim">Reference to the animation to play in reverse.</param>
    /// <param name="frame">The zero-based index of the frame at which to start playing.</param>
    public void PlayAnimInReverse(UVAnimation anim, int frame)
    {
#if UNITY_4_0 || UNITY_4_1 || UNITY_4_2 || UNITY_4_3 || UNITY_4_4 || UNITY_4_5 || UNITY_4_6 || UNITY_4_7 || UNITY_4_8 || UNITY_4_9
        if (deleted || !gameObject.activeInHierarchy)
#else
        if (deleted || !gameObject.active)
#endif
        { return; }
        if (!m_started)
        {
            Start();
        }

        curAnim = anim;
        curAnim.Reset();
        curAnim.PlayInReverse();
        curAnim.SetCurrentFrame(frame + 1);             // curFrame inside UVAnimation will be decremented before it is used, so anticipate this by decrementing by 1

        // Ensure the framerate is not 0 so we don't
        // divide by zero:
        anim.framerate = Mathf.Max(0.0001f, anim.framerate);

        timeBetweenAnimFrames = 1f / anim.framerate;
        timeSinceLastFrame    = timeBetweenAnimFrames;

        // Only add to the animated list if
        // the animation has more than 1 frame:
        if (anim.GetFrameCount() > 1)
        {
            StepAnim(0);
            // Start coroutine
            if (!animating)
            {
                //animating = true;
                AddToAnimatedList();
                //StartCoroutine(AnimationPump());
            }
        }
        else
        {
            // Since this is a single-frame anim,
            // call our delegate before setting
            // the frame so that our behavior is
            // consistent with multi-frame anims:
            if (animCompleteDelegate != null)
            {
                animCompleteDelegate(this);
            }

            StepAnim(0);
        }
    }
Exemple #35
0
    // Resets all sprite values to defaults for reuse:
    public void Clear()
    {
        client      = null;
        billboarded = false;
        hidden      = false;
        SetColor(Color.white);
        offset = Vector3.zero;

        PauseAnim();
        animations.Clear();
        curAnim = null;
        animCompleteDelegate = null;
    }
Exemple #36
0
 // Call this function to set current animation, it will automatically call reset function to start it.
 public void SetAnimation(string animationName)
 {
     for (int i = 0; i < animations.Length; i++)
     {
         if (animations[i].name == animationName)
         {
             currentAnimation = animations[i];
             ResetAnimation();
             return;
         }
     }
     Debug.LogWarning("Warning: " + gameObject.name + " (Instance: " + gameObject.GetInstanceID() + ") was not able to find <" + animationName + "> animation", gameObject);
 }
Exemple #37
0
    // Starts playing the specified animation
    // (Note: this doesn't resume from a pause,
    // it completely restarts the animation. To
    // unpause, use UnpauseAnim):
    public void PlayAnim(UVAnimation anim)
    {
        // First stop any currently playing animation:
        m_manager.StopAnimation(this);

        curAnim = anim;
        curAnim.Reset();
        timeBetweenAnimFrames = 1f / anim.framerate;
        timeSinceLastFrame    = timeBetweenAnimFrames;
        StepAnim(0);

        m_manager.AnimateSprite(this);
    }
    protected override void createAnimations()
    {
        // Set up animation
        anim            = new UVAnimation();
        anim.name       = "Flat Animation";
        anim.loopCycles = -1;
        anim.framerate  = 24;

        anim.BuildUVAnim(new Vector2(0f, 8f / numRows), cellSize, 18, 1, 18, 24);
        sprite.AddAnimation(anim);

        sprite.PlayAnim(anim);
    }
Exemple #39
0
    void DelayFunc()
    {
        if (hold != null)
        {
            hold.SetActive(true);

            m_UVAnimation = hold.GetComponent <UVAnimation>();
            if (m_UVAnimation != null)
            {
                m_UVAnimation.enabled = true;
            }
        }
    }
	public void DrawAnimation() {
		// Put sprite on the client object
		GameObject totem = GameObject.Find("TotemMono");
		totem.renderer.enabled = false;
		Sprite totemSprite = spriteManager.AddSprite(totem, 1f, 1f, new Vector2(0, 0.5f), new Vector2(0.5f, 0.5f), Vector3.zero, false);
		
		// Set up animation
		UVAnimation anim = new UVAnimation();
		anim.name = "animation1";
		anim.loopCycles = -1;
		anim.framerate = framerate;
		
		anim.BuildUVAnim(new Vector2(0, 0.5f), new Vector2(0.5f, 0.5f), 2, 2, 4, framerate);
		
		// Prepare sprite
		totemSprite.AddAnimation(anim);
		totemSprite.PlayAnim("animation1");
	}
    // Use this for initialization
    void Start()
    {
        width = collider.bounds.size.x * 2 + 0.15f;
        height = collider.bounds.size.y * 2 + 0.15f;

        sprite = spriteManager.AddSprite(gameObject, width, height, 0, 127, 128, 128, false);

        // Create and setup anims
        UVAnimation anim = new UVAnimation();
        var firstFrame = spriteManager.PixelCoordToUVCoord(new Vector2(0, 127));
        var cellSize = spriteManager.PixelSpaceToUVSpace(new Vector2(128, 128));
        anim.BuildUVAnim(firstFrame, cellSize, 8, 8, 11, 15);
        anim.name = "Idle";
        anim.loopCycles = -1;

        sprite.AddAnimation(anim);
        sprite.PlayAnim("Idle");
    }
Exemple #42
0
    public void drawAnim(ArrayList polesWithLights)
    {
        print (polesWithLights.Count);
        int len = polesWithLights.Count;
        clients = new Sprite[len*amount];
        xForms = new GameObject[len*amount];
        initPositions = new Vector3[len * amount];

        flaps = new UVAnimation[7];

        for (int i = 0; i < 7; i++) {
            flaps[i] = new UVAnimation ();
            flaps[i].name = "flap_"+(7-i);
            flaps[i].loopCycles = -1;
            flaps[i].framerate = 14;
            flaps[i].BuildUVAnim (new Vector2 (0f, (i+7f) / 14f), new Vector2 (1f / 14f, 1f / 14f), 14, 14, 14, 14);
        }

        int ct = 0;
        int lampCount = 0;
        for (int j = 0; j < polesWithLights.Count; j++) {
            for (int i = 0; i < amount; i++) {
                Transform pole = (Transform) polesWithLights[j];
                //				print (pole);
                GameObject lamp = pole.Find("bulb").gameObject;
                Vector3 p = new Vector3(lamp.transform.position.x+Random.Range(-2,2),lamp.transform.position.y-Random.Range(0,15),lamp.transform.position.z+Random.Range(-2,2));
                initPositions[ct] = p;
                xForms[ct] = Instantiate (gClient, p, Quaternion.identity) as GameObject;
                xForms[ct].transform.parent = GameObject.Find("parent/poles").transform;
                Sprite tempClient = spManager.AddSprite (xForms [ct], 1f, 1f, new Vector2 (0f, 7f / 14f), new Vector2 (1f / 14f, 1f / 14f), Vector3.zero, true);
                clients [ct] = tempClient;//spManager.AddSprite (xForms [ct], 1f, 1f, new Vector2 (0f, 7f / 14f), new Vector2 (1f / 14f, 1f / 14f), Vector3.zero, true);
                spManager.SetBillboarded (clients [ct]);
                for (int q = 0; q < 7; q++) {
                    UVAnimation tFlap = flaps [q];
                    clients [ct].AddAnimation (tFlap);
                }
                clients [ct].PlayAnim ("flap_1");
                ct++;
                lampCount++;
                //				print (i+ " " + j + " " + ct);
            }
        }
        built = true;
    }
    // Use this for initialization
    void Start()
    {
        sprite = spriteManager.AddSprite(gameObject, width, height, 0, 127, 128, 128, false);

        // Create and setup anims
        UVAnimation anim = new UVAnimation();
        var firstFrame = spriteManager.PixelCoordToUVCoord(new Vector2(0, 127));
        var cellSize = spriteManager.PixelSpaceToUVSpace(new Vector2(128, 128));
        anim.BuildUVAnim(firstFrame, cellSize, 8, 8, 10, 15);
        anim.name = "Idle";
        anim.loopCycles = 0;

        sprite.AddAnimation(anim);
        sprite.PlayAnim("Idle");

        sprite.SetAnimCompleteDelegate(delegate()
        {
            Destroy(transform.parent.gameObject);
        });
    }
Exemple #44
0
	public void Init()
	{
		bool wasDeactivated = false;

		if (sprite != null)
		{
			// See if we need to activate our sprite
			// to work with it:
			if (!sprite.gameObject.active)
			{
				wasDeactivated = true;
				sprite.gameObject.active = true;
			}

			anim = sprite.GetAnim(animName);

			if (anim == null)
				Debug.LogError("SuperSprite error: No animation by the name of \"" + animName + "\" was found on sprite \"" + sprite.name + "\". Please verify the spelling and capitalization of the name, including any extra spaces, etc.");

			if (wasDeactivated)
				sprite.gameObject.active = false;
		}
	}
	/// <summary>
	/// Like PlayAnim, but plays the animation in reverse.
	/// See <see cref="PlayAnim"/>.
	/// </summary>
	/// <param name="anim">Reference to the animation to play in reverse.</param>
	public void PlayAnimInReverse(UVAnimation anim)
	{
#if UNITY_4_0 || UNITY_4_1 || UNITY_4_2 || UNITY_4_3 || UNITY_4_4 || UNITY_4_5 || UNITY_4_6 || UNITY_4_7 || UNITY_4_8 || UNITY_4_9
		if (deleted || !gameObject.activeInHierarchy)
#else
		if (deleted || !gameObject.active)
#endif
			return;

		curAnim = anim;
		curAnim.Reset();
		curAnim.PlayInReverse();

		// Ensure the framerate is not 0 so we don't
		// divide by zero:
		if (anim.framerate != 0.0f)
		{
			timeBetweenAnimFrames = 1f / anim.framerate;
		}
		else
		{
			timeBetweenAnimFrames = 1f; // Just some dummy value since it won't be used
		}

		timeSinceLastFrame = timeBetweenAnimFrames;

		// Only add to the animated list if
		// the animation has more than 1 frame:
		if ((anim.GetFrameCount() > 1 || anim.onAnimEnd != UVAnimation.ANIM_END_ACTION.Do_Nothing) && anim.framerate != 0.0f)
		{
			StepAnim(0);
			// Start coroutine
			if (!animating)
			{
				//animating = true;
				AddToAnimatedList();
				//StartCoroutine(AnimationPump());
			}
		}
		else
		{
			// Make sure we are no longer in the animation pump:
			PauseAnim();

			// Since this is a single-frame anim,
			// call our delegate before setting
			// the frame so that our behavior is
			// consistent with multi-frame anims:
			if (animCompleteDelegate != null)
				animCompleteDelegate(this);

			StepAnim(0);
		}
	}
	/// <summary>
	/// Starts playing the specified animation
	/// Note: this doesn't resume from a pause,
	/// it completely restarts the animation. To
	/// unpause, use <see cref="UnpauseAnim"/>.
	/// </summary>
	/// <param name="anim">A reference to the animation to play.</param>
	public void PlayAnim(UVAnimation anim)
	{
		PlayAnim(anim, 0);
	}
	/// <summary>
	/// Starts playing the specified animation
	/// Note: this doesn't resume from a pause,
	/// it completely restarts the animation. To
	/// unpause, use <see cref="UnpauseAnim"/>.
	/// </summary>
	/// <param name="anim">A reference to the animation to play.</param>
	/// <param name="frame">The zero-based index of the frame at which to start playing.</param>
	public void PlayAnim(UVAnimation anim, int frame)
	{
#if UNITY_4_0 || UNITY_4_1 || UNITY_4_2 || UNITY_4_3 || UNITY_4_4 || UNITY_4_5 || UNITY_4_6 || UNITY_4_7 || UNITY_4_8 || UNITY_4_9
		if (deleted || !gameObject.activeInHierarchy)
#else
		if (deleted || !gameObject.active)
#endif
			return;

		if (!m_started)
			Start();

		curAnim = anim;
		curAnimIndex = curAnim.index;
		curAnim.Reset();
		curAnim.SetCurrentFrame(frame - 1);	// curFrame inside UVAnimation will be incremented before it is used, so anticipate this by decrementing by 1

		// Ensure the framerate is not 0 so we don't
		// divide by zero:
		if (anim.framerate != 0.0f)
		{
			timeBetweenAnimFrames = 1f / anim.framerate;
		}
		else
		{
			timeBetweenAnimFrames = 1f; // Just some dummy value since it won't be used
		}

		timeSinceLastFrame = timeBetweenAnimFrames;

		// Only add to the animated list if
		// the animation has more than 1 frame
		// or the framerate is non-zero:
		if ((anim.GetFrameCount() > 1 || anim.onAnimEnd != UVAnimation.ANIM_END_ACTION.Do_Nothing) && anim.framerate != 0.0f)
		{
			StepAnim(0);
			// Start coroutine
			if (!animating)
			{
				//animating = true;
				AddToAnimatedList();
				//StartCoroutine(AnimationPump());
			}
		}
		else
		{
			// Make sure we are no longer in the animation pump:
			PauseAnim();

			// Since this is a single-frame anim,
			// call our delegate before setting
			// the frame so that our behavior is
			// consistent with multi-frame anims:
			if (animCompleteDelegate != null)
			{
				// See if we need to delay calling
				// our delegate to be consistent
				// with our framerate:
				if (anim.framerate != 0)
				{
					Invoke("CallAnimCompleteDelegate", 1f / anim.framerate);
				}
				else
					animCompleteDelegate(this);
			}

			StepAnim(0);
		}
	}
	// Steps to the next frame of sprite animation
	public override bool StepAnim(float time)
	{
		if (curAnim == null)
			return false;

		timeSinceLastFrame += Mathf.Max(0, time);
		//timeSinceLastFrame += time;

		framesToAdvance = (timeSinceLastFrame / timeBetweenAnimFrames);

		// If there's nothing to do, return:
		if (framesToAdvance < 1)
		{
			if (crossfadeFrames)
				SetColor(new Color(1f, 1f, 1f, (1f - framesToAdvance)));
			return true;
		}

		//timeSinceLastFrame -= timeBetweenAnimFrames * (float)framesToAdvance;

		while (framesToAdvance >= 1f)
		{
			if (curAnim.GetNextFrame(ref frameInfo))
			{
#if SPRITE_FRAME_DELEGATE
				// Notify the delegate:
				if(framesToAdvance >= 1f)
					if (animFrameDelegate != null)
						animFrameDelegate(this, curAnim.GetCurPosition());
#endif
				framesToAdvance -= 1f;
				timeSinceLastFrame -= timeBetweenAnimFrames;
			}
			else
			{
				// We reached the end of our animation
				if (crossfadeFrames)
					SetColor(Color.white);

				// See if we should revert to a static appearance,
				// default anim, or do nothing, etc:
				switch (curAnim.onAnimEnd)
				{
					case UVAnimation.ANIM_END_ACTION.Do_Nothing:
						PauseAnim();

						// Update mesh UVs:
						uvRect = frameInfo.uvs;
						SetBleedCompensation();

						// Resize if selected:
						if (autoResize || pixelPerfect)
							CalcSize();
						break;

					case UVAnimation.ANIM_END_ACTION.Revert_To_Static:
						RevertToStatic();
						break;

					case UVAnimation.ANIM_END_ACTION.Play_Default_Anim:
						// Notify the delegates:
						/*
						#if SPRITE_FRAME_DELEGATE
												if (animFrameDelegate != null)
													animFrameDelegate(this, curAnim.GetCurPosition());
						#endif
						*/

						if (animCompleteDelegate != null)
							animCompleteDelegate(this);

						// Play the default animation:
						PlayAnim(defaultAnim);
						return false;

					case UVAnimation.ANIM_END_ACTION.Hide:
						Hide(true);
						break;
					case UVAnimation.ANIM_END_ACTION.Deactivate:
#if UNITY_4_0 || UNITY_4_1 || UNITY_4_2 || UNITY_4_3 || UNITY_4_4 || UNITY_4_5 || UNITY_4_6 || UNITY_4_7 || UNITY_4_8 || UNITY_4_9
						gameObject.SetActive(false);
#else
						gameObject.active = false;
#endif
						break;
					case UVAnimation.ANIM_END_ACTION.Destroy:
						// Notify the delegates:
						/*
						#if SPRITE_FRAME_DELEGATE
												if (animFrameDelegate != null)
													animFrameDelegate(this, curAnim.GetCurPosition());
						#endif
						*/
						if (animCompleteDelegate != null)
							animCompleteDelegate(this);

						Delete();
						Destroy(gameObject);
						break;
				}

				// Notify the delegates:
				/*
				#if SPRITE_FRAME_DELEGATE
								if (animFrameDelegate != null)
									animFrameDelegate(this, curAnim.GetCurPosition());
				#endif
				*/
				if (animCompleteDelegate != null)
					animCompleteDelegate(this);

				// Check to see if we are still animating
				// before setting the curAnim to null.
				// Animating should be turned off if
				// PauseAnim() was called above, or if we
				// reverted to static.  But it could have
				// been turned on again by the 
				// animCompleteDelegate.
				if (!animating)
					curAnim = null;

				return false;
			}
		}

		// Cross-fade to the next frame:
		if (crossfadeFrames)
		{
			int curFrame = curAnim.GetCurPosition();
			int stepDir = curAnim.StepDirection;

			curAnim.GetNextFrame(ref nextFrameInfo);

			Vector2[] uvs2 = m_spriteMesh.uvs2;
			Rect nextUV = nextFrameInfo.uvs;
			uvs2[0].x = nextUV.xMin; uvs2[0].y = nextUV.yMax;
			uvs2[1].x = nextUV.xMin; uvs2[1].y = nextUV.yMin;
			uvs2[2].x = nextUV.xMax; uvs2[2].y = nextUV.yMin;
			uvs2[3].x = nextUV.xMax; uvs2[3].y = nextUV.yMax;

			// Undo our advance:
			curAnim.SetCurrentFrame(curFrame);
			curAnim.StepDirection = stepDir;

			SetColor(new Color(1f, 1f, 1f, (1f - framesToAdvance)));
		}
		/*
		#if SPRITE_FRAME_DELEGATE
				if (animFrameDelegate != null)
					animFrameDelegate(this, curAnim.GetCurPosition());
		#endif
		*/
		// Update mesh UVs:
		uvRect = frameInfo.uvs;
		SetBleedCompensation();

		// Resize if selected:
		if (autoResize || pixelPerfect)
			CalcSize();
		else if (anchor == SpriteRoot.ANCHOR_METHOD.TEXTURE_OFFSET)
			SetSize(width, height);

		//timeSinceLastFrame = 0;

		return true;
	}
	/// <summary>
	/// Copies all the attributes of another sprite,
	/// including its edit-time TextureAnimations.
	/// </summary>
	/// <param name="s">A reference to the sprite to be copied.</param>
	public virtual void CopyAll(SpriteRoot s)
	{
		AutoSpriteBase sp;

		base.Copy(s);

		// Check the type:
		if (!(s is AutoSpriteBase))
			return;

		sp = (AutoSpriteBase)s;

		States = new TextureAnim[sp.States.Length];

		for (int i = 0; i < States.Length; ++i)
		{
			States[i] = new TextureAnim();
			States[i].Copy(sp.States[i]);
		}

		animations = new UVAnimation[States.Length];

		for (int i = 0; i < States.Length; ++i)
		{
			animations[i] = new UVAnimation();
			animations[i].SetAnim(States[i], i);
		}

		doNotTrimImages = sp.doNotTrimImages;
	}
	/// <summary>
	/// Sets the sprite to display the given frame of the
	/// specified animation.
	/// </summary>
	/// <param name="anim">The animation containing the desired frame.</param>
	/// <param name="frameNum">The 0-based index of the frame to be displayed.</param>
	public void SetFrame(UVAnimation anim, int frameNum)
	{
		PlayAnim(anim);
		if (IsAnimating())
			PauseAnim();
		SetCurFrame(frameNum);
	}
	protected override void Awake()
	{
		base.Awake();

		animations = new UVAnimation[States.Length];

		for (int i = 0; i < States.Length; ++i)
		{
			animations[i] = new UVAnimation();
			animations[i].SetAnim(States[i], i);
		}
	}
Exemple #52
0
	//-----------------------------------------------------------------
	// Animation-related routines:
	//-----------------------------------------------------------------


	/// <summary>
	/// Adds an animation to the sprite for its use.
	/// </summary>
	/// <param name="anim">The animation to add</param>
	public void AddAnimation(UVAnimation anim)
	{
		UVAnimation[] temp;
		temp = animations;

		animations = new UVAnimation[temp.Length + 1];
		temp.CopyTo(animations, 0);

		animations[animations.Length - 1] = anim;
	}
Exemple #53
0
    //Plays the animation.
    void Play()
    {
        animationTimer -= Time.deltaTime; // First off, reduce animationTimer to check if we should switch frames.

        if (animationTimer < 0) {												// If this timer gets under 0 secs
            currentFrame += 1; 													// Start by increasing currentFrame value
            if (currentFrame < currentAnimation.frames)							// Check if there are more frames after current one
            {
                SetFramedImage();												// If yes, set the next frame image
                animationTimer = currentAnimation.frameDuration;				// and reset animationTimer to wait for next frame
            }
            else 																// If the current frame was the last one
            {
                if (currentAnimation.nextAnimation == "starting"  || currentAnimation.nextAnimation == "none")					// Reset to starting frame
                {
                    SetSingleImage(startingHorizontalCell, startingVerticalCell);
                }
                else if (string.IsNullOrEmpty(currentAnimation.nextAnimation) || currentAnimation.nextAnimation == "stop")		// Stop the animation and keep it's last frame
                {
                    currentAnimation = null;
                }
                else if (currentAnimation.nextAnimation == currentAnimation.name || currentAnimation.nextAnimation == "loop")	// Loop the same animation
                {
                    ResetAnimation();
                }
                else 																											// Start another animation
                {
                    SetAnimation(currentAnimation.nextAnimation);
                }
            }
        }
    }
Exemple #54
0
    protected List<Affector> InitAffectors(EffectNode node)
    {
        List<Affector> AffectorList = new List<Affector>();

        if (UVAffectorEnable)
        {
            UVAnimation uvAnim = new UVAnimation();
            if (UVType == 1)
            {
                float perWidth = OriUVDimensions.x / Cols;
                float perHeight = Mathf.Abs(OriUVDimensions.y / Rows);
                Vector2 cellSize = new Vector2(perWidth, perHeight);
                uvAnim.BuildUVAnim(OriTopLeftUV, cellSize, Cols, Rows, Cols * Rows);
            }
            UVDimension = uvAnim.UVDimensions[0];
            UVTopLeft = uvAnim.frames[0];

            if (uvAnim.frames.Length != 1)
            {
                uvAnim.loopCycles = LoopCircles;
                Affector aft = new UVAffector(uvAnim, UVTime, node, RandomStartFrame);
                AffectorList.Add(aft);
            }
        }
        else
        {
            UVDimension = OriUVDimensions;
            UVTopLeft = OriTopLeftUV;
        }

        if (RotAffectorEnable && RotateType != RSTYPE.NONE)
        {
            Affector aft;
            if (RotateType == RSTYPE.CURVE)
                aft = new RotateAffector(RotateCurve, node);
            else
                aft = new RotateAffector(DeltaRot, node);
            AffectorList.Add(aft);
        }
        if (ScaleAffectorEnable && ScaleType != RSTYPE.NONE)
        {
            Affector aft;

            if (UseSameScaleCurve)
                ScaleYCurve = ScaleXCurve;

            if (ScaleType == RSTYPE.CURVE)
                aft = new ScaleAffector(ScaleXCurve, ScaleYCurve, node);
            else
                aft = new ScaleAffector(DeltaScaleX, DeltaScaleY, node);
            AffectorList.Add(aft);
        }
        if (ColorAffectorEnable /*&& ColorAffectType != 0*/)
        {
            ColorAffector aft = new ColorAffector(this, node);
            AffectorList.Add(aft);
        }
        if (JetAffectorEnable)
        {
            Affector aft = new JetAffector(JetMag,JetMagType,JetCurve,node);
            AffectorList.Add(aft);
        }
        if (VortexAffectorEnable)
        {
            Affector aft;
            aft = new VortexAffector(VortexObj, VortexMagType, VortexMag, VortexCurve, VortexDirection, VortexInheritRotation, node);

            AffectorList.Add(aft);
        }
        if (UVRotAffectorEnable)
        {
            Affector aft;

            float xscroll = UVRotXSpeed;
            float yscroll = UVRotYSpeed;
            if (RandomUVRotateSpeed)
            {
                xscroll = Random.Range(UVRotXSpeed,UVRotXSpeedMax);
                yscroll = Random.Range(UVRotYSpeed,UVRotYSpeedMax);
            }

            aft = new UVRotAffector(xscroll, yscroll, node);
            AffectorList.Add(aft);
        }

        if (GravityAffectorEnable)
        {
            Affector aft;
            aft = new GravityAffector(GravityObject, GravityAftType, GravityMagType, IsGravityAccelerate,GravityDirection, GravityMag, GravityCurve, node);
            AffectorList.Add(aft);

            if (GravityAftType == GAFTTYPE.Spherical && GravityObject == null)
            {
                Debug.LogWarning("Gravity Object is missing, automatically set to effect layer self:" + gameObject.name);
                GravityObject = transform;
            }

        }
        if (AirAffectorEnable)
        {
            Affector aft = new AirFieldAffector(AirObject, AirDirection, AirMagType, AirMagnitude, AirMagCurve, AirAttenuation, AirUseMaxDistance,
                AirMaxDistance, AirEnableSpread, AirSpread, AirInheritVelocity, AirInheritRotation, node);
            AffectorList.Add(aft);
        }
        if (BombAffectorEnable)
        {
            Affector aft = new BombAffector(BombObject, BombType, BombMagType, BombDecayType, BombMagnitude, BombMagCurve, BombDecay, BombAxis, node);
            AffectorList.Add(aft);
        }
        if (TurbulenceAffectorEnable)
        {
            Affector aft = new TurbulenceFieldAffector(TurbulenceObject, TurbulenceMagType, TurbulenceMagnitude, TurbulenceMagCurve, TurbulenceAttenuation, TurbulenceUseMaxDistance, TurbulenceMaxDistance, node);
            AffectorList.Add(aft);
        }
        if (DragAffectorEnable)
        {
            Affector aft = new DragAffector(DragObj,DragUseDir,DragDir,DragMag,DragUseMaxDist,DragMaxDist,DragAtten,node);
            AffectorList.Add(aft);
        }
        return AffectorList;
    }
	/// <summary>
	/// Like PlayAnim, but plays the animation in reverse.
	/// See <see cref="PlayAnim"/>.
	/// </summary>
	/// <param name="anim">Reference to the animation to play in reverse.</param>
	/// <param name="frame">The zero-based index of the frame at which to start playing.</param>
	public void PlayAnimInReverse(UVAnimation anim, int frame)
	{
#if UNITY_4_0 || UNITY_4_1 || UNITY_4_2 || UNITY_4_3 || UNITY_4_4 || UNITY_4_5 || UNITY_4_6 || UNITY_4_7 || UNITY_4_8 || UNITY_4_9
		if (deleted || !gameObject.activeInHierarchy)
#else
		if (deleted || !gameObject.active)
#endif
			return;
		if (!m_started)
			Start();

		curAnim = anim;
		curAnim.Reset();
		curAnim.PlayInReverse();
		curAnim.SetCurrentFrame(frame + 1);	// curFrame inside UVAnimation will be decremented before it is used, so anticipate this by decrementing by 1

		// Ensure the framerate is not 0 so we don't
		// divide by zero:
		anim.framerate = Mathf.Max(0.0001f, anim.framerate);

		timeBetweenAnimFrames = 1f / anim.framerate;
		timeSinceLastFrame = timeBetweenAnimFrames;

		// Only add to the animated list if
		// the animation has more than 1 frame:
		if (anim.GetFrameCount() > 1)
		{
			StepAnim(0);
			// Start coroutine
			if (!animating)
			{
				//animating = true;
				AddToAnimatedList();
				//StartCoroutine(AnimationPump());
			}
		}
		else
		{
			// Since this is a single-frame anim,
			// call our delegate before setting
			// the frame so that our behavior is
			// consistent with multi-frame anims:
			if (animCompleteDelegate != null)
				animCompleteDelegate(this);

			StepAnim(0);
		}
	}
	// Resets all sprite values to defaults for reuse:
	public override void Clear()
	{
		base.Clear();

		if (curAnim != null)
		{
			PauseAnim();
			curAnim = null;
		}
	}
	/// <summary>
	/// Plays the specified animation only if it
	/// is not already playing.
	/// </summary>
	/// <param name="anim">Reference to the animation to play.</param>
	public void DoAnim(UVAnimation anim)
	{
		if (curAnim != anim || !animating)
			PlayAnim(anim);
	}
	/// <summary>
	/// Copies all the attributes of another sprite.
	/// </summary>
	/// <param name="s">A reference to the sprite to be copied.</param>
	public override void Copy(SpriteRoot s)
	{
		AutoSpriteBase sp;

		base.Copy(s);

		// Check the type:
		if (!(s is AutoSpriteBase))
			return;

		sp = (AutoSpriteBase)s;

		// See if it is an actual sprite instance:
		if (sp.spriteMesh != null)
		{
			if (sp.animations.Length > 0)
			{
				animations = new UVAnimation[sp.animations.Length];
				for (int i = 0; i < animations.Length; ++i)
					animations[i] = sp.animations[i].Clone();
			}
		}
		else if (States != null)
		{
			// Assume this is a prefab, so copy the UV info 
			//from its TextureAnimations instead:			
			animations = new UVAnimation[sp.States.Length];

			for (int i = 0; i < sp.States.Length; ++i)
			{
				animations[i] = new UVAnimation();
				animations[i].SetAnim(sp.States[i], i);
			}
		}
	}
Exemple #59
0
	/// <summary>
	/// Appends UV animation clip to the end of the animation sequence.
	/// </summary>
	/// <param name="clip">Animation clip to append.</param>
	public void AppendClip(UVAnimation clip)
	{
		UVAnimation[] temp;
		temp = clips;

		clips = new UVAnimation_Auto[clips.Length + 1];
		temp.CopyTo(clips, 0);

		clips[clips.Length - 1] = (UVAnimation_Auto)clip;

		CalcDuration();
	}
Exemple #60
0
	// Copy constructor:
	public UVAnimation(UVAnimation anim)
	{
		frames = new SPRITE_FRAME[anim.frames.Length];
		anim.frames.CopyTo(frames, 0);

		name = anim.name;

		loopCycles = anim.loopCycles;
		loopReverse = anim.loopReverse;
		framerate = anim.framerate;
		onAnimEnd = anim.onAnimEnd;

		curFrame = anim.curFrame;
		stepDir = anim.stepDir;
		numLoops = anim.numLoops;
		playInReverse = anim.playInReverse;
		length = anim.length;

		CalcLength();
	}