예제 #1
0
        /// <summary>
        /// Shoot bullets in sequence queue.
        /// </summary>
        /// <param name="hit"></param>
        /// <param name="pos"></param>
        public void ShootsInSequence(int hit, Vector3 pos)
        {
            if (mShootAction.Bullet == null)
            {
                JCS_Debug.LogReminder(
                    "There is no bullet assign to \"JCS_ShootAction\", so we cannot shoot a sequence...");

                return;
            }

            if (hit <= 0)
            {
                JCS_Debug.LogReminder(
                    "Cannot shoot sequence of bullet with lower than 0 hit...");

                return;
            }

            // thread itself
            mThread.push(mThread.length);

            // needed data
            mTimers.push(0);                // timer to calculate between each shoot.
            mShootCount.push(hit);          // hit per sequence.
            mShootCounter.push(0);          // counter to count how many shoot left?
            mShootPos.push(pos);            // position to spawn the bullet implements the position stay effect!
            mShootAngles.push(mShootAction.SpawnPoint.eulerAngles);
        }
        /* Functions */

        private void Awake()
        {
            this.mLiveObject = this.GetComponent <JCS_2DLiveObject>();

            if (mDetectCollider.Length == 0)
            {
                JCS_Debug.LogReminder("No Collider assing for dectetion");
            }


            for (int index = 0; index < mDetectCollider.Length; ++index)
            {
                if (mDetectCollider[index] == null)
                {
                    JCS_Debug.LogReminder("No Collider assing for dectetion");
                    continue;
                }

                // let the detect area know his parent class (this)
                JCS_DetectArea da = mDetectCollider[index].gameObject.AddComponent <JCS_DetectArea>();
                da.SetAction(this);

                // force the collider equals to true!!
                mDetectCollider[index].isTrigger = true;
            }

            // create list to manage all detected object
            mDetectedObjects = new JCS_Vector <JCS_DetectAreaObject>();
        }
        /// <summary>
        /// Set the parent object base on the
        /// fit screen setting.
        /// </summary>
        protected void SetParentObjectByMode()
        {
            JCS_Canvas jcsCanvas = JCS_Canvas.instance;

            if (jcsCanvas == null)
            {
                JCS_Debug.LogReminder("Doesn't use JCS_Canvas object");
                return;
            }

            Transform parentObject = null;

            // if is Resize UI is enable than add Dialogue under resize ui transform
            if (JCS_UISettings.instance.RESIZE_UI)
            {
                parentObject = jcsCanvas.GetResizeUI().transform;
            }
            // Else we add it directly under the Canvas
            else
            {
                parentObject = jcsCanvas.GetCanvas().transform;
            }

            // set it to parent
            this.gameObject.transform.SetParent(parentObject);
        }
예제 #4
0
        /// <summary>
        /// Remove linked node from the managed list.
        /// </summary>
        /// <param name="n"> Number of linked object to remove. </param>
        /// <param name="startIndex"> Starting index to remove. </param>
        /// <returns> List of removed linked object. </returns>
        public List <JCS_TransformLinkedObject> RemoveLinked(int n = 1, int startIndex = 0)
        {
            if (!JCS_Utility.WithInArrayRange(startIndex, mManagedList))
            {
                JCS_Debug.LogReminder("Can't remove linked node with index lower than 0");
                return(null);
            }

            var lst = new List <JCS_TransformLinkedObject>();

            int        maxIndex = startIndex + n;
            List <int> ids      = new List <int>();

            for (int index = startIndex; index < mManagedList.Count && index < maxIndex; ++index)
            {
                JCS_TransformLinkedObject node = mManagedList[index];

                ids.Add(index); // First record it down.
                lst.Add(node);  // Added to the remove list, and ready to return.
            }

            for (int index = 0; index < ids.Count; ++index)
            {
                int id = ids[index];

                JCS_TransformLinkedObject node = mManagedList[id];
                Destroy(node.gameObject);

                mManagedList.RemoveAt(id);
            }

            OrganizedLinked();

            return(lst);
        }
        /// <summary>
        /// Active the skill.
        /// </summary>
        public void ActiveSkill()
        {
            if (mSkillAnim == null)
            {
                JCS_Debug.LogReminder(
                    "Assigning active skill action without animation is not allowed.");

                return;
            }

            GameObject obj = JCS_Util.SpawnAnimateObject(mSkillAnim, mOrderLayer);

            if (mSamePosition)
            {
                obj.transform.position = this.transform.position;
            }
            if (mSameRotation)
            {
                obj.transform.rotation = this.transform.rotation;
            }

            // if stay with player, simple set the position to
            // same position and set to child so it will follows
            // the active target!
            if (mStayWithActiveTarget)
            {
                obj.transform.SetParent(this.transform);
            }


            // add anim death event,
            // so when animation ends destroy itself.
            obj.AddComponent <JCS_DestroyAnimEndEvent>();
        }
예제 #6
0
        /// <summary>
        /// Do take snap shot api call.
        /// </summary>
        private void TakeSnapshotWebcam()
        {
            if (mWebcam == null)
            {
                JCS_Debug.LogReminder("Assign the button but no webcam attached or in the scene");
                return;
            }

            mCurrentWebcamImagePath = mWebcam.TakeSnapshotWebcam();
        }
예제 #7
0
        /// <summary>
        /// Button click function pointer override.
        /// </summary>
        public override void JCS_OnClickCallback()
        {
            if (mSlideCameras.Length == 0)
            {
                JCS_Debug.LogReminder("Assign the button without camera is not allowed");
                return;
            }

            // start counting delay
            mStartDelay = true;
        }
        /* Functions */

        private void Awake()
        {
            instance = this;

            SetSpecificGameTypeGameManager();

#if (UNITY_EDITOR)
            // Check time scale
            if (TIME_SCALE != 1)
            {
                JCS_Debug.LogReminder("Current time scale [" + TIME_SCALE + "] isn't one.");
            }
#endif
        }
예제 #9
0
        /// <summary>
        ///
        /// </summary>
        private void SpawnAttackAnimation()
        {
            if (mAtkAnim == null)
            {
                JCS_Debug.LogReminder(
                    "No animation assign but you still want to spawn a animation...");

                return;
            }


            GameObject gm = new GameObject();

#if (UNITY_EDITOR)
            gm.name = "JCS_SwingAttackAction";
#endif
            // set the effect transform.
            if (mAsSamePosition)
            {
                gm.transform.position = this.mAtkAnimSpawnTrans.position;
            }
            if (mAsSameRotation)
            {
                gm.transform.rotation = this.mAtkAnimSpawnTrans.rotation;
            }
            if (mAsSameScale)
            {
                gm.transform.localScale = this.mAtkAnimSpawnTrans.localScale;
            }

            gm.transform.position   += mAnimOffsetPosition;
            gm.transform.localScale += mAnimOffsetScale;

            if (this.transform.localScale.x < 0)
            {
                Vector3 newScale = gm.transform.localScale;
                newScale.x = JCS_Mathf.ToNegative(newScale.x);
                gm.transform.localScale = newScale;
            }

            SpriteRenderer sr = gm.AddComponent <SpriteRenderer>();
            sr.sortingOrder = mOrderLayer;
            Animator animator = gm.AddComponent <Animator>();
            animator.runtimeAnimatorController = mAtkAnim;
            animator.speed = animator.speed * JCS_Mathf.Reciprocal(mAnimSpeed);


            JCS_DestroyAnimEndEvent dae = gm.AddComponent <JCS_DestroyAnimEndEvent>();
            dae.LoopTimes = mLoopTimes;
        }
        /* Setter & Getter */

        /* Functions */

        private void Update()
        {
            mTimer += Time.deltaTime;

            if (mRemindPerTime < mTimer)
            {
                JCS_Debug.LogReminder(
                    "Object you should destroy but you did not...");

#if (UNITY_EDITOR)
                gameObject.name = "Object you should destroy but you did not...";
#endif
            }
        }
        /// <summary>
        /// Do the damage to live object.
        /// </summary>
        /// <param name="liveObject"></param>
        private void DamageLiveObject(JCS_2DLiveObject liveObject)
        {
            // if cannot damage this live object than do nothing.
            if (!liveObject.CanDamage)
            {
                return;
            }

            if (!JCS_GameSettings.instance.TRIBE_DAMAGE_EACH_OTHER)
            {
                // if both player does not need to add in to list.
                // or if both enemy does not need to add in to list.
                if (liveObject.IsPlayer == mLiveObject.IsPlayer)
                {
                    return;
                }
            }

            if (mAbilityFormat == null)
            {
                JCS_Debug.LogReminder(
                    "You sure to not using any \"JCS_AbilityFormat\"?");
                return;
            }

            liveObject.ApplyDamageText(
                mAbilityFormat.GetMinDamage(),
                mAbilityFormat.GetMaxDamage(),
                this.transform.position,
                1,          // hit
                0,
                mHitSound); // critical chance


            // see if the collider is player.
            JCS_Player p = liveObject.GetComponent <JCS_Player>();

            if (p == null)
            {
                return;
            }

            // if the living object we are attacking is
            // player do the hit effect.
            p.Hit();
        }
예제 #12
0
        /// <summary>
        /// Spawn the text pool base on number of handle.
        /// </summary>
        private void SpawnTextPool()
        {
            if (mLogText == null)
            {
                JCS_Debug.LogReminder(
                    "No log text assign in the text pool...");

                return;
            }


            // NOTE(JenChieh): this might change in
            // the future.
            // Get the log system from the
            // same transfrom/node.
            JCS_IGLogSystem logSystem = this.GetComponent <JCS_IGLogSystem>();


            mLogTexts = new JCS_Vector <JCS_LogText>(mNumberOfHandle);

            for (int count = 0;
                 count < mNumberOfHandle;
                 ++count)
            {
                // spawn a new game object,
                // and get the component
                JCS_LogText logText = (JCS_LogText)JCS_Utility.SpawnGameObject(mLogText);

                // add to array
                mLogTexts.set(count, logText);

                // set parent
                JCS_Utility.SetParentWithoutLosingInfo(logText.transform, this.transform);

                // NOTE(JenChieh): this might change in
                // the future.
                // set the log system if there is one.
                logText.SetIGLogSystem(logSystem);
            }
        }
예제 #13
0
        /// <summary>
        /// Create new linked node object by N count.
        /// </summary>
        /// <param name="n"> Number of linked object to create. </param>
        /// <param name="startIndex"> Starting index to create. </param>
        /// <returns> List of created linked object. </returns>
        public List <JCS_TransformLinkedObject> NewLinked(int n = 1, int startIndex = 0)
        {
            if (mClone == null)
            {
                JCS_Debug.LogReminder("Can't create new linked node without the clone");
                return(null);
            }

            if (n <= 0)
            {
                JCS_Debug.LogReminder("Can't create new linked node N lower than 1");
                return(null);
            }

            var lst = new List <JCS_TransformLinkedObject>();

            int maxIndex = startIndex + n;

            for (int index = startIndex; index < maxIndex; ++index)
            {
                var newNode = JCS_Utility.SpawnGameObject(mClone) as JCS_TransformLinkedObject;

                // Set to it centers.
                {
                    newNode.transform.SetParent(this.transform);
                    newNode.transform.localPosition = Vector3.zero;
                    newNode.transform.localScale    = Vector3.one;
                }

                lst.Add(newNode);
                mManagedList.Insert(index, newNode);
            }

            OrganizedLinked();

            return(lst);
        }
        /// <summary>
        /// Load scene with self-define fade in time.
        /// </summary>
        /// <param name="sceneName"> scene name to load </param>
        /// <param name="fadeInTime"> time to fade in </param>
        /// <param name="screenColor"> screen color </param>
        /// <param name="keepBGM"> keep background music playing? </param>
        public void LoadScene(string sceneName, float fadeInTime, Color screenColor, bool keepBGM)
        {
#if (UNITY_EDITOR)
            // only do this in Editor Mode,
            // this help level designer to do their job.
            if (!ReadSceneNames.CheckSceneAvailable(sceneName))
            {
                JCS_Debug.LogReminder("Scene [" + sceneName + "] you want to load is not in the Build Setting");
                return;
            }
#endif

            // if is loading already, dont load it agian
            if (mSwitchSceneEffect)
            {
                return;
            }

            // set the next scene name
            this.mNextSceneName = sceneName;

            var gs = JCS_GameSettings.instance;

            if (gs.SAVE_ON_SWITCH_SCENE && gs.SAVE_GAME_DATA_FUNC != null)
            {
                // do the saving.
                gs.SAVE_GAME_DATA_FUNC.Invoke();
            }

            // preload the scene
            mAsyncOperation = SceneManager.LoadSceneAsync(mNextSceneName);
            mAsyncOperation.allowSceneActivation = false;

            switch (mSwitchSceneType)
            {
            case JCS_SwitchSceneType.BLACK_SCREEN:
            {
                // move to the last child in order
                // to render the black screen in front of
                // any UI's GUI
                mBlackScreen.MoveToTheLastChild();

                // set the screen color.
                // NOTE(jenchieh): always start with opacity the same
                // as previous.
                screenColor.a           = mBlackScreen.LocalColor.a;
                mBlackScreen.LocalColor = screenColor;

                // record down the screen color.
                JCS_SceneSettings.instance.SCREEN_COLOR = screenColor;

                // start fading in (black screen)
                mBlackScreen.FadeIn(fadeInTime);
            }
            break;

            case JCS_SwitchSceneType.SLIDE_SCREEN:
            {
                mBlackSlideScreen.MoveToTheLastChild();

                mBlackSlideScreen.StartSlideIn(mAlign, fadeInTime);
            }
            break;
            }

            var ss = JCS_SoundSettings.instance;

            ss.KEEP_BGM_SWITCH_SCENE = keepBGM;

            if (!keepBGM)
            {
                // start fading sound
                if (ss.SMOOTH_SWITCH_SOUND_BETWEEN_SCENE)
                {
                    // get the component.
                    if (mJCSFadeSound == null)
                    {
                        mJCSFadeSound = this.gameObject.AddComponent <JCS_FadeSound>();
                    }

                    mJCSFadeSound.SetAudioSource(JCS_SoundManager.instance.GetBGMAudioSource());

                    // fade out sound to zero
                    mJCSFadeSound.FadeOut(0, fadeInTime);
                }
            }

            // start check to switch scene or not
            mSwitchSceneEffect = true;

            // Pause the game depends on setting...
            JCS_GameManager.instance.GAME_PAUSE = mPauseGameWhileLoadingScene;
        }
예제 #15
0
        /// <summary>
        /// Apply Damage text by the chosen effect and
        /// algorithm. Lastly, apply it to Health Point.
        /// </summary>
        /// <param name="attacker"> Attacker </param>
        /// <param name="minDamage"> minimum damage could be </param>
        /// <param name="maxDamage"> maximum damage could be </param>
        /// <param name="pos"> position, usually this transform's position </param>
        /// <param name="hit"> how many hit in this sequence, could be one. </param>
        /// <param name="criticalChance"> critical chance could be? </param>
        public void ApplyDamageText(
            Transform attacker,
            int minDamage, int maxDamage,
            Vector2 pos,
            int hit            = 1,
            int criticalChance = 0,
            AudioClip hitSound = null)
        {
            int[] damages = null;

            // set the last attack in the safe way.
            SetLastAttacker(attacker);

            int defenseValue = 0;

            // get the defense value.
            if (mAbilityFormat != null)
            {
                defenseValue = mAbilityFormat.GetDefenseValue();
            }
            else
            {
                JCS_Debug.LogReminder(
                    "No Ability Format attached.");
            }

            // Damage text version
            if (mDamageTextEffect)
            {
                JCS_MixDamageTextPool mixTP = JCS_UtilitiesManager.instance.GetMixDamageTextPool();
                if (mixTP == null)
                {
#if (UNITY_EDITOR)
                    if (JCS_GameSettings.instance.DEBUG_MODE)
                    {
                        JCS_Debug.LogError(
                            "There is no Mix Damage Text Pool in the scene. Consider to grab one?");
                    }
#endif
                    return;
                }


                // spawn the damage text
                damages = mixTP.DamageTextSpawnerSimple(
                    minDamage, maxDamage,
                    pos,
                    hit,
                    criticalChance,
                    defenseValue,        // defense value
                    IsPlayer,
                    hitSound);
            }
            // Do damage without damage text.
            else
            {
                // since is not pre-calculate.
                // we have to calculate the damage before
                // actually apply the damage to
                // this live object.
                for (int index = 0;
                     index < hit;
                     ++index)
                {
                    int dm = Random.Range(minDamage, maxDamage);

                    // 受到的傷害 = 傷害 - 防禦力
                    damages[index] = dm - defenseValue;
                }
            }

            ReceiveDamage(damages, attacker);
        }
예제 #16
0
        private void OnTriggerEnter(Collider other)
        {
            if (mIsDestroyed)
            {
                return;
            }

            // do not target itself.
            if (other.transform == mAttackerInfo.Attacker)
            {
                return;
            }


            if (mInSequence)
            {
                if (mDestroyByThisAction)
                {
                    if (mTargetTransform == other.transform)
                    {
                        Destroy(this.gameObject);
                    }
                }

                return;
            }

            JCS_2DLiveObject liveObject = other.GetComponent <JCS_2DLiveObject>();

            // doing the lock on effect
            if (mOnlyWithTarget)
            {
                // if the target isn't what we want ignore than.
                if (mTargetTransform != other.transform)
                {
                    return;
                }
                else
                {
                    if (liveObject != null)
                    {
                        JCS_2DTrackAction tact = this.GetComponent <JCS_2DTrackAction>();

                        // only the last bullet in sequence will check dead.
                        if (tact != null)
                        {
                            if (tact.OrderIndex == Hit)
                            {
                                liveObject.BeenTarget = false;
                                liveObject.CheckDie();
                            }
                        }
                    }

                    DestroyWithAction();
                }
            }
            // if not in sequence
            else
            {
                if (liveObject == null)
                {
                    return;
                }

                if (!liveObject.CanDamage)
                {
                    return;
                }

                // liveObject is already dead.
                if (liveObject.IsDead())
                {
                    //DestroyWithAction();
                    return;
                }
            }

            Transform attacker = mAttackerInfo.Attacker;

            if (attacker != null)
            {
                JCS_2DLiveObject owenerLiveObject = mAttackerInfo.Attacker.GetComponent <JCS_2DLiveObject>();
                if (owenerLiveObject != null)
                {
                    if (!JCS_GameSettings.instance.TRIBE_DAMAGE_EACH_OTHER)
                    {
                        // if both player does not need to add in to list.
                        // or if both enemy does not need to add in to list.
                        if (liveObject.IsPlayer == owenerLiveObject.IsPlayer)
                        {
                            return;
                        }
                    }
                }
            }

            if (mAbilityFormat != null)
            {
                mMinDamage      = mAbilityFormat.GetMinDamage();
                mMaxDamage      = mAbilityFormat.GetMaxDamage();
                mCriticalChance = mAbilityFormat.GetCriticalChance();
            }
            else
            {
                JCS_Debug.LogReminder(
                    "You sure to not using any \"JCS_AbilityFormat\"?");
            }

            Vector3 currentPos = liveObject.transform.position + mDamageTextPositionOffset;

            if (mRandPos)
            {
                AddRandomPosition(ref currentPos);
            }

            if (mPreCalculateEffect)
            {
                liveObject.ApplyDamageText(
                    this.mAttackerInfo.Attacker,
                    mDamageApplying,
                    currentPos,
                    mCriticalChance,
                    mHitSound);

                mHit = this.mDamageApplying.Length;
            }
            else
            {
                liveObject.ApplyDamageText(
                    this.mAttackerInfo.Attacker,
                    mMinDamage,
                    mMaxDamage,
                    currentPos,
                    mHit,
                    mCriticalChance,
                    mHitSound);
            }

            // only if there is only one hit need to do this.
            if (mHit == 1)
            {
                liveObject.BeenTarget = false;
            }

            liveObject.CheckDie();

            DestroyWithAction();
        }
예제 #17
0
        /// <summary>
        /// Shoot bullets multiple times in times. (not in per frame)
        /// </summary>
        public void Shoots(int hit, Vector3 pos)
        {
            if (mShootAction.Bullet == null)
            {
                JCS_Debug.LogReminder(
                    "There is no bullet assign to \"JCS_ShootAction\", so we cannot shoot a sequence...");

                return;
            }

            if (hit <= 0)
            {
                JCS_Debug.LogReminder(
                    "Cannot shoot sequence of bullet with lower than 0 hit...");

                return;
            }

            // after finding once is still null,
            // try it agian!
            if (mDetectedObject == null)
            {
                // find the target
                switch (mShootAction.GetTrackType())
                {
                case JCS_ShootAction.TrackType.CLOSEST:
                    mDetectedObject = mShootAction.GetDetectAreaAction().FindTheClosest();
                    break;

                case JCS_ShootAction.TrackType.FURTHEST:
                    mDetectedObject = mShootAction.GetDetectAreaAction().FindTheFurthest();
                    break;
                }
            }

            // does not found the target to damage
            if (mDetectedObject == null)
            {
                mTargetsPerSequence.push(null);
            }
            else
            {
                // found target to damage, add in to data segment
                mTargetsPerSequence.push(mDetectedObject.transform);

                JCS_2DLiveObject liveObj = mDetectedObject.GetComponent <JCS_2DLiveObject>();
                if (liveObj != null)
                {
                    int defenseVal = 0;

                    // get the targeting defense value
                    if (liveObj.AbilityFormat != null)
                    {
                        defenseVal = liveObj.AbilityFormat.GetDefenseValue();
                    }

                    // calculate the damage we are going to apply to
                    // the target object.
                    mDamageApplying = PreCalculateSequenceDamage(
                        mAbilityFormat.GetMinDamage(),
                        mAbilityFormat.GetMaxDamage(),
                        hit,
                        defenseVal);

                    // pre calculate the damage before the
                    // actual bullet hit the object,
                    // so it could decide what object are dead already.
                    // and other object or this object wont target the
                    // object is going die.
                    liveObj.ReceivePreCalDamage(mDamageApplying);

                    // start targeting object to hit
                    liveObj.BeenTarget = true;
                }
            }


            // thread itself
            mThread.push(mThread.length);

            // needed data
            mTimers.push(0);                // timer to calculate between each shoot.
            mShootCount.push(hit);          // hit per sequence.
            mShootCounter.push(0);          // counter to count how many shoot left?
            mShootPos.push(pos);            // position to spawn the bullet implements the position stay effect!


            bool isLeft = true;

            if (this.transform.localScale.x < 0)
            {
                isLeft = false;
            }

            // shoot direction
            mShootDirection.push(isLeft);   // decide which direction should the bullet goes? (right/left)
        }