//======================================== // 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>(); }
/// <summary> /// Return the closest object in the array. /// </summary> /// <returns></returns> public JCS_DetectAreaObject FindTheClosest() { int closestIndex = -1; float closestDistance = -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 = obj.transform.position; Vector3 areaPos = this.transform.position; float distance = Vector3.Distance(objectPos, areaPos); // assign the first value! if (theFirstAssign) { closestDistance = distance; closestIndex = index; theFirstAssign = false; continue; } if (distance < closestDistance) { closestDistance = distance; closestIndex = index; } } // nothing found or nothing in the list(nothing detected)! if (theFirstAssign) { return(null); } // return result return(mDetectedObjects.at(closestIndex)); }
//======================================== // Unity's function //------------------------------ private void Awake() { // try to get the ability format from this object. mAbilityFormat = this.GetComponent <JCS_AbilityFormat>(); mLiveObject = this.GetComponent <JCS_2DLiveObject>(); mLiveObjectList = new List <JCS_2DLiveObject>(); }
/* Setter & Getter */ /* Functions */ private void Awake() { mLiveObject = this.GetComponent <JCS_2DLiveObject>(); if (mLiveObjectAnimator == null) { mLiveObjectAnimator = this.GetComponent <JCS_2DLiveObjectAnimator>(); } }
/// <summary> /// Check if the object are the same tribe. /// </summary> /// <param name="liveObj1"> obj one </param> /// <param name="liveObj2"> obj two </param> /// <returns> /// true: same tribe /// false: not the same tribe /// </returns> public static bool IsSameTribe(JCS_2DLiveObject liveObj1, JCS_2DLiveObject liveObj2) { if (liveObj1 == null || liveObj2 == null) return false; // if both player does not need to add in to list. // or if both enemy does not need to add in to list. return (liveObj1.IsPlayer == liveObj2.IsPlayer); }
private void OnTriggerExit(Collider other) { JCS_2DLiveObject liveObject = other.GetComponent <JCS_2DLiveObject>(); if (liveObject == null) { return; } mLiveObjectList.Remove(liveObject); }
/// <summary> /// Find the closest object. /// </summary> /// <returns> oject found </returns> private JCS_2DLiveObject FindClosest() { // find all living object in the scene JCS_2DLiveObject[] objs = JCS_2DLiveObjectManager.instance.LIVE_OBJECT_LIST; float distance = 0; bool firstAssign = false; JCS_2DLiveObject targetFound = null; foreach (JCS_2DLiveObject obj in objs) { if (obj == null) { continue; } if (mUseAttacker) { if (!AbleTarget(obj)) { continue; } } // first assign. if (!firstAssign) { targetFound = obj; distance = Vector3.Distance(obj.transform.position, this.transform.position); // no more first assign firstAssign = true; continue; } // current distance we are checking. float checkingDistance = Vector3.Distance(obj.transform.position, this.transform.position); // check if the distance are closer. if (checkingDistance < distance) { // found another object that are // closer than the last object we found, // Update the distance and object. distance = checkingDistance; targetFound = obj; } } return(targetFound); }
/// <summary> /// Check if the object are ok to do push. /// </summary> /// <param name="other"></param> private void CheckAvailableToPush(Collider other) { JCS_2DLiveObject liveObject = other.GetComponent <JCS_2DLiveObject>(); if (liveObject == null) { return; } // do the effect. PushEffect(liveObject); }
//======================================== // 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(); }
/// <summary> /// /// </summary> /// <param name="liveObj"> object to check </param> /// <returns> /// true: able to target, no worry. /// false: not able to target by following reason. /// 1) Same Tribe /// 2) not able in the scene/hierarchy. /// </returns> private bool AbleTarget(JCS_2DLiveObject liveObj) { if (mAttackerInfo.Attacker != null) { // cannot target it-self. if (liveObj.transform == mAttackerInfo.Attacker) { return(false); } JCS_2DLiveObject owenerLiveObject = mAttackerInfo.Attacker.GetComponent <JCS_2DLiveObject>(); if (!JCS_GameSettings.instance.TRIBE_DAMAGE_EACH_OTHER) { // check same tribe. if (JCS_Utility.IsSameTribe(liveObj, owenerLiveObject)) { return(false); } } } // don't target the are disabled. if (liveObj.gameObject.activeInHierarchy == false) { return(false); } // don't target the dead live object if (liveObj.IsDead()) { return(false); } // make sure the object can be target/damage. if (!liveObj.CanDamage) { return(false); } return(true); }
/// <summary> /// Do once the push effect. /// </summary> public void PushEffect(JCS_2DLiveObject liveObject) { // knock back the object. liveObject.KnockBack(mPushForce, this.transform); }
/// <summary> /// Lock a gameobject, and look at it. /// So the object will seems like it /// "approach/further away" to the object. /// </summary> /// <param name="method"> method to find. </param> public void LockOnInit(FindMethod method) { JCS_2DLiveObject closestliveObj = null; switch (method) { case FindMethod.CLOSEST: closestliveObj = FindClosest(); break; case FindMethod.CLOSEST_RIGHT: closestliveObj = FindClosestRight(); break; case FindMethod.CLOSEST_LEFT: closestliveObj = FindClosestLeft(); break; case FindMethod.CLOSEST_TOP: closestliveObj = FindClosestTop(); break; case FindMethod.CLOSEST_BOTTOM: closestliveObj = FindClosestBottom(); break; } // no object found! if (closestliveObj == null) { return; } Vector3 newLookPoint = closestliveObj.transform.position; // look at the target object this.transform.LookAt(newLookPoint); // rotate back to original point. if (mRotateBack90) { this.transform.Rotate(0, -90, 0); } if (mAttackerInfo.Attacker != null) { if (mDirection == State.NONE) { if (JCS_Mathf.IsNegative(mAttackerInfo.Attacker.localScale.x)) { mDirection = State.NEGATIVE; } else { mDirection = State.POSITIVE; } } // 我們規定所有的圖往一邊, 所以只檢查一邊. if (mDirection == State.NEGATIVE) { this.transform.Rotate(0, 0, 180); } } #if (UNITY_EDITOR) // print out the name. if (JCS_GameSettings.instance.DEBUG_MODE) { JCS_Debug.PrintName(closestliveObj.transform); } #endif }
/* Functions */ private void Awake() { mLiveObject = this.GetComponent <JCS_2DLiveObject>(); }
//======================================== // 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.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(); }