//---------------------- // Protected Functions /// <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.LogReminders("Does not 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); }
//======================================== // Unity's function //------------------------------ private void Awake() { this.mLiveObject = this.GetComponent <JCS_2DLiveObject>(); if (mDetectCollider.Length == 0) { JCS_Debug.LogReminders( "No Collider assing for dectetion..."); } for (int index = 0; index < mDetectCollider.Length; ++index) { if (mDetectCollider[index] == null) { JCS_Debug.LogReminders( "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>(); }
//======================================== // Self-Define //------------------------------ //---------------------- // Public Functions /// <summary> /// Either use keycode or call it with script! /// </summary> public void ActiveSkill() { if (mSkillAnim == null) { JCS_Debug.LogReminders( "Assigning active skill action without animation is not allowed."); return; } GameObject obj = JCS_Utility.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>(); }
/// <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.LogReminders( "There is no bullet assign to \"JCS_ShootAction\", so we cannot shoot a sequence..."); return; } if (hit <= 0) { JCS_Debug.LogReminders( "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); }
/*******************************************/ /* Self-Define */ /*******************************************/ //---------------------- // Public Functions /// <summary> /// Button click function pointer override. /// </summary> public override void JCS_OnClickCallback() { if (mSlideCameras.Length == 0) { JCS_Debug.LogReminders( "Assign the button without camera is not allowed..."); return; } // start counting delay mStartDelay = true; }
/// <summary> /// Do take snap shot api call. /// </summary> private void TakeSnapshotWebcam() { if (mWebcam == null) { JCS_Debug.LogReminders( "Assign the button but no webcam attached or in the scene."); return; } mWebcam.TakeSnapshotWebcam(); }
/// <summary> /// /// </summary> private void SpawnAttackAnimation() { if (mAtkAnim == null) { JCS_Debug.LogReminders( "JCS_SwingAttackAction", @"No animation assign but u 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; }
//---------------------- // Protected Variables //======================================== // setter / getter //------------------------------ //======================================== // Unity's function //------------------------------ private void Update() { mTimer += Time.deltaTime; if (mRemindPerTime < mTimer) { JCS_Debug.LogReminders( "Object u should destroy but u did not..."); #if (UNITY_EDITOR) gameObject.name = "Object u should destroy but u did not..."; #endif } }
//-------------------------------- // Unity's functions //-------------------------------- private void Awake() { instance = this; SetSpecificGameTypeGameManager(); #if (UNITY_EDITOR) // Check time scale if (TIME_SCALE != 1) { JCS_Debug.LogReminders( "Current time scale [" + TIME_SCALE + "] isn't one."); } #endif }
//======================================== // Self-Define //------------------------------ //---------------------- // Public Functions //---------------------- // Protected Functions //---------------------- // Private Functions /// <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.LogReminders( "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(); }
//======================================== // Self-Define //------------------------------ //---------------------- // Public Functions //---------------------- // Protected Functions //---------------------- // Private Functions /// <summary> /// Spawn the text pool base on number of handle. /// </summary> private void SpawnTextPool() { if (mLogText == null) { JCS_Debug.LogReminders( "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); } }
//======================================== // Self-Define //------------------------------ //---------------------- // Public Functions /// <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.LogReminders( "There is no bullet assign to \"JCS_ShootAction\", so we cannot shoot a sequence..."); return; } if (hit <= 0) { JCS_Debug.LogReminders( "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) }
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.LogReminders( "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(); }
/// <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.LogReminders( "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); }
/// <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.LogReminders( "Scene [" + sceneName + "] u 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; JCS_GameSettings 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 mJCSBlackScreen.MoveToTheLastChild(); // set the screen color. // NOTE(jenchieh): always start with opacity the same // as previous. screenColor.a = mJCSBlackScreen.LocalColor.a; mJCSBlackScreen.LocalColor = screenColor; // record down the screen color. JCS_SceneSettings.instance.SCREEN_COLOR = screenColor; // start fading in (black screen) mJCSBlackScreen.FadeIn(fadeInTime); } break; case JCS_SwitchSceneType.SLIDE_SCREEN: { mJCSBlackSlideScreen.MoveToTheLastChild(); mJCSBlackSlideScreen.StartSlideIn(mAlign, fadeInTime); } break; } JCS_SoundSettings 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; }