add ckg
plantilla base para movimiento básico
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace GameKitController.Player
|
||||
{
|
||||
public class AddPlayerSpawned : MonoBehaviour
|
||||
{
|
||||
private playerCharactersManager _playerCharactersManager;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
_playerCharactersManager = FindObjectOfType<playerCharactersManager>();
|
||||
|
||||
AddNewPlayerSpawned(gameObject);
|
||||
}
|
||||
|
||||
public void AddNewPlayerSpawned(GameObject gameObj)
|
||||
{
|
||||
if (gameObj == null) {
|
||||
gameObj = gameObject;
|
||||
}
|
||||
|
||||
_playerCharactersManager.addNewPlayerSpawned(gameObj);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 018b264a50b1b7748970207236110b8b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 40995
|
||||
packageName: Game Kit Controller - Shooter Melee Adventure Creator 3D + 2.5D
|
||||
packageVersion: 3.77g
|
||||
assetPath: Assets/Game Kit Controller/Scripts/Player/AddPlayerSpawned.cs
|
||||
uploadId: 814740
|
||||
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1c6249c8cb018f24ea0bc7ee92a7c7bd
|
||||
folderAsset: yes
|
||||
timeCreated: 1626772298
|
||||
licenseType: Store
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,567 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class IKFootSystem : OnAnimatorIKComponent
|
||||
{
|
||||
[Header ("Main Settings")]
|
||||
[Space]
|
||||
|
||||
public bool IKFootSystemEnabled = true;
|
||||
|
||||
public LayerMask layerMask;
|
||||
|
||||
[Space]
|
||||
|
||||
public float IKWeightEnabledSpeed = 10;
|
||||
public float IKWeightDisabledSpeed = 2;
|
||||
public float extraFootOffset = 0.005f;
|
||||
|
||||
public float minSurfaceAngleToUseIKFoot = 0.1f;
|
||||
|
||||
public float maxSurfaceAngleToUseIKFoot = 0;
|
||||
|
||||
[Space]
|
||||
[Header ("Hips Settings")]
|
||||
[Space]
|
||||
|
||||
//public bool adjustHipsPositionEnabled = true;
|
||||
|
||||
public float hipsMovementSpeed = 1.2f;
|
||||
public float hipsPositionUpClampAmount = 0.2f;
|
||||
public float hipsPositionDownClampAmount = -0.2f;
|
||||
|
||||
public float hipsPositionUpMovingClampAmount = 0.2f;
|
||||
public float hipsPositionDownMovingClampAmount = -0.2f;
|
||||
|
||||
[Space]
|
||||
[Header ("Other Settings")]
|
||||
[Space]
|
||||
|
||||
public bool disableComponentIfIKSystemNotEnabledOnStart = true;
|
||||
|
||||
[Space]
|
||||
[Header ("Leg Info List Settings")]
|
||||
[Space]
|
||||
|
||||
public List<legInfo> legInfoList = new List<legInfo> ();
|
||||
|
||||
[Space]
|
||||
[Header ("Debug")]
|
||||
[Space]
|
||||
|
||||
public bool canUseIkFoot;
|
||||
public bool IKFootPaused;
|
||||
|
||||
public bool removeIKValue;
|
||||
|
||||
public float currentSurfaceAngle;
|
||||
|
||||
public bool fullBodyAwarenessActive;
|
||||
|
||||
public bool canAdjustHipsPosition = true;
|
||||
|
||||
public Vector3 hipsPosition;
|
||||
|
||||
[Space]
|
||||
[Header ("Components")]
|
||||
[Space]
|
||||
|
||||
public playerController playerControllerManager;
|
||||
public Animator mainAnimator;
|
||||
public Transform playerTransform;
|
||||
|
||||
public Transform hips;
|
||||
|
||||
|
||||
float newHipsOffset;
|
||||
|
||||
bool usingIKFootPreviously;
|
||||
|
||||
float currentHipsOffset;
|
||||
|
||||
bool playerOnGround;
|
||||
|
||||
bool currentLegIsRight;
|
||||
|
||||
RaycastHit hit;
|
||||
|
||||
legInfo currentLegInfo;
|
||||
|
||||
float currentRaycastDistance;
|
||||
float currentAdjustmentSpeed;
|
||||
Vector3 currentRaycastPosition;
|
||||
float newRaycastDistance;
|
||||
|
||||
float newOffset;
|
||||
|
||||
Vector3 newFootPosition;
|
||||
Quaternion newFootRotation;
|
||||
float targetWeight;
|
||||
Vector3 localFootPosition;
|
||||
|
||||
Vector3 newKneePosition;
|
||||
|
||||
bool initialPositionAssigned;
|
||||
|
||||
Vector3 newRaycastPosition;
|
||||
Vector3 newLocalHipsPosition;
|
||||
|
||||
bool playerIsMoving;
|
||||
|
||||
bool checkRaycast;
|
||||
|
||||
int i;
|
||||
|
||||
Vector3 currentTransfrormUp;
|
||||
|
||||
Vector3 currentGravityNormal;
|
||||
|
||||
float currentWeightToApply;
|
||||
|
||||
AvatarIKGoal currentIKGoal;
|
||||
|
||||
AvatarIKHint currenIKHint;
|
||||
|
||||
float minIKValue = 0.001f;
|
||||
|
||||
Vector3 rightFootHitPoint;
|
||||
Vector3 leftFootHitPoint;
|
||||
|
||||
bool fullBodyAwarenessActiveChecked;
|
||||
|
||||
|
||||
|
||||
void Start ()
|
||||
{
|
||||
calculateInitialFootValues ();
|
||||
}
|
||||
|
||||
public void calculateInitialFootValues ()
|
||||
{
|
||||
for (i = 0; i < 2; i++) {
|
||||
currentLegInfo = legInfoList [i];
|
||||
|
||||
if (currentLegInfo.useCustomOffset) {
|
||||
currentLegInfo.offset = currentLegInfo.customOffset;
|
||||
} else {
|
||||
currentLegInfo.offset = playerTransform.InverseTransformPoint (currentLegInfo.foot.position).y;
|
||||
}
|
||||
|
||||
if (currentLegInfo.useCustomMaxLegLength) {
|
||||
currentLegInfo.maxLegLength = currentLegInfo.customMaxLegLength;
|
||||
} else {
|
||||
currentLegInfo.maxLegLength = playerTransform.InverseTransformPoint (currentLegInfo.lowerLeg.position).y;
|
||||
}
|
||||
}
|
||||
|
||||
hipsPosition = hips.position;
|
||||
|
||||
if (disableComponentIfIKSystemNotEnabledOnStart) {
|
||||
if (!IKFootSystemEnabled) {
|
||||
enabled = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void LateUpdate ()
|
||||
{
|
||||
if (!IKFootSystemEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
canUseIkFoot = true;
|
||||
|
||||
if (playerControllerManager.isPlayerDead () ||
|
||||
playerControllerManager.isPlayerDriving () ||
|
||||
playerControllerManager.isPlayerOnFirstPerson () ||
|
||||
(playerControllerManager.isPlayerOnFFOrZeroGravityModeOn () && !playerControllerManager.isPlayerOnGround ()) ||
|
||||
playerControllerManager.isUsingJetpack () ||
|
||||
playerControllerManager.isFlyingActive () ||
|
||||
playerControllerManager.isSwimModeActive () ||
|
||||
playerControllerManager.isMovingOnPlatformActive ()) {
|
||||
canUseIkFoot = false;
|
||||
}
|
||||
|
||||
if (usingIKFootPreviously != canUseIkFoot) {
|
||||
if (!usingIKFootPreviously) {
|
||||
hipsPosition = playerTransform.InverseTransformPoint (hips.position);
|
||||
}
|
||||
|
||||
usingIKFootPreviously = canUseIkFoot;
|
||||
}
|
||||
|
||||
if (!canUseIkFoot) {
|
||||
return;
|
||||
}
|
||||
|
||||
fullBodyAwarenessActive = playerControllerManager.isFullBodyAwarenessActive ();
|
||||
|
||||
if (fullBodyAwarenessActive) {
|
||||
if (!fullBodyAwarenessActiveChecked) {
|
||||
canAdjustHipsPosition = false;
|
||||
|
||||
fullBodyAwarenessActiveChecked = true;
|
||||
}
|
||||
} else {
|
||||
if (fullBodyAwarenessActiveChecked) {
|
||||
canAdjustHipsPosition = true;
|
||||
|
||||
fullBodyAwarenessActiveChecked = false;
|
||||
}
|
||||
}
|
||||
|
||||
//&& adjustHipsPositionEnabled
|
||||
|
||||
if (canAdjustHipsPosition) {
|
||||
hips.position = playerTransform.TransformPoint (hipsPosition);
|
||||
}
|
||||
|
||||
if (!initialPositionAssigned) {
|
||||
initialPositionAssigned = true;
|
||||
}
|
||||
}
|
||||
|
||||
public override void updateOnAnimatorIKState ()
|
||||
{
|
||||
if (!IKFootSystemEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!canUseIkFoot) {
|
||||
return;
|
||||
}
|
||||
|
||||
playerOnGround = playerControllerManager.isPlayerOnGround ();
|
||||
|
||||
newHipsOffset = 0f;
|
||||
|
||||
currentTransfrormUp = playerTransform.up;
|
||||
|
||||
if (playerOnGround) {
|
||||
for (i = 0; i < 2; i++) {
|
||||
currentLegInfo = legInfoList [i];
|
||||
//raycast from the foot
|
||||
|
||||
currentRaycastPosition = getNewRaycastPosition (currentLegInfo.foot.position, currentLegInfo.lowerLeg.position, out currentRaycastDistance);
|
||||
|
||||
newRaycastDistance = currentRaycastDistance + currentLegInfo.offset + currentLegInfo.maxLegLength - (extraFootOffset * 2);
|
||||
|
||||
checkRaycast = true;
|
||||
|
||||
if (float.IsNaN (currentRaycastPosition.x) && float.IsNaN (currentRaycastPosition.y) && float.IsNaN (currentRaycastPosition.z)) {
|
||||
checkRaycast = false;
|
||||
}
|
||||
|
||||
if (checkRaycast) {
|
||||
if (Physics.Raycast (currentRaycastPosition, -currentTransfrormUp, out hit, newRaycastDistance, layerMask)) {
|
||||
currentLegInfo.raycastDistance = currentRaycastDistance;
|
||||
currentLegInfo.surfaceDistance = hit.distance;
|
||||
currentLegInfo.surfacePoint = hit.point;
|
||||
currentLegInfo.surfaceNormal = hit.normal;
|
||||
} else {
|
||||
currentLegInfo.surfaceDistance = float.MaxValue;
|
||||
}
|
||||
} else {
|
||||
currentLegInfo.surfaceDistance = float.MaxValue;
|
||||
}
|
||||
|
||||
//raycast from the toe, if a closer object is found, the raycast used is the one in the toe
|
||||
|
||||
currentRaycastPosition = getNewRaycastPosition (currentLegInfo.toes.position, currentLegInfo.lowerLeg.position, out currentRaycastDistance);
|
||||
|
||||
newRaycastDistance = currentRaycastDistance + currentLegInfo.offset + currentLegInfo.maxLegLength - (extraFootOffset * 2);
|
||||
|
||||
checkRaycast = true;
|
||||
|
||||
if (float.IsNaN (currentRaycastPosition.x) && float.IsNaN (currentRaycastPosition.y) && float.IsNaN (currentRaycastPosition.z)) {
|
||||
checkRaycast = false;
|
||||
}
|
||||
|
||||
if (checkRaycast) {
|
||||
if (Physics.Raycast (currentRaycastPosition, -currentTransfrormUp, out hit, newRaycastDistance, layerMask)) {
|
||||
if (hit.distance < currentLegInfo.surfaceDistance && hit.normal == currentTransfrormUp) {
|
||||
currentLegInfo.raycastDistance = currentRaycastDistance;
|
||||
currentLegInfo.surfaceDistance = hit.distance;
|
||||
currentLegInfo.surfacePoint = hit.point;
|
||||
currentLegInfo.surfaceNormal = hit.normal;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Debug.DrawLine (currentRaycastPosition, currentRaycastPosition + playerTransform.up * 4, Color.red, 3);
|
||||
|
||||
if (currentLegInfo.surfaceDistance != float.MaxValue) {
|
||||
newOffset = currentLegInfo.surfaceDistance - currentLegInfo.raycastDistance - playerTransform.InverseTransformPoint (currentLegInfo.foot.position).y;
|
||||
|
||||
if (newOffset > newHipsOffset) {
|
||||
newHipsOffset = newOffset;
|
||||
}
|
||||
}
|
||||
|
||||
if (currentIKGoal == AvatarIKGoal.RightFoot) {
|
||||
rightFootHitPoint = currentLegInfo.surfacePoint;
|
||||
} else {
|
||||
leftFootHitPoint = currentLegInfo.surfacePoint;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
playerIsMoving = playerControllerManager.isPlayerMoving (0);
|
||||
|
||||
if (playerIsMoving) {
|
||||
newHipsOffset = Mathf.Clamp (newHipsOffset, hipsPositionDownMovingClampAmount, hipsPositionUpMovingClampAmount);
|
||||
} else {
|
||||
newHipsOffset = Mathf.Clamp (newHipsOffset, hipsPositionDownClampAmount, hipsPositionUpClampAmount);
|
||||
}
|
||||
|
||||
if (IKFootPaused) {
|
||||
newHipsOffset = 0;
|
||||
}
|
||||
|
||||
//set hips position
|
||||
if (initialPositionAssigned) {
|
||||
currentHipsOffset = Mathf.Lerp (currentHipsOffset, newHipsOffset, hipsMovementSpeed * Time.fixedDeltaTime);
|
||||
} else {
|
||||
currentHipsOffset = newHipsOffset;
|
||||
}
|
||||
|
||||
hipsPosition = playerTransform.InverseTransformPoint (hips.position);
|
||||
|
||||
hipsPosition.y -= currentHipsOffset;
|
||||
|
||||
currentGravityNormal = playerControllerManager.getCurrentNormal ();
|
||||
|
||||
//set position and rotation on player's feet
|
||||
for (i = 0; i < 2; i++) {
|
||||
currentLegInfo = legInfoList [i];
|
||||
|
||||
currentIKGoal = currentLegInfo.IKGoal;
|
||||
|
||||
newFootPosition = mainAnimator.GetIKPosition (currentIKGoal);
|
||||
|
||||
newFootRotation = mainAnimator.GetIKRotation (currentIKGoal);
|
||||
|
||||
targetWeight = currentLegInfo.IKWeight - 1;
|
||||
|
||||
currentAdjustmentSpeed = IKWeightDisabledSpeed;
|
||||
|
||||
if (playerOnGround) {
|
||||
if (currentLegInfo.surfaceDistance != float.MaxValue) {
|
||||
if (playerTransform.InverseTransformDirection (newFootPosition - currentLegInfo.surfacePoint).y - currentLegInfo.offset - extraFootOffset - currentHipsOffset < 0) {
|
||||
localFootPosition = playerTransform.InverseTransformPoint (newFootPosition);
|
||||
localFootPosition.y = playerTransform.InverseTransformPoint (currentLegInfo.surfacePoint).y;
|
||||
|
||||
newFootPosition = playerTransform.TransformPoint (localFootPosition) +
|
||||
(currentLegInfo.offset + currentHipsOffset - extraFootOffset) * currentTransfrormUp;
|
||||
|
||||
newFootRotation = Quaternion.LookRotation (Vector3.Cross (currentLegInfo.surfaceNormal, newFootRotation * -Vector3.right), currentTransfrormUp);
|
||||
|
||||
targetWeight = currentLegInfo.IKWeight + 1;
|
||||
currentAdjustmentSpeed = IKWeightEnabledSpeed;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
removeIKValue = false;
|
||||
|
||||
if (IKFootPaused) {
|
||||
removeIKValue = true;
|
||||
}
|
||||
|
||||
if (!removeIKValue) {
|
||||
currentSurfaceAngle = playerControllerManager.getCurrentSurfaceHitAngle ();
|
||||
|
||||
if (currentSurfaceAngle < minSurfaceAngleToUseIKFoot) {
|
||||
removeIKValue = true;
|
||||
}
|
||||
|
||||
if (maxSurfaceAngleToUseIKFoot > 0) {
|
||||
if (Mathf.Abs (currentSurfaceAngle) > maxSurfaceAngleToUseIKFoot) {
|
||||
removeIKValue = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!removeIKValue) {
|
||||
if (!playerIsMoving && currentLegInfo.surfaceNormal == currentGravityNormal) {
|
||||
float footHeightDifference = Mathf.Abs (playerTransform.InverseTransformPoint (leftFootHitPoint).y) -
|
||||
Mathf.Abs (playerTransform.InverseTransformPoint (rightFootHitPoint).y);
|
||||
if (Mathf.Abs (footHeightDifference) < 0.02f) {
|
||||
removeIKValue = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (removeIKValue) {
|
||||
targetWeight = 0;
|
||||
}
|
||||
|
||||
if (initialPositionAssigned) {
|
||||
currentLegInfo.IKWeight = Mathf.Clamp01 (Mathf.Lerp (currentLegInfo.IKWeight, targetWeight, currentAdjustmentSpeed * Time.fixedDeltaTime));
|
||||
} else {
|
||||
currentLegInfo.IKWeight = Mathf.Clamp01 (targetWeight);
|
||||
}
|
||||
|
||||
currentWeightToApply = currentLegInfo.IKWeight;
|
||||
|
||||
if (currentWeightToApply >= minIKValue) {
|
||||
|
||||
mainAnimator.SetIKPosition (currentIKGoal, newFootPosition);
|
||||
mainAnimator.SetIKRotation (currentIKGoal, newFootRotation);
|
||||
|
||||
mainAnimator.SetIKPositionWeight (currentIKGoal, currentWeightToApply);
|
||||
mainAnimator.SetIKRotationWeight (currentIKGoal, currentWeightToApply);
|
||||
}
|
||||
|
||||
if (currentLegInfo.useKneeIK) {
|
||||
if (!playerIsMoving || !currentLegInfo.adjustOnlyWhenNotMoving) {
|
||||
|
||||
currenIKHint = currentLegInfo.IKHint;
|
||||
|
||||
newKneePosition = mainAnimator.GetIKHintPosition (currenIKHint);
|
||||
|
||||
newKneePosition += (currentLegInfo.kneeOffset.x * playerTransform.right) +
|
||||
(currentLegInfo.kneeOffset.y * playerTransform.up) +
|
||||
(currentLegInfo.kneeOffset.z * playerTransform.forward);
|
||||
|
||||
if (currentLegInfo.useLerpForIKHintWeight) {
|
||||
currentLegInfo.currentIKHintWeight = Mathf.Clamp01 (Mathf.Lerp (currentLegInfo.currentIKHintWeight,
|
||||
currentWeightToApply, currentLegInfo.lerpSpeedForIKHintWeight * Time.fixedDeltaTime));
|
||||
} else {
|
||||
currentLegInfo.currentIKHintWeight = currentWeightToApply;
|
||||
}
|
||||
|
||||
currentLegInfo.currentIKHintWeight *= currentLegInfo.IKHintWeightMultiplier;
|
||||
|
||||
if (removeIKValue) {
|
||||
currentLegInfo.currentIKHintWeight = 0;
|
||||
}
|
||||
|
||||
mainAnimator.SetIKHintPositionWeight (currenIKHint, currentLegInfo.currentIKHintWeight);
|
||||
|
||||
mainAnimator.SetIKHintPosition (currenIKHint, newKneePosition);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Vector3 getNewRaycastPosition (Vector3 targetTransformPosition, Vector3 lowerLegPosition, out float newDistance)
|
||||
{
|
||||
newRaycastPosition = playerTransform.InverseTransformPoint (targetTransformPosition);
|
||||
newLocalHipsPosition = playerTransform.InverseTransformPoint (lowerLegPosition);
|
||||
|
||||
newDistance = (newLocalHipsPosition.y - newRaycastPosition.y);
|
||||
newRaycastPosition.y = newLocalHipsPosition.y;
|
||||
|
||||
return playerTransform.TransformPoint (newRaycastPosition);
|
||||
}
|
||||
|
||||
public void setIKFootPausedState (bool state)
|
||||
{
|
||||
IKFootPaused = state;
|
||||
}
|
||||
|
||||
public void setLegsInfo (Transform newHips, Transform rightLowerLeg, Transform leftLowerLeg, Transform rightFoot, Transform leftFoot, Transform rightToes, Transform leftToes)
|
||||
{
|
||||
hips = newHips;
|
||||
|
||||
for (i = 0; i < legInfoList.Count; i++) {
|
||||
if (legInfoList [i].IKGoal == AvatarIKGoal.RightFoot) {
|
||||
legInfoList [i].lowerLeg = rightLowerLeg;
|
||||
legInfoList [i].foot = rightFoot;
|
||||
legInfoList [i].toes = rightToes;
|
||||
} else {
|
||||
legInfoList [i].lowerLeg = leftLowerLeg;
|
||||
legInfoList [i].foot = leftFoot;
|
||||
legInfoList [i].toes = leftToes;
|
||||
}
|
||||
}
|
||||
|
||||
updateComponent ();
|
||||
}
|
||||
|
||||
public void setIKFootSystemEnabledState (bool state)
|
||||
{
|
||||
IKFootSystemEnabled = state;
|
||||
|
||||
if (IKFootSystemEnabled && disableComponentIfIKSystemNotEnabledOnStart) {
|
||||
if (Application.isPlaying) {
|
||||
if (!enabled) {
|
||||
enabled = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setIKFootSystemEnabledStateFromEditor (bool state)
|
||||
{
|
||||
setIKFootSystemEnabledState (state);
|
||||
|
||||
updateComponent ();
|
||||
}
|
||||
|
||||
public void updateComponent ()
|
||||
{
|
||||
GKC_Utils.updateComponent (this);
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public class legInfo
|
||||
{
|
||||
[Header ("Main Settings")]
|
||||
[Space]
|
||||
|
||||
public string Name;
|
||||
public AvatarIKGoal IKGoal;
|
||||
|
||||
[Space]
|
||||
|
||||
public Transform lowerLeg;
|
||||
public Transform foot;
|
||||
public Transform toes;
|
||||
|
||||
[Space]
|
||||
[Header ("Other Settings")]
|
||||
[Space]
|
||||
|
||||
public bool useCustomOffset;
|
||||
public float customOffset;
|
||||
|
||||
[Space]
|
||||
|
||||
public bool useCustomMaxLegLength;
|
||||
public float customMaxLegLength;
|
||||
|
||||
[Space]
|
||||
[Header ("Knee Settings")]
|
||||
[Space]
|
||||
|
||||
public bool useKneeIK;
|
||||
public AvatarIKHint IKHint;
|
||||
public Vector3 kneeOffset;
|
||||
public bool adjustOnlyWhenNotMoving;
|
||||
|
||||
public float IKHintWeightMultiplier = 1;
|
||||
|
||||
public bool useLerpForIKHintWeight;
|
||||
public float lerpSpeedForIKHintWeight;
|
||||
|
||||
[Space]
|
||||
[Header ("Debug")]
|
||||
[Space]
|
||||
|
||||
public float IKWeight;
|
||||
public float offset;
|
||||
public float maxLegLength;
|
||||
public float raycastDistance;
|
||||
public float surfaceDistance;
|
||||
public Vector3 surfacePoint;
|
||||
public Vector3 surfaceNormal;
|
||||
|
||||
[Space]
|
||||
[Space]
|
||||
|
||||
public float currentIKHintWeight;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 92dee05715eb2d342a993d775438908c
|
||||
timeCreated: 1548926669
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 40995
|
||||
packageName: Game Kit Controller - Shooter Melee Adventure Creator 3D + 2.5D
|
||||
packageVersion: 3.77g
|
||||
assetPath: Assets/Game Kit Controller/Scripts/Player/Animator IK/IKFootSystem.cs
|
||||
uploadId: 814740
|
||||
2203
Assets/Game Kit Controller/Scripts/Player/Animator IK/IKSystem.cs
Normal file
2203
Assets/Game Kit Controller/Scripts/Player/Animator IK/IKSystem.cs
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e7b3304a7d85fff42a88d74355f0f2f2
|
||||
timeCreated: 1457548976
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 40995
|
||||
packageName: Game Kit Controller - Shooter Melee Adventure Creator 3D + 2.5D
|
||||
packageVersion: 3.77g
|
||||
assetPath: Assets/Game Kit Controller/Scripts/Player/Animator IK/IKSystem.cs
|
||||
uploadId: 814740
|
||||
@@ -0,0 +1,55 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class OnAnimatorIKComponent : MonoBehaviour
|
||||
{
|
||||
public bool updateIKEnabled = true;
|
||||
|
||||
public virtual void updateOnAnimatorIKState ()
|
||||
{
|
||||
if (!updateIKEnabled) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
public void setUpdateIKEnabledState (bool state)
|
||||
{
|
||||
updateIKEnabled = state;
|
||||
}
|
||||
|
||||
public bool isUpdateIKEnabled ()
|
||||
{
|
||||
return updateIKEnabled;
|
||||
}
|
||||
|
||||
public virtual void setActiveState (bool state)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public virtual void enableBothHands ()
|
||||
{
|
||||
enableOrDisableRightOrLeftHand (true, false, true);
|
||||
}
|
||||
|
||||
public virtual void enableOnlyLeftHand ()
|
||||
{
|
||||
enableOrDisableRightOrLeftHand (true, false, false);
|
||||
}
|
||||
|
||||
public virtual void enableOnlyRightHand ()
|
||||
{
|
||||
enableOrDisableRightOrLeftHand (true, true, false);
|
||||
}
|
||||
|
||||
public virtual void enableOrDisableRightOrLeftHand (bool state, bool isRightHand, bool setStateOnBothHands)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public virtual void setCharacterElements (GameObject newCharacter)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d5d9fd7fda0983a4a8ae9ff8f4009681
|
||||
timeCreated: 1626186969
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 40995
|
||||
packageName: Game Kit Controller - Shooter Melee Adventure Creator 3D + 2.5D
|
||||
packageVersion: 3.77g
|
||||
assetPath: Assets/Game Kit Controller/Scripts/Player/Animator IK/OnAnimatorIKComponent.cs
|
||||
uploadId: 814740
|
||||
@@ -0,0 +1,445 @@
|
||||
using UnityEngine;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine.Events;
|
||||
|
||||
public class handsOnMeleeWeaponIKSystem : OnAnimatorIKComponent
|
||||
{
|
||||
[Header ("Main Settings")]
|
||||
[Space]
|
||||
|
||||
public bool adjustHandsEnabled = true;
|
||||
|
||||
public float weightLerpSpeed = 6;
|
||||
|
||||
public float busyBodyPartWeightLerpSpeed = 3;
|
||||
|
||||
public float minWaitTimeToActiveHands = 0.3f;
|
||||
|
||||
[Space]
|
||||
[Header ("Hands Info List Settings")]
|
||||
[Space]
|
||||
|
||||
public List<handInfo> handInfoList = new List<handInfo> ();
|
||||
|
||||
[Space]
|
||||
[Header ("Debug")]
|
||||
[Space]
|
||||
|
||||
public bool showDebugPrint;
|
||||
public bool handsOnMeleeActive;
|
||||
|
||||
public bool usingHands;
|
||||
|
||||
public bool isBusy;
|
||||
|
||||
public bool adjustHandsPaused;
|
||||
|
||||
public bool smoothBusyDisableActive;
|
||||
|
||||
public bool handsCheckPausedWithDelayActive;
|
||||
|
||||
[Space]
|
||||
[Header ("Event Settings")]
|
||||
[Space]
|
||||
|
||||
public bool useEventsOnActiveStateChange;
|
||||
public UnityEvent eventOnActive;
|
||||
public UnityEvent eventOnDeactivate;
|
||||
|
||||
[Space]
|
||||
[Header ("Component Elements")]
|
||||
[Space]
|
||||
|
||||
public Animator animator;
|
||||
public IKSystem IKManager;
|
||||
public playerController playerControllerManager;
|
||||
public meleeWeaponsGrabbedManager mainMeleeWeaponsGrabbedManager;
|
||||
|
||||
handInfo currentHandInfo;
|
||||
|
||||
bool isThirdPersonView;
|
||||
|
||||
float originalWeightLerpSpeed;
|
||||
|
||||
float currentWeightToApply;
|
||||
|
||||
AvatarIKGoal currentIKGoal;
|
||||
|
||||
int handInfoListCount;
|
||||
|
||||
float minIKValue = 0.001f;
|
||||
|
||||
Coroutine delayToResumeStateCoroutine;
|
||||
|
||||
bool valuesInitialized;
|
||||
|
||||
float lastTimeHandsActive = 0;
|
||||
|
||||
float currentWeightLerpSpeed;
|
||||
|
||||
|
||||
public override void updateOnAnimatorIKState ()
|
||||
{
|
||||
if (handsOnMeleeActive) {
|
||||
isThirdPersonView = !playerControllerManager.isPlayerOnFirstPerson ();
|
||||
|
||||
usingHands = IKManager.getUsingHands ();
|
||||
|
||||
if (IKManager.isObjectGrabbed ()) {
|
||||
usingHands = false;
|
||||
}
|
||||
|
||||
isBusy = playerIsBusy ();
|
||||
|
||||
if (Time.time < lastTimeHandsActive + minWaitTimeToActiveHands) {
|
||||
isBusy = true;
|
||||
}
|
||||
|
||||
bool IKBodyPaused = IKManager.isIKBodyPaused ();
|
||||
|
||||
bool pauseIKBodyResult = playerControllerManager.isActionActive () ||
|
||||
mainMeleeWeaponsGrabbedManager.isAimingBowActive () ||
|
||||
mainMeleeWeaponsGrabbedManager.isCuttingModeActive ();
|
||||
|
||||
if (!isBusy || smoothBusyDisableActive) {
|
||||
|
||||
for (int j = 0; j < handInfoListCount; j++) {
|
||||
|
||||
currentHandInfo = handInfoList [j];
|
||||
|
||||
if (currentHandInfo.IKBodyPartEnabled) {
|
||||
if (IKBodyPaused || pauseIKBodyResult) {
|
||||
if (!currentHandInfo.bodyPartBusy) {
|
||||
currentHandInfo.bodyPartBusy = true;
|
||||
currentHandInfo.IKBodyWeigthTarget = 0;
|
||||
}
|
||||
} else {
|
||||
|
||||
if (!usingHands) {
|
||||
if (currentHandInfo.bodyPartBusy) {
|
||||
currentHandInfo.bodyPartBusy = false;
|
||||
currentHandInfo.IKBodyWeigthTarget = 1;
|
||||
} else {
|
||||
currentHandInfo.IKBodyWeigthTarget = 1;
|
||||
}
|
||||
} else {
|
||||
if (!currentHandInfo.bodyPartBusy) {
|
||||
currentHandInfo.bodyPartBusy = true;
|
||||
currentHandInfo.IKBodyWeigthTarget = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (currentHandInfo.currentIKWeight != currentHandInfo.IKBodyWeigthTarget) {
|
||||
|
||||
if (currentHandInfo.bodyPartBusy) {
|
||||
currentWeightLerpSpeed = busyBodyPartWeightLerpSpeed;
|
||||
} else {
|
||||
currentWeightLerpSpeed = weightLerpSpeed;
|
||||
}
|
||||
|
||||
currentHandInfo.currentIKWeight = Mathf.MoveTowards (currentHandInfo.currentIKWeight,
|
||||
currentHandInfo.IKBodyWeigthTarget, Time.fixedDeltaTime * currentWeightLerpSpeed);
|
||||
}
|
||||
|
||||
bool applyIKToBodyPart = false;
|
||||
|
||||
if (!currentHandInfo.bodyPartBusy) {
|
||||
|
||||
currentHandInfo.IKGoalPosition = currentHandInfo.targetToFollow.position;
|
||||
currentHandInfo.IKGoalRotation = currentHandInfo.targetToFollow.rotation;
|
||||
|
||||
applyIKToBodyPart = true;
|
||||
|
||||
} else if (currentHandInfo.currentIKWeight != currentHandInfo.IKBodyWeigthTarget) {
|
||||
applyIKToBodyPart = true;
|
||||
}
|
||||
|
||||
if (applyIKToBodyPart) {
|
||||
|
||||
currentWeightToApply = currentHandInfo.currentIKWeight;
|
||||
|
||||
if (currentWeightToApply > minIKValue) {
|
||||
currentIKGoal = currentHandInfo.IKGoal;
|
||||
|
||||
animator.SetIKRotationWeight (currentIKGoal, currentWeightToApply);
|
||||
animator.SetIKPositionWeight (currentIKGoal, currentWeightToApply);
|
||||
animator.SetIKPosition (currentIKGoal, currentHandInfo.IKGoalPosition);
|
||||
animator.SetIKRotation (currentIKGoal, currentHandInfo.IKGoalRotation);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (int j = 0; j < handInfoListCount; j++) {
|
||||
|
||||
currentHandInfo = handInfoList [j];
|
||||
|
||||
currentHandInfo.bodyPartBusy = false;
|
||||
|
||||
currentHandInfo.IKBodyWeigthTarget = 0;
|
||||
|
||||
currentHandInfo.currentIKWeight = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool playerIsBusy ()
|
||||
{
|
||||
return
|
||||
|
||||
(usingHands && !IKManager.isObjectGrabbed ()) ||
|
||||
!isThirdPersonView ||
|
||||
playerControllerManager.isPlayerOnFFOrZeroGravityModeOn () ||
|
||||
playerControllerManager.isUsingCloseCombatActive () ||
|
||||
playerControllerManager.isPlayerDead () ||
|
||||
adjustHandsPaused ||
|
||||
playerControllerManager.isUsingJetpack () ||
|
||||
playerControllerManager.isFlyingActive () ||
|
||||
playerControllerManager.isSwimModeActive ();
|
||||
}
|
||||
|
||||
public void setWeightLerpSpeedValue (float newValue)
|
||||
{
|
||||
weightLerpSpeed = newValue;
|
||||
}
|
||||
|
||||
public void setOriginalWeightLerpSpeed ()
|
||||
{
|
||||
setWeightLerpSpeedValue (originalWeightLerpSpeed);
|
||||
}
|
||||
|
||||
public void setAdjustHandsPausedState (bool state)
|
||||
{
|
||||
adjustHandsPaused = state;
|
||||
}
|
||||
|
||||
public void setSmoothBusyDisableActiveState (bool state)
|
||||
{
|
||||
smoothBusyDisableActive = state;
|
||||
}
|
||||
|
||||
public void setAdjustHandsEnabledState (bool state)
|
||||
{
|
||||
adjustHandsEnabled = state;
|
||||
}
|
||||
|
||||
|
||||
public void enableHandsCheckPausedWithDelayActive (float duration)
|
||||
{
|
||||
stopUpdateDelayToResumeStateCoroutine ();
|
||||
|
||||
delayToResumeStateCoroutine = StartCoroutine (updateDelayToResumeStateCoroutine (duration));
|
||||
}
|
||||
|
||||
public void stopUpdateDelayToResumeStateCoroutine ()
|
||||
{
|
||||
if (delayToResumeStateCoroutine != null) {
|
||||
StopCoroutine (delayToResumeStateCoroutine);
|
||||
}
|
||||
|
||||
handsCheckPausedWithDelayActive = false;
|
||||
}
|
||||
|
||||
IEnumerator updateDelayToResumeStateCoroutine (float duration)
|
||||
{
|
||||
handsCheckPausedWithDelayActive = true;
|
||||
|
||||
WaitForSeconds delay = new WaitForSeconds (duration);
|
||||
|
||||
yield return delay;
|
||||
|
||||
handsCheckPausedWithDelayActive = false;
|
||||
}
|
||||
|
||||
public override void enableBothHands ()
|
||||
{
|
||||
enableOrDisableRightOrLeftHand (true, false, true);
|
||||
}
|
||||
|
||||
public override void enableOnlyLeftHand ()
|
||||
{
|
||||
enableOrDisableRightOrLeftHand (true, false, false);
|
||||
}
|
||||
|
||||
public override void enableOnlyRightHand ()
|
||||
{
|
||||
enableOrDisableRightOrLeftHand (true, true, false);
|
||||
}
|
||||
|
||||
public override void enableOrDisableRightOrLeftHand (bool state, bool isRightHand, bool setStateOnBothHands)
|
||||
{
|
||||
if (showDebugPrint) {
|
||||
print (state + " " + isRightHand + " " + setStateOnBothHands);
|
||||
}
|
||||
|
||||
handInfoListCount = handInfoList.Count;
|
||||
|
||||
for (int j = 0; j < handInfoListCount; j++) {
|
||||
|
||||
currentHandInfo = handInfoList [j];
|
||||
|
||||
if (setStateOnBothHands) {
|
||||
currentHandInfo.IKBodyPartEnabled = state;
|
||||
} else {
|
||||
if (currentHandInfo.isRightHand) {
|
||||
if (isRightHand) {
|
||||
currentHandInfo.IKBodyPartEnabled = state;
|
||||
} else {
|
||||
currentHandInfo.IKBodyPartEnabled = false;
|
||||
|
||||
currentHandInfo.bodyPartBusy = false;
|
||||
|
||||
currentHandInfo.IKBodyWeigthTarget = 0;
|
||||
|
||||
currentHandInfo.currentIKWeight = 0;
|
||||
}
|
||||
} else {
|
||||
if (isRightHand) {
|
||||
currentHandInfo.IKBodyPartEnabled = false;
|
||||
|
||||
currentHandInfo.bodyPartBusy = false;
|
||||
|
||||
currentHandInfo.IKBodyWeigthTarget = 0;
|
||||
|
||||
currentHandInfo.currentIKWeight = 0;
|
||||
} else {
|
||||
currentHandInfo.IKBodyPartEnabled = state;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool checkEnableEventsResult = currentHandInfo.IKBodyPartEnabled;
|
||||
|
||||
if (currentHandInfo.useEventOnIKPartEnabledStateChange) {
|
||||
if (checkEnableEventsResult) {
|
||||
currentHandInfo.eventOnIKPartEnabled.Invoke ();
|
||||
} else {
|
||||
currentHandInfo.eventOnIKPartDisabled.Invoke ();
|
||||
}
|
||||
}
|
||||
|
||||
if (showDebugPrint) {
|
||||
print (currentHandInfo.Name + " " + checkEnableEventsResult + " " + currentHandInfo.bodyPartBusy);
|
||||
}
|
||||
}
|
||||
|
||||
if (showDebugPrint) {
|
||||
for (int j = 0; j < handInfoListCount; j++) {
|
||||
|
||||
currentHandInfo = handInfoList [j];
|
||||
|
||||
print (currentHandInfo.isRightHand + " " + currentHandInfo.IKBodyPartEnabled);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void setActiveState (bool state)
|
||||
{
|
||||
if (!adjustHandsEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (handsOnMeleeActive == state) {
|
||||
return;
|
||||
}
|
||||
|
||||
handsOnMeleeActive = state;
|
||||
|
||||
if (handsOnMeleeActive) {
|
||||
if (!valuesInitialized) {
|
||||
originalWeightLerpSpeed = weightLerpSpeed;
|
||||
|
||||
handInfoListCount = handInfoList.Count;
|
||||
|
||||
valuesInitialized = true;
|
||||
}
|
||||
|
||||
lastTimeHandsActive = Time.time;
|
||||
} else {
|
||||
for (int j = 0; j < handInfoListCount; j++) {
|
||||
|
||||
currentHandInfo = handInfoList [j];
|
||||
|
||||
currentHandInfo.bodyPartBusy = false;
|
||||
|
||||
currentHandInfo.IKBodyWeigthTarget = 0;
|
||||
|
||||
currentHandInfo.currentIKWeight = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (useEventsOnActiveStateChange) {
|
||||
if (state) {
|
||||
eventOnActive.Invoke ();
|
||||
} else {
|
||||
eventOnDeactivate.Invoke ();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void disableStateIfNotCurrentlyActiveOnIKSystem ()
|
||||
{
|
||||
if (handsOnMeleeActive) {
|
||||
if (!IKManager.checkIfTemporalOnAnimatorIKComponentIfIsCurrent (this)) {
|
||||
setActiveState (false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//EDITOR FUNCTIONS
|
||||
public void setAdjustHandsEnabledStateFromEditor (bool state)
|
||||
{
|
||||
setAdjustHandsEnabledState (state);
|
||||
|
||||
updateComponent ();
|
||||
}
|
||||
|
||||
void updateComponent ()
|
||||
{
|
||||
GKC_Utils.updateComponent (this);
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public class handInfo
|
||||
{
|
||||
[Header ("Main Settings")]
|
||||
[Space]
|
||||
|
||||
public string Name;
|
||||
public bool IKBodyPartEnabled = true;
|
||||
|
||||
public bool isRightHand;
|
||||
|
||||
public Transform targetToFollow;
|
||||
|
||||
[Space]
|
||||
[Header ("IK Settings")]
|
||||
[Space]
|
||||
|
||||
public AvatarIKGoal IKGoal;
|
||||
|
||||
[Space]
|
||||
[Header ("Debug")]
|
||||
[Space]
|
||||
|
||||
public bool bodyPartBusy;
|
||||
|
||||
public float currentIKWeight;
|
||||
public float IKBodyWeigthTarget;
|
||||
|
||||
[HideInInspector] public Vector3 IKGoalPosition;
|
||||
[HideInInspector] public Quaternion IKGoalRotation;
|
||||
|
||||
[Space]
|
||||
[Header ("Event Settings")]
|
||||
[Space]
|
||||
|
||||
public bool useEventOnIKPartEnabledStateChange;
|
||||
public UnityEvent eventOnIKPartEnabled;
|
||||
public UnityEvent eventOnIKPartDisabled;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2f06345fd3ad781458c9f7b286542fc0
|
||||
timeCreated: 1698018505
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 40995
|
||||
packageName: Game Kit Controller - Shooter Melee Adventure Creator 3D + 2.5D
|
||||
packageVersion: 3.77g
|
||||
assetPath: Assets/Game Kit Controller/Scripts/Player/Animator IK/handsOnMeleeWeaponIKSystem.cs
|
||||
uploadId: 814740
|
||||
@@ -0,0 +1,595 @@
|
||||
using UnityEngine;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
public class handsOnSurfaceIKSystem : OnAnimatorIKComponent
|
||||
{
|
||||
[Header ("Main Settings")]
|
||||
[Space]
|
||||
|
||||
public bool adjustHandsToSurfacesEnabled = true;
|
||||
|
||||
public LayerMask layerToAdjustHandsToSurfaces;
|
||||
|
||||
public float movementSpeedLerpSpeed = 2;
|
||||
|
||||
public float waitTimeAfterGroundToCheckSurface = 1.5f;
|
||||
public float waitTimeAfterCrouchToCheckSurface = 1.5f;
|
||||
|
||||
public float weightLerpSpeed = 6;
|
||||
|
||||
public float maxHandsDistance = 3;
|
||||
|
||||
public float minMovingInputToUseWalkSpeed = 0.5f;
|
||||
public float minIKWeightToUseWalkSpeed = 0.4f;
|
||||
|
||||
public bool pauseHandsOnSurfaceIfCloseCombatActive;
|
||||
|
||||
[Space]
|
||||
[Header ("Hands Info List Settings")]
|
||||
[Space]
|
||||
|
||||
public List<handsToSurfaceInfo> handsToSurfaceInfoList = new List<handsToSurfaceInfo> ();
|
||||
|
||||
[Space]
|
||||
[Header ("Debug")]
|
||||
[Space]
|
||||
|
||||
public bool usingHands;
|
||||
public bool adjustHandsPaused;
|
||||
|
||||
public bool smoothBusyDisableActive;
|
||||
|
||||
public bool handsCheckPausedWithDelayActive;
|
||||
|
||||
public bool isBusy;
|
||||
|
||||
[Space]
|
||||
[Header ("Gizmo Settings")]
|
||||
[Space]
|
||||
|
||||
public bool showGizmo;
|
||||
public Color gizmoColor = Color.white;
|
||||
public float gizmoRadius;
|
||||
|
||||
[Space]
|
||||
[Header ("Component Elements")]
|
||||
[Space]
|
||||
|
||||
public Animator animator;
|
||||
public IKSystem IKManager;
|
||||
public playerController playerControllerManager;
|
||||
public Transform playerTransform;
|
||||
|
||||
handsToSurfaceInfo currentHandInfo;
|
||||
Vector3 rayDirection;
|
||||
|
||||
RaycastHit hit;
|
||||
float movementSpeed;
|
||||
float currentMovementSpeed;
|
||||
|
||||
bool isThirdPersonView;
|
||||
|
||||
bool onGround;
|
||||
|
||||
bool movingOnPlatformActive;
|
||||
|
||||
bool dead;
|
||||
|
||||
bool groundChecked;
|
||||
float lastTimeOnGround;
|
||||
|
||||
bool crouchingChecked;
|
||||
float lastTimeCrouch;
|
||||
|
||||
Vector3 currentPositionCenter;
|
||||
|
||||
float currentRotationSpeed;
|
||||
|
||||
float originalWeightLerpSpeed;
|
||||
|
||||
bool crouching;
|
||||
|
||||
Transform rightHandTransform;
|
||||
Transform leftHandTransform;
|
||||
|
||||
bool isRightHand;
|
||||
|
||||
multipleRayInfo currentMultipleRayInfo;
|
||||
|
||||
Vector3 currentTransformUp;
|
||||
|
||||
Vector3 currentTransformForward;
|
||||
|
||||
Vector3 vector3Zero = Vector3.zero;
|
||||
|
||||
Quaternion targetRotation;
|
||||
|
||||
Vector3 currentHandPosition;
|
||||
|
||||
float currentWeightToApply;
|
||||
|
||||
AvatarIKGoal currentIKGoal;
|
||||
|
||||
int handsToSurfaceInfoListCount;
|
||||
|
||||
float minIKValue = 0.001f;
|
||||
|
||||
float currentDeltaTime;
|
||||
|
||||
Coroutine delayToResumeStateCoroutine;
|
||||
|
||||
|
||||
void Start ()
|
||||
{
|
||||
originalWeightLerpSpeed = weightLerpSpeed;
|
||||
|
||||
rightHandTransform = animator.GetBoneTransform (HumanBodyBones.RightHand);
|
||||
|
||||
leftHandTransform = animator.GetBoneTransform (HumanBodyBones.LeftHand);
|
||||
|
||||
handsToSurfaceInfoListCount = handsToSurfaceInfoList.Count;
|
||||
}
|
||||
|
||||
void FixedUpdate ()
|
||||
{
|
||||
if (!adjustHandsToSurfacesEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
isThirdPersonView = !playerControllerManager.isPlayerOnFirstPerson ();
|
||||
|
||||
usingHands = IKManager.getUsingHands ();
|
||||
|
||||
onGround = playerControllerManager.isPlayerOnGround ();
|
||||
|
||||
movingOnPlatformActive = playerControllerManager.isMovingOnPlatformActive ();
|
||||
|
||||
isBusy = playerIsBusy ();
|
||||
|
||||
crouching = playerControllerManager.isCrouching ();
|
||||
|
||||
dead = playerControllerManager.isPlayerDead ();
|
||||
|
||||
if (groundChecked != onGround) {
|
||||
groundChecked = onGround;
|
||||
|
||||
if (onGround) {
|
||||
lastTimeOnGround = Time.time;
|
||||
}
|
||||
}
|
||||
|
||||
if (crouchingChecked != crouching) {
|
||||
crouchingChecked = crouching;
|
||||
|
||||
if (!crouching) {
|
||||
lastTimeCrouch = Time.time;
|
||||
}
|
||||
}
|
||||
|
||||
if (adjustHandsToSurfacesEnabled) {
|
||||
if (!isBusy || smoothBusyDisableActive) {
|
||||
|
||||
currentTransformUp = playerTransform.up;
|
||||
currentTransformForward = playerTransform.forward;
|
||||
|
||||
for (int j = 0; j < handsToSurfaceInfoListCount; j++) {
|
||||
|
||||
currentHandInfo = handsToSurfaceInfoList [j];
|
||||
|
||||
currentHandInfo.surfaceFound = false;
|
||||
currentHandInfo.multipleRaycastHitNormal = vector3Zero;
|
||||
currentHandInfo.multipleRaycastHitPoint = vector3Zero;
|
||||
currentHandInfo.numberOfSurfacesFound = 0;
|
||||
currentHandInfo.multipleRaycastDirection = vector3Zero;
|
||||
|
||||
for (int k = 0; k < currentHandInfo.raycastTransformList.Count; k++) {
|
||||
currentMultipleRayInfo = currentHandInfo.raycastTransformList [k];
|
||||
|
||||
rayDirection = currentMultipleRayInfo.raycastTransform.forward;
|
||||
|
||||
if (currentMultipleRayInfo.raycastEnabled &&
|
||||
Physics.Raycast (currentMultipleRayInfo.raycastTransform.position, rayDirection, out hit,
|
||||
currentMultipleRayInfo.rayCastDistance, layerToAdjustHandsToSurfaces)) {
|
||||
|
||||
currentMultipleRayInfo.hitPoint = hit.point;
|
||||
currentMultipleRayInfo.hitNormal = hit.normal;
|
||||
currentHandInfo.surfaceFound = true;
|
||||
currentHandInfo.multipleRaycastHitNormal += hit.normal;
|
||||
currentHandInfo.multipleRaycastHitPoint += hit.point;
|
||||
|
||||
currentHandInfo.numberOfSurfacesFound++;
|
||||
currentHandInfo.multipleRaycastDirection += rayDirection;
|
||||
|
||||
if (showGizmo) {
|
||||
Debug.DrawRay (currentMultipleRayInfo.raycastTransform.position, hit.distance * rayDirection, Color.green);
|
||||
}
|
||||
} else {
|
||||
if (showGizmo) {
|
||||
Debug.DrawRay (currentMultipleRayInfo.raycastTransform.position,
|
||||
currentMultipleRayInfo.rayCastDistance * rayDirection, Color.red);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (smoothBusyDisableActive) {
|
||||
currentHandInfo.surfaceFound = false;
|
||||
|
||||
if (currentWeightInBothHandsEqualTo (0)) {
|
||||
smoothBusyDisableActive = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (currentHandInfo.surfaceFound) {
|
||||
currentHandInfo.handPosition =
|
||||
(currentHandInfo.multipleRaycastHitPoint / currentHandInfo.numberOfSurfacesFound) +
|
||||
(currentHandInfo.handSurfaceOffset * currentHandInfo.multipleRaycastDirection / currentHandInfo.numberOfSurfacesFound);
|
||||
|
||||
targetRotation = Quaternion.LookRotation (currentHandInfo.multipleRaycastDirection / currentHandInfo.numberOfSurfacesFound);
|
||||
|
||||
currentHandInfo.handRotation =
|
||||
Quaternion.FromToRotation (currentTransformUp, currentHandInfo.multipleRaycastHitNormal / currentHandInfo.numberOfSurfacesFound) * targetRotation;
|
||||
|
||||
currentHandInfo.elbowPosition =
|
||||
((currentHandInfo.multipleRaycastHitPoint / currentHandInfo.numberOfSurfacesFound) + currentHandInfo.raycastTransform.position) / 2 - currentTransformUp * 0.1f;
|
||||
|
||||
currentHandInfo.handWeight = 1;
|
||||
|
||||
if (currentHandInfo.useMinDistance) {
|
||||
currentHandInfo.currentDistance = GKC_Utils.distance (currentHandInfo.raycastTransform.position, currentHandInfo.handPosition);
|
||||
|
||||
if (currentHandInfo.currentDistance < currentHandInfo.minDistance) {
|
||||
currentHandInfo.surfaceFound = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (handsCheckPausedWithDelayActive ||
|
||||
!currentHandInfo.surfaceFound ||
|
||||
movingOnPlatformActive ||
|
||||
!onGround ||
|
||||
Time.time < waitTimeAfterGroundToCheckSurface + lastTimeOnGround ||
|
||||
crouching ||
|
||||
Time.time < waitTimeAfterCrouchToCheckSurface + lastTimeCrouch ||
|
||||
dead) {
|
||||
|
||||
currentHandInfo.handPosition = currentHandInfo.noSurfaceHandPosition.position;
|
||||
currentHandInfo.handRotation = Quaternion.LookRotation (currentTransformForward);
|
||||
|
||||
currentHandInfo.elbowPosition = currentHandInfo.noSurfaceElbowPosition.position;
|
||||
|
||||
currentHandInfo.handWeight = 0;
|
||||
}
|
||||
|
||||
if (playerControllerManager.isPlayerMoving (minMovingInputToUseWalkSpeed) &&
|
||||
currentHandInfo.surfaceFound && currentHandInfo.currentHandWeight > minIKWeightToUseWalkSpeed) {
|
||||
movementSpeed = currentHandInfo.walkingMovementSpeed;
|
||||
} else {
|
||||
movementSpeed = currentHandInfo.movementSpeed;
|
||||
}
|
||||
|
||||
currentDeltaTime = Time.deltaTime;
|
||||
|
||||
currentMovementSpeed = Mathf.Lerp (currentMovementSpeed, movementSpeed, currentDeltaTime * movementSpeedLerpSpeed);
|
||||
|
||||
currentHandInfo.currentHandPosition = Vector3.Lerp (currentHandInfo.currentHandPosition, currentHandInfo.handPosition, currentDeltaTime * currentMovementSpeed);
|
||||
|
||||
currentRotationSpeed = currentDeltaTime * currentHandInfo.rotationSpeed;
|
||||
|
||||
if (currentRotationSpeed > 0) {
|
||||
currentHandInfo.currentHandRotation = Quaternion.Lerp (currentHandInfo.currentHandRotation, currentHandInfo.handRotation, currentRotationSpeed);
|
||||
}
|
||||
|
||||
currentHandInfo.currentElbowPosition = Vector3.Lerp (currentHandInfo.currentElbowPosition, currentHandInfo.elbowPosition, currentDeltaTime * currentMovementSpeed);
|
||||
|
||||
currentHandInfo.currentHandWeight = Mathf.Lerp (currentHandInfo.currentHandWeight, currentHandInfo.handWeight, currentDeltaTime * weightLerpSpeed);
|
||||
|
||||
if (currentHandInfo.currentHandWeight < 0.01f) {
|
||||
currentHandInfo.handPosition = currentHandInfo.noSurfaceHandPosition.position;
|
||||
currentHandInfo.handRotation = Quaternion.LookRotation (currentTransformForward);
|
||||
|
||||
currentHandInfo.elbowPosition = currentHandInfo.noSurfaceElbowPosition.position;
|
||||
|
||||
currentHandInfo.currentHandPosition = currentHandInfo.handPosition;
|
||||
|
||||
currentHandInfo.currentHandRotation = currentHandInfo.handRotation;
|
||||
|
||||
currentHandInfo.currentElbowPosition = currentHandInfo.elbowPosition;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
||||
currentTransformForward = playerTransform.forward;
|
||||
|
||||
for (int j = 0; j < handsToSurfaceInfoListCount; j++) {
|
||||
|
||||
currentHandInfo = handsToSurfaceInfoList [j];
|
||||
|
||||
currentHandInfo.surfaceFound = false;
|
||||
|
||||
currentHandInfo.handWeight = 0;
|
||||
|
||||
currentHandInfo.currentHandWeight = 0;
|
||||
currentHandInfo.handPosition = currentHandInfo.noSurfaceHandPosition.position;
|
||||
currentHandInfo.handRotation = Quaternion.LookRotation (currentTransformForward);
|
||||
|
||||
currentHandInfo.elbowPosition = currentHandInfo.noSurfaceElbowPosition.position;
|
||||
|
||||
currentHandInfo.currentHandPosition = currentHandInfo.handPosition;
|
||||
|
||||
currentHandInfo.currentHandRotation = currentHandInfo.handRotation;
|
||||
|
||||
currentHandInfo.currentElbowPosition = currentHandInfo.elbowPosition;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool currentWeightInBothHandsEqualTo (float weightValue)
|
||||
{
|
||||
int numberOfHands = 0;
|
||||
|
||||
for (int j = 0; j < handsToSurfaceInfoListCount; j++) {
|
||||
if (handsToSurfaceInfoList [j].currentHandWeight == weightValue) {
|
||||
numberOfHands++;
|
||||
}
|
||||
}
|
||||
|
||||
if (numberOfHands == 2) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public override void updateOnAnimatorIKState ()
|
||||
{
|
||||
if (adjustHandsToSurfacesEnabled) {
|
||||
|
||||
if (!isBusy || smoothBusyDisableActive) {
|
||||
|
||||
currentPositionCenter = playerTransform.position + playerTransform.up;
|
||||
|
||||
for (int j = 0; j < handsToSurfaceInfoListCount; j++) {
|
||||
|
||||
currentHandInfo = handsToSurfaceInfoList [j];
|
||||
|
||||
isRightHand = currentHandInfo.isRightHand;
|
||||
|
||||
currentHandPosition = currentHandInfo.currentHandPosition;
|
||||
|
||||
if (float.IsNaN (currentHandPosition.x)) {
|
||||
if (isRightHand) {
|
||||
currentHandPosition.x = rightHandTransform.position.x;
|
||||
} else {
|
||||
currentHandPosition.x = leftHandTransform.position.x;
|
||||
}
|
||||
}
|
||||
|
||||
if (float.IsNaN (currentHandPosition.y)) {
|
||||
if (isRightHand) {
|
||||
currentHandPosition.y = rightHandTransform.position.y;
|
||||
} else {
|
||||
currentHandPosition.y = leftHandTransform.position.y;
|
||||
}
|
||||
}
|
||||
|
||||
if (float.IsNaN (currentHandPosition.z)) {
|
||||
if (isRightHand) {
|
||||
currentHandPosition.z = rightHandTransform.position.z;
|
||||
} else {
|
||||
currentHandPosition.z = leftHandTransform.position.z;
|
||||
}
|
||||
}
|
||||
|
||||
currentHandPosition.x =
|
||||
Mathf.Clamp (currentHandPosition.x, currentPositionCenter.x - maxHandsDistance, currentPositionCenter.x + maxHandsDistance);
|
||||
currentHandPosition.y =
|
||||
Mathf.Clamp (currentHandPosition.y, currentPositionCenter.y - maxHandsDistance, currentPositionCenter.y + maxHandsDistance);
|
||||
currentHandPosition.z =
|
||||
Mathf.Clamp (currentHandPosition.z, currentPositionCenter.z - maxHandsDistance, currentPositionCenter.z + maxHandsDistance);
|
||||
|
||||
currentHandInfo.currentHandPosition = currentHandPosition;
|
||||
|
||||
|
||||
currentWeightToApply = currentHandInfo.currentHandWeight;
|
||||
|
||||
if (currentWeightToApply > minIKValue) {
|
||||
|
||||
currentIKGoal = currentHandInfo.IKGoal;
|
||||
|
||||
animator.SetIKRotationWeight (currentIKGoal, currentWeightToApply);
|
||||
animator.SetIKPositionWeight (currentIKGoal, currentWeightToApply);
|
||||
|
||||
animator.SetIKPosition (currentIKGoal, currentHandInfo.currentHandPosition);
|
||||
animator.SetIKRotation (currentIKGoal, currentHandInfo.currentHandRotation);
|
||||
|
||||
animator.SetIKHintPositionWeight (currentHandInfo.IKHint, currentWeightToApply);
|
||||
animator.SetIKHintPosition (currentHandInfo.IKHint, currentHandInfo.currentElbowPosition);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool playerIsBusy ()
|
||||
{
|
||||
return
|
||||
|
||||
usingHands ||
|
||||
!isThirdPersonView ||
|
||||
playerControllerManager.isPlayerOnFFOrZeroGravityModeOn () ||
|
||||
(playerControllerManager.isUsingCloseCombatActive () && pauseHandsOnSurfaceIfCloseCombatActive) ||
|
||||
playerControllerManager.iscloseCombatAttackInProcess () ||
|
||||
playerControllerManager.isActionActive () ||
|
||||
adjustHandsPaused ||
|
||||
playerControllerManager.isUsingJetpack () ||
|
||||
playerControllerManager.isFlyingActive () ||
|
||||
playerControllerManager.isSwimModeActive () ||
|
||||
playerControllerManager.isCarryingPhysicalObject ();
|
||||
}
|
||||
|
||||
public void setWeightLerpSpeedValue (float newValue)
|
||||
{
|
||||
weightLerpSpeed = newValue;
|
||||
}
|
||||
|
||||
public void setOriginalWeightLerpSpeed ()
|
||||
{
|
||||
setWeightLerpSpeedValue (originalWeightLerpSpeed);
|
||||
}
|
||||
|
||||
public void setAdjustHandsPausedState (bool state)
|
||||
{
|
||||
adjustHandsPaused = state;
|
||||
}
|
||||
|
||||
public void setSmoothBusyDisableActiveState (bool state)
|
||||
{
|
||||
smoothBusyDisableActive = state;
|
||||
}
|
||||
|
||||
public void setAdjustHandsToSurfacesEnabledState (bool state)
|
||||
{
|
||||
adjustHandsToSurfacesEnabled = state;
|
||||
}
|
||||
|
||||
|
||||
public void enableHandsCheckPausedWithDelayActive (float duration)
|
||||
{
|
||||
stopUpdateDelayToResumeStateCoroutine ();
|
||||
|
||||
delayToResumeStateCoroutine = StartCoroutine (updateDelayToResumeStateCoroutine (duration));
|
||||
}
|
||||
|
||||
public void stopUpdateDelayToResumeStateCoroutine ()
|
||||
{
|
||||
if (delayToResumeStateCoroutine != null) {
|
||||
StopCoroutine (delayToResumeStateCoroutine);
|
||||
}
|
||||
|
||||
handsCheckPausedWithDelayActive = false;
|
||||
}
|
||||
|
||||
IEnumerator updateDelayToResumeStateCoroutine (float duration)
|
||||
{
|
||||
handsCheckPausedWithDelayActive = true;
|
||||
|
||||
WaitForSeconds delay = new WaitForSeconds (duration);
|
||||
|
||||
yield return delay;
|
||||
|
||||
handsCheckPausedWithDelayActive = false;
|
||||
}
|
||||
|
||||
|
||||
//EDITOR FUNCTIONS
|
||||
public void setAdjustHandsToSurfacesEnabledStateFromEditor (bool state)
|
||||
{
|
||||
setAdjustHandsToSurfacesEnabledState (state);
|
||||
|
||||
updateComponent ();
|
||||
}
|
||||
|
||||
void updateComponent ()
|
||||
{
|
||||
GKC_Utils.updateComponent (this);
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
void OnDrawGizmos ()
|
||||
{
|
||||
if (!showGizmo) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (GKC_Utils.isCurrentSelectionActiveGameObject (gameObject)) {
|
||||
DrawGizmos ();
|
||||
}
|
||||
}
|
||||
|
||||
void OnDrawGizmosSelected ()
|
||||
{
|
||||
DrawGizmos ();
|
||||
}
|
||||
|
||||
void DrawGizmos ()
|
||||
{
|
||||
if (showGizmo) {
|
||||
for (int j = 0; j < handsToSurfaceInfoList.Count; j++) {
|
||||
Gizmos.color = Color.green;
|
||||
Gizmos.DrawSphere (handsToSurfaceInfoList [j].handPosition, gizmoRadius);
|
||||
|
||||
Gizmos.color = Color.yellow;
|
||||
Gizmos.DrawSphere (handsToSurfaceInfoList [j].elbowPosition, gizmoRadius);
|
||||
|
||||
Gizmos.color = gizmoColor;
|
||||
Gizmos.DrawSphere (handsToSurfaceInfoList [j].currentHandPosition, gizmoRadius);
|
||||
Gizmos.DrawSphere (handsToSurfaceInfoList [j].currentElbowPosition, gizmoRadius);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
[System.Serializable]
|
||||
public class handsToSurfaceInfo
|
||||
{
|
||||
public string Name;
|
||||
public Transform raycastTransform;
|
||||
|
||||
public bool useMultipleRaycast;
|
||||
public List<multipleRayInfo> raycastTransformList = new List<multipleRayInfo> ();
|
||||
|
||||
public AvatarIKHint IKHint;
|
||||
[HideInInspector] public Vector3 elbowPosition;
|
||||
[HideInInspector] public Vector3 currentElbowPosition;
|
||||
|
||||
public bool isRightHand;
|
||||
public AvatarIKGoal IKGoal;
|
||||
public float handSurfaceOffset;
|
||||
public float rayCastDistance;
|
||||
|
||||
public float currentHandWeight;
|
||||
|
||||
public float movementSpeed;
|
||||
public float rotationSpeed;
|
||||
|
||||
public float walkingMovementSpeed;
|
||||
|
||||
[HideInInspector] public bool surfaceFound;
|
||||
|
||||
public bool useMinDistance;
|
||||
public float minDistance;
|
||||
|
||||
[HideInInspector]public float currentDistance;
|
||||
|
||||
[HideInInspector] public Vector3 multipleRaycastDirection;
|
||||
|
||||
[HideInInspector] public int numberOfSurfacesFound;
|
||||
[HideInInspector] public Vector3 multipleRaycastHitNormal;
|
||||
[HideInInspector] public Vector3 multipleRaycastHitPoint;
|
||||
|
||||
[HideInInspector] public float handWeight;
|
||||
[HideInInspector] public Vector3 handPosition;
|
||||
[HideInInspector] public Quaternion handRotation;
|
||||
|
||||
[HideInInspector] public Vector3 currentHandPosition;
|
||||
[HideInInspector] public Quaternion currentHandRotation;
|
||||
|
||||
public Transform noSurfaceHandPosition;
|
||||
public Transform noSurfaceElbowPosition;
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public class multipleRayInfo
|
||||
{
|
||||
public Transform raycastTransform;
|
||||
public bool surfaceFound;
|
||||
[HideInInspector] public Vector3 hitPoint;
|
||||
[HideInInspector] public Vector3 hitNormal;
|
||||
public float rayCastDistance;
|
||||
public bool raycastEnabled = true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9cfcfa56079afbc42a6379886d12b52f
|
||||
timeCreated: 1538062040
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 40995
|
||||
packageName: Game Kit Controller - Shooter Melee Adventure Creator 3D + 2.5D
|
||||
packageVersion: 3.77g
|
||||
assetPath: Assets/Game Kit Controller/Scripts/Player/Animator IK/handsOnSurfaceIKSystem.cs
|
||||
uploadId: 814740
|
||||
@@ -0,0 +1,48 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class simpleIKHand : OnAnimatorIKComponent
|
||||
{
|
||||
[Header ("Main Settings")]
|
||||
[Space]
|
||||
|
||||
public bool simpleIKHandActive;
|
||||
|
||||
public float IKWeight;
|
||||
|
||||
public AvatarIKGoal handIKGoal;
|
||||
|
||||
[Space]
|
||||
[Header ("Components")]
|
||||
[Space]
|
||||
|
||||
public Animator mainAnimator;
|
||||
|
||||
public Transform IKPositionTransform;
|
||||
|
||||
public override void updateOnAnimatorIKState ()
|
||||
{
|
||||
if (simpleIKHandActive) {
|
||||
mainAnimator.SetIKRotationWeight (handIKGoal, IKWeight);
|
||||
mainAnimator.SetIKPositionWeight (handIKGoal, IKWeight);
|
||||
mainAnimator.SetIKPosition (handIKGoal, IKPositionTransform.position);
|
||||
mainAnimator.SetIKRotation (handIKGoal, IKPositionTransform.rotation);
|
||||
}
|
||||
}
|
||||
|
||||
public override void setActiveState (bool state)
|
||||
{
|
||||
simpleIKHandActive = state;
|
||||
}
|
||||
|
||||
public override void setCharacterElements (GameObject newCharacter)
|
||||
{
|
||||
playerComponentsManager currentPlayerComponentsManager = newCharacter.GetComponent<playerComponentsManager> ();
|
||||
|
||||
if (currentPlayerComponentsManager != null) {
|
||||
mainAnimator = currentPlayerComponentsManager.getPlayerController ().getCharacterAnimator ();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 11d0773023d38d44eb305df5d8dd896d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 40995
|
||||
packageName: Game Kit Controller - Shooter Melee Adventure Creator 3D + 2.5D
|
||||
packageVersion: 3.77g
|
||||
assetPath: Assets/Game Kit Controller/Scripts/Player/Animator IK/simpleIKHand.cs
|
||||
uploadId: 814740
|
||||
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: baa02415aa11a1242854cc7434295d14
|
||||
folderAsset: yes
|
||||
timeCreated: 1626772068
|
||||
licenseType: Store
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,274 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class bodyMountPointsSystem : MonoBehaviour
|
||||
{
|
||||
[Header ("Main Setting")]
|
||||
[Space]
|
||||
|
||||
public bool useBoneTransformToLocateBone = true;
|
||||
|
||||
public List<bodyMountPointInfo> bodyMountPointInfoList = new List<bodyMountPointInfo> ();
|
||||
|
||||
[Space]
|
||||
[Header ("Editor Setting")]
|
||||
[Space]
|
||||
|
||||
public string mountPointToEditName;
|
||||
|
||||
public Vector3 mountPointInitialPositionOffset = new Vector3 (-0.008f, -0.1237f, -0.0205f);
|
||||
public Vector3 mountPointInitialEulerOffset = new Vector3 (47.453f, 0, -15.026f);
|
||||
|
||||
public bool showGizmo;
|
||||
|
||||
[Space]
|
||||
[Header ("Debug")]
|
||||
[Space]
|
||||
|
||||
public bool editingMountPoint;
|
||||
|
||||
public Transform temporalMountPointTransform;
|
||||
|
||||
public GameObject temporalMountPointObjectReference;
|
||||
|
||||
[Space]
|
||||
[Header ("Components")]
|
||||
[Space]
|
||||
|
||||
public Animator mainAnimator;
|
||||
|
||||
public GameObject mountPointObjectReferencePrefab;
|
||||
|
||||
|
||||
public void setCharacterBodyMountPointsInfoList ()
|
||||
{
|
||||
for (int i = 0; i < bodyMountPointInfoList.Count; i++) {
|
||||
|
||||
setIndividualCharacterBodyMountPointInfoByName (bodyMountPointInfoList [i].Name);
|
||||
}
|
||||
}
|
||||
|
||||
public void setIndividualCharacterBodyMountPointInfoByName (string mountPointName)
|
||||
{
|
||||
int mountPointIndex = bodyMountPointInfoList.FindIndex (s => s.Name.ToLower ().Equals (mountPointName.ToLower ()));
|
||||
|
||||
if (mountPointIndex <= -1) {
|
||||
return;
|
||||
}
|
||||
|
||||
bodyMountPointInfo currentBodyMountPointInfo = bodyMountPointInfoList [mountPointIndex];
|
||||
|
||||
Transform currentBone = null;
|
||||
|
||||
if (currentBodyMountPointInfo.useCustomBoneTransform) {
|
||||
currentBone = currentBodyMountPointInfo.customBoneTransform;
|
||||
}
|
||||
|
||||
if (currentBone == null) {
|
||||
currentBone = mainAnimator.GetBoneTransform (currentBodyMountPointInfo.boneToAttach);
|
||||
}
|
||||
|
||||
if (currentBone == null) {
|
||||
currentBone = mainAnimator.GetBoneTransform (currentBodyMountPointInfo.alternativeBoneToAttach);
|
||||
}
|
||||
|
||||
if (currentBone == null) {
|
||||
currentBone = mainAnimator.GetBoneTransform (HumanBodyBones.Hips);
|
||||
|
||||
if (currentBone == null) {
|
||||
currentBone = mainAnimator.transform;
|
||||
|
||||
print ("WARNING: No bone found on character body elements list for " + currentBodyMountPointInfo.Name + "" +
|
||||
" setting that character element inside the character model " + currentBone.name);
|
||||
}
|
||||
}
|
||||
|
||||
if (!useBoneTransformToLocateBone) {
|
||||
if (currentBone == null && mainAnimator != null) {
|
||||
currentBone = mainAnimator.transform;
|
||||
}
|
||||
}
|
||||
|
||||
if (currentBone != null) {
|
||||
for (int j = 0; j < currentBodyMountPointInfo.objectPointInfoList.Count; j++) {
|
||||
objectPointInfo currentObjectPointInfo = currentBodyMountPointInfo.objectPointInfoList [j];
|
||||
|
||||
if (currentObjectPointInfo.objectTransform != null) {
|
||||
Vector3 targetPosition = Vector3.zero;
|
||||
Vector3 targerEuler = Vector3.zero;
|
||||
|
||||
if (currentObjectPointInfo.setPreviousLocalValues) {
|
||||
targetPosition = currentObjectPointInfo.objectTransform.localPosition;
|
||||
targerEuler = currentObjectPointInfo.objectTransform.localEulerAngles;
|
||||
}
|
||||
|
||||
currentObjectPointInfo.objectTransform.SetParent (currentBone);
|
||||
|
||||
if (currentObjectPointInfo.setPreviousLocalValues) {
|
||||
currentObjectPointInfo.objectTransform.localPosition = targetPosition;
|
||||
currentObjectPointInfo.objectTransform.localEulerAngles = targerEuler;
|
||||
}
|
||||
|
||||
if (currentObjectPointInfo.usePositionOffset) {
|
||||
currentObjectPointInfo.objectTransform.localPosition = currentObjectPointInfo.positionOffset;
|
||||
}
|
||||
|
||||
if (currentObjectPointInfo.useEulerOffset) {
|
||||
currentObjectPointInfo.objectTransform.localEulerAngles = currentObjectPointInfo.eulerOffset;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Transform getMountPointTransformByName (string mountPointName)
|
||||
{
|
||||
for (int i = 0; i < bodyMountPointInfoList.Count; i++) {
|
||||
|
||||
bodyMountPointInfo currentBodyMountPointInfo = bodyMountPointInfoList [i];
|
||||
|
||||
if (currentBodyMountPointInfo.Name.Equals (mountPointName)) {
|
||||
if (currentBodyMountPointInfo.Name.Equals (mountPointName)) {
|
||||
return currentBodyMountPointInfo.objectPointInfoList [0].objectTransform;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public Transform getHumanBoneMountPointTransformByName (string mountPointName)
|
||||
{
|
||||
for (int i = 0; i < bodyMountPointInfoList.Count; i++) {
|
||||
|
||||
bodyMountPointInfo currentBodyMountPointInfo = bodyMountPointInfoList [i];
|
||||
|
||||
if (currentBodyMountPointInfo.Name.Equals (mountPointName)) {
|
||||
Transform currentBone = null;
|
||||
|
||||
if (currentBodyMountPointInfo.useCustomBoneTransform) {
|
||||
currentBone = currentBodyMountPointInfo.customBoneTransform;
|
||||
}
|
||||
|
||||
if (currentBone == null) {
|
||||
currentBone = mainAnimator.GetBoneTransform (currentBodyMountPointInfo.boneToAttach);
|
||||
}
|
||||
|
||||
if (currentBone == null) {
|
||||
currentBone = mainAnimator.GetBoneTransform (currentBodyMountPointInfo.alternativeBoneToAttach);
|
||||
}
|
||||
|
||||
return currentBone;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setCustomBoneMountPointTransformByName (string mountPointName, Transform newCUstomBoneTransform, bool state)
|
||||
{
|
||||
int mountPointIndex = bodyMountPointInfoList.FindIndex (s => s.Name.ToLower ().Equals (mountPointName.ToLower ()));
|
||||
|
||||
if (mountPointIndex > -1) {
|
||||
bodyMountPointInfo currentBodyMountPointInfo = bodyMountPointInfoList [mountPointIndex];
|
||||
currentBodyMountPointInfo.useCustomBoneTransform = state;
|
||||
|
||||
currentBodyMountPointInfo.customBoneTransform = newCUstomBoneTransform;
|
||||
}
|
||||
}
|
||||
|
||||
public void setCustomBoneMountPointTransformByNameFromEditor (string mountPointName, Transform newCUstomBoneTransform, bool state)
|
||||
{
|
||||
setCustomBoneMountPointTransformByName (mountPointName, newCUstomBoneTransform, state);
|
||||
|
||||
updateComponent ();
|
||||
}
|
||||
|
||||
public void toggleShowHandleGizmo ()
|
||||
{
|
||||
showGizmo = !showGizmo;
|
||||
}
|
||||
|
||||
public void toggleEditMountPoint ()
|
||||
{
|
||||
editingMountPoint = !editingMountPoint;
|
||||
|
||||
if (editingMountPoint) {
|
||||
int mountPointIndex = bodyMountPointInfoList.FindIndex (s => s.Name.ToLower () == mountPointToEditName.ToLower ());
|
||||
|
||||
if (mountPointIndex > -1) {
|
||||
bodyMountPointInfo temporalBodyMountPointInfo = bodyMountPointInfoList [mountPointIndex];
|
||||
|
||||
temporalMountPointTransform = temporalBodyMountPointInfo.objectPointInfoList [0].objectTransform;
|
||||
|
||||
if (temporalMountPointObjectReference == null) {
|
||||
temporalMountPointObjectReference = (GameObject)Instantiate (mountPointObjectReferencePrefab, Vector3.zero, Quaternion.identity, temporalMountPointTransform);
|
||||
}
|
||||
|
||||
temporalMountPointObjectReference.transform.SetParent (temporalMountPointTransform);
|
||||
|
||||
temporalMountPointObjectReference.transform.localPosition = mountPointInitialPositionOffset;
|
||||
|
||||
temporalMountPointObjectReference.transform.localEulerAngles = mountPointInitialEulerOffset;
|
||||
|
||||
|
||||
} else {
|
||||
print ("No mount point found");
|
||||
}
|
||||
} else {
|
||||
if (temporalMountPointObjectReference != null) {
|
||||
DestroyImmediate (temporalMountPointObjectReference);
|
||||
}
|
||||
|
||||
temporalMountPointTransform = null;
|
||||
}
|
||||
}
|
||||
|
||||
public void setNewAnimator (Animator newAnimator)
|
||||
{
|
||||
mainAnimator = newAnimator;
|
||||
|
||||
updateComponent ();
|
||||
}
|
||||
|
||||
void updateComponent ()
|
||||
{
|
||||
GKC_Utils.updateComponent (this);
|
||||
GKC_Utils.updateDirtyScene ("Update Body Mount Point System", gameObject);
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public class bodyMountPointInfo
|
||||
{
|
||||
public string Name;
|
||||
|
||||
public HumanBodyBones boneToAttach;
|
||||
public HumanBodyBones alternativeBoneToAttach;
|
||||
|
||||
[Space]
|
||||
|
||||
public bool useCustomBoneTransform;
|
||||
public Transform customBoneTransform;
|
||||
|
||||
[Space]
|
||||
|
||||
public List<objectPointInfo> objectPointInfoList = new List<objectPointInfo> ();
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public class objectPointInfo
|
||||
{
|
||||
public Transform objectTransform;
|
||||
|
||||
[Space]
|
||||
|
||||
public bool usePositionOffset;
|
||||
public Vector3 positionOffset;
|
||||
|
||||
public bool useEulerOffset;
|
||||
public Vector3 eulerOffset;
|
||||
|
||||
public bool setPreviousLocalValues;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: dbd4bec9345101449933209c684fd87e
|
||||
timeCreated: 1633558698
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 40995
|
||||
packageName: Game Kit Controller - Shooter Melee Adventure Creator 3D + 2.5D
|
||||
packageVersion: 3.77g
|
||||
assetPath: Assets/Game Kit Controller/Scripts/Player/Character Builder/bodyMountPointsSystem.cs
|
||||
uploadId: 814740
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,17 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 786e8d3b4b6818946b50a34313b5788a
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 40995
|
||||
packageName: Game Kit Controller - Shooter Melee Adventure Creator 3D + 2.5D
|
||||
packageVersion: 3.77g
|
||||
assetPath: Assets/Game Kit Controller/Scripts/Player/Character Builder/buildPlayer.cs
|
||||
uploadId: 814740
|
||||
@@ -0,0 +1,10 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
[CreateAssetMenu (fileName = "Character Settings Template", menuName = "GKC/Create Character Template", order = 51)]
|
||||
public class characterSettingsTemplate : ScriptableObject
|
||||
{
|
||||
public int characterTemplateID = 0;
|
||||
public List<buildPlayer.settingsInfoCategory> settingsInfoCategoryList = new List<buildPlayer.settingsInfoCategory> ();
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: dd63c29a68f5b01498e309ed46abe3ad
|
||||
timeCreated: 1598023720
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 40995
|
||||
packageName: Game Kit Controller - Shooter Melee Adventure Creator 3D + 2.5D
|
||||
packageVersion: 3.77g
|
||||
assetPath: Assets/Game Kit Controller/Scripts/Player/Character Builder/characterSettingsTemplate.cs
|
||||
uploadId: 814740
|
||||
@@ -0,0 +1,675 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using UnityEngine.Events;
|
||||
|
||||
public class ragdollBuilder : MonoBehaviour
|
||||
{
|
||||
[Header ("Animator Settings")]
|
||||
[Space]
|
||||
|
||||
public Animator animator;
|
||||
public ragdollActivator mainRagdollActivator;
|
||||
|
||||
[Space]
|
||||
[Header ("Skeleton Settings")]
|
||||
[Space]
|
||||
|
||||
public Transform head;
|
||||
public Transform rightElbow;
|
||||
public Transform leftElbow;
|
||||
public Transform rightArm;
|
||||
public Transform leftArm;
|
||||
public Transform middleSpine;
|
||||
public Transform pelvis;
|
||||
public Transform rightHips;
|
||||
public Transform leftHips;
|
||||
public Transform rightKnee;
|
||||
public Transform leftKnee;
|
||||
|
||||
[Space]
|
||||
[Header ("Main Settings")]
|
||||
[Space]
|
||||
|
||||
public bool setSameMassToEachBone;
|
||||
public float totalMass;
|
||||
|
||||
public bool assignBonesManually;
|
||||
|
||||
[Space]
|
||||
[Header ("Ragdoll Scale and Mass Settings")]
|
||||
[Space]
|
||||
|
||||
public float hipsScale = 1;
|
||||
public float upperLegsScale = 0.2f;
|
||||
public float lowerLegsScale = 0.2f;
|
||||
public float upperArmsScale = 0.25f;
|
||||
public float lowerArmsScale = 0.2f;
|
||||
public float spineScale = 1;
|
||||
public float headScale = 1;
|
||||
public float hipsMassPercentage = 20;
|
||||
public float upperLegsMassPercentage = 9;
|
||||
public float lowerLegsMassPercentage = 8;
|
||||
public float upperArmsMassPercentage = 7;
|
||||
public float lowerArmsMassPercentage = 6;
|
||||
public float spineMassPercentage = 10;
|
||||
public float headMassPercentage = 10;
|
||||
|
||||
[Space]
|
||||
[Header ("Debug")]
|
||||
[Space]
|
||||
|
||||
public bool ragdollAdded;
|
||||
|
||||
public List<boneParts> bones = new List<boneParts> ();
|
||||
public List<Transform> bonesTransforms = new List<Transform> ();
|
||||
|
||||
[Space]
|
||||
[Header ("Event Settings")]
|
||||
[Space]
|
||||
|
||||
public UnityEvent eventOnCreateRagdoll;
|
||||
|
||||
|
||||
Vector3 vectorRight = Vector3.right;
|
||||
Vector3 vectorUp = Vector3.up;
|
||||
Vector3 vectorForward = Vector3.forward;
|
||||
Vector3 worldRight = Vector3.right;
|
||||
Vector3 worldUp = Vector3.up;
|
||||
Vector3 worldForward = Vector3.forward;
|
||||
|
||||
bool canBeCreated;
|
||||
int i;
|
||||
float distance;
|
||||
int direction;
|
||||
|
||||
|
||||
public void getCharacterBonesFromEditor ()
|
||||
{
|
||||
getCharacterBones ();
|
||||
|
||||
if (!checkAllBonesFound ()) {
|
||||
print ("WARNING: not all bones necessary for the ragdoll of the new player has been found, " +
|
||||
"assign them manually on the top part to make sure all of them are configured correctly\n");
|
||||
|
||||
bonesTransforms.Clear ();
|
||||
}
|
||||
}
|
||||
|
||||
public void getCharacterBones ()
|
||||
{
|
||||
if (animator != null) {
|
||||
|
||||
bonesTransforms.Clear ();
|
||||
|
||||
pelvis = animator.GetBoneTransform (HumanBodyBones.Hips);
|
||||
|
||||
leftHips = animator.GetBoneTransform (HumanBodyBones.LeftUpperLeg);
|
||||
|
||||
leftKnee = animator.GetBoneTransform (HumanBodyBones.LeftLowerLeg);
|
||||
|
||||
rightHips = animator.GetBoneTransform (HumanBodyBones.RightUpperLeg);
|
||||
|
||||
rightKnee = animator.GetBoneTransform (HumanBodyBones.RightLowerLeg);
|
||||
|
||||
leftArm = animator.GetBoneTransform (HumanBodyBones.LeftUpperArm);
|
||||
|
||||
leftElbow = animator.GetBoneTransform (HumanBodyBones.LeftLowerArm);
|
||||
|
||||
rightArm = animator.GetBoneTransform (HumanBodyBones.RightUpperArm);
|
||||
|
||||
rightElbow = animator.GetBoneTransform (HumanBodyBones.RightLowerArm);
|
||||
|
||||
middleSpine = animator.GetBoneTransform (HumanBodyBones.Chest);
|
||||
|
||||
head = animator.GetBoneTransform (HumanBodyBones.Head);
|
||||
|
||||
//add every bone to a list
|
||||
addBonesTransforms ();
|
||||
} else {
|
||||
print ("WARNING: animator not assigned for the ragdoll builder\n");
|
||||
}
|
||||
}
|
||||
|
||||
void addBonesTransforms ()
|
||||
{
|
||||
bonesTransforms.Add (pelvis);
|
||||
bonesTransforms.Add (leftHips);
|
||||
bonesTransforms.Add (leftKnee);
|
||||
bonesTransforms.Add (rightHips);
|
||||
bonesTransforms.Add (rightKnee);
|
||||
bonesTransforms.Add (leftArm);
|
||||
bonesTransforms.Add (leftElbow);
|
||||
bonesTransforms.Add (rightArm);
|
||||
bonesTransforms.Add (rightElbow);
|
||||
bonesTransforms.Add (middleSpine);
|
||||
bonesTransforms.Add (head);
|
||||
}
|
||||
|
||||
public bool checkAllBonesFound ()
|
||||
{
|
||||
return
|
||||
(head != null) &&
|
||||
(pelvis != null) &&
|
||||
(leftHips != null) &&
|
||||
(leftKnee != null) &&
|
||||
(rightHips != null) &&
|
||||
(rightKnee != null) &&
|
||||
(leftArm != null) &&
|
||||
(leftElbow != null) &&
|
||||
(rightArm != null) &&
|
||||
(rightElbow != null) &&
|
||||
(middleSpine != null);
|
||||
}
|
||||
|
||||
public bool createRagdoll ()
|
||||
{
|
||||
bool created = false;
|
||||
distance = 0;
|
||||
direction = 0;
|
||||
canBeCreated = true;
|
||||
bonesTransforms.Clear ();
|
||||
|
||||
bones.Clear ();
|
||||
|
||||
//get the correct bones
|
||||
|
||||
if (animator != null) {
|
||||
|
||||
if (assignBonesManually) {
|
||||
addBonesTransforms ();
|
||||
} else {
|
||||
getCharacterBones ();
|
||||
}
|
||||
|
||||
if (!checkAllBonesFound ()) {
|
||||
print ("WARNING: not all bones necessary for the ragdoll of the new player has been found, " +
|
||||
"assign them manually on the top part to make sure all of them are configured correctly\n");
|
||||
|
||||
bonesTransforms.Clear ();
|
||||
|
||||
updateRagdollActivatorParts ();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!assignBonesManually) {
|
||||
//check that every bone has been found, else the ragdoll is not built
|
||||
for (int i = 0; i < bonesTransforms.Count; i++) {
|
||||
if (bonesTransforms [i] == null) {
|
||||
canBeCreated = false;
|
||||
|
||||
bonesTransforms.Clear ();
|
||||
|
||||
print ("Some bone is not placed in the ragdollBuilder inspector\n");
|
||||
|
||||
updateRagdollActivatorParts ();
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//calculate axis of the model
|
||||
vectorUp = getDirectionAxis (pelvis.InverseTransformPoint (head.position));
|
||||
Vector3 pelvisDir = pelvis.InverseTransformPoint (rightElbow.position);
|
||||
Vector3 newVector = vectorUp.normalized * Vector3.Dot (pelvisDir, vectorUp.normalized);
|
||||
vectorRight = getDirectionAxis (pelvisDir - newVector);
|
||||
vectorForward = Vector3.Cross (vectorRight, vectorUp);
|
||||
|
||||
//set the world axis directions
|
||||
worldRight = pelvis.TransformDirection (vectorRight);
|
||||
worldUp = pelvis.TransformDirection (vectorUp);
|
||||
worldForward = pelvis.TransformDirection (vectorForward);
|
||||
|
||||
//create the bones list
|
||||
bones.Clear ();
|
||||
|
||||
//create the pelvis bone first which is the main bone
|
||||
boneParts pelvisBone = new boneParts ();
|
||||
pelvisBone.name = "pelvis";
|
||||
pelvisBone.boneTransform = pelvis;
|
||||
pelvisBone.parent = null;
|
||||
pelvisBone.mass = hipsMassPercentage;
|
||||
|
||||
bones.Add (pelvisBone);
|
||||
|
||||
//then create the rest of limbs
|
||||
createDoubleLimb ("hips", leftHips, rightHips, "pelvis", "capsule", worldRight, worldForward, new Vector2 (-20, 70), 30, upperLegsScale, upperLegsMassPercentage);
|
||||
createDoubleLimb ("knee", leftKnee, rightKnee, "hips", "capsule", worldRight, worldForward, new Vector2 (-80, 0), 0, lowerLegsScale, lowerLegsMassPercentage);
|
||||
createLimb ("middle Spine", middleSpine, "pelvis", "", worldRight, worldForward, new Vector2 (-20, 20), 10, spineScale, spineMassPercentage);
|
||||
createDoubleLimb ("arm", leftArm, rightArm, "middle Spine", "capsule", worldUp, worldForward, new Vector2 (-70, 10), 50, upperArmsScale, upperArmsMassPercentage);
|
||||
createDoubleLimb ("elbow", leftElbow, rightElbow, "arm", "capsule", worldForward, worldUp, new Vector2 (-90, 0), 0, lowerArmsScale, lowerArmsMassPercentage);
|
||||
createLimb ("head", head, "middle Spine", "", worldRight, worldForward, new Vector2 (-40, 25), 25, headScale, headMassPercentage);
|
||||
|
||||
//if every part has been correctly configured, build the ragdoll
|
||||
if (canBeCreated) {
|
||||
buildRagdollComponents ();
|
||||
|
||||
created = true;
|
||||
|
||||
if (eventOnCreateRagdoll != null) {
|
||||
if (eventOnCreateRagdoll.GetPersistentEventCount () > 0) {
|
||||
eventOnCreateRagdoll.Invoke ();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
updateComponent ();
|
||||
|
||||
updateRagdollActivatorParts ();
|
||||
|
||||
assignBonesManually = false;
|
||||
|
||||
return created;
|
||||
}
|
||||
|
||||
public void updateRagdollActivatorParts ()
|
||||
{
|
||||
if (mainRagdollActivator != null) {
|
||||
mainRagdollActivator.setBodyColliderList ();
|
||||
|
||||
mainRagdollActivator.setBodyRigidbodyList ();
|
||||
|
||||
mainRagdollActivator.setBodyParts ();
|
||||
|
||||
GKC_Utils.updateComponent (mainRagdollActivator);
|
||||
|
||||
print ("Ragdoll Activator components assigned and updated");
|
||||
}
|
||||
}
|
||||
|
||||
void createDoubleLimb (string name, Transform leftTransform, Transform rightTransform, string parent, string colliderType,
|
||||
Vector3 axis, Vector3 swingAxis, Vector2 limits, float swingLimit, float scale, float mass)
|
||||
{
|
||||
createLimb ("left " + name, leftTransform, parent, colliderType, axis, swingAxis, limits, swingLimit, scale, mass);
|
||||
createLimb ("right " + name, rightTransform, parent, colliderType, axis, swingAxis, limits, swingLimit, scale, mass);
|
||||
}
|
||||
|
||||
void createLimb (string name, Transform boneTransform, string parent, string colliderType, Vector3 axis, Vector3 swingAxis,
|
||||
Vector2 limits, float swingLimit, float scale, float mass)
|
||||
{
|
||||
boneParts bone = new boneParts ();
|
||||
bone.name = name;
|
||||
bone.boneTransform = boneTransform;
|
||||
|
||||
if (getBoneParent (parent) != null) {
|
||||
bone.parent = getBoneParent (parent);
|
||||
} else if (name.StartsWith ("left")) {
|
||||
bone.parent = getBoneParent ("left " + parent);
|
||||
} else if (name.StartsWith ("right")) {
|
||||
bone.parent = getBoneParent ("right " + parent);
|
||||
}
|
||||
|
||||
bone.colliderType = colliderType;
|
||||
bone.axis = axis;
|
||||
bone.swingAxis = swingAxis;
|
||||
bone.limits.x = limits.x;
|
||||
bone.limits.y = limits.y;
|
||||
bone.swingLimit = swingLimit;
|
||||
bone.scale = scale;
|
||||
bone.mass = mass;
|
||||
bone.parent.children.Add (bone);
|
||||
bones.Add (bone);
|
||||
}
|
||||
|
||||
boneParts getBoneParent (string boneName)
|
||||
{
|
||||
for (int i = 0; i < bones.Count; i++) {
|
||||
if (bones [i].name.Equals (boneName)) {
|
||||
return bones [i];
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
void buildRagdollComponents ()
|
||||
{
|
||||
Vector3 center = Vector3.zero;
|
||||
|
||||
removeRagdoll ();
|
||||
|
||||
for (int i = 0; i < bones.Count; i++) {
|
||||
//create capsule colliders
|
||||
if (bones [i].colliderType == "capsule") {
|
||||
//print ("current ragdoll bone " + bones [i].name);
|
||||
|
||||
if (bones [i].children.Count == 1) {
|
||||
boneParts childBone = (boneParts)bones [i].children [0];
|
||||
Vector3 endPosition = childBone.boneTransform.position;
|
||||
|
||||
getOrientation (bones [i].boneTransform.InverseTransformPoint (endPosition));
|
||||
|
||||
//print ("current ragdoll bone children count == 1 " + distance);
|
||||
} else {
|
||||
Vector3 endPosition = (bones [i].boneTransform.position - bones [i].parent.boneTransform.position) + bones [i].boneTransform.position;
|
||||
|
||||
getOrientation (bones [i].boneTransform.InverseTransformPoint (endPosition));
|
||||
|
||||
//print ("checking if bone children higher than 1 " + distance);
|
||||
|
||||
if (bones [i].boneTransform.GetComponentsInChildren (typeof (Transform)).Length > 1) {
|
||||
Bounds bounds = new Bounds ();
|
||||
|
||||
int childCounter = 0;
|
||||
|
||||
foreach (Transform child in bones [i].boneTransform.GetComponentsInChildren (typeof (Transform))) {
|
||||
if (childCounter < 4) {
|
||||
bounds.Encapsulate (bones [i].boneTransform.InverseTransformPoint (child.position));
|
||||
|
||||
childCounter++;
|
||||
}
|
||||
}
|
||||
|
||||
if (distance > 0) {
|
||||
distance = bounds.max [direction];
|
||||
} else {
|
||||
distance = bounds.min [direction];
|
||||
}
|
||||
|
||||
//print ("current ragdoll bone children higher than 1 " + distance);
|
||||
} else {
|
||||
//print ("current ragdoll bone without children " + distance);
|
||||
}
|
||||
}
|
||||
|
||||
CapsuleCollider collider = bones [i].boneTransform.gameObject.AddComponent<CapsuleCollider> ();
|
||||
|
||||
collider.direction = direction;
|
||||
center = Vector3.zero;
|
||||
center [direction] = distance * 0.5f;
|
||||
collider.center = center;
|
||||
collider.height = Mathf.Abs (distance);
|
||||
collider.radius = Mathf.Abs (distance * bones [i].scale);
|
||||
}
|
||||
|
||||
//add rigidbodies
|
||||
bones [i].boneRigidbody = bones [i].boneTransform.gameObject.AddComponent<Rigidbody> ();
|
||||
bones [i].boneRigidbody.mass = bones [i].mass;
|
||||
|
||||
//build joints
|
||||
if (bones [i].parent != null) {
|
||||
CharacterJoint joint = bones [i].boneTransform.gameObject.AddComponent<CharacterJoint> ();
|
||||
bones [i].joint = joint;
|
||||
|
||||
//configure joint connections
|
||||
joint.axis = getDirectionAxis (bones [i].boneTransform.InverseTransformDirection (bones [i].axis));
|
||||
joint.swingAxis = getDirectionAxis (bones [i].boneTransform.InverseTransformDirection (bones [i].swingAxis));
|
||||
joint.anchor = Vector3.zero;
|
||||
joint.connectedBody = bones [i].parent.boneTransform.GetComponent<Rigidbody> ();
|
||||
|
||||
//configure jount limits
|
||||
SoftJointLimit limit = new SoftJointLimit ();
|
||||
limit.limit = bones [i].limits.x;
|
||||
joint.lowTwistLimit = limit;
|
||||
limit.limit = bones [i].limits.y;
|
||||
joint.highTwistLimit = limit;
|
||||
limit.limit = bones [i].swingLimit;
|
||||
joint.swing1Limit = limit;
|
||||
limit.limit = 0;
|
||||
joint.swing2Limit = limit;
|
||||
joint.enableProjection = true;
|
||||
}
|
||||
}
|
||||
|
||||
//add box colliders to the hips and spine
|
||||
Bounds boxColliderInfo;
|
||||
BoxCollider boxCollider;
|
||||
boxColliderInfo = adjustColliderScale (getColliderSize (pelvis), pelvis, middleSpine, false);
|
||||
boxCollider = pelvis.gameObject.AddComponent<BoxCollider> ();
|
||||
boxCollider.center = boxColliderInfo.center;
|
||||
boxCollider.size = boxColliderInfo.size * spineScale;
|
||||
|
||||
boxColliderInfo = adjustColliderScale (getColliderSize (middleSpine), middleSpine, middleSpine, true);
|
||||
boxCollider = middleSpine.gameObject.AddComponent<BoxCollider> ();
|
||||
boxCollider.center = boxColliderInfo.center;
|
||||
boxCollider.size = boxColliderInfo.size * spineScale;
|
||||
|
||||
//add head collider
|
||||
float radius = (GKC_Utils.distance (rightArm.transform.position, leftArm.transform.position)) / 4;
|
||||
SphereCollider sphere = head.gameObject.AddComponent<SphereCollider> ();
|
||||
sphere.radius = radius;
|
||||
center = Vector3.zero;
|
||||
|
||||
getOrientation (head.InverseTransformPoint (pelvis.position));
|
||||
|
||||
if (distance > 0) {
|
||||
center [direction] = -radius;
|
||||
} else {
|
||||
center [direction] = radius;
|
||||
}
|
||||
sphere.center = center;
|
||||
|
||||
//set the mass in the children of the pelvis
|
||||
for (int i = 0; i < bones.Count; i++) {
|
||||
bones [i].boneCollider = bones [i].boneTransform.GetComponent<Collider> ();
|
||||
|
||||
if (setSameMassToEachBone) {
|
||||
bones [i].boneRigidbody.mass = totalMass;
|
||||
} else {
|
||||
bones [i].boneRigidbody.mass = (totalMass * bones [i].mass) / 100;
|
||||
}
|
||||
|
||||
bones [i].mass = bones [i].boneRigidbody.mass;
|
||||
}
|
||||
|
||||
ragdollAdded = true;
|
||||
}
|
||||
|
||||
//adjust the box colliders for hips and spine
|
||||
Bounds adjustColliderScale (Bounds bounds, Transform relativeTo, Transform clipTransform, bool below)
|
||||
{
|
||||
int axis = getCorrectAxis (bounds.size, true);
|
||||
if (Vector3.Dot (worldUp, relativeTo.TransformPoint (bounds.max)) > Vector3.Dot (worldUp, relativeTo.TransformPoint (bounds.min)) == below) {
|
||||
Vector3 min = bounds.min;
|
||||
min [axis] = relativeTo.InverseTransformPoint (clipTransform.position) [axis];
|
||||
bounds.min = min;
|
||||
} else {
|
||||
Vector3 max = bounds.max;
|
||||
max [axis] = relativeTo.InverseTransformPoint (clipTransform.position) [axis];
|
||||
bounds.max = max;
|
||||
}
|
||||
|
||||
return bounds;
|
||||
}
|
||||
|
||||
//get the size of the box collider for hips and spine
|
||||
Bounds getColliderSize (Transform relativeTo)
|
||||
{
|
||||
Bounds bounds = new Bounds ();
|
||||
bounds.Encapsulate (relativeTo.InverseTransformPoint (leftHips.position));
|
||||
bounds.Encapsulate (relativeTo.InverseTransformPoint (rightHips.position));
|
||||
bounds.Encapsulate (relativeTo.InverseTransformPoint (leftArm.position));
|
||||
bounds.Encapsulate (relativeTo.InverseTransformPoint (rightArm.position));
|
||||
|
||||
Vector3 size = bounds.size;
|
||||
size [getCorrectAxis (bounds.size, false)] = size [getCorrectAxis (bounds.size, true)] / 2;
|
||||
bounds.size = size;
|
||||
return bounds;
|
||||
}
|
||||
|
||||
public bool removeRagdoll ()
|
||||
{
|
||||
bool removed = false;
|
||||
|
||||
if (animator != null) {
|
||||
if (bones.Count == 0) {
|
||||
for (int i = 0; i < bonesTransforms.Count; i++) {
|
||||
if (bonesTransforms [i] != null) {
|
||||
Component [] components = bonesTransforms [i].GetComponents (typeof (Joint));
|
||||
foreach (Joint child in components) {
|
||||
DestroyImmediate (child);
|
||||
}
|
||||
|
||||
components = bonesTransforms [i].GetComponents (typeof (Rigidbody));
|
||||
foreach (Rigidbody child in components) {
|
||||
DestroyImmediate (child);
|
||||
}
|
||||
|
||||
components = bonesTransforms [i].GetComponents (typeof (Collider));
|
||||
foreach (Collider child in components) {
|
||||
DestroyImmediate (child);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < bones.Count; i++) {
|
||||
//remove colliders, joints or rigidbodies
|
||||
if (bones [i].boneTransform != null) {
|
||||
if (bones [i].boneTransform.GetComponent<Joint> ()) {
|
||||
DestroyImmediate (bones [i].boneTransform.GetComponent<Joint> ());
|
||||
}
|
||||
|
||||
if (bones [i].boneTransform.GetComponent<Rigidbody> ()) {
|
||||
DestroyImmediate (bones [i].boneTransform.GetComponent<Rigidbody> ());
|
||||
}
|
||||
|
||||
if (bones [i].boneTransform.GetComponent<Collider> ()) {
|
||||
DestroyImmediate (bones [i].boneTransform.GetComponent<Collider> ());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
removed = true;
|
||||
|
||||
if (ragdollAdded) {
|
||||
ragdollAdded = false;
|
||||
}
|
||||
}
|
||||
|
||||
// updateRagdollActivatorParts ();
|
||||
|
||||
return removed;
|
||||
}
|
||||
|
||||
public bool removeRagdollFromEditor ()
|
||||
{
|
||||
removeRagdoll ();
|
||||
|
||||
bonesTransforms.Clear ();
|
||||
|
||||
bones.Clear ();
|
||||
|
||||
updateRagdollActivatorParts ();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public void enableRagdollColliders ()
|
||||
{
|
||||
setRagdollCollidersState (true);
|
||||
}
|
||||
|
||||
public void disableRagdollColliders ()
|
||||
{
|
||||
setRagdollCollidersState (false);
|
||||
}
|
||||
|
||||
public void setRagdollCollidersState (bool state)
|
||||
{
|
||||
if (animator != null) {
|
||||
for (int i = 0; i < bones.Count; i++) {
|
||||
//enable or disalbe colliders in the ragdoll
|
||||
if (bones [i].boneTransform != null) {
|
||||
Collider currentCollider = bones [i].boneTransform.GetComponent<Collider> ();
|
||||
|
||||
if (currentCollider != null) {
|
||||
currentCollider.enabled = state;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void getOrientation (Vector3 point)
|
||||
{
|
||||
//get the axis with the longest value
|
||||
direction = 0;
|
||||
if (Mathf.Abs (point.y) > Mathf.Abs (point.x)) {
|
||||
direction = 1;
|
||||
}
|
||||
|
||||
if (Mathf.Abs (point.z) > Mathf.Abs (point [direction])) {
|
||||
direction = 2;
|
||||
}
|
||||
|
||||
distance = point [direction];
|
||||
}
|
||||
|
||||
Vector3 getDirectionAxis (Vector3 point)
|
||||
{
|
||||
getOrientation (point);
|
||||
Vector3 axis = Vector3.zero;
|
||||
|
||||
if (distance > 0) {
|
||||
axis [direction] = 1;
|
||||
} else {
|
||||
axis [direction] = -1;
|
||||
}
|
||||
|
||||
return axis;
|
||||
}
|
||||
|
||||
int getCorrectAxis (Vector3 point, bool biggest)
|
||||
{
|
||||
//get the bigger or lower axis to set the scale of the box collider
|
||||
direction = 0;
|
||||
|
||||
if (biggest) {
|
||||
if (Mathf.Abs (point.y) > Mathf.Abs (point.x)) {
|
||||
direction = 1;
|
||||
}
|
||||
if (Mathf.Abs (point.z) > Mathf.Abs (point [direction])) {
|
||||
direction = 2;
|
||||
}
|
||||
} else {
|
||||
if (Mathf.Abs (point.y) < Mathf.Abs (point.x)) {
|
||||
direction = 1;
|
||||
}
|
||||
if (Mathf.Abs (point.z) < Mathf.Abs (point [direction])) {
|
||||
direction = 2;
|
||||
}
|
||||
}
|
||||
|
||||
return direction;
|
||||
}
|
||||
|
||||
public void getAnimator (Animator anim)
|
||||
{
|
||||
animator = anim;
|
||||
}
|
||||
|
||||
public void setRagdollActivator (ragdollActivator newRagdollActivator)
|
||||
{
|
||||
mainRagdollActivator = newRagdollActivator;
|
||||
}
|
||||
|
||||
void updateComponent ()
|
||||
{
|
||||
GKC_Utils.updateComponent (this);
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public class boneParts
|
||||
{
|
||||
public string name;
|
||||
public Transform boneTransform;
|
||||
public CharacterJoint joint;
|
||||
public boneParts parent;
|
||||
public string colliderType;
|
||||
public Vector3 axis;
|
||||
public Vector3 swingAxis;
|
||||
public Vector2 limits;
|
||||
public float swingLimit;
|
||||
public float scale;
|
||||
public float mass;
|
||||
public float childrenMass;
|
||||
public ArrayList children = new ArrayList ();
|
||||
public Collider boneCollider;
|
||||
public Rigidbody boneRigidbody;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ec2af294ff5801549819ebab9e36b703
|
||||
timeCreated: 1464457873
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 40995
|
||||
packageName: Game Kit Controller - Shooter Melee Adventure Creator 3D + 2.5D
|
||||
packageVersion: 3.77g
|
||||
assetPath: Assets/Game Kit Controller/Scripts/Player/Character Builder/ragdollBuilder.cs
|
||||
uploadId: 814740
|
||||
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a395bc6ca224c37479c0e5579224523d
|
||||
folderAsset: yes
|
||||
timeCreated: 1626771874
|
||||
licenseType: Store
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,705 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
|
||||
public class bulletTimeFiringSystem : OnAnimatorIKComponent
|
||||
{
|
||||
[Header ("Main Settings")]
|
||||
[Space]
|
||||
|
||||
public bool movementEnabled = true;
|
||||
|
||||
public float lookDirectionForwardOffset = 1000;
|
||||
|
||||
public float timeForRaisingHands = 0.5f;
|
||||
|
||||
public bool onlyActiveIfUsingFireWeapons;
|
||||
|
||||
public float bodyWeightLerpSpeed = 1;
|
||||
|
||||
[Space]
|
||||
[Header ("Get Up Settings")]
|
||||
[Space]
|
||||
|
||||
public bool getUpAfterDelayOnGround;
|
||||
|
||||
public float delayToGetUpOnGround;
|
||||
|
||||
public float minWaitToCheckOnGroundState;
|
||||
|
||||
[Space]
|
||||
[Header ("Weapons Settings")]
|
||||
[Space]
|
||||
|
||||
public bool keepWeaponsDuringAction;
|
||||
|
||||
public bool drawWeaponsAfterAction;
|
||||
|
||||
public bool useOnlyWhenUsingFireWeapons;
|
||||
|
||||
[Space]
|
||||
[Header ("Time Bullet Settings")]
|
||||
[Space]
|
||||
|
||||
public bool useTimeBullet;
|
||||
public float timeBulletScale = 0.5f;
|
||||
|
||||
public bool useTimeBulletDuration;
|
||||
public float timeBulletDuration;
|
||||
|
||||
public bool useEventsOnTimeBullet;
|
||||
public UnityEvent eventOnTimeBulletStart;
|
||||
public UnityEvent eventOnTimeBulletEnd;
|
||||
|
||||
[Space]
|
||||
[Header ("Physics Settings")]
|
||||
[Space]
|
||||
|
||||
public float jumpForce;
|
||||
public float pushForce;
|
||||
|
||||
public float extraSpeedOnFall;
|
||||
public float addExtraSpeedOnFallDuration;
|
||||
public float delayToAddExtraSpeedOnFall;
|
||||
|
||||
[Space]
|
||||
[Header ("Third Person Settings")]
|
||||
[Space]
|
||||
|
||||
public int actionID = 323565;
|
||||
public int actionIDWithRoll = 323566;
|
||||
|
||||
public bool startActionWithRoll;
|
||||
public float rollOnStartDuration;
|
||||
|
||||
public string externalControlleBehaviorActiveAnimatorName = "External Behavior Active";
|
||||
public string actionIDAnimatorName = "Action ID";
|
||||
|
||||
public string horizontalAnimatorName = "Horizontal Action";
|
||||
public string verticalAnimatorName = "Vertical Action";
|
||||
|
||||
public float delayToResumeAfterGetUp = 1;
|
||||
|
||||
[Space]
|
||||
[Header ("Third Person Camera State Settings")]
|
||||
[Space]
|
||||
|
||||
public bool setNewCameraStateOnThirdPerson;
|
||||
|
||||
public string newCameraStateOnThirdPerson;
|
||||
|
||||
[Space]
|
||||
[Header ("Action System Settings")]
|
||||
[Space]
|
||||
|
||||
public int customActionCategoryID = -1;
|
||||
public int regularActionCategoryID = -1;
|
||||
|
||||
|
||||
[Space]
|
||||
[Header ("Debug")]
|
||||
[Space]
|
||||
|
||||
public bool showDebugPrint;
|
||||
|
||||
public bool movementActive;
|
||||
|
||||
public bool armsIKActive;
|
||||
|
||||
public float currentTimeForRisingHands;
|
||||
|
||||
public float currentArmsWeight;
|
||||
|
||||
public float armsWeight = 1;
|
||||
|
||||
public bool playerIsCarryingWeapons;
|
||||
|
||||
public Vector3 lookDirectionTarget;
|
||||
|
||||
public bool groundDetectedAfterJump;
|
||||
|
||||
[Space]
|
||||
[Header ("Events Settings")]
|
||||
[Space]
|
||||
|
||||
public UnityEvent eventOnStart;
|
||||
public UnityEvent eventOnEnd;
|
||||
|
||||
public UnityEvent eventOnGetUpForward;
|
||||
public UnityEvent eventOnGetUpBackward;
|
||||
public UnityEvent eventOnGetUpRight;
|
||||
public UnityEvent eventOnGetUpLeft;
|
||||
|
||||
[Space]
|
||||
[Header ("Components")]
|
||||
[Space]
|
||||
|
||||
public playerController mainPlayerController;
|
||||
|
||||
public playerCamera mainPlayerCamera;
|
||||
|
||||
public playerInputManager playerInput;
|
||||
|
||||
public timeBullet mainTimeBullet;
|
||||
|
||||
public Animator mainAnimator;
|
||||
|
||||
public Camera mainCamera;
|
||||
|
||||
public Transform mainCameraTransform;
|
||||
|
||||
public playerWeaponsManager mainPlayerWeaponsManager;
|
||||
|
||||
public headTrack mainHeadTrack;
|
||||
|
||||
public Transform playerTransform;
|
||||
|
||||
Vector3 lookDirection;
|
||||
|
||||
Vector2 mouseAxisValues;
|
||||
|
||||
Vector3 leftArmAimPosition;
|
||||
|
||||
Vector3 rightArmAimPosition;
|
||||
|
||||
int externalControlleBehaviorActiveAnimatorID;
|
||||
|
||||
int actionIDAnimatorID;
|
||||
|
||||
int horizontalAnimatorID;
|
||||
|
||||
int verticalAnimatorID;
|
||||
|
||||
bool activateGetUp;
|
||||
|
||||
float lastTimeGetup;
|
||||
|
||||
string previousCameraState;
|
||||
|
||||
float bodyWeight;
|
||||
|
||||
Vector3 lastJumpDirection;
|
||||
|
||||
bool timeBulletActive;
|
||||
|
||||
bool carryingWeaponsPreviously;
|
||||
|
||||
float lastTimeMovementActive;
|
||||
|
||||
|
||||
void Start ()
|
||||
{
|
||||
externalControlleBehaviorActiveAnimatorID = Animator.StringToHash (externalControlleBehaviorActiveAnimatorName);
|
||||
|
||||
actionIDAnimatorID = Animator.StringToHash (actionIDAnimatorName);
|
||||
|
||||
horizontalAnimatorID = Animator.StringToHash (horizontalAnimatorName);
|
||||
|
||||
verticalAnimatorID = Animator.StringToHash (verticalAnimatorName);
|
||||
}
|
||||
|
||||
void Update ()
|
||||
{
|
||||
if (movementActive) {
|
||||
if (!activateGetUp) {
|
||||
lookDirectionTarget = mainCameraTransform.position + mainCameraTransform.forward * lookDirectionForwardOffset;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void FixedUpdate ()
|
||||
{
|
||||
if (movementActive) {
|
||||
if (activateGetUp) {
|
||||
if (Time.unscaledTime > delayToResumeAfterGetUp + lastTimeGetup) {
|
||||
disableMovement ();
|
||||
}
|
||||
} else {
|
||||
Vector3 aimDirection = mainCameraTransform.forward;
|
||||
|
||||
aimDirection.y = 0f;
|
||||
|
||||
aimDirection = aimDirection.normalized;
|
||||
|
||||
aimDirection = playerTransform.InverseTransformDirection (aimDirection);
|
||||
|
||||
mainAnimator.SetFloat (horizontalAnimatorID, aimDirection.x);
|
||||
mainAnimator.SetFloat (verticalAnimatorID, aimDirection.z);
|
||||
|
||||
if (mainPlayerController.isPlayerOnGround ()) {
|
||||
if (Time.unscaledTime > minWaitToCheckOnGroundState + lastTimeMovementActive) {
|
||||
groundDetectedAfterJump = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!jumpCoroutineActive) {
|
||||
if (extraSpeedOnFall > 0) {
|
||||
if (Time.unscaledTime > lastTimeMovementActive + delayToAddExtraSpeedOnFall) {
|
||||
if (Time.unscaledTime < addExtraSpeedOnFallDuration + lastTimeMovementActive) {
|
||||
if (!groundDetectedAfterJump) {
|
||||
mainPlayerController.addExternalForce (lastJumpDirection * extraSpeedOnFall);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (getUpAfterDelayOnGround && groundDetectedAfterJump) {
|
||||
if (Time.unscaledTime > lastTimeMovementActive + delayToGetUpOnGround) {
|
||||
setMovementActiveState (false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (useEventsOnTimeBullet && timeBulletActive) {
|
||||
if (Time.unscaledTime > lastTimeMovementActive + timeBulletDuration) {
|
||||
// print (Time.unscaledTime + " " + (lastTimeMovementActive + timeBulletDuration));
|
||||
|
||||
checkTimeBullet (false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setMovementActiveState (bool state)
|
||||
{
|
||||
if (!movementEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (movementActive == state) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (state) {
|
||||
movementActive = state;
|
||||
|
||||
mainPlayerController.setIgnoreUseDelayOnGroundJumpActiveState (true);
|
||||
|
||||
lastTimeMovementActive = Time.unscaledTime;
|
||||
|
||||
if (startActionWithRoll) {
|
||||
stopActivateJumpForcesCoroutine ();
|
||||
|
||||
activateJumpCoroutine = StartCoroutine (activateJumpForcesCoroutine ());
|
||||
} else {
|
||||
activateJumpForces ();
|
||||
}
|
||||
|
||||
setPlayerState (true);
|
||||
|
||||
checkTimeBullet (true);
|
||||
} else {
|
||||
bool lookingForward = false;
|
||||
|
||||
Vector3 movementDirection = playerTransform.forward;
|
||||
|
||||
if (playerInput.getPlayerMovementAxis () != Vector2.zero) {
|
||||
movementDirection = mainPlayerController.getMoveInputDirection ();
|
||||
}
|
||||
|
||||
float angle = Vector3.SignedAngle (movementDirection, mainCameraTransform.forward, playerTransform.up);
|
||||
|
||||
float ABSAngle = Mathf.Abs (angle);
|
||||
|
||||
if (ABSAngle < 160) {
|
||||
lookingForward = true;
|
||||
}
|
||||
|
||||
if (showDebugPrint) {
|
||||
print ("looking in forward direction " + lookingForward + " " + ABSAngle);
|
||||
}
|
||||
|
||||
activateGetUp = true;
|
||||
|
||||
lastTimeGetup = Time.unscaledTime;
|
||||
|
||||
mainAnimator.SetBool (externalControlleBehaviorActiveAnimatorID, false);
|
||||
|
||||
mainAnimator.SetInteger (actionIDAnimatorID, 0);
|
||||
|
||||
if (lookingForward) {
|
||||
if (ABSAngle < 45) {
|
||||
eventOnGetUpForward.Invoke ();
|
||||
} else if (angle < 0) {
|
||||
eventOnGetUpRight.Invoke ();
|
||||
|
||||
if (showDebugPrint) {
|
||||
print ("activating event on right");
|
||||
}
|
||||
} else {
|
||||
eventOnGetUpLeft.Invoke ();
|
||||
|
||||
if (showDebugPrint) {
|
||||
print ("activating event on left");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
eventOnGetUpBackward.Invoke ();
|
||||
}
|
||||
|
||||
checkTimeBullet (false);
|
||||
|
||||
lastJumpDirection = Vector3.zero;
|
||||
}
|
||||
|
||||
groundDetectedAfterJump = false;
|
||||
|
||||
//desactivar el salto y demas acciones que no se puedan hacer, quizas algunas cosas de las armas
|
||||
//opciones de usar con y sin armas, quizas para algun tipo de dash o esquive
|
||||
}
|
||||
|
||||
void activateJumpForces ()
|
||||
{
|
||||
setUpdateIKEnabledState (true);
|
||||
|
||||
Vector2 movementDirection = playerInput.getPlayerMovementAxis ();
|
||||
|
||||
Vector3 forceDirection = new Vector3 (movementDirection.x, 0, movementDirection.y);
|
||||
|
||||
if (playerInput.getAuxRawMovementAxis () == Vector2.zero) {
|
||||
forceDirection = playerTransform.forward;
|
||||
}
|
||||
|
||||
lastJumpDirection = forceDirection;
|
||||
|
||||
Vector3 jumpDirection = pushForce * forceDirection;
|
||||
|
||||
jumpDirection += playerTransform.up * jumpForce;
|
||||
|
||||
mainPlayerController.useJumpPlatform (jumpDirection, ForceMode.Impulse);
|
||||
}
|
||||
|
||||
bool jumpCoroutineActive;
|
||||
|
||||
Coroutine activateJumpCoroutine;
|
||||
|
||||
public void stopActivateJumpForcesCoroutine ()
|
||||
{
|
||||
if (activateJumpCoroutine != null) {
|
||||
StopCoroutine (activateJumpCoroutine);
|
||||
}
|
||||
|
||||
jumpCoroutineActive = false;
|
||||
}
|
||||
|
||||
IEnumerator activateJumpForcesCoroutine ()
|
||||
{
|
||||
jumpCoroutineActive = true;
|
||||
|
||||
yield return new WaitForSeconds (rollOnStartDuration);
|
||||
|
||||
jumpCoroutineActive = false;
|
||||
|
||||
activateJumpForces ();
|
||||
}
|
||||
|
||||
void checkTimeBullet (bool state)
|
||||
{
|
||||
if (useTimeBullet) {
|
||||
if (state) {
|
||||
if (!timeBulletActive) {
|
||||
if (mainTimeBullet.isTimeBulletActivated ()) {
|
||||
mainTimeBullet.updateTimeBulletTime (timeBulletScale);
|
||||
|
||||
mainTimeBullet.updateTimeScaleValue ();
|
||||
} else {
|
||||
mainTimeBullet.setNewTimeBulletTimeSpeedValue (timeBulletScale);
|
||||
|
||||
mainTimeBullet.activateTime ();
|
||||
}
|
||||
|
||||
timeBulletActive = true;
|
||||
|
||||
if (useEventsOnTimeBullet) {
|
||||
eventOnTimeBulletStart.Invoke ();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (timeBulletActive) {
|
||||
if (mainTimeBullet.isTimeBulletActivated ()) {
|
||||
mainTimeBullet.setOriginalTimeBulletTimeSpeed ();
|
||||
|
||||
mainTimeBullet.activateTime ();
|
||||
}
|
||||
|
||||
timeBulletActive = false;
|
||||
|
||||
if (useEventsOnTimeBullet) {
|
||||
eventOnTimeBulletEnd.Invoke ();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void disableMovement ()
|
||||
{
|
||||
if (movementActive) {
|
||||
stopActivateJumpForcesCoroutine ();
|
||||
|
||||
movementActive = false;
|
||||
|
||||
activateGetUp = false;
|
||||
|
||||
setPlayerState (false);
|
||||
}
|
||||
}
|
||||
|
||||
void setPlayerState (bool state)
|
||||
{
|
||||
bool isFirstPersonActive = mainPlayerController.isPlayerOnFirstPerson ();
|
||||
|
||||
if (state) {
|
||||
if (startActionWithRoll) {
|
||||
mainAnimator.SetInteger (actionIDAnimatorID, actionIDWithRoll);
|
||||
} else {
|
||||
mainAnimator.SetInteger (actionIDAnimatorID, actionID);
|
||||
}
|
||||
|
||||
mainAnimator.SetBool (externalControlleBehaviorActiveAnimatorID, state);
|
||||
|
||||
if (setNewCameraStateOnThirdPerson && !isFirstPersonActive) {
|
||||
previousCameraState = mainPlayerCamera.getCurrentStateName ();
|
||||
|
||||
mainPlayerCamera.setCameraStateOnlyOnThirdPerson (newCameraStateOnThirdPerson);
|
||||
}
|
||||
|
||||
carryingWeaponsPreviously = mainPlayerWeaponsManager.isPlayerCarringWeapon ();
|
||||
|
||||
if (carryingWeaponsPreviously) {
|
||||
if (keepWeaponsDuringAction) {
|
||||
mainPlayerWeaponsManager.checkIfDisableCurrentWeapon ();
|
||||
|
||||
mainPlayerWeaponsManager.resetWeaponHandIKWeight ();
|
||||
} else {
|
||||
mainPlayerWeaponsManager.stopShootingFireWeaponIfActive ();
|
||||
|
||||
mainPlayerWeaponsManager.enableOrDisableIKOnWeaponsDuringAction (false);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
mainAnimator.SetBool (externalControlleBehaviorActiveAnimatorID, false);
|
||||
|
||||
mainAnimator.SetInteger (actionIDAnimatorID, 0);
|
||||
|
||||
if (setNewCameraStateOnThirdPerson && !isFirstPersonActive) {
|
||||
if (previousCameraState != "") {
|
||||
if (previousCameraState != newCameraStateOnThirdPerson) {
|
||||
mainPlayerCamera.setCameraStateOnlyOnThirdPerson (previousCameraState);
|
||||
}
|
||||
|
||||
previousCameraState = "";
|
||||
}
|
||||
}
|
||||
|
||||
if (carryingWeaponsPreviously) {
|
||||
if (drawWeaponsAfterAction) {
|
||||
mainPlayerWeaponsManager.checkIfDrawSingleOrDualWeapon ();
|
||||
} else {
|
||||
if (mainPlayerWeaponsManager.isAimingWeapons ()) {
|
||||
mainPlayerWeaponsManager.setPauseUpperBodyRotationSystemActiveState (false);
|
||||
}
|
||||
|
||||
mainPlayerWeaponsManager.enableOrDisableIKOnWeaponsDuringAction (true);
|
||||
}
|
||||
|
||||
carryingWeaponsPreviously = false;
|
||||
}
|
||||
|
||||
checkTimeBullet (false);
|
||||
|
||||
mainPlayerController.setIgnoreUseDelayOnGroundJumpActiveState (false);
|
||||
}
|
||||
|
||||
setCurrentPlayerActionSystemCustomActionCategoryID ();
|
||||
|
||||
setUpdateIKEnabledState (state);
|
||||
|
||||
mainPlayerController.setIgnoreExternalActionsActiveState (state);
|
||||
|
||||
mainPlayerController.setAddExtraRotationPausedState (state);
|
||||
|
||||
mainHeadTrack.setHeadTrackSmoothPauseState (state);
|
||||
|
||||
mainPlayerController.setUseExternalControllerBehaviorPausedState (state);
|
||||
|
||||
mainPlayerWeaponsManager.setPauseUpperBodyRotationSystemActiveState (state);
|
||||
|
||||
mainPlayerWeaponsManager.setPauseRecoilOnWeaponActiveState (state);
|
||||
|
||||
mainPlayerWeaponsManager.setPauseWeaponReloadActiveState (state);
|
||||
|
||||
mainPlayerWeaponsManager.setPauseWeaponAimMovementActiveState (state);
|
||||
|
||||
mainPlayerController.setIgnoreLookInCameraDirectionOnFreeFireActiveState (state);
|
||||
|
||||
checkEventOnStateChange (state);
|
||||
|
||||
mainPlayerController.setFootStepManagerState (state);
|
||||
|
||||
mainPlayerController.setIgnoreInputOnAirControlActiveState (state);
|
||||
|
||||
mainPlayerController.setPlayerActionsInputEnabledState (!state);
|
||||
}
|
||||
|
||||
public void resetActionIdOnTimeBulletJump ()
|
||||
{
|
||||
mainAnimator.SetInteger (actionIDAnimatorID, 0);
|
||||
}
|
||||
|
||||
public override void updateOnAnimatorIKState ()
|
||||
{
|
||||
if (!updateIKEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
mainAnimator.SetLookAtPosition (lookDirectionTarget);
|
||||
|
||||
mainAnimator.SetLookAtWeight (bodyWeight, 0.5f, 1.0f, 1.0f, 0.7f);
|
||||
|
||||
if (activateGetUp || jumpCoroutineActive) {
|
||||
bodyWeight = Mathf.Lerp (0, bodyWeight, currentTimeForRisingHands / bodyWeightLerpSpeed);
|
||||
} else {
|
||||
bodyWeight = Mathf.Lerp (1, bodyWeight, currentTimeForRisingHands / bodyWeightLerpSpeed);
|
||||
}
|
||||
|
||||
if (activateGetUp || jumpCoroutineActive) {
|
||||
if (!armsIKActive) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (currentTimeForRisingHands > 0) {
|
||||
currentTimeForRisingHands -= Time.unscaledDeltaTime;
|
||||
|
||||
currentArmsWeight = Mathf.Lerp (0, armsWeight, currentTimeForRisingHands / timeForRaisingHands);
|
||||
} else {
|
||||
currentTimeForRisingHands = 0;
|
||||
|
||||
currentArmsWeight = 0;
|
||||
|
||||
armsIKActive = false;
|
||||
}
|
||||
|
||||
} else {
|
||||
armsIKActive = true;
|
||||
|
||||
if (currentTimeForRisingHands < timeForRaisingHands) {
|
||||
currentTimeForRisingHands += Time.unscaledDeltaTime;
|
||||
|
||||
currentArmsWeight = Mathf.Lerp (0, armsWeight, currentTimeForRisingHands / timeForRaisingHands);
|
||||
} else {
|
||||
currentTimeForRisingHands = timeForRaisingHands;
|
||||
|
||||
currentArmsWeight = armsWeight;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setCurrentPlayerActionSystemCustomActionCategoryID ()
|
||||
{
|
||||
if (movementActive) {
|
||||
if (customActionCategoryID > -1) {
|
||||
mainPlayerController.setCurrentCustomActionCategoryID (customActionCategoryID);
|
||||
}
|
||||
} else {
|
||||
if (regularActionCategoryID > -1) {
|
||||
mainPlayerController.setCurrentCustomActionCategoryID (regularActionCategoryID);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void checkIfSetBulletTimeFiringState ()
|
||||
{
|
||||
if (movementEnabled) {
|
||||
if (activateGetUp) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (mainPlayerController.iscloseCombatAttackInProcess ()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (useOnlyWhenUsingFireWeapons) {
|
||||
if (!mainPlayerController.isPlayerUsingWeapons () ||
|
||||
mainPlayerWeaponsManager.weaponsAreMoving () ||
|
||||
mainPlayerWeaponsManager.currentWeaponIsMoving ()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (mainPlayerController.isExternalControllBehaviorActive ()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (mainPlayerController.isActionActive ()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (mainPlayerController.playerIsBusy ()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!mainPlayerController.canPlayerMove ()) {
|
||||
return;
|
||||
}
|
||||
|
||||
playerIsCarryingWeapons = mainPlayerController.isPlayerUsingWeapons ();
|
||||
|
||||
if (onlyActiveIfUsingFireWeapons) {
|
||||
if (!playerIsCarryingWeapons) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (movementActive) {
|
||||
if (mainPlayerController.isPlayerOnGround ()) {
|
||||
setMovementActiveState (false);
|
||||
} else {
|
||||
disableMovement ();
|
||||
}
|
||||
} else {
|
||||
if (!mainPlayerController.isPlayerOnGround ()) {
|
||||
return;
|
||||
}
|
||||
|
||||
setMovementActiveState (true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void inputSetTimeBullettFiring ()
|
||||
{
|
||||
checkIfSetBulletTimeFiringState ();
|
||||
}
|
||||
|
||||
public void checkEventOnStateChange (bool state)
|
||||
{
|
||||
if (state) {
|
||||
eventOnStart.Invoke ();
|
||||
} else {
|
||||
eventOnEnd.Invoke ();
|
||||
}
|
||||
}
|
||||
|
||||
public void setMovementEnabledState (bool state)
|
||||
{
|
||||
movementEnabled = state;
|
||||
}
|
||||
|
||||
//EDITOR FUNCTIONS
|
||||
public void setMovementEnabledStateFromEditor (bool state)
|
||||
{
|
||||
setMovementEnabledState (state);
|
||||
|
||||
updateComponent ();
|
||||
}
|
||||
|
||||
void updateComponent ()
|
||||
{
|
||||
GKC_Utils.updateComponent (this);
|
||||
|
||||
GKC_Utils.updateDirtyScene ("Update Bullet Time Firing System", gameObject);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 561cb443837fec1478d234c5af802460
|
||||
timeCreated: 1642467817
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 40995
|
||||
packageName: Game Kit Controller - Shooter Melee Adventure Creator 3D + 2.5D
|
||||
packageVersion: 3.77g
|
||||
assetPath: Assets/Game Kit Controller/Scripts/Player/Extra Movements/bulletTimeFiringSystem.cs
|
||||
uploadId: 814740
|
||||
@@ -0,0 +1,742 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class climbDetectionCollisionSystem : MonoBehaviour
|
||||
{
|
||||
[Header ("Main Settings")]
|
||||
[Space]
|
||||
|
||||
[SerializeField, Range (0f, 100f)]
|
||||
float maxSpeed = 10f;
|
||||
|
||||
[SerializeField, Range (0f, 100f)]
|
||||
float maxVerticalClimbSpeed = 4f;
|
||||
|
||||
[SerializeField, Range (0f, 100f)]
|
||||
float maxHorizontalClimbSpeed = 4;
|
||||
|
||||
[SerializeField, Range (0f, 100f)]
|
||||
float maxDiagonalUpClimbSpeed = 4;
|
||||
|
||||
[SerializeField, Range (0f, 100f)]
|
||||
float maxDiagonalDownClimbSpeed = 4;
|
||||
|
||||
[SerializeField, Range (0f, 100f)]
|
||||
float maxSlideDownClimbSpeed = 6;
|
||||
|
||||
[SerializeField, Range (0f, 100f)]
|
||||
float maxBoostClimbSpeedMultiplier = 1.5f;
|
||||
|
||||
[Space]
|
||||
|
||||
[SerializeField, Range (0f, 100f)]
|
||||
float maxAcceleration = 10f;
|
||||
|
||||
[SerializeField, Range (0f, 100f)]
|
||||
float maxAirAcceleration = 1f;
|
||||
|
||||
[SerializeField, Range (0f, 100f)]
|
||||
float maxClimbAcceleration = 40f;
|
||||
|
||||
[SerializeField, Range (0, 90)]
|
||||
float maxGroundAngle = 25f, maxStairsAngle = 50f;
|
||||
|
||||
[SerializeField, Range (90, 170)]
|
||||
float maxClimbAngle = 140f;
|
||||
|
||||
[SerializeField, Range (0f, 100f)]
|
||||
float maxSnapSpeed = 100f;
|
||||
|
||||
[Space]
|
||||
|
||||
[SerializeField]
|
||||
float probeDistance = 1f;
|
||||
|
||||
[SerializeField]
|
||||
LayerMask probeMask = -1, stairsMask = -1, climbMask = -1;
|
||||
|
||||
[SerializeField]
|
||||
float sphereRadius = 0.5f;
|
||||
|
||||
[SerializeField]
|
||||
float sphereAlignSpeed = 45;
|
||||
|
||||
[SerializeField]
|
||||
float sphereAirRotation = 0.5f;
|
||||
|
||||
[Space]
|
||||
[Header ("Curve Speed Settings")]
|
||||
[Space]
|
||||
|
||||
public bool useCurveSpeedEnabled = true;
|
||||
|
||||
public float horizontalCurveSpeed = 0.1f;
|
||||
public float verticalCurveSpeed = 0.1f;
|
||||
public float diagonalUpCurveSpeed = 0.1f;
|
||||
public float diagonalDownCurveSpeed = 0.1f;
|
||||
|
||||
[Space]
|
||||
|
||||
public AnimationCurve climbSpeedCurve;
|
||||
public AnimationCurve climbBoostSpeedCurve;
|
||||
|
||||
[Space]
|
||||
[Header ("Debug")]
|
||||
[Space]
|
||||
|
||||
public bool anyOnGround;
|
||||
|
||||
public int climbContactCount;
|
||||
|
||||
public int groundContactCount;
|
||||
|
||||
public int steepContactCount;
|
||||
|
||||
public int stepsSinceLastGrounded;
|
||||
|
||||
public bool climbDetectionActive;
|
||||
|
||||
[Space]
|
||||
|
||||
public Vector3 velocity;
|
||||
|
||||
public Vector3 contactNormal;
|
||||
|
||||
public Vector3 climbNormal;
|
||||
|
||||
public Vector3 steepNormal;
|
||||
public Vector3 lastClimbNormal;
|
||||
|
||||
public float currentCurveValue = 0;
|
||||
|
||||
[Space]
|
||||
[Header ("Movement Debug")]
|
||||
[Space]
|
||||
|
||||
public bool movingHorizontal;
|
||||
public bool movingVertical;
|
||||
public bool movingDiagonalUp;
|
||||
public bool movingDiagonalDown;
|
||||
|
||||
[Space]
|
||||
[Header ("Components")]
|
||||
[Space]
|
||||
|
||||
public freeClimbSystem mainFreeClimbSystem;
|
||||
|
||||
public Rigidbody mainRigidbody;
|
||||
|
||||
public Transform mainCameraTransform;
|
||||
|
||||
public Collider mainCollider;
|
||||
|
||||
public Collider mainPlayerCollider;
|
||||
|
||||
public Transform sphereTransform;
|
||||
|
||||
|
||||
Vector3 moveInput;
|
||||
|
||||
Rigidbody connectedBody;
|
||||
Rigidbody previousConnectedBody;
|
||||
|
||||
Vector3 connectionVelocity;
|
||||
|
||||
Vector3 connectionWorldPosition;
|
||||
Vector3 connectionLocalPosition;
|
||||
|
||||
Vector3 upAxis, rightAxis, forwardAxis;
|
||||
|
||||
Vector3 lastContactNormal;
|
||||
|
||||
Vector3 lastSteepNormal;
|
||||
|
||||
Vector3 lastConnectionVelocity;
|
||||
|
||||
float minGroundDotProduct, minStairsDotProduct, minClimbDotProduct;
|
||||
|
||||
Coroutine updateCoroutine;
|
||||
|
||||
float currentCurveSpeed = 0;
|
||||
|
||||
|
||||
public void updateObjectPosition (Vector3 newPosition)
|
||||
{
|
||||
transform.position = newPosition;
|
||||
}
|
||||
|
||||
public void enableOrDisableClimbDetection (bool state)
|
||||
{
|
||||
climbDetectionActive = state;
|
||||
|
||||
groundContactCount = 1;
|
||||
|
||||
mainRigidbody.isKinematic = !state;
|
||||
|
||||
mainCollider.enabled = state;
|
||||
|
||||
if (climbDetectionActive) {
|
||||
minGroundDotProduct = Mathf.Cos (maxGroundAngle * Mathf.Deg2Rad);
|
||||
|
||||
minStairsDotProduct = Mathf.Cos (maxStairsAngle * Mathf.Deg2Rad);
|
||||
|
||||
minClimbDotProduct = Mathf.Cos (maxClimbAngle * Mathf.Deg2Rad);
|
||||
|
||||
Physics.IgnoreCollision (mainCollider, mainPlayerCollider, true);
|
||||
|
||||
mainFreeClimbSystem.mainPlayerController.setIgnoreCollisionOnExternalColliderOnlyWithExtraColliderList (mainCollider, true);
|
||||
|
||||
Vector3 climbPosition = mainPlayerCollider.transform.position;
|
||||
|
||||
Vector3 climbDetectionCollisionPositionOffset = mainFreeClimbSystem.climbDetectionCollisionPositionOffset;
|
||||
|
||||
if (climbDetectionCollisionPositionOffset != Vector3.zero) {
|
||||
climbPosition += mainPlayerCollider.transform.right * climbDetectionCollisionPositionOffset.x;
|
||||
climbPosition += mainPlayerCollider.transform.up * climbDetectionCollisionPositionOffset.y;
|
||||
climbPosition += mainPlayerCollider.transform.forward * climbDetectionCollisionPositionOffset.z;
|
||||
}
|
||||
|
||||
transform.position = climbPosition;
|
||||
} else {
|
||||
|
||||
}
|
||||
|
||||
mainPlayerCollider.isTrigger = state;
|
||||
|
||||
if (climbDetectionActive) {
|
||||
updateCoroutine = StartCoroutine (updateSystemCoroutine ());
|
||||
} else {
|
||||
stopUpdateCoroutine ();
|
||||
}
|
||||
}
|
||||
|
||||
public void stopUpdateCoroutine ()
|
||||
{
|
||||
if (updateCoroutine != null) {
|
||||
StopCoroutine (updateCoroutine);
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator updateSystemCoroutine ()
|
||||
{
|
||||
var waitTime = new WaitForFixedUpdate ();
|
||||
|
||||
while (true) {
|
||||
updateSystem ();
|
||||
|
||||
yield return waitTime;
|
||||
}
|
||||
}
|
||||
|
||||
void updateSystem ()
|
||||
{
|
||||
moveInput.x = mainFreeClimbSystem.currentHorizontalMovement;
|
||||
moveInput.z = mainFreeClimbSystem.currentVerticalMovement;
|
||||
moveInput.y = 0;
|
||||
moveInput = Vector3.ClampMagnitude (moveInput, 1f);
|
||||
|
||||
|
||||
rightAxis = projectDirectionOnPlane (mainCameraTransform.right, upAxis);
|
||||
|
||||
forwardAxis = projectDirectionOnPlane (mainCameraTransform.forward, upAxis);
|
||||
|
||||
movingHorizontal = false;
|
||||
movingVertical = false;
|
||||
movingDiagonalUp = false;
|
||||
movingDiagonalDown = false;
|
||||
|
||||
if (moveInput.x != 0) {
|
||||
movingHorizontal = true;
|
||||
}
|
||||
|
||||
if (moveInput.z != 0) {
|
||||
movingVertical = true;
|
||||
}
|
||||
|
||||
if (movingHorizontal && movingVertical) {
|
||||
if (moveInput.z < 0) {
|
||||
movingDiagonalUp = false;
|
||||
movingDiagonalDown = true;
|
||||
} else {
|
||||
movingDiagonalUp = true;
|
||||
movingDiagonalDown = false;
|
||||
}
|
||||
}
|
||||
|
||||
updateSphereState ();
|
||||
}
|
||||
|
||||
|
||||
void FixedUpdate ()
|
||||
{
|
||||
if (climbDetectionActive) {
|
||||
anyOnGround = isOnGround ();
|
||||
|
||||
upAxis = mainFreeClimbSystem.getCurrentNormal ();
|
||||
|
||||
Vector3 gravity = -upAxis;
|
||||
//* mainVehicleGravityControl.getGravityForce ();
|
||||
|
||||
fixedUpdateSphereState ();
|
||||
|
||||
adjustVelocity ();
|
||||
|
||||
if (climbSurfaceDetected ()) {
|
||||
velocity -= contactNormal * (maxClimbAcceleration * 0.9f * Time.deltaTime);
|
||||
|
||||
} else if (isOnGround () && velocity.sqrMagnitude < 0.01f) {
|
||||
velocity += contactNormal * (Vector3.Dot (gravity, contactNormal) * Time.deltaTime);
|
||||
|
||||
} else if (climbDetectionActive && isOnGround ()) {
|
||||
velocity += (gravity - contactNormal * (maxClimbAcceleration * 0.9f)) * Time.deltaTime;
|
||||
|
||||
} else {
|
||||
velocity += gravity * Time.deltaTime;
|
||||
|
||||
}
|
||||
|
||||
mainRigidbody.linearVelocity = velocity;
|
||||
|
||||
mainFreeClimbSystem.updateClimbContactCount (climbContactCount);
|
||||
|
||||
mainFreeClimbSystem.updateContactNormal (contactNormal);
|
||||
|
||||
mainFreeClimbSystem.updateLastClimbNormal (lastClimbNormal);
|
||||
|
||||
clearState ();
|
||||
}
|
||||
}
|
||||
|
||||
void updateSphereState ()
|
||||
{
|
||||
Vector3 rotationPlaneNormal = lastContactNormal;
|
||||
|
||||
float rotationFactor = 1f;
|
||||
|
||||
if (climbSurfaceDetected ()) {
|
||||
|
||||
} else if (!isOnGround ()) {
|
||||
if (isOnSteep ()) {
|
||||
rotationPlaneNormal = lastSteepNormal;
|
||||
} else {
|
||||
rotationFactor = sphereAirRotation;
|
||||
}
|
||||
}
|
||||
|
||||
Vector3 movement = (mainRigidbody.linearVelocity - lastConnectionVelocity) * Time.deltaTime;
|
||||
|
||||
movement -= rotationPlaneNormal * Vector3.Dot (movement, rotationPlaneNormal);
|
||||
|
||||
float distance = movement.magnitude;
|
||||
|
||||
Quaternion rotation = sphereTransform.localRotation;
|
||||
|
||||
if (connectedBody != null && connectedBody == previousConnectedBody) {
|
||||
rotation = Quaternion.Euler (connectedBody.angularVelocity * (Mathf.Rad2Deg * Time.deltaTime)) * rotation;
|
||||
|
||||
if (distance < 0.001f) {
|
||||
sphereTransform.localRotation = rotation;
|
||||
|
||||
return;
|
||||
}
|
||||
} else if (distance < 0.001f) {
|
||||
return;
|
||||
}
|
||||
|
||||
float angle = distance * rotationFactor * (180f / Mathf.PI) / sphereRadius;
|
||||
|
||||
Vector3 rotationAxis = Vector3.Cross (rotationPlaneNormal, movement).normalized;
|
||||
|
||||
rotation = Quaternion.Euler (rotationAxis * angle) * rotation;
|
||||
|
||||
if (sphereAlignSpeed > 0f) {
|
||||
rotation = alignSphereRotation (rotationAxis, rotation, distance);
|
||||
}
|
||||
|
||||
sphereTransform.localRotation = rotation;
|
||||
}
|
||||
|
||||
Quaternion alignSphereRotation (Vector3 rotationAxis, Quaternion rotation, float traveledDistance)
|
||||
{
|
||||
Vector3 sphereAxis = sphereTransform.up;
|
||||
|
||||
float dot = Mathf.Clamp (Vector3.Dot (sphereAxis, rotationAxis), -1f, 1f);
|
||||
|
||||
float angle = Mathf.Acos (dot) * Mathf.Rad2Deg;
|
||||
|
||||
float maxAngle = sphereAlignSpeed * traveledDistance;
|
||||
|
||||
Quaternion newAlignment = Quaternion.FromToRotation (sphereAxis, rotationAxis) * rotation;
|
||||
|
||||
if (angle <= maxAngle) {
|
||||
return newAlignment;
|
||||
} else {
|
||||
return Quaternion.SlerpUnclamped (rotation, newAlignment, maxAngle / angle);
|
||||
}
|
||||
}
|
||||
|
||||
void clearState ()
|
||||
{
|
||||
lastContactNormal = contactNormal;
|
||||
|
||||
lastSteepNormal = steepNormal;
|
||||
|
||||
lastConnectionVelocity = connectionVelocity;
|
||||
|
||||
groundContactCount = steepContactCount = climbContactCount = 0;
|
||||
|
||||
contactNormal = steepNormal = climbNormal = Vector3.zero;
|
||||
|
||||
connectionVelocity = Vector3.zero;
|
||||
|
||||
previousConnectedBody = connectedBody;
|
||||
|
||||
connectedBody = null;
|
||||
}
|
||||
|
||||
void fixedUpdateSphereState ()
|
||||
{
|
||||
stepsSinceLastGrounded += 1;
|
||||
|
||||
velocity = mainRigidbody.linearVelocity;
|
||||
|
||||
if (checkClimbing () ||
|
||||
isOnGround () ||
|
||||
snapToGround () ||
|
||||
checkSteepContacts ()) {
|
||||
|
||||
stepsSinceLastGrounded = 0;
|
||||
|
||||
if (groundContactCount > 1) {
|
||||
contactNormal.Normalize ();
|
||||
}
|
||||
} else {
|
||||
contactNormal = upAxis;
|
||||
}
|
||||
|
||||
if (connectedBody != null) {
|
||||
if (connectedBody.isKinematic || connectedBody.mass >= mainRigidbody.mass) {
|
||||
updateConnectionState ();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void updateConnectionState ()
|
||||
{
|
||||
if (connectedBody == previousConnectedBody) {
|
||||
Vector3 connectionMovement = connectedBody.transform.TransformPoint (connectionLocalPosition) - connectionWorldPosition;
|
||||
|
||||
connectionVelocity = connectionMovement / Time.deltaTime;
|
||||
}
|
||||
|
||||
connectionWorldPosition = mainRigidbody.position;
|
||||
|
||||
connectionLocalPosition = connectedBody.transform.InverseTransformPoint (connectionWorldPosition);
|
||||
}
|
||||
|
||||
bool checkClimbing ()
|
||||
{
|
||||
if (climbSurfaceDetected ()) {
|
||||
if (climbContactCount > 1) {
|
||||
climbNormal.Normalize ();
|
||||
|
||||
float upDot = Vector3.Dot (upAxis, climbNormal);
|
||||
|
||||
if (upDot >= minGroundDotProduct) {
|
||||
climbNormal = lastClimbNormal;
|
||||
}
|
||||
}
|
||||
|
||||
groundContactCount = 1;
|
||||
|
||||
contactNormal = climbNormal;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool snapToGround ()
|
||||
{
|
||||
if (stepsSinceLastGrounded > 1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
float speed = velocity.magnitude;
|
||||
|
||||
if (speed > maxSnapSpeed) {
|
||||
return false;
|
||||
}
|
||||
|
||||
RaycastHit hit;
|
||||
|
||||
if (!Physics.Raycast (mainRigidbody.position, -upAxis, out hit, probeDistance, probeMask, QueryTriggerInteraction.Ignore)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Vector3 hitNormal = hit.normal;
|
||||
|
||||
float upDot = Vector3.Dot (upAxis, hitNormal);
|
||||
|
||||
if (upDot < getMinDot (hit.collider.gameObject.layer)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
groundContactCount = 1;
|
||||
|
||||
contactNormal = hitNormal;
|
||||
|
||||
float dot = Vector3.Dot (velocity, hitNormal);
|
||||
|
||||
if (dot > 0f) {
|
||||
velocity = (velocity - hitNormal * dot).normalized * speed;
|
||||
}
|
||||
|
||||
connectedBody = hit.rigidbody;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool checkSteepContacts ()
|
||||
{
|
||||
if (steepContactCount > 1) {
|
||||
steepNormal.Normalize ();
|
||||
|
||||
float upDot = Vector3.Dot (upAxis, steepNormal);
|
||||
|
||||
if (upDot >= minGroundDotProduct) {
|
||||
steepContactCount = 0;
|
||||
|
||||
groundContactCount = 1;
|
||||
|
||||
contactNormal = steepNormal;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void adjustVelocity ()
|
||||
{
|
||||
float acceleration, speed;
|
||||
|
||||
Vector3 xAxis, zAxis;
|
||||
|
||||
float boostInput = mainFreeClimbSystem.getCurrentClimbTurboSpeed ();
|
||||
|
||||
bool usingBoost = mainFreeClimbSystem.isTurboActive () && !mainFreeClimbSystem.isPauseTurboActive ();
|
||||
|
||||
bool isSlidingDownActive = mainFreeClimbSystem.isSlidingDownActive ();
|
||||
|
||||
float currentMaxSpeed = maxSpeed;
|
||||
|
||||
if (climbSurfaceDetected ()) {
|
||||
acceleration = maxClimbAcceleration;
|
||||
|
||||
speed = maxHorizontalClimbSpeed;
|
||||
|
||||
if (movingDiagonalDown) {
|
||||
speed = maxDiagonalDownClimbSpeed;
|
||||
} else if (movingDiagonalUp) {
|
||||
speed = maxDiagonalUpClimbSpeed;
|
||||
} else if (movingVertical) {
|
||||
speed = maxVerticalClimbSpeed;
|
||||
}
|
||||
|
||||
if (isSlidingDownActive) {
|
||||
speed = maxSlideDownClimbSpeed;
|
||||
}
|
||||
|
||||
if (usingBoost) {
|
||||
speed *= maxBoostClimbSpeedMultiplier;
|
||||
}
|
||||
|
||||
xAxis = Vector3.Cross (contactNormal, upAxis);
|
||||
|
||||
zAxis = upAxis;
|
||||
} else {
|
||||
acceleration = isOnGround () ? maxAcceleration : maxAirAcceleration;
|
||||
|
||||
float currentClimbSpeed = maxHorizontalClimbSpeed; ;
|
||||
|
||||
if (movingDiagonalDown) {
|
||||
currentClimbSpeed = maxDiagonalDownClimbSpeed;
|
||||
} else if (movingDiagonalUp) {
|
||||
currentClimbSpeed = maxDiagonalUpClimbSpeed;
|
||||
} else if (movingVertical) {
|
||||
currentClimbSpeed = maxVerticalClimbSpeed;
|
||||
}
|
||||
|
||||
if (isSlidingDownActive) {
|
||||
speed = maxSlideDownClimbSpeed;
|
||||
}
|
||||
|
||||
if (usingBoost) {
|
||||
currentClimbSpeed *= maxBoostClimbSpeedMultiplier;
|
||||
}
|
||||
|
||||
speed = isOnGround () && climbDetectionActive ? currentClimbSpeed : currentMaxSpeed;
|
||||
|
||||
xAxis = rightAxis;
|
||||
zAxis = forwardAxis;
|
||||
}
|
||||
|
||||
xAxis = projectDirectionOnPlane (xAxis, contactNormal);
|
||||
zAxis = projectDirectionOnPlane (zAxis, contactNormal);
|
||||
|
||||
if (useCurveSpeedEnabled) {
|
||||
|
||||
currentCurveSpeed = 0;
|
||||
|
||||
if (movingDiagonalDown) {
|
||||
currentCurveSpeed = diagonalDownCurveSpeed;
|
||||
} else if (movingDiagonalUp) {
|
||||
currentCurveSpeed = diagonalUpCurveSpeed;
|
||||
} else if (movingVertical) {
|
||||
currentCurveSpeed = verticalCurveSpeed;
|
||||
} else if (movingHorizontal) {
|
||||
currentCurveSpeed = horizontalCurveSpeed;
|
||||
}
|
||||
|
||||
if (isSlidingDownActive) {
|
||||
currentCurveSpeed = 0;
|
||||
}
|
||||
|
||||
if (currentCurveSpeed != 0) {
|
||||
var time = Mathf.Repeat ((float)Time.time, 1.0F);
|
||||
|
||||
if (usingBoost) {
|
||||
currentCurveValue = climbBoostSpeedCurve.Evaluate (time) * currentCurveSpeed;
|
||||
} else {
|
||||
currentCurveValue = climbSpeedCurve.Evaluate (time) * currentCurveSpeed;
|
||||
}
|
||||
}
|
||||
|
||||
if (currentCurveValue != 0) {
|
||||
speed *= currentCurveValue;
|
||||
}
|
||||
}
|
||||
|
||||
Vector3 relativeVelocity = velocity - connectionVelocity;
|
||||
|
||||
Vector3 adjustment;
|
||||
|
||||
adjustment.x = moveInput.x * speed - Vector3.Dot (relativeVelocity, xAxis);
|
||||
adjustment.z = moveInput.z * speed - Vector3.Dot (relativeVelocity, zAxis);
|
||||
adjustment.y = 0f;
|
||||
|
||||
adjustment = Vector3.ClampMagnitude (adjustment, acceleration * Time.deltaTime);
|
||||
|
||||
velocity += (xAxis * adjustment.x + zAxis * adjustment.z) * boostInput;
|
||||
}
|
||||
|
||||
bool isOnGround ()
|
||||
{
|
||||
return groundContactCount > 0;
|
||||
}
|
||||
|
||||
bool isOnSteep ()
|
||||
{
|
||||
return steepContactCount > 0;
|
||||
}
|
||||
|
||||
public bool climbSurfaceDetected ()
|
||||
{
|
||||
return climbContactCount > 0;
|
||||
}
|
||||
|
||||
void OnCollisionEnter (Collision collision)
|
||||
{
|
||||
EvaluateCollision (collision);
|
||||
}
|
||||
|
||||
void OnCollisionStay (Collision collision)
|
||||
{
|
||||
EvaluateCollision (collision);
|
||||
}
|
||||
|
||||
void EvaluateCollision (Collision collision)
|
||||
{
|
||||
int layer = collision.gameObject.layer;
|
||||
|
||||
float minDot = getMinDot (layer);
|
||||
|
||||
for (int i = 0; i < collision.contacts.Length; i++) {
|
||||
Vector3 normal = collision.contacts [i].normal;
|
||||
|
||||
float upDot = Vector3.Dot (upAxis, normal);
|
||||
|
||||
if (upDot >= minDot) {
|
||||
groundContactCount += 1;
|
||||
|
||||
contactNormal += normal;
|
||||
|
||||
connectedBody = collision.rigidbody;
|
||||
} else {
|
||||
if (upDot > -0.01f) {
|
||||
steepContactCount += 1;
|
||||
|
||||
steepNormal += normal;
|
||||
|
||||
if (groundContactCount == 0) {
|
||||
connectedBody = collision.rigidbody;
|
||||
}
|
||||
}
|
||||
|
||||
if (climbDetectionActive && upDot >= minClimbDotProduct && (climbMask & (1 << layer)) != 0) {
|
||||
|
||||
climbContactCount += 1;
|
||||
|
||||
climbNormal += normal;
|
||||
|
||||
lastClimbNormal = normal;
|
||||
|
||||
connectedBody = collision.rigidbody;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Vector3 projectDirectionOnPlane (Vector3 direction, Vector3 normal)
|
||||
{
|
||||
return (direction - normal * Vector3.Dot (direction, normal)).normalized;
|
||||
}
|
||||
|
||||
float getMinDot (int layer)
|
||||
{
|
||||
if ((stairsMask & (1 << layer)) == 0) {
|
||||
return minGroundDotProduct;
|
||||
} else {
|
||||
return minStairsDotProduct;
|
||||
}
|
||||
}
|
||||
|
||||
public Vector3 getMainRigidbodyVelocity ()
|
||||
{
|
||||
return mainRigidbody.linearVelocity;
|
||||
}
|
||||
|
||||
public Vector3 getMainRigidbodyPosition ()
|
||||
{
|
||||
return mainRigidbody.position;
|
||||
}
|
||||
|
||||
public Vector3 getLastClimbNormal ()
|
||||
{
|
||||
return lastClimbNormal;
|
||||
}
|
||||
|
||||
public Vector3 getContactNormal ()
|
||||
{
|
||||
return contactNormal;
|
||||
}
|
||||
|
||||
public void setNewParent (Transform newParent)
|
||||
{
|
||||
transform.SetParent (newParent);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 34cf004e2d174964281e39bb96c6106c
|
||||
timeCreated: 1682591552
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 40995
|
||||
packageName: Game Kit Controller - Shooter Melee Adventure Creator 3D + 2.5D
|
||||
packageVersion: 3.77g
|
||||
assetPath: Assets/Game Kit Controller/Scripts/Player/Extra Movements/climbDetectionCollisionSystem.cs
|
||||
uploadId: 814740
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 277a9da828efa1a479d62a9d6f71f305
|
||||
timeCreated: 1641540499
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 40995
|
||||
packageName: Game Kit Controller - Shooter Melee Adventure Creator 3D + 2.5D
|
||||
packageVersion: 3.77g
|
||||
assetPath: Assets/Game Kit Controller/Scripts/Player/Extra Movements/climbRopeSystem.cs
|
||||
uploadId: 814740
|
||||
@@ -0,0 +1,87 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class climbRopeTriggerMatchSystem : MonoBehaviour
|
||||
{
|
||||
[Header ("Main Settings")]
|
||||
[Space]
|
||||
|
||||
public bool movementZoneActive = true;
|
||||
|
||||
public bool checkOnTriggerEnter = true;
|
||||
public bool checkOnTriggerExit = true;
|
||||
|
||||
public string tagToCheck;
|
||||
|
||||
[Space]
|
||||
[Header ("Components")]
|
||||
[Space]
|
||||
|
||||
public climbRopeTriggerSystem mainClimbRopeTriggerSystem;
|
||||
|
||||
|
||||
GameObject currentPlayer;
|
||||
|
||||
|
||||
void OnTriggerEnter (Collider col)
|
||||
{
|
||||
checkTriggerInfo (col, true);
|
||||
}
|
||||
|
||||
void OnTriggerExit (Collider col)
|
||||
{
|
||||
checkTriggerInfo (col, false);
|
||||
}
|
||||
|
||||
public void checkTriggerInfo (Collider col, bool isEnter)
|
||||
{
|
||||
if (!movementZoneActive) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (isEnter) {
|
||||
if (!checkOnTriggerEnter) {
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
if (!checkOnTriggerExit) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (!col.gameObject.CompareTag (tagToCheck)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (isEnter) {
|
||||
currentPlayer = col.gameObject;
|
||||
|
||||
playerComponentsManager currentPlayerComponentsManager = currentPlayer.GetComponent<playerComponentsManager> ();
|
||||
|
||||
if (currentPlayerComponentsManager != null) {
|
||||
externalControllerBehavior movementExternalControllerBehavior = currentPlayerComponentsManager.getClimbRopeExternaControllerBehavior ();
|
||||
|
||||
if (movementExternalControllerBehavior != null) {
|
||||
climbRopeSystem currentClimbRopeSystem = movementExternalControllerBehavior.GetComponent<climbRopeSystem> ();
|
||||
|
||||
currentClimbRopeSystem.addClimbRopeTriggerMatchSystem (this);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
currentPlayer = col.gameObject;
|
||||
|
||||
playerComponentsManager currentPlayerComponentsManager = currentPlayer.GetComponent<playerComponentsManager> ();
|
||||
|
||||
if (currentPlayerComponentsManager != null) {
|
||||
externalControllerBehavior movementExternalControllerBehavior = currentPlayerComponentsManager.getClimbRopeExternaControllerBehavior ();
|
||||
|
||||
if (movementExternalControllerBehavior != null) {
|
||||
climbRopeSystem currentClimbRopeSystem = movementExternalControllerBehavior.GetComponent<climbRopeSystem> ();
|
||||
|
||||
currentClimbRopeSystem.removeClimbRopeTriggerMatchSystem (this);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 31299bc7605bd3a449bda73b9459baef
|
||||
timeCreated: 1641892453
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 40995
|
||||
packageName: Game Kit Controller - Shooter Melee Adventure Creator 3D + 2.5D
|
||||
packageVersion: 3.77g
|
||||
assetPath: Assets/Game Kit Controller/Scripts/Player/Extra Movements/climbRopeTriggerMatchSystem.cs
|
||||
uploadId: 814740
|
||||
@@ -0,0 +1,154 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class climbRopeTriggerSystem : MonoBehaviour
|
||||
{
|
||||
[Header ("Main Settings")]
|
||||
[Space]
|
||||
|
||||
public string tagToCheck;
|
||||
public bool movementZoneActive = true;
|
||||
|
||||
public Transform bottomTransform;
|
||||
public Transform topTransform;
|
||||
|
||||
public bool checkOnTriggerEnter = true;
|
||||
public bool checkOnTriggerExit = true;
|
||||
|
||||
public bool setPlayerAsChild = true;
|
||||
public Transform playerParentTransform;
|
||||
|
||||
public bool setNewClimbActionID;
|
||||
public int newClimbActionID;
|
||||
|
||||
[Space]
|
||||
[Header ("Remote Events Settings")]
|
||||
[Space]
|
||||
|
||||
public bool useRemoteEvents;
|
||||
public bool useRemoteEventOnStart;
|
||||
public List<string> remoteEventNameListOnStart = new List<string> ();
|
||||
|
||||
public bool useRemoteEventOnEnd;
|
||||
public List<string> remoteEventNameListOnEnd = new List<string> ();
|
||||
|
||||
GameObject currentPlayer;
|
||||
|
||||
|
||||
void OnTriggerEnter (Collider col)
|
||||
{
|
||||
checkTriggerInfo (col, true);
|
||||
}
|
||||
|
||||
void OnTriggerExit (Collider col)
|
||||
{
|
||||
checkTriggerInfo (col, false);
|
||||
}
|
||||
|
||||
public void checkTriggerInfo (Collider col, bool isEnter)
|
||||
{
|
||||
if (!movementZoneActive) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (isEnter) {
|
||||
if (!checkOnTriggerEnter) {
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
if (!checkOnTriggerExit) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (!col.gameObject.CompareTag (tagToCheck)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (isEnter) {
|
||||
currentPlayer = col.gameObject;
|
||||
|
||||
playerComponentsManager currentPlayerComponentsManager = currentPlayer.GetComponent<playerComponentsManager> ();
|
||||
|
||||
if (currentPlayerComponentsManager != null) {
|
||||
externalControllerBehavior movementExternalControllerBehavior = currentPlayerComponentsManager.getClimbRopeExternaControllerBehavior ();
|
||||
|
||||
if (movementExternalControllerBehavior != null) {
|
||||
climbRopeSystem currentClimbRopeSystem = movementExternalControllerBehavior.GetComponent<climbRopeSystem> ();
|
||||
|
||||
if (playerParentTransform == null) {
|
||||
playerParentTransform = transform;
|
||||
}
|
||||
|
||||
currentClimbRopeSystem.setCurrentClimbRopeTriggerSystem (this);
|
||||
|
||||
currentClimbRopeSystem.setSetPlayerAsChildStateState (setPlayerAsChild, playerParentTransform);
|
||||
|
||||
currentClimbRopeSystem.setTransformElements (bottomTransform, topTransform);
|
||||
|
||||
currentClimbRopeSystem.setMovementSystemActivestate (true);
|
||||
|
||||
if (setNewClimbActionID) {
|
||||
currentClimbRopeSystem.setNewClimbActionID (newClimbActionID);
|
||||
}
|
||||
|
||||
checkRemoteEvents (true, currentPlayer);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
currentPlayer = col.gameObject;
|
||||
|
||||
playerComponentsManager currentPlayerComponentsManager = currentPlayer.GetComponent<playerComponentsManager> ();
|
||||
|
||||
if (currentPlayerComponentsManager != null) {
|
||||
externalControllerBehavior movementExternalControllerBehavior = currentPlayerComponentsManager.getClimbRopeExternaControllerBehavior ();
|
||||
|
||||
if (movementExternalControllerBehavior != null) {
|
||||
climbRopeSystem currentClimbRopeSystem = movementExternalControllerBehavior.GetComponent<climbRopeSystem> ();
|
||||
|
||||
currentClimbRopeSystem.setSetPlayerAsChildStateState (false, null);
|
||||
|
||||
currentClimbRopeSystem.setMovementSystemActivestate (false);
|
||||
|
||||
currentClimbRopeSystem.setTransformElements (null, null);
|
||||
|
||||
currentClimbRopeSystem.setOriginalClimbActionID ();
|
||||
|
||||
checkRemoteEvents (false, currentPlayer);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void checkRemoteEvents (bool state, GameObject objectToCheck)
|
||||
{
|
||||
if (!useRemoteEvents) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (state) {
|
||||
if (useRemoteEventOnStart) {
|
||||
remoteEventSystem currentRemoteEventSystem = objectToCheck.GetComponent<remoteEventSystem> ();
|
||||
|
||||
if (currentRemoteEventSystem != null) {
|
||||
for (int i = 0; i < remoteEventNameListOnStart.Count; i++) {
|
||||
|
||||
currentRemoteEventSystem.callRemoteEvent (remoteEventNameListOnStart [i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (useRemoteEventOnEnd) {
|
||||
remoteEventSystem currentRemoteEventSystem = objectToCheck.GetComponent<remoteEventSystem> ();
|
||||
|
||||
if (currentRemoteEventSystem != null) {
|
||||
for (int i = 0; i < remoteEventNameListOnEnd.Count; i++) {
|
||||
|
||||
currentRemoteEventSystem.callRemoteEvent (remoteEventNameListOnEnd [i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 78e546c203f384a4ca05eddd5d3423ca
|
||||
timeCreated: 1641540867
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 40995
|
||||
packageName: Game Kit Controller - Shooter Melee Adventure Creator 3D + 2.5D
|
||||
packageVersion: 3.77g
|
||||
assetPath: Assets/Game Kit Controller/Scripts/Player/Extra Movements/climbRopeTriggerSystem.cs
|
||||
uploadId: 814740
|
||||
@@ -0,0 +1,140 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class externalControllerBehavior : MonoBehaviour
|
||||
{
|
||||
[Header ("Behavior Main Settings")]
|
||||
[Space]
|
||||
|
||||
public string behaviorName;
|
||||
|
||||
public bool externalControllerJumpEnabled;
|
||||
|
||||
[Space]
|
||||
[Header ("Disable Other Behaviors Settings")]
|
||||
[Space]
|
||||
|
||||
public bool canBeActivatedIfOthersBehaviorsActive;
|
||||
|
||||
public bool disableAllOthersBehaviorsOnActive;
|
||||
|
||||
public List<string> listOfBehaviorToDisableOnActive = new List<string> ();
|
||||
|
||||
[Space]
|
||||
[Header ("Action System Settings")]
|
||||
[Space]
|
||||
|
||||
public int customActionCategoryID = -1;
|
||||
public int regularActionCategoryID = -1;
|
||||
|
||||
[Space]
|
||||
[Header ("Debug")]
|
||||
[Space]
|
||||
|
||||
public bool behaviorCurrentlyActive;
|
||||
|
||||
public virtual void updateControllerBehavior ()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public virtual bool isCharacterOnGround ()
|
||||
{
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public virtual bool isBehaviorActive ()
|
||||
{
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public virtual void setExternalForceActiveState (bool state)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public virtual void setExternalForceEnabledState (bool state)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public virtual void updateExternalForceActiveState (Vector3 forceDirection, float forceAmount)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public virtual void checkIfActivateExternalForce ()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public virtual void setJumpActiveForExternalForce ()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public virtual void setExtraImpulseForce (Vector3 forceAmount, bool useCameraDirection)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public virtual void disableExternalControllerState ()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public virtual void checkIfResumeExternalControllerState ()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public virtual bool checkIfCanEnableBehavior (string behaviorName)
|
||||
{
|
||||
if (behaviorName != "") {
|
||||
if (disableAllOthersBehaviorsOnActive) {
|
||||
return true;
|
||||
} else {
|
||||
if (listOfBehaviorToDisableOnActive.Contains (behaviorName)) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void setBehaviorCurrentlyActiveState (bool state)
|
||||
{
|
||||
behaviorCurrentlyActive = state;
|
||||
}
|
||||
|
||||
public virtual bool isBehaviorCurrentlyActive ()
|
||||
{
|
||||
return behaviorCurrentlyActive;
|
||||
}
|
||||
|
||||
public virtual void setCurrentPlayerActionSystemCustomActionCategoryID ()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public virtual void checkPauseStateDuringExternalForceOrBehavior ()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public virtual void checkResumeStateAfterExternalForceOrBehavior ()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public virtual void checkChangeCameraViewStateOnExternalControllerBehavior ()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2724654d13705bc449698702051bd993
|
||||
timeCreated: 1608112213
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 40995
|
||||
packageName: Game Kit Controller - Shooter Melee Adventure Creator 3D + 2.5D
|
||||
packageVersion: 3.77g
|
||||
assetPath: Assets/Game Kit Controller/Scripts/Player/Extra Movements/externalControllerBehavior.cs
|
||||
uploadId: 814740
|
||||
@@ -0,0 +1,165 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
|
||||
public class externalControllerBehaviorManager : MonoBehaviour
|
||||
{
|
||||
[Header ("Main Settings")]
|
||||
[Space]
|
||||
|
||||
public List<externalControllerInfo> externalControllerInfoList = new List<externalControllerInfo> ();
|
||||
|
||||
[Space]
|
||||
[Header ("Debug")]
|
||||
[Space]
|
||||
|
||||
public bool showDebugPrint;
|
||||
|
||||
[Space]
|
||||
[Header ("Components")]
|
||||
[Space]
|
||||
|
||||
public playerInputManager mainPlayerInputManager;
|
||||
public playerWeaponsManager mainPlayerWeaponsManager;
|
||||
|
||||
public Transform playerTransform;
|
||||
|
||||
bool carryingWeaponsPreviously;
|
||||
bool aimingWeaponsPrevously;
|
||||
|
||||
|
||||
public void setExternalControllerActive (string nameToCheck)
|
||||
{
|
||||
setExternalControllerState (nameToCheck, true);
|
||||
}
|
||||
|
||||
public void setExternalControllerDeactive (string nameToCheck)
|
||||
{
|
||||
setExternalControllerState (nameToCheck, false);
|
||||
}
|
||||
|
||||
public void setExternalControllerState (string nameToCheck, bool state)
|
||||
{
|
||||
if (nameToCheck == null || nameToCheck == "") {
|
||||
return;
|
||||
}
|
||||
|
||||
if (showDebugPrint) {
|
||||
print ("External Controller state " + nameToCheck + " " + state);
|
||||
}
|
||||
|
||||
for (int i = 0; i < externalControllerInfoList.Count; i++) {
|
||||
externalControllerInfo currentInfo = externalControllerInfoList [i];
|
||||
|
||||
if (currentInfo.Name.Equals (nameToCheck)) {
|
||||
if (showDebugPrint) {
|
||||
print (nameToCheck + " state found");
|
||||
}
|
||||
|
||||
checkInputListToPauseDuringAction (currentInfo.customInputToPauseOnActionInfoList, state);
|
||||
|
||||
if (currentInfo.useEventsOnStateChange) {
|
||||
if (state) {
|
||||
currentInfo.eventOnStateActive.Invoke ();
|
||||
} else {
|
||||
currentInfo.eventOnStatDeactive.Invoke ();
|
||||
}
|
||||
}
|
||||
|
||||
if (state) {
|
||||
carryingWeaponsPreviously = mainPlayerWeaponsManager.isPlayerCarringWeapon ();
|
||||
|
||||
aimingWeaponsPrevously = mainPlayerWeaponsManager.isAimingWeapons ();
|
||||
|
||||
if (carryingWeaponsPreviously) {
|
||||
bool stopShootingWeaponActivated = mainPlayerWeaponsManager.stopShootingFireWeaponIfActive ();
|
||||
|
||||
if (aimingWeaponsPrevously) {
|
||||
mainPlayerWeaponsManager.setAimWeaponState (false);
|
||||
}
|
||||
|
||||
if (currentInfo.keepWeaponsDuringAction) {
|
||||
|
||||
mainPlayerWeaponsManager.checkIfDisableCurrentWeapon ();
|
||||
|
||||
mainPlayerWeaponsManager.resetWeaponHandIKWeight ();
|
||||
} else if (currentInfo.disableIKWeaponsDuringAction) {
|
||||
if (!stopShootingWeaponActivated) {
|
||||
mainPlayerWeaponsManager.stopShootingFireWeaponIfActive ();
|
||||
}
|
||||
|
||||
mainPlayerWeaponsManager.enableOrDisableIKOnWeaponsDuringAction (false);
|
||||
}
|
||||
}
|
||||
|
||||
if (currentInfo.keepMeleeWeaponGrabbed) {
|
||||
GKC_Utils.keepMeleeWeaponGrabbed (playerTransform.gameObject);
|
||||
}
|
||||
} else {
|
||||
if (carryingWeaponsPreviously) {
|
||||
if (currentInfo.drawWeaponsAfterAction) {
|
||||
mainPlayerWeaponsManager.checkIfDrawSingleOrDualWeapon ();
|
||||
} else if (currentInfo.disableIKWeaponsDuringAction) {
|
||||
mainPlayerWeaponsManager.enableOrDisableIKOnWeaponsDuringAction (true);
|
||||
}
|
||||
|
||||
carryingWeaponsPreviously = false;
|
||||
}
|
||||
|
||||
if (currentInfo.drawMeleeWeaponGrabbedOnActionEnd) {
|
||||
GKC_Utils.drawMeleeWeaponGrabbed (playerTransform.gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void checkInputListToPauseDuringAction (List<playerActionSystem.inputToPauseOnActionIfo> inputList, bool state)
|
||||
{
|
||||
for (int i = 0; i < inputList.Count; i++) {
|
||||
if (state) {
|
||||
inputList [i].previousActiveState = mainPlayerInputManager.setPlayerInputMultiAxesStateAndGetPreviousState (false, inputList [i].inputName);
|
||||
} else {
|
||||
if (inputList [i].previousActiveState) {
|
||||
mainPlayerInputManager.setPlayerInputMultiAxesState (inputList [i].previousActiveState, inputList [i].inputName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public class externalControllerInfo
|
||||
{
|
||||
public string Name;
|
||||
|
||||
public externalControllerBehavior mainExternalControllerBehavior;
|
||||
|
||||
[Space]
|
||||
[Space]
|
||||
|
||||
public bool keepWeaponsDuringAction = true;
|
||||
|
||||
public bool disableIKWeaponsDuringAction = true;
|
||||
|
||||
public bool drawWeaponsAfterAction;
|
||||
|
||||
public bool keepMeleeWeaponGrabbed = true;
|
||||
|
||||
public bool drawMeleeWeaponGrabbedOnActionEnd = true;
|
||||
|
||||
[Space]
|
||||
[Space]
|
||||
|
||||
public List<playerActionSystem.inputToPauseOnActionIfo> customInputToPauseOnActionInfoList = new List<playerActionSystem.inputToPauseOnActionIfo> ();
|
||||
|
||||
[Space]
|
||||
[Space]
|
||||
|
||||
public bool useEventsOnStateChange;
|
||||
public UnityEvent eventOnStateActive;
|
||||
public UnityEvent eventOnStatDeactive;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f86e7992408aed141b9eb62b247aeede
|
||||
timeCreated: 1646474653
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 40995
|
||||
packageName: Game Kit Controller - Shooter Melee Adventure Creator 3D + 2.5D
|
||||
packageVersion: 3.77g
|
||||
assetPath: Assets/Game Kit Controller/Scripts/Player/Extra Movements/externalControllerBehaviorManager.cs
|
||||
uploadId: 814740
|
||||
@@ -0,0 +1,561 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine.Events;
|
||||
|
||||
public class flySystem : externalControllerBehavior
|
||||
{
|
||||
[Header ("Main Settings")]
|
||||
[Space]
|
||||
|
||||
public bool flyModeEnabled = true;
|
||||
|
||||
public float flyForce;
|
||||
|
||||
public float airFriction = 5;
|
||||
|
||||
public float maxFlyVelocity = 50;
|
||||
|
||||
public float flyHorizontalSpeedMultiplier = 1;
|
||||
public float flyVerticalSpeedMultiplier = 2;
|
||||
|
||||
public bool useForceMode = true;
|
||||
|
||||
public ForceMode flyForceMode;
|
||||
|
||||
[Space]
|
||||
[Header ("Vertical Movement Settings")]
|
||||
[Space]
|
||||
|
||||
public bool moveUpAndDownEnabled = true;
|
||||
|
||||
public float flyMoveUpSpeed = 2;
|
||||
public float flyMoveDownSpeed = 2;
|
||||
|
||||
[Space]
|
||||
[Header ("Dash Settings")]
|
||||
[Space]
|
||||
|
||||
public bool setNewDashID;
|
||||
public int newDashID;
|
||||
|
||||
[Space]
|
||||
[Header ("Turbo Settings")]
|
||||
[Space]
|
||||
|
||||
public bool turboEnabled = true;
|
||||
public float flyTurboSpeed;
|
||||
|
||||
[Space]
|
||||
[Header ("Locked Camera Settings")]
|
||||
[Space]
|
||||
|
||||
public bool useCustomFlyMovementDirectionLockedCamera;
|
||||
|
||||
public Transform customFlyMovementDirectionLockedCamera;
|
||||
|
||||
[Space]
|
||||
[Header ("Other Settings")]
|
||||
[Space]
|
||||
|
||||
public float flyRotationSpeedTowardCameraDirection = 10;
|
||||
|
||||
public float flySpeedOnAimMultiplier = 0.5f;
|
||||
|
||||
public string shakeCameraStateName = "Use Fly Turbo";
|
||||
|
||||
[Space]
|
||||
[Header ("Animation Settings")]
|
||||
[Space]
|
||||
|
||||
public int regularAirID = -1;
|
||||
public int flyingID = 4;
|
||||
|
||||
public string flyingModeName = "Flying Mode";
|
||||
|
||||
public bool useIKFlying;
|
||||
|
||||
[Space]
|
||||
[Header ("Debug")]
|
||||
[Space]
|
||||
|
||||
public bool flyModeActive;
|
||||
public bool turboActive;
|
||||
|
||||
public bool playerIsMoving;
|
||||
|
||||
public bool movingUp;
|
||||
public bool movingDown;
|
||||
|
||||
public float velocityMagnitude;
|
||||
|
||||
public bool flyForcesPaused;
|
||||
|
||||
[Space]
|
||||
[Header ("Events Settings")]
|
||||
[Space]
|
||||
|
||||
public UnityEvent eventOnStateEnabled;
|
||||
public UnityEvent eventOnStateDisabled;
|
||||
|
||||
[Space]
|
||||
[Header ("Components")]
|
||||
[Space]
|
||||
|
||||
public playerController mainPlayerController;
|
||||
public playerCamera mainPlayerCamera;
|
||||
public IKSystem IKManager;
|
||||
public Rigidbody mainRigidbody;
|
||||
public Transform mainCameraTransform;
|
||||
public Transform playerCameraTransform;
|
||||
public Transform playerTransform;
|
||||
public dashSystem mainDashSystem;
|
||||
|
||||
public Transform COM;
|
||||
|
||||
Coroutine resetCOMCoroutine;
|
||||
|
||||
Vector3 totalForce;
|
||||
|
||||
float currentAimSpeedMultipler;
|
||||
|
||||
bool originalFlyModeEnabled;
|
||||
|
||||
int previousDashID = -1;
|
||||
|
||||
Transform currentLockedCameraTransform;
|
||||
|
||||
|
||||
void Start ()
|
||||
{
|
||||
originalFlyModeEnabled = flyModeEnabled;
|
||||
}
|
||||
|
||||
public override void updateControllerBehavior ()
|
||||
{
|
||||
//if the player is flying
|
||||
if (flyModeActive) {
|
||||
if (flyForcesPaused) {
|
||||
return;
|
||||
}
|
||||
|
||||
Vector3 mainCameraTransformForward = Vector3.zero;
|
||||
Vector3 mainCameraTransformRight = Vector3.zero;
|
||||
Vector3 mainCameraTransformUp = Vector3.zero;
|
||||
|
||||
bool isCameraTypeFree = mainPlayerCamera.isCameraTypeFree ();
|
||||
|
||||
bool isPlayerMovingOn3dWorld = mainPlayerController.isPlayerMovingOn3dWorld ();
|
||||
|
||||
if (isCameraTypeFree) {
|
||||
mainCameraTransformForward = mainCameraTransform.forward;
|
||||
mainCameraTransformRight = mainCameraTransform.right;
|
||||
} else {
|
||||
if (useCustomFlyMovementDirectionLockedCamera && isPlayerMovingOn3dWorld) {
|
||||
|
||||
currentLockedCameraTransform = customFlyMovementDirectionLockedCamera;
|
||||
} else {
|
||||
currentLockedCameraTransform = mainPlayerCamera.getLockedCameraTransform ();
|
||||
|
||||
}
|
||||
|
||||
mainCameraTransformForward = currentLockedCameraTransform.forward;
|
||||
mainCameraTransformRight = currentLockedCameraTransform.right;
|
||||
|
||||
mainCameraTransformUp = currentLockedCameraTransform.up;
|
||||
}
|
||||
|
||||
Vector3 targetDirection = Vector3.zero;
|
||||
|
||||
if (isPlayerMovingOn3dWorld) {
|
||||
targetDirection = mainCameraTransformForward * (mainPlayerController.getVerticalInput () * flyVerticalSpeedMultiplier) +
|
||||
mainCameraTransformRight * (mainPlayerController.getHorizontalInput () * flyHorizontalSpeedMultiplier);
|
||||
|
||||
if (!isCameraTypeFree && useCustomFlyMovementDirectionLockedCamera) {
|
||||
Vector3 localMove = playerTransform.InverseTransformDirection (targetDirection);
|
||||
|
||||
targetDirection = localMove;
|
||||
}
|
||||
|
||||
} else {
|
||||
targetDirection = mainCameraTransformUp * (mainPlayerController.getVerticalInput () * flyVerticalSpeedMultiplier) +
|
||||
mainCameraTransformRight * (mainPlayerController.getHorizontalInput () * flyHorizontalSpeedMultiplier);
|
||||
}
|
||||
|
||||
playerIsMoving = mainPlayerController.isPlayerMoving (0.1f);
|
||||
|
||||
if (!mainPlayerController.isPlayerOnFirstPerson () && !mainPlayerController.isPlayerRotatingToSurface ()) {
|
||||
if (isPlayerMovingOn3dWorld) {
|
||||
Quaternion COMTargetRotation = Quaternion.identity;
|
||||
|
||||
bool isPlayerUsingWeapons = mainPlayerController.isPlayerUsingWeapons ();
|
||||
|
||||
if (mainPlayerController.isFullBodyAwarenessActive () && isPlayerUsingWeapons) {
|
||||
float angleDifference = Quaternion.Angle (COM.localRotation, COMTargetRotation);
|
||||
|
||||
if (angleDifference > 0.05f) {
|
||||
COM.localRotation = Quaternion.Lerp (COM.localRotation, COMTargetRotation,
|
||||
flyRotationSpeedTowardCameraDirection * Time.fixedDeltaTime);
|
||||
}
|
||||
} else {
|
||||
if ((playerIsMoving && targetDirection != Vector3.zero) || (!isCameraTypeFree && !isPlayerUsingWeapons)) {
|
||||
float currentLookAngle = 0;
|
||||
|
||||
if (isCameraTypeFree) {
|
||||
currentLookAngle = Vector3.SignedAngle (playerCameraTransform.forward, mainCameraTransformForward, playerCameraTransform.right);
|
||||
}
|
||||
|
||||
if (Mathf.Abs (currentLookAngle) > 10 && !mainPlayerController.isPlayerAiming ()) {
|
||||
if (turboActive) {
|
||||
currentLookAngle = Mathf.Clamp (currentLookAngle, -50, 50);
|
||||
} else {
|
||||
currentLookAngle = Mathf.Clamp (currentLookAngle, -30, 30);
|
||||
}
|
||||
} else {
|
||||
currentLookAngle = 0;
|
||||
}
|
||||
|
||||
COMTargetRotation = Quaternion.Euler (Vector3.right * currentLookAngle);
|
||||
|
||||
Quaternion targetRotation = Quaternion.identity;
|
||||
|
||||
if (isCameraTypeFree) {
|
||||
targetRotation = playerCameraTransform.rotation;
|
||||
} else {
|
||||
targetRotation = currentLockedCameraTransform.rotation;
|
||||
}
|
||||
|
||||
playerTransform.rotation = Quaternion.Lerp (playerTransform.rotation, targetRotation,
|
||||
flyRotationSpeedTowardCameraDirection * Time.fixedDeltaTime);
|
||||
}
|
||||
|
||||
COM.localRotation = Quaternion.Lerp (COM.localRotation, COMTargetRotation,
|
||||
flyRotationSpeedTowardCameraDirection * Time.fixedDeltaTime);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
currentAimSpeedMultipler = 1;
|
||||
|
||||
if (!mainPlayerController.isPlayerOnFirstPerson () && mainPlayerController.isPlayerAiming ()) {
|
||||
currentAimSpeedMultipler = flySpeedOnAimMultiplier;
|
||||
}
|
||||
|
||||
totalForce = targetDirection * (flyForce * currentAimSpeedMultipler);
|
||||
|
||||
if (isPlayerMovingOn3dWorld) {
|
||||
if (movingUp) {
|
||||
totalForce += playerTransform.up * flyMoveUpSpeed;
|
||||
|
||||
playerIsMoving = true;
|
||||
}
|
||||
|
||||
if (movingDown) {
|
||||
totalForce -= playerTransform.up * flyMoveDownSpeed;
|
||||
|
||||
playerIsMoving = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (playerIsMoving) {
|
||||
if (turboActive) {
|
||||
totalForce *= flyTurboSpeed;
|
||||
}
|
||||
|
||||
velocityMagnitude = totalForce.magnitude;
|
||||
|
||||
if (velocityMagnitude > maxFlyVelocity) {
|
||||
totalForce = Vector3.ClampMagnitude (totalForce, maxFlyVelocity);
|
||||
}
|
||||
|
||||
velocityMagnitude = totalForce.magnitude;
|
||||
|
||||
if (useForceMode) {
|
||||
mainRigidbody.AddForce (totalForce, flyForceMode);
|
||||
} else {
|
||||
mainRigidbody.AddForce (totalForce);
|
||||
}
|
||||
} else {
|
||||
velocityMagnitude = mainRigidbody.linearVelocity.magnitude;
|
||||
|
||||
if (velocityMagnitude > 0) {
|
||||
totalForce = mainRigidbody.linearVelocity * (-1 * airFriction);
|
||||
}
|
||||
|
||||
mainRigidbody.AddForce (totalForce, flyForceMode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void enableOrDisableFlyingMode (bool state)
|
||||
{
|
||||
if (!flyModeEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (mainPlayerController.isUseExternalControllerBehaviorPaused ()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (flyModeActive == state) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (state) {
|
||||
externalControllerBehavior currentExternalControllerBehavior = mainPlayerController.getCurrentExternalControllerBehavior ();
|
||||
|
||||
if (currentExternalControllerBehavior != null && currentExternalControllerBehavior != this) {
|
||||
if (canBeActivatedIfOthersBehaviorsActive && checkIfCanEnableBehavior (currentExternalControllerBehavior.behaviorName)) {
|
||||
currentExternalControllerBehavior.disableExternalControllerState ();
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool flyModeActivePrevioulsy = flyModeActive;
|
||||
|
||||
flyModeActive = state;
|
||||
|
||||
mainPlayerController.enableOrDisableFlyingMode (state);
|
||||
|
||||
setBehaviorCurrentlyActiveState (state);
|
||||
|
||||
setCurrentPlayerActionSystemCustomActionCategoryID ();
|
||||
|
||||
if (flyModeActive) {
|
||||
mainPlayerController.setExternalControllerBehavior (this);
|
||||
} else {
|
||||
if (flyModeActivePrevioulsy) {
|
||||
externalControllerBehavior currentExternalControllerBehavior = mainPlayerController.getCurrentExternalControllerBehavior ();
|
||||
|
||||
if (currentExternalControllerBehavior == null || currentExternalControllerBehavior == this) {
|
||||
mainPlayerController.setExternalControllerBehavior (null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (useIKFlying) {
|
||||
IKManager.setIKBodyState (state, flyingModeName);
|
||||
}
|
||||
|
||||
if (!state) {
|
||||
mainPlayerController.setLastTimeFalling ();
|
||||
}
|
||||
|
||||
if (state) {
|
||||
mainPlayerController.setCurrentAirIDValue (flyingID);
|
||||
} else {
|
||||
mainPlayerController.setCurrentAirIDValue (regularAirID);
|
||||
|
||||
mainPlayerController.setCurrentAirSpeedValue (1);
|
||||
}
|
||||
|
||||
if (setNewDashID) {
|
||||
if (mainDashSystem != null) {
|
||||
if (state) {
|
||||
if (previousDashID == -1) {
|
||||
previousDashID = mainDashSystem.getCurrentDashID ();
|
||||
}
|
||||
|
||||
mainDashSystem.setCheckGroundPausedState (true);
|
||||
|
||||
mainDashSystem.setOverrideStrafeModeActiveStateResult (true);
|
||||
|
||||
mainDashSystem.setCurrentDashID (newDashID);
|
||||
} else {
|
||||
if (previousDashID != -1) {
|
||||
|
||||
mainDashSystem.setCurrentDashID (previousDashID);
|
||||
|
||||
previousDashID = -1;
|
||||
|
||||
mainDashSystem.setCheckGroundPausedState (false);
|
||||
|
||||
mainDashSystem.setOverrideStrafeModeActiveStateResult (false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (flyModeActive) {
|
||||
eventOnStateEnabled.Invoke ();
|
||||
} else {
|
||||
eventOnStateDisabled.Invoke ();
|
||||
|
||||
resetCOMRotation ();
|
||||
|
||||
if (turboActive) {
|
||||
enableOrDisableTurbo (false);
|
||||
}
|
||||
|
||||
enableOrDisableVerticalMovementUp (false);
|
||||
|
||||
enableOrDisableVerticalMovementDown (false);
|
||||
}
|
||||
|
||||
mainPlayerCamera.stopShakeCamera ();
|
||||
|
||||
if (flyModeActive) {
|
||||
mainPlayerController.setPlayerOnGroundState (false);
|
||||
|
||||
mainPlayerController.setOnGroundAnimatorIDValue (false);
|
||||
|
||||
mainPlayerController.setPreviousValueOnGroundAnimatorStateValue (false);
|
||||
}
|
||||
|
||||
movingUp = false;
|
||||
|
||||
movingDown = false;
|
||||
}
|
||||
|
||||
public void enableOrDisableTurbo (bool state)
|
||||
{
|
||||
turboActive = state;
|
||||
|
||||
mainPlayerController.enableOrDisableFlyModeTurbo (turboActive);
|
||||
|
||||
mainPlayerCamera.changeCameraFov (turboActive);
|
||||
|
||||
//when the player accelerates his movement in the air, the camera shakes
|
||||
if (turboActive) {
|
||||
mainPlayerCamera.setShakeCameraState (true, shakeCameraStateName);
|
||||
} else {
|
||||
mainPlayerCamera.setShakeCameraState (false, "");
|
||||
|
||||
mainPlayerCamera.stopShakeCamera ();
|
||||
}
|
||||
|
||||
if (turboActive) {
|
||||
mainPlayerController.setCurrentAirSpeedValue (2);
|
||||
} else {
|
||||
mainPlayerController.setCurrentAirSpeedValue (1);
|
||||
}
|
||||
}
|
||||
|
||||
public void resetCOMRotation ()
|
||||
{
|
||||
if (resetCOMCoroutine != null) {
|
||||
StopCoroutine (resetCOMCoroutine);
|
||||
}
|
||||
|
||||
resetCOMCoroutine = StartCoroutine (resetCOMRotationCoroutine ());
|
||||
}
|
||||
|
||||
public IEnumerator resetCOMRotationCoroutine ()
|
||||
{
|
||||
for (float t = 0; t < 1;) {
|
||||
t += Time.deltaTime * 4;
|
||||
|
||||
COM.localRotation = Quaternion.Slerp (COM.localRotation, Quaternion.identity, t);
|
||||
|
||||
yield return null;
|
||||
}
|
||||
}
|
||||
|
||||
public void inputChangeTurboState (bool state)
|
||||
{
|
||||
if (flyModeActive && turboEnabled) {
|
||||
enableOrDisableTurbo (state);
|
||||
}
|
||||
}
|
||||
|
||||
public void inputMoveUp (bool state)
|
||||
{
|
||||
if (flyModeActive && moveUpAndDownEnabled) {
|
||||
enableOrDisableVerticalMovementUp (state);
|
||||
}
|
||||
}
|
||||
|
||||
public void inputMoveDown (bool state)
|
||||
{
|
||||
if (flyModeActive && moveUpAndDownEnabled) {
|
||||
enableOrDisableVerticalMovementDown (state);
|
||||
}
|
||||
}
|
||||
|
||||
void enableOrDisableVerticalMovementUp (bool state)
|
||||
{
|
||||
movingUp = state;
|
||||
|
||||
if (movingUp) {
|
||||
movingDown = false;
|
||||
}
|
||||
}
|
||||
|
||||
void enableOrDisableVerticalMovementDown (bool state)
|
||||
{
|
||||
movingDown = state;
|
||||
|
||||
if (movingDown) {
|
||||
movingUp = false;
|
||||
}
|
||||
}
|
||||
|
||||
public void setFlyModeEnabledState (bool state)
|
||||
{
|
||||
if (flyModeActive) {
|
||||
enableOrDisableFlyingMode (false);
|
||||
}
|
||||
|
||||
flyModeEnabled = state;
|
||||
}
|
||||
|
||||
public void setOriginalFlyModeEnabledState ()
|
||||
{
|
||||
setFlyModeEnabledState (originalFlyModeEnabled);
|
||||
}
|
||||
|
||||
public override void disableExternalControllerState ()
|
||||
{
|
||||
enableOrDisableFlyingMode (false);
|
||||
}
|
||||
|
||||
public override void setCurrentPlayerActionSystemCustomActionCategoryID ()
|
||||
{
|
||||
if (behaviorCurrentlyActive) {
|
||||
if (customActionCategoryID > -1) {
|
||||
mainPlayerController.setCurrentCustomActionCategoryID (customActionCategoryID);
|
||||
}
|
||||
} else {
|
||||
if (regularActionCategoryID > -1) {
|
||||
mainPlayerController.setCurrentCustomActionCategoryID (regularActionCategoryID);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void checkPauseStateDuringExternalForceOrBehavior ()
|
||||
{
|
||||
flyForcesPaused = true;
|
||||
}
|
||||
|
||||
public override void checkResumeStateAfterExternalForceOrBehavior ()
|
||||
{
|
||||
if (flyModeActive) {
|
||||
setCurrentPlayerActionSystemCustomActionCategoryID ();
|
||||
|
||||
flyForcesPaused = false;
|
||||
}
|
||||
}
|
||||
|
||||
public void setEnableExternalForceOnFlyModeState (bool state)
|
||||
{
|
||||
if (flyModeActive) {
|
||||
mainPlayerController.setEnableExternalForceOnFlyModeState (state);
|
||||
}
|
||||
}
|
||||
|
||||
public void setFlyModeEnabledStateFromEditor (bool state)
|
||||
{
|
||||
setFlyModeEnabledState (state);
|
||||
|
||||
updateComponent ();
|
||||
}
|
||||
|
||||
void updateComponent ()
|
||||
{
|
||||
GKC_Utils.updateComponent (this);
|
||||
|
||||
GKC_Utils.updateDirtyScene ("Update Fly System", gameObject);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a98d7a433a016334a995b26efd31c0eb
|
||||
timeCreated: 1472232124
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 40995
|
||||
packageName: Game Kit Controller - Shooter Melee Adventure Creator 3D + 2.5D
|
||||
packageVersion: 3.77g
|
||||
assetPath: Assets/Game Kit Controller/Scripts/Player/Extra Movements/flySystem.cs
|
||||
uploadId: 814740
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,15 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 543ec5a1b3d90d04fae53cfc97180869
|
||||
timeCreated: 1660901422
|
||||
licenseType: Store
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 40995
|
||||
packageName: Game Kit Controller - Shooter Melee Adventure Creator 3D + 2.5D
|
||||
packageVersion: 3.77g
|
||||
assetPath: Assets/Game Kit Controller/Scripts/Player/Extra Movements/freeClimbSystem.cs.bak
|
||||
uploadId: 814740
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 902d7024813923e43af96cec4f0e5cb7
|
||||
timeCreated: 1655176838
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 40995
|
||||
packageName: Game Kit Controller - Shooter Melee Adventure Creator 3D + 2.5D
|
||||
packageVersion: 3.77g
|
||||
assetPath: Assets/Game Kit Controller/Scripts/Player/Extra Movements/freeClimbSystem.cs
|
||||
uploadId: 814740
|
||||
@@ -0,0 +1,145 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class freeClimbSystemIK : OnAnimatorIKComponent
|
||||
{
|
||||
[Header ("Main Settings")]
|
||||
[Space]
|
||||
|
||||
public bool climbSystemIKActive;
|
||||
|
||||
public LayerMask layerMask;
|
||||
|
||||
public float IKWeightEnabledSpeed = 10;
|
||||
public float IKWeightDisabledSpeed = 2;
|
||||
|
||||
public float raycastDistance = 1.3f;
|
||||
|
||||
public List<bodyPartIKInfo> bodyPartIKInfoList = new List<bodyPartIKInfo> ();
|
||||
|
||||
[Space]
|
||||
[Header ("Debug")]
|
||||
[Space]
|
||||
|
||||
public bool playerIsMoving;
|
||||
|
||||
[Space]
|
||||
[Header ("Components")]
|
||||
[Space]
|
||||
|
||||
public freeClimbSystem mainFreeClimbSystem;
|
||||
public Animator mainAnimator;
|
||||
public Transform playerTransform;
|
||||
|
||||
RaycastHit hit;
|
||||
|
||||
bool checkRaycast;
|
||||
|
||||
Vector3 currentTransformForward;
|
||||
|
||||
AvatarIKGoal currentIKGoal;
|
||||
|
||||
float minIKValue = 0.001f;
|
||||
|
||||
float currentAdjustmentSpeed;
|
||||
|
||||
bodyPartIKInfo currentBodyPartIKInfo;
|
||||
|
||||
int bodyPartIKInfoListCount;
|
||||
|
||||
|
||||
public override void updateOnAnimatorIKState ()
|
||||
{
|
||||
if (!updateIKEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!mainFreeClimbSystem.climbActive) {
|
||||
return;
|
||||
}
|
||||
|
||||
currentTransformForward = playerTransform.forward;
|
||||
|
||||
bool isPlayerMoving = mainFreeClimbSystem.isPlayerMoving ();
|
||||
|
||||
float currentDeltatime = Time.fixedDeltaTime;
|
||||
|
||||
for (int i = 0; i < bodyPartIKInfoListCount; i++) {
|
||||
currentBodyPartIKInfo = bodyPartIKInfoList [i];
|
||||
|
||||
AvatarIKGoal currentIKGoal = currentBodyPartIKInfo.IKGoal;
|
||||
|
||||
checkRaycast = true;
|
||||
|
||||
currentBodyPartIKInfo.targetWeight = 0;
|
||||
|
||||
currentAdjustmentSpeed = IKWeightDisabledSpeed;
|
||||
|
||||
if (isPlayerMoving) {
|
||||
checkRaycast = false;
|
||||
}
|
||||
|
||||
if (checkRaycast) {
|
||||
Vector3 direction = currentTransformForward;
|
||||
|
||||
if (Physics.Raycast (currentBodyPartIKInfo.IKGoalTransform.position - direction, direction, out hit, raycastDistance, layerMask)) {
|
||||
currentBodyPartIKInfo.newBodyPartPosition = hit.point - direction * currentBodyPartIKInfo.bodyPartOffset;
|
||||
|
||||
currentBodyPartIKInfo.targetWeight = 1;
|
||||
|
||||
currentAdjustmentSpeed = IKWeightEnabledSpeed;
|
||||
}
|
||||
}
|
||||
|
||||
currentBodyPartIKInfo.IKWeight =
|
||||
Mathf.Clamp01 (Mathf.Lerp (currentBodyPartIKInfo.IKWeight, currentBodyPartIKInfo.targetWeight, currentAdjustmentSpeed * currentDeltatime));
|
||||
|
||||
if (currentBodyPartIKInfo.IKWeight >= minIKValue) {
|
||||
|
||||
mainAnimator.SetIKPosition (currentIKGoal, currentBodyPartIKInfo.newBodyPartPosition);
|
||||
|
||||
mainAnimator.SetIKPositionWeight (currentIKGoal, currentBodyPartIKInfo.IKWeight);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void setActiveState (bool state)
|
||||
{
|
||||
climbSystemIKActive = state;
|
||||
|
||||
if (climbSystemIKActive) {
|
||||
|
||||
bodyPartIKInfoListCount = bodyPartIKInfoList.Count;
|
||||
|
||||
for (int i = 0; i < bodyPartIKInfoListCount; i++) {
|
||||
if (bodyPartIKInfoList [i].IKGoalTransform == null) {
|
||||
bodyPartIKInfoList [i].IKGoalTransform = mainAnimator.GetBoneTransform (bodyPartIKInfoList [i].mainBone);
|
||||
}
|
||||
|
||||
bodyPartIKInfoList [i].IKWeight = 0;
|
||||
bodyPartIKInfoList [i].targetWeight = 0;
|
||||
|
||||
bodyPartIKInfoList [i].newBodyPartPosition = Vector3.zero;
|
||||
}
|
||||
} else {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public class bodyPartIKInfo
|
||||
{
|
||||
public string Name;
|
||||
public AvatarIKGoal IKGoal;
|
||||
public HumanBodyBones mainBone;
|
||||
public Transform IKGoalTransform;
|
||||
|
||||
public float IKWeight;
|
||||
public float targetWeight;
|
||||
|
||||
public Vector3 newBodyPartPosition;
|
||||
|
||||
public float bodyPartOffset = 0.1f;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8addac3fcdec1094e81ad84f03b79957
|
||||
timeCreated: 1659294896
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 40995
|
||||
packageName: Game Kit Controller - Shooter Melee Adventure Creator 3D + 2.5D
|
||||
packageVersion: 3.77g
|
||||
assetPath: Assets/Game Kit Controller/Scripts/Player/Extra Movements/freeClimbSystemIK.cs
|
||||
uploadId: 814740
|
||||
@@ -0,0 +1,144 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class freeClimbZoneSystem : MonoBehaviour
|
||||
{
|
||||
[Header ("Main Settings")]
|
||||
[Space]
|
||||
|
||||
public string tagToCheck;
|
||||
public bool climbZoneActive = true;
|
||||
|
||||
public bool activateClimbCheckOnTriggerEnter = true;
|
||||
|
||||
public bool stopClimbOnTriggerExit;
|
||||
|
||||
public bool activateClimbStateAutomaticallyOnEnter;
|
||||
|
||||
public bool climbAutomaticallyOnlyIfPlayerOnAir;
|
||||
|
||||
[Space]
|
||||
[Header ("Action Settings")]
|
||||
[Space]
|
||||
|
||||
public bool ignoreSurfaceToClimbEnabled;
|
||||
|
||||
public bool allowClimbSurfaceOnInputEnabled;
|
||||
|
||||
public bool activateAutoSlideDownOnSurface;
|
||||
|
||||
public bool movementInputDisabledOnSurface;
|
||||
|
||||
[Space]
|
||||
[Header ("Other Settings")]
|
||||
[Space]
|
||||
|
||||
public bool setPlayerAsChild;
|
||||
|
||||
public Transform playerParentTransform;
|
||||
|
||||
GameObject currentPlayer;
|
||||
|
||||
|
||||
void OnTriggerEnter (Collider col)
|
||||
{
|
||||
checkTriggerInfo (col, true);
|
||||
}
|
||||
|
||||
void OnTriggerExit (Collider col)
|
||||
{
|
||||
checkTriggerInfo (col, false);
|
||||
}
|
||||
|
||||
public void checkTriggerInfo (Collider col, bool isEnter)
|
||||
{
|
||||
if (!climbZoneActive) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!col.gameObject.CompareTag (tagToCheck)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (isEnter) {
|
||||
currentPlayer = col.gameObject;
|
||||
|
||||
playerComponentsManager currentPlayerComponentsManager = currentPlayer.GetComponent<playerComponentsManager> ();
|
||||
|
||||
if (currentPlayerComponentsManager != null) {
|
||||
externalControllerBehavior freeClimbExteralControllerBehavior = currentPlayerComponentsManager.getFreeClimbExternalControllerBehavior ();
|
||||
|
||||
if (freeClimbExteralControllerBehavior != null) {
|
||||
freeClimbSystem currentFreeClimbSystem = freeClimbExteralControllerBehavior.GetComponent<freeClimbSystem> ();
|
||||
|
||||
if (activateClimbCheckOnTriggerEnter) {
|
||||
currentFreeClimbSystem.setCheckIfDetectClimbActiveState (true);
|
||||
|
||||
if (activateClimbStateAutomaticallyOnEnter) {
|
||||
bool canActivateClimbStateResult = true;
|
||||
|
||||
if (climbAutomaticallyOnlyIfPlayerOnAir) {
|
||||
if (currentPlayerComponentsManager.getPlayerController ().isPlayerOnGround ()) {
|
||||
canActivateClimbStateResult = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (canActivateClimbStateResult) {
|
||||
currentFreeClimbSystem.activateGrabSurface ();
|
||||
}
|
||||
}
|
||||
|
||||
// if (movementInputDisabledOnSurface) {
|
||||
// currentFreeClimbSystem.setMovementInputDisabledOnSurfaceState (true);
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
currentPlayer = col.gameObject;
|
||||
|
||||
playerComponentsManager currentPlayerComponentsManager = currentPlayer.GetComponent<playerComponentsManager> ();
|
||||
|
||||
if (currentPlayerComponentsManager != null) {
|
||||
externalControllerBehavior freeClimbExteralControllerBehavior = currentPlayerComponentsManager.getFreeClimbExternalControllerBehavior ();
|
||||
|
||||
if (freeClimbExteralControllerBehavior != null) {
|
||||
freeClimbSystem currentFreeClimbSystem = freeClimbExteralControllerBehavior.GetComponent<freeClimbSystem> ();
|
||||
|
||||
if (stopClimbOnTriggerExit) {
|
||||
currentFreeClimbSystem.setCheckIfDetectClimbActiveState (false);
|
||||
}
|
||||
|
||||
// if (movementInputDisabledOnSurface) {
|
||||
// currentFreeClimbSystem.setMovementInputDisabledOnSurfaceState (false);
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Transform checkPlayerParentState ()
|
||||
{
|
||||
if (setPlayerAsChild) {
|
||||
return playerParentTransform;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public bool isIgnoreSurfaceToClimbEnabled ()
|
||||
{
|
||||
return ignoreSurfaceToClimbEnabled;
|
||||
}
|
||||
|
||||
public void setIgnoreSurfaceToClimbEnabledState (bool state)
|
||||
{
|
||||
ignoreSurfaceToClimbEnabled = state;
|
||||
}
|
||||
|
||||
public bool isAllowClimbSurfaceOnInputEnabled ()
|
||||
{
|
||||
return allowClimbSurfaceOnInputEnabled;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8fd5dfcee1de27f44838c409bf8ef66b
|
||||
timeCreated: 1655185750
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 40995
|
||||
packageName: Game Kit Controller - Shooter Melee Adventure Creator 3D + 2.5D
|
||||
packageVersion: 3.77g
|
||||
assetPath: Assets/Game Kit Controller/Scripts/Player/Extra Movements/freeClimbZoneSystem.cs
|
||||
uploadId: 814740
|
||||
@@ -0,0 +1,329 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
|
||||
public class freeFallCharacterActivator : MonoBehaviour
|
||||
{
|
||||
[Header ("Main Settings")]
|
||||
[Space]
|
||||
|
||||
public bool checkCharacterFallEnabled = true;
|
||||
|
||||
public float minTimeOnAirToActivateFreeFall = 2;
|
||||
|
||||
public int regularAirID = -1;
|
||||
public int freeFallID = 3;
|
||||
|
||||
public bool setNewCameraStateOnFreeFallActive;
|
||||
|
||||
public string newCameraStateOnFreeFall;
|
||||
|
||||
public Vector3 capsuleColliderCenter = new Vector3 (0, 1, 0);
|
||||
|
||||
public bool useMinFallSpeedToActivateState;
|
||||
public float minFallSpeedToActivateState;
|
||||
|
||||
public bool avoidFallDamageOnFreeFall;
|
||||
|
||||
public bool avoidFallDamageOnFreeFallOnlyOnTurbo;
|
||||
|
||||
[Space]
|
||||
[Header ("Turbo Settings")]
|
||||
[Space]
|
||||
|
||||
public bool fallTurboEnabled = true;
|
||||
public float fallTurboMultiplier = 2;
|
||||
|
||||
public bool useCameraShake;
|
||||
public string regularCameraShakeName;
|
||||
|
||||
public bool useMaxFallSpeed;
|
||||
|
||||
public float maxFallSpeed;
|
||||
|
||||
[Space]
|
||||
|
||||
public bool useEventOnLandingWithTurbo;
|
||||
public UnityEvent eventOnLandingWithTurbo;
|
||||
|
||||
[Space]
|
||||
[Header ("Debug")]
|
||||
[Space]
|
||||
|
||||
public bool checkingFreeFall;
|
||||
|
||||
public bool freeFallActive;
|
||||
|
||||
public bool freeFallPaused;
|
||||
|
||||
public bool fallTurboActive;
|
||||
|
||||
[Space]
|
||||
[Header ("Event Settings")]
|
||||
[Space]
|
||||
|
||||
public bool useEventsOnFreeFallStateChange;
|
||||
public UnityEvent eventOnFreeFallActive;
|
||||
public UnityEvent eventOnFreeFallDeactivate;
|
||||
|
||||
[Space]
|
||||
[Header ("Components")]
|
||||
[Space]
|
||||
|
||||
public playerCamera mainPlayerCamera;
|
||||
|
||||
public playerController mainPlayerController;
|
||||
|
||||
float lastTimeFalling;
|
||||
|
||||
float lastTimeJump;
|
||||
|
||||
string previousCameraState;
|
||||
|
||||
bool resetCheckOnFreeFallActive;
|
||||
|
||||
void Update ()
|
||||
{
|
||||
if (checkCharacterFallEnabled) {
|
||||
if (freeFallPaused) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!checkingFreeFall) {
|
||||
if (!mainPlayerController.isPlayerOnGround () &&
|
||||
mainPlayerController.getCurrentAirID () == regularAirID &&
|
||||
!mainPlayerController.isExternalControlBehaviorForAirTypeActive () &&
|
||||
!mainPlayerController.isPlayerDriving ()) {
|
||||
|
||||
checkingFreeFall = true;
|
||||
|
||||
lastTimeFalling = Time.time;
|
||||
}
|
||||
} else {
|
||||
if (!freeFallActive) {
|
||||
if (Time.time > minTimeOnAirToActivateFreeFall + lastTimeFalling && checkFallSpeed ()) {
|
||||
|
||||
if (mainPlayerController.getCurrentAirID () == regularAirID) {
|
||||
setFreeFallState (true);
|
||||
} else {
|
||||
checkingFreeFall = false;
|
||||
}
|
||||
} else {
|
||||
if (mainPlayerController.isPlayerOnGround () ||
|
||||
mainPlayerController.isActionActive () ||
|
||||
mainPlayerController.isGravityPowerActive () ||
|
||||
mainPlayerController.isPlayerOnFFOrZeroGravityModeOn () ||
|
||||
mainPlayerController.isChoosingGravityDirection () ||
|
||||
mainPlayerController.isGravityForcePaused () ||
|
||||
mainPlayerController.isWallRunningActive () ||
|
||||
mainPlayerController.isSwimModeActive () ||
|
||||
mainPlayerController.isSphereModeActive () ||
|
||||
mainPlayerController.isExternalControlBehaviorForAirTypeActive () ||
|
||||
mainPlayerController.isPlayerDriving () ||
|
||||
mainPlayerController.isSlowFallExternallyActive ()) {
|
||||
|
||||
setFreeFallState (false);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (mainPlayerController.isPlayerOnGround () ||
|
||||
mainPlayerController.isPlayerAiming () ||
|
||||
lastTimeJump != mainPlayerController.getLastDoubleJumpTime () ||
|
||||
mainPlayerController.isExternalControlBehaviorForAirTypeActive () ||
|
||||
resetCheckOnFreeFallActive) {
|
||||
|
||||
resetRegularPlayerValues ();
|
||||
|
||||
disableFreeFallActiveState ();
|
||||
}
|
||||
|
||||
if (mainPlayerController.getCurrentAirID () != freeFallID) {
|
||||
disableFreeFallActiveState ();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void disableFreeFallActiveState ()
|
||||
{
|
||||
resetCheckOnFreeFallActive = false;
|
||||
|
||||
setFreeFallState (false);
|
||||
}
|
||||
|
||||
public void setFreeFallPausedState (bool state)
|
||||
{
|
||||
if (!state) {
|
||||
if (freeFallActive) {
|
||||
resetRegularPlayerValues ();
|
||||
|
||||
disableFreeFallActiveState ();
|
||||
}
|
||||
}
|
||||
|
||||
freeFallPaused = state;
|
||||
}
|
||||
|
||||
public bool checkFallSpeed ()
|
||||
{
|
||||
if (useMinFallSpeedToActivateState) {
|
||||
if (Mathf.Abs (mainPlayerController.getVerticalSpeed ()) > minFallSpeedToActivateState) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public void setResetCheckOnFreeFallActiveState (bool state)
|
||||
{
|
||||
resetCheckOnFreeFallActive = state;
|
||||
}
|
||||
|
||||
public void inputEnableOrDisableFallTurbo (bool state)
|
||||
{
|
||||
if (!fallTurboEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (freeFallActive) {
|
||||
setTurboState (state);
|
||||
}
|
||||
}
|
||||
|
||||
void setTurboState (bool state)
|
||||
{
|
||||
if (fallTurboActive == state) {
|
||||
return;
|
||||
}
|
||||
|
||||
fallTurboActive = state;
|
||||
|
||||
if (fallTurboActive) {
|
||||
mainPlayerController.setGravityMultiplierValueFromExternalFunction (fallTurboMultiplier);
|
||||
|
||||
mainPlayerController.setCurrentAirSpeedValue (2);
|
||||
|
||||
if (useCameraShake) {
|
||||
mainPlayerCamera.setShakeCameraState (true, regularCameraShakeName);
|
||||
}
|
||||
} else {
|
||||
mainPlayerController.setGravityMultiplierValue (true, 0);
|
||||
|
||||
mainPlayerController.setCurrentAirSpeedValue (1);
|
||||
|
||||
if (useCameraShake) {
|
||||
mainPlayerCamera.setShakeCameraState (false, "");
|
||||
}
|
||||
}
|
||||
|
||||
if (avoidFallDamageOnFreeFall && avoidFallDamageOnFreeFallOnlyOnTurbo) {
|
||||
mainPlayerController.setFallDamageCheckOnHealthPausedState (state);
|
||||
}
|
||||
|
||||
if (useMaxFallSpeed) {
|
||||
mainPlayerController.setUseMaxFallSpeedExternallyActiveState (state);
|
||||
|
||||
if (state) {
|
||||
mainPlayerController.setCustomMaxFallSpeedExternally (maxFallSpeed);
|
||||
} else {
|
||||
mainPlayerController.setCustomMaxFallSpeedExternally (0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void setFreeFallState (bool state)
|
||||
{
|
||||
if (state) {
|
||||
freeFallActive = true;
|
||||
|
||||
mainPlayerController.setCurrentAirIDValue (freeFallID);
|
||||
|
||||
mainPlayerController.setPlayerCapsuleColliderDirection (2);
|
||||
|
||||
mainPlayerController.setPlayerColliderCapsuleCenter (capsuleColliderCenter);
|
||||
|
||||
lastTimeJump = mainPlayerController.getLastDoubleJumpTime ();
|
||||
|
||||
if (setNewCameraStateOnFreeFallActive) {
|
||||
previousCameraState = mainPlayerCamera.getCurrentStateName ();
|
||||
|
||||
mainPlayerCamera.setCameraStateOnlyOnThirdPerson (newCameraStateOnFreeFall);
|
||||
}
|
||||
|
||||
if (avoidFallDamageOnFreeFall && !avoidFallDamageOnFreeFallOnlyOnTurbo) {
|
||||
mainPlayerController.setFallDamageCheckOnHealthPausedState (true);
|
||||
}
|
||||
|
||||
} else {
|
||||
if (avoidFallDamageOnFreeFall) {
|
||||
mainPlayerController.setFallDamageCheckOnHealthPausedState (false);
|
||||
}
|
||||
|
||||
if (fallTurboActive) {
|
||||
if (useEventOnLandingWithTurbo) {
|
||||
if (mainPlayerController.checkIfPlayerOnGroundWithRaycast () || mainPlayerController.isPlayerOnGround ()) {
|
||||
eventOnLandingWithTurbo.Invoke ();
|
||||
}
|
||||
}
|
||||
|
||||
setTurboState (false);
|
||||
}
|
||||
|
||||
checkingFreeFall = false;
|
||||
|
||||
freeFallActive = false;
|
||||
|
||||
if (setNewCameraStateOnFreeFallActive) {
|
||||
if (previousCameraState != "") {
|
||||
mainPlayerCamera.setCameraStateOnlyOnThirdPerson (previousCameraState);
|
||||
|
||||
previousCameraState = "";
|
||||
}
|
||||
}
|
||||
|
||||
if (useMaxFallSpeed) {
|
||||
mainPlayerController.setUseMaxFallSpeedExternallyActiveState (false);
|
||||
|
||||
mainPlayerController.setCustomMaxFallSpeedExternally (0);
|
||||
}
|
||||
}
|
||||
|
||||
checkEventsOnFreeFallStateChange (state);
|
||||
}
|
||||
|
||||
public void stopFreeFallStateIfActive ()
|
||||
{
|
||||
if (freeFallActive) {
|
||||
resetRegularPlayerValues ();
|
||||
|
||||
disableFreeFallActiveState ();
|
||||
}
|
||||
}
|
||||
|
||||
void resetRegularPlayerValues ()
|
||||
{
|
||||
if (mainPlayerController.getCurrentAirID () == freeFallID) {
|
||||
mainPlayerController.setCurrentAirIDValue (regularAirID);
|
||||
|
||||
mainPlayerController.setPlayerCapsuleColliderDirection (1);
|
||||
|
||||
mainPlayerController.setOriginalPlayerColliderCapsuleScale ();
|
||||
}
|
||||
}
|
||||
|
||||
void checkEventsOnFreeFallStateChange (bool state)
|
||||
{
|
||||
if (useEventsOnFreeFallStateChange) {
|
||||
if (state) {
|
||||
eventOnFreeFallActive.Invoke ();
|
||||
} else {
|
||||
eventOnFreeFallDeactivate.Invoke ();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d88ceceb9b7d35742b983e34d2f62662
|
||||
timeCreated: 1621379777
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 40995
|
||||
packageName: Game Kit Controller - Shooter Melee Adventure Creator 3D + 2.5D
|
||||
packageVersion: 3.77g
|
||||
assetPath: Assets/Game Kit Controller/Scripts/Player/Extra Movements/freeFallCharacterActivator.cs
|
||||
uploadId: 814740
|
||||
@@ -0,0 +1,630 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.Events;
|
||||
|
||||
public class jetpackSystem : externalControllerBehavior
|
||||
{
|
||||
[Header ("Main Setting")]
|
||||
[Space]
|
||||
|
||||
public bool jetpackEnabled;
|
||||
|
||||
public float jetpackForce;
|
||||
public float jetpackAirSpeed;
|
||||
public float jetpackAirControl;
|
||||
|
||||
public bool turboEnabled = true;
|
||||
public float jetpackTurboHorizontalSpeed = 5;
|
||||
public float jetpackTurboVerticalSpeed = 5;
|
||||
|
||||
public bool useForceMode;
|
||||
|
||||
public ForceMode forceMode;
|
||||
|
||||
[Space]
|
||||
[Header ("Other Settings")]
|
||||
[Space]
|
||||
|
||||
public bool disableJetpackMeshWhenNotEquipped = true;
|
||||
|
||||
public float jetpackHorizontalSpeedOnAimMultiplier = 0.5f;
|
||||
public float jetpackVerticalSpeedOnAimMultiplier = 0.5f;
|
||||
|
||||
public string shakeCameraStateName = "Use Jetpack Turbo";
|
||||
|
||||
[Space]
|
||||
|
||||
public bool useCustomJetpackUpDirection;
|
||||
public Transform customJetpackUpDirection;
|
||||
|
||||
public bool usedByAI;
|
||||
|
||||
[Space]
|
||||
[Header ("Fuel Settings")]
|
||||
[Space]
|
||||
|
||||
public float jetpackFuelAmount;
|
||||
public float jetpackFuelRate;
|
||||
public float regenerativeSpeed;
|
||||
public float timeToRegenerate;
|
||||
|
||||
[Space]
|
||||
[Header ("Animation Settings")]
|
||||
[Space]
|
||||
|
||||
public bool useJetpackAnimation = true;
|
||||
|
||||
public string jetpackModeName = "Jetpack Mode";
|
||||
|
||||
public int regularAirID = -1;
|
||||
public int jetpackID = 2;
|
||||
|
||||
public bool useIKJetpack;
|
||||
|
||||
public string animationName;
|
||||
|
||||
[Space]
|
||||
[Header ("Particles Settings")]
|
||||
[Space]
|
||||
|
||||
public List<ParticleSystem> thrustsParticles = new List<ParticleSystem> ();
|
||||
|
||||
[Space]
|
||||
[Header ("Debug")]
|
||||
[Space]
|
||||
|
||||
public bool jetPackEquiped;
|
||||
public bool usingJetpack;
|
||||
public bool turboActive;
|
||||
|
||||
public bool jetpackModePaused;
|
||||
|
||||
[Space]
|
||||
[Header ("Event Setting")]
|
||||
[Space]
|
||||
|
||||
public UnityEvent eventOnStartUsingJetpack;
|
||||
public UnityEvent eventOnStopUsingJetpack;
|
||||
|
||||
public UnityEvent eventOnStateEnabled;
|
||||
public UnityEvent eventOnStateDisabled;
|
||||
|
||||
[Space]
|
||||
[Header ("Components")]
|
||||
[Space]
|
||||
|
||||
public GameObject jetpack;
|
||||
public GameObject jetpackHUDInfo;
|
||||
public Slider jetpackSlider;
|
||||
public Text fuelAmountText;
|
||||
|
||||
public playerController mainPlayerController;
|
||||
public playerCamera mainPlayerCamera;
|
||||
public Animation jetPackAnimation;
|
||||
public IKSystem IKManager;
|
||||
public Transform playerTransform;
|
||||
|
||||
public Rigidbody mainRigidbody;
|
||||
|
||||
|
||||
bool hudEnabled;
|
||||
float lastTimeUsed;
|
||||
|
||||
Vector3 airMove;
|
||||
|
||||
float currentHorizontalAimSpeedMultipler;
|
||||
float currentVerticalAimSpeedMultipler;
|
||||
|
||||
Vector3 totalForce;
|
||||
|
||||
bool playerIsAiming;
|
||||
|
||||
bool turboActivePreviously;
|
||||
|
||||
bool originalJetpackEnabled;
|
||||
|
||||
externalControllerBehavior previousExternalControllerBehavior;
|
||||
|
||||
|
||||
void Start ()
|
||||
{
|
||||
if (usedByAI) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (jetpack == null) {
|
||||
jetpackEnabled = false;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
changeThrustsParticlesState (false);
|
||||
|
||||
if (jetpackFuelAmount > 0) {
|
||||
jetpackSlider.maxValue = jetpackFuelAmount;
|
||||
jetpackSlider.value = jetpackFuelAmount;
|
||||
|
||||
hudEnabled = true;
|
||||
|
||||
updateJetpackUIInfo ();
|
||||
}
|
||||
|
||||
if (!jetpackEnabled || disableJetpackMeshWhenNotEquipped) {
|
||||
if (jetpack.activeSelf) {
|
||||
jetpack.SetActive (false);
|
||||
}
|
||||
}
|
||||
|
||||
originalJetpackEnabled = jetpackEnabled;
|
||||
}
|
||||
|
||||
public override void updateControllerBehavior ()
|
||||
{
|
||||
if (usedByAI) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (jetPackEquiped) {
|
||||
//if the player is using the jetpack
|
||||
if (usingJetpack) {
|
||||
|
||||
currentHorizontalAimSpeedMultipler = 1;
|
||||
currentVerticalAimSpeedMultipler = 1;
|
||||
|
||||
playerIsAiming = mainPlayerController.isPlayerAiming ();
|
||||
|
||||
if (!mainPlayerController.isPlayerOnFirstPerson () && playerIsAiming) {
|
||||
currentHorizontalAimSpeedMultipler = jetpackHorizontalSpeedOnAimMultiplier;
|
||||
currentVerticalAimSpeedMultipler = jetpackVerticalSpeedOnAimMultiplier;
|
||||
}
|
||||
|
||||
airMove = mainPlayerController.getMoveInputDirection () * (jetpackAirSpeed * currentHorizontalAimSpeedMultipler);
|
||||
|
||||
if (turboActive) {
|
||||
airMove *= jetpackTurboHorizontalSpeed;
|
||||
}
|
||||
|
||||
Vector3 currentUpDirection = playerTransform.up;
|
||||
|
||||
if (useCustomJetpackUpDirection) {
|
||||
currentUpDirection = customJetpackUpDirection.up;
|
||||
}
|
||||
|
||||
airMove += playerTransform.InverseTransformDirection (mainPlayerController.currentVelocity).y * currentUpDirection;
|
||||
|
||||
mainPlayerController.currentVelocity = Vector3.Lerp (mainPlayerController.currentVelocity, airMove, Time.fixedDeltaTime * jetpackAirControl);
|
||||
|
||||
totalForce = currentUpDirection * (-mainPlayerController.getGravityForce () * mainRigidbody.mass * jetpackForce * currentVerticalAimSpeedMultipler);
|
||||
|
||||
if (turboActive) {
|
||||
totalForce *= jetpackTurboVerticalSpeed;
|
||||
}
|
||||
|
||||
if (useForceMode) {
|
||||
mainRigidbody.AddForce (totalForce, forceMode);
|
||||
} else {
|
||||
mainRigidbody.AddForce (totalForce);
|
||||
}
|
||||
|
||||
if (playerIsAiming) {
|
||||
if (turboActive) {
|
||||
if (!turboActivePreviously) {
|
||||
turboActivePreviously = true;
|
||||
|
||||
enableOrDisableTurbo (false);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (turboActivePreviously) {
|
||||
enableOrDisableTurbo (true);
|
||||
|
||||
turboActivePreviously = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (mainPlayerController.isPlayerOnFFOrZeroGravityModeOn ()) {
|
||||
enableOrDisableJetpack (false);
|
||||
}
|
||||
|
||||
if (usingJetpack) {
|
||||
mainPlayerController.setPlayerOnGroundState (false);
|
||||
|
||||
if (hudEnabled) {
|
||||
jetpackFuelAmount -= Time.deltaTime * jetpackFuelRate;
|
||||
|
||||
updateJetpackUIInfo ();
|
||||
|
||||
jetpackSlider.value = jetpackFuelAmount;
|
||||
}
|
||||
|
||||
if (jetpackFuelAmount <= 0) {
|
||||
startOrStopJetpack (false);
|
||||
}
|
||||
|
||||
} else {
|
||||
if (regenerativeSpeed > 0 && lastTimeUsed != 0) {
|
||||
|
||||
if (Time.time > lastTimeUsed + timeToRegenerate) {
|
||||
|
||||
jetpackFuelAmount += regenerativeSpeed * Time.deltaTime;
|
||||
|
||||
if (jetpackFuelAmount >= jetpackSlider.maxValue) {
|
||||
jetpackFuelAmount = jetpackSlider.maxValue;
|
||||
lastTimeUsed = 0;
|
||||
}
|
||||
|
||||
updateJetpackUIInfo ();
|
||||
|
||||
jetpackSlider.value = jetpackFuelAmount;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void updateJetpackUIInfo ()
|
||||
{
|
||||
//jetpackSlider.maxValue.ToString ("0") + " / " +
|
||||
fuelAmountText.text = jetpackFuelAmount.ToString ("0");
|
||||
}
|
||||
|
||||
public bool canUseJetpack ()
|
||||
{
|
||||
bool value = false;
|
||||
|
||||
if (jetpackFuelAmount > 0) {
|
||||
value = true;
|
||||
}
|
||||
|
||||
if (jetpackModePaused) {
|
||||
value = false;
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
public void startOrStopJetpack (bool state)
|
||||
{
|
||||
if (usingJetpack != state) {
|
||||
usingJetpack = state;
|
||||
|
||||
if (useJetpackAnimation) {
|
||||
if (usingJetpack) {
|
||||
jetPackAnimation [animationName].speed = 1;
|
||||
jetPackAnimation.Play (animationName);
|
||||
} else {
|
||||
jetPackAnimation [animationName].speed = -1;
|
||||
jetPackAnimation [animationName].time = jetPackAnimation [animationName].length;
|
||||
jetPackAnimation.Play (animationName);
|
||||
}
|
||||
}
|
||||
|
||||
if (usingJetpack) {
|
||||
externalControllerBehavior currentExternalControllerBehavior = mainPlayerController.getCurrentExternalControllerBehavior ();
|
||||
|
||||
if (currentExternalControllerBehavior != this) {
|
||||
if (previousExternalControllerBehavior == null && currentExternalControllerBehavior != null) {
|
||||
previousExternalControllerBehavior = currentExternalControllerBehavior;
|
||||
}
|
||||
|
||||
mainPlayerController.setExternalControllerBehavior (this);
|
||||
}
|
||||
}
|
||||
|
||||
mainPlayerController.setUsingJetpackState (usingJetpack);
|
||||
|
||||
if (!usingJetpack) {
|
||||
mainPlayerController.setLastTimeFalling ();
|
||||
|
||||
lastTimeUsed = Time.time;
|
||||
}
|
||||
|
||||
changeThrustsParticlesState (usingJetpack);
|
||||
|
||||
if (useIKJetpack) {
|
||||
IKManager.setIKBodyState (usingJetpack, jetpackModeName);
|
||||
}
|
||||
|
||||
if (usingJetpack) {
|
||||
mainPlayerController.setCurrentAirIDValue (jetpackID);
|
||||
} else {
|
||||
mainPlayerController.setCurrentAirIDValue (regularAirID);
|
||||
}
|
||||
|
||||
if (usingJetpack) {
|
||||
eventOnStartUsingJetpack.Invoke ();
|
||||
} else {
|
||||
eventOnStopUsingJetpack.Invoke ();
|
||||
}
|
||||
|
||||
if (!usingJetpack) {
|
||||
if (turboActive) {
|
||||
enableOrDisableTurbo (false);
|
||||
}
|
||||
}
|
||||
|
||||
turboActivePreviously = false;
|
||||
}
|
||||
}
|
||||
|
||||
public void changeThrustsParticlesState (bool state)
|
||||
{
|
||||
for (int i = 0; i < thrustsParticles.Count; i++) {
|
||||
if (state) {
|
||||
if (!thrustsParticles [i].isPlaying) {
|
||||
thrustsParticles [i].gameObject.SetActive (true);
|
||||
thrustsParticles [i].Play ();
|
||||
|
||||
var boostingParticlesMain = thrustsParticles [i].main;
|
||||
boostingParticlesMain.loop = true;
|
||||
}
|
||||
} else {
|
||||
if (thrustsParticles [i].isPlaying) {
|
||||
var boostingParticlesMain = thrustsParticles [i].main;
|
||||
boostingParticlesMain.loop = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void enableOrDisableJetpack (bool state)
|
||||
{
|
||||
if (!jetpackEnabled && state) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (jetPackEquiped == state) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (mainPlayerController.isUseExternalControllerBehaviorPaused ()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (jetpackModePaused && state) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (state) {
|
||||
externalControllerBehavior currentExternalControllerBehavior = mainPlayerController.getCurrentExternalControllerBehavior ();
|
||||
|
||||
if (currentExternalControllerBehavior != null && currentExternalControllerBehavior != this) {
|
||||
if (canBeActivatedIfOthersBehaviorsActive && checkIfCanEnableBehavior (currentExternalControllerBehavior.behaviorName)) {
|
||||
currentExternalControllerBehavior.disableExternalControllerState ();
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool jetpackEquipedPreviously = jetPackEquiped;
|
||||
|
||||
jetPackEquiped = state;
|
||||
|
||||
mainPlayerController.equipJetpack (state);
|
||||
|
||||
setBehaviorCurrentlyActiveState (state);
|
||||
|
||||
setCurrentPlayerActionSystemCustomActionCategoryID ();
|
||||
|
||||
if (jetPackEquiped) {
|
||||
if (previousExternalControllerBehavior == null) {
|
||||
previousExternalControllerBehavior = mainPlayerController.getCurrentExternalControllerBehavior ();
|
||||
|
||||
if (previousExternalControllerBehavior == this) {
|
||||
previousExternalControllerBehavior = null;
|
||||
}
|
||||
}
|
||||
|
||||
mainPlayerController.setExternalControllerBehavior (this);
|
||||
} else {
|
||||
if (jetpackEquipedPreviously) {
|
||||
externalControllerBehavior currentExternalControllerBehavior = mainPlayerController.getCurrentExternalControllerBehavior ();
|
||||
|
||||
if (currentExternalControllerBehavior == null || currentExternalControllerBehavior == this) {
|
||||
mainPlayerController.setExternalControllerBehavior (null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (jetPackEquiped) {
|
||||
if (hudEnabled) {
|
||||
if (jetpackHUDInfo.activeSelf != jetPackEquiped) {
|
||||
jetpackHUDInfo.SetActive (jetPackEquiped);
|
||||
}
|
||||
}
|
||||
|
||||
eventOnStateEnabled.Invoke ();
|
||||
} else {
|
||||
if (jetpackHUDInfo.activeSelf != jetPackEquiped) {
|
||||
jetpackHUDInfo.SetActive (jetPackEquiped);
|
||||
}
|
||||
|
||||
eventOnStateDisabled.Invoke ();
|
||||
|
||||
if (usingJetpack) {
|
||||
if (useJetpackAnimation) {
|
||||
jetPackAnimation [animationName].speed = -1;
|
||||
jetPackAnimation [animationName].time = 0;
|
||||
|
||||
jetPackAnimation.Rewind ();
|
||||
}
|
||||
|
||||
startOrStopJetpack (false);
|
||||
}
|
||||
}
|
||||
|
||||
if (disableJetpackMeshWhenNotEquipped) {
|
||||
if (jetpack != null) {
|
||||
if (jetpack.activeSelf != jetPackEquiped) {
|
||||
jetpack.SetActive (jetPackEquiped);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!state) {
|
||||
if (previousExternalControllerBehavior != null) {
|
||||
|
||||
if (previousExternalControllerBehavior != this) {
|
||||
previousExternalControllerBehavior.checkIfResumeExternalControllerState ();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void getJetpackFuel (float amount)
|
||||
{
|
||||
jetpackFuelAmount += amount;
|
||||
|
||||
if (jetpackFuelAmount > jetpackSlider.maxValue) {
|
||||
jetpackFuelAmount = jetpackSlider.maxValue;
|
||||
}
|
||||
|
||||
updateJetpackUIInfo ();
|
||||
|
||||
jetpackSlider.value = jetpackFuelAmount;
|
||||
}
|
||||
|
||||
public float getJetpackFuelAmountToPick ()
|
||||
{
|
||||
return jetpackSlider.maxValue - jetpackFuelAmount;
|
||||
}
|
||||
|
||||
public void enableOrDisableJetPackMesh (bool state)
|
||||
{
|
||||
if (!jetpackEnabled && state) {
|
||||
return;
|
||||
}
|
||||
|
||||
bool jetpackMeshState = state;
|
||||
|
||||
if (disableJetpackMeshWhenNotEquipped && !jetPackEquiped) {
|
||||
jetpackMeshState = false;
|
||||
}
|
||||
|
||||
if (jetpack != null) {
|
||||
if (jetpack.activeSelf != jetpackMeshState) {
|
||||
jetpack.SetActive (jetpackMeshState);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void removeJetpackMesh ()
|
||||
{
|
||||
if (jetpack != null) {
|
||||
DestroyImmediate (jetpack);
|
||||
}
|
||||
}
|
||||
|
||||
public void setUsedByAIState (bool state)
|
||||
{
|
||||
usedByAI = state;
|
||||
}
|
||||
|
||||
public void enableOrDisableTurbo (bool state)
|
||||
{
|
||||
turboActive = state;
|
||||
|
||||
mainPlayerCamera.changeCameraFov (turboActive);
|
||||
|
||||
//when the player accelerates his movement in the air, the camera shakes
|
||||
if (turboActive) {
|
||||
mainPlayerCamera.setShakeCameraState (true, shakeCameraStateName);
|
||||
} else {
|
||||
mainPlayerCamera.setShakeCameraState (false, "");
|
||||
|
||||
mainPlayerCamera.stopShakeCamera ();
|
||||
}
|
||||
|
||||
if (turboActive) {
|
||||
mainPlayerController.setCurrentAirSpeedValue (2);
|
||||
} else {
|
||||
mainPlayerController.setCurrentAirSpeedValue (1);
|
||||
}
|
||||
}
|
||||
|
||||
public void setJetpackEnabledState (bool state)
|
||||
{
|
||||
if (jetPackEquiped) {
|
||||
enableOrDisableJetpack (false);
|
||||
}
|
||||
|
||||
jetpackEnabled = state;
|
||||
}
|
||||
|
||||
public void setOriginalJetpackEnabledState ()
|
||||
{
|
||||
setJetpackEnabledState (originalJetpackEnabled);
|
||||
}
|
||||
|
||||
public void setJetpackModePausedState (bool state)
|
||||
{
|
||||
if (state) {
|
||||
if (usingJetpack) {
|
||||
startOrStopJetpack (false);
|
||||
}
|
||||
}
|
||||
|
||||
jetpackModePaused = state;
|
||||
}
|
||||
|
||||
//Input Elements
|
||||
public void inputStartOrStopJetpack (bool state)
|
||||
{
|
||||
if (jetPackEquiped && !mainPlayerController.driving && canUseJetpack ()) {
|
||||
startOrStopJetpack (state);
|
||||
}
|
||||
}
|
||||
|
||||
public void inputChangeTurboState (bool state)
|
||||
{
|
||||
if (jetPackEquiped && usingJetpack && turboEnabled) {
|
||||
if (state) {
|
||||
if (playerIsAiming) {
|
||||
turboActivePreviously = true;
|
||||
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
turboActivePreviously = false;
|
||||
}
|
||||
|
||||
enableOrDisableTurbo (state);
|
||||
}
|
||||
}
|
||||
|
||||
public override void disableExternalControllerState ()
|
||||
{
|
||||
enableOrDisableJetpack (false);
|
||||
}
|
||||
|
||||
public override void setCurrentPlayerActionSystemCustomActionCategoryID ()
|
||||
{
|
||||
if (behaviorCurrentlyActive) {
|
||||
if (customActionCategoryID > -1) {
|
||||
mainPlayerController.setCurrentCustomActionCategoryID (customActionCategoryID);
|
||||
}
|
||||
} else {
|
||||
if (regularActionCategoryID > -1) {
|
||||
mainPlayerController.setCurrentCustomActionCategoryID (regularActionCategoryID);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setJetpackEnabledStateFromEditor (bool state)
|
||||
{
|
||||
setJetpackEnabledState (state);
|
||||
|
||||
updateComponent ();
|
||||
}
|
||||
|
||||
void updateComponent ()
|
||||
{
|
||||
GKC_Utils.updateComponent (this);
|
||||
|
||||
GKC_Utils.updateDirtyScene ("Update Jetpack System", gameObject);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 78069a5ce99c82e49b3f94deaf3d8608
|
||||
timeCreated: 1468340135
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 40995
|
||||
packageName: Game Kit Controller - Shooter Melee Adventure Creator 3D + 2.5D
|
||||
packageVersion: 3.77g
|
||||
assetPath: Assets/Game Kit Controller/Scripts/Player/Extra Movements/jetpackSystem.cs
|
||||
uploadId: 814740
|
||||
@@ -0,0 +1,470 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine.Events;
|
||||
|
||||
public class paragliderSystem : externalControllerBehavior
|
||||
{
|
||||
[Header ("Main Settings")]
|
||||
[Space]
|
||||
|
||||
public bool paragliderModeEnabled = true;
|
||||
|
||||
public float gravityForce = -9.8f;
|
||||
public float gravityMultiplier;
|
||||
|
||||
public float minWaitTimeToActivateParaglider = 0.6f;
|
||||
|
||||
public float airSpeed = 25;
|
||||
public float airControl = 10;
|
||||
|
||||
[Space]
|
||||
[Header ("Extra Force Settings")]
|
||||
[Space]
|
||||
|
||||
public bool addExtraUpForce;
|
||||
public float extraUpForceAmount = 5;
|
||||
|
||||
public bool removeExtraUpForceAfterDelay;
|
||||
public float delayToRemoveExtraUpForce;
|
||||
|
||||
[Space]
|
||||
[Header ("Animation Settings")]
|
||||
[Space]
|
||||
|
||||
public int regularAirID = -1;
|
||||
public int paragliderID = 1;
|
||||
|
||||
[Space]
|
||||
[Header ("Debug")]
|
||||
[Space]
|
||||
|
||||
public bool showDebugPrint;
|
||||
|
||||
public bool paragliderModePaused;
|
||||
|
||||
public bool paragliderModeActive;
|
||||
|
||||
public bool playerIsMoving;
|
||||
|
||||
public bool externalForceActive;
|
||||
|
||||
public Vector3 externaForceDirection;
|
||||
|
||||
public float externalForceAmount;
|
||||
|
||||
public bool checkingToActivateParaglider;
|
||||
|
||||
public int externalForcesCounter;
|
||||
|
||||
public bool useLastTimeParagliderPauseActive;
|
||||
|
||||
public float previousGravityForce = -1000;
|
||||
|
||||
public float previousGravityMultiplier = -1000;
|
||||
|
||||
[Space]
|
||||
[Header ("Events Settings")]
|
||||
[Space]
|
||||
|
||||
public UnityEvent eventOnStateEnabled;
|
||||
public UnityEvent eventOnStateDisabled;
|
||||
|
||||
[Space]
|
||||
[Header ("Components")]
|
||||
[Space]
|
||||
|
||||
public playerController mainPlayerController;
|
||||
public playerCamera mainPlayerCamera;
|
||||
public Rigidbody mainRigidbody;
|
||||
public Transform playerTransform;
|
||||
|
||||
float lastTimeParagliderPauseActive;
|
||||
float useLastTimeParagliderPauseActiveDuration;
|
||||
|
||||
Coroutine checkingToActivateCoroutine;
|
||||
|
||||
bool originalParagliderModeEnabled;
|
||||
|
||||
float lastTimeParagliderActive;
|
||||
|
||||
|
||||
void Start ()
|
||||
{
|
||||
originalParagliderModeEnabled = paragliderModeEnabled;
|
||||
}
|
||||
|
||||
public override void updateControllerBehavior ()
|
||||
{
|
||||
if (paragliderModeActive) {
|
||||
if ((!mainPlayerController.isPlayerOnFirstPerson () && mainPlayerController.isPlayerAiming ()) ||
|
||||
mainPlayerController.isPlayerOnGround () ||
|
||||
mainPlayerController.isSwimModeActive () ||
|
||||
mainPlayerController.isWallRunningActive () ||
|
||||
mainPlayerController.isExternalControlBehaviorForAirTypeActive ()) {
|
||||
|
||||
enableOrDisableParagliderMode (false);
|
||||
}
|
||||
|
||||
mainPlayerController.setLastTimeFalling ();
|
||||
|
||||
Vector3 movementDirection = airSpeed * mainPlayerController.getMoveInputDirection ();
|
||||
|
||||
movementDirection += playerTransform.InverseTransformDirection (mainRigidbody.linearVelocity).y * playerTransform.up;
|
||||
|
||||
if (addExtraUpForce) {
|
||||
bool addExtraUpResult = true;
|
||||
|
||||
if (removeExtraUpForceAfterDelay) {
|
||||
if (Time.time > delayToRemoveExtraUpForce + lastTimeParagliderActive) {
|
||||
addExtraUpResult = false;
|
||||
}
|
||||
|
||||
}
|
||||
if (addExtraUpResult) {
|
||||
movementDirection += extraUpForceAmount * playerTransform.up;
|
||||
}
|
||||
}
|
||||
|
||||
if (externalForceActive) {
|
||||
movementDirection += externalForceAmount * externaForceDirection;
|
||||
}
|
||||
|
||||
mainPlayerController.setExternalForceOnAir (movementDirection, airControl);
|
||||
}
|
||||
}
|
||||
|
||||
public override bool isCharacterOnGround ()
|
||||
{
|
||||
if (paragliderModeActive) {
|
||||
return mainPlayerController.isPlayerOnGround ();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public override bool isBehaviorActive ()
|
||||
{
|
||||
return paragliderModeActive;
|
||||
}
|
||||
|
||||
public void enableOrDisableParagliderMode (bool state)
|
||||
{
|
||||
if (showDebugPrint) {
|
||||
print ("paraglider " + state);
|
||||
}
|
||||
|
||||
if (!paragliderModeEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (mainPlayerController.isUseExternalControllerBehaviorPaused ()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (paragliderModePaused && state) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (paragliderModeActive == state) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (state) {
|
||||
externalControllerBehavior currentExternalControllerBehavior = mainPlayerController.getCurrentExternalControllerBehavior ();
|
||||
|
||||
if (currentExternalControllerBehavior != null && currentExternalControllerBehavior != this) {
|
||||
if (canBeActivatedIfOthersBehaviorsActive && checkIfCanEnableBehavior (currentExternalControllerBehavior.behaviorName)) {
|
||||
currentExternalControllerBehavior.disableExternalControllerState ();
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool paragliderModeActivePrevioulsy = paragliderModeActive;
|
||||
|
||||
paragliderModeActive = state;
|
||||
|
||||
bool usingDifferentExternalControllerBehavior = false;
|
||||
|
||||
if (showDebugPrint) {
|
||||
print ("setting state");
|
||||
}
|
||||
|
||||
setBehaviorCurrentlyActiveState (state);
|
||||
|
||||
setCurrentPlayerActionSystemCustomActionCategoryID ();
|
||||
|
||||
if (paragliderModeActive) {
|
||||
mainPlayerController.setExternalControllerBehavior (this);
|
||||
} else {
|
||||
if (paragliderModeActivePrevioulsy) {
|
||||
externalControllerBehavior currentExternalControllerBehavior = mainPlayerController.getCurrentExternalControllerBehavior ();
|
||||
|
||||
if (currentExternalControllerBehavior == null || currentExternalControllerBehavior == this) {
|
||||
mainPlayerController.setExternalControllerBehavior (null);
|
||||
} else {
|
||||
usingDifferentExternalControllerBehavior = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!state) {
|
||||
if (!usingDifferentExternalControllerBehavior) {
|
||||
mainPlayerController.setLastTimeFalling ();
|
||||
}
|
||||
}
|
||||
|
||||
if (state) {
|
||||
mainPlayerController.setCurrentAirIDValue (paragliderID);
|
||||
} else {
|
||||
if (!usingDifferentExternalControllerBehavior) {
|
||||
mainPlayerController.setCurrentAirIDValue (regularAirID);
|
||||
}
|
||||
}
|
||||
|
||||
if (paragliderModeActive) {
|
||||
eventOnStateEnabled.Invoke ();
|
||||
} else {
|
||||
eventOnStateDisabled.Invoke ();
|
||||
}
|
||||
|
||||
mainPlayerController.setSlowFallExternallyActiveState (paragliderModeActive);
|
||||
|
||||
if (paragliderModeActive) {
|
||||
if (previousGravityForce == -1000) {
|
||||
previousGravityForce = mainPlayerController.getGravityForce ();
|
||||
|
||||
previousGravityMultiplier = mainPlayerController.getGravityMultiplier ();
|
||||
|
||||
if (previousGravityMultiplier > gravityMultiplier) {
|
||||
mainPlayerController.setGravityMultiplierValue (false, gravityMultiplier);
|
||||
}
|
||||
|
||||
if (previousGravityForce > gravityForce) {
|
||||
mainPlayerController.setGravityForceValue (false, gravityForce);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (previousGravityForce != -1000) {
|
||||
mainPlayerController.setGravityMultiplierValue (false, previousGravityMultiplier);
|
||||
|
||||
mainPlayerController.setGravityForceValue (false, previousGravityForce);
|
||||
|
||||
previousGravityForce = -1000;
|
||||
|
||||
previousGravityMultiplier = -1000;
|
||||
}
|
||||
}
|
||||
|
||||
mainPlayerCamera.stopShakeCamera ();
|
||||
|
||||
mainPlayerController.resetOtherInputFields ();
|
||||
|
||||
mainPlayerController.disableExternalForceOnAirActive ();
|
||||
|
||||
if (!paragliderModeActive) {
|
||||
if (mainPlayerController.checkIfPlayerOnGroundWithRaycast () || mainPlayerController.isPlayerOnGround ()) {
|
||||
mainPlayerController.setCheckOnGroungPausedState (false);
|
||||
|
||||
mainPlayerController.setPlayerOnGroundState (false);
|
||||
|
||||
mainPlayerController.setPlayerOnGroundAnimatorStateOnOverrideOnGroundWithTime (true);
|
||||
|
||||
mainPlayerController.disableOverrideOnGroundAnimatorValue ();
|
||||
|
||||
mainPlayerController.setPauseResetAnimatorStateFOrGroundAnimatorState (true);
|
||||
|
||||
|
||||
mainPlayerController.setJumpAnimatorIDValue (-9);
|
||||
|
||||
mainPlayerController.setPlayerOnGroundState (true);
|
||||
|
||||
mainPlayerController.setOnGroundAnimatorIDValue (true);
|
||||
}
|
||||
}
|
||||
|
||||
lastTimeParagliderActive = Time.time;
|
||||
}
|
||||
|
||||
public override void updateExternalForceActiveState (Vector3 forceDirection, float forceAmount)
|
||||
{
|
||||
if (!paragliderModeEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
externaForceDirection = forceDirection;
|
||||
|
||||
externalForceAmount = forceAmount;
|
||||
}
|
||||
|
||||
public override void setExternalForceActiveState (bool state)
|
||||
{
|
||||
if (!paragliderModeEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
externalForceActive = state;
|
||||
|
||||
if (state) {
|
||||
externalForcesCounter++;
|
||||
} else {
|
||||
externalForcesCounter--;
|
||||
}
|
||||
|
||||
if (externalForcesCounter < 0) {
|
||||
externalForcesCounter = 0;
|
||||
}
|
||||
|
||||
if (externalForcesCounter > 0) {
|
||||
externalForceActive = true;
|
||||
} else if (externalForcesCounter == 0) {
|
||||
externalForceActive = false;
|
||||
}
|
||||
}
|
||||
|
||||
public void inputToggletParagliderActiveState ()
|
||||
{
|
||||
if (paragliderModeActive) {
|
||||
enableOrDisableParagliderMode (false);
|
||||
} else {
|
||||
inputSetParagliderActiveState (!checkingToActivateParaglider);
|
||||
}
|
||||
}
|
||||
|
||||
public void inputSetParagliderActiveState (bool state)
|
||||
{
|
||||
if (!paragliderModeEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (mainPlayerController.isPlayerOnGround () ||
|
||||
mainPlayerController.isPlayerOnFFOrZeroGravityModeOn () ||
|
||||
mainPlayerController.isWallRunningActive () ||
|
||||
mainPlayerController.isSwimModeActive () ||
|
||||
mainPlayerController.isPlayerDriving () ||
|
||||
mainPlayerController.isExternalControlBehaviorForAirTypeActive ()) {
|
||||
|
||||
if (checkingToActivateParaglider) {
|
||||
|
||||
stopCheckingToActivateParagliderCoroutine ();
|
||||
|
||||
checkingToActivateParaglider = false;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (useLastTimeParagliderPauseActive) {
|
||||
if (Time.time < lastTimeParagliderPauseActive + useLastTimeParagliderPauseActiveDuration) {
|
||||
return;
|
||||
} else {
|
||||
useLastTimeParagliderPauseActive = false;
|
||||
}
|
||||
}
|
||||
|
||||
checkingToActivateParaglider = state;
|
||||
|
||||
if (checkingToActivateParaglider) {
|
||||
stopCheckingToActivateParagliderCoroutine ();
|
||||
|
||||
checkingToActivateCoroutine = StartCoroutine (checkingToActivateParagliderCoroutine ());
|
||||
} else {
|
||||
if (paragliderModeActive) {
|
||||
enableOrDisableParagliderMode (false);
|
||||
}
|
||||
|
||||
stopCheckingToActivateParagliderCoroutine ();
|
||||
}
|
||||
}
|
||||
|
||||
public void stopCheckingToActivateParagliderCoroutine ()
|
||||
{
|
||||
if (checkingToActivateCoroutine != null) {
|
||||
StopCoroutine (checkingToActivateCoroutine);
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator checkingToActivateParagliderCoroutine ()
|
||||
{
|
||||
WaitForSeconds delay = new WaitForSeconds (minWaitTimeToActivateParaglider);
|
||||
|
||||
yield return delay;
|
||||
|
||||
if (checkingToActivateParaglider) {
|
||||
|
||||
enableOrDisableParagliderMode (true);
|
||||
|
||||
checkingToActivateParaglider = false;
|
||||
}
|
||||
}
|
||||
|
||||
public void setParagliderModePausedState (bool state)
|
||||
{
|
||||
if (state) {
|
||||
if (paragliderModeActive) {
|
||||
enableOrDisableParagliderMode (false);
|
||||
}
|
||||
}
|
||||
|
||||
paragliderModePaused = state;
|
||||
}
|
||||
|
||||
public void setUseLastTimeParagliderPauseActive (float newDuration)
|
||||
{
|
||||
useLastTimeParagliderPauseActive = true;
|
||||
|
||||
lastTimeParagliderPauseActive = Time.time;
|
||||
|
||||
useLastTimeParagliderPauseActiveDuration = newDuration;
|
||||
}
|
||||
|
||||
public void setParagliderModeEnabledState (bool state)
|
||||
{
|
||||
if (paragliderModeActive) {
|
||||
enableOrDisableParagliderMode (false);
|
||||
}
|
||||
|
||||
paragliderModeEnabled = state;
|
||||
}
|
||||
|
||||
public void setOriginalParagliderModeEnabledState ()
|
||||
{
|
||||
setParagliderModeEnabledState (originalParagliderModeEnabled);
|
||||
}
|
||||
|
||||
public override void disableExternalControllerState ()
|
||||
{
|
||||
if (paragliderModeActive) {
|
||||
enableOrDisableParagliderMode (false);
|
||||
}
|
||||
}
|
||||
|
||||
public override void setCurrentPlayerActionSystemCustomActionCategoryID ()
|
||||
{
|
||||
if (behaviorCurrentlyActive) {
|
||||
if (customActionCategoryID > -1) {
|
||||
mainPlayerController.setCurrentCustomActionCategoryID (customActionCategoryID);
|
||||
}
|
||||
} else {
|
||||
if (regularActionCategoryID > -1) {
|
||||
mainPlayerController.setCurrentCustomActionCategoryID (regularActionCategoryID);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setParagliderModeEnabledStateFromEditor (bool state)
|
||||
{
|
||||
setParagliderModeEnabledState (state);
|
||||
|
||||
updateComponent ();
|
||||
}
|
||||
|
||||
void updateComponent ()
|
||||
{
|
||||
GKC_Utils.updateComponent (this);
|
||||
|
||||
GKC_Utils.updateDirtyScene ("Update Paraglider System", gameObject);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: aa96fce354d98d043b355a6baacfc0b3
|
||||
timeCreated: 1621049163
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 40995
|
||||
packageName: Game Kit Controller - Shooter Melee Adventure Creator 3D + 2.5D
|
||||
packageVersion: 3.77g
|
||||
assetPath: Assets/Game Kit Controller/Scripts/Player/Extra Movements/paragliderSystem.cs
|
||||
uploadId: 814740
|
||||
@@ -0,0 +1,544 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
|
||||
public class playerSphereModeSystem : MonoBehaviour
|
||||
{
|
||||
[Header ("Main Settings")]
|
||||
[Space]
|
||||
|
||||
public bool sphereModeEnabled;
|
||||
|
||||
public string defaultVehicleStateName = "Sphere";
|
||||
|
||||
[Space]
|
||||
[Header ("Vehicle Info List Settings")]
|
||||
[Space]
|
||||
|
||||
public List<vehicleInfo> vehicleInfoList = new List<vehicleInfo> ();
|
||||
|
||||
[Space]
|
||||
[Header ("Debug")]
|
||||
[Space]
|
||||
|
||||
public bool showDebugPrint;
|
||||
|
||||
public bool usingSphereMode;
|
||||
|
||||
public bool isExternalVehicleController;
|
||||
public mainRiderSystem currentRiderSystem;
|
||||
|
||||
public Transform currentRiderSystemTransform;
|
||||
|
||||
[Space]
|
||||
|
||||
public Transform currentObjectToControlTransform;
|
||||
public GameObject currentObjectToControl;
|
||||
|
||||
[Space]
|
||||
[Header ("Components")]
|
||||
[Space]
|
||||
|
||||
public playerController playerManager;
|
||||
public gravitySystem gravityManager;
|
||||
public usingDevicesSystem usingDevicesManager;
|
||||
public Collider playerCollider;
|
||||
|
||||
public overrideElementControlSystem mainOverrideElementControlSystem;
|
||||
|
||||
|
||||
Collider mainVehicleCollider;
|
||||
|
||||
GameObject vehicleCamera;
|
||||
vehicleGravityControl vehicleGravityManager;
|
||||
|
||||
bool initialized;
|
||||
|
||||
Coroutine updateCoroutine;
|
||||
|
||||
vehicleHUDManager currenVehicleHUDManager;
|
||||
|
||||
bool currenVehicleHUDManagerLocated;
|
||||
|
||||
vehicleInfo currentVehicleInfo;
|
||||
|
||||
|
||||
void stopUpdateCoroutine ()
|
||||
{
|
||||
if (updateCoroutine != null) {
|
||||
StopCoroutine (updateCoroutine);
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator updateSystemCoroutine ()
|
||||
{
|
||||
var waitTime = new WaitForFixedUpdate ();
|
||||
|
||||
while (true) {
|
||||
updateSystem ();
|
||||
|
||||
yield return waitTime;
|
||||
}
|
||||
}
|
||||
|
||||
void updateSystem ()
|
||||
{
|
||||
if (usingSphereMode && currenVehicleHUDManagerLocated) {
|
||||
if (currenVehicleHUDManager.vehicleIsDestroyed ()) {
|
||||
stopUpdateCoroutine ();
|
||||
|
||||
|
||||
//setSphereModeActiveState (false);
|
||||
|
||||
if (currentVehicleInfo.useEventOnVehicleDestroyed) {
|
||||
currentVehicleInfo.eventOnVehicleDestroyed.Invoke ();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void checkCurrentVehicleInfo ()
|
||||
{
|
||||
if (currentVehicleInfo == null || !initialized) {
|
||||
initialized = true;
|
||||
|
||||
setCurrentVehicleInfo (defaultVehicleStateName);
|
||||
}
|
||||
}
|
||||
|
||||
public void setCurrentVehicleInfo (string newVehicleInfoName)
|
||||
{
|
||||
for (int i = 0; i < vehicleInfoList.Count; i++) {
|
||||
if (vehicleInfoList [i].Name.Equals (newVehicleInfoName)) {
|
||||
if (currentVehicleInfo != null) {
|
||||
if (currentObjectToControl != null) {
|
||||
if (currentVehicleInfo != vehicleInfoList [i]) {
|
||||
currentObjectToControl = null;
|
||||
|
||||
currentRiderSystemTransform = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
currentVehicleInfo = vehicleInfoList [i];
|
||||
|
||||
if (!currentVehicleInfo.isCurrentVehicle) {
|
||||
if (currentVehicleInfo.useEventOnVehicleInfoState) {
|
||||
currentVehicleInfo.eventOnVehicleInfoState.Invoke ();
|
||||
}
|
||||
}
|
||||
|
||||
currentVehicleInfo.isCurrentVehicle = true;
|
||||
|
||||
if (showDebugPrint) {
|
||||
print ("setCurrentVehicleInfo " + newVehicleInfoName);
|
||||
}
|
||||
} else {
|
||||
if (vehicleInfoList [i].isCurrentVehicle) {
|
||||
setSphereModeActiveState (false);
|
||||
}
|
||||
|
||||
vehicleInfoList [i].isCurrentVehicle = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void toggleSphereModeActiveState ()
|
||||
{
|
||||
setSphereModeActiveState (!usingSphereMode);
|
||||
}
|
||||
|
||||
public void setSphereModeActiveState (bool state)
|
||||
{
|
||||
if (!sphereModeEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (showDebugPrint) {
|
||||
print ("calling setVehicleState coroutine " + state);
|
||||
}
|
||||
|
||||
if (playerManager.canUseSphereMode) {
|
||||
StartCoroutine (setVehicleState (state));
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator setVehicleState (bool state)
|
||||
{
|
||||
checkCurrentVehicleInfo ();
|
||||
|
||||
currenVehicleHUDManagerLocated = false;
|
||||
|
||||
usingSphereMode = state;
|
||||
|
||||
if (showDebugPrint) {
|
||||
print ("setVehicleState " + state);
|
||||
}
|
||||
|
||||
if (state) {
|
||||
if (currentVehicleInfo.controlWithOverrideSystem) {
|
||||
if (currentVehicleInfo.currentVehicleObject != null) {
|
||||
if (!mainOverrideElementControlSystem.checkIfTemporalObjectOnList (currentVehicleInfo.currentVehicleObject)) {
|
||||
currentVehicleInfo.currentVehicleObject = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (currentObjectToControl != null) {
|
||||
currenVehicleHUDManager = currentObjectToControl.GetComponentInChildren<vehicleHUDManager> ();
|
||||
|
||||
currenVehicleHUDManagerLocated = currenVehicleHUDManager != null;
|
||||
|
||||
if (currenVehicleHUDManagerLocated) {
|
||||
if (currenVehicleHUDManager.vehicleIsDestroyed ()) {
|
||||
currentVehicleInfo.currentVehicleObject = null;
|
||||
|
||||
currentObjectToControl = null;
|
||||
|
||||
currentRiderSystem = null;
|
||||
|
||||
if (showDebugPrint) {
|
||||
print ("current vehicle is destroying, removing to instantiate a new one");
|
||||
}
|
||||
|
||||
currenVehicleHUDManager = null;
|
||||
|
||||
currenVehicleHUDManagerLocated = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (currentVehicleInfo.currentVehicleObject == null) {
|
||||
Vector3 vehiclePosition = Vector3.one * 1000;
|
||||
|
||||
if (currentVehicleInfo.adjustVehicleParentToPlayerPosition) {
|
||||
vehiclePosition = playerManager.transform.position + playerManager.transform.up;
|
||||
}
|
||||
|
||||
currentVehicleInfo.currentVehicleObject = (GameObject)Instantiate (currentVehicleInfo.vehiclePrefab, vehiclePosition, Quaternion.identity);
|
||||
|
||||
if (!currentVehicleInfo.currentVehicleObject.activeSelf) {
|
||||
currentVehicleInfo.currentVehicleObject.SetActive (true);
|
||||
}
|
||||
|
||||
yield return new WaitForSeconds (0.00001f);
|
||||
|
||||
getCurrentVehicleComponents ();
|
||||
|
||||
if (vehicleGravityManager != null) {
|
||||
vehicleGravityManager.pauseDownForce (true);
|
||||
}
|
||||
|
||||
currentObjectToControlTransform.gameObject.SetActive (false);
|
||||
|
||||
if (mainVehicleCollider != null) {
|
||||
mainVehicleCollider.enabled = false;
|
||||
}
|
||||
|
||||
yield return new WaitForSeconds (0.00001f);
|
||||
|
||||
if (vehicleGravityManager != null) {
|
||||
vehicleGravityManager.pauseDownForce (false);
|
||||
}
|
||||
|
||||
yield return null;
|
||||
} else {
|
||||
getCurrentVehicleComponents ();
|
||||
|
||||
yield return null;
|
||||
}
|
||||
|
||||
// if (currentVehicleInfo.currentVehicleObject != null) {
|
||||
// getCurrentVehicleComponents ();
|
||||
// }
|
||||
|
||||
if (currentObjectToControl != null) {
|
||||
if (!currentObjectToControlTransform.gameObject.activeSelf) {
|
||||
if (vehicleGravityManager != null) {
|
||||
vehicleGravityManager.setCustomNormal (gravityManager.getCurrentNormal ());
|
||||
}
|
||||
|
||||
Vector3 vehiclePosition = playerManager.transform.position + playerManager.transform.up;
|
||||
|
||||
currentObjectToControlTransform.position = vehiclePosition;
|
||||
|
||||
if (currentVehicleInfo.setVehicleRotationWheGetOn) {
|
||||
currentObjectToControlTransform.rotation = playerManager.transform.rotation;
|
||||
}
|
||||
|
||||
if (vehicleCamera != null) {
|
||||
vehicleCamera.transform.position = vehiclePosition;
|
||||
}
|
||||
|
||||
if (isExternalVehicleController) {
|
||||
if (currentRiderSystemTransform != currentObjectToControlTransform) {
|
||||
print (currentObjectToControlTransform.name + " " + currentRiderSystemTransform.name);
|
||||
currentRiderSystemTransform.SetParent (currentObjectToControlTransform);
|
||||
|
||||
currentRiderSystemTransform.transform.localPosition = Vector3.zero;
|
||||
|
||||
currentRiderSystemTransform.transform.localRotation = Quaternion.identity;
|
||||
}
|
||||
}
|
||||
|
||||
if (!currentObjectToControlTransform.gameObject.activeSelf) {
|
||||
currentObjectToControlTransform.gameObject.SetActive (true);
|
||||
}
|
||||
|
||||
if (currentRiderSystem != null) {
|
||||
currentRiderSystem.setTriggerToDetect (playerCollider);
|
||||
}
|
||||
|
||||
yield return null;
|
||||
}
|
||||
|
||||
stopUpdateCoroutine ();
|
||||
|
||||
updateCoroutine = StartCoroutine (updateSystemCoroutine ());
|
||||
}
|
||||
} else {
|
||||
stopUpdateCoroutine ();
|
||||
|
||||
if (currentObjectToControl != null) {
|
||||
if (currentObjectToControlTransform.gameObject.activeSelf) {
|
||||
if (vehicleCamera != null) {
|
||||
if (currentVehicleInfo.setVehicleRotationWheGetOn) {
|
||||
currentObjectToControlTransform.rotation = vehicleCamera.transform.rotation;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (currentObjectToControl != null) {
|
||||
if (currentVehicleInfo.controlWithOverrideSystem) {
|
||||
if (state) {
|
||||
mainOverrideElementControlSystem.overrideElementControl (currentObjectToControl);
|
||||
|
||||
mainOverrideElementControlSystem.addNewTemporalObject (currentObjectToControl);
|
||||
} else {
|
||||
mainOverrideElementControlSystem.inputStopOverrideControl ();
|
||||
|
||||
if (mainOverrideElementControlSystem.checkIfTemporalObjectOnList (currentObjectToControl)) {
|
||||
currentObjectToControlTransform.gameObject.SetActive (false);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (state) {
|
||||
usingDevicesManager.clearDeviceList ();
|
||||
|
||||
usingDevicesManager.addDeviceToList (currentObjectToControl);
|
||||
|
||||
usingDevicesManager.setCurrentVehicle (currentObjectToControl);
|
||||
|
||||
usingDevicesManager.useCurrentDevice (currentObjectToControl);
|
||||
|
||||
usingDevicesManager.setUseDeviceButtonEnabledState (false);
|
||||
|
||||
usingDevicesManager.setPauseVehicleGetOffInputState (true);
|
||||
} else {
|
||||
if (currentVehicleInfo.currentVehicleObject != null) {
|
||||
usingDevicesManager.useDevice ();
|
||||
|
||||
usingDevicesManager.checkTriggerInfo (mainVehicleCollider, false);
|
||||
|
||||
usingDevicesManager.removeCurrentVehicle (currentObjectToControl);
|
||||
}
|
||||
|
||||
if (isExternalVehicleController) {
|
||||
currentRiderSystemTransform.SetParent (null);
|
||||
}
|
||||
|
||||
currentObjectToControlTransform.gameObject.SetActive (false);
|
||||
|
||||
usingDevicesManager.setUseDeviceButtonEnabledState (true);
|
||||
|
||||
usingDevicesManager.setPauseVehicleGetOffInputState (false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (state) {
|
||||
if (currentVehicleInfo != null) {
|
||||
playerManager.enableOrDisableSphereMode (true);
|
||||
|
||||
playerManager.setCheckOnGroungPausedState (true);
|
||||
|
||||
playerManager.setPlayerOnGroundState (false);
|
||||
|
||||
playerManager.setPlayerOnGroundAnimatorStateOnOverrideOnGroundWithTime (false);
|
||||
|
||||
playerManager.overrideOnGroundAnimatorValue (0);
|
||||
|
||||
playerManager.setPlayerOnGroundAnimatorStateOnOverrideOnGround (false);
|
||||
|
||||
playerManager.setOnGroundAnimatorIDValue (false);
|
||||
|
||||
currentVehicleInfo.isCurrentVehicle = true;
|
||||
}
|
||||
} else {
|
||||
if (currentVehicleInfo != null) {
|
||||
if (currentVehicleInfo.isCurrentVehicle) {
|
||||
|
||||
currentVehicleInfo.isCurrentVehicle = false;
|
||||
|
||||
playerManager.enableOrDisableSphereMode (false);
|
||||
|
||||
playerManager.setCheckOnGroungPausedState (false);
|
||||
|
||||
playerManager.setPlayerOnGroundState (false);
|
||||
|
||||
playerManager.setPlayerOnGroundAnimatorStateOnOverrideOnGroundWithTime (true);
|
||||
|
||||
playerManager.disableOverrideOnGroundAnimatorValue ();
|
||||
|
||||
playerManager.setPauseResetAnimatorStateFOrGroundAnimatorState (true);
|
||||
|
||||
if (playerManager.getCurrentSurfaceBelowPlayer () != null) {
|
||||
playerManager.setPlayerOnGroundState (true);
|
||||
|
||||
playerManager.setOnGroundAnimatorIDValue (true);
|
||||
}
|
||||
|
||||
if (currentVehicleInfo.destroyVehicleOnStopUse) {
|
||||
StartCoroutine (destroyVehicleObjectCororutine (currentVehicleInfo.currentVehicleObject));
|
||||
|
||||
currentVehicleInfo.currentVehicleObject = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (currentObjectToControl != null) {
|
||||
currenVehicleHUDManager = currentObjectToControl.GetComponentInChildren<vehicleHUDManager> ();
|
||||
|
||||
currenVehicleHUDManagerLocated = currenVehicleHUDManager != null;
|
||||
}
|
||||
}
|
||||
|
||||
void getCurrentVehicleComponents ()
|
||||
{
|
||||
if (currentVehicleInfo.controlWithOverrideSystem) {
|
||||
currentObjectToControl = currentVehicleInfo.currentVehicleObject;
|
||||
|
||||
currentObjectToControlTransform = currentObjectToControl.transform;
|
||||
} else {
|
||||
currentRiderSystem = currentVehicleInfo.currentVehicleObject.GetComponentInChildren<mainRiderSystem> ();
|
||||
|
||||
if (currentRiderSystem == null) {
|
||||
GKCRiderSocketSystem currentGKCRiderSocketSystem = currentVehicleInfo.currentVehicleObject.GetComponentInChildren<GKCRiderSocketSystem> ();
|
||||
|
||||
if (currentGKCRiderSocketSystem != null) {
|
||||
currentRiderSystem = currentGKCRiderSocketSystem.getMainRiderSystem ();
|
||||
}
|
||||
}
|
||||
|
||||
isExternalVehicleController = currentRiderSystem.isExternalVehicleController;
|
||||
|
||||
if (currentRiderSystem != null) {
|
||||
vehicleGravityManager = currentRiderSystem.getVehicleGravityControl ();
|
||||
|
||||
if (isExternalVehicleController) {
|
||||
currentRiderSystemTransform = currentRiderSystem.transform;
|
||||
|
||||
electronicDevice currentElectronicDevice = currentRiderSystem.gameObject.GetComponentInChildren<electronicDevice> ();
|
||||
|
||||
if (currentElectronicDevice != null) {
|
||||
currentElectronicDevice.setPlayerManually (playerManager.gameObject);
|
||||
}
|
||||
} else {
|
||||
currentRiderSystemTransform = null;
|
||||
}
|
||||
}
|
||||
|
||||
if (currentRiderSystem != null) {
|
||||
currentRiderSystem.setPlayerVisibleInVehicleState (currentVehicleInfo.playerVisibleInVehicle);
|
||||
|
||||
currentRiderSystem.setEjectPlayerWhenDestroyedState (currentVehicleInfo.ejectPlayerWhenDestroyed);
|
||||
|
||||
currentRiderSystem.setResetCameraRotationWhenGetOnState (currentVehicleInfo.resetCameraRotationWhenGetOn);
|
||||
}
|
||||
|
||||
if (currentRiderSystem != null) {
|
||||
currentObjectToControl = currentRiderSystem.getVehicleGameObject ();
|
||||
|
||||
currentObjectToControlTransform = currentRiderSystem.getCustomVehicleTransform ();
|
||||
|
||||
vehicleCamera = currentRiderSystem.getVehicleCameraGameObject ();
|
||||
}
|
||||
|
||||
mainVehicleCollider = currentObjectToControl.GetComponent<Collider> ();
|
||||
|
||||
tutorialActivatorSystem currentTutorialActivatorSystem = currentVehicleInfo.currentVehicleObject.GetComponent<tutorialActivatorSystem> ();
|
||||
|
||||
if (currentTutorialActivatorSystem != null) {
|
||||
currentTutorialActivatorSystem.setTutorialEnabledState (false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator destroyVehicleObjectCororutine (GameObject currentVehicleObject)
|
||||
{
|
||||
yield return new WaitForSeconds (0.00001f);
|
||||
|
||||
currenVehicleHUDManager = currentVehicleObject.GetComponent<vehicleHUDManager> ();
|
||||
|
||||
if (currenVehicleHUDManager != null) {
|
||||
currenVehicleHUDManager.destroyVehicleAtOnce ();
|
||||
} else {
|
||||
Destroy (currentVehicleInfo.currentVehicleObject);
|
||||
}
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public class vehicleInfo
|
||||
{
|
||||
[Header ("Main Settings")]
|
||||
[Space]
|
||||
|
||||
public string Name;
|
||||
|
||||
[Space]
|
||||
[Header ("Other Settings")]
|
||||
[Space]
|
||||
|
||||
public bool playerVisibleInVehicle;
|
||||
|
||||
public bool adjustVehicleParentToPlayerPosition;
|
||||
|
||||
public bool ejectPlayerWhenDestroyed = true;
|
||||
|
||||
public bool controlWithOverrideSystem;
|
||||
|
||||
public bool setVehicleRotationWheGetOn = true;
|
||||
|
||||
public bool resetCameraRotationWhenGetOn;
|
||||
|
||||
public bool destroyVehicleOnStopUse;
|
||||
|
||||
[Space]
|
||||
[Header ("Debug")]
|
||||
[Space]
|
||||
|
||||
public bool isCurrentVehicle;
|
||||
|
||||
public GameObject currentVehicleObject;
|
||||
|
||||
[Space]
|
||||
[Header ("Components Settings")]
|
||||
[Space]
|
||||
|
||||
public GameObject vehiclePrefab;
|
||||
|
||||
[Space]
|
||||
[Header ("Events Settings")]
|
||||
[Space]
|
||||
|
||||
public bool useEventOnVehicleInfoState;
|
||||
public UnityEvent eventOnVehicleInfoState;
|
||||
|
||||
public bool useEventOnVehicleDestroyed;
|
||||
public UnityEvent eventOnVehicleDestroyed;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4accd2f648fb0df43b04c56d06cf4f00
|
||||
timeCreated: 1554011709
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 40995
|
||||
packageName: Game Kit Controller - Shooter Melee Adventure Creator 3D + 2.5D
|
||||
packageVersion: 3.77g
|
||||
assetPath: Assets/Game Kit Controller/Scripts/Player/Extra Movements/playerSphereModeSystem.cs
|
||||
uploadId: 814740
|
||||
@@ -0,0 +1,179 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class portableClimbRopeTriggerSystem : MonoBehaviour
|
||||
{
|
||||
[Header ("Main Settings")]
|
||||
[Space]
|
||||
|
||||
public bool useDownRaycastDirection;
|
||||
|
||||
public LayerMask raycastLayermask;
|
||||
|
||||
public float maxRaycastDistance;
|
||||
|
||||
public bool adjustRopeEndToAnyDistance;
|
||||
|
||||
public bool activateOnStart;
|
||||
|
||||
[Space]
|
||||
[Header ("Other Settings")]
|
||||
[Space]
|
||||
|
||||
public bool checkSurfaceLayer;
|
||||
public LayerMask layerSurface;
|
||||
public float raycastRadius;
|
||||
public bool destroyObjectIfSurfaceNotFound;
|
||||
|
||||
public bool checkSurfaceInclination;
|
||||
public float maxSurfaceInclination;
|
||||
|
||||
[Space]
|
||||
[Header ("Debug")]
|
||||
[Space]
|
||||
|
||||
public bool showDebugPrint;
|
||||
|
||||
[Space]
|
||||
[Header ("Components")]
|
||||
[Space]
|
||||
|
||||
public climbRopeTriggerSystem mainClimbRopeTriggerSystem;
|
||||
|
||||
public Transform ropePivotTransform;
|
||||
|
||||
public Transform customRaycastDirection;
|
||||
|
||||
RaycastHit hit;
|
||||
|
||||
void Start ()
|
||||
{
|
||||
if (activateOnStart) {
|
||||
activateClimbRopeTrigger ();
|
||||
}
|
||||
}
|
||||
|
||||
public void activateClimbRopeTrigger ()
|
||||
{
|
||||
if (checkSurfaceLayer) {
|
||||
Collider[] hits = Physics.OverlapSphere (transform.position, raycastRadius);
|
||||
|
||||
if (hits.Length <= 0) {
|
||||
if (destroyObjectIfSurfaceNotFound) {
|
||||
if (showDebugPrint) {
|
||||
print ("No surface found on portacle climb rope trigger system, destroy rope");
|
||||
}
|
||||
|
||||
Destroy (gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
if (checkSurfaceInclination) {
|
||||
Vector3 rayPosition = transform.position;
|
||||
|
||||
for (int i = 0; i < hits.Length; i++) {
|
||||
Vector3 heading = hits [i].transform.position - rayPosition;
|
||||
|
||||
float distance = heading.magnitude;
|
||||
|
||||
Vector3 rayDirection = heading / distance;
|
||||
|
||||
if (Physics.Raycast (rayPosition, rayDirection, out hit, distance + 1, raycastLayermask)) {
|
||||
|
||||
float hitAngle = Vector3.Angle (Vector3.up, hit.normal);
|
||||
|
||||
if (showDebugPrint) {
|
||||
print ("Angle with surface found of " + hitAngle + " degrees");
|
||||
}
|
||||
|
||||
if (Mathf.Abs (hitAngle) > maxSurfaceInclination) {
|
||||
|
||||
if (showDebugPrint) {
|
||||
print ("Surface angle not possible for portacle climb rope trigger system, destroy rope");
|
||||
}
|
||||
|
||||
Destroy (gameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Vector3 raycastPosition = transform.position;
|
||||
|
||||
Vector3 raycastDirection = Vector3.down;
|
||||
|
||||
if (!useDownRaycastDirection) {
|
||||
raycastDirection = customRaycastDirection.forward;
|
||||
}
|
||||
|
||||
float raycastDistance = maxRaycastDistance;
|
||||
|
||||
if (adjustRopeEndToAnyDistance) {
|
||||
raycastDistance = Mathf.Infinity;
|
||||
}
|
||||
|
||||
Vector3 targetPosition = transform.position;
|
||||
|
||||
bool surfaceDetected = false;
|
||||
|
||||
if (Physics.Raycast (raycastPosition, raycastDirection, out hit, raycastDistance, raycastLayermask)) {
|
||||
targetPosition = hit.point;
|
||||
|
||||
surfaceDetected = true;
|
||||
} else {
|
||||
targetPosition += Vector3.down * maxRaycastDistance;
|
||||
}
|
||||
|
||||
Transform bottomTransform = mainClimbRopeTriggerSystem.bottomTransform;
|
||||
Transform topTransform = mainClimbRopeTriggerSystem.topTransform;
|
||||
|
||||
topTransform.position = transform.position;
|
||||
|
||||
bottomTransform.position = targetPosition;
|
||||
|
||||
|
||||
bool scaleDown = true;
|
||||
|
||||
if (surfaceDetected) {
|
||||
if (hit.distance < 3) {
|
||||
raycastDirection = Vector3.up;
|
||||
|
||||
targetPosition = transform.position;
|
||||
|
||||
if (Physics.Raycast (raycastPosition, raycastDirection, out hit, raycastDistance, raycastLayermask)) {
|
||||
targetPosition = hit.point;
|
||||
} else {
|
||||
targetPosition += raycastDirection * maxRaycastDistance;
|
||||
}
|
||||
|
||||
topTransform.position = targetPosition;
|
||||
|
||||
scaleDown = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
float scaleZ = GKC_Utils.distance (topTransform.position, bottomTransform.position);
|
||||
|
||||
float finalScaleValue = scaleZ + (scaleZ * 0.01f) + 0.5f;
|
||||
|
||||
float scaleMultiplier = 1;
|
||||
|
||||
if (!scaleDown) {
|
||||
scaleMultiplier = -1;
|
||||
}
|
||||
|
||||
ropePivotTransform.localScale = new Vector3 (1, 1, finalScaleValue * scaleMultiplier);
|
||||
|
||||
Vector3 direction = bottomTransform.position - topTransform.position;
|
||||
|
||||
direction = direction / direction.magnitude;
|
||||
|
||||
ropePivotTransform.rotation = Quaternion.LookRotation (direction);
|
||||
|
||||
bottomTransform.position += Vector3.up * 0.5f;
|
||||
topTransform.position -= Vector3.up * 2;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9f4a8b7843918c04099f60ac19a2af65
|
||||
timeCreated: 1641680181
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 40995
|
||||
packageName: Game Kit Controller - Shooter Melee Adventure Creator 3D + 2.5D
|
||||
packageVersion: 3.77g
|
||||
assetPath: Assets/Game Kit Controller/Scripts/Player/Extra Movements/portableClimbRopeTriggerSystem.cs
|
||||
uploadId: 814740
|
||||
@@ -0,0 +1,163 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class portableWalkOnBalanceTriggerSystem : MonoBehaviour
|
||||
{
|
||||
[Header ("Main Settings")]
|
||||
[Space]
|
||||
|
||||
public LayerMask raycastLayermask;
|
||||
|
||||
public float maxRaycastDistance;
|
||||
|
||||
public bool adjustEndToAnyDistance;
|
||||
|
||||
public bool activateOnStart;
|
||||
|
||||
[Space]
|
||||
[Header ("Other Settings")]
|
||||
[Space]
|
||||
|
||||
public bool checkSurfaceLayer;
|
||||
public LayerMask layerSurface;
|
||||
public float raycastRadius;
|
||||
public bool destroyObjectIfSurfaceNotFound;
|
||||
|
||||
public bool checkSurfaceInclination;
|
||||
public float minSurfaceInclination;
|
||||
|
||||
[Space]
|
||||
[Header ("Debug")]
|
||||
[Space]
|
||||
|
||||
public bool showDebugPrint;
|
||||
|
||||
[Space]
|
||||
[Header ("Components")]
|
||||
[Space]
|
||||
|
||||
public Transform pivotTransform;
|
||||
|
||||
public Transform startTransform;
|
||||
public Transform endTransform;
|
||||
|
||||
RaycastHit hit;
|
||||
|
||||
void Start ()
|
||||
{
|
||||
if (activateOnStart) {
|
||||
activateWalkOnBalanceTrigger ();
|
||||
}
|
||||
}
|
||||
|
||||
public void activateWalkOnBalanceTrigger ()
|
||||
{
|
||||
if (checkSurfaceLayer) {
|
||||
Collider[] hits = Physics.OverlapSphere (transform.position, raycastRadius);
|
||||
|
||||
if (hits.Length <= 0) {
|
||||
if (destroyObjectIfSurfaceNotFound) {
|
||||
if (showDebugPrint) {
|
||||
print ("No surface found on portacle walk on balance trigger system, destroy object");
|
||||
}
|
||||
|
||||
Destroy (gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
if (checkSurfaceInclination) {
|
||||
Vector3 rayPosition = transform.position;
|
||||
|
||||
for (int i = 0; i < hits.Length; i++) {
|
||||
Vector3 heading = hits [i].transform.position - rayPosition;
|
||||
|
||||
float distance = heading.magnitude;
|
||||
|
||||
Vector3 rayDirection = heading / distance;
|
||||
|
||||
if (Physics.Raycast (rayPosition, rayDirection, out hit, distance + 1, raycastLayermask)) {
|
||||
|
||||
float hitAngle = Vector3.Angle (Vector3.up, hit.normal);
|
||||
|
||||
if (showDebugPrint) {
|
||||
print ("Angle with surface found of " + hitAngle + " degrees");
|
||||
}
|
||||
|
||||
if (Mathf.Abs (hitAngle) < minSurfaceInclination) {
|
||||
|
||||
if (showDebugPrint) {
|
||||
print ("Surface angle not possible for portacle walk on balance trigger system, destroy object");
|
||||
}
|
||||
|
||||
Destroy (gameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Vector3 raycastPosition = transform.position;
|
||||
|
||||
Vector3 raycastDirection = transform.forward;
|
||||
|
||||
float raycastDistance = maxRaycastDistance;
|
||||
|
||||
if (Physics.Raycast (raycastPosition, raycastDirection, out hit, raycastDistance, raycastLayermask)) {
|
||||
transform.rotation = Quaternion.LookRotation (hit.normal);
|
||||
|
||||
transform.position = hit.point + hit.normal * 0.1f;
|
||||
|
||||
transform.eulerAngles = new Vector3 (0, transform.eulerAngles.y, 0);
|
||||
} else {
|
||||
Collider[] hits = Physics.OverlapSphere (transform.position, raycastRadius);
|
||||
|
||||
bool surfaceLocated = false;
|
||||
|
||||
Vector3 rayPosition = transform.position;
|
||||
|
||||
for (int i = 0; i < hits.Length; i++) {
|
||||
if (!surfaceLocated) {
|
||||
Vector3 heading = hits [i].transform.position - rayPosition;
|
||||
|
||||
float distance = heading.magnitude;
|
||||
|
||||
Vector3 rayDirection = heading / distance;
|
||||
|
||||
if (Physics.Raycast (rayPosition, rayDirection, out hit, distance + 1, raycastLayermask)) {
|
||||
transform.rotation = Quaternion.LookRotation (hit.normal);
|
||||
|
||||
transform.position = hit.point + hit.normal * 0.1f;
|
||||
|
||||
surfaceLocated = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
raycastDirection = transform.forward;
|
||||
|
||||
raycastPosition = transform.position;
|
||||
|
||||
if (adjustEndToAnyDistance) {
|
||||
raycastDistance = Mathf.Infinity;
|
||||
}
|
||||
|
||||
Vector3 targetPosition = transform.position;
|
||||
|
||||
if (Physics.Raycast (raycastPosition, raycastDirection, out hit, raycastDistance, raycastLayermask)) {
|
||||
targetPosition = hit.point;
|
||||
} else {
|
||||
targetPosition += transform.forward * maxRaycastDistance;
|
||||
}
|
||||
|
||||
startTransform.position = transform.position;
|
||||
|
||||
endTransform.position = targetPosition;
|
||||
|
||||
float scaleZ = GKC_Utils.distance (startTransform.position, endTransform.position);
|
||||
|
||||
float finalScaleValue = scaleZ + (scaleZ * 0.01f) + 0.5f;
|
||||
|
||||
pivotTransform.localScale = new Vector3 (1, 1, finalScaleValue);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2a9e034611ec7424295b423ccaca2874
|
||||
timeCreated: 1643734958
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 40995
|
||||
packageName: Game Kit Controller - Shooter Melee Adventure Creator 3D + 2.5D
|
||||
packageVersion: 3.77g
|
||||
assetPath: Assets/Game Kit Controller/Scripts/Player/Extra Movements/portableWalkOnBalanceTriggerSystem.cs
|
||||
uploadId: 814740
|
||||
@@ -0,0 +1,891 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
|
||||
public class railSystem : externalControllerBehavior
|
||||
{
|
||||
[Header ("Main Settings")]
|
||||
[Space]
|
||||
|
||||
public bool railSystemEnabled = true;
|
||||
|
||||
public float lookDirectionSpeed;
|
||||
|
||||
public float resetPlayerRotationSpeed = 5;
|
||||
|
||||
public float adjustPlayerToRailSpeed = 5;
|
||||
|
||||
[Space]
|
||||
[Header ("Reverse Direction Settings")]
|
||||
[Space]
|
||||
|
||||
public bool canChangeDirectionEnabled;
|
||||
|
||||
public float minWaitToChangeDirection = 0.8f;
|
||||
|
||||
public float delayToReverseDirection = 1;
|
||||
|
||||
public float delayToResumeMovementOnReverseDirection = 0.5f;
|
||||
|
||||
public bool reduceSlideSpeedOnReversingDirection;
|
||||
|
||||
public float reduceSlideSpeedOnReversingDirectionMultiplier = 0.2f;
|
||||
|
||||
[Space]
|
||||
[Header ("Physics Settings")]
|
||||
[Space]
|
||||
|
||||
public bool useForceMode;
|
||||
|
||||
public ForceMode railForceMode;
|
||||
|
||||
public bool turboEnabled;
|
||||
|
||||
public float turboSpeed;
|
||||
|
||||
public float speedOnAimMultiplier;
|
||||
|
||||
[Space]
|
||||
[Header ("Speed Settings")]
|
||||
[Space]
|
||||
|
||||
public bool adjustSpeedBasedOnInclination;
|
||||
public float speedMultiplierOnInclinationUp;
|
||||
public float speedMultiplierOnInclinationDown;
|
||||
public float minInclinationDifferenceToAffectSpeed;
|
||||
|
||||
public float speedMultiplierOnInclinationLerp;
|
||||
|
||||
[Space]
|
||||
[Header ("Jump Settings")]
|
||||
[Space]
|
||||
|
||||
public bool canJumpEnabled;
|
||||
|
||||
public Vector3 impulseOnJump;
|
||||
public Vector3 endOfSurfaceImpulse;
|
||||
|
||||
public float maxVelocityChangeOnJump;
|
||||
|
||||
[Space]
|
||||
[Header ("Third Person Settings")]
|
||||
[Space]
|
||||
|
||||
public int actionID = 08632946;
|
||||
|
||||
public string externalControlleBehaviorActiveAnimatorName = "External Behavior Active";
|
||||
public string actionIDAnimatorName = "Action ID";
|
||||
|
||||
public string horizontalAnimatorName = "Horizontal Action";
|
||||
|
||||
public float inputLerpSpeed = 3;
|
||||
|
||||
[Space]
|
||||
[Header ("Third Person Camera State Settings")]
|
||||
[Space]
|
||||
|
||||
public bool setNewCameraStateOnThirdPerson;
|
||||
|
||||
public string newCameraStateOnThirdPerson;
|
||||
|
||||
[Space]
|
||||
[Header ("Debug")]
|
||||
[Space]
|
||||
|
||||
public bool showDebugPrint;
|
||||
|
||||
public bool movementOnRailPausedDebug;
|
||||
|
||||
public bool railSystemActive;
|
||||
|
||||
public float bezierDuration;
|
||||
|
||||
public bool turboActive;
|
||||
|
||||
public Vector3 targetDirection;
|
||||
|
||||
public BezierSpline currentSpline;
|
||||
|
||||
public bool movingForward;
|
||||
|
||||
public bool adjustingPlayerToRail;
|
||||
|
||||
public float progress = 0;
|
||||
public float progressTarget = 0;
|
||||
|
||||
public bool playerAiming;
|
||||
|
||||
|
||||
[Space]
|
||||
[Header ("Events Settings")]
|
||||
[Space]
|
||||
|
||||
public UnityEvent eventOnStateEnabled;
|
||||
public UnityEvent eventOnStateDisabled;
|
||||
|
||||
public UnityEvent eventBeforeActivatingState;
|
||||
public UnityEvent eventBeforeDeactivatingState;
|
||||
|
||||
public bool useEventUseTurbo;
|
||||
public UnityEvent eventOnStarTurbo;
|
||||
public UnityEvent eventOnEndTurbo;
|
||||
|
||||
[Space]
|
||||
[Header ("Components")]
|
||||
[Space]
|
||||
|
||||
public playerController mainPlayerController;
|
||||
|
||||
public Animator mainAnimator;
|
||||
|
||||
public playerCamera mainPlayerCamera;
|
||||
|
||||
public Transform playerTransform;
|
||||
public Transform playerCameraTransform;
|
||||
|
||||
public Rigidbody mainRigidbody;
|
||||
|
||||
public headTrack mainHeadTrack;
|
||||
|
||||
float currentAimSpeedMultipler;
|
||||
|
||||
bool canUseTurboPausedState;
|
||||
|
||||
int externalControlleBehaviorActiveAnimatorID;
|
||||
|
||||
int actionIDAnimatorID;
|
||||
|
||||
int horizontalAnimatorID;
|
||||
|
||||
bool isFirstPersonActive;
|
||||
|
||||
string previousCameraState = "";
|
||||
|
||||
bool turnAndForwardAnimatorValuesPaused;
|
||||
|
||||
Coroutine adjustPlayerToRailCoroutine;
|
||||
|
||||
Coroutine resetPlayerCoroutine;
|
||||
|
||||
Vector3 lookDirection;
|
||||
|
||||
float currentInclinationSpeed;
|
||||
|
||||
bool resetCameraShakeActive;
|
||||
|
||||
float lastTimeDirectionChanged;
|
||||
|
||||
float lastTimeReverseMovementDirectionInput;
|
||||
|
||||
bool originalCanChangeDirectionEnabled;
|
||||
|
||||
bool activateReverseDirectionActive;
|
||||
|
||||
float reverseDirectionValue;
|
||||
|
||||
|
||||
void Start ()
|
||||
{
|
||||
externalControlleBehaviorActiveAnimatorID = Animator.StringToHash (externalControlleBehaviorActiveAnimatorName);
|
||||
|
||||
actionIDAnimatorID = Animator.StringToHash (actionIDAnimatorName);
|
||||
|
||||
horizontalAnimatorID = Animator.StringToHash (horizontalAnimatorName);
|
||||
|
||||
originalCanChangeDirectionEnabled = canChangeDirectionEnabled;
|
||||
|
||||
if (playerCameraTransform == null) {
|
||||
playerCameraTransform = mainPlayerCamera.transform;
|
||||
}
|
||||
}
|
||||
|
||||
public override void updateControllerBehavior ()
|
||||
{
|
||||
if (railSystemActive && !movementOnRailPausedDebug) {
|
||||
if (!adjustingPlayerToRail) {
|
||||
bool targetReached = false;
|
||||
|
||||
if (mainPlayerController.isPlayerRunning ()) {
|
||||
if (!turboActive) {
|
||||
enableOrDisableTurbo (true);
|
||||
}
|
||||
} else {
|
||||
if (turboActive) {
|
||||
enableOrDisableTurbo (false);
|
||||
}
|
||||
}
|
||||
|
||||
int slidingAnimatorValue = 0;
|
||||
|
||||
float currentSpeed = bezierDuration;
|
||||
|
||||
if (turboActive) {
|
||||
slidingAnimatorValue = 1;
|
||||
|
||||
currentSpeed /= turboSpeed;
|
||||
}
|
||||
|
||||
if (adjustSpeedBasedOnInclination) {
|
||||
|
||||
lookDirection = currentSpline.GetDirection (progress);
|
||||
|
||||
Vector3 currentNormal = mainPlayerController.getCurrentNormal ();
|
||||
|
||||
float angle = Vector3.SignedAngle (playerTransform.up, currentNormal, playerTransform.right);
|
||||
|
||||
if (Mathf.Abs (angle) > minInclinationDifferenceToAffectSpeed) {
|
||||
if (angle < 0) {
|
||||
currentInclinationSpeed = Mathf.Lerp (currentInclinationSpeed, speedMultiplierOnInclinationDown, Time.deltaTime * speedMultiplierOnInclinationLerp);
|
||||
} else {
|
||||
currentInclinationSpeed = Mathf.Lerp (currentInclinationSpeed, speedMultiplierOnInclinationUp, Time.deltaTime * speedMultiplierOnInclinationLerp);
|
||||
}
|
||||
} else {
|
||||
currentInclinationSpeed = Mathf.Lerp (currentInclinationSpeed, 1, Time.deltaTime * speedMultiplierOnInclinationLerp);
|
||||
}
|
||||
|
||||
currentSpeed *= currentInclinationSpeed;
|
||||
}
|
||||
|
||||
|
||||
bool canRotatePlayerResult = true;
|
||||
|
||||
currentAimSpeedMultipler = 1;
|
||||
|
||||
|
||||
if (!mainPlayerController.isPlayerOnFirstPerson () &&
|
||||
(mainPlayerController.isPlayerAiming () || mainPlayerController.isUsingFreeFireMode ()) &&
|
||||
!mainPlayerController.isCheckToKeepWeaponAfterAimingWeaponFromShooting ()) {
|
||||
|
||||
currentAimSpeedMultipler = speedOnAimMultiplier;
|
||||
|
||||
if (!turnAndForwardAnimatorValuesPaused) {
|
||||
mainPlayerController.setTurnAndForwardAnimatorValuesPausedState (true);
|
||||
|
||||
mainPlayerController.setRotateInCameraDirectionOnAirOnExternalActionActiveState (true);
|
||||
|
||||
turnAndForwardAnimatorValuesPaused = true;
|
||||
}
|
||||
|
||||
canRotatePlayerResult = false;
|
||||
|
||||
if (Time.time > mainPlayerController.getLastTimeFiring () + 0.2f) {
|
||||
if (resetCameraShakeActive) {
|
||||
mainPlayerCamera.stopAllHeadbobMovements ();
|
||||
|
||||
resetCameraShakeActive = false;
|
||||
}
|
||||
} else {
|
||||
resetCameraShakeActive = true;
|
||||
}
|
||||
|
||||
} else {
|
||||
if (turnAndForwardAnimatorValuesPaused) {
|
||||
mainPlayerController.setTurnAndForwardAnimatorValuesPausedState (false);
|
||||
|
||||
mainPlayerController.setRotateInCameraDirectionOnAirOnExternalActionActiveState (false);
|
||||
|
||||
turnAndForwardAnimatorValuesPaused = false;
|
||||
|
||||
mainPlayerCamera.stopAllHeadbobMovements ();
|
||||
}
|
||||
}
|
||||
|
||||
if (canChangeDirectionEnabled && canRotatePlayerResult) {
|
||||
Vector2 rawMovementAxis = mainPlayerController.getRawAxisValues ();
|
||||
|
||||
if (rawMovementAxis != Vector2.zero) {
|
||||
|
||||
Vector3 movementDirection = rawMovementAxis.y * mainPlayerController.getCurrentForwardDirection () +
|
||||
rawMovementAxis.x * mainPlayerController.getCurrentRightDirection ();
|
||||
|
||||
float directionAngle = Vector3.SignedAngle (movementDirection, playerTransform.forward, playerTransform.up);
|
||||
|
||||
if (Mathf.Abs (directionAngle) > 90) {
|
||||
if (movingForward) {
|
||||
if (Time.time > minWaitToChangeDirection + lastTimeDirectionChanged) {
|
||||
reverseDirectionValue = -1;
|
||||
// calculateMovementDirection (-1);
|
||||
|
||||
lastTimeReverseMovementDirectionInput = Time.time;
|
||||
|
||||
activateReverseDirectionActive = true;
|
||||
}
|
||||
} else {
|
||||
if (Time.time > minWaitToChangeDirection + lastTimeDirectionChanged) {
|
||||
reverseDirectionValue = 1;
|
||||
|
||||
// calculateMovementDirection (1);
|
||||
|
||||
lastTimeReverseMovementDirectionInput = Time.time;
|
||||
|
||||
activateReverseDirectionActive = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (activateReverseDirectionActive) {
|
||||
if (Time.time > delayToReverseDirection + lastTimeReverseMovementDirectionInput) {
|
||||
activateReverseDirectionActive = false;
|
||||
|
||||
calculateMovementDirection (reverseDirectionValue);
|
||||
}
|
||||
}
|
||||
|
||||
bool canMove = true;
|
||||
|
||||
if (lastTimeReverseMovementDirectionInput > 0) {
|
||||
if (Time.time < lastTimeReverseMovementDirectionInput + delayToResumeMovementOnReverseDirection) {
|
||||
canMove = false;
|
||||
|
||||
slidingAnimatorValue = 0;
|
||||
|
||||
if (reduceSlideSpeedOnReversingDirection) {
|
||||
currentSpeed *= reduceSlideSpeedOnReversingDirectionMultiplier;
|
||||
|
||||
canMove = true;
|
||||
}
|
||||
} else {
|
||||
lastTimeReverseMovementDirectionInput = 0;
|
||||
}
|
||||
}
|
||||
|
||||
mainAnimator.SetFloat (horizontalAnimatorID, slidingAnimatorValue, inputLerpSpeed, Time.fixedDeltaTime);
|
||||
|
||||
|
||||
float currentProgress = 0;
|
||||
|
||||
if (canMove) {
|
||||
currentProgress = Time.deltaTime / (currentSpeed * currentAimSpeedMultipler);
|
||||
}
|
||||
|
||||
if (movingForward) {
|
||||
progress += currentProgress;
|
||||
} else {
|
||||
progress -= currentProgress;
|
||||
}
|
||||
|
||||
Vector3 position = currentSpline.GetPoint (progress);
|
||||
|
||||
playerTransform.position = position;
|
||||
|
||||
if (mainPlayerCamera.isFullBodyAwarenessActive ()) {
|
||||
playerCameraTransform.position = position;
|
||||
}
|
||||
|
||||
lookDirection = currentSpline.GetDirection (progress);
|
||||
|
||||
if (!movingForward) {
|
||||
lookDirection = -lookDirection;
|
||||
}
|
||||
|
||||
|
||||
if (canRotatePlayerResult) {
|
||||
Quaternion targetRotation = Quaternion.LookRotation (lookDirection);
|
||||
|
||||
if (mainPlayerCamera.isFullBodyAwarenessActive ()) {
|
||||
playerCameraTransform.rotation = Quaternion.Lerp (playerCameraTransform.rotation, targetRotation, Time.fixedDeltaTime * lookDirectionSpeed);
|
||||
} else {
|
||||
playerTransform.rotation = Quaternion.Lerp (playerTransform.rotation, targetRotation, Time.fixedDeltaTime * lookDirectionSpeed);
|
||||
}
|
||||
}
|
||||
|
||||
if (movingForward) {
|
||||
if (progress > progressTarget) {
|
||||
targetReached = true;
|
||||
}
|
||||
} else {
|
||||
if (progress < progressTarget) {
|
||||
targetReached = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (targetReached) {
|
||||
stopRail ();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void setExtraImpulseForce (Vector3 forceAmount, bool useCameraDirection)
|
||||
{
|
||||
setImpulseForce (forceAmount, useCameraDirection);
|
||||
}
|
||||
|
||||
public void setImpulseForce (Vector3 forceAmount, bool useCameraDirection)
|
||||
{
|
||||
Vector3 impulseForce = forceAmount;
|
||||
|
||||
Vector3 velocityChange = Vector3.zero;
|
||||
|
||||
if (maxVelocityChangeOnJump > 0) {
|
||||
velocityChange = impulseForce - mainRigidbody.linearVelocity;
|
||||
|
||||
velocityChange = Vector3.ClampMagnitude (velocityChange, maxVelocityChangeOnJump);
|
||||
|
||||
} else {
|
||||
velocityChange = impulseForce;
|
||||
}
|
||||
|
||||
mainPlayerController.setVelocityChangeValue (impulseForce);
|
||||
|
||||
mainRigidbody.AddForce (impulseForce, ForceMode.VelocityChange);
|
||||
}
|
||||
|
||||
public override void setJumpActiveForExternalForce ()
|
||||
{
|
||||
setJumpActive (impulseOnJump);
|
||||
}
|
||||
|
||||
public void setJumpActive (Vector3 newImpulseOnJumpAmount)
|
||||
{
|
||||
if (railSystemActive) {
|
||||
setRailSystemActivestate (false);
|
||||
|
||||
Vector3 totalForce = newImpulseOnJumpAmount.y * playerTransform.up + newImpulseOnJumpAmount.z * playerTransform.forward;
|
||||
|
||||
mainPlayerController.useJumpPlatform (totalForce, ForceMode.Impulse);
|
||||
}
|
||||
}
|
||||
|
||||
public override void setExternalForceActiveState (bool state)
|
||||
{
|
||||
setRailSystemActivestate (state);
|
||||
}
|
||||
|
||||
public void setRailSystemActivestate (bool state)
|
||||
{
|
||||
if (!railSystemEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (railSystemActive == state) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (mainPlayerController.isUseExternalControllerBehaviorPaused ()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (state && mainPlayerController.isPlayerDead ()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (state) {
|
||||
externalControllerBehavior currentExternalControllerBehavior = mainPlayerController.getCurrentExternalControllerBehavior ();
|
||||
|
||||
if (currentExternalControllerBehavior != null && currentExternalControllerBehavior != this) {
|
||||
if (canBeActivatedIfOthersBehaviorsActive && checkIfCanEnableBehavior (currentExternalControllerBehavior.behaviorName)) {
|
||||
currentExternalControllerBehavior.disableExternalControllerState ();
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool modeActivePrevioulsy = railSystemActive;
|
||||
|
||||
railSystemActive = state;
|
||||
|
||||
setBehaviorCurrentlyActiveState (state);
|
||||
|
||||
setCurrentPlayerActionSystemCustomActionCategoryID ();
|
||||
|
||||
if (showDebugPrint) {
|
||||
print ("Setting state as " + railSystemActive);
|
||||
}
|
||||
|
||||
mainPlayerController.setExternalControlBehaviorForAirTypeActiveState (state);
|
||||
|
||||
if (state) {
|
||||
mainPlayerController.setCheckOnGroungPausedState (true);
|
||||
|
||||
mainPlayerController.setPlayerOnGroundState (false);
|
||||
|
||||
mainPlayerController.setPlayerOnGroundAnimatorStateOnOverrideOnGroundWithTime (false);
|
||||
|
||||
mainPlayerController.overrideOnGroundAnimatorValue (0);
|
||||
|
||||
mainPlayerController.setPlayerOnGroundAnimatorStateOnOverrideOnGround (false);
|
||||
|
||||
mainPlayerController.setOnGroundAnimatorIDValue (false);
|
||||
|
||||
} else {
|
||||
mainPlayerController.setCheckOnGroungPausedState (false);
|
||||
|
||||
mainPlayerController.setPlayerOnGroundState (false);
|
||||
|
||||
mainPlayerController.setPlayerOnGroundAnimatorStateOnOverrideOnGroundWithTime (true);
|
||||
|
||||
mainPlayerController.disableOverrideOnGroundAnimatorValue ();
|
||||
|
||||
mainPlayerController.setPauseResetAnimatorStateFOrGroundAnimatorState (true);
|
||||
|
||||
mainPlayerController.setOnGroundAnimatorIDValue (false);
|
||||
}
|
||||
|
||||
mainPlayerController.setUpdate2_5dClampedPositionPausedState (state);
|
||||
|
||||
mainPlayerController.setFootStepManagerState (state);
|
||||
|
||||
mainPlayerController.setAddExtraRotationPausedState (state);
|
||||
|
||||
mainPlayerController.setIgnoreExternalActionsActiveState (state);
|
||||
|
||||
if (railSystemActive) {
|
||||
mainPlayerController.setExternalControllerBehavior (this);
|
||||
} else {
|
||||
if (modeActivePrevioulsy) {
|
||||
externalControllerBehavior currentExternalControllerBehavior = mainPlayerController.getCurrentExternalControllerBehavior ();
|
||||
|
||||
if (currentExternalControllerBehavior == null || currentExternalControllerBehavior == this) {
|
||||
mainPlayerController.setExternalControllerBehavior (null);
|
||||
}
|
||||
|
||||
if (playerTransform.up != mainPlayerController.getCurrentNormal ()) {
|
||||
resetPlayerRotation ();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (state) {
|
||||
eventBeforeActivatingState.Invoke ();
|
||||
} else {
|
||||
eventBeforeDeactivatingState.Invoke ();
|
||||
}
|
||||
|
||||
mainPlayerController.setFallDamageCheckPausedState (state);
|
||||
|
||||
if (railSystemActive) {
|
||||
eventOnStateEnabled.Invoke ();
|
||||
} else {
|
||||
eventOnStateDisabled.Invoke ();
|
||||
|
||||
if (turboActive) {
|
||||
enableOrDisableTurbo (false);
|
||||
}
|
||||
}
|
||||
|
||||
mainHeadTrack.setExternalHeadTrackPauseActiveState (state);
|
||||
|
||||
mainPlayerController.stopShakeCamera ();
|
||||
|
||||
mainPlayerCamera.setPausePlayerCameraViewChangeState (state);
|
||||
|
||||
mainPlayerController.setLastTimeFalling ();
|
||||
|
||||
if (state) {
|
||||
calculateMovementDirection (0);
|
||||
} else {
|
||||
stopAdjustPlayerToRailOnStartCoroutine ();
|
||||
}
|
||||
|
||||
if (state) {
|
||||
mainAnimator.SetInteger (actionIDAnimatorID, actionID);
|
||||
|
||||
mainAnimator.SetBool (externalControlleBehaviorActiveAnimatorID, state);
|
||||
} else {
|
||||
mainAnimator.SetBool (externalControlleBehaviorActiveAnimatorID, state);
|
||||
|
||||
mainAnimator.SetInteger (actionIDAnimatorID, 0);
|
||||
}
|
||||
|
||||
isFirstPersonActive = mainPlayerController.isPlayerOnFirstPerson ();
|
||||
|
||||
if (setNewCameraStateOnThirdPerson && !isFirstPersonActive) {
|
||||
if (state) {
|
||||
previousCameraState = mainPlayerCamera.getCurrentStateName ();
|
||||
|
||||
mainPlayerCamera.setCameraStateOnlyOnThirdPerson (newCameraStateOnThirdPerson);
|
||||
} else {
|
||||
|
||||
if (previousCameraState != "") {
|
||||
if (previousCameraState != newCameraStateOnThirdPerson) {
|
||||
mainPlayerCamera.setCameraStateOnlyOnThirdPerson (previousCameraState);
|
||||
}
|
||||
|
||||
previousCameraState = "";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (turnAndForwardAnimatorValuesPaused) {
|
||||
mainPlayerController.setTurnAndForwardAnimatorValuesPausedState (false);
|
||||
|
||||
mainPlayerController.setRotateInCameraDirectionOnAirOnExternalActionActiveState (false);
|
||||
|
||||
turnAndForwardAnimatorValuesPaused = false;
|
||||
}
|
||||
|
||||
currentInclinationSpeed = 1;
|
||||
|
||||
playerAiming = false;
|
||||
|
||||
resetCameraShakeActive = false;
|
||||
}
|
||||
|
||||
void calculateMovementDirection (float inputDirection)
|
||||
{
|
||||
progress = 0;
|
||||
|
||||
progressTarget = 1;
|
||||
|
||||
Vector3 playerPosition = currentSpline.FindNearestPointTo (playerTransform.position, 100, 30);
|
||||
|
||||
adjustPlayerToRailOnStart (playerPosition);
|
||||
|
||||
float step = currentSpline.AccuracyToStepSize (100);
|
||||
|
||||
float minDistance = Mathf.Infinity;
|
||||
|
||||
for (float i = 0f; i < 1f; i += step) {
|
||||
Vector3 thisPoint = currentSpline.GetPoint (i);
|
||||
float thisDistance = (playerPosition - thisPoint).sqrMagnitude;
|
||||
|
||||
if (thisDistance < minDistance) {
|
||||
minDistance = thisDistance;
|
||||
progress = i;
|
||||
}
|
||||
}
|
||||
|
||||
lookDirection = currentSpline.GetDirection (progress);
|
||||
|
||||
float angle = Vector3.SignedAngle (playerTransform.forward, lookDirection, playerTransform.up);
|
||||
|
||||
movingForward = false;
|
||||
|
||||
if (Mathf.Abs (angle) < 90) {
|
||||
movingForward = true;
|
||||
}
|
||||
|
||||
if (showDebugPrint) {
|
||||
print (movingForward + " " + progress + " " + angle);
|
||||
}
|
||||
|
||||
if (inputDirection != 0) {
|
||||
if (inputDirection > 0) {
|
||||
movingForward = true;
|
||||
} else {
|
||||
movingForward = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!movingForward) {
|
||||
progressTarget = 0;
|
||||
}
|
||||
|
||||
lastTimeDirectionChanged = Time.time;
|
||||
|
||||
lastTimeReverseMovementDirectionInput = 0;
|
||||
|
||||
activateReverseDirectionActive = false;
|
||||
}
|
||||
|
||||
public override void setExternalForceEnabledState (bool state)
|
||||
{
|
||||
setRailEnabledState (state);
|
||||
}
|
||||
|
||||
public void setRailEnabledState (bool state)
|
||||
{
|
||||
if (!state) {
|
||||
setRailSystemActivestate (false);
|
||||
}
|
||||
|
||||
railSystemEnabled = state;
|
||||
}
|
||||
|
||||
public void enableOrDisableTurbo (bool state)
|
||||
{
|
||||
if (turboActive == state) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (state && canUseTurboPausedState) {
|
||||
return;
|
||||
}
|
||||
|
||||
turboActive = state;
|
||||
|
||||
if (useEventUseTurbo) {
|
||||
if (state) {
|
||||
eventOnStarTurbo.Invoke ();
|
||||
} else {
|
||||
eventOnEndTurbo.Invoke ();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setCanUseTurboPausedState (bool state)
|
||||
{
|
||||
if (!state && turboActive) {
|
||||
enableOrDisableTurbo (false);
|
||||
}
|
||||
|
||||
canUseTurboPausedState = state;
|
||||
}
|
||||
|
||||
public override void disableExternalControllerState ()
|
||||
{
|
||||
setRailSystemActivestate (false);
|
||||
}
|
||||
|
||||
public void inputChangeTurboState (bool state)
|
||||
{
|
||||
if (railSystemActive && turboEnabled) {
|
||||
enableOrDisableTurbo (state);
|
||||
}
|
||||
}
|
||||
|
||||
public void setCanChangeDirectionEnabledState (bool state)
|
||||
{
|
||||
canChangeDirectionEnabled = state;
|
||||
}
|
||||
|
||||
public void setOriginalCanChangeDirectionEnabled ()
|
||||
{
|
||||
setCanChangeDirectionEnabledState (originalCanChangeDirectionEnabled);
|
||||
}
|
||||
|
||||
public void setCurrentSpline (BezierSpline newSpline)
|
||||
{
|
||||
currentSpline = newSpline;
|
||||
}
|
||||
|
||||
public void setCurrentBezierDuration (float newValue)
|
||||
{
|
||||
bezierDuration = newValue;
|
||||
}
|
||||
|
||||
void stopRail ()
|
||||
{
|
||||
Vector3 totalForce = Vector3.zero;
|
||||
|
||||
totalForce = playerTransform.forward * endOfSurfaceImpulse.z + playerTransform.up * endOfSurfaceImpulse.y;
|
||||
|
||||
setRailSystemActivestate (false);
|
||||
|
||||
setImpulseForce (totalForce, false);
|
||||
}
|
||||
|
||||
public void adjustPlayerToRailOnStart (Vector3 initialPosition)
|
||||
{
|
||||
stopResetPlayerRotationCoroutine ();
|
||||
|
||||
adjustPlayerToRailCoroutine = StartCoroutine (adjustPlayerToRailOnStartCoroutine (initialPosition));
|
||||
}
|
||||
|
||||
void stopAdjustPlayerToRailOnStartCoroutine ()
|
||||
{
|
||||
if (adjustPlayerToRailCoroutine != null) {
|
||||
StopCoroutine (adjustPlayerToRailCoroutine);
|
||||
}
|
||||
|
||||
adjustingPlayerToRail = false;
|
||||
}
|
||||
|
||||
IEnumerator adjustPlayerToRailOnStartCoroutine (Vector3 initialPosition)
|
||||
{
|
||||
adjustingPlayerToRail = true;
|
||||
|
||||
float dist = GKC_Utils.distance (playerTransform.position, initialPosition);
|
||||
|
||||
float duration = dist / adjustPlayerToRailSpeed;
|
||||
|
||||
float t = 0;
|
||||
|
||||
Vector3 pos = initialPosition;
|
||||
|
||||
float movementTimer = 0;
|
||||
|
||||
bool targetReached = false;
|
||||
|
||||
while (!targetReached) {
|
||||
t += Time.deltaTime / duration;
|
||||
|
||||
playerTransform.position = Vector3.Slerp (playerTransform.position, pos, t);
|
||||
|
||||
movementTimer += Time.deltaTime;
|
||||
|
||||
if (GKC_Utils.distance (playerTransform.position, pos) < 0.01f || movementTimer > (duration + 1)) {
|
||||
targetReached = true;
|
||||
}
|
||||
|
||||
yield return null;
|
||||
}
|
||||
|
||||
adjustingPlayerToRail = false;
|
||||
}
|
||||
|
||||
public void resetPlayerRotation ()
|
||||
{
|
||||
stopResetPlayerRotationCoroutine ();
|
||||
|
||||
resetPlayerCoroutine = StartCoroutine (resetPlayerRotationCoroutine ());
|
||||
}
|
||||
|
||||
void stopResetPlayerRotationCoroutine ()
|
||||
{
|
||||
if (resetPlayerCoroutine != null) {
|
||||
StopCoroutine (resetPlayerCoroutine);
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator resetPlayerRotationCoroutine ()
|
||||
{
|
||||
float movementTimer = 0;
|
||||
|
||||
float t = 0;
|
||||
|
||||
float duration = 1;
|
||||
|
||||
float angleDifference = 0;
|
||||
|
||||
Vector3 currentNormal = mainPlayerController.getCurrentNormal ();
|
||||
|
||||
bool isFullBodyAwarenessActive = mainPlayerCamera.isFullBodyAwarenessActive ();
|
||||
|
||||
Transform objectToRotate = playerTransform;
|
||||
|
||||
if (isFullBodyAwarenessActive) {
|
||||
objectToRotate = playerCameraTransform;
|
||||
}
|
||||
|
||||
Quaternion currentPlayerRotation = objectToRotate.rotation;
|
||||
Vector3 currentPlayerForward = Vector3.Cross (objectToRotate.right, currentNormal);
|
||||
Quaternion playerTargetRotation = Quaternion.LookRotation (currentPlayerForward, currentNormal);
|
||||
|
||||
bool targetReached = false;
|
||||
|
||||
while (!targetReached) {
|
||||
t += (Time.deltaTime / duration) * resetPlayerRotationSpeed;
|
||||
|
||||
objectToRotate.rotation = Quaternion.Slerp (objectToRotate.rotation, playerTargetRotation, t);
|
||||
|
||||
angleDifference = Quaternion.Angle (objectToRotate.rotation, playerTargetRotation);
|
||||
|
||||
movementTimer += Time.deltaTime;
|
||||
|
||||
if (angleDifference < 0.01f || movementTimer > (duration + 1)) {
|
||||
targetReached = true;
|
||||
}
|
||||
|
||||
yield return null;
|
||||
}
|
||||
}
|
||||
|
||||
public override void setCurrentPlayerActionSystemCustomActionCategoryID ()
|
||||
{
|
||||
if (behaviorCurrentlyActive) {
|
||||
if (customActionCategoryID > -1) {
|
||||
mainPlayerController.setCurrentCustomActionCategoryID (customActionCategoryID);
|
||||
}
|
||||
} else {
|
||||
if (regularActionCategoryID > -1) {
|
||||
mainPlayerController.setCurrentCustomActionCategoryID (regularActionCategoryID);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2a02a143ff2ffb8449eaf9418cf4ab0c
|
||||
timeCreated: 1639204783
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 40995
|
||||
packageName: Game Kit Controller - Shooter Melee Adventure Creator 3D + 2.5D
|
||||
packageVersion: 3.77g
|
||||
assetPath: Assets/Game Kit Controller/Scripts/Player/Extra Movements/railSystem.cs
|
||||
uploadId: 814740
|
||||
@@ -0,0 +1,151 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class railTriggerSystem : MonoBehaviour
|
||||
{
|
||||
[Header ("Main Settings")]
|
||||
[Space]
|
||||
|
||||
public string tagToCheck;
|
||||
public bool railZoneActive = true;
|
||||
|
||||
public float bezierDuration;
|
||||
|
||||
public BezierSpline railSpline;
|
||||
|
||||
public bool checkOnTriggerEnter = true;
|
||||
public bool checkOnTriggerExit = true;
|
||||
|
||||
[Space]
|
||||
[Header ("Reverse Direction Settings")]
|
||||
[Space]
|
||||
|
||||
public bool setCanChangeDirectionEnabled;
|
||||
|
||||
public bool canChangeDirectionEnabled;
|
||||
|
||||
[Space]
|
||||
[Header ("Remote Events Settings")]
|
||||
[Space]
|
||||
|
||||
public bool useRemoteEvents;
|
||||
public bool useRemoteEventOnStart;
|
||||
public List<string> remoteEventNameListOnStart = new List<string> ();
|
||||
|
||||
public bool useRemoteEventOnEnd;
|
||||
public List<string> remoteEventNameListOnEnd = new List<string> ();
|
||||
|
||||
GameObject currentPlayer;
|
||||
|
||||
|
||||
void OnTriggerEnter (Collider col)
|
||||
{
|
||||
checkTriggerInfo (col, true);
|
||||
}
|
||||
|
||||
void OnTriggerExit (Collider col)
|
||||
{
|
||||
checkTriggerInfo (col, false);
|
||||
}
|
||||
|
||||
public void checkTriggerInfo (Collider col, bool isEnter)
|
||||
{
|
||||
if (!railZoneActive) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (isEnter) {
|
||||
if (!checkOnTriggerEnter) {
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
if (!checkOnTriggerExit) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (!col.gameObject.CompareTag (tagToCheck)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (isEnter) {
|
||||
currentPlayer = col.gameObject;
|
||||
|
||||
playerComponentsManager currentPlayerComponentsManager = currentPlayer.GetComponent<playerComponentsManager> ();
|
||||
|
||||
if (currentPlayerComponentsManager != null) {
|
||||
externalControllerBehavior railExternalControllerBehavior = currentPlayerComponentsManager.getRailExternalControllerBehavior ();
|
||||
|
||||
if (railExternalControllerBehavior != null) {
|
||||
railSystem currentRailSystem = railExternalControllerBehavior.GetComponent<railSystem> ();
|
||||
|
||||
currentRailSystem.setCurrentSpline (railSpline);
|
||||
|
||||
currentRailSystem.setCurrentBezierDuration (bezierDuration);
|
||||
|
||||
currentRailSystem.setRailSystemActivestate (true);
|
||||
|
||||
checkRemoteEvents (true, currentPlayer);
|
||||
|
||||
if (setCanChangeDirectionEnabled) {
|
||||
currentRailSystem.setCanChangeDirectionEnabledState (canChangeDirectionEnabled);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
currentPlayer = col.gameObject;
|
||||
|
||||
playerComponentsManager currentPlayerComponentsManager = currentPlayer.GetComponent<playerComponentsManager> ();
|
||||
|
||||
if (currentPlayerComponentsManager != null) {
|
||||
externalControllerBehavior railExternalControllerBehavior = currentPlayerComponentsManager.getRailExternalControllerBehavior ();
|
||||
|
||||
if (railExternalControllerBehavior != null) {
|
||||
railSystem currentRailSystem = railExternalControllerBehavior.GetComponent<railSystem> ();
|
||||
|
||||
currentRailSystem.setRailSystemActivestate (false);
|
||||
|
||||
currentRailSystem.setCurrentSpline (null);
|
||||
|
||||
checkRemoteEvents (false, currentPlayer);
|
||||
|
||||
if (setCanChangeDirectionEnabled) {
|
||||
currentRailSystem.setOriginalCanChangeDirectionEnabled ();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void checkRemoteEvents (bool state, GameObject objectToCheck)
|
||||
{
|
||||
if (!useRemoteEvents) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (state) {
|
||||
if (useRemoteEventOnStart) {
|
||||
remoteEventSystem currentRemoteEventSystem = objectToCheck.GetComponent<remoteEventSystem> ();
|
||||
|
||||
if (currentRemoteEventSystem != null) {
|
||||
for (int i = 0; i < remoteEventNameListOnStart.Count; i++) {
|
||||
|
||||
currentRemoteEventSystem.callRemoteEvent (remoteEventNameListOnStart [i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (useRemoteEventOnEnd) {
|
||||
remoteEventSystem currentRemoteEventSystem = objectToCheck.GetComponent<remoteEventSystem> ();
|
||||
|
||||
if (currentRemoteEventSystem != null) {
|
||||
for (int i = 0; i < remoteEventNameListOnEnd.Count; i++) {
|
||||
|
||||
currentRemoteEventSystem.callRemoteEvent (remoteEventNameListOnEnd [i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c35ab1a59c4084b4995f5ba5ca223d41
|
||||
timeCreated: 1639204991
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 40995
|
||||
packageName: Game Kit Controller - Shooter Melee Adventure Creator 3D + 2.5D
|
||||
packageVersion: 3.77g
|
||||
assetPath: Assets/Game Kit Controller/Scripts/Player/Extra Movements/railTriggerSystem.cs
|
||||
uploadId: 814740
|
||||
@@ -0,0 +1,198 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
|
||||
public class rollOnLandingSystem : MonoBehaviour
|
||||
{
|
||||
[Header ("Main Settings")]
|
||||
[Space]
|
||||
|
||||
public bool rollOnlandingEnabled = true;
|
||||
|
||||
public float rollOnLandingCheckDuration;
|
||||
|
||||
public float eventsOnRollLandingDelay;
|
||||
|
||||
public float distanceFromGroundToActivateRollOnLanding = 1;
|
||||
|
||||
public float minWaitToActivateRollOnLandingInput = 0.5f;
|
||||
|
||||
public LayerMask raycastLayermask;
|
||||
|
||||
public bool useMaxTimeOnAirToActivateRollOnLanding;
|
||||
public float maxTimeOnAirToActivateRollOnLanding;
|
||||
|
||||
[Space]
|
||||
[Header ("Debug")]
|
||||
[Space]
|
||||
|
||||
public bool rollOnLandingCheckActive;
|
||||
|
||||
public bool showDebugPrint;
|
||||
|
||||
[Space]
|
||||
[Header ("Events Settings")]
|
||||
[Space]
|
||||
|
||||
public UnityEvent eventsOnRollOnLandingThirdPerson;
|
||||
|
||||
public UnityEvent eventsOnRollOnLandingFirstPerson;
|
||||
|
||||
[Space]
|
||||
[Header ("Components")]
|
||||
[Space]
|
||||
|
||||
public playerController mainPlayerController;
|
||||
|
||||
public Transform playerTransform;
|
||||
|
||||
Coroutine landingCoroutine;
|
||||
|
||||
float lastTimeRollOnLandingActive;
|
||||
|
||||
bool eventsActivated;
|
||||
|
||||
float lastTimeRollOnLandingInputActive;
|
||||
|
||||
bool cancelCheckRollOnLandingOnceActive;
|
||||
|
||||
float lastTimeCancelCheckRoll;
|
||||
|
||||
public void setCancelCheckRollOnLandingOnceActive (bool state)
|
||||
{
|
||||
cancelCheckRollOnLandingOnceActive = state;
|
||||
|
||||
lastTimeCancelCheckRoll = Time.time;
|
||||
}
|
||||
|
||||
public void inputActivateRollOnLanding ()
|
||||
{
|
||||
// print (cancelCheckRollOnLandingOnceActive + " " + (Time.time) + " " + (lastTimeCancelCheckRoll + 0.7f));
|
||||
|
||||
if (cancelCheckRollOnLandingOnceActive) {
|
||||
if (Time.time > lastTimeCancelCheckRoll + 0.7f) {
|
||||
|
||||
cancelCheckRollOnLandingOnceActive = false;
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (!rollOnlandingEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (mainPlayerController.isPlayerOnGround ()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (Time.time < minWaitToActivateRollOnLandingInput + lastTimeRollOnLandingInputActive) {
|
||||
return;
|
||||
}
|
||||
|
||||
stopActivateRollOnLandingCoroutine ();
|
||||
|
||||
bool canActivateRollOnLanding = true;
|
||||
|
||||
if (useMaxTimeOnAirToActivateRollOnLanding) {
|
||||
float totalTimeOnAir = Mathf.Abs (Time.time - mainPlayerController.getLastTimeFalling ());
|
||||
|
||||
if (showDebugPrint) {
|
||||
print ("Current time on air " + totalTimeOnAir);
|
||||
}
|
||||
|
||||
if (totalTimeOnAir > maxTimeOnAirToActivateRollOnLanding) {
|
||||
canActivateRollOnLanding = false;
|
||||
|
||||
if (showDebugPrint) {
|
||||
print ("Too much time on air, can't activate roll on landing");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (mainPlayerController.isFlyingActive () ||
|
||||
mainPlayerController.isPlayerOnFreeFloatingMode ()) {
|
||||
canActivateRollOnLanding = false;
|
||||
|
||||
if (showDebugPrint) {
|
||||
print ("can't activate roll on landing on fly mode, or flotaing mode");
|
||||
}
|
||||
}
|
||||
|
||||
if (canActivateRollOnLanding) {
|
||||
landingCoroutine = StartCoroutine (activateRollOnLandingCoroutine ());
|
||||
|
||||
lastTimeRollOnLandingInputActive = Time.time;
|
||||
}
|
||||
}
|
||||
|
||||
public void inputDeactivateRollOnLanding ()
|
||||
{
|
||||
if (!rollOnlandingEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (mainPlayerController.isPlayerOnGround ()) {
|
||||
return;
|
||||
}
|
||||
|
||||
stopActivateRollOnLandingCoroutine ();
|
||||
}
|
||||
|
||||
void stopActivateRollOnLandingCoroutine ()
|
||||
{
|
||||
if (landingCoroutine != null) {
|
||||
StopCoroutine (landingCoroutine);
|
||||
}
|
||||
|
||||
if (rollOnLandingCheckActive) {
|
||||
mainPlayerController.setCheckFallStatePausedState (false);
|
||||
|
||||
rollOnLandingCheckActive = false;
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator activateRollOnLandingCoroutine ()
|
||||
{
|
||||
rollOnLandingCheckActive = true;
|
||||
|
||||
lastTimeRollOnLandingActive = Time.time;
|
||||
|
||||
eventsActivated = false;
|
||||
|
||||
mainPlayerController.setCheckFallStatePausedState (true);
|
||||
|
||||
bool targetReached = false;
|
||||
|
||||
while (!targetReached) {
|
||||
if (Time.time > lastTimeRollOnLandingActive + rollOnLandingCheckDuration) {
|
||||
targetReached = true;
|
||||
} else {
|
||||
if (!eventsActivated) {
|
||||
if (Physics.Raycast (playerTransform.position, -playerTransform.up, distanceFromGroundToActivateRollOnLanding, raycastLayermask)) {
|
||||
if (Time.time > lastTimeRollOnLandingActive + eventsOnRollLandingDelay) {
|
||||
eventsActivated = true;
|
||||
|
||||
if (showDebugPrint) {
|
||||
print ("Activate roll on landing");
|
||||
}
|
||||
|
||||
if (mainPlayerController.isPlayerOnFirstPerson ()) {
|
||||
eventsOnRollOnLandingFirstPerson.Invoke ();
|
||||
} else {
|
||||
eventsOnRollOnLandingThirdPerson.Invoke ();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
yield return null;
|
||||
}
|
||||
|
||||
mainPlayerController.setCheckFallStatePausedState (false);
|
||||
|
||||
rollOnLandingCheckActive = false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 07d80340cb5235c4e8aacae0bf6ff4bf
|
||||
timeCreated: 1626090105
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 40995
|
||||
packageName: Game Kit Controller - Shooter Melee Adventure Creator 3D + 2.5D
|
||||
packageVersion: 3.77g
|
||||
assetPath: Assets/Game Kit Controller/Scripts/Player/Extra Movements/rollOnLandingSystem.cs
|
||||
uploadId: 814740
|
||||
@@ -0,0 +1,58 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class simpleWaypointSystem : MonoBehaviour
|
||||
{
|
||||
[Header ("Main Settings")]
|
||||
[Space]
|
||||
|
||||
public List<Transform> wayPoints = new List<Transform> ();
|
||||
|
||||
[Space]
|
||||
[Header ("Gizmo Settings")]
|
||||
[Space]
|
||||
|
||||
public bool showGizmo;
|
||||
public Color gizmoLabelColor = Color.black;
|
||||
public float gizmoRadius;
|
||||
|
||||
public List<Transform> getWayPoints ()
|
||||
{
|
||||
return wayPoints;
|
||||
}
|
||||
|
||||
void OnDrawGizmos ()
|
||||
{
|
||||
if (!showGizmo) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (GKC_Utils.isCurrentSelectionActiveGameObject (gameObject)) {
|
||||
DrawGizmos ();
|
||||
}
|
||||
}
|
||||
|
||||
void OnDrawGizmosSelected ()
|
||||
{
|
||||
DrawGizmos ();
|
||||
}
|
||||
|
||||
void DrawGizmos ()
|
||||
{
|
||||
if (showGizmo) {
|
||||
for (int i = 0; i < wayPoints.Count; i++) {
|
||||
if (wayPoints [i] != null) {
|
||||
Gizmos.color = Color.yellow;
|
||||
Gizmos.DrawSphere (wayPoints [i].position, gizmoRadius);
|
||||
|
||||
if (i + 1 < wayPoints.Count && wayPoints [i + 1] != null) {
|
||||
Gizmos.color = Color.white;
|
||||
Gizmos.DrawLine (wayPoints [i].position, wayPoints [i + 1].position);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b54a005b5cb9d4945b0024e7888dfafe
|
||||
timeCreated: 1641103010
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 40995
|
||||
packageName: Game Kit Controller - Shooter Melee Adventure Creator 3D + 2.5D
|
||||
packageVersion: 3.77g
|
||||
assetPath: Assets/Game Kit Controller/Scripts/Player/Extra Movements/simpleWaypointSystem.cs
|
||||
uploadId: 814740
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5ec6f7b00092b254ca0a769cc1887cb3
|
||||
timeCreated: 1630724656
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 40995
|
||||
packageName: Game Kit Controller - Shooter Melee Adventure Creator 3D + 2.5D
|
||||
packageVersion: 3.77g
|
||||
assetPath: Assets/Game Kit Controller/Scripts/Player/Extra Movements/slideSystem.cs
|
||||
uploadId: 814740
|
||||
@@ -0,0 +1,137 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class slideZoneSystem : MonoBehaviour
|
||||
{
|
||||
[Header ("Main Settings")]
|
||||
[Space]
|
||||
|
||||
public string tagToCheck;
|
||||
public bool slideZoneActive = true;
|
||||
|
||||
public float slideSpeedMultiplier = 1;
|
||||
|
||||
public bool setEnterStateActive = true;
|
||||
|
||||
public bool setExitStateActive = true;
|
||||
|
||||
public bool justUpdateSlideTransform;
|
||||
|
||||
[Space]
|
||||
[Header ("Jump Settings")]
|
||||
[Space]
|
||||
|
||||
public bool justActivateJumpStateOnSlide;
|
||||
|
||||
public Vector3 impulseOnJump;
|
||||
|
||||
[Space]
|
||||
[Header ("Gravity Settings")]
|
||||
[Space]
|
||||
|
||||
public bool justSetAdhereToSurfacesActiveState;
|
||||
|
||||
public bool adhereToSurfacesActiveState;
|
||||
|
||||
public bool setResetGravityDirectionOnSlideExitEnabledState;
|
||||
|
||||
public bool resetGravityDirectionOnSlideExitEnabledState;
|
||||
|
||||
[Space]
|
||||
[Header ("Components")]
|
||||
[Space]
|
||||
|
||||
public Transform slideTransform;
|
||||
|
||||
GameObject currentPlayer;
|
||||
|
||||
void OnTriggerEnter (Collider col)
|
||||
{
|
||||
checkTriggerInfo (col, true);
|
||||
}
|
||||
|
||||
void OnTriggerExit (Collider col)
|
||||
{
|
||||
checkTriggerInfo (col, false);
|
||||
}
|
||||
|
||||
public void checkTriggerInfo (Collider col, bool isEnter)
|
||||
{
|
||||
if (!slideZoneActive) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!col.gameObject.CompareTag (tagToCheck)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (isEnter) {
|
||||
if (!setEnterStateActive) {
|
||||
return;
|
||||
}
|
||||
|
||||
currentPlayer = col.gameObject;
|
||||
|
||||
playerComponentsManager currentPlayerComponentsManager = currentPlayer.GetComponent<playerComponentsManager> ();
|
||||
|
||||
if (currentPlayerComponentsManager != null) {
|
||||
externalControllerBehavior slideExternalControllerBehavior = currentPlayerComponentsManager.getSlideExternalControllerBehavior ();
|
||||
|
||||
if (slideExternalControllerBehavior != null) {
|
||||
slideSystem currentSlideSystem = slideExternalControllerBehavior.GetComponent<slideSystem> ();
|
||||
|
||||
if (setResetGravityDirectionOnSlideExitEnabledState) {
|
||||
currentSlideSystem.setResetGravityDirectionOnSlideExitEnabledState (resetGravityDirectionOnSlideExitEnabledState);
|
||||
}
|
||||
|
||||
if (justActivateJumpStateOnSlide) {
|
||||
currentSlideSystem.setJumpActive (impulseOnJump);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (justSetAdhereToSurfacesActiveState) {
|
||||
currentSlideSystem.setAdhereToSurfacesActiveState (adhereToSurfacesActiveState);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
currentSlideSystem.setCurrentSlideTransform (slideTransform);
|
||||
|
||||
if (justUpdateSlideTransform) {
|
||||
return;
|
||||
}
|
||||
|
||||
currentSlideSystem.setSlideSpeedMultiplier (slideSpeedMultiplier);
|
||||
|
||||
currentSlideSystem.setCheckIfDetectSlideActiveState (true, true);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (!setExitStateActive) {
|
||||
return;
|
||||
}
|
||||
|
||||
currentPlayer = col.gameObject;
|
||||
|
||||
playerComponentsManager currentPlayerComponentsManager = currentPlayer.GetComponent<playerComponentsManager> ();
|
||||
|
||||
if (currentPlayerComponentsManager != null) {
|
||||
externalControllerBehavior slideExternalControllerBehavior = currentPlayerComponentsManager.getSlideExternalControllerBehavior ();
|
||||
|
||||
if (slideExternalControllerBehavior != null) {
|
||||
slideSystem currentSlideSystem = slideExternalControllerBehavior.GetComponent<slideSystem> ();
|
||||
|
||||
currentSlideSystem.setCheckIfDetectSlideActiveState (false, false);
|
||||
|
||||
currentSlideSystem.setCurrentSlideTransform (null);
|
||||
|
||||
// if (setResetGravityDirectionOnSlideExitEnabledState) {
|
||||
// currentSlideSystem.setOriginalResetGravityDirectionOnSlideExitEnabled ();
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ec1334c27d138374ca0506fce9029fb6
|
||||
timeCreated: 1630727393
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 40995
|
||||
packageName: Game Kit Controller - Shooter Melee Adventure Creator 3D + 2.5D
|
||||
packageVersion: 3.77g
|
||||
assetPath: Assets/Game Kit Controller/Scripts/Player/Extra Movements/slideZoneSystem.cs
|
||||
uploadId: 814740
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c707040a722187c4fb2cbc84dd8ed5ce
|
||||
timeCreated: 1627607236
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 40995
|
||||
packageName: Game Kit Controller - Shooter Melee Adventure Creator 3D + 2.5D
|
||||
packageVersion: 3.77g
|
||||
assetPath: Assets/Game Kit Controller/Scripts/Player/Extra Movements/swimSystem.cs
|
||||
uploadId: 814740
|
||||
@@ -0,0 +1,303 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class swimTriggerSystem : MonoBehaviour
|
||||
{
|
||||
[Header ("Main Settings")]
|
||||
[Space]
|
||||
|
||||
public string tagToCheck;
|
||||
public bool swimZoneActive = true;
|
||||
|
||||
public bool updateSurfaceTransformDynamically;
|
||||
|
||||
[Space]
|
||||
[Header ("Vehicle Settings")]
|
||||
[Space]
|
||||
|
||||
public bool checkVehiclesOnEnteringWater;
|
||||
public bool disableVehiclesInteractionOnEnterWater;
|
||||
public bool ejectPassengersOnVehicleOnEnterWater;
|
||||
public bool explodeVehiclesAfterXTime;
|
||||
public float timeToExplodeVehiclesAfterXTime;
|
||||
|
||||
public bool setVehicleGravityForce;
|
||||
public float newVehicleGravityForce;
|
||||
|
||||
public bool reduceVehicleSpeedOnEnterWater;
|
||||
public float reducedVehicleSpeedMultiplier;
|
||||
|
||||
public LayerMask vehicleLayerToCheck;
|
||||
|
||||
[Space]
|
||||
[Space]
|
||||
|
||||
public bool checkVehiclesOnExitingWater;
|
||||
|
||||
[Space]
|
||||
[Header ("Remote Events Settings")]
|
||||
[Space]
|
||||
|
||||
public bool useRemoteEvents;
|
||||
public bool useRemoteEventOnSwimStart;
|
||||
public List<string> remoteEventNameListOnSwimStart = new List<string> ();
|
||||
|
||||
public bool useRemoteEventOnSwimEnd;
|
||||
public List<string> remoteEventNameListOnSwimEnd = new List<string> ();
|
||||
|
||||
[Space]
|
||||
[Header ("Debug")]
|
||||
[Space]
|
||||
|
||||
public List<GameObject> vehicleDetectedList = new List<GameObject> ();
|
||||
|
||||
public bool showGizmo;
|
||||
public Color gizmoColor = Color.red;
|
||||
public float gizmoRadius = 0.1f;
|
||||
|
||||
[Space]
|
||||
[Header ("Components")]
|
||||
[Space]
|
||||
|
||||
public Transform swimZoneTransform;
|
||||
|
||||
public waterSurfaceSystem mainWaterSurfaceSystem;
|
||||
|
||||
public Collider mainTrigger;
|
||||
|
||||
|
||||
GameObject currentPlayer;
|
||||
|
||||
|
||||
void OnTriggerEnter (Collider col)
|
||||
{
|
||||
checkTriggerInfo (col, true);
|
||||
}
|
||||
|
||||
void OnTriggerExit (Collider col)
|
||||
{
|
||||
checkTriggerInfo (col, false);
|
||||
}
|
||||
|
||||
public void checkTriggerInfo (Collider col, bool isEnter)
|
||||
{
|
||||
if (!swimZoneActive) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!col.gameObject.CompareTag (tagToCheck)) {
|
||||
|
||||
if (isEnter) {
|
||||
if (checkVehiclesOnEnteringWater) {
|
||||
GameObject objectToCheck = col.gameObject;
|
||||
|
||||
if ((1 << objectToCheck.layer & vehicleLayerToCheck.value) == 1 << objectToCheck.layer) {
|
||||
|
||||
GameObject vehicleGameObject = applyDamage.getVehicle (objectToCheck);
|
||||
|
||||
if (vehicleGameObject != null) {
|
||||
regularVehicleOnWater currentRegularVehicleOnWater = vehicleGameObject.GetComponent<regularVehicleOnWater> ();
|
||||
|
||||
if (currentRegularVehicleOnWater != null) {
|
||||
Collider mainVehicleCollider = currentRegularVehicleOnWater.getMainCollider ();
|
||||
|
||||
if (mainVehicleCollider != col) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (vehicleDetectedList.Contains (vehicleGameObject)) {
|
||||
return;
|
||||
} else {
|
||||
vehicleDetectedList.Add (vehicleGameObject);
|
||||
}
|
||||
}
|
||||
|
||||
if (disableVehiclesInteractionOnEnterWater) {
|
||||
applyDamage.setVehicleInteractionTriggerState (objectToCheck, false);
|
||||
}
|
||||
|
||||
if (ejectPassengersOnVehicleOnEnterWater) {
|
||||
applyDamage.ejectAllPassengersFromVehicle (objectToCheck);
|
||||
}
|
||||
|
||||
if (explodeVehiclesAfterXTime) {
|
||||
applyDamage.activateSelfDestructionOnVehicleExternally (objectToCheck, timeToExplodeVehiclesAfterXTime);
|
||||
}
|
||||
|
||||
if (setVehicleGravityForce) {
|
||||
applyDamage.setNewVehicleGravityForce (objectToCheck, newVehicleGravityForce);
|
||||
}
|
||||
|
||||
if (reduceVehicleSpeedOnEnterWater) {
|
||||
applyDamage.setReducedVehicleSpeed (objectToCheck, reducedVehicleSpeedMultiplier);
|
||||
}
|
||||
|
||||
checkRemoteEvents (true, objectToCheck);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (checkVehiclesOnExitingWater) {
|
||||
GameObject objectToCheck = col.gameObject;
|
||||
|
||||
if ((1 << objectToCheck.layer & vehicleLayerToCheck.value) == 1 << objectToCheck.layer) {
|
||||
|
||||
GameObject vehicleGameObject = applyDamage.getVehicle (objectToCheck);
|
||||
|
||||
if (vehicleGameObject != null) {
|
||||
regularVehicleOnWater currentRegularVehicleOnWater = vehicleGameObject.GetComponent<regularVehicleOnWater> ();
|
||||
|
||||
if (currentRegularVehicleOnWater != null) {
|
||||
Collider mainVehicleCollider = currentRegularVehicleOnWater.getMainCollider ();
|
||||
|
||||
if (mainVehicleCollider != col) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (!vehicleDetectedList.Contains (vehicleGameObject)) {
|
||||
return;
|
||||
} else {
|
||||
vehicleDetectedList.Remove (vehicleGameObject);
|
||||
}
|
||||
}
|
||||
|
||||
if (setVehicleGravityForce) {
|
||||
applyDamage.setOriginalGravityForce (objectToCheck);
|
||||
}
|
||||
|
||||
checkRemoteEvents (false, objectToCheck);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (isEnter) {
|
||||
currentPlayer = col.gameObject;
|
||||
|
||||
playerComponentsManager currentPlayerComponentsManager = currentPlayer.GetComponent<playerComponentsManager> ();
|
||||
|
||||
if (currentPlayerComponentsManager != null) {
|
||||
externalControllerBehavior swimExternalControllerBehavior = currentPlayerComponentsManager.getSwimExternalControllerBehavior ();
|
||||
|
||||
if (swimExternalControllerBehavior != null) {
|
||||
swimSystem currentSwimSystem = swimExternalControllerBehavior.GetComponent<swimSystem> ();
|
||||
|
||||
if (mainTrigger == null) {
|
||||
mainTrigger = GetComponent<Collider> ();
|
||||
}
|
||||
|
||||
currentSwimSystem.addSwimTrigger (mainTrigger);
|
||||
|
||||
currentSwimSystem.setSwimZoneTransform (swimZoneTransform);
|
||||
|
||||
currentSwimSystem.setSwimTrigger (mainTrigger);
|
||||
|
||||
if (updateSurfaceTransformDynamically) {
|
||||
currentSwimSystem.setCurrentWaterSurfaceSystem (mainWaterSurfaceSystem);
|
||||
}
|
||||
|
||||
currentSwimSystem.setSwimSystemActivestate (true);
|
||||
|
||||
checkRemoteEvents (true, currentPlayer);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
currentPlayer = col.gameObject;
|
||||
|
||||
playerComponentsManager currentPlayerComponentsManager = currentPlayer.GetComponent<playerComponentsManager> ();
|
||||
|
||||
if (currentPlayerComponentsManager != null) {
|
||||
externalControllerBehavior swimExternalControllerBehavior = currentPlayerComponentsManager.getSwimExternalControllerBehavior ();
|
||||
|
||||
if (swimExternalControllerBehavior != null) {
|
||||
swimSystem currentSwimSystem = swimExternalControllerBehavior.GetComponent<swimSystem> ();
|
||||
|
||||
if (mainTrigger == null) {
|
||||
mainTrigger = GetComponent<Collider> ();
|
||||
}
|
||||
|
||||
currentSwimSystem.removeSwimTrigger (mainTrigger);
|
||||
|
||||
if (currentSwimSystem.isSwimTriggerListEmpty ()) {
|
||||
|
||||
currentSwimSystem.setSwimSystemActivestate (false);
|
||||
|
||||
currentSwimSystem.setSwimZoneTransform (null);
|
||||
|
||||
currentSwimSystem.setSwimTrigger (null);
|
||||
|
||||
currentSwimSystem.setCurrentWaterSurfaceSystem (null);
|
||||
}
|
||||
|
||||
checkRemoteEvents (false, currentPlayer);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void checkRemoteEvents (bool state, GameObject objectToCheck)
|
||||
{
|
||||
if (!useRemoteEvents) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (state) {
|
||||
if (useRemoteEventOnSwimStart) {
|
||||
remoteEventSystem currentRemoteEventSystem = objectToCheck.GetComponent<remoteEventSystem> ();
|
||||
|
||||
if (currentRemoteEventSystem != null) {
|
||||
for (int i = 0; i < remoteEventNameListOnSwimStart.Count; i++) {
|
||||
|
||||
currentRemoteEventSystem.callRemoteEvent (remoteEventNameListOnSwimStart [i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (useRemoteEventOnSwimEnd) {
|
||||
remoteEventSystem currentRemoteEventSystem = objectToCheck.GetComponent<remoteEventSystem> ();
|
||||
|
||||
if (currentRemoteEventSystem != null) {
|
||||
for (int i = 0; i < remoteEventNameListOnSwimEnd.Count; i++) {
|
||||
|
||||
currentRemoteEventSystem.callRemoteEvent (remoteEventNameListOnSwimEnd [i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Draw gizmos
|
||||
void OnDrawGizmos ()
|
||||
{
|
||||
if (!showGizmo) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (GKC_Utils.isCurrentSelectionActiveGameObject (gameObject)) {
|
||||
DrawGizmos ();
|
||||
}
|
||||
}
|
||||
|
||||
void OnDrawGizmosSelected ()
|
||||
{
|
||||
DrawGizmos ();
|
||||
}
|
||||
|
||||
void DrawGizmos ()
|
||||
{
|
||||
if (showGizmo) {
|
||||
if (swimZoneTransform != null) {
|
||||
Gizmos.color = gizmoColor;
|
||||
|
||||
Vector3 position = swimZoneTransform.position;
|
||||
Gizmos.DrawSphere (position, gizmoRadius);
|
||||
|
||||
Debug.DrawRay (position, transform.position, Color.white);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cdd0d41c1e184df4fa7cbe214312faf6
|
||||
timeCreated: 1627609583
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 40995
|
||||
packageName: Game Kit Controller - Shooter Melee Adventure Creator 3D + 2.5D
|
||||
packageVersion: 3.77g
|
||||
assetPath: Assets/Game Kit Controller/Scripts/Player/Extra Movements/swimTriggerSystem.cs
|
||||
uploadId: 814740
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 35dae826841d85b4495940c8baa42f23
|
||||
timeCreated: 1641102092
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 40995
|
||||
packageName: Game Kit Controller - Shooter Melee Adventure Creator 3D + 2.5D
|
||||
packageVersion: 3.77g
|
||||
assetPath: Assets/Game Kit Controller/Scripts/Player/Extra Movements/walkOnBalanceSystem.cs
|
||||
uploadId: 814740
|
||||
@@ -0,0 +1,155 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class walkOnBalanceTriggerSystem : MonoBehaviour
|
||||
{
|
||||
[Header ("Main Settings")]
|
||||
[Space]
|
||||
|
||||
public string tagToCheck;
|
||||
public bool movementZoneActive = true;
|
||||
|
||||
public simpleWaypointSystem mainSimpleWaypointSystem;
|
||||
|
||||
public bool checkOnTriggerEnter = true;
|
||||
public bool checkOnTriggerExit = true;
|
||||
|
||||
public bool setPlayerAsChild = true;
|
||||
public Transform playerParentTransform;
|
||||
|
||||
[Space]
|
||||
[Header ("Jump On Target Position Reached Settings")]
|
||||
[Space]
|
||||
|
||||
public bool setJumpOnEndState;
|
||||
public bool jumpOnEndState;
|
||||
|
||||
[Space]
|
||||
[Header ("Remote Events Settings")]
|
||||
[Space]
|
||||
|
||||
public bool useRemoteEvents;
|
||||
public bool useRemoteEventOnStart;
|
||||
public List<string> remoteEventNameListOnStart = new List<string> ();
|
||||
|
||||
public bool useRemoteEventOnEnd;
|
||||
public List<string> remoteEventNameListOnEnd = new List<string> ();
|
||||
|
||||
GameObject currentPlayer;
|
||||
|
||||
|
||||
void OnTriggerEnter (Collider col)
|
||||
{
|
||||
checkTriggerInfo (col, true);
|
||||
}
|
||||
|
||||
void OnTriggerExit (Collider col)
|
||||
{
|
||||
checkTriggerInfo (col, false);
|
||||
}
|
||||
|
||||
public void checkTriggerInfo (Collider col, bool isEnter)
|
||||
{
|
||||
if (!movementZoneActive) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (isEnter) {
|
||||
if (!checkOnTriggerEnter) {
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
if (!checkOnTriggerExit) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (!col.gameObject.CompareTag (tagToCheck)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (isEnter) {
|
||||
currentPlayer = col.gameObject;
|
||||
|
||||
playerComponentsManager currentPlayerComponentsManager = currentPlayer.GetComponent<playerComponentsManager> ();
|
||||
|
||||
if (currentPlayerComponentsManager != null) {
|
||||
externalControllerBehavior movementExternalControllerBehavior = currentPlayerComponentsManager.getWalkOnBalanceExternaControllerBehavior ();
|
||||
|
||||
if (movementExternalControllerBehavior != null) {
|
||||
walkOnBalanceSystem currentMovementSystem = movementExternalControllerBehavior.GetComponent<walkOnBalanceSystem> ();
|
||||
|
||||
if (playerParentTransform == null) {
|
||||
playerParentTransform = transform;
|
||||
}
|
||||
|
||||
currentMovementSystem.setSetPlayerAsChildStateState (setPlayerAsChild, playerParentTransform);
|
||||
|
||||
currentMovementSystem.setCurrentWaypoint (mainSimpleWaypointSystem);
|
||||
|
||||
currentMovementSystem.setMovementSystemActivestate (true);
|
||||
|
||||
if (setJumpOnEndState) {
|
||||
currentMovementSystem.setJumpOnEndState (jumpOnEndState);
|
||||
}
|
||||
|
||||
checkRemoteEvents (true, currentPlayer);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
currentPlayer = col.gameObject;
|
||||
|
||||
playerComponentsManager currentPlayerComponentsManager = currentPlayer.GetComponent<playerComponentsManager> ();
|
||||
|
||||
if (currentPlayerComponentsManager != null) {
|
||||
externalControllerBehavior movementExternalControllerBehavior = currentPlayerComponentsManager.getWalkOnBalanceExternaControllerBehavior ();
|
||||
|
||||
if (movementExternalControllerBehavior != null) {
|
||||
walkOnBalanceSystem currentMovementSystem = movementExternalControllerBehavior.GetComponent<walkOnBalanceSystem> ();
|
||||
|
||||
currentMovementSystem.setSetPlayerAsChildStateState (false, null);
|
||||
|
||||
currentMovementSystem.setMovementSystemActivestate (false);
|
||||
|
||||
currentMovementSystem.setCurrentWaypoint (null);
|
||||
|
||||
currentMovementSystem.setJumpOnEndState (true);
|
||||
|
||||
checkRemoteEvents (false, currentPlayer);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void checkRemoteEvents (bool state, GameObject objectToCheck)
|
||||
{
|
||||
if (!useRemoteEvents) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (state) {
|
||||
if (useRemoteEventOnStart) {
|
||||
remoteEventSystem currentRemoteEventSystem = objectToCheck.GetComponent<remoteEventSystem> ();
|
||||
|
||||
if (currentRemoteEventSystem != null) {
|
||||
for (int i = 0; i < remoteEventNameListOnStart.Count; i++) {
|
||||
|
||||
currentRemoteEventSystem.callRemoteEvent (remoteEventNameListOnStart [i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (useRemoteEventOnEnd) {
|
||||
remoteEventSystem currentRemoteEventSystem = objectToCheck.GetComponent<remoteEventSystem> ();
|
||||
|
||||
if (currentRemoteEventSystem != null) {
|
||||
for (int i = 0; i < remoteEventNameListOnEnd.Count; i++) {
|
||||
|
||||
currentRemoteEventSystem.callRemoteEvent (remoteEventNameListOnEnd [i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d6f5de43177c80b4987823eecb2beced
|
||||
timeCreated: 1641102528
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 40995
|
||||
packageName: Game Kit Controller - Shooter Melee Adventure Creator 3D + 2.5D
|
||||
packageVersion: 3.77g
|
||||
assetPath: Assets/Game Kit Controller/Scripts/Player/Extra Movements/walkOnBalanceTriggerSystem.cs
|
||||
uploadId: 814740
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 590da6696ac96f7499b00c27b6a29f42
|
||||
timeCreated: 1626531706
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 40995
|
||||
packageName: Game Kit Controller - Shooter Melee Adventure Creator 3D + 2.5D
|
||||
packageVersion: 3.77g
|
||||
assetPath: Assets/Game Kit Controller/Scripts/Player/Extra Movements/wallRunningSystem.cs
|
||||
uploadId: 814740
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 65b06d1a88346ae4f9e6b72f3c9607be
|
||||
timeCreated: 1633972856
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 40995
|
||||
packageName: Game Kit Controller - Shooter Melee Adventure Creator 3D + 2.5D
|
||||
packageVersion: 3.77g
|
||||
assetPath: Assets/Game Kit Controller/Scripts/Player/Extra Movements/wallSlideJumpSystem.cs
|
||||
uploadId: 814740
|
||||
@@ -0,0 +1,78 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class wallSlideJumpZoneSystem : MonoBehaviour
|
||||
{
|
||||
[Header ("Main Settings")]
|
||||
[Space]
|
||||
|
||||
public string tagToCheck;
|
||||
public bool slideZoneActive = true;
|
||||
|
||||
public float slideDownSpeedMultiplier = 1;
|
||||
|
||||
public bool forceSlowDownOnSurfaceActive;
|
||||
|
||||
GameObject currentPlayer;
|
||||
|
||||
|
||||
void OnTriggerEnter (Collider col)
|
||||
{
|
||||
checkTriggerInfo (col, true);
|
||||
}
|
||||
|
||||
void OnTriggerExit (Collider col)
|
||||
{
|
||||
checkTriggerInfo (col, false);
|
||||
}
|
||||
|
||||
public void checkTriggerInfo (Collider col, bool isEnter)
|
||||
{
|
||||
if (!slideZoneActive) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!col.gameObject.CompareTag (tagToCheck)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (isEnter) {
|
||||
currentPlayer = col.gameObject;
|
||||
|
||||
playerComponentsManager currentPlayerComponentsManager = currentPlayer.GetComponent<playerComponentsManager> ();
|
||||
|
||||
if (currentPlayerComponentsManager != null) {
|
||||
externalControllerBehavior wallSlideJumpExteralControllerBehavior = currentPlayerComponentsManager.getWallSlideJumpExteralControllerBehavior ();
|
||||
|
||||
if (wallSlideJumpExteralControllerBehavior != null) {
|
||||
wallSlideJumpSystem currentWallSlideJumpSystem = wallSlideJumpExteralControllerBehavior.GetComponent<wallSlideJumpSystem> ();
|
||||
|
||||
currentWallSlideJumpSystem.setSlideDownSpeedMultiplier (slideDownSpeedMultiplier);
|
||||
|
||||
currentWallSlideJumpSystem.setForceSlowDownOnSurfaceActiveState (forceSlowDownOnSurfaceActive);
|
||||
|
||||
currentWallSlideJumpSystem.setCheckIfDetectSlideActiveState (true);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
currentPlayer = col.gameObject;
|
||||
|
||||
playerComponentsManager currentPlayerComponentsManager = currentPlayer.GetComponent<playerComponentsManager> ();
|
||||
|
||||
if (currentPlayerComponentsManager != null) {
|
||||
externalControllerBehavior wallSlideJumpExteralControllerBehavior = currentPlayerComponentsManager.getWallSlideJumpExteralControllerBehavior ();
|
||||
|
||||
if (wallSlideJumpExteralControllerBehavior != null) {
|
||||
wallSlideJumpSystem currentWallSlideJumpSystem = wallSlideJumpExteralControllerBehavior.GetComponent<wallSlideJumpSystem> ();
|
||||
|
||||
currentWallSlideJumpSystem.setSlideDownSpeedMultiplier (1);
|
||||
|
||||
currentWallSlideJumpSystem.setForceSlowDownOnSurfaceActiveState (false);
|
||||
|
||||
currentWallSlideJumpSystem.setCheckIfDetectSlideActiveState (false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c99084ff035b3ac4982f833b7657e716
|
||||
timeCreated: 1633983350
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 40995
|
||||
packageName: Game Kit Controller - Shooter Melee Adventure Creator 3D + 2.5D
|
||||
packageVersion: 3.77g
|
||||
assetPath: Assets/Game Kit Controller/Scripts/Player/Extra Movements/wallSlideJumpZoneSystem.cs
|
||||
uploadId: 814740
|
||||
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4b56abf1b7d5f874e87903570b3aabac
|
||||
folderAsset: yes
|
||||
timeCreated: 1631788922
|
||||
licenseType: Store
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,181 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
|
||||
public class AIMountManager : MonoBehaviour
|
||||
{
|
||||
[Header ("Main Settings")]
|
||||
[Space]
|
||||
|
||||
public bool mountManagerEnabled = true;
|
||||
|
||||
public string remoteEventToCallAIMount = "Set Player As Target For Mount AI";
|
||||
|
||||
public string remoteEventToAssignAIMount = "Assign Player To Mount AI";
|
||||
|
||||
public float minDistanceToCallAIMount = 20;
|
||||
|
||||
public float minDistanceToTeleportAIMount = 100;
|
||||
|
||||
public LayerMask layerToTeleportRaycast;
|
||||
|
||||
public float raycastDistance;
|
||||
|
||||
[Space]
|
||||
[Header ("Events Settings")]
|
||||
[Space]
|
||||
|
||||
public UnityEvent eventOnCallAIMount;
|
||||
|
||||
public UnityEvent eventOnTeleportAIMountBefore;
|
||||
public UnityEvent eventOnTeleportAIMountAfter;
|
||||
|
||||
[Space]
|
||||
[Header ("Debug")]
|
||||
[Space]
|
||||
|
||||
public bool showDebugPrint;
|
||||
|
||||
public bool currentMountAssigned;
|
||||
|
||||
public GameObject currentMountGameObject;
|
||||
|
||||
[Space]
|
||||
[Header ("Components")]
|
||||
[Space]
|
||||
|
||||
public Transform teleportAIMountTargetTransform;
|
||||
|
||||
public Transform playerTransform;
|
||||
|
||||
playerController mountPlayerController;
|
||||
|
||||
Transform currentMountTransform;
|
||||
|
||||
float lastTimeAIMountAssigned;
|
||||
|
||||
remoteEventSystem currentRemoteEventSystem;
|
||||
|
||||
public void assignCurrentMountGameObject (GameObject newObject)
|
||||
{
|
||||
if (!mountManagerEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
StartCoroutine (assignCurrentMountGameObjectCoroutine (newObject));
|
||||
}
|
||||
|
||||
IEnumerator assignCurrentMountGameObjectCoroutine (GameObject newObject)
|
||||
{
|
||||
yield return new WaitForSeconds (0.01f);
|
||||
|
||||
mountPlayerController = newObject.GetComponentInChildren<playerController> ();
|
||||
|
||||
if (mountPlayerController != null) {
|
||||
currentMountGameObject = mountPlayerController.gameObject;
|
||||
|
||||
currentMountTransform = currentMountGameObject.transform;
|
||||
|
||||
currentRemoteEventSystem = currentMountGameObject.GetComponent<remoteEventSystem> ();
|
||||
|
||||
if (currentRemoteEventSystem != null) {
|
||||
currentRemoteEventSystem.callRemoteEventWithGameObject (remoteEventToAssignAIMount, playerTransform.gameObject);
|
||||
}
|
||||
|
||||
currentMountAssigned = true;
|
||||
|
||||
lastTimeAIMountAssigned = Time.time;
|
||||
|
||||
if (showDebugPrint) {
|
||||
print ("Mount Assigned " + currentMountGameObject.name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void removeCurrentMountGameObject ()
|
||||
{
|
||||
if (currentMountAssigned) {
|
||||
mountPlayerController = null;
|
||||
|
||||
currentMountGameObject = null;
|
||||
|
||||
currentMountAssigned = false;
|
||||
|
||||
lastTimeAIMountAssigned = 0;
|
||||
|
||||
if (showDebugPrint) {
|
||||
print ("Mount removed ");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void callCurrentMount ()
|
||||
{
|
||||
if (!mountManagerEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!currentMountAssigned) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (Time.time < lastTimeAIMountAssigned + 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (currentMountGameObject == null || applyDamage.checkIfDeadOnObjectChilds (currentMountGameObject)) {
|
||||
removeCurrentMountGameObject ();
|
||||
|
||||
if (showDebugPrint) {
|
||||
print ("Mount is dead, removing ");
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
bool mountAICalled = false;
|
||||
|
||||
float distanceToPlayer = GKC_Utils.distance (playerTransform.position, currentMountGameObject.transform.position);
|
||||
|
||||
if (distanceToPlayer < minDistanceToCallAIMount) {
|
||||
if (currentRemoteEventSystem != null) {
|
||||
currentRemoteEventSystem.callRemoteEventWithGameObject (remoteEventToCallAIMount, playerTransform.gameObject);
|
||||
|
||||
mountAICalled = true;
|
||||
|
||||
if (showDebugPrint) {
|
||||
print ("Calling mount from distance on navmesh");
|
||||
}
|
||||
}
|
||||
} else if (distanceToPlayer < minDistanceToTeleportAIMount) {
|
||||
eventOnTeleportAIMountBefore.Invoke ();
|
||||
|
||||
Vector3 targetPosition = teleportAIMountTargetTransform.position;
|
||||
Quaternion targetRotation = teleportAIMountTargetTransform.rotation;
|
||||
|
||||
RaycastHit hit = new RaycastHit ();
|
||||
|
||||
if (Physics.Raycast (targetPosition, -Vector3.up, out hit, raycastDistance, layerToTeleportRaycast)) {
|
||||
targetPosition = hit.point + hit.normal * 0.1f;
|
||||
}
|
||||
|
||||
currentMountTransform.position = targetPosition;
|
||||
currentMountTransform.rotation = targetRotation;
|
||||
|
||||
currentRemoteEventSystem.callRemoteEventWithGameObject (remoteEventToCallAIMount, playerTransform.gameObject);
|
||||
|
||||
mountAICalled = true;
|
||||
|
||||
if (showDebugPrint) {
|
||||
print ("teleporting mount");
|
||||
}
|
||||
|
||||
eventOnTeleportAIMountAfter.Invoke ();
|
||||
}
|
||||
|
||||
if (mountAICalled) {
|
||||
eventOnCallAIMount.Invoke ();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6df7400d4652e3f46b3b47c62d05e975
|
||||
timeCreated: 1636372509
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 40995
|
||||
packageName: Game Kit Controller - Shooter Melee Adventure Creator 3D + 2.5D
|
||||
packageVersion: 3.77g
|
||||
assetPath: Assets/Game Kit Controller/Scripts/Player/Generic Model Controller/AIMountManager.cs
|
||||
uploadId: 814740
|
||||
@@ -0,0 +1,102 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class GKCCharacterController : playerController
|
||||
{
|
||||
[Space]
|
||||
[Header ("Custom Settings")]
|
||||
[Space]
|
||||
|
||||
public customCharacterControllerBase mainCustomCharacterControllerBase;
|
||||
|
||||
bool characterInitialized;
|
||||
|
||||
Vector2 customAxisValues;
|
||||
Vector2 customRawAxisValues;
|
||||
|
||||
void OnEnable ()
|
||||
{
|
||||
if (characterInitialized) {
|
||||
return;
|
||||
}
|
||||
|
||||
StartCoroutine (startGameWithCustomCharacterControllerCoroutine ());
|
||||
|
||||
characterInitialized = true;
|
||||
}
|
||||
|
||||
IEnumerator startGameWithCustomCharacterControllerCoroutine ()
|
||||
{
|
||||
yield return new WaitForSeconds (0.3f);
|
||||
|
||||
mainCustomCharacterControllerBase.setCharacterControllerActiveState (true);
|
||||
|
||||
mainCustomCharacterControllerBase.updateOnGroundValue (isPlayerOnGround ());
|
||||
|
||||
setCustomCharacterControllerActiveState (true, mainCustomCharacterControllerBase);
|
||||
|
||||
animator.runtimeAnimatorController = mainCustomCharacterControllerBase.originalAnimatorController;
|
||||
animator.avatar = mainCustomCharacterControllerBase.originalAvatar;
|
||||
|
||||
if (mainCustomCharacterControllerBase.setCapsuleColliderValues) {
|
||||
setPlayerColliderCapsuleScale (mainCustomCharacterControllerBase.capsuleColliderHeight);
|
||||
|
||||
setPlayerCapsuleColliderDirection (mainCustomCharacterControllerBase.capsuleColliderDirection);
|
||||
|
||||
setPlayerColliderCapsuleCenter (mainCustomCharacterControllerBase.capsuleColliderCenter);
|
||||
|
||||
setPlayerCapsuleColliderRadius (mainCustomCharacterControllerBase.capsuleColliderRadius);
|
||||
}
|
||||
|
||||
setCharacterMeshGameObjectState (false);
|
||||
|
||||
setCharacterMeshesListToDisableOnEventState (false);
|
||||
}
|
||||
|
||||
public override void setCustomAxisValues (Vector2 newValue)
|
||||
{
|
||||
customAxisValues = newValue;
|
||||
|
||||
if (customAxisValues.x > 0) {
|
||||
customRawAxisValues.x = 1;
|
||||
} else if (customAxisValues.x < 0) {
|
||||
customRawAxisValues.x = -1;
|
||||
} else {
|
||||
customRawAxisValues.x = 0;
|
||||
}
|
||||
|
||||
if (customAxisValues.y > 0) {
|
||||
customRawAxisValues.y = 1;
|
||||
} else if (customAxisValues.y < 0) {
|
||||
customRawAxisValues.y = -1;
|
||||
} else {
|
||||
customRawAxisValues.y = 0;
|
||||
}
|
||||
}
|
||||
|
||||
public override void setMainAxisValues ()
|
||||
{
|
||||
axisValues = customAxisValues;
|
||||
}
|
||||
|
||||
public override void setMainRawAxisValues ()
|
||||
{
|
||||
rawAxisValues = customRawAxisValues;
|
||||
}
|
||||
|
||||
public override void setAIMainAxisValues ()
|
||||
{
|
||||
axisValues = customAxisValues;
|
||||
}
|
||||
|
||||
public override void setMainAIRawAxisValues ()
|
||||
{
|
||||
rawAxisValues = customRawAxisValues;
|
||||
}
|
||||
|
||||
public override void updateOverrideInputValues (Vector2 inputValues, bool state)
|
||||
{
|
||||
// playerInput.overrideInputValues (inputValues, state);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: eda91f1a19d0d0f4ea08d5aaee031f96
|
||||
timeCreated: 1630672236
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 40995
|
||||
packageName: Game Kit Controller - Shooter Melee Adventure Creator 3D + 2.5D
|
||||
packageVersion: 3.77g
|
||||
assetPath: Assets/Game Kit Controller/Scripts/Player/Generic Model Controller/GKCCharacterController.cs
|
||||
uploadId: 814740
|
||||
@@ -0,0 +1,125 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class basicAnimatorController : customCharacterControllerBase
|
||||
{
|
||||
[Header ("Custom Settings")]
|
||||
[Space]
|
||||
|
||||
public string horizontalAnimatorName = "Horizontal";
|
||||
public string verticalAnimatorName = "Vertical";
|
||||
public string stateAnimatorName = "State";
|
||||
|
||||
public string groundedStateAnimatorName = "Grounded";
|
||||
public string movementAnimatorName = "Movement";
|
||||
public string speedMultiplierAnimatorName = "SpeedMultiplier";
|
||||
|
||||
[Space]
|
||||
[Header ("Other Settings")]
|
||||
[Space]
|
||||
|
||||
public int jumpState = 2;
|
||||
public int movementState = 1;
|
||||
public int fallState = 3;
|
||||
public int deathState = 10;
|
||||
|
||||
public int currentState;
|
||||
|
||||
int horizontalAnimatorID;
|
||||
int verticalAnimatorID;
|
||||
|
||||
int stateAnimatorID;
|
||||
int groundedStateAnimatorID;
|
||||
|
||||
int movementAnimatorID;
|
||||
|
||||
bool valuesInitialized;
|
||||
|
||||
void Start ()
|
||||
{
|
||||
initialiveValues ();
|
||||
}
|
||||
|
||||
void initialiveValues ()
|
||||
{
|
||||
if (!valuesInitialized) {
|
||||
horizontalAnimatorID = Animator.StringToHash (horizontalAnimatorName);
|
||||
verticalAnimatorID = Animator.StringToHash (verticalAnimatorName);
|
||||
|
||||
stateAnimatorID = Animator.StringToHash (stateAnimatorName);
|
||||
groundedStateAnimatorID = Animator.StringToHash (groundedStateAnimatorName);
|
||||
movementAnimatorID = Animator.StringToHash (movementAnimatorName);
|
||||
|
||||
valuesInitialized = true;
|
||||
}
|
||||
}
|
||||
|
||||
public override void updateCharacterControllerState ()
|
||||
{
|
||||
updateAnimatorFloatValueLerping (horizontalAnimatorID, turnAmount, animatorTurnInputLerpSpeed, Time.fixedDeltaTime);
|
||||
|
||||
updateAnimatorFloatValueLerping (verticalAnimatorID, forwardAmount, animatorForwardInputLerpSpeed, Time.fixedDeltaTime);
|
||||
|
||||
updateAnimatorBoolValue (groundedStateAnimatorID, onGround);
|
||||
|
||||
updateAnimatorBoolValue (movementAnimatorID, playerUsingInput);
|
||||
}
|
||||
|
||||
public override void updateCharacterControllerAnimator ()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override void updateMovementInputValues (Vector3 newValues)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override void updateHorizontalVerticalInputValues (Vector2 newValues)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override void activateJumpAnimatorState ()
|
||||
{
|
||||
updateAnimatorIntegerValue (stateAnimatorID, jumpState);
|
||||
|
||||
currentState = jumpState;
|
||||
}
|
||||
|
||||
public override void updateOnGroundValue (bool state)
|
||||
{
|
||||
base.updateOnGroundValue (state);
|
||||
|
||||
if (currentState == 1) {
|
||||
if (!onGround) {
|
||||
updateAnimatorIntegerValue (stateAnimatorID, 3);
|
||||
|
||||
currentState = 3;
|
||||
}
|
||||
} else {
|
||||
if (onGround) {
|
||||
updateAnimatorIntegerValue (stateAnimatorID, 1);
|
||||
|
||||
currentState = 1;
|
||||
} else {
|
||||
|
||||
// if (currentState == 2) {
|
||||
// updateAnimatorIntegerValue (stateAnimatorID, 20);
|
||||
//
|
||||
// currentState = 20;
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void setCharacterControllerActiveState (bool state)
|
||||
{
|
||||
base.setCharacterControllerActiveState (state);
|
||||
|
||||
if (state) {
|
||||
initialiveValues ();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e9350a7221815ae45a9785310f96d809
|
||||
timeCreated: 1629368377
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 40995
|
||||
packageName: Game Kit Controller - Shooter Melee Adventure Creator 3D + 2.5D
|
||||
packageVersion: 3.77g
|
||||
assetPath: Assets/Game Kit Controller/Scripts/Player/Generic Model Controller/basicAnimatorController.cs
|
||||
uploadId: 814740
|
||||
@@ -0,0 +1,529 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
|
||||
public class customCharacterControllerBase : MonoBehaviour
|
||||
{
|
||||
[Header ("Main Settings")]
|
||||
[Space]
|
||||
|
||||
public bool characterControllerEnabled = true;
|
||||
|
||||
public float animatorForwardInputLerpSpeed = 0.1f;
|
||||
public float animatorTurnInputLerpSpeed = 0.1f;
|
||||
|
||||
public float forwardAmountMultiplier = 1;
|
||||
|
||||
public bool updateForwardAmountInputValueFromPlayerController;
|
||||
|
||||
public bool updateTurnAmountInputValueFromPlayerController;
|
||||
|
||||
public bool updateUsingInputValueFromPlayerController;
|
||||
|
||||
[Space]
|
||||
|
||||
public float placeToShootOffset;
|
||||
|
||||
public bool usePlaceToShootLocalPosition;
|
||||
|
||||
public Vector3 placeToShootLocalPosition;
|
||||
|
||||
[Space]
|
||||
[Header ("Collider Settings")]
|
||||
[Space]
|
||||
|
||||
public bool setCapsuleColliderValues;
|
||||
|
||||
public Vector3 capsuleColliderCenter;
|
||||
public float capsuleColliderRadius;
|
||||
public float capsuleColliderHeight;
|
||||
public int capsuleColliderDirection = 0;
|
||||
|
||||
[Space]
|
||||
|
||||
public bool useExtraColliders;
|
||||
public List<Collider> extraCollidersList = new List<Collider> ();
|
||||
|
||||
public bool setLayerOnExtraCollider = true;
|
||||
|
||||
[Space]
|
||||
[Header ("Animator Settings")]
|
||||
[Space]
|
||||
|
||||
public Animator mainAnimator;
|
||||
public RuntimeAnimatorController originalAnimatorController;
|
||||
|
||||
public Avatar originalAvatar;
|
||||
|
||||
public Vector3 charactetPositionOffset;
|
||||
|
||||
public Vector3 characterRotationOffset;
|
||||
|
||||
[Space]
|
||||
[Header ("Root Motion Settings")]
|
||||
[Space]
|
||||
|
||||
public bool useRootMotion = true;
|
||||
|
||||
public float noRootWalkMovementSpeed;
|
||||
public float noRootRunMovementSpeed;
|
||||
public float noRootSprintMovementSpeed;
|
||||
public float noRootCrouchMovementSpeed;
|
||||
public float noRootCrouchRunMovementSpeed = 4;
|
||||
public float noRootWalkStrafeMovementSpeed;
|
||||
public float noRootRunStrafeMovementSpeed;
|
||||
|
||||
[Space]
|
||||
[Header ("Camera Settings")]
|
||||
[Space]
|
||||
|
||||
public bool setNewCameraStates;
|
||||
|
||||
public string newCameraStateThirdPerson;
|
||||
public string newCameraStateFirstPerson;
|
||||
|
||||
[Space]
|
||||
[Header ("Combat Settings")]
|
||||
[Space]
|
||||
|
||||
public int combatTypeID;
|
||||
|
||||
public string playerModeName = "Combat";
|
||||
|
||||
[Space]
|
||||
|
||||
public bool moveDamageTriggersToMainParentsEnabled = true;
|
||||
public Transform parentForCombatDamageTriggers;
|
||||
|
||||
[Space]
|
||||
|
||||
public Transform otherPowersShootZoneParent;
|
||||
|
||||
[Space]
|
||||
[Header ("Abilities Settings")]
|
||||
[Space]
|
||||
|
||||
public bool setAbilityBrainAttackEnabledState;
|
||||
public bool abilityBrainAttackEnabledState;
|
||||
|
||||
[Space]
|
||||
|
||||
public bool setCustomAbilitiesList;
|
||||
public List<string> customAbilitiesList = new List<string> ();
|
||||
|
||||
[Space]
|
||||
|
||||
public bool setChangeAbilityAfterTimeEnabledState;
|
||||
public bool changeAbilityAfterTimeEnabledState;
|
||||
|
||||
[Space]
|
||||
|
||||
public bool setAbilityByDefault;
|
||||
public string abilityByDefaultName;
|
||||
|
||||
[Space]
|
||||
[Header ("AI Visibility")]
|
||||
[Space]
|
||||
|
||||
public bool hiddenFromAIAttacks;
|
||||
|
||||
[Space]
|
||||
[Header ("AI Settings")]
|
||||
[Space]
|
||||
|
||||
public bool setAIValues;
|
||||
|
||||
[Space]
|
||||
|
||||
public float minRandomTimeBetweenAttacks;
|
||||
public float maxRandomTimeBetweenAttacks;
|
||||
|
||||
public float minTimeBetweenAttacks;
|
||||
|
||||
[Space]
|
||||
|
||||
public float newMinDistanceToEnemyUsingCloseCombat;
|
||||
public float newMinDistanceToCloseCombat;
|
||||
|
||||
public float raycastPositionOffset = 1;
|
||||
|
||||
[Space]
|
||||
[Header ("Other Settings")]
|
||||
[Space]
|
||||
|
||||
public int customActionCategoryID;
|
||||
public float characterRadius;
|
||||
|
||||
public string customRagdollInfoName;
|
||||
|
||||
public float healthBarOffset;
|
||||
|
||||
[Space]
|
||||
[Header ("Ground Adherence Settings")]
|
||||
[Space]
|
||||
|
||||
public float heightDiffRaycastRadius;
|
||||
|
||||
public float maxStepHeight;
|
||||
|
||||
public float newRayDistance = 0;
|
||||
|
||||
[Space]
|
||||
[Header ("Other Components")]
|
||||
[Space]
|
||||
|
||||
public List<GameObject> characterMeshesList = new List<GameObject> ();
|
||||
public GameObject characterGameObject;
|
||||
|
||||
[Space]
|
||||
[Header ("Debug")]
|
||||
[Space]
|
||||
|
||||
public bool characterControllerActive;
|
||||
|
||||
public float horizontalInput;
|
||||
public float verticalInput;
|
||||
|
||||
public bool playerUsingInput;
|
||||
|
||||
public Vector3 movementInput;
|
||||
|
||||
public float forwardAmount;
|
||||
public float turnAmount;
|
||||
|
||||
public bool onGround;
|
||||
|
||||
public Transform characterTransform;
|
||||
|
||||
public bool extraCollidersInfoInitialized;
|
||||
|
||||
public Vector3 originalCharacterPivotTransformPosition;
|
||||
|
||||
public Transform playerControllerTransform;
|
||||
|
||||
public bool canMove;
|
||||
|
||||
public bool ragdollCurrentlyActive;
|
||||
|
||||
[Space]
|
||||
[Header ("Events Settings")]
|
||||
[Space]
|
||||
|
||||
public bool useEventsOnStateChange;
|
||||
|
||||
[Space]
|
||||
|
||||
public UnityEvent eventOnCharacterControllerActivated;
|
||||
public UnityEvent eventOnCharacterControllerDeactivated;
|
||||
|
||||
public bool useEventToSendCharacterObjectOnStart;
|
||||
public eventParameters.eventToCallWithGameObject eventToSendCharacterObjectOnStart;
|
||||
public eventParameters.eventToCallWithGameObject eventToSendCharacterObjectOnEnd;
|
||||
|
||||
public UnityEvent eventOnInstantiateCustomCharacterObject;
|
||||
|
||||
public virtual void updateCharacterControllerState ()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public virtual void updateCanMoveState (bool state)
|
||||
{
|
||||
canMove = state;
|
||||
}
|
||||
|
||||
public virtual void setRagdollCurrentlyActiveState (bool state)
|
||||
{
|
||||
ragdollCurrentlyActive = state;
|
||||
}
|
||||
|
||||
public virtual void updateCharacterControllerAnimator ()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public virtual void updateMovementInputValues (Vector3 newValues)
|
||||
{
|
||||
movementInput = newValues;
|
||||
}
|
||||
|
||||
public virtual void updateHorizontalVerticalInputValues (Vector2 newValues)
|
||||
{
|
||||
horizontalInput = newValues.x;
|
||||
verticalInput = newValues.y;
|
||||
}
|
||||
|
||||
public virtual void activateJumpAnimatorState ()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public virtual void updateForwardAmountInputValue (float newValue)
|
||||
{
|
||||
forwardAmount = newValue * forwardAmountMultiplier;
|
||||
}
|
||||
|
||||
public virtual void updateTurnAmountInputValue (float newValue)
|
||||
{
|
||||
turnAmount = newValue;
|
||||
}
|
||||
|
||||
public virtual void updateOnGroundValue (bool state)
|
||||
{
|
||||
onGround = state;
|
||||
}
|
||||
|
||||
public virtual void updatePlayerUsingInputValue (bool state)
|
||||
{
|
||||
playerUsingInput = state;
|
||||
}
|
||||
|
||||
public virtual void setForwardAmountMultiplierValue (float newValue)
|
||||
{
|
||||
forwardAmountMultiplier = newValue;
|
||||
}
|
||||
|
||||
public virtual void resetAnimatorState ()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public virtual void setCharacterControllerActiveState (bool state)
|
||||
{
|
||||
if (!characterControllerEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
characterControllerActive = state;
|
||||
|
||||
checkEventsOnStateChange (characterControllerActive);
|
||||
|
||||
enableOrDisableCharacterMeshesList (state);
|
||||
}
|
||||
|
||||
public virtual void enableOrDisableCharacterMeshesList (bool state)
|
||||
{
|
||||
for (int i = 0; i < characterMeshesList.Count; i++) {
|
||||
if (characterMeshesList [i] != null) {
|
||||
if (characterMeshesList [i].activeSelf != state) {
|
||||
characterMeshesList [i].SetActive (state);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void setOriginalCharacterGameObjectTransformPosition (Vector3 newValue)
|
||||
{
|
||||
originalCharacterPivotTransformPosition = newValue;
|
||||
}
|
||||
|
||||
public virtual void setPlayerControllerTransform (Transform newTransform)
|
||||
{
|
||||
playerControllerTransform = newTransform;
|
||||
}
|
||||
|
||||
public virtual void setCharacterTransform (Transform newTransform)
|
||||
{
|
||||
characterTransform = newTransform;
|
||||
}
|
||||
|
||||
public void checkEventsOnStateChange (bool state)
|
||||
{
|
||||
if (useEventsOnStateChange) {
|
||||
if (state) {
|
||||
eventOnCharacterControllerActivated.Invoke ();
|
||||
} else {
|
||||
eventOnCharacterControllerDeactivated.Invoke ();
|
||||
}
|
||||
}
|
||||
|
||||
if (useEventToSendCharacterObjectOnStart) {
|
||||
if (state) {
|
||||
eventToSendCharacterObjectOnStart.Invoke (characterGameObject);
|
||||
} else {
|
||||
eventToSendCharacterObjectOnEnd.Invoke (characterGameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void updateAnimatorFloatValue (int animatorIDValue, float floatValue)
|
||||
{
|
||||
mainAnimator.SetFloat (animatorIDValue, floatValue);
|
||||
}
|
||||
|
||||
public void updateAnimatorIntegerValue (int animatorIDValue, int intValue)
|
||||
{
|
||||
mainAnimator.SetInteger (animatorIDValue, intValue);
|
||||
}
|
||||
|
||||
public void updateAnimatorBoolValue (int animatorIDValue, bool boolValue)
|
||||
{
|
||||
mainAnimator.SetBool (animatorIDValue, boolValue);
|
||||
}
|
||||
|
||||
public void updateAnimatorFloatValueLerping (int animatorIDValue, float floatValue, float animatorLerpSpeed, float currentFixedUpdateDeltaTime)
|
||||
{
|
||||
mainAnimator.SetFloat (animatorIDValue, floatValue, animatorLerpSpeed, currentFixedUpdateDeltaTime);
|
||||
}
|
||||
|
||||
//Collider Settings
|
||||
public void setCapsuleColliderDirectionValue (float newValue)
|
||||
{
|
||||
capsuleColliderDirection = (int)newValue;
|
||||
}
|
||||
|
||||
public void setCapsuleColliderCenterValue (Vector3 newValue)
|
||||
{
|
||||
capsuleColliderCenter = newValue;
|
||||
}
|
||||
|
||||
public void setCapsuleColliderRadiusValue (float newValue)
|
||||
{
|
||||
capsuleColliderRadius = newValue;
|
||||
}
|
||||
|
||||
public void setCapsuleColliderHeightValue (float newValue)
|
||||
{
|
||||
capsuleColliderHeight = newValue;
|
||||
}
|
||||
|
||||
public void setPlaceToShootOffsetValue (float newValue)
|
||||
{
|
||||
placeToShootOffset = newValue;
|
||||
}
|
||||
|
||||
//Animator Settings
|
||||
public void setCharactetPositionOffsetValue (Vector3 newValue)
|
||||
{
|
||||
charactetPositionOffset = newValue;
|
||||
}
|
||||
|
||||
public void setCharacterRotationOffsetValue (Vector3 newValue)
|
||||
{
|
||||
characterRotationOffset = newValue;
|
||||
}
|
||||
|
||||
//Root Motion Settings
|
||||
public void setUseRootMotionValue (bool state)
|
||||
{
|
||||
useRootMotion = state;
|
||||
}
|
||||
|
||||
public void setNoRootWalkMovementSpeedValue (float newValue)
|
||||
{
|
||||
noRootWalkMovementSpeed = newValue;
|
||||
}
|
||||
|
||||
public void setNoRootRunMovementSpeedValue (float newValue)
|
||||
{
|
||||
noRootRunMovementSpeed = newValue;
|
||||
}
|
||||
|
||||
public void setNoRootSprintMovementSpeedValue (float newValue)
|
||||
{
|
||||
noRootSprintMovementSpeed = newValue;
|
||||
}
|
||||
|
||||
public void setNoRootCrouchMovementSpeedValue (float newValue)
|
||||
{
|
||||
noRootCrouchMovementSpeed = newValue;
|
||||
}
|
||||
|
||||
public void setNoRootWalkStrafeMovementSpeedValue (float newValue)
|
||||
{
|
||||
noRootWalkStrafeMovementSpeed = newValue;
|
||||
}
|
||||
|
||||
public void setNoRootRunStrafeMovementSpeedValue (float newValue)
|
||||
{
|
||||
noRootRunStrafeMovementSpeed = newValue;
|
||||
}
|
||||
|
||||
//Camera Settings
|
||||
public void setSetNewCameraStatesValue (bool state)
|
||||
{
|
||||
setNewCameraStates = state;
|
||||
}
|
||||
|
||||
public void setNewCameraStateThirdPersonValue (string newValue)
|
||||
{
|
||||
newCameraStateThirdPerson = newValue;
|
||||
}
|
||||
|
||||
public void setNewCameraStateFirstPersonValue (string newValue)
|
||||
{
|
||||
newCameraStateFirstPerson = newValue;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//Other Settings
|
||||
public void setCustomActionCategoryIDValue (float newValue)
|
||||
{
|
||||
customActionCategoryID = (int)newValue;
|
||||
}
|
||||
|
||||
public void setCharacterRadiusValue (float newValue)
|
||||
{
|
||||
characterRadius = newValue;
|
||||
}
|
||||
|
||||
public void setCombatTypeIDValue (float newValue)
|
||||
{
|
||||
combatTypeID = (int)newValue;
|
||||
}
|
||||
|
||||
public void setCustomRagdollInfoNameValue (string newValue)
|
||||
{
|
||||
customRagdollInfoName = newValue;
|
||||
}
|
||||
|
||||
public void setPlayerModeNameValue (string newValue)
|
||||
{
|
||||
playerModeName = newValue;
|
||||
}
|
||||
|
||||
public void setHealthBarOffsetValue (float newValue)
|
||||
{
|
||||
healthBarOffset = newValue;
|
||||
}
|
||||
|
||||
//AI Visibility
|
||||
public void setHiddenFromAIAttacksValue (bool state)
|
||||
{
|
||||
hiddenFromAIAttacks = state;
|
||||
}
|
||||
|
||||
|
||||
//AI Settings
|
||||
public void setSetAIValuesValue (bool state)
|
||||
{
|
||||
setAIValues = state;
|
||||
}
|
||||
|
||||
public void setMaxRandomTimeBetweenAttacksValue (float newValue)
|
||||
{
|
||||
maxRandomTimeBetweenAttacks = newValue;
|
||||
}
|
||||
|
||||
public void setMinRandomTimeBetweenAttacksValue (float newValue)
|
||||
{
|
||||
minRandomTimeBetweenAttacks = newValue;
|
||||
}
|
||||
|
||||
public void setNewMinDistanceToEnemyUsingCloseCombatValue (float newValue)
|
||||
{
|
||||
newMinDistanceToEnemyUsingCloseCombat = newValue;
|
||||
}
|
||||
|
||||
public void setNewMinDistanceToCloseCombatValue (float newValue)
|
||||
{
|
||||
newMinDistanceToCloseCombat = newValue;
|
||||
}
|
||||
|
||||
public void setRaycastPositionOffsetValue (float newValue)
|
||||
{
|
||||
raycastPositionOffset = newValue;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4eec8819e94bd5249aaf8286a52d11d6
|
||||
timeCreated: 1629077631
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 40995
|
||||
packageName: Game Kit Controller - Shooter Melee Adventure Creator 3D + 2.5D
|
||||
packageVersion: 3.77g
|
||||
assetPath: Assets/Game Kit Controller/Scripts/Player/Generic Model Controller/customCharacterControllerBase.cs
|
||||
uploadId: 814740
|
||||
@@ -0,0 +1,107 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class customCharacterControllerBaseBuilder : MonoBehaviour
|
||||
{
|
||||
public List<buildPlayer.settingsInfoCategory> settingsInfoCategoryList = new List<buildPlayer.settingsInfoCategory> ();
|
||||
|
||||
public customCharacterControllerBase mainCustomCharacterControllerBase;
|
||||
|
||||
buildPlayer.settingsInfo currentSettingsInfo;
|
||||
buildPlayer.settingsInfoCategory currentSettingsInfoCategory;
|
||||
|
||||
public void adjustSettingsFromEditor ()
|
||||
{
|
||||
adjustSettings ();
|
||||
}
|
||||
|
||||
public void adjustSettings ()
|
||||
{
|
||||
for (int i = 0; i < settingsInfoCategoryList.Count; i++) {
|
||||
|
||||
currentSettingsInfoCategory = settingsInfoCategoryList [i];
|
||||
|
||||
adjustSettingsFromList (currentSettingsInfoCategory.settingsInfoList);
|
||||
}
|
||||
|
||||
GKC_Utils.updateComponent (mainCustomCharacterControllerBase);
|
||||
}
|
||||
|
||||
public void adjustSettingsFromList (List<buildPlayer.settingsInfo> settingsList)
|
||||
{
|
||||
print ("\n\n");
|
||||
|
||||
print ("Setting list applied to character: \n\n");
|
||||
|
||||
for (int j = 0; j < settingsList.Count; j++) {
|
||||
|
||||
currentSettingsInfo = settingsList [j];
|
||||
|
||||
if (currentSettingsInfo.settingEnabled) {
|
||||
|
||||
if (currentSettingsInfo.useBoolState) {
|
||||
currentSettingsInfo.eventToSetBoolState.Invoke (currentSettingsInfo.boolState);
|
||||
|
||||
if (currentSettingsInfo.eventToSetBoolState.GetPersistentEventCount () > 0) {
|
||||
GKC_Utils.updateComponent (currentSettingsInfo.eventToSetBoolState.GetPersistentTarget (0));
|
||||
}
|
||||
|
||||
print ("Setting " + currentSettingsInfo.Name + " set as " + currentSettingsInfo.useBoolState);
|
||||
}
|
||||
|
||||
if (currentSettingsInfo.useFloatValue) {
|
||||
currentSettingsInfo.eventToSetFloatValue.Invoke (currentSettingsInfo.floatValue);
|
||||
|
||||
if (currentSettingsInfo.eventToSetFloatValue.GetPersistentEventCount () > 0) {
|
||||
GKC_Utils.updateComponent (currentSettingsInfo.eventToSetFloatValue.GetPersistentTarget (0));
|
||||
}
|
||||
|
||||
print ("Setting " + currentSettingsInfo.Name + " set as " + currentSettingsInfo.floatValue);
|
||||
}
|
||||
|
||||
if (currentSettingsInfo.useStringValue) {
|
||||
currentSettingsInfo.eventToSetStringValue.Invoke (currentSettingsInfo.stringValue);
|
||||
|
||||
if (currentSettingsInfo.eventToSetStringValue.GetPersistentEventCount () > 0) {
|
||||
GKC_Utils.updateComponent (currentSettingsInfo.eventToSetStringValue.GetPersistentTarget (0));
|
||||
}
|
||||
|
||||
print ("Setting " + currentSettingsInfo.Name + " set as " + currentSettingsInfo.stringValue);
|
||||
}
|
||||
|
||||
if (currentSettingsInfo.useVector3Value) {
|
||||
currentSettingsInfo.eventToSetVector3Value.Invoke (currentSettingsInfo.vector3Value);
|
||||
|
||||
if (currentSettingsInfo.eventToSetVector3Value.GetPersistentEventCount () > 0) {
|
||||
GKC_Utils.updateComponent (currentSettingsInfo.eventToSetVector3Value.GetPersistentTarget (0));
|
||||
}
|
||||
|
||||
print ("Setting " + currentSettingsInfo.Name + " set as " + currentSettingsInfo.vector3Value);
|
||||
}
|
||||
|
||||
if (currentSettingsInfo.useRegularValue) {
|
||||
if (currentSettingsInfo.regularValue) {
|
||||
currentSettingsInfo.eventToEnableActiveValue.Invoke ();
|
||||
|
||||
if (currentSettingsInfo.eventToEnableActiveValue.GetPersistentEventCount () > 0) {
|
||||
GKC_Utils.updateComponent (currentSettingsInfo.eventToEnableActiveValue.GetPersistentTarget (0));
|
||||
}
|
||||
} else {
|
||||
currentSettingsInfo.eventToDisableActiveValue.Invoke ();
|
||||
|
||||
if (currentSettingsInfo.eventToDisableActiveValue.GetPersistentEventCount () > 0) {
|
||||
GKC_Utils.updateComponent (currentSettingsInfo.eventToDisableActiveValue.GetPersistentTarget (0));
|
||||
}
|
||||
}
|
||||
|
||||
print ("Setting " + currentSettingsInfo.Name + " set as " + currentSettingsInfo.regularValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
print ("Character Settings Applied\n\n\n");
|
||||
|
||||
GKC_Utils.updateDirtyScene ("Updated Settings", gameObject);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c613971cae792154dae1427b1f88eb10
|
||||
timeCreated: 1653800505
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 40995
|
||||
packageName: Game Kit Controller - Shooter Melee Adventure Creator 3D + 2.5D
|
||||
packageVersion: 3.77g
|
||||
assetPath: Assets/Game Kit Controller/Scripts/Player/Generic Model Controller/customCharacterControllerBaseBuilder.cs
|
||||
uploadId: 814740
|
||||
@@ -0,0 +1,888 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
|
||||
public class customCharacterControllerManager : MonoBehaviour
|
||||
{
|
||||
[Header ("Main Settings")]
|
||||
[Space]
|
||||
|
||||
public bool startGameWithCustomCharacterController;
|
||||
public string customCharacterControllerToStartName;
|
||||
|
||||
[Space]
|
||||
|
||||
public bool enableNewCustomCharacterIfActiveWhenTogglingToNewOne;
|
||||
|
||||
[Space]
|
||||
[Header ("Other Settings")]
|
||||
[Space]
|
||||
|
||||
public bool ignoreSetAIValues;
|
||||
|
||||
public bool setCharacterModeOnRegularState;
|
||||
|
||||
public bool setNewCharacterModeOnRegularState;
|
||||
public string newCharacterModeOnRegularState;
|
||||
|
||||
[Space]
|
||||
[Header ("Character Controller List Settings")]
|
||||
[Space]
|
||||
|
||||
public List<characterControllerStateInfo> characterControllerStateInfoList = new List<characterControllerStateInfo> ();
|
||||
|
||||
[Space]
|
||||
[Header ("Debug")]
|
||||
[Space]
|
||||
|
||||
public bool showDebugPrint;
|
||||
public bool customCharacterControllerActive;
|
||||
|
||||
public string currentCharacterControllerName;
|
||||
|
||||
public bool toggleCustomCharacterControllerPaused;
|
||||
|
||||
public bool genericModelVisibleOnEditor;
|
||||
|
||||
public Avatar originalAvatar;
|
||||
|
||||
public customCharacterControllerBase currentCustomCharacterControllerBase;
|
||||
|
||||
[Space]
|
||||
[Header ("Events Settings")]
|
||||
[Space]
|
||||
|
||||
public bool useEventsOnStateChange;
|
||||
|
||||
public UnityEvent eventOnCustomCharacterEnter;
|
||||
public UnityEvent eventOnCustomCharacterExit;
|
||||
|
||||
[Space]
|
||||
[Header ("Components")]
|
||||
[Space]
|
||||
|
||||
public playerController mainPlayerController;
|
||||
|
||||
public playerCamera mainPlayerCamera;
|
||||
|
||||
public Animator mainAnimator;
|
||||
|
||||
public RuntimeAnimatorController originalAnimatorController;
|
||||
|
||||
public playerWeaponsManager mainPlayerWeaponManager;
|
||||
|
||||
public playerStatesManager mainPlayerStatesManager;
|
||||
|
||||
public Transform customCharacterControllerParent;
|
||||
|
||||
public CapsuleCollider mainCapsuleCollider;
|
||||
|
||||
public ragdollActivator mainRagdollActivator;
|
||||
public closeCombatSystem mainCloseCombatSystem;
|
||||
|
||||
public otherPowers mainOtherPowersSystem;
|
||||
|
||||
public healthManagement mainHealth;
|
||||
|
||||
public grabObjects mainGrabObjects;
|
||||
|
||||
public AIAbilitiesSystemBrain mainAIAbilitiesSystemBrain;
|
||||
|
||||
[Space]
|
||||
[Header ("AI Components")]
|
||||
[Space]
|
||||
|
||||
public findObjectivesSystem mainFindObjectivesSystem;
|
||||
public AICloseCombatSystemBrain mainAICloseCombatSystemBrain;
|
||||
|
||||
[Space]
|
||||
[Header ("Custom Character Prefab Settings")]
|
||||
[Space]
|
||||
|
||||
public GameObject customCharacterPrefab;
|
||||
|
||||
|
||||
characterControllerStateInfo currentCharacterControllerStateInfo;
|
||||
|
||||
string originalCameraStateThirdPerson;
|
||||
string originalCameraStateFirstPerson;
|
||||
|
||||
string previousCharacterModeName = "";
|
||||
|
||||
|
||||
void Start ()
|
||||
{
|
||||
if (originalAvatar == null) {
|
||||
originalAvatar = mainAnimator.avatar;
|
||||
}
|
||||
|
||||
if (startGameWithCustomCharacterController) {
|
||||
StartCoroutine (startGameWithCustomCharacterControllerCoroutine ());
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator startGameWithCustomCharacterControllerCoroutine ()
|
||||
{
|
||||
yield return new WaitForSeconds (0.2f);
|
||||
|
||||
toggleCustomCharacterController (customCharacterControllerToStartName);
|
||||
}
|
||||
|
||||
public void toggleCustomCharacterControllerExternally (string characterControllerName)
|
||||
{
|
||||
bool previousToggleCustomCharacterControllerPausedValue = toggleCustomCharacterControllerPaused;
|
||||
|
||||
toggleCustomCharacterControllerPaused = false;
|
||||
|
||||
toggleCustomCharacterController (characterControllerName);
|
||||
|
||||
toggleCustomCharacterControllerPaused = previousToggleCustomCharacterControllerPausedValue;
|
||||
}
|
||||
|
||||
public void toggleCustomCharacterController (string characterControllerName)
|
||||
{
|
||||
if (toggleCustomCharacterControllerPaused) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!customCharacterControllerActive) {
|
||||
setCustomCharacterControllerState (characterControllerName);
|
||||
} else {
|
||||
string lastCharacterControllerName = currentCharacterControllerName;
|
||||
|
||||
disableCustomCharacterControllerState ();
|
||||
|
||||
if (enableNewCustomCharacterIfActiveWhenTogglingToNewOne) {
|
||||
if (lastCharacterControllerName != "" && lastCharacterControllerName != characterControllerName) {
|
||||
setCustomCharacterControllerState (characterControllerName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void disableCustomCharacterControllerState ()
|
||||
{
|
||||
if (!customCharacterControllerActive) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (currentCharacterControllerStateInfo != null) {
|
||||
|
||||
currentCharacterControllerStateInfo.isCurrentCharacterController = false;
|
||||
|
||||
currentCharacterControllerStateInfo.eventOnStateEnd.Invoke ();
|
||||
|
||||
if (currentCharacterControllerStateInfo.useEventToSendCharacterObjectOnStateChange) {
|
||||
currentCharacterControllerStateInfo.eventToSendCharacterObjectOnEnd.Invoke (currentCharacterControllerStateInfo.customCharacterController.characterGameObject);
|
||||
}
|
||||
|
||||
setCharacterState (false);
|
||||
|
||||
currentCharacterControllerStateInfo = null;
|
||||
|
||||
currentCharacterControllerName = "";
|
||||
}
|
||||
}
|
||||
|
||||
public void setRandomCustomCharacterControllerState ()
|
||||
{
|
||||
int randomIndex = Random.Range (0, characterControllerStateInfoList.Count - 1);
|
||||
|
||||
if (randomIndex <= characterControllerStateInfoList.Count) {
|
||||
setCustomCharacterControllerState (characterControllerStateInfoList [randomIndex].Name);
|
||||
}
|
||||
}
|
||||
|
||||
public void setCustomCharacterControllerState (string characterControllerStateName)
|
||||
{
|
||||
if (showDebugPrint) {
|
||||
print ("trying to activate " + characterControllerStateName);
|
||||
}
|
||||
|
||||
if (currentCharacterControllerName == characterControllerStateName) {
|
||||
return;
|
||||
}
|
||||
|
||||
int newCharacterIndex = -1;
|
||||
|
||||
for (int i = 0; i < characterControllerStateInfoList.Count; i++) {
|
||||
if (characterControllerStateInfoList [i].stateEnabled && characterControllerStateInfoList [i].Name.Equals (characterControllerStateName)) {
|
||||
newCharacterIndex = i;
|
||||
} else {
|
||||
if (characterControllerStateInfoList [i].isCurrentCharacterController) {
|
||||
// characterControllerStateInfoList [i].customCharacterController.setCharacterControllerActiveState (false);
|
||||
|
||||
currentCharacterControllerStateInfo = characterControllerStateInfoList [i];
|
||||
|
||||
currentCharacterControllerStateInfo.eventOnStateEnd.Invoke ();
|
||||
|
||||
if (currentCharacterControllerStateInfo.useEventToSendCharacterObjectOnStateChange) {
|
||||
currentCharacterControllerStateInfo.eventToSendCharacterObjectOnEnd.Invoke (currentCharacterControllerStateInfo.customCharacterController.characterGameObject);
|
||||
}
|
||||
|
||||
setCharacterState (false);
|
||||
|
||||
if (showDebugPrint) {
|
||||
print ("disabling first the character " + currentCharacterControllerStateInfo.Name);
|
||||
}
|
||||
}
|
||||
|
||||
characterControllerStateInfoList [i].isCurrentCharacterController = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (newCharacterIndex != -1) {
|
||||
|
||||
currentCharacterControllerStateInfo = characterControllerStateInfoList [newCharacterIndex];
|
||||
|
||||
if (showDebugPrint) {
|
||||
print (newCharacterIndex + " " + currentCharacterControllerStateInfo.Name);
|
||||
}
|
||||
|
||||
if (currentCharacterControllerStateInfo.spawnCustomCharacterPrefab) {
|
||||
if (currentCharacterControllerStateInfo.customCharacterInstantiatedObject == null) {
|
||||
instantiateCustomCharacter (currentCharacterControllerStateInfo, false);
|
||||
}
|
||||
}
|
||||
|
||||
currentCharacterControllerStateInfo.isCurrentCharacterController = true;
|
||||
|
||||
currentCharacterControllerName = currentCharacterControllerStateInfo.Name;
|
||||
|
||||
setCharacterState (true);
|
||||
} else {
|
||||
if (showDebugPrint) {
|
||||
print (characterControllerStateName + " not found");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void instantiateCustomCharacter (characterControllerStateInfo characterInfo, bool instantiatedOnEditorTime)
|
||||
{
|
||||
GameObject customCharacterObject = (GameObject)Instantiate (characterInfo.customCharacterPrefab, Vector3.zero, Quaternion.identity, transform);
|
||||
|
||||
customCharacterObject.name = characterInfo.customCharacterPrefab.name;
|
||||
|
||||
characterInfo.customCharacterInstantiatedObject = customCharacterObject;
|
||||
|
||||
characterInfo.customCharacterController = customCharacterObject.GetComponent<customCharacterControllerBase> ();
|
||||
|
||||
customCharacterObject.transform.localPosition = Vector3.zero;
|
||||
customCharacterObject.transform.localRotation = Quaternion.identity;
|
||||
|
||||
characterInfo.customCharacterController.eventOnInstantiateCustomCharacterObject.Invoke ();
|
||||
|
||||
characterInfo.customCharacterController.mainAnimator = mainAnimator;
|
||||
|
||||
genericRagdollBuilder currentGenericRagdollBuilder = customCharacterObject.GetComponentInChildren<genericRagdollBuilder> ();
|
||||
|
||||
if (currentGenericRagdollBuilder != null) {
|
||||
currentGenericRagdollBuilder.mainRagdollActivator = mainRagdollActivator;
|
||||
|
||||
currentGenericRagdollBuilder.updateRagdollActivatorParts (instantiatedOnEditorTime);
|
||||
}
|
||||
|
||||
followObjectPositionSystem currentFollowObjectPositionSystem = customCharacterObject.GetComponentInChildren<followObjectPositionSystem> ();
|
||||
|
||||
if (currentFollowObjectPositionSystem != null) {
|
||||
currentFollowObjectPositionSystem.setObjectToFollow (mainPlayerController.transform);
|
||||
}
|
||||
|
||||
simpleSliceSystem currentSimpleSliceSystem = customCharacterObject.GetComponentInChildren<simpleSliceSystem> ();
|
||||
|
||||
if (currentSimpleSliceSystem != null) {
|
||||
surfaceToSlice currentSurfaceToSlice = mainPlayerController.GetComponent<surfaceToSlice> ();
|
||||
|
||||
if (currentSurfaceToSlice != null) {
|
||||
currentSurfaceToSlice.mainSimpleSliceSystem = currentSimpleSliceSystem;
|
||||
|
||||
currentSimpleSliceSystem.mainSurfaceToSlice = currentSurfaceToSlice;
|
||||
|
||||
currentSimpleSliceSystem.initializeValuesOnHackableComponent ();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void setCharacterState (bool state)
|
||||
{
|
||||
currentCustomCharacterControllerBase = currentCharacterControllerStateInfo.customCharacterController;
|
||||
|
||||
currentCustomCharacterControllerBase.setCharacterControllerActiveState (state);
|
||||
|
||||
if (ignoreSetAIValues) {
|
||||
currentCustomCharacterControllerBase.setAIValues = false;
|
||||
}
|
||||
|
||||
bool isFirstPersonActive = mainPlayerCamera.isFirstPersonActive ();
|
||||
|
||||
bool isFullBodyAwarenessActive = mainPlayerCamera.isFullBodyAwarenessActive ();
|
||||
|
||||
if (isFirstPersonActive) {
|
||||
mainPlayerCamera.changeCameraToThirdOrFirstView ();
|
||||
} else {
|
||||
if (isFullBodyAwarenessActive) {
|
||||
mainPlayerCamera.changeCameraToThirdOrFirstView ();
|
||||
}
|
||||
}
|
||||
|
||||
if (state) {
|
||||
mainPlayerController.setCustomCharacterControllerActiveState (true, currentCustomCharacterControllerBase);
|
||||
|
||||
currentCustomCharacterControllerBase.characterGameObject.transform.SetParent (customCharacterControllerParent);
|
||||
|
||||
currentCustomCharacterControllerBase.characterGameObject.transform.position = mainPlayerController.transform.position +
|
||||
currentCustomCharacterControllerBase.charactetPositionOffset;
|
||||
|
||||
currentCustomCharacterControllerBase.setOriginalCharacterGameObjectTransformPosition (currentCustomCharacterControllerBase.characterGameObject.transform.localPosition);
|
||||
|
||||
currentCustomCharacterControllerBase.setPlayerControllerTransform (mainPlayerController.transform);
|
||||
|
||||
Quaternion targetRotation = Quaternion.Euler (currentCustomCharacterControllerBase.characterRotationOffset);
|
||||
|
||||
currentCustomCharacterControllerBase.characterGameObject.transform.localRotation = targetRotation;
|
||||
|
||||
Animator characterAnimator = currentCustomCharacterControllerBase.characterGameObject.GetComponent<Animator> ();
|
||||
|
||||
if (characterAnimator != null && characterAnimator.enabled) {
|
||||
characterAnimator.enabled = false;
|
||||
}
|
||||
|
||||
if (previousCharacterModeName == "") {
|
||||
previousCharacterModeName = mainPlayerStatesManager.getCurrentPlayersModeName ();
|
||||
}
|
||||
|
||||
mainPlayerStatesManager.checkPlayerStates ();
|
||||
|
||||
currentCharacterControllerStateInfo.eventOnStateStart.Invoke ();
|
||||
|
||||
if (currentCharacterControllerStateInfo.useEventToSendCharacterObjectOnStateChange) {
|
||||
currentCharacterControllerStateInfo.eventToSendCharacterObjectOnStart.Invoke (currentCharacterControllerStateInfo.customCharacterController.characterGameObject);
|
||||
}
|
||||
|
||||
mainPlayerStatesManager.setPlayerModeByName (currentCustomCharacterControllerBase.playerModeName);
|
||||
|
||||
mainAnimator.runtimeAnimatorController = currentCustomCharacterControllerBase.originalAnimatorController;
|
||||
mainAnimator.avatar = currentCustomCharacterControllerBase.originalAvatar;
|
||||
|
||||
currentCustomCharacterControllerBase.updateOnGroundValue (mainPlayerController.isPlayerOnGround ());
|
||||
|
||||
if (currentCustomCharacterControllerBase.setCapsuleColliderValues) {
|
||||
mainPlayerController.setPlayerColliderCapsuleScale (currentCustomCharacterControllerBase.capsuleColliderHeight);
|
||||
|
||||
mainPlayerController.setPlayerCapsuleColliderDirection (currentCustomCharacterControllerBase.capsuleColliderDirection);
|
||||
|
||||
mainCapsuleCollider.center = currentCustomCharacterControllerBase.capsuleColliderCenter;
|
||||
|
||||
mainPlayerController.setPlayerCapsuleColliderRadius (currentCustomCharacterControllerBase.capsuleColliderRadius);
|
||||
}
|
||||
|
||||
if (currentCustomCharacterControllerBase.useExtraColliders) {
|
||||
if (!currentCustomCharacterControllerBase.extraCollidersInfoInitialized) {
|
||||
int extraCollidersListCount = currentCustomCharacterControllerBase.extraCollidersList.Count;
|
||||
|
||||
health mainCharacterHealth = mainHealth as health;
|
||||
|
||||
int characterLayer = mainPlayerController.gameObject.layer;
|
||||
|
||||
for (int i = 0; i < extraCollidersListCount; i++) {
|
||||
Physics.IgnoreCollision (mainCapsuleCollider, currentCustomCharacterControllerBase.extraCollidersList [i], true);
|
||||
|
||||
if (currentCustomCharacterControllerBase.setLayerOnExtraCollider) {
|
||||
currentCustomCharacterControllerBase.extraCollidersList [i].gameObject.layer = characterLayer;
|
||||
}
|
||||
|
||||
characterDamageReceiver currentDamageReceiverToCheck = currentCustomCharacterControllerBase.extraCollidersList [i].GetComponent<characterDamageReceiver> ();
|
||||
|
||||
if (currentDamageReceiverToCheck != null) {
|
||||
currentDamageReceiverToCheck.setCharacter (mainPlayerController.gameObject, mainCharacterHealth);
|
||||
|
||||
mainCharacterHealth.addDamageReceiverGameObjectList (currentDamageReceiverToCheck.gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
currentCustomCharacterControllerBase.extraCollidersInfoInitialized = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (currentCustomCharacterControllerBase.usePlaceToShootLocalPosition) {
|
||||
mainPlayerController.setPlaceToShootLocalPosition (currentCustomCharacterControllerBase.placeToShootLocalPosition);
|
||||
} else {
|
||||
mainPlayerController.setPlaceToShootPositionOffset (currentCustomCharacterControllerBase.placeToShootOffset);
|
||||
}
|
||||
|
||||
mainPlayerController.setUseRootMotionActiveState (currentCustomCharacterControllerBase.useRootMotion);
|
||||
|
||||
if (!currentCustomCharacterControllerBase.useRootMotion) {
|
||||
mainPlayerController.setNoRootMotionValues (currentCustomCharacterControllerBase.noRootWalkMovementSpeed,
|
||||
currentCustomCharacterControllerBase.noRootRunMovementSpeed, currentCustomCharacterControllerBase.noRootSprintMovementSpeed,
|
||||
currentCustomCharacterControllerBase.noRootCrouchMovementSpeed, currentCustomCharacterControllerBase.noRootCrouchRunMovementSpeed,
|
||||
currentCustomCharacterControllerBase.noRootWalkStrafeMovementSpeed, currentCustomCharacterControllerBase.noRootRunStrafeMovementSpeed);
|
||||
}
|
||||
|
||||
|
||||
mainPlayerController.setCharacterMeshGameObjectState (!state);
|
||||
|
||||
mainPlayerController.setUsingExternalCharacterMeshListState (true);
|
||||
|
||||
mainPlayerController.setExternalCharacterMeshList (currentCustomCharacterControllerBase.characterMeshesList);
|
||||
|
||||
//CAMERA ELEMENTS
|
||||
if (currentCustomCharacterControllerBase.setNewCameraStates && !currentCustomCharacterControllerBase.setAIValues) {
|
||||
originalCameraStateThirdPerson = mainPlayerCamera.getDefaultThirdPersonStateName ();
|
||||
|
||||
originalCameraStateFirstPerson = mainPlayerCamera.getDefaultFirstPersonStateName ();
|
||||
|
||||
if (mainPlayerCamera.isFirstPersonActive ()) {
|
||||
mainPlayerCamera.setCameraStateExternally (currentCustomCharacterControllerBase.newCameraStateFirstPerson);
|
||||
} else {
|
||||
mainPlayerCamera.setCameraStateExternally (currentCustomCharacterControllerBase.newCameraStateThirdPerson);
|
||||
}
|
||||
|
||||
mainPlayerCamera.setDefaultThirdPersonStateName (currentCustomCharacterControllerBase.newCameraStateThirdPerson);
|
||||
|
||||
mainPlayerCamera.setDefaultFirstPersonStateName (currentCustomCharacterControllerBase.newCameraStateFirstPerson);
|
||||
}
|
||||
|
||||
|
||||
//OTHER COMPONENTS FUNCTIONS
|
||||
mainPlayerController.setCurrentCustomActionCategoryID (currentCustomCharacterControllerBase.customActionCategoryID);
|
||||
|
||||
mainPlayerController.setCharacterRadius (currentCustomCharacterControllerBase.characterRadius);
|
||||
|
||||
mainPlayerController.setExtraHeightDiffRaycastRadius (currentCustomCharacterControllerBase.heightDiffRaycastRadius);
|
||||
|
||||
mainPlayerController.setCustomMaxStepHeight (currentCustomCharacterControllerBase.maxStepHeight);
|
||||
|
||||
if (currentCustomCharacterControllerBase.newRayDistance > 0) {
|
||||
mainPlayerController.setNewRayDistance (currentCustomCharacterControllerBase.newRayDistance);
|
||||
}
|
||||
|
||||
mainCloseCombatSystem.setCombatTypeID (currentCustomCharacterControllerBase.combatTypeID);
|
||||
|
||||
if (currentCustomCharacterControllerBase.moveDamageTriggersToMainParentsEnabled) {
|
||||
mainCloseCombatSystem.setNewParentForDamageTriggers (currentCustomCharacterControllerBase.parentForCombatDamageTriggers);
|
||||
}
|
||||
|
||||
mainRagdollActivator.setCurrentRagdollInfo (currentCustomCharacterControllerBase.customRagdollInfoName);
|
||||
|
||||
if (mainOtherPowersSystem != null && currentCustomCharacterControllerBase.otherPowersShootZoneParent != null) {
|
||||
if (state) {
|
||||
mainOtherPowersSystem.setCustomShootZoneParentActiveState (true, currentCustomCharacterControllerBase.otherPowersShootZoneParent);
|
||||
} else {
|
||||
mainOtherPowersSystem.setCustomShootZoneParentActiveState (false, null);
|
||||
}
|
||||
}
|
||||
|
||||
//AI COMPONENTS
|
||||
if (currentCustomCharacterControllerBase.setAIValues) {
|
||||
mainAICloseCombatSystemBrain.setMaxRandomTimeBetweenAttacks (currentCustomCharacterControllerBase.maxRandomTimeBetweenAttacks);
|
||||
mainAICloseCombatSystemBrain.setMinRandomTimeBetweenAttacks (currentCustomCharacterControllerBase.minRandomTimeBetweenAttacks);
|
||||
|
||||
if (currentCustomCharacterControllerBase.minTimeBetweenAttacks > 0) {
|
||||
mainAICloseCombatSystemBrain.setMinTimeBetweenAttacks (currentCustomCharacterControllerBase.minTimeBetweenAttacks);
|
||||
}
|
||||
|
||||
mainAICloseCombatSystemBrain.setBlockEnabledState (false);
|
||||
|
||||
mainFindObjectivesSystem.setNewMinDistanceToEnemyUsingCloseCombat (currentCustomCharacterControllerBase.newMinDistanceToEnemyUsingCloseCombat);
|
||||
|
||||
mainFindObjectivesSystem.setNewMinDistanceToCloseCombat (currentCustomCharacterControllerBase.newMinDistanceToCloseCombat);
|
||||
|
||||
mainFindObjectivesSystem.setCloseCombatAttackMode ();
|
||||
|
||||
mainFindObjectivesSystem.setRayCastPositionOffsetValue (currentCustomCharacterControllerBase.raycastPositionOffset);
|
||||
|
||||
if (currentCustomCharacterControllerBase.healthBarOffset != 0) {
|
||||
mainHealth.updateSliderOffset (currentCustomCharacterControllerBase.healthBarOffset);
|
||||
}
|
||||
}
|
||||
|
||||
if (currentCharacterControllerStateInfo.overrideHiddenFromAIAttacksValue) {
|
||||
mainPlayerController.setStealthModeActiveState (currentCharacterControllerStateInfo.hiddenFromAIAttacksValue);
|
||||
} else {
|
||||
if (currentCustomCharacterControllerBase.hiddenFromAIAttacks) {
|
||||
mainPlayerController.setStealthModeActiveState (true);
|
||||
}
|
||||
}
|
||||
|
||||
currentCustomCharacterControllerBase.setCharacterTransform (mainPlayerController.transform);
|
||||
} else {
|
||||
currentCustomCharacterControllerBase.updateOnGroundValue (mainPlayerController.isPlayerOnGround ());
|
||||
|
||||
mainAnimator.runtimeAnimatorController = originalAnimatorController;
|
||||
mainAnimator.avatar = originalAvatar;
|
||||
|
||||
mainPlayerController.setCustomCharacterControllerActiveState (false, null);
|
||||
|
||||
currentCustomCharacterControllerBase.characterGameObject.transform.SetParent (null);
|
||||
|
||||
mainPlayerController.setOriginalPlayerColliderCapsuleScale ();
|
||||
|
||||
if (currentCustomCharacterControllerBase.setCapsuleColliderValues) {
|
||||
mainPlayerController.setPlayerCapsuleColliderDirection (1);
|
||||
|
||||
mainPlayerController.setOriginalPlayerCapsuleColliderRadius ();
|
||||
}
|
||||
|
||||
mainPlayerController.setPlaceToShootPositionOffset (-1);
|
||||
|
||||
mainPlayerController.setOriginalUseRootMotionActiveState ();
|
||||
|
||||
mainPlayerController.setOriginalNoRootMotionValues ();
|
||||
|
||||
mainPlayerController.setUsingExternalCharacterMeshListState (false);
|
||||
|
||||
mainPlayerController.setExternalCharacterMeshList (null);
|
||||
|
||||
if (isFirstPersonActive) {
|
||||
currentCustomCharacterControllerBase.enableOrDisableCharacterMeshesList (false);
|
||||
}
|
||||
|
||||
mainPlayerController.setCharacterMeshGameObjectState (!state);
|
||||
|
||||
|
||||
//CAMERA ELEMENTS
|
||||
if (currentCustomCharacterControllerBase.setNewCameraStates && !currentCustomCharacterControllerBase.setAIValues) {
|
||||
if (mainPlayerCamera.isFirstPersonActive ()) {
|
||||
mainPlayerCamera.setCameraStateExternally (originalCameraStateFirstPerson);
|
||||
} else {
|
||||
mainPlayerCamera.setCameraStateExternally (originalCameraStateThirdPerson);
|
||||
}
|
||||
|
||||
mainPlayerCamera.setDefaultThirdPersonStateName (originalCameraStateThirdPerson);
|
||||
|
||||
mainPlayerCamera.setDefaultFirstPersonStateName (originalCameraStateFirstPerson);
|
||||
}
|
||||
|
||||
|
||||
//OTHER COMPONENTS FUNCTIONS
|
||||
mainPlayerController.setCurrentCustomActionCategoryID (0);
|
||||
|
||||
mainPlayerController.setCharacterRadius (0);
|
||||
|
||||
mainPlayerController.setExtraHeightDiffRaycastRadius (0);
|
||||
|
||||
mainPlayerController.setCustomMaxStepHeight (0);
|
||||
|
||||
if (currentCustomCharacterControllerBase.newRayDistance > 0) {
|
||||
mainPlayerController.setOriginalRayDistance ();
|
||||
}
|
||||
|
||||
mainCloseCombatSystem.setCombatTypeID (0);
|
||||
|
||||
if (currentCustomCharacterControllerBase.moveDamageTriggersToMainParentsEnabled) {
|
||||
mainCloseCombatSystem.setOriginalParentForDamageTriggers ();
|
||||
}
|
||||
|
||||
mainRagdollActivator.setCurrentRagdollInfo ("");
|
||||
|
||||
|
||||
//AI COMPONENTS
|
||||
if (currentCustomCharacterControllerBase.setAIValues) {
|
||||
mainAICloseCombatSystemBrain.setOriginalMaxRandomTimeBetweenAttacks ();
|
||||
|
||||
mainAICloseCombatSystemBrain.setOriginalMinRandomTimeBetweenAttacks ();
|
||||
|
||||
mainAICloseCombatSystemBrain.setBlockEnabledState (true);
|
||||
|
||||
mainAICloseCombatSystemBrain.setOriginalMinTimeBetweenAttacks ();
|
||||
|
||||
mainFindObjectivesSystem.setOriginalRayCastPositionOffsetValue ();
|
||||
|
||||
if (currentCustomCharacterControllerBase.healthBarOffset != 0) {
|
||||
mainHealth.updateOriginalSliderOffset ();
|
||||
}
|
||||
}
|
||||
|
||||
if (currentCustomCharacterControllerBase.hiddenFromAIAttacks || currentCharacterControllerStateInfo.overrideHiddenFromAIAttacksValue) {
|
||||
mainPlayerController.setStealthModeActiveState (false);
|
||||
}
|
||||
|
||||
currentCustomCharacterControllerBase.setCharacterTransform (null);
|
||||
}
|
||||
|
||||
mainRagdollActivator.setPauseAnimatorStatesToGetUpState (state);
|
||||
|
||||
mainPlayerWeaponManager.enableOrDisableWeaponsMesh (!state);
|
||||
|
||||
mainPlayerController.setCharacterMeshesListToDisableOnEventState (!state);
|
||||
|
||||
mainPlayerController.enableOrDisableIKSystemManagerState (!state);
|
||||
|
||||
mainPlayerController.setFootStepManagerState (state);
|
||||
|
||||
customCharacterControllerActive = state;
|
||||
|
||||
mainPlayerController.setUsingGenericModelActiveState (state);
|
||||
|
||||
mainPlayerCamera.setUsingGenericModelActiveState (state);
|
||||
|
||||
checkEventsOnStateChange (customCharacterControllerActive);
|
||||
|
||||
mainHealth.setIgnoreWeakSpotsActiveState (state);
|
||||
|
||||
if (currentCustomCharacterControllerBase.useExtraColliders) {
|
||||
int extraCollidersListCount = currentCustomCharacterControllerBase.extraCollidersList.Count;
|
||||
|
||||
for (int i = 0; i < extraCollidersListCount; i++) {
|
||||
mainCloseCombatSystem.addOrRemoveObjectToIgnoreByHitTriggers (
|
||||
currentCustomCharacterControllerBase.extraCollidersList [i].gameObject, state);
|
||||
}
|
||||
}
|
||||
|
||||
if (!state) {
|
||||
if (setCharacterModeOnRegularState) {
|
||||
if (previousCharacterModeName != "") {
|
||||
if (setNewCharacterModeOnRegularState) {
|
||||
if (!mainPlayerStatesManager.getCurrentPlayersModeName ().Equals (newCharacterModeOnRegularState)) {
|
||||
mainPlayerStatesManager.setPlayerModeByName (newCharacterModeOnRegularState);
|
||||
}
|
||||
} else {
|
||||
if (!mainPlayerStatesManager.getCurrentPlayersModeName ().Equals (previousCharacterModeName)) {
|
||||
mainPlayerStatesManager.setPlayerModeByName (previousCharacterModeName);
|
||||
}
|
||||
}
|
||||
|
||||
previousCharacterModeName = "";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isFirstPersonActive) {
|
||||
mainPlayerCamera.changeCameraToThirdOrFirstView ();
|
||||
} else {
|
||||
if (isFullBodyAwarenessActive) {
|
||||
mainPlayerCamera.changeCameraToThirdOrFirstView ();
|
||||
}
|
||||
}
|
||||
|
||||
mainPlayerCamera.setHeadColliderStateOnFBA (!state);
|
||||
|
||||
grabObjectGenericModeMountPointSystem currentGrabObjectGenericModeMountPointSystem =
|
||||
currentCustomCharacterControllerBase.GetComponent<grabObjectGenericModeMountPointSystem> ();
|
||||
|
||||
if (currentGrabObjectGenericModeMountPointSystem != null) {
|
||||
if (mainGrabObjects != null) {
|
||||
if (state) {
|
||||
mainGrabObjects.setCurrentGrabObjectGenericModeMountPointSystem (currentGrabObjectGenericModeMountPointSystem);
|
||||
} else {
|
||||
mainGrabObjects.setCurrentGrabObjectGenericModeMountPointSystem (null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (currentCustomCharacterControllerBase.useExtraColliders) {
|
||||
int extraCollidersListCount = currentCustomCharacterControllerBase.extraCollidersList.Count;
|
||||
|
||||
int characterLayer = mainPlayerController.getCharacterLayer ();
|
||||
|
||||
for (int i = 0; i < extraCollidersListCount; i++) {
|
||||
mainPlayerController.addOrRemoveExtraColliders (currentCustomCharacterControllerBase.extraCollidersList [i], state);
|
||||
|
||||
currentCustomCharacterControllerBase.extraCollidersList [i].gameObject.layer = characterLayer;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (mainAIAbilitiesSystemBrain != null) {
|
||||
if (state) {
|
||||
if (currentCustomCharacterControllerBase.setAbilityBrainAttackEnabledState) {
|
||||
mainAIAbilitiesSystemBrain.setAttackEnabledState (currentCustomCharacterControllerBase.abilityBrainAttackEnabledState);
|
||||
}
|
||||
|
||||
if (currentCustomCharacterControllerBase.setCustomAbilitiesList) {
|
||||
mainAIAbilitiesSystemBrain.setUseCustomListToChangeAbilityState (true);
|
||||
|
||||
mainAIAbilitiesSystemBrain.setCustomListToChangeAbility (currentCustomCharacterControllerBase.customAbilitiesList);
|
||||
}
|
||||
|
||||
if (currentCustomCharacterControllerBase.setChangeAbilityAfterTimeEnabledState) {
|
||||
mainAIAbilitiesSystemBrain.setChangeAbilityAfterTimeEnabledState (currentCustomCharacterControllerBase.changeAbilityAfterTimeEnabledState);
|
||||
}
|
||||
|
||||
if (currentCustomCharacterControllerBase.setAbilityByDefault) {
|
||||
mainAIAbilitiesSystemBrain.setNewAbilityByName (currentCustomCharacterControllerBase.abilityByDefaultName);
|
||||
}
|
||||
} else {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if (currentCustomCharacterControllerBase.setAIValues) {
|
||||
mainFindObjectivesSystem.getAINavMesh ().updateUseExtraColliderListState ();
|
||||
}
|
||||
}
|
||||
|
||||
public bool isCustomCharacterControllerActive ()
|
||||
{
|
||||
return customCharacterControllerActive;
|
||||
}
|
||||
|
||||
public void checkEventsOnStateChange (bool state)
|
||||
{
|
||||
if (useEventsOnStateChange) {
|
||||
if (state) {
|
||||
eventOnCustomCharacterEnter.Invoke ();
|
||||
} else {
|
||||
eventOnCustomCharacterExit.Invoke ();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setToggleCustomCharacterControllerPausedState (bool state)
|
||||
{
|
||||
toggleCustomCharacterControllerPaused = state;
|
||||
}
|
||||
|
||||
public void addNewCustomCharacterController (customCharacterControllerBase newCustomCharacterControllerBase, string newName)
|
||||
{
|
||||
characterControllerStateInfo newCharacterControllerStateInfo = new characterControllerStateInfo ();
|
||||
|
||||
newCharacterControllerStateInfo.Name = newName;
|
||||
|
||||
newCharacterControllerStateInfo.customCharacterController = newCustomCharacterControllerBase;
|
||||
|
||||
characterControllerStateInfoList.Add (newCharacterControllerStateInfo);
|
||||
|
||||
updateComponent ();
|
||||
}
|
||||
|
||||
public void addNewCustomCharacterControllerToSpawn (GameObject newCustomCharacterControllerBaseObject, string newName)
|
||||
{
|
||||
characterControllerStateInfo newCharacterControllerStateInfo = new characterControllerStateInfo ();
|
||||
|
||||
newCharacterControllerStateInfo.Name = newName;
|
||||
|
||||
newCharacterControllerStateInfo.customCharacterPrefab = newCustomCharacterControllerBaseObject;
|
||||
|
||||
newCharacterControllerStateInfo.spawnCustomCharacterPrefab = true;
|
||||
|
||||
characterControllerStateInfoList.Add (newCharacterControllerStateInfo);
|
||||
|
||||
updateComponent ();
|
||||
}
|
||||
|
||||
public void toggleCharacterModelMeshOnEditor (bool state)
|
||||
{
|
||||
if (genericModelVisibleOnEditor == state) {
|
||||
return;
|
||||
}
|
||||
|
||||
genericModelVisibleOnEditor = state;
|
||||
|
||||
if (currentCustomCharacterControllerBase != null && !genericModelVisibleOnEditor) {
|
||||
currentCustomCharacterControllerBase.setCharacterControllerActiveState (genericModelVisibleOnEditor);
|
||||
|
||||
currentCustomCharacterControllerBase = null;
|
||||
}
|
||||
|
||||
int characterIndex = characterControllerStateInfoList.FindIndex (s => s.Name == customCharacterControllerToStartName);
|
||||
|
||||
if (characterIndex > -1) {
|
||||
currentCharacterControllerStateInfo = characterControllerStateInfoList [characterIndex];
|
||||
|
||||
currentCustomCharacterControllerBase = currentCharacterControllerStateInfo.customCharacterController;
|
||||
|
||||
if (currentCustomCharacterControllerBase == null) {
|
||||
instantiateCustomCharacter (currentCharacterControllerStateInfo, true);
|
||||
|
||||
currentCustomCharacterControllerBase = currentCharacterControllerStateInfo.customCharacterController;
|
||||
}
|
||||
|
||||
if (currentCustomCharacterControllerBase != null) {
|
||||
currentCustomCharacterControllerBase.setCharacterControllerActiveState (genericModelVisibleOnEditor);
|
||||
}
|
||||
}
|
||||
|
||||
mainPlayerController.setCharacterMeshGameObjectState (!genericModelVisibleOnEditor);
|
||||
|
||||
mainPlayerWeaponManager.enableOrDisableAllWeaponsMeshes (!genericModelVisibleOnEditor);
|
||||
|
||||
mainPlayerController.setCharacterMeshesListToDisableOnEventState (!genericModelVisibleOnEditor);
|
||||
|
||||
updateComponent ();
|
||||
}
|
||||
|
||||
public void setStartGameWithCustomCharacterControllerFromEditor (bool state)
|
||||
{
|
||||
startGameWithCustomCharacterController = state;
|
||||
|
||||
updateComponent ();
|
||||
}
|
||||
|
||||
public void setCustomCharacterControllerToStartNameFromEditor (string newCharacterName)
|
||||
{
|
||||
customCharacterControllerToStartName = newCharacterName;
|
||||
|
||||
updateComponent ();
|
||||
}
|
||||
|
||||
public void setCapsuleValuesFromMainCharacter ()
|
||||
{
|
||||
if (currentCustomCharacterControllerBase != null) {
|
||||
currentCustomCharacterControllerBase.setCapsuleColliderDirectionValue (mainCapsuleCollider.direction);
|
||||
|
||||
currentCustomCharacterControllerBase.setCapsuleColliderCenterValue (mainCapsuleCollider.center);
|
||||
currentCustomCharacterControllerBase.setCapsuleColliderRadiusValue (mainCapsuleCollider.radius);
|
||||
currentCustomCharacterControllerBase.setCapsuleColliderHeightValue (mainCapsuleCollider.height);
|
||||
}
|
||||
}
|
||||
|
||||
void updateComponent ()
|
||||
{
|
||||
GKC_Utils.updateComponent (this);
|
||||
|
||||
GKC_Utils.updateDirtyScene ("Add New Custom Character Controller", gameObject);
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public class characterControllerStateInfo
|
||||
{
|
||||
[Header ("Main Settings")]
|
||||
[Space]
|
||||
|
||||
public string Name;
|
||||
public bool stateEnabled = true;
|
||||
|
||||
public bool isCurrentCharacterController;
|
||||
|
||||
[Space]
|
||||
[Space]
|
||||
|
||||
public customCharacterControllerBase customCharacterController;
|
||||
|
||||
[Space]
|
||||
|
||||
[Header ("Spawn Character Ingame Settings")]
|
||||
[Space]
|
||||
|
||||
public bool spawnCustomCharacterPrefab;
|
||||
public GameObject customCharacterPrefab;
|
||||
|
||||
[HideInInspector] public GameObject customCharacterInstantiatedObject;
|
||||
|
||||
[Space]
|
||||
[Header ("AI Visibility")]
|
||||
[Space]
|
||||
|
||||
public bool overrideHiddenFromAIAttacksValue;
|
||||
public bool hiddenFromAIAttacksValue;
|
||||
|
||||
[Space]
|
||||
[Space]
|
||||
|
||||
[Header ("Events Settings")]
|
||||
[Space]
|
||||
|
||||
public UnityEvent eventOnStateStart;
|
||||
public UnityEvent eventOnStateEnd;
|
||||
|
||||
public bool useEventToSendCharacterObjectOnStateChange;
|
||||
public eventParameters.eventToCallWithGameObject eventToSendCharacterObjectOnStart;
|
||||
public eventParameters.eventToCallWithGameObject eventToSendCharacterObjectOnEnd;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,703 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
|
||||
public class customCharacterControllerManager : MonoBehaviour
|
||||
{
|
||||
[Header ("Main Settings")]
|
||||
[Space]
|
||||
|
||||
public bool startGameWithCustomCharacterController;
|
||||
public string customCharacterControllerToStartName;
|
||||
|
||||
[Space]
|
||||
[Header ("Other Settings")]
|
||||
[Space]
|
||||
|
||||
public bool ignoreSetAIValues;
|
||||
|
||||
public bool setCharacterModeOnRegularState;
|
||||
|
||||
public bool setNewCharacterModeOnRegularState;
|
||||
public string newCharacterModeOnRegularState;
|
||||
|
||||
[Space]
|
||||
[Header ("Character Controller List Settings")]
|
||||
[Space]
|
||||
|
||||
public List<characterControllerStateInfo> characterControllerStateInfoList = new List<characterControllerStateInfo> ();
|
||||
|
||||
[Space]
|
||||
[Header ("Debug")]
|
||||
[Space]
|
||||
|
||||
public bool showDebugPrint;
|
||||
public bool customCharacterControllerActive;
|
||||
|
||||
public string currentCharacterControllerName;
|
||||
|
||||
public bool toggleCustomCharacterControllerPaused;
|
||||
|
||||
public bool genericModelVisibleOnEditor;
|
||||
|
||||
public Avatar originalAvatar;
|
||||
|
||||
public customCharacterControllerBase currentCustomCharacterControllerBase;
|
||||
|
||||
[Space]
|
||||
[Header ("Events Settings")]
|
||||
[Space]
|
||||
|
||||
public bool useEventsOnStateChange;
|
||||
|
||||
public UnityEvent eventOnCustomCharacterEnter;
|
||||
public UnityEvent eventOnCustomCharacterExit;
|
||||
|
||||
[Space]
|
||||
[Header ("Components")]
|
||||
[Space]
|
||||
|
||||
public playerController mainPlayerController;
|
||||
|
||||
public playerCamera mainPlayerCamera;
|
||||
|
||||
public Animator mainAnimator;
|
||||
|
||||
public RuntimeAnimatorController originalAnimatorController;
|
||||
|
||||
public playerWeaponsManager mainPlayerWeaponManager;
|
||||
|
||||
public playerStatesManager mainPlayerStatesManager;
|
||||
|
||||
public Transform customCharacterControllerParent;
|
||||
|
||||
public CapsuleCollider mainCapsuleCollider;
|
||||
|
||||
public ragdollActivator mainRagdollActivator;
|
||||
public closeCombatSystem mainCloseCombatSystem;
|
||||
|
||||
public healthManagement mainHealth;
|
||||
|
||||
[Space]
|
||||
[Header ("AI Components")]
|
||||
[Space]
|
||||
|
||||
public findObjectivesSystem mainFindObjectivesSystem;
|
||||
public AICloseCombatSystemBrain mainAICloseCombatSystemBrain;
|
||||
|
||||
[Space]
|
||||
[Header ("Custom Character Prefab Settings")]
|
||||
[Space]
|
||||
|
||||
public GameObject customCharacterPrefab;
|
||||
|
||||
|
||||
characterControllerStateInfo currentCharacterControllerStateInfo;
|
||||
|
||||
string originalCameraStateThirdPerson;
|
||||
string originalCameraStateFirstPerson;
|
||||
|
||||
string previousCharacterModeName = "";
|
||||
|
||||
|
||||
void Start ()
|
||||
{
|
||||
if (originalAvatar == null) {
|
||||
originalAvatar = mainAnimator.avatar;
|
||||
}
|
||||
|
||||
if (startGameWithCustomCharacterController) {
|
||||
StartCoroutine (startGameWithCustomCharacterControllerCoroutine ());
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator startGameWithCustomCharacterControllerCoroutine ()
|
||||
{
|
||||
yield return new WaitForSeconds (0.2f);
|
||||
|
||||
toggleCustomCharacterController (customCharacterControllerToStartName);
|
||||
}
|
||||
|
||||
public void toggleCustomCharacterControllerExternally (string characterControllerName)
|
||||
{
|
||||
bool previousToggleCustomCharacterControllerPausedValue = toggleCustomCharacterControllerPaused;
|
||||
|
||||
toggleCustomCharacterControllerPaused = false;
|
||||
|
||||
toggleCustomCharacterController (characterControllerName);
|
||||
|
||||
toggleCustomCharacterControllerPaused = previousToggleCustomCharacterControllerPausedValue;
|
||||
}
|
||||
|
||||
public void toggleCustomCharacterController (string characterControllerName)
|
||||
{
|
||||
if (toggleCustomCharacterControllerPaused) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!customCharacterControllerActive) {
|
||||
setCustomCharacterControllerState (characterControllerName);
|
||||
} else {
|
||||
disableCustomCharacterControllerState ();
|
||||
}
|
||||
}
|
||||
|
||||
public void disableCustomCharacterControllerState ()
|
||||
{
|
||||
if (!customCharacterControllerActive) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (currentCharacterControllerStateInfo != null) {
|
||||
|
||||
currentCharacterControllerStateInfo.isCurrentCharacterController = false;
|
||||
|
||||
currentCharacterControllerStateInfo.eventOnStateEnd.Invoke ();
|
||||
|
||||
if (currentCharacterControllerStateInfo.useEventToSendCharacterObjectOnStateChange) {
|
||||
currentCharacterControllerStateInfo.eventToSendCharacterObjectOnEnd.Invoke (currentCharacterControllerStateInfo.customCharacterController.characterGameObject);
|
||||
}
|
||||
|
||||
setCharacterState (false);
|
||||
|
||||
currentCharacterControllerStateInfo = null;
|
||||
|
||||
currentCharacterControllerName = "";
|
||||
}
|
||||
}
|
||||
|
||||
public void setRandomCustomCharacterControllerState ()
|
||||
{
|
||||
int randomIndex = Random.Range (0, characterControllerStateInfoList.Count - 1);
|
||||
|
||||
if (randomIndex <= characterControllerStateInfoList.Count) {
|
||||
setCustomCharacterControllerState (characterControllerStateInfoList [randomIndex].Name);
|
||||
}
|
||||
}
|
||||
|
||||
public void setCustomCharacterControllerState (string characterControllerStateName)
|
||||
{
|
||||
if (showDebugPrint) {
|
||||
print ("trying to activate " + characterControllerStateName);
|
||||
}
|
||||
|
||||
if (currentCharacterControllerName == characterControllerStateName) {
|
||||
return;
|
||||
}
|
||||
|
||||
int newCharacterIndex = -1;
|
||||
|
||||
for (int i = 0; i < characterControllerStateInfoList.Count; i++) {
|
||||
if (characterControllerStateInfoList [i].stateEnabled && characterControllerStateInfoList [i].Name.Equals (characterControllerStateName)) {
|
||||
newCharacterIndex = i;
|
||||
} else {
|
||||
if (characterControllerStateInfoList [i].isCurrentCharacterController) {
|
||||
// characterControllerStateInfoList [i].customCharacterController.setCharacterControllerActiveState (false);
|
||||
|
||||
currentCharacterControllerStateInfo = characterControllerStateInfoList [i];
|
||||
|
||||
currentCharacterControllerStateInfo.eventOnStateEnd.Invoke ();
|
||||
|
||||
if (currentCharacterControllerStateInfo.useEventToSendCharacterObjectOnStateChange) {
|
||||
currentCharacterControllerStateInfo.eventToSendCharacterObjectOnEnd.Invoke (currentCharacterControllerStateInfo.customCharacterController.characterGameObject);
|
||||
}
|
||||
|
||||
setCharacterState (false);
|
||||
|
||||
if (showDebugPrint) {
|
||||
print ("disabling first the character " + currentCharacterControllerStateInfo.Name);
|
||||
}
|
||||
}
|
||||
|
||||
characterControllerStateInfoList [i].isCurrentCharacterController = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (newCharacterIndex != -1) {
|
||||
|
||||
currentCharacterControllerStateInfo = characterControllerStateInfoList [newCharacterIndex];
|
||||
|
||||
if (showDebugPrint) {
|
||||
print (newCharacterIndex + " " + currentCharacterControllerStateInfo.Name);
|
||||
}
|
||||
|
||||
if (currentCharacterControllerStateInfo.spawnCustomCharacterPrefab) {
|
||||
if (currentCharacterControllerStateInfo.customCharacterInstantiatedObject == null) {
|
||||
instantiateCustomCharacter (currentCharacterControllerStateInfo);
|
||||
}
|
||||
}
|
||||
|
||||
currentCharacterControllerStateInfo.isCurrentCharacterController = true;
|
||||
|
||||
currentCharacterControllerName = currentCharacterControllerStateInfo.Name;
|
||||
|
||||
setCharacterState (true);
|
||||
} else {
|
||||
if (showDebugPrint) {
|
||||
print (characterControllerStateName + " not found");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void instantiateCustomCharacter (characterControllerStateInfo characterInfo)
|
||||
{
|
||||
GameObject customCharacterObject = (GameObject)Instantiate (characterInfo.customCharacterPrefab, Vector3.zero, Quaternion.identity, transform);
|
||||
|
||||
customCharacterObject.name = characterInfo.customCharacterPrefab.name;
|
||||
|
||||
characterInfo.customCharacterInstantiatedObject = customCharacterObject;
|
||||
|
||||
characterInfo.customCharacterController = customCharacterObject.GetComponent<customCharacterControllerBase> ();
|
||||
|
||||
customCharacterObject.transform.localPosition = Vector3.zero;
|
||||
customCharacterObject.transform.localRotation = Quaternion.identity;
|
||||
|
||||
characterInfo.customCharacterController.eventOnInstantiateCustomCharacterObject.Invoke ();
|
||||
|
||||
characterInfo.customCharacterController.mainAnimator = mainAnimator;
|
||||
|
||||
genericRagdollBuilder currentGenericRagdollBuilder = customCharacterObject.GetComponentInChildren<genericRagdollBuilder> ();
|
||||
|
||||
if (currentGenericRagdollBuilder != null) {
|
||||
currentGenericRagdollBuilder.mainRagdollActivator = mainRagdollActivator;
|
||||
|
||||
currentGenericRagdollBuilder.updateRagdollActivatorPatsIngame ();
|
||||
}
|
||||
|
||||
followObjectPositionSystem currentFollowObjectPositionSystem = customCharacterObject.GetComponentInChildren<followObjectPositionSystem> ();
|
||||
|
||||
if (currentFollowObjectPositionSystem != null) {
|
||||
currentFollowObjectPositionSystem.setObjectToFollow (mainPlayerController.transform);
|
||||
}
|
||||
|
||||
simpleSliceSystem currentSimpleSliceSystem = customCharacterObject.GetComponentInChildren<simpleSliceSystem> ();
|
||||
|
||||
if (currentSimpleSliceSystem != null) {
|
||||
surfaceToSlice currentSurfaceToSlice = mainPlayerController.GetComponent<surfaceToSlice> ();
|
||||
|
||||
if (currentSurfaceToSlice != null) {
|
||||
currentSurfaceToSlice.mainSimpleSliceSystem = currentSimpleSliceSystem;
|
||||
|
||||
currentSimpleSliceSystem.mainSurfaceToSlice = currentSurfaceToSlice;
|
||||
|
||||
currentSimpleSliceSystem.initializeValuesOnHackableComponent ();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void setCharacterState (bool state)
|
||||
{
|
||||
currentCustomCharacterControllerBase = currentCharacterControllerStateInfo.customCharacterController;
|
||||
|
||||
currentCustomCharacterControllerBase.setCharacterControllerActiveState (state);
|
||||
|
||||
if (ignoreSetAIValues) {
|
||||
currentCustomCharacterControllerBase.setAIValues = false;
|
||||
}
|
||||
|
||||
if (state) {
|
||||
mainPlayerController.setCustomCharacterControllerActiveState (true, currentCustomCharacterControllerBase);
|
||||
|
||||
currentCustomCharacterControllerBase.characterGameObject.transform.SetParent (customCharacterControllerParent);
|
||||
|
||||
currentCustomCharacterControllerBase.characterGameObject.transform.position = mainPlayerController.transform.position +
|
||||
currentCustomCharacterControllerBase.charactetPositionOffset;
|
||||
|
||||
Quaternion targetRotation = Quaternion.Euler (currentCustomCharacterControllerBase.characterRotationOffset);
|
||||
|
||||
currentCustomCharacterControllerBase.characterGameObject.transform.localRotation = targetRotation;
|
||||
|
||||
Animator characterAnimator = currentCustomCharacterControllerBase.characterGameObject.GetComponent<Animator> ();
|
||||
|
||||
if (characterAnimator != null && characterAnimator.enabled) {
|
||||
characterAnimator.enabled = false;
|
||||
}
|
||||
|
||||
if (previousCharacterModeName == "") {
|
||||
previousCharacterModeName = mainPlayerStatesManager.getCurrentPlayersModeName ();
|
||||
}
|
||||
|
||||
mainPlayerStatesManager.checkPlayerStates ();
|
||||
|
||||
currentCharacterControllerStateInfo.eventOnStateStart.Invoke ();
|
||||
|
||||
if (currentCharacterControllerStateInfo.useEventToSendCharacterObjectOnStateChange) {
|
||||
currentCharacterControllerStateInfo.eventToSendCharacterObjectOnStart.Invoke (currentCharacterControllerStateInfo.customCharacterController.characterGameObject);
|
||||
}
|
||||
|
||||
mainPlayerStatesManager.setPlayerModeByName (currentCustomCharacterControllerBase.playerModeName);
|
||||
|
||||
mainAnimator.runtimeAnimatorController = currentCustomCharacterControllerBase.originalAnimatorController;
|
||||
mainAnimator.avatar = currentCustomCharacterControllerBase.originalAvatar;
|
||||
|
||||
currentCustomCharacterControllerBase.updateOnGroundValue (mainPlayerController.isPlayerOnGround ());
|
||||
|
||||
if (currentCustomCharacterControllerBase.setCapsuleColliderValues) {
|
||||
mainPlayerController.setPlayerColliderCapsuleScale (currentCustomCharacterControllerBase.capsuleColliderHeight);
|
||||
|
||||
mainPlayerController.setPlayerCapsuleColliderDirection (currentCustomCharacterControllerBase.capsuleColliderDirection);
|
||||
|
||||
mainCapsuleCollider.center = currentCustomCharacterControllerBase.capsuleColliderCenter;
|
||||
|
||||
mainPlayerController.setPlayerCapsuleColliderRadius (currentCustomCharacterControllerBase.capsuleColliderRadius);
|
||||
}
|
||||
|
||||
mainPlayerController.setPlaceToShootPositionOffset (currentCustomCharacterControllerBase.placeToShootOffset);
|
||||
|
||||
|
||||
mainPlayerController.setUseRootMotionActiveState (currentCustomCharacterControllerBase.useRootMotion);
|
||||
|
||||
if (currentCustomCharacterControllerBase.useRootMotion) {
|
||||
mainPlayerController.setNoRootMotionValues (currentCustomCharacterControllerBase.noRootWalkMovementSpeed,
|
||||
currentCustomCharacterControllerBase.noRootRunMovementSpeed, currentCustomCharacterControllerBase.noRootSprintMovementSpeed,
|
||||
currentCustomCharacterControllerBase.noRootCrouchMovementSpeed,
|
||||
currentCustomCharacterControllerBase.noRootWalkStrafeMovementSpeed, currentCustomCharacterControllerBase.noRootRunStrafeMovementSpeed);
|
||||
}
|
||||
|
||||
|
||||
mainPlayerController.setCharacterMeshGameObjectState (!state);
|
||||
|
||||
mainPlayerController.setUsingExternalCharacterMeshListState (true);
|
||||
|
||||
mainPlayerController.setExternalCharacterMeshList (currentCustomCharacterControllerBase.characterMeshesList);
|
||||
|
||||
//CAMERA ELEMENTS
|
||||
if (currentCustomCharacterControllerBase.setNewCameraStates && !currentCustomCharacterControllerBase.setAIValues) {
|
||||
originalCameraStateThirdPerson = mainPlayerCamera.getDefaultThirdPersonStateName ();
|
||||
|
||||
originalCameraStateFirstPerson = mainPlayerCamera.getDefaultFirstPersonStateName ();
|
||||
|
||||
if (mainPlayerCamera.isFirstPersonActive ()) {
|
||||
mainPlayerCamera.setCameraState (currentCustomCharacterControllerBase.newCameraStateFirstPerson);
|
||||
} else {
|
||||
mainPlayerCamera.setCameraState (currentCustomCharacterControllerBase.newCameraStateThirdPerson);
|
||||
}
|
||||
|
||||
mainPlayerCamera.setDefaultThirdPersonStateName (currentCustomCharacterControllerBase.newCameraStateThirdPerson);
|
||||
|
||||
mainPlayerCamera.setDefaultFirstPersonStateName (currentCustomCharacterControllerBase.newCameraStateFirstPerson);
|
||||
}
|
||||
|
||||
|
||||
//OTHER COMPONENTS FUNCTIONS
|
||||
mainPlayerController.setCurrentCustomActionCategoryID (currentCustomCharacterControllerBase.customActionCategoryID);
|
||||
|
||||
mainPlayerController.setCharacterRadius (currentCustomCharacterControllerBase.characterRadius);
|
||||
|
||||
mainCloseCombatSystem.setCombatTypeID (currentCustomCharacterControllerBase.combatTypeID);
|
||||
|
||||
mainCloseCombatSystem.setNewParentForDamageTriggers (currentCustomCharacterControllerBase.parentForCombatDamageTriggers);
|
||||
|
||||
mainRagdollActivator.setCurrentRagdollInfo (currentCustomCharacterControllerBase.customRagdollInfoName);
|
||||
|
||||
|
||||
//AI COMPONENTS
|
||||
if (currentCustomCharacterControllerBase.setAIValues) {
|
||||
mainAICloseCombatSystemBrain.setMaxRandomTimeBetweenAttacks (currentCustomCharacterControllerBase.maxRandomTimeBetweenAttacks);
|
||||
mainAICloseCombatSystemBrain.setMinRandomTimeBetweenAttacks (currentCustomCharacterControllerBase.minRandomTimeBetweenAttacks);
|
||||
|
||||
mainAICloseCombatSystemBrain.setBlockEnabledState (false);
|
||||
|
||||
mainFindObjectivesSystem.setNewMinDistanceToEnemyUsingCloseCombat (currentCustomCharacterControllerBase.newMinDistanceToEnemyUsingCloseCombat);
|
||||
|
||||
mainFindObjectivesSystem.setNewMinDistanceToCloseCombat (currentCustomCharacterControllerBase.newMinDistanceToCloseCombat);
|
||||
|
||||
mainFindObjectivesSystem.setCloseCombatAttackMode ();
|
||||
|
||||
mainFindObjectivesSystem.setRayCastPositionOffsetValue (currentCustomCharacterControllerBase.raycastPositionOffset);
|
||||
|
||||
if (currentCustomCharacterControllerBase.healthBarOffset != 0) {
|
||||
mainHealth.updateSliderOffset (currentCustomCharacterControllerBase.healthBarOffset);
|
||||
}
|
||||
}
|
||||
|
||||
if (currentCharacterControllerStateInfo.overrideHiddenFromAIAttacksValue) {
|
||||
mainPlayerController.setStealthModeActiveState (currentCharacterControllerStateInfo.hiddenFromAIAttacksValue);
|
||||
} else {
|
||||
if (currentCustomCharacterControllerBase.hiddenFromAIAttacks) {
|
||||
mainPlayerController.setStealthModeActiveState (true);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
currentCustomCharacterControllerBase.updateOnGroundValue (mainPlayerController.isPlayerOnGround ());
|
||||
|
||||
mainAnimator.runtimeAnimatorController = originalAnimatorController;
|
||||
mainAnimator.avatar = originalAvatar;
|
||||
|
||||
mainPlayerController.setCustomCharacterControllerActiveState (false, null);
|
||||
|
||||
currentCustomCharacterControllerBase.characterGameObject.transform.SetParent (null);
|
||||
|
||||
mainPlayerController.setOriginalPlayerColliderCapsuleScale ();
|
||||
|
||||
if (currentCustomCharacterControllerBase.setCapsuleColliderValues) {
|
||||
mainPlayerController.setPlayerCapsuleColliderDirection (1);
|
||||
|
||||
mainPlayerController.setOriginalPlayerCapsuleColliderRadius ();
|
||||
}
|
||||
|
||||
mainPlayerController.setPlaceToShootPositionOffset (-1);
|
||||
|
||||
mainPlayerController.setOriginalUseRootMotionActiveState ();
|
||||
|
||||
mainPlayerController.setOriginalNoRootMotionValues ();
|
||||
|
||||
mainPlayerController.setUsingExternalCharacterMeshListState (false);
|
||||
|
||||
mainPlayerController.setExternalCharacterMeshList (null);
|
||||
|
||||
mainPlayerController.setCharacterMeshGameObjectState (!state);
|
||||
|
||||
|
||||
//CAMERA ELEMENTS
|
||||
if (currentCustomCharacterControllerBase.setNewCameraStates && !currentCustomCharacterControllerBase.setAIValues) {
|
||||
if (mainPlayerCamera.isFirstPersonActive ()) {
|
||||
mainPlayerCamera.setCameraState (originalCameraStateFirstPerson);
|
||||
} else {
|
||||
mainPlayerCamera.setCameraState (originalCameraStateThirdPerson);
|
||||
}
|
||||
|
||||
mainPlayerCamera.setDefaultThirdPersonStateName (originalCameraStateThirdPerson);
|
||||
|
||||
mainPlayerCamera.setDefaultFirstPersonStateName (originalCameraStateFirstPerson);
|
||||
}
|
||||
|
||||
|
||||
//OTHER COMPONENTS FUNCTIONS
|
||||
mainPlayerController.setCurrentCustomActionCategoryID (0);
|
||||
|
||||
mainPlayerController.setCharacterRadius (0);
|
||||
|
||||
mainCloseCombatSystem.setCombatTypeID (0);
|
||||
|
||||
mainCloseCombatSystem.setOriginalParentForDamageTriggers ();
|
||||
|
||||
mainRagdollActivator.setCurrentRagdollInfo ("");
|
||||
|
||||
|
||||
//AI COMPONENTS
|
||||
if (currentCustomCharacterControllerBase.setAIValues) {
|
||||
mainAICloseCombatSystemBrain.setOriginalMaxRandomTimeBetweenAttacks ();
|
||||
mainAICloseCombatSystemBrain.setOriginalMinRandomTimeBetweenAttacks ();
|
||||
mainAICloseCombatSystemBrain.setBlockEnabledState (true);
|
||||
|
||||
mainFindObjectivesSystem.setOriginalRayCastPositionOffsetValue ();
|
||||
|
||||
if (currentCustomCharacterControllerBase.healthBarOffset != 0) {
|
||||
mainHealth.updateOriginalSliderOffset ();
|
||||
}
|
||||
}
|
||||
|
||||
if (currentCustomCharacterControllerBase.hiddenFromAIAttacks || currentCharacterControllerStateInfo.overrideHiddenFromAIAttacksValue) {
|
||||
mainPlayerController.setStealthModeActiveState (false);
|
||||
}
|
||||
}
|
||||
|
||||
mainRagdollActivator.setPauseAnimatorStatesToGetUpState (state);
|
||||
|
||||
mainPlayerWeaponManager.enableOrDisableWeaponsMesh (!state);
|
||||
|
||||
mainPlayerController.setCharacterMeshesListToDisableOnEventState (!state);
|
||||
|
||||
mainPlayerController.enableOrDisableIKSystemManagerState (!state);
|
||||
|
||||
mainPlayerController.setFootStepManagerState (state);
|
||||
|
||||
customCharacterControllerActive = state;
|
||||
|
||||
mainPlayerController.setUsingGenericModelActiveState (state);
|
||||
|
||||
checkEventsOnStateChange (customCharacterControllerActive);
|
||||
|
||||
if (!state) {
|
||||
if (setCharacterModeOnRegularState) {
|
||||
if (previousCharacterModeName != "") {
|
||||
if (setNewCharacterModeOnRegularState) {
|
||||
if (!mainPlayerStatesManager.getCurrentPlayersModeName ().Equals (newCharacterModeOnRegularState)) {
|
||||
mainPlayerStatesManager.setPlayerModeByName (newCharacterModeOnRegularState);
|
||||
}
|
||||
} else {
|
||||
if (!mainPlayerStatesManager.getCurrentPlayersModeName ().Equals (previousCharacterModeName)) {
|
||||
mainPlayerStatesManager.setPlayerModeByName (previousCharacterModeName);
|
||||
}
|
||||
}
|
||||
|
||||
previousCharacterModeName = "";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool isCustomCharacterControllerActive ()
|
||||
{
|
||||
return customCharacterControllerActive;
|
||||
}
|
||||
|
||||
public void checkEventsOnStateChange (bool state)
|
||||
{
|
||||
if (useEventsOnStateChange) {
|
||||
if (state) {
|
||||
eventOnCustomCharacterEnter.Invoke ();
|
||||
} else {
|
||||
eventOnCustomCharacterExit.Invoke ();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setToggleCustomCharacterControllerPausedState (bool state)
|
||||
{
|
||||
toggleCustomCharacterControllerPaused = state;
|
||||
}
|
||||
|
||||
public void addNewCustomCharacterController (customCharacterControllerBase newCustomCharacterControllerBase, string newName)
|
||||
{
|
||||
characterControllerStateInfo newCharacterControllerStateInfo = new characterControllerStateInfo ();
|
||||
|
||||
newCharacterControllerStateInfo.Name = newName;
|
||||
|
||||
newCharacterControllerStateInfo.customCharacterController = newCustomCharacterControllerBase;
|
||||
|
||||
characterControllerStateInfoList.Add (newCharacterControllerStateInfo);
|
||||
|
||||
updateComponent ();
|
||||
}
|
||||
|
||||
public void addNewCustomCharacterControllerToSpawn (GameObject newCustomCharacterControllerBaseObject, string newName)
|
||||
{
|
||||
characterControllerStateInfo newCharacterControllerStateInfo = new characterControllerStateInfo ();
|
||||
|
||||
newCharacterControllerStateInfo.Name = newName;
|
||||
|
||||
newCharacterControllerStateInfo.customCharacterPrefab = newCustomCharacterControllerBaseObject;
|
||||
|
||||
newCharacterControllerStateInfo.spawnCustomCharacterPrefab = true;
|
||||
|
||||
characterControllerStateInfoList.Add (newCharacterControllerStateInfo);
|
||||
|
||||
updateComponent ();
|
||||
}
|
||||
|
||||
public void toggleCharacterModelMeshOnEditor (bool state)
|
||||
{
|
||||
if (genericModelVisibleOnEditor == state) {
|
||||
return;
|
||||
}
|
||||
|
||||
genericModelVisibleOnEditor = state;
|
||||
|
||||
if (currentCustomCharacterControllerBase != null && !genericModelVisibleOnEditor) {
|
||||
currentCustomCharacterControllerBase.setCharacterControllerActiveState (genericModelVisibleOnEditor);
|
||||
|
||||
currentCustomCharacterControllerBase = null;
|
||||
}
|
||||
|
||||
int characterIndex = characterControllerStateInfoList.FindIndex (s => s.Name == customCharacterControllerToStartName);
|
||||
|
||||
if (characterIndex > -1) {
|
||||
currentCharacterControllerStateInfo = characterControllerStateInfoList [characterIndex];
|
||||
|
||||
currentCustomCharacterControllerBase = currentCharacterControllerStateInfo.customCharacterController;
|
||||
|
||||
if (currentCustomCharacterControllerBase == null) {
|
||||
instantiateCustomCharacter (currentCharacterControllerStateInfo);
|
||||
|
||||
currentCustomCharacterControllerBase = currentCharacterControllerStateInfo.customCharacterController;
|
||||
}
|
||||
|
||||
if (currentCustomCharacterControllerBase != null) {
|
||||
currentCustomCharacterControllerBase.setCharacterControllerActiveState (genericModelVisibleOnEditor);
|
||||
}
|
||||
}
|
||||
|
||||
mainPlayerController.setCharacterMeshGameObjectState (!genericModelVisibleOnEditor);
|
||||
|
||||
mainPlayerWeaponManager.enableOrDisableAllWeaponsMeshes (!genericModelVisibleOnEditor);
|
||||
|
||||
mainPlayerController.setCharacterMeshesListToDisableOnEventState (!genericModelVisibleOnEditor);
|
||||
|
||||
updateComponent ();
|
||||
}
|
||||
|
||||
public void setStartGameWithCustomCharacterControllerFromEditor (bool state)
|
||||
{
|
||||
startGameWithCustomCharacterController = state;
|
||||
|
||||
updateComponent ();
|
||||
}
|
||||
|
||||
public void setCustomCharacterControllerToStartNameFromEditor (string newCharacterName)
|
||||
{
|
||||
customCharacterControllerToStartName = newCharacterName;
|
||||
|
||||
updateComponent ();
|
||||
}
|
||||
|
||||
public void setCapsuleValuesFromMainCharacter ()
|
||||
{
|
||||
if (currentCustomCharacterControllerBase != null) {
|
||||
currentCustomCharacterControllerBase.setCapsuleColliderDirectionValue (mainCapsuleCollider.direction);
|
||||
|
||||
currentCustomCharacterControllerBase.setCapsuleColliderCenterValue (mainCapsuleCollider.center);
|
||||
currentCustomCharacterControllerBase.setCapsuleColliderRadiusValue (mainCapsuleCollider.radius);
|
||||
currentCustomCharacterControllerBase.setCapsuleColliderHeightValue (mainCapsuleCollider.height);
|
||||
}
|
||||
}
|
||||
|
||||
void updateComponent ()
|
||||
{
|
||||
GKC_Utils.updateComponent (this);
|
||||
|
||||
GKC_Utils.updateDirtyScene ("Add New Custom Character Controller", gameObject);
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public class characterControllerStateInfo
|
||||
{
|
||||
[Header ("Main Settings")]
|
||||
[Space]
|
||||
|
||||
public string Name;
|
||||
public bool stateEnabled = true;
|
||||
|
||||
public bool isCurrentCharacterController;
|
||||
|
||||
[Space]
|
||||
[Space]
|
||||
|
||||
public customCharacterControllerBase customCharacterController;
|
||||
|
||||
[Space]
|
||||
|
||||
[Header ("Spawn Character Ingame Settings")]
|
||||
[Space]
|
||||
|
||||
public bool spawnCustomCharacterPrefab;
|
||||
public GameObject customCharacterPrefab;
|
||||
|
||||
[HideInInspector] public GameObject customCharacterInstantiatedObject;
|
||||
|
||||
[Space]
|
||||
[Header ("AI Visibility")]
|
||||
[Space]
|
||||
|
||||
public bool overrideHiddenFromAIAttacksValue;
|
||||
public bool hiddenFromAIAttacksValue;
|
||||
|
||||
[Space]
|
||||
[Space]
|
||||
|
||||
[Header ("Events Settings")]
|
||||
[Space]
|
||||
|
||||
public UnityEvent eventOnStateStart;
|
||||
public UnityEvent eventOnStateEnd;
|
||||
|
||||
public bool useEventToSendCharacterObjectOnStateChange;
|
||||
public eventParameters.eventToCallWithGameObject eventToSendCharacterObjectOnStart;
|
||||
public eventParameters.eventToCallWithGameObject eventToSendCharacterObjectOnEnd;
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user