protected virtual void OnTriggerEnter(Collider other) { JCS_2DSideScrollerPlayer player = other.GetComponent <JCS_2DSideScrollerPlayer>(); if (player == null) { return; } AddSafe(player); bool isTopOfBox = JCS_Physics.TopOfBox( player.GetCharacterController(), mPositionPlatform.GetPlatformCollider()); if (isTopOfBox) { // show character behind the ladder int backOrderLayer = OrderLayerObject.sortingOrder - ClimbableManager.SORTING_ORDER_BEHIND_OFFSET; SetPlayerSortingOrder(player, backOrderLayer); } else { // show character infront int frontOrderLayer = OrderLayerObject.sortingOrder + ClimbableManager.SORTING_ORDER_INFRONT_OFFSET; SetPlayerSortingOrder(player, frontOrderLayer); } player.CanLadder = true; player.CanRope = false; player.ClimbableObject = this; }
/* Functions */ private void Awake() { mRandomMultiSoundAction = this.GetComponent <JCS_SoundPoolAction>(); // assign default spawn point if (mSpawnPoint == null) { mSpawnPoint = this.transform; } // try to get the ability format it own if (mAbilityFormat == null) { this.mAbilityFormat = this.GetComponent <JCS_AbilityFormat>(); } // try to get the detect area action it own if (mDetectAreaAction == null) { this.mDetectAreaAction = this.GetComponent <JCS_DetectAreaAction>(); } // try to get the player if (mPlayer == null) { this.mPlayer = this.GetComponent <JCS_2DSideScrollerPlayer>(); } }
protected virtual void OnTriggerExit(Collider other) { JCS_2DSideScrollerPlayer player = other.GetComponent <JCS_2DSideScrollerPlayer>(); if (player == null) { return; } player.ClimbableObject = null; player.GetCharacterAnimator().PlayAnimationInFrame(); player.CanLadder = false; RemoveNullPlayerAndSelf(player); }
/// <summary> /// Add object with no duplicate. /// </summary> /// <param name="player"></param> private void AddSafe(JCS_2DSideScrollerPlayer player) { for (int index = 0; index < mSSPlayers.Count; ++index) { // already in here. if (mSSPlayers[index] == player) { return; } } mSSPlayers.Add(player); }
/// <summary> /// If the player is no longer exists, remove the empty slot. /// </summary> /// <param name="player"></param> private void RemoveNullPlayerAndSelf(JCS_2DSideScrollerPlayer player = null) { for (int index = 0; index < mSSPlayers.Count; ++index) { // remove itself. if (mSSPlayers[index] == null) { mSSPlayers.RemoveAt(index); } if (mSSPlayers[index] == player) { mSSPlayers.RemoveAt(index); } } }
/// <summary> /// Set the player in specific sorting order /// layer. (JCS_OrderLayer) /// </summary> /// <param name="player"> player to sort </param> /// <param name="layer"> layer number/id. </param> private void SetPlayerSortingOrder(JCS_2DSideScrollerPlayer player, int layer) { player.OrderLayerObject.SetObjectParentToOrderLayerByOrderLayerIndex( layer); }
protected void OnTriggerStay(Collider other) { CharacterController cc = other.GetComponent <CharacterController>(); if (cc == null) { return; } bool isTopOfBox = JCS_Physics.TopOfBoxWithSlope(cc, mPlatformCollider); if (isTopOfBox) { Physics.IgnoreCollision( mPlatformCollider, cc, false); } else { Physics.IgnoreCollision( mPlatformCollider, cc, true); } JCS_2DSideScrollerPlayer p = other.GetComponent <JCS_2DSideScrollerPlayer>(); if (p == null) { return; } bool isJumpDown = p.IsDownJump(); if (!mCanBeDownJump) { // if cannot be down jump, fore it to false. isJumpDown = false; } if (p.CharacterState == JCS_2DCharacterState.CLIMBING || isJumpDown) { // IMPORTANT(JenChieh): Note that IgnoreCollision will reset // the trigger state of affected colliders, // so you might receive OnTriggerExit and // OnTriggerEnter messages in response to // calling this. Physics.IgnoreCollision( mPlatformCollider, p.GetCharacterController(), true); } if (isJumpDown && isTopOfBox) { if (JCS_PlatformSettings.instance != null) { /** * Make the player go down ward, so it will not stop by * the other collision detection. In order not to let the * render frame goes off. set the value as small as possible. */ p.VelY = -JCS_PlatformSettings.instance.POSITION_PLATFORM_DOWN_JUMP_FORCE; } else { JCS_Debug.Log( "No platform setting, could not set the down jump force..."); } } p.ResetingCollision = true; }