コード例 #1
0
        /// <summary>
        /// Update all current active log messages' spacing.
        /// </summary>
        /// <param name="spaces"></param>
        public void UpdateSpace(int spaces = 1)
        {
            JCS_LogText logText = null;

            for (int index = 0; index < mRenderLogText.length; ++index)
            {
                logText = mRenderLogText.at(index);

                logText.SimpleTrackAction.DeltaTargetPosY(mLogSpacing * spaces);
            }
        }
コード例 #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="secondSearch"></param>
        /// <returns></returns>
        public JCS_LogText ExecuteOneFromPool(bool secondSearch = false)
        {
            if (mNumberOfHandle == 0)
            {
                return(null);
            }

            JCS_LogText logText;

            // loop through and see any not active
            // log text we can use in the pool
            for (int index = mLastSpawnPos;
                 index < mNumberOfHandle;
                 ++index)
            {
                logText = mLogTexts.at(index);

                // if not active, meaning we can
                // active the log text
                if (!logText.isActive())
                {
                    // set the last spawn count
                    mLastSpawnPos = index;

                    return(logText);
                }
            }

            // if we get here mean we cycle once but we
            // did not spawn a text!
            // so reset the spawn pos and
            // try to search agian until we find one!
            mLastSpawnPos = 0;

            // if function call the second time,
            // and try to call the third time,
            // exit the function call.
            // so prevent "stack overflow
            // search/infinite function call".
            // IMPORTANT(JenChieh): it wont spawn damage text this time,
            // if this happens.
            if (secondSearch)
            {
#if (UNITY_EDITOR)
                if (JCS_GameSettings.instance.DEBUG_MODE)
                {
                    JCS_Debug.LogWarning(
                        "Prevent, stack overflow function call.");
                }
#endif
                return(null);
            }

            // dangerious, use carefully!
            // make sure u have enough number of handle
            // or else the program might crash? (too many delay?)
            return(ExecuteOneFromPool(true));
        }
コード例 #3
0
        /// <summary>
        /// Return the furthest object in the array.
        /// </summary>
        /// <returns></returns>
        public JCS_DetectAreaObject FindTheFurthest()
        {
            int furthestIndex = -1;

            float furthestDistance = -1.0f;

            bool theFirstAssign = true;

            for (int index = 0; index < mDetectedObjects.length; ++index)
            {
                JCS_DetectAreaObject obj = mDetectedObjects.at(index);
                if (mDetectedObjects.at(index) == null)
                {
                    // remove from the list,
                    // the object could be dead for some reason.
                    mDetectedObjects.slice(index);
                    return(null);
                }

                // check to see if the object is live object.
                JCS_2DLiveObject liveObj = obj.GetComponent <JCS_2DLiveObject>();
                if (liveObj != null)
                {
                    // cannot target object that cannot be damage.
                    if (!liveObj.CanDamage)
                    {
                        continue;
                    }
                }

                Vector3 objectPos = mDetectedObjects.at(index).transform.position;
                Vector3 areaPos   = this.transform.position;

                float distance = Vector3.Distance(objectPos, areaPos);

                // assign the first value!
                if (theFirstAssign)
                {
                    furthestDistance = distance;
                    furthestIndex    = index;
                    theFirstAssign   = false;
                    continue;
                }

                if (distance > furthestDistance)
                {
                    furthestDistance = distance;
                    furthestIndex    = index;
                }
            }

            // nothing found or nothing in the list(nothing detected)!
            if (theFirstAssign)
            {
                return(null);
            }

            // return result
            return(mDetectedObjects.at(furthestIndex));
        }
コード例 #4
0
 /// <summary>
 /// Set the sound mute or not with list needed.
 /// </summary>
 /// <param name="list"> list of the audio source. </param>
 /// <param name="act"> target mute action. </param>
 private void SetSoundtMute(JCS_Vector <AudioSource> list, bool act)
 {
     for (int index = 0;
          index < list.length;
          ++index)
     {
         list.at(index).mute = act;
     }
 }
コード例 #5
0
 /// <summary>
 /// Set the sound volume in the list.
 /// </summary>
 /// <param name="list"> list of the audio source </param>
 /// <param name="vol"> target volume. </param>
 private void SetSoundVolume(JCS_Vector <AudioSource> list, float vol)
 {
     for (int index = 0;
          index < list.length;
          ++index)
     {
         list.at(index).volume = vol;
     }
 }
コード例 #6
0
        /// <summary>
        /// Push to the sound effect into array ready for use!
        /// </summary>
        /// <param name="sound"></param>
        public void PlayOneShotSFXSound(int index)
        {
            AudioSource aud = mSFXSounds.at(index);

            if (aud.clip != null)
            {
                aud.PlayOneShot(aud.clip, JCS_SoundSettings.instance.GetSFXSound_Volume());
            }
        }
コード例 #7
0
        //----------------------
        // Protected Functions

        //----------------------
        // Private Functions

        /// <summary>
        /// Disable all the actions in the array.
        /// </summary>
        private void DisableActions()
        {
            for (int index = 0;
                 index < mAIActions.length;
                 ++index)
            {
                JCS_AIAction aa = mAIActions.at(index);
                aa.enabled = false;
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="processIndex"></param>
        private void Sequence(int processIndex)
        {
            // get the timer from the thread
            float newTimer = mTimers.at(processIndex);

            // add time to timer
            newTimer += Time.deltaTime;

            // check if we can shoot or not
            if (mTimePerShoot < newTimer)
            {
                int totalShootCount   = mShootCount.at(processIndex);
                int currentShootCount = mShootCounter.at(processIndex);
                if (currentShootCount == totalShootCount)
                {
                    // Remove Thread.
                    EndProcessSequence(processIndex);
                    return;
                }

                Vector3 spawnPos   = this.transform.position;
                Vector3 shootAngle = this.mShootAction.SpawnPoint.eulerAngles;

                // if stay in the same position
                if (mSequenceStay)
                {
                    spawnPos = mShootPos.at(processIndex);
                }

                if (mShootGapEffect)
                {
                    spawnPos.y += currentShootCount * mShootGap;
                }

                if (mKeepShootAngle)
                {
                    shootAngle = mShootAngles.at(processIndex);
                }

                // do shooting
                mShootAction.ShootWithShootCount(spawnPos, shootAngle);

                ++currentShootCount;

                // update new count, in order
                // to spawn next bullet
                mShootCounter.set(processIndex, currentShootCount);
                newTimer = 0;
            }

            // update timer
            mTimers.set(processIndex, newTimer);
        }
コード例 #9
0
        /// <summary>
        /// Process the thread.
        /// </summary>
        /// <param name="processIndex"> thread id </param>
        private void Sequence(int processIndex)
        {
            // get the timer from the thread
            float newTimer = mTimers.at(processIndex);

            // add time to timer
            newTimer += Time.deltaTime;

            // check if we can do the particle or not
            if (mTimeAParticle < newTimer)
            {
                int totalParticleCount   = mParticleCount.at(processIndex);
                int currentParticleCount = mParticleCounter.at(processIndex);
                if (currentParticleCount == totalParticleCount)
                {
                    // Remove Thread.
                    EndProcessSequence(processIndex);
                    return;
                }

                // find a particle
                JCS_Particle particle = SearchAvaliableParticles();

                if (particle == null)
                {
                    // exit function.
                    return;
                }

                SetParticleBySetting(particle);

                ++currentParticleCount;

                // update new count, in order
                // to spawn next bullet
                mParticleCounter.set(processIndex, currentParticleCount);
                newTimer = 0;
            }

            // update timer
            mTimers.set(processIndex, newTimer);
        }
コード例 #10
0
        /// <summary>
        /// Find the avaliable particle in the list.
        /// </summary>
        /// <returns> non-active paritcle. </returns>
        private JCS_Particle SearchAvaliableParticles(bool sec = false)
        {
            if (mNumOfParticle <= 0)
            {
                JCS_Debug.LogError(
                    "Number of particle cannot lower or equal to zero...");
                return(null);
            }

            for (int index = mLastAvaliableIndex;
                 index < mParticles.length;
                 ++index)
            {
                JCS_Particle particle = mParticles.at(index);
                bool         isActive = particle.gameObject.activeInHierarchy;
                if (isActive == false)
                {
                    particle.gameObject.SetActive(true);
                    mLastAvaliableIndex = index;
                    return(particle);
                }
            }

            // if we get here mean we cycle once but we
            // did not spawn a text!
            // so reset the spawn pos and
            // try to search agian until we find one!
            mLastAvaliableIndex = 0;

            // if second time still does not find, return null.
            // prevent stack overflow.
            if (sec)
            {
                return(null);
            }

            // dangerious, use carefully!
            // make sure u have enough number of handle
            // or else the program might crash? (too many delay?)
            return(SearchAvaliableParticles(true));
        }
コード例 #11
0
        /// <summary>
        /// Spawn one damage text.
        /// </summary>
        /// <param name="damage"> damage number </param>
        /// <param name="pos"> spawn position </param>
        public void SpawnDamageTextFromPool(
            int damage,
            Vector3 pos,
            AudioClip hitSound,
            bool secondSearch = false)
        {
            if (mNumberOfHandle == 0)
            {
                return;
            }

            JCS_DamageText dt = null;

            for (int index = mLastSpawnPos; index < mNumberOfHandle; ++index)
            {
                dt = mDamageTexts.at(index);
                // if not active, meaning we can spawn the text
                if (!dt.isActive())
                {
                    dt.SpawnDamageText(damage, pos);

                    // Hit Sound is the part of SFX sound
                    PlayHitSound(hitSound);

                    // set the last spawn count
                    mLastSpawnPos = index;

                    // Look at the camera once!
                    if (mFaceCamera)
                    {
                        dt.transform.LookAt(Camera.main.transform.position);

                        dt.transform.Rotate(0.0f, 180.0f, 0.0f);
                    }

                    return;
                }
            }

            // if we get here mean we cycle once but we
            // did not spawn a text!
            // so reset the spawn pos and
            // try to search agian until we find one!
            mLastSpawnPos = 0;

            // if function call the second time,
            // and try to call the third time,
            // exit the function call.
            // so prevent "stack overflow
            // search/infinite function call".
            // IMPORTANT(JenChieh): it wont spawn damage text this time,
            // if this happens.
            if (secondSearch)
            {
#if (UNITY_EDITOR)
                if (JCS_GameSettings.instance.DEBUG_MODE)
                {
                    JCS_Debug.LogWarning("Prevent, stack overflow function call.");
                }
#endif
                return;
            }

            // dangerious, use carefully!
            // make sure u have enough number of handle
            // or else the program might crash? (too many delay?)
            SpawnDamageTextFromPool(damage, pos, hitSound, true);
        }
コード例 #12
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="processIndex"> thread id. </param>
        private void Sequence(int processIndex)
        {
            // get the timer from the thread
            float newTimer = mTimers.at(processIndex);

            // add time to timer
            newTimer += Time.deltaTime;

            // check if we can shoot or not
            if (mTimePerShoot < newTimer)
            {
                int totalShootCount   = mShootCount.at(processIndex);
                int currentShootCount = mShootCounter.at(processIndex);
                if (currentShootCount == totalShootCount)
                {
                    // Remove Thread.
                    EndProcessSequence(processIndex);
                    return;
                }

                Vector3 spawnPos = this.transform.position;

                // if stay in the same position
                if (mSequenceStay)
                {
                    spawnPos = mShootPos.at(processIndex);
                }

                if (mShootGapEffect)
                {
                    spawnPos.y += currentShootCount * mShootGap;
                }

                // direction.
                bool direction = mShootDirection.at(processIndex);

                // shoot a bullet
                if (mInSequenceEffect)
                {
                    bool theSub = true;

                    // meaning the head of the bullet in sequence.
                    if (currentShootCount == 0)
                    {
                        theSub = false;
                        if (mDamageApplying != null)
                        {
                            mShootAction.Shoot(spawnPos, direction, mDamageApplying, currentShootCount, theSub, mTargetsPerSequence.at(processIndex));
                        }
                        else
                        {
                            mShootAction.Shoot(spawnPos, direction, mHit, currentShootCount, theSub, mTargetsPerSequence.at(processIndex));
                        }

                        // after set the damage set it back to null
                        mDamageApplying = null;
                    }
                    // process the sub bullet in sequence
                    else
                    {
                        mShootAction.Shoot(spawnPos, direction, mHit, currentShootCount, theSub, mTargetsPerSequence.at(processIndex));
                    }
                }
                else
                {
                    mShootAction.Shoot(spawnPos, direction, 1, currentShootCount, false);
                }


                ++currentShootCount;

                // update new count, in order
                // to spawn next bullet
                mShootCounter.set(processIndex, currentShootCount);
                newTimer = 0;
            }

            // update timer
            mTimers.set(processIndex, newTimer);
        }
コード例 #13
0
        //----------------------
        // Protected Functions

        //----------------------
        // Private Functions
        private Vector3 CalculateTheCameraPosition()
        {
            // no target trackable
            if (mTargetList.length == 0)
            {
                return(transform.position);
            }

            float minHeight = 0,
                  maxHeight = 0,
                  minWidth  = 0,
                  maxWidth  = 0;

            bool firstAssign = false;

            JCS_Player p = null;

            for (int index = 0;
                 index < mTargetList.length;
                 ++index)
            {
                p = mTargetList.at(index);

                if (p == null)
                {
                    continue;
                }

                Transform trans = p.transform;

                // found the first object
                if (!firstAssign)
                {
                    minWidth    = trans.position.x;
                    maxWidth    = trans.position.x;
                    minHeight   = trans.position.y;
                    maxHeight   = trans.position.y;
                    firstAssign = true;
                    continue;
                }
                else
                {
                    // if other object is height than the other
                    // override the min/max value
                    if (trans.position.x < minWidth)
                    {
                        minWidth = trans.position.x;
                    }
                    if (trans.position.x > maxWidth)
                    {
                        maxWidth = trans.position.x;
                    }

                    if (trans.position.y < minHeight)
                    {
                        minHeight = trans.position.y;
                    }
                    if (trans.position.y > maxHeight)
                    {
                        maxHeight = trans.position.y;
                    }
                }
            }

            // 找出兩個物體最遠的距離
            float currentDiffDistanceX = maxWidth - minWidth;
            float currentDiffDistanceY = maxHeight - minHeight;

            // 如果超出一定距離, 則把鏡頭往後拉
            // 這樣才能 keep track of all the object
            {
                // X-axis
                if (currentDiffDistanceX > mViewWidth)
                {
                    float temp = (currentDiffDistanceX - mLastDiffDistanceX) * mCamerSpeed;
                    //mJCS_2DCamera.DeltaFieldOfView(temp);
                    mTargetFieldOfView += temp;
                }
                // Y-axis
                if (currentDiffDistanceY > mViewHeight)
                {
                    float temp = (currentDiffDistanceY - mLastDiffDistanceY) * mCamerSpeed;
                    //mJCS_2DCamera.DeltaFieldOfView(temp);
                    mTargetFieldOfView += temp;
                }
            }

            // record down the last distance
            mLastDiffDistanceX = currentDiffDistanceX;
            mLastDiffDistanceY = currentDiffDistanceY;


            // position
            float finalPosX = ((maxWidth - minWidth) / 2) + minWidth;
            float finalPosY = ((maxHeight - minHeight) / 2) + minHeight;

            return(new Vector3(finalPosX, finalPosY, transform.position.z));
        }