protected override void Start() { base.Start(); // Use player from "JCS_GameManager" as default if (this.mTargetTransform == null) { JCS_Player player = JCS_GameManager.instance.GetJCSPlayer(); if (player != null) { SetFollowTarget(player.transform); } } if (mTargetTransform != null) { // first assign the target transform's position // to target position. mTargetPosition = this.mTargetTransform.position; // record the target position mLastFramePos = this.mTargetTransform.position; } if (mSetToPlayerPositionAtStart) { JCS_Player player = JCS_PlayerManager.instance.GetActivePlayer(); if (player != null) { // set the camera position JCS_Camera.main.SetPosition(player.transform.position.x, player.transform.position.y); } } }
//======================================== // Self-Define //------------------------------ //---------------------- // Public Functions /// <summary> /// Add the player to the list, in order to get manage /// by this manager. /// </summary> /// <param name="player"> Player to add to the list. </param> public void AddPlayerToManage(JCS_Player player) { if (player == null) { return; } mPlayers.Add(player); }
private void OnTriggerStay(Collider other) { JCS_Player p = other.GetComponent<JCS_Player>(); if (p == null) return; // switch the scene. DoPortal(mType, p); }
//---------------------- // Protected Variables //======================================== // setter / getter //------------------------------ //======================================== // Unity's function //------------------------------ private void OnTriggerStay(Collider other) { JCS_Player player = other.GetComponent <JCS_Player>(); if (player == null) { return; } player.VelX += mPushSpeed * -(int)mDirection * Time.deltaTime; }
/// <summary> /// Check if is on top of the lean platform. /// </summary> /// <param name="player"></param> /// <returns> /// true: is on top of the box. /// false: vice versa. /// </returns> public virtual bool IsOpTopOfLeanPlatform(JCS_Player player) { if (mPositionPlatform == null || player == null) { return(false); } bool isTopOfBox = JCS_Physics.TopOfBox( player.GetCharacterController(), mPositionPlatform.GetPlatformCollider()); return(isTopOfBox); }
/// <summary> /// This player will be in the active player slot. /// </summary> /// <param name="player"> player to be active. </param> public void ActiveOnePlayer(JCS_Player player) { foreach (JCS_Player p in mPlayers) { if (p == player) { p.ControlEnable(true); mActivePlayer = p; } else { p.ControlEnable(false); } } }
protected virtual void OnTriggerExit(Collider other) { JCS_Player player = JCS_GameManager.instance.GetJCSPlayer(); if (player == null) { return; } if (other.gameObject.name == player.name) { Physics.IgnoreCollision(mPlatformCollider, player.GetCharacterController(), false); } }
//======================================== // 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 /// <summary> /// /// </summary> public void DoPortal(JCS_3DPortalType type, JCS_Player player) { switch (type) { case JCS_3DPortalType.SCENE_PORTAL: { if (!mAutoTrigger) { if (JCS_Input.GetKey(mKeyToTrigger)) { JCS_SceneManager.instance.LoadScene(mSceneName); } } else { // auto do the action JCS_SceneManager.instance.LoadScene(mSceneName); } } break; case JCS_3DPortalType.TRANSFER_PORTAL: { if (!mAutoTrigger) { if (JCS_Input.GetKeyDown(mKeyToTrigger)) { if (mTargetPortal != null) { player.transform.position = mTargetPortal.position; } } } else { // auto do the action if (mTargetPortal != null) { player.transform.position = mTargetPortal.position; } } } break; } }
/// <summary> /// Pick the item up. /// </summary> /// <param name="other"></param> public void Pick(Collider other) { if (!mCanPick) { return; } JCS_OneJump joj = this.GetComponent <JCS_OneJump>(); if (joj != null) { // Only when item is on the ground! if (joj.GetVelocity().y != 0) { return; } } JCS_Player p = other.GetComponent <JCS_Player>(); if (mAutoPickColliderTouched && p != null) { DoPick(other); return; } if (mMustBeActivePlayer) { // Check the colliding object are is active player. if (JCS_PlayerManager.instance.IsActivePlayerTransform(other.transform)) { DoPick(other); } } else { DoPick(other); } }
/// <summary> /// Set the player to current portal label. /// </summary> private void SetPlayerToPortalByLabel() { JCS_PortalSettings jcsPs = JCS_PortalSettings.instance; // check manager exists? if (jcsPs == null) { return; } // check effect enable? if (!jcsPs.RESET_POSITION_AT_START) { return; } mPortals = JCS_Utility.RemoveEmptySlotIncludeMissing <JCS_2DPortal>(mPortals); foreach (JCS_2DPortal portal in mPortals) { if (portal.PortalLabel == jcsPs.SCENE_PORTAL_LABEL) { // get the player JCS_Player player = JCS_PlayerManager.instance.GetActivePlayer(); // NOTE(jenchieh): this uses execution order in Unity Engine. // move the player to portal position. player.transform.position = portal.transform.position; // set the camera position JCS_Camera.main.SetPosition( portal.transform.position.x, portal.transform.position.y); break; } } }
/* Functions */ protected override void Awake() { base.Awake(); this.mSpriteRenderer = this.GetComponent <SpriteRenderer>(); this.m2DAnimator = this.GetComponent <JCS_2DAnimator>(); // try to get this component in this transform. if (mVelocityInfo == null) { mVelocityInfo = this.GetComponent <JCS_VelocityInfo>(); } if (mAbilityFormat == null) { mAbilityFormat = this.GetComponent <JCS_AbilityFormat>(); } if (mAttackRecorder == null) { mAttackRecorder = this.GetComponent <JCS_AttackerRecorder>(); } // auto detect to see if this gameobject player or not. JCS_Player p = this.GetComponent <JCS_Player>(); // if found it return true! if (p != null) { mIsPlayer = true; } else { mIsPlayer = false; } // set hp the same mPreCalHP = HP; }
public void SetJCSPlayer(JCS_Player player) { this.mJCSPlayer = player; }
public void RemoveTargetFromTrackList(JCS_Player p) { mTargetList.slice(p); }
/// <summary> /// Finding Player but using the list /// instead of the list of player /// current manager handled. /// </summary> /// <param name="direction"> direction u want to search </param> /// <param name="players"> player u want to search </param> /// <returns> player with that direction. </returns> public JCS_Player FindPlayerByDirectionUsingList(JCS_2D4Direction direction, List <JCS_Player> players) { if (players.Count == 0) { JCS_Debug.LogError( "JCS_PlayerManager", "Cannot use the current function cuz the player list in the manager is lower than 0..."); return(null); } Vector3 foundPos = players[0].transform.position; int foundIndex = 0; JCS_Player currentPlayer = null; switch (direction) { case JCS_2D4Direction.TOP: { for (int index = 1; index < players.Count; ++index) { currentPlayer = players[index]; if (foundPos.y < currentPlayer.transform.position.y) { // update position if found the highest position foundPos = currentPlayer.transform.position; // update found index. foundIndex = index; } } } break; case JCS_2D4Direction.BOTTOM: { for (int index = 1; index < players.Count; ++index) { currentPlayer = players[index]; if (foundPos.y > currentPlayer.transform.position.y) { // update position if found the highest position foundPos = currentPlayer.transform.position; // update found index. foundIndex = index; } } } break; case JCS_2D4Direction.RIGHT: { for (int index = 1; index < players.Count; ++index) { currentPlayer = players[index]; if (foundPos.x < currentPlayer.transform.position.x) { // update position if found the highest position foundPos = currentPlayer.transform.position; // update found index. foundIndex = index; } } } break; case JCS_2D4Direction.LEFT: { for (int index = 1; index < players.Count; ++index) { currentPlayer = players[index]; if (foundPos.x > currentPlayer.transform.position.x) { // update position if found the highest position foundPos = currentPlayer.transform.position; // update found index. foundIndex = index; } } } break; } return(players[foundIndex]); }
//---------------------- // 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)); }
/// <summary> /// Do the portal by portal type. /// </summary> /// <param name="player"> Player take effect by the portal. </param> public void DoPortal(JCS_Player player) { DoPortal(mType, player); }
/// <summary> /// Return the player on the scene, according to /// the direction. /// </summary> /// <param name="direction"> position u want to find the player </param> /// <returns> player with the position </returns> public JCS_Player FindPlayerByDirection(JCS_2D4Direction direction) { if (GetPlayerList().Count == 0) { JCS_Debug.LogError("Can't use the current function cuz the player list in the manager is lower than 0..."); return(null); } Vector3 foundPos = GetPlayerAt(0).transform.position; int foundIndex = 0; JCS_Player currentPlayer = null; switch (direction) { case JCS_2D4Direction.TOP: { for (int index = 1; index < GetPlayerList().Count; ++index) { currentPlayer = GetPlayerAt(index); if (foundPos.y < currentPlayer.transform.position.y) { // update position if found the highest position foundPos = currentPlayer.transform.position; // update found index. foundIndex = index; } } } break; case JCS_2D4Direction.BOTTOM: { for (int index = 1; index < GetPlayerList().Count; ++index) { currentPlayer = GetPlayerAt(index); if (foundPos.y > currentPlayer.transform.position.y) { // update position if found the highest position foundPos = currentPlayer.transform.position; // update found index. foundIndex = index; } } } break; case JCS_2D4Direction.RIGHT: { for (int index = 1; index < GetPlayerList().Count; ++index) { currentPlayer = GetPlayerAt(index); if (foundPos.x < currentPlayer.transform.position.x) { // update position if found the highest position foundPos = currentPlayer.transform.position; // update found index. foundIndex = index; } } } break; case JCS_2D4Direction.LEFT: { for (int index = 1; index < GetPlayerList().Count; ++index) { currentPlayer = GetPlayerAt(index); if (foundPos.x > currentPlayer.transform.position.x) { // update position if found the highest position foundPos = currentPlayer.transform.position; // update found index. foundIndex = index; } } } break; } return(GetPlayerAt(foundIndex)); }
//======================================== // Self-Define //------------------------------ //---------------------- // Public Functions public void AddTargetToTrackList(JCS_Player p) { mTargetList.push(p); }