示例#1
0
        //========================================
        //      Self-Define
        //------------------------------
        //----------------------
        // Public Functions

        /// <summary>
        /// Play the animation base on the animation ID.
        /// </summary>
        /// <param name="id"> animation index in array. </param>
        /// <param name="over"> override the animation? </param>
        /// <param name="oneShot"> Is this animation playing one shot? </param>
        public void DoAnimation(
            int id,
            bool over    = false,
            bool oneShot = false)
        {
            if (!over)
            {
                // if same id, return.
                if (mCurrentAnimId == id)
                {
                    return;
                }
            }

            mCurrentAnimId = id;

            PutAnimaIdInSequence();

            // get the current playing animation.
            mCurrentAnimation = mAnimations[mCurrentAnimId];

            if (mCurrentAnimation == null)
            {
#if (UNITY_EDITOR)
                if (JCS_GameSettings.instance.DEBUG_MODE)
                {
                    JCS_Debug.LogError(
                        "Swtich animation failed cuz of null reference animation assigned...");
                }
#endif
                return;
            }

            if (oneShot)
            {
                // restart the target animation.
                mCurrentAnimation.Play(0, true);
            }
            else
            {
                // play target animation.
                mCurrentAnimation.Play(-1, true);
            }

            // active this animation.
            ActiveOneAnimation(mCurrentAnimId);
        }
示例#2
0
        /// <summary>
        /// play the animation in current frame.
        /// </summary>
        public void PlayAnimationInFrame()
        {
            if (mCurrentAnimation == null)
            {
                return;
            }

            mCurrentAnimation.Play();
        }
示例#3
0
        private void Update()
        {
#if (UNITY_EDITOR)
            Test();
#endif

            if (!mActive)
            {
                return;
            }

            // check if done playing the sequence, and is not looping.
            if (mDonePlayingSequence && !Loop)
            {
                return;
            }

            // check if reach the animation count.
            if (mAnimations.Length <= mAnimCounter)
            {
                // done playing.
                mDonePlayingSequence = true;

                if (Loop)
                {
                    // start with zero.
                    mAnimCounter = 0;
                }

                return;
            }
            else
            {
                // not done playing.
                mDonePlayingSequence = false;
            }

            mTimer += Time.deltaTime;

            // check if reach the time.
            if (mTimer < mTimePerAnim)
            {
                return;
            }

            mTimer = 0;

            // do the animation base on counter.
            mCurrentAnimation = mAnimations[mAnimCounter];

            mCurrentAnimation.Play(0, true);

            // add up the counter.
            ++mAnimCounter;
        }
示例#4
0
        private void LateUpdate()
        {
            if (!this.m2DAnimation.IsDonePlaying)
            {
                return;
            }

            ++mLoopCount;

            if (mLoopCount <= mLoopTimes)
            {
                Destroy(this.gameObject);
            }
            else
            {
                // play once more.
                m2DAnimation.Play();
            }
        }
        private void OnDestroy()
        {
            // if is quitting the application don't spawn object,
            // or else will cause memory leak!
            if (JCS_ApplicationManager.APP_QUITTING)
            {
                return;
            }

            // if switching the scene, don't spawn new gameObject.
            if (JCS_SceneManager.instance.IsSwitchingScene())
            {
                return;
            }

            // trigger this effect?
            bool onTrigger = false;

            if (mActiveWhatever)
            {
                onTrigger = true;
            }
            // no need to check the rest.
            else
            {
                // if checking for hit list
                if (mActiveWithHitList)
                {
                    if (mHitList.IsHit)
                    {
                        onTrigger = true;
                    }
                }

                // if checking for destroy time.
                if (mActiveWithDestroyTime)
                {
                    if (mDestroyObjectWithTime != null)
                    {
                        if (mDestroyObjectWithTime.TimesUp)
                        {
                            onTrigger = true;
                        }
                    }
                    else
                    {
                        JCS_Debug.LogError(
                            "You active the destroy time but without the JCS_DestroyObjectWithTime component...");
                    }
                }
            }

            // do not trigger this effect.
            if (!onTrigger)
            {
                return;
            }


            GameObject gm = new GameObject();

#if (UNITY_EDITOR)
            gm.name = "JCS_2DDestroyAnimEffect";
#endif

            SpriteRenderer sr = gm.AddComponent <SpriteRenderer>();
            sr.sortingOrder = mOrderLayer;

            JCS_2DAnimation randAnim = m2DAnimPool.GetRandomAnim();
            JCS_2DAnimation newAnim  = gm.AddComponent <JCS_2DAnimation>();

            newAnim.Active      = randAnim.Active;
            newAnim.Loop        = randAnim.Loop;
            newAnim.PlayOnAwake = randAnim.PlayOnAwake;
            newAnim.FramePerSec = randAnim.FramePerSec;

            // set the animation to just spawn animation.
            newAnim.SetAnimationFrame(randAnim.GetAnimationFrame());
            newAnim.Play();

            // add this event, so the when animation done play it will get destroy.
            JCS_2DDestroyAnimEndEvent das = gm.AddComponent <JCS_2DDestroyAnimEndEvent>();
            das.LoopTimes = mLoopTimes;

            if (mSamePosition)
            {
                sr.transform.position = this.transform.position;
            }
            if (mSameRotation)
            {
                sr.transform.rotation = this.transform.rotation;
            }
            if (mSameScale)
            {
                sr.transform.localScale = this.transform.localScale;
            }

            // Random Effect
            if (mRandPos)
            {
                AddRandomPosition(sr);
            }
            if (mRandRot)
            {
                AddRandomRotation(sr);
            }
            if (mRandScale)
            {
                AddRandomScale(sr);
            }
        }