Exemple #1
0
        /* Functions */

        private void Awake()
        {
            this.mHitList           = this.GetComponent <JCS_HitListEvent>();
            this.mRandomSoundAction = this.GetComponent <JCS_SoundPool>();

            mDestroyObjectWithTime = this.GetComponent <JCS_DestroyObjectWithTime>();
        }
        /* Functions */

        private void Awake()
        {
            this.mHitList       = this.GetComponent <JCS_HitListEvent>();
            this.mTransformPool = this.GetComponent <JCS_TransformPool>();

            this.mDestroyObjectWithTime = this.GetComponent <JCS_DestroyObjectWithTime>();
        }
        //----------------------
        // Protected Variables

        //========================================
        //      setter / getter
        //------------------------------

        //========================================
        //      Unity's function
        //------------------------------
        private void Awake()
        {
            this.mObjectList            = this.GetComponent <JCS_ObjectList>();
            this.mHitList               = this.GetComponent <JCS_HitListEvent>();
            this.mDestroyObjectWithTime = this.GetComponent <JCS_DestroyObjectWithTime>();
        }
        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_DestroyParticleEffect";
#endif

            JCS_ParticleSystem jcsps = gm.AddComponent <JCS_ParticleSystem>();

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

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

            // copy and paste component to new one.
            {
                jcsps.Particle      = mParticleSystem.Particle;
                jcsps.NumOfParticle = mParticleSystem.NumOfParticle;

                jcsps.Active       = mParticleSystem.Active;
                jcsps.ActiveThread = mParticleSystem.ActiveThread;
                jcsps.OrderLayer   = mParticleSystem.OrderLayer;
                jcsps.Density      = mParticleSystem.Density;
                jcsps.WindSpeed    = mParticleSystem.WindSpeed;

                jcsps.AlwaysTheSameScale = mParticleSystem.AlwaysTheSameScale;

                jcsps.FreezeX = mParticleSystem.FreezeX;
                jcsps.FreezeY = mParticleSystem.FreezeY;
                jcsps.FreezeZ = mParticleSystem.FreezeZ;

                jcsps.RandPosX = mParticleSystem.RandPosX;
                jcsps.RandPosY = mParticleSystem.RandPosY;
                jcsps.RandPosZ = mParticleSystem.RandPosZ;

                jcsps.RandAngleX = mParticleSystem.RandAngleX;
                jcsps.RandAngleY = mParticleSystem.RandAngleY;
                jcsps.RandAngleZ = mParticleSystem.RandAngleZ;

                jcsps.RandScaleX = mParticleSystem.RandScaleX;
                jcsps.RandScaleY = mParticleSystem.RandScaleY;
                jcsps.RandScaleZ = mParticleSystem.RandScaleZ;

                jcsps.DoShotImmediately = mParticleSystem.DoShotImmediately;

                jcsps.SetChild = mParticleSystem.SetChild;
                jcsps.SetToSamePositionWhenActive = mParticleSystem.SetToSamePositionWhenActive;
            }

            // spawn the particle immediately.
            jcsps.SpawnParticles();

            // spawn the particle.
            jcsps.PlayOneShot();


            if (mDestroyByTime)
            {
                JCS_DestroyObjectWithTime dowt = gm.AddComponent <JCS_DestroyObjectWithTime>();
                dowt.DestroyTime = mDestroyTime;
            }
            else
            {
                // add destroy event.
                gm.AddComponent <JCS_DestroyParticleEndEvent>();
            }
        }
        /// <summary>
        /// Drop an item.
        /// </summary>
        /// <param name="item"> item u want to spawn </param>
        /// <param name="index"> index to know the force this is pushing to. </param>
        /// <param name="isEven"> is the index even number? </param>
        /// <param name="isGravity"> do gravity effect. </param>
        /// <param name="spreadEffect"> do spread effect. </param>
        /// <param name="rotateDrop"> rotate while dropping. </param>
        /// <param name="waveEffect"> do wave effect while on the ground. </param>
        /// <param name="destroyFade"> while picking it up will fade and destroy. </param>
        private void DropAnItem(
            JCS_Item item,
            int index,
            bool isEven,
            bool isGravity,
            bool spreadEffect,
            bool rotateDrop,
            bool waveEffect,
            bool destroyFade)
        {
            JCS_Item newItem = (JCS_Item)JCS_Utility.SpawnGameObject(
                item,
                this.transform.position,
                this.transform.rotation);

            bool isEvenIndex = ((index % 2) == 0) ? true : false;

            if (isGravity)
            {
                JCS_OneJump oj = newItem.gameObject.AddComponent <JCS_OneJump>();

                float gapDirection = mSpreadGap;
                if (isEvenIndex)
                {
                    gapDirection = -mSpreadGap;
                }

                oj.BounceBackfromWall = BounceBackfromWall;

                float gapForce = 0;

                if (spreadEffect)
                {
                    if (isEven)
                    {
                        if (!isEvenIndex)
                        {
                            gapForce = (gapDirection * (index - 1)) + gapDirection;
                        }
                        else
                        {
                            gapForce = (gapDirection * (index)) + gapDirection;
                        }
                    }
                    // if total is odd
                    else
                    {
                        if (isEvenIndex)
                        {
                            gapForce = (gapDirection * (index));
                        }
                        else
                        {
                            gapForce = (gapDirection * (index)) + gapDirection;
                        }
                    }
                }

                float jumpForce = mJumpForce;
                if (mRandomizeJumpForce)
                {
                    jumpForce += JCS_Random.Range(-mRandomizeJumpForceForce, mRandomizeJumpForceForce);
                }

                oj.DoForce(gapForce, jumpForce, mIncludeDepth);

                if (rotateDrop)
                {
                    JCS_ItemRotation irx = newItem.gameObject.AddComponent <JCS_ItemRotation>();
                    irx.RotateSpeed     = JCS_Random.Range(-mRotateSpeed, mRotateSpeed);
                    irx.Effect          = true;
                    irx.RotateDirection = JCS_Vector3Direction.FORWARD;

                    // if z axis interact in game
                    if (mIncludeDepth)
                    {
                        // add rotation on y axis.
                        JCS_ItemRotation iry = newItem.gameObject.AddComponent <JCS_ItemRotation>();
                        iry.RotateSpeed     = JCS_Random.Range(-mRotateSpeed, mRotateSpeed);
                        iry.Effect          = true;
                        iry.RotateDirection = JCS_Vector3Direction.UP;

                        // add rotation on z axis.
                        JCS_ItemRotation irz = newItem.gameObject.AddComponent <JCS_ItemRotation>();
                        irz.RotateSpeed     = JCS_Random.Range(-mRotateSpeed, mRotateSpeed);
                        irz.Effect          = true;
                        irz.RotateDirection = JCS_Vector3Direction.RIGHT;
                    }
                }
            }

            if (waveEffect)
            {
                JCS_3DConstWaveEffect cwe = newItem.gameObject.AddComponent <JCS_3DConstWaveEffect>();
                cwe.SetObjectType(newItem.GetObjectType());
                cwe.Effect = true;
            }

            if (destroyFade)
            {
                JCS_DestroyObjectWithTime dowt = newItem.gameObject.AddComponent <JCS_DestroyObjectWithTime>();
                dowt.FadeTime    = mFadeTime;
                dowt.DestroyTime = mDestroyTime;

                Renderer[] renderers = newItem.GetComponentsInChildren <Renderer>();

                foreach (Renderer rdr in renderers)
                {
                    JCS_FadeObject fo = rdr.gameObject.AddComponent <JCS_FadeObject>();

                    dowt.FadeObjects.Add(fo);

                    // set the object type the same.
                    fo.SetObjectType(item.GetObjectType());
                    fo.UpdateUnityData();
                }
            }
        }
        /// <summary>
        /// Drop an item.
        /// </summary>
        /// <param name="item"> item u want to spawn </param>
        /// <param name="index"> index to know the force this is pushing to. </param>
        /// <param name="isEven"> is the index even number? </param>
        /// <param name="isGravity"> do gravity effect. </param>
        /// <param name="spreadEffect"> do spread effect. </param>
        /// <param name="rotateDrop"> rotate while dropping. </param>
        /// <param name="waveEffect"> do wave effect while on the ground. </param>
        /// <param name="destroyFade"> while picking it up will fade and destroy. </param>
        private void DropAnItem(
            JCS_Item item,
            int index,
            bool isEven,
            bool isGravity,
            bool spreadEffect,
            bool rotateDrop,
            bool waveEffect,
            bool destroyFade)
        {
            JCS_Item jcsi = (JCS_Item)JCS_Utility.SpawnGameObject(
                item,
                this.transform.position,
                this.transform.rotation);

            bool isEvenIndex = ((index % 2) == 0) ? true : false;

            if (isGravity)
            {
                JCS_OneJump jcsoj = jcsi.gameObject.AddComponent <JCS_OneJump>();

                float gapDirection = mSpreadGap;
                if (isEvenIndex)
                {
                    gapDirection = -mSpreadGap;
                }

                jcsoj.BounceBackfromWall = BounceBackfromWall;

                float gapForce = 0;

                if (spreadEffect)
                {
                    if (isEven)
                    {
                        if (!isEvenIndex)
                        {
                            gapForce = (gapDirection * (index - 1)) + gapDirection;
                        }
                        else
                        {
                            gapForce = (gapDirection * (index)) + gapDirection;
                        }
                    }
                    // if total is odd
                    else
                    {
                        if (isEvenIndex)
                        {
                            gapForce = (gapDirection * (index));
                        }
                        else
                        {
                            gapForce = (gapDirection * (index)) + gapDirection;
                        }
                    }
                }

                float jumpForce = mJumpForce;
                if (mRandomizeJumpForce)
                {
                    jumpForce += JCS_Random.Range(-mRandomizeJumpForceForce, mRandomizeJumpForceForce);
                }

                jcsoj.DoForce(gapForce, jumpForce, mIncludeDepth);

                if (rotateDrop)
                {
                    JCS_ItemRotation jcsir = jcsi.gameObject.AddComponent <JCS_ItemRotation>();
                    jcsir.RotateSpeed = mRotateSpeed;
                    jcsir.Effect      = true;

                    // if z axis interact in game
                    if (mIncludeDepth)
                    {
                        // add one more axis.
                        JCS_ItemRotation jcsir2 = jcsi.gameObject.AddComponent <JCS_ItemRotation>();
                        jcsir2.RotateSpeed     = JCS_Random.Range(-mRotateSpeed, mRotateSpeed);
                        jcsir2.Effect          = true;
                        jcsir2.RotateDirection = JCS_Vector3Direction.UP;
                    }
                }
            }

            if (waveEffect)
            {
                JCS_3DConstWaveEffect jcscw = jcsi.gameObject.AddComponent <JCS_3DConstWaveEffect>();
                jcscw.Effect = true;
            }

            if (destroyFade)
            {
                JCS_DestroyObjectWithTime jcsao = jcsi.gameObject.AddComponent <JCS_DestroyObjectWithTime>();
                jcsao.GetFadeObject().FadeTime  = mFadeTime;
                jcsao.DestroyTime = mDestroyTime;

                // set the object type the same.
                jcsao.GetFadeObject().SetObjectType(item.GetObjectType());

                jcsao.GetFadeObject().UpdateUnityData();
            }
        }