add some extra assets FX and SFX
This commit is contained in:
@@ -0,0 +1,495 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.AI;
|
||||
|
||||
public class adjustCharacterHeightSystem : MonoBehaviour
|
||||
{
|
||||
[Header ("Main Settings")]
|
||||
[Space]
|
||||
|
||||
public bool adjustCharacterHeight;
|
||||
public float characterHeight = 2;
|
||||
|
||||
public bool setCharacterModelScale;
|
||||
public float characterModelScale = 1;
|
||||
|
||||
public bool resetMountPointLocalPositions;
|
||||
|
||||
[Space]
|
||||
|
||||
public float capsuleHeight = 2;
|
||||
public float capsuleRadius = 0.3f;
|
||||
public float capsuleHeightOnCrouch = 1;
|
||||
|
||||
[Space]
|
||||
|
||||
public float characterRadius;
|
||||
|
||||
[Space]
|
||||
|
||||
public bool enableHeadTrack;
|
||||
|
||||
[Space]
|
||||
[Header ("Camera Settings")]
|
||||
[Space]
|
||||
|
||||
public List<cameraStateHeightInfo> cameraStateHeightInfoList = new List<cameraStateHeightInfo> ();
|
||||
|
||||
[Space]
|
||||
[Header ("Character Transform Parts Settings")]
|
||||
[Space]
|
||||
|
||||
public List<transformPartInfo> transformPartInfoList = new List<transformPartInfo> ();
|
||||
|
||||
[Space]
|
||||
[Header ("Fire Weapons Settings")]
|
||||
[Space]
|
||||
|
||||
public bool applyScaleToFireWeapons;
|
||||
public float scaleForFireWeapons;
|
||||
|
||||
public Vector3 offsetParentThirdPerson;
|
||||
|
||||
[Space]
|
||||
|
||||
public bool setFixedOffsetParentThirdPerson;
|
||||
public Vector3 fixedOffsetParentThirdPerson;
|
||||
|
||||
[Space]
|
||||
|
||||
public float fireWeaponTransformReferenceScale = 1;
|
||||
|
||||
[Space]
|
||||
[Header ("Melee Weapons Settings")]
|
||||
[Space]
|
||||
|
||||
public bool applyScaleToMeleeWapons;
|
||||
public float scaleForMeleeWeapons;
|
||||
|
||||
public bool placeTriggerInFrontOfCharacterOnAllMeleeAttacks;
|
||||
|
||||
[Space]
|
||||
|
||||
public bool useExtraTriggerMultiplierScaleOnAllMeleeAttacksActive;
|
||||
public float extraTriggerMultiplierScaleOnAllMeleeAttacksAmount;
|
||||
|
||||
[Space]
|
||||
[Header ("Close Combat Settings")]
|
||||
[Space]
|
||||
|
||||
public bool setNewCloseCombatTriggerRadius;
|
||||
public float newCloseCombatTriggerRadius;
|
||||
|
||||
public bool placeTriggerInFrontOfCharacterOnAllCloseCombatAttacks;
|
||||
|
||||
[Space]
|
||||
[Header ("AI Settings")]
|
||||
[Space]
|
||||
|
||||
public bool characterIsAI;
|
||||
public bool characterUsesExtraColliders;
|
||||
public List<Collider> extraColliderList = new List<Collider> ();
|
||||
|
||||
[Space]
|
||||
|
||||
public bool useNewMinDistanceToTarget;
|
||||
public float newMinDistanceToEnemyUsingCloseCombat;
|
||||
public float newMinDistanceToCloseCombat;
|
||||
|
||||
[Space]
|
||||
|
||||
public float newMinDistanceToMelee;
|
||||
|
||||
public float newMinDistanceToEnemyUsingMelee;
|
||||
|
||||
[Space]
|
||||
|
||||
public bool setNewAgentRadius;
|
||||
public float newAgentRadius;
|
||||
|
||||
[Space]
|
||||
[Header ("Components")]
|
||||
[Space]
|
||||
|
||||
public playerComponentsManager mainPlayerComponentsManager;
|
||||
public playerController mainPlayerController;
|
||||
public playerCamera mainPlayerCamera;
|
||||
public playerWeaponsManager mainPlayerWeaponsManager;
|
||||
public meleeWeaponsGrabbedManager mainMeleeWeaponsGrabbedManager;
|
||||
public bodyMountPointsSystem mainBodyMountPointSystem;
|
||||
public buildPlayer mainBuildPlayer;
|
||||
public headTrack mainHeadTrack;
|
||||
public IKSystem mainIKSystem;
|
||||
public health mainHealth;
|
||||
public closeCombatSystem mainCloseCombatSystem;
|
||||
|
||||
public findObjectivesSystem mainFindObjectivesSystem;
|
||||
public AINavMesh mainAINavmesh;
|
||||
|
||||
bool adjustingHeighValueOnRuntimeActive;
|
||||
|
||||
bool applicationisPlaying;
|
||||
|
||||
|
||||
void Start ()
|
||||
{
|
||||
if (characterUsesExtraColliders) {
|
||||
int extraColliderListCount = extraColliderList.Count;
|
||||
|
||||
for (int i = 0; i < extraColliderListCount; i++) {
|
||||
mainPlayerController.setIgnoreCollisionOnExternalCollider (extraColliderList [i], true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void adjustHeightValueInRuntime ()
|
||||
{
|
||||
updateApplicationisPlayingValue ();
|
||||
|
||||
adjustingHeighValueOnRuntimeActive = true;
|
||||
|
||||
adjustHeightValue ();
|
||||
|
||||
adjustCameraStates ();
|
||||
|
||||
adjustFireWeaponsScale ();
|
||||
|
||||
if (setFixedOffsetParentThirdPerson) {
|
||||
Vector3 previousOffsetParentThirdPerson = offsetParentThirdPerson;
|
||||
|
||||
offsetParentThirdPerson = fixedOffsetParentThirdPerson;
|
||||
|
||||
adjustFireWeaponsOffset ();
|
||||
|
||||
adjustFireWeaponsTransformReferences ();
|
||||
|
||||
offsetParentThirdPerson = previousOffsetParentThirdPerson;
|
||||
}
|
||||
|
||||
adjustingHeighValueOnRuntimeActive = false;
|
||||
}
|
||||
|
||||
|
||||
public void adjustHeightValue ()
|
||||
{
|
||||
getComponents ();
|
||||
|
||||
bool resetWeaponsTransformResult = false;
|
||||
|
||||
if (setCharacterModelScale) {
|
||||
//unpack the character to avoid issues with the prefab
|
||||
if (!adjustingHeighValueOnRuntimeActive) {
|
||||
GKC_Utils.unpackPrefabObjectByCheckingTransformRoot (mainPlayerController.gameObject);
|
||||
}
|
||||
|
||||
//put all the internal objects that are inside the body into a temporal transform
|
||||
mainBodyMountPointSystem.removeCharacterBodyMountPointsToTemporalParent (transform);
|
||||
|
||||
Transform mainCOMTransform = mainIKSystem.getIKBodyCOM ();
|
||||
|
||||
Transform characterCOMChild = null;
|
||||
|
||||
if (mainCOMTransform != null && mainCOMTransform.childCount > 0) {
|
||||
characterCOMChild = mainCOMTransform.GetChild (0);
|
||||
}
|
||||
|
||||
if (characterCOMChild != null) {
|
||||
characterCOMChild.localScale = Vector3.one * characterModelScale;
|
||||
}
|
||||
|
||||
//put back all the mount points back to the character's body
|
||||
mainBodyMountPointSystem.setCharacterBodyMountPointsInfoList ();
|
||||
|
||||
mainPlayerController.setCharacterCustomScale (characterModelScale);
|
||||
|
||||
resetWeaponsTransformResult = true;
|
||||
}
|
||||
|
||||
if (adjustCharacterHeight) {
|
||||
resetWeaponsTransformResult = true;
|
||||
}
|
||||
|
||||
if (resetMountPointLocalPositions) {
|
||||
mainBodyMountPointSystem.resetCharacterBodyMountPointsLocalPositions ();
|
||||
}
|
||||
|
||||
adjustTransformParts ();
|
||||
|
||||
if (resetWeaponsTransformResult) {
|
||||
mainPlayerWeaponsManager.resetWeaponsParentToPlayerPosition ();
|
||||
mainPlayerWeaponsManager.resetWeaponsTransformInThirdPersonToPlayerPosition ();
|
||||
}
|
||||
|
||||
mainPlayerController.setPlayerCapsuleColliderRadius (capsuleRadius);
|
||||
|
||||
mainPlayerController.setPlayerColliderCapsuleScaleWithCenterAsRadius (capsuleHeight);
|
||||
|
||||
mainPlayerController.setCapsuleHeightOnCrouch (capsuleHeightOnCrouch);
|
||||
|
||||
mainPlayerController.setCharacterRadius (characterRadius);
|
||||
|
||||
if (enableHeadTrack) {
|
||||
mainHeadTrack.setHeadTrackEnabledState (true);
|
||||
}
|
||||
|
||||
if (characterIsAI) {
|
||||
if (setNewAgentRadius) {
|
||||
NavMeshAgent currenAgent = mainAINavmesh.getAgent ();
|
||||
|
||||
currenAgent.radius = newAgentRadius;
|
||||
|
||||
currenAgent.height = characterHeight;
|
||||
}
|
||||
}
|
||||
|
||||
if (characterUsesExtraColliders) {
|
||||
int extraColliderListCount = extraColliderList.Count;
|
||||
|
||||
int characterLayer = mainPlayerController.getCharacterLayer ();
|
||||
|
||||
for (int i = 0; i < extraColliderListCount; i++) {
|
||||
mainPlayerController.addOrRemoveExtraColliders (extraColliderList [i], true);
|
||||
|
||||
extraColliderList [i].gameObject.layer = characterLayer;
|
||||
|
||||
mainCloseCombatSystem.addOrRemoveObjectToIgnoreByHitTriggers (extraColliderList [i].gameObject, true);
|
||||
|
||||
characterDamageReceiver currentDamageReceiverToCheck = extraColliderList [i].GetComponent<characterDamageReceiver> ();
|
||||
|
||||
if (currentDamageReceiverToCheck != null) {
|
||||
currentDamageReceiverToCheck.setCharacter (mainPlayerController.gameObject, mainHealth);
|
||||
|
||||
mainHealth.addDamageReceiverGameObjectList (currentDamageReceiverToCheck.gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
if (adjustingHeighValueOnRuntimeActive) {
|
||||
for (int i = 0; i < extraColliderListCount; i++) {
|
||||
mainPlayerController.setIgnoreCollisionOnExternalCollider (extraColliderList [i], true);
|
||||
}
|
||||
}
|
||||
|
||||
mainAINavmesh.setCheckForExtraCollidersOnOwnerIfDetectedStateFromEditor (true);
|
||||
|
||||
mainFindObjectivesSystem.setCheckForExtraCollidersOnOwnerIfDetectedStateFromEditor (true);
|
||||
}
|
||||
|
||||
if (setNewCloseCombatTriggerRadius) {
|
||||
mainCloseCombatSystem.updateHitCombatTriggerRadius (newCloseCombatTriggerRadius);
|
||||
}
|
||||
|
||||
if (useNewMinDistanceToTarget) {
|
||||
if (newMinDistanceToEnemyUsingCloseCombat > 0) {
|
||||
mainFindObjectivesSystem.setNewMinDistanceToEnemyUsingCloseCombat (newMinDistanceToEnemyUsingCloseCombat);
|
||||
}
|
||||
|
||||
if (newMinDistanceToCloseCombat > 0) {
|
||||
mainFindObjectivesSystem.setNewMinDistanceToCloseCombat (newMinDistanceToCloseCombat);
|
||||
}
|
||||
|
||||
if (newMinDistanceToMelee > 0) {
|
||||
mainFindObjectivesSystem.setNewMinDistanceToMelee (newMinDistanceToMelee);
|
||||
}
|
||||
|
||||
if (newMinDistanceToEnemyUsingMelee > 0) {
|
||||
mainFindObjectivesSystem.setMinDistanceToEnemyUsingMelee (newMinDistanceToEnemyUsingMelee);
|
||||
}
|
||||
}
|
||||
|
||||
mainHealth.setSliderOffset (characterHeight + 0.5f);
|
||||
|
||||
if (applyScaleToMeleeWapons) {
|
||||
mainMeleeWeaponsGrabbedManager.setWeaponMeshScaleOnAllWeapons (scaleForMeleeWeapons);
|
||||
}
|
||||
|
||||
if (placeTriggerInFrontOfCharacterOnAllMeleeAttacks) {
|
||||
mainMeleeWeaponsGrabbedManager.setPlaceTriggerInFrontOfCharacterOnAllAttacksState (true);
|
||||
}
|
||||
|
||||
if (placeTriggerInFrontOfCharacterOnAllCloseCombatAttacks) {
|
||||
mainCloseCombatSystem.setPlaceTriggerInFrontOfCharacterOnAllAttacksState (true);
|
||||
}
|
||||
|
||||
if (useExtraTriggerMultiplierScaleOnAllMeleeAttacksActive) {
|
||||
mainMeleeWeaponsGrabbedManager.setExtraTriggerMultiplierScaleOnAllMeleeAttacksActiveState (true, extraTriggerMultiplierScaleOnAllMeleeAttacksAmount);
|
||||
}
|
||||
|
||||
if (!adjustingHeighValueOnRuntimeActive) {
|
||||
updateComponent ();
|
||||
|
||||
print ("Height values adjusted on Character " + gameObject.name);
|
||||
}
|
||||
}
|
||||
|
||||
void adjustTransformParts ()
|
||||
{
|
||||
for (int i = 0; i < transformPartInfoList.Count; i++) {
|
||||
|
||||
transformPartInfo currentPart = transformPartInfoList [i];
|
||||
|
||||
Vector3 newPosition = currentPart.transformPart.position;
|
||||
|
||||
float newYValue = (characterHeight * currentPart.defaultHeightPercentage) / 100;
|
||||
|
||||
newPosition = new Vector3 (newPosition.x, newYValue, newPosition.z);
|
||||
|
||||
currentPart.transformPart.position = newPosition;
|
||||
}
|
||||
}
|
||||
|
||||
public void adjustFireWeaponsScale ()
|
||||
{
|
||||
if (applyScaleToFireWeapons) {
|
||||
mainPlayerWeaponsManager.setWeaponMeshScaleOnAllWeapons (scaleForFireWeapons);
|
||||
|
||||
if (!adjustingHeighValueOnRuntimeActive) {
|
||||
updateComponent ();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void adjustFireWeaponsOffset ()
|
||||
{
|
||||
mainPlayerWeaponsManager.setCurrentOffsetParentThirdPersonValues (offsetParentThirdPerson);
|
||||
|
||||
mainPlayerWeaponsManager.setCurrentOffsetParentOnThirdPersonOnAllWeapons ();
|
||||
|
||||
mainPlayerWeaponsManager.adjustDrawKeepPositionToWeaponPositionOnAllWeapons ();
|
||||
|
||||
if (!adjustingHeighValueOnRuntimeActive) {
|
||||
updateComponent ();
|
||||
}
|
||||
}
|
||||
|
||||
public void adjustFireWeaponsTransformReferences ()
|
||||
{
|
||||
mainPlayerWeaponsManager.adjustAllFireWeaponTransformReferencePositionOnAllWeapons (fireWeaponTransformReferenceScale);
|
||||
|
||||
if (!adjustingHeighValueOnRuntimeActive) {
|
||||
updateComponent ();
|
||||
}
|
||||
}
|
||||
|
||||
public void adjustCameraStates ()
|
||||
{
|
||||
int cameraIndex = 0;
|
||||
|
||||
for (int i = 0; i < cameraStateHeightInfoList.Count; i++) {
|
||||
|
||||
cameraStateHeightInfo currentState = cameraStateHeightInfoList [i];
|
||||
|
||||
cameraIndex = mainPlayerCamera.playerCameraStates.FindIndex (s => s.Name.Equals (currentState.cameraStateName));
|
||||
|
||||
if (cameraIndex > -1) {
|
||||
float newYValue = (characterHeight * currentState.defaultPivotHeightPercentage) / 100;
|
||||
|
||||
mainPlayerCamera.playerCameraStates [cameraIndex].pivotPositionOffset.y = newYValue;
|
||||
|
||||
if (adjustingHeighValueOnRuntimeActive) {
|
||||
mainPlayerCamera.updateCameraStateValuesOnEditor (cameraIndex);
|
||||
}
|
||||
|
||||
if (!adjustingHeighValueOnRuntimeActive) {
|
||||
print ("Camera State " + currentState.cameraStateName + " update with " + newYValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cameraIndex = mainPlayerCamera.playerCameraStates.FindIndex (s => s.Name.Equals (mainPlayerCamera.getCurrentStateName ()));
|
||||
|
||||
if (cameraIndex > -1) {
|
||||
mainPlayerCamera.getPivotCameraTransform ().localPosition = mainPlayerCamera.playerCameraStates [cameraIndex].pivotPositionOffset;
|
||||
|
||||
if (adjustingHeighValueOnRuntimeActive) {
|
||||
mainPlayerCamera.updateCameraStateValuesOnEditor (cameraIndex);
|
||||
}
|
||||
}
|
||||
|
||||
if (!adjustingHeighValueOnRuntimeActive) {
|
||||
updateComponent ();
|
||||
}
|
||||
}
|
||||
|
||||
void updateComponent ()
|
||||
{
|
||||
GKC_Utils.updateComponent (this);
|
||||
|
||||
GKC_Utils.updateDirtyScene ("Update Character Height/Scale", gameObject);
|
||||
}
|
||||
|
||||
void getComponents ()
|
||||
{
|
||||
if (mainPlayerComponentsManager != null) {
|
||||
if (mainPlayerController == null) {
|
||||
mainPlayerController = mainPlayerComponentsManager.getPlayerController ();
|
||||
}
|
||||
|
||||
if (mainPlayerCamera == null) {
|
||||
mainPlayerCamera = mainPlayerComponentsManager.getPlayerCamera ();
|
||||
}
|
||||
|
||||
if (mainPlayerWeaponsManager == null) {
|
||||
mainPlayerWeaponsManager = mainPlayerComponentsManager.getPlayerWeaponsManager ();
|
||||
}
|
||||
|
||||
if (mainBodyMountPointSystem == null) {
|
||||
mainBodyMountPointSystem = mainPlayerComponentsManager.getBodyMountPointsSystem ();
|
||||
}
|
||||
|
||||
if (mainBuildPlayer == null) {
|
||||
mainBuildPlayer = mainPlayerComponentsManager.getBuildPlayer ();
|
||||
}
|
||||
|
||||
if (mainHeadTrack == null) {
|
||||
mainHeadTrack = mainPlayerComponentsManager.getHeadTrack ();
|
||||
}
|
||||
|
||||
if (mainIKSystem == null) {
|
||||
mainIKSystem = mainPlayerComponentsManager.getIKSystem ();
|
||||
}
|
||||
|
||||
if (mainHealth == null) {
|
||||
mainHealth = mainPlayerComponentsManager.getHealth ();
|
||||
}
|
||||
|
||||
if (mainCloseCombatSystem == null) {
|
||||
mainCloseCombatSystem = mainPlayerComponentsManager.getCloseCombatSystem ();
|
||||
}
|
||||
|
||||
if (mainFindObjectivesSystem == null) {
|
||||
mainFindObjectivesSystem = mainPlayerComponentsManager.getFindObjectivesSystem ();
|
||||
}
|
||||
|
||||
if (mainAINavmesh == null) {
|
||||
mainAINavmesh = mainFindObjectivesSystem.getAINavMesh ();
|
||||
}
|
||||
|
||||
if (mainMeleeWeaponsGrabbedManager == null) {
|
||||
mainMeleeWeaponsGrabbedManager = mainPlayerComponentsManager.getMeleeWeaponsGrabbedManager ();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void updateApplicationisPlayingValue ()
|
||||
{
|
||||
applicationisPlaying = Application.isPlaying;
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public class transformPartInfo
|
||||
{
|
||||
public Transform transformPart;
|
||||
|
||||
public float defaultHeightPercentage;
|
||||
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public class cameraStateHeightInfo
|
||||
{
|
||||
public string cameraStateName;
|
||||
|
||||
public float defaultPivotHeightPercentage;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2dfbf4ca959f0b648b83d9aa02f7fea3
|
||||
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 FPS TPS Creator 3D +
|
||||
2.5D
|
||||
packageVersion: 3.77h
|
||||
assetPath: Assets/Game Kit Controller/Scripts/Player/Character Builder/adjustCharacterHeightSystem.cs
|
||||
uploadId: 889948
|
||||
@@ -41,6 +41,39 @@ public class bodyMountPointsSystem : MonoBehaviour
|
||||
public GameObject mountPointObjectReferencePrefab;
|
||||
|
||||
|
||||
public void removeCharacterBodyMountPointsToTemporalParent (Transform newParent)
|
||||
{
|
||||
for (int i = 0; i < bodyMountPointInfoList.Count; i++) {
|
||||
|
||||
bodyMountPointInfo currentBodyMountPointInfo = bodyMountPointInfoList [i];
|
||||
|
||||
for (int j = 0; j < currentBodyMountPointInfo.objectPointInfoList.Count; j++) {
|
||||
objectPointInfo currentObjectPointInfo = currentBodyMountPointInfo.objectPointInfoList [j];
|
||||
|
||||
if (currentObjectPointInfo.objectTransform != null) {
|
||||
currentObjectPointInfo.objectTransform.SetParent (newParent);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void resetCharacterBodyMountPointsLocalPositions ()
|
||||
{
|
||||
for (int i = 0; i < bodyMountPointInfoList.Count; i++) {
|
||||
|
||||
bodyMountPointInfo currentBodyMountPointInfo = bodyMountPointInfoList [i];
|
||||
|
||||
for (int j = 0; j < currentBodyMountPointInfo.objectPointInfoList.Count; j++) {
|
||||
objectPointInfo currentObjectPointInfo = currentBodyMountPointInfo.objectPointInfoList [j];
|
||||
|
||||
if (currentObjectPointInfo.objectTransform != null) {
|
||||
currentObjectPointInfo.objectTransform.localPosition = Vector3.zero;
|
||||
currentObjectPointInfo.objectTransform.localRotation = Quaternion.identity;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setCharacterBodyMountPointsInfoList ()
|
||||
{
|
||||
for (int i = 0; i < bodyMountPointInfoList.Count; i++) {
|
||||
@@ -63,24 +96,34 @@ public class bodyMountPointsSystem : MonoBehaviour
|
||||
|
||||
if (currentBodyMountPointInfo.useCustomBoneTransform) {
|
||||
currentBone = currentBodyMountPointInfo.customBoneTransform;
|
||||
|
||||
if (currentBone != null) {
|
||||
if (!currentBone.IsChildOf (mainAnimator.transform)) {
|
||||
print ("transform assigned is not part of the current animator, recalculating " + currentBone.name);
|
||||
|
||||
currentBone = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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 (mainAnimator.isHuman) {
|
||||
if (currentBone == null) {
|
||||
currentBone = mainAnimator.GetBoneTransform (currentBodyMountPointInfo.boneToAttach);
|
||||
}
|
||||
|
||||
if (currentBone == null) {
|
||||
currentBone = mainAnimator.transform;
|
||||
currentBone = mainAnimator.GetBoneTransform (currentBodyMountPointInfo.alternativeBoneToAttach);
|
||||
}
|
||||
|
||||
print ("WARNING: No bone found on character body elements list for " + currentBodyMountPointInfo.Name + "" +
|
||||
" setting that character element inside the character model " + currentBone.name);
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,8 @@ MonoImporter:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 40995
|
||||
packageName: Game Kit Controller - Shooter Melee Adventure Creator 3D + 2.5D
|
||||
packageVersion: 3.77g
|
||||
packageName: Game Kit Controller - Shooter Melee Adventure FPS TPS Creator 3D +
|
||||
2.5D
|
||||
packageVersion: 3.77h
|
||||
assetPath: Assets/Game Kit Controller/Scripts/Player/Character Builder/bodyMountPointsSystem.cs
|
||||
uploadId: 814740
|
||||
uploadId: 889948
|
||||
|
||||
@@ -133,6 +133,81 @@ public class buildPlayer : MonoBehaviour
|
||||
|
||||
bool checkUnpackCharacterPrefabActive;
|
||||
|
||||
bool replacingCharacterModelInRuntimeActive;
|
||||
|
||||
bool applicationisPlaying;
|
||||
|
||||
bool setNewChestUpVectorValueActive;
|
||||
Vector3 newChestUpVectorValue;
|
||||
|
||||
|
||||
public void setNewCharacterModelToReplaceInRuntime (GameObject newObject)
|
||||
{
|
||||
if (newObject == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
newCharacterModel = newObject;
|
||||
|
||||
//assign the new character model and the bones for the mount points manually from its character info
|
||||
}
|
||||
|
||||
public void buildCharacterInRuntime ()
|
||||
{
|
||||
updateApplicationisPlayingValue ();
|
||||
|
||||
replacingCharacterModelInRuntimeActive = true;
|
||||
|
||||
ignoreApplyCharacterSettings = true;
|
||||
|
||||
if (!applicationisPlaying) {
|
||||
checkUnpackCharacterPrefab ();
|
||||
}
|
||||
|
||||
buildCharacter ();
|
||||
|
||||
ignoreApplyCharacterSettings = false;
|
||||
|
||||
replacingCharacterModelInRuntimeActive = false;
|
||||
|
||||
|
||||
//disable the destroy current character model and the usage of character settings
|
||||
|
||||
//it will need that each component that access to the character model gets the info updated
|
||||
|
||||
//the ragdoll creator should be avoided, as each model would have its ragdoll created, the system will check for the
|
||||
//ragdoll elements inside and assign if already exists
|
||||
|
||||
//check for other objects that check for bone references on start, like head collision
|
||||
}
|
||||
|
||||
public void checkElementsBeforeReplacingCharacterModelInRuntime ()
|
||||
{
|
||||
updateApplicationisPlayingValue ();
|
||||
|
||||
if (applicationisPlaying) {
|
||||
GKC_Utils.checkPlayerStates (player);
|
||||
}
|
||||
}
|
||||
|
||||
public void checkElementsAfterReplacingCharacterModelInRuntime ()
|
||||
{
|
||||
updateApplicationisPlayingValue ();
|
||||
|
||||
if (applicationisPlaying) {
|
||||
weaponsManager.resetWeaponsTransformInThirdPersonToPlayerPosition ();
|
||||
|
||||
weaponsManager.resetWeaponsParentToPlayerPosition ();
|
||||
|
||||
weaponsManager.updateWeaponsParentAndLocalPosition ();
|
||||
}
|
||||
|
||||
Transform temporalChestBone = upperBodyRotationManager.getChestTransform ();
|
||||
|
||||
upperBodyRotationManager.calculateCharacterRotationValues ();
|
||||
|
||||
weaponsManager.updateWeaponsParentsInRuntime (temporalChestBone, newModelAnimator);
|
||||
}
|
||||
|
||||
public void buildCharacterByButton ()
|
||||
{
|
||||
@@ -155,23 +230,61 @@ public class buildPlayer : MonoBehaviour
|
||||
void checkUnpackCharacterPrefab ()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
|
||||
currentPlayerComponentsManager = player.GetComponent<playerComponentsManager> ();
|
||||
|
||||
playerControllerManager = currentPlayerComponentsManager.getPlayerController ();
|
||||
|
||||
bool characterIsAI = playerControllerManager.isCharacterUsedByAI ();
|
||||
|
||||
bool checkPrefabResult = false;
|
||||
|
||||
GameObject mainParentGameObject = null;
|
||||
|
||||
if (transform.parent != null) {
|
||||
if (transform.root != null) {
|
||||
GameObject mainParentGameObject = transform.root.gameObject;
|
||||
print ("checking unpack character " + transform.parent.name);
|
||||
|
||||
if (PrefabUtility.GetCorrespondingObjectFromSource (mainParentGameObject)) {
|
||||
//GKC_Utils.setActiveGameObjectInEditorWithoutCheckNull (null);
|
||||
Transform currentTransformRoot = transform.root;
|
||||
|
||||
print ("Character parent is currently a prefab, unpacking before creating new character\n");
|
||||
if (currentTransformRoot != null) {
|
||||
if (characterIsAI) {
|
||||
currentTransformRoot = transform;
|
||||
|
||||
print (PrefabUtility.GetCorrespondingObjectFromSource (mainParentGameObject).name);
|
||||
|
||||
PrefabUtility.UnpackPrefabInstance (mainParentGameObject, PrefabUnpackMode.Completely, InteractionMode.UserAction);
|
||||
} else {
|
||||
print ("Character parent prefab not found, continuing creating new character process\n");
|
||||
print ("character is AI, the root is this object " + currentTransformRoot.name);
|
||||
}
|
||||
}
|
||||
|
||||
print ("checking unpack character " + currentTransformRoot.name);
|
||||
|
||||
mainParentGameObject = currentTransformRoot.gameObject;
|
||||
|
||||
checkPrefabResult = true;
|
||||
}
|
||||
} else {
|
||||
Transform currentTransformRoot = transform.root;
|
||||
|
||||
if (currentTransformRoot != null) {
|
||||
print ("checking unpack character " + currentTransformRoot.name);
|
||||
|
||||
mainParentGameObject = currentTransformRoot.gameObject;
|
||||
|
||||
checkPrefabResult = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (checkPrefabResult && mainParentGameObject != null) {
|
||||
print ("unpack check condition found, checking result");
|
||||
|
||||
if (PrefabUtility.GetCorrespondingObjectFromSource (mainParentGameObject)) {
|
||||
//GKC_Utils.setActiveGameObjectInEditorWithoutCheckNull (null);
|
||||
|
||||
print ("Character parent is currently a prefab, unpacking before creating new character\n");
|
||||
|
||||
print (PrefabUtility.GetCorrespondingObjectFromSource (mainParentGameObject).name);
|
||||
|
||||
PrefabUtility.UnpackPrefabInstance (mainParentGameObject, PrefabUnpackMode.Completely, InteractionMode.UserAction);
|
||||
} else {
|
||||
print ("Character parent prefab not found, continuing creating new character process\n");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -318,12 +431,19 @@ public class buildPlayer : MonoBehaviour
|
||||
(leftToes != null);
|
||||
}
|
||||
|
||||
void updateApplicationisPlayingValue ()
|
||||
{
|
||||
applicationisPlaying = Application.isPlaying;
|
||||
}
|
||||
|
||||
//set all the objects inside the character's body
|
||||
public void buildCharacter ()
|
||||
{
|
||||
updateApplicationisPlayingValue ();
|
||||
|
||||
//it only works in the editor mode, checking the game is not running
|
||||
if (!Application.isPlaying) {
|
||||
if (!assignNewModelManually) {
|
||||
if (!applicationisPlaying || replacingCharacterModelInRuntimeActive) {
|
||||
if (!assignNewModelManually && !replacingCharacterModelInRuntimeActive) {
|
||||
getCharacterBones ();
|
||||
}
|
||||
|
||||
@@ -337,11 +457,13 @@ public class buildPlayer : MonoBehaviour
|
||||
return;
|
||||
}
|
||||
|
||||
print ("\n\n");
|
||||
print ("CREATING NEW CHARACTER");
|
||||
print ("\n\n");
|
||||
if (!applicationisPlaying) {
|
||||
print ("\n\n");
|
||||
print ("CREATING NEW CHARACTER");
|
||||
print ("\n\n");
|
||||
}
|
||||
|
||||
if (assignNewModelManually) {
|
||||
if (assignNewModelManually || replacingCharacterModelInRuntimeActive) {
|
||||
newModelAnimator = newCharacterModel.GetComponent<Animator> ();
|
||||
|
||||
newCharacterModel.transform.position = currentCharacterModel.transform.position;
|
||||
@@ -383,7 +505,11 @@ public class buildPlayer : MonoBehaviour
|
||||
|
||||
playerCOM = IKManager.getIKBodyCOM ();
|
||||
|
||||
currentCharacterModel.transform.SetParent (null);
|
||||
if (replacingCharacterModelInRuntimeActive) {
|
||||
currentCharacterModel.transform.SetParent (transform);
|
||||
} else {
|
||||
currentCharacterModel.transform.SetParent (null);
|
||||
}
|
||||
|
||||
newCharacterModel.transform.SetParent (playerCOM);
|
||||
|
||||
@@ -404,7 +530,9 @@ public class buildPlayer : MonoBehaviour
|
||||
|
||||
setIKUpperBodyComponents ();
|
||||
|
||||
setMapSystemComponents ();
|
||||
if (!replacingCharacterModelInRuntimeActive) {
|
||||
setMapSystemComponents ();
|
||||
}
|
||||
|
||||
setHealthWeakSpots ();
|
||||
|
||||
@@ -418,18 +546,22 @@ public class buildPlayer : MonoBehaviour
|
||||
|
||||
setCharacterCustomizationManager ();
|
||||
|
||||
if (buildPlayerType) {
|
||||
print ("\n\n");
|
||||
if (buildPlayerType && !replacingCharacterModelInRuntimeActive) {
|
||||
if (!applicationisPlaying) {
|
||||
print ("\n\n");
|
||||
|
||||
print ("Creating new player, adding all main managers into scene");
|
||||
print ("Creating new player, adding all main managers into scene");
|
||||
|
||||
print ("\n\n");
|
||||
print ("\n\n");
|
||||
}
|
||||
|
||||
GKC_Utils.addAllMainManagersToScene ();
|
||||
}
|
||||
|
||||
if (ignoreApplyCharacterSettings) {
|
||||
print ("Character settings not applied due to use the manual build with the ignore option active");
|
||||
if (!applicationisPlaying) {
|
||||
print ("Character settings not applied due to use the manual build with the ignore option active");
|
||||
}
|
||||
|
||||
} else {
|
||||
adjustSettings ();
|
||||
@@ -443,7 +575,15 @@ public class buildPlayer : MonoBehaviour
|
||||
checkUnpackCharacterPrefabActive = false;
|
||||
}
|
||||
|
||||
DestroyImmediate (currentCharacterModel);
|
||||
if (replacingCharacterModelInRuntimeActive) {
|
||||
currentCharacterModel.SetActive (false);
|
||||
|
||||
if (applicationisPlaying) {
|
||||
playerControllerManager.resetAnimatorEvenIfFullBodyAwarenessActive ();
|
||||
}
|
||||
} else {
|
||||
DestroyImmediate (currentCharacterModel);
|
||||
}
|
||||
|
||||
currentCharacterModel = newCharacterModel;
|
||||
|
||||
@@ -451,9 +591,7 @@ public class buildPlayer : MonoBehaviour
|
||||
|
||||
newModelAnimator.enabled = false;
|
||||
|
||||
// DestroyImmediate (newModelAnimator);
|
||||
|
||||
if (isInstantiated) {
|
||||
if (isInstantiated && !replacingCharacterModelInRuntimeActive) {
|
||||
placeCharacterInCameraPosition ();
|
||||
}
|
||||
|
||||
@@ -477,16 +615,20 @@ public class buildPlayer : MonoBehaviour
|
||||
|
||||
newCharacterModel = null;
|
||||
|
||||
eventOnCreatePlayer.Invoke ();
|
||||
if (!replacingCharacterModelInRuntimeActive) {
|
||||
eventOnCreatePlayer.Invoke ();
|
||||
}
|
||||
|
||||
if (currentCharacterModel != null) {
|
||||
eventToSendNewPlayerModel.Invoke (currentCharacterModel);
|
||||
}
|
||||
|
||||
updateComponent ();
|
||||
if (!replacingCharacterModelInRuntimeActive || !applicationisPlaying) {
|
||||
updateComponent ();
|
||||
|
||||
print ("IMPORTANT: Character created successfully. Remember to check the component Upper Body Rotation System, in Player Controller gameObject. In that inspector, check the value " +
|
||||
"Chest Up Vector and adjust it if the player spine behaves strange when aiming a weapon in third person. You can find a better explanation in the documentation");
|
||||
print ("IMPORTANT: Character created successfully. Remember to check the component Upper Body Rotation System, in Player Controller gameObject. In that inspector, check the value " +
|
||||
"Chest Up Vector and adjust it if the player spine behaves strange when aiming a weapon in third person. You can find a better explanation in the documentation");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -539,6 +681,12 @@ public class buildPlayer : MonoBehaviour
|
||||
if (ragdollActivatorManager != null) {
|
||||
ragdollActivatorManager.setCharacterBody (newCharacterModel, newModelAnimator);
|
||||
}
|
||||
|
||||
if (replacingCharacterModelInRuntimeActive) {
|
||||
ragdollBuilderManager.setRagdollCollidersState (false);
|
||||
|
||||
ragdollActivatorManager.enableOrDisableRagdollPhysics (false);
|
||||
}
|
||||
}
|
||||
|
||||
void setIKFootElements ()
|
||||
@@ -556,6 +704,8 @@ public class buildPlayer : MonoBehaviour
|
||||
return;
|
||||
}
|
||||
|
||||
updateApplicationisPlayingValue ();
|
||||
|
||||
checkUnpackCharacterPrefab ();
|
||||
|
||||
currentPlayerComponentsManager = player.GetComponent<playerComponentsManager> ();
|
||||
@@ -577,6 +727,13 @@ public class buildPlayer : MonoBehaviour
|
||||
updateComponent ();
|
||||
}
|
||||
|
||||
public void setCustomChestUpVectorValue (Vector3 newValue)
|
||||
{
|
||||
newChestUpVectorValue = newValue;
|
||||
|
||||
setNewChestUpVectorValueActive = (newChestUpVectorValue != -Vector3.one);
|
||||
}
|
||||
|
||||
void setIKUpperBodyComponents ()
|
||||
{
|
||||
upperBodyRotationManager.setSpineTransform (spine);
|
||||
@@ -586,19 +743,33 @@ public class buildPlayer : MonoBehaviour
|
||||
|
||||
localDirection = new Vector3 (Mathf.RoundToInt (localDirection.x), Mathf.RoundToInt (localDirection.y), Mathf.RoundToInt (localDirection.z));
|
||||
|
||||
if (setNewChestUpVectorValueActive) {
|
||||
localDirection = newChestUpVectorValue;
|
||||
|
||||
setNewChestUpVectorValueActive = false;
|
||||
}
|
||||
|
||||
upperBodyRotationManager.setNewChestUpVectorValue (localDirection);
|
||||
|
||||
Transform currentMountPointChest = mainBodyMountPointsSystem.getHumanBoneMountPointTransformByName (mainChestMountPointName);
|
||||
|
||||
if (currentMountPointChest != null) {
|
||||
print ("Chest bones names " + currentMountPointChest.name + " " + chest.name);
|
||||
if (!applicationisPlaying) {
|
||||
print ("Chest bones names " + currentMountPointChest.name + " " + chest.name);
|
||||
}
|
||||
|
||||
if (currentMountPointChest != chest) {
|
||||
mainBodyMountPointsSystem.setCustomBoneMountPointTransformByName (mainChestMountPointName, chest, true);
|
||||
|
||||
mainBodyMountPointsSystem.setIndividualCharacterBodyMountPointInfoByName (mainChestMountPointName);
|
||||
|
||||
print ("New Chest Bone assigned on mount point system\n\n");
|
||||
if (!applicationisPlaying) {
|
||||
print ("New Chest Bone assigned on mount point system\n\n");
|
||||
}
|
||||
} else {
|
||||
if (!applicationisPlaying) {
|
||||
print ("Chest bone hasn't changed on mount point, all is properly update");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -609,6 +780,7 @@ public class buildPlayer : MonoBehaviour
|
||||
mapSystemManager.searchBuildingList ();
|
||||
}
|
||||
}
|
||||
|
||||
void setHealthWeakSpots ()
|
||||
{
|
||||
if (!buildPlayerType) {
|
||||
@@ -637,10 +809,12 @@ public class buildPlayer : MonoBehaviour
|
||||
weaponsManager.setLeftHandTransform (leftHand);
|
||||
}
|
||||
|
||||
weaponsManager.setWeaponList ();
|
||||
if (!replacingCharacterModelInRuntimeActive) {
|
||||
weaponsManager.setWeaponList ();
|
||||
|
||||
if (!hasWeaponsEnabled) {
|
||||
weaponsManager.enableOrDisableWeaponsList (false);
|
||||
if (!hasWeaponsEnabled) {
|
||||
weaponsManager.enableOrDisableWeaponsList (false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -674,9 +848,7 @@ public class buildPlayer : MonoBehaviour
|
||||
playerCullingSystem currentPlayerCullingSystem = playerCameraGameObject.GetComponent<playerCullingSystem> ();
|
||||
|
||||
if (currentPlayerCullingSystem != null && currentSkinnedMeshRenderer != null) {
|
||||
currentPlayerCullingSystem.playerGameObjectList.Clear ();
|
||||
|
||||
currentPlayerCullingSystem.playerGameObjectList.Add (currentSkinnedMeshRenderer.gameObject);
|
||||
currentPlayerCullingSystem.setNewPlayerGameObject (currentSkinnedMeshRenderer.gameObject);
|
||||
|
||||
currentPlayerCullingSystem.storePlayerRendererFromEditor ();
|
||||
}
|
||||
@@ -690,11 +862,16 @@ public class buildPlayer : MonoBehaviour
|
||||
characterCustomizationManager currentCharacterCustomizationManager = GetComponentInChildren<characterCustomizationManager> ();
|
||||
|
||||
if (currentCharacterCustomizationManager != null) {
|
||||
currentInventoryCharacterCustomizationSystem.mainCharacterCustomizationManager = currentCharacterCustomizationManager;
|
||||
currentInventoryCharacterCustomizationSystem.setNewCharacterCustomizationManager (currentCharacterCustomizationManager);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public GameObject getPlayerGameObject ()
|
||||
{
|
||||
return player;
|
||||
}
|
||||
|
||||
public void setCharacterValuesAndAdjustSettingsExternally (bool characterHasBeenPreInstantiatedOnEditorValue,
|
||||
bool characterIsAI,
|
||||
bool configuredAsEnemy,
|
||||
|
||||
@@ -11,7 +11,8 @@ MonoImporter:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 40995
|
||||
packageName: Game Kit Controller - Shooter Melee Adventure Creator 3D + 2.5D
|
||||
packageVersion: 3.77g
|
||||
packageName: Game Kit Controller - Shooter Melee Adventure FPS TPS Creator 3D +
|
||||
2.5D
|
||||
packageVersion: 3.77h
|
||||
assetPath: Assets/Game Kit Controller/Scripts/Player/Character Builder/buildPlayer.cs
|
||||
uploadId: 814740
|
||||
uploadId: 889948
|
||||
|
||||
@@ -0,0 +1,170 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class characterModelElementInfo : MonoBehaviour
|
||||
{
|
||||
[Header ("Main Setting")]
|
||||
[Space]
|
||||
|
||||
public bool setNewHeightOnCharacter;
|
||||
|
||||
[Space]
|
||||
[Header ("Other Settings")]
|
||||
[Space]
|
||||
|
||||
public bool setNewAnimator;
|
||||
public RuntimeAnimatorController newRuntimeAnimatorController;
|
||||
|
||||
[Space]
|
||||
|
||||
public bool setNewChestUpVectorValueOnRuntime;
|
||||
|
||||
public Vector3 chestUpVector;
|
||||
|
||||
[Space]
|
||||
[Header ("Armor Cloth Data Settings")]
|
||||
[Space]
|
||||
|
||||
public bool setNewArmorClothData;
|
||||
|
||||
public armorClothPieceTemplateData mainArmorClothPieceTemplateData;
|
||||
|
||||
[Space]
|
||||
[Space]
|
||||
|
||||
public fullArmorClothTemplateData mainFullArmorClothTemplateData;
|
||||
|
||||
[Space]
|
||||
[Space]
|
||||
|
||||
public characterAspectCustomizationTemplateData mainCharacterAspectCustomizationTemplateData;
|
||||
|
||||
[Space]
|
||||
[Space]
|
||||
|
||||
public bool setNewArmorClothSet;
|
||||
|
||||
public characterAspectCustomizationTemplate initialCharacterAspectCustomizationTemplate;
|
||||
|
||||
[Space]
|
||||
|
||||
public bool setRandomArmorClothSet;
|
||||
|
||||
public List<characterAspectCustomizationTemplate> characterAspectCustomizationTemplateList = new List<characterAspectCustomizationTemplate> ();
|
||||
|
||||
|
||||
[Space]
|
||||
[Header ("Character Elements")]
|
||||
[Space]
|
||||
|
||||
public Transform head;
|
||||
public Transform neck;
|
||||
public Transform chest;
|
||||
public Transform spine;
|
||||
|
||||
public Transform hips;
|
||||
|
||||
public Transform rightLowerArm;
|
||||
public Transform leftLowerArm;
|
||||
public Transform rightHand;
|
||||
public Transform leftHand;
|
||||
|
||||
public Transform rightLowerLeg;
|
||||
public Transform leftLowerLeg;
|
||||
public Transform rightFoot;
|
||||
public Transform leftFoot;
|
||||
public Transform rightToes;
|
||||
public Transform leftToes;
|
||||
|
||||
[Space]
|
||||
[Header ("Ragdoll Elements")]
|
||||
[Space]
|
||||
|
||||
public bool setRagdollBonesManually;
|
||||
|
||||
public Transform rightUpperArm;
|
||||
public Transform leftUpperArm;
|
||||
|
||||
public Transform rightUpperLeg;
|
||||
public Transform leftUpperLeg;
|
||||
|
||||
public Transform middleSpine;
|
||||
public Transform pelvis;
|
||||
|
||||
[Space]
|
||||
[Header ("Components")]
|
||||
[Space]
|
||||
|
||||
public GameObject characterGameObject;
|
||||
|
||||
public Animator mainAnimator;
|
||||
|
||||
|
||||
public void getCharacterElements ()
|
||||
{
|
||||
getCharacterBones ();
|
||||
|
||||
updateComponent ();
|
||||
}
|
||||
|
||||
public void getCharacterBones ()
|
||||
{
|
||||
if (mainAnimator == null) {
|
||||
mainAnimator = GetComponent<Animator> ();
|
||||
|
||||
if (mainAnimator == null) {
|
||||
Debug.Log ("WARNING: There is not an animator component in this model, make sure to attach that component before create a new character");
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
head = mainAnimator.GetBoneTransform (HumanBodyBones.Head);
|
||||
neck = mainAnimator.GetBoneTransform (HumanBodyBones.Neck);
|
||||
|
||||
if (neck == null) {
|
||||
if (head != null) {
|
||||
neck = head.parent;
|
||||
} else {
|
||||
Debug.Log ("WARNING: no head found, assign it manually to make sure all of them are configured correctly");
|
||||
}
|
||||
}
|
||||
|
||||
chest = mainAnimator.GetBoneTransform (HumanBodyBones.Chest);
|
||||
spine = mainAnimator.GetBoneTransform (HumanBodyBones.Spine);
|
||||
|
||||
if (spine != null) {
|
||||
if (chest != null) {
|
||||
if (spine != chest.parent) {
|
||||
spine = chest.parent;
|
||||
}
|
||||
} else {
|
||||
Debug.Log ("WARNING: no chest found, assign it manually to make sure all of them are configured correctly");
|
||||
}
|
||||
} else {
|
||||
Debug.Log ("WARNING: no spine found, assign it manually to make sure all of them are configured correctly");
|
||||
}
|
||||
|
||||
hips = mainAnimator.GetBoneTransform (HumanBodyBones.Hips);
|
||||
|
||||
rightLowerArm = mainAnimator.GetBoneTransform (HumanBodyBones.RightLowerArm);
|
||||
leftLowerArm = mainAnimator.GetBoneTransform (HumanBodyBones.LeftLowerArm);
|
||||
rightHand = mainAnimator.GetBoneTransform (HumanBodyBones.RightHand);
|
||||
leftHand = mainAnimator.GetBoneTransform (HumanBodyBones.LeftHand);
|
||||
|
||||
rightLowerLeg = mainAnimator.GetBoneTransform (HumanBodyBones.RightLowerLeg);
|
||||
leftLowerLeg = mainAnimator.GetBoneTransform (HumanBodyBones.LeftLowerLeg);
|
||||
rightFoot = mainAnimator.GetBoneTransform (HumanBodyBones.RightFoot);
|
||||
leftFoot = mainAnimator.GetBoneTransform (HumanBodyBones.LeftFoot);
|
||||
rightToes = mainAnimator.GetBoneTransform (HumanBodyBones.RightToes);
|
||||
leftToes = mainAnimator.GetBoneTransform (HumanBodyBones.LeftToes);
|
||||
}
|
||||
|
||||
void updateComponent ()
|
||||
{
|
||||
GKC_Utils.updateComponent (this);
|
||||
|
||||
GKC_Utils.updateDirtyScene ("Update Character Model Info", gameObject);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 17b721e525ae0964abfa73f722765eac
|
||||
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 FPS TPS Creator 3D +
|
||||
2.5D
|
||||
packageVersion: 3.77h
|
||||
assetPath: Assets/Game Kit Controller/Scripts/Player/Character Builder/characterModelElementInfo.cs
|
||||
uploadId: 889948
|
||||
@@ -0,0 +1,389 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
|
||||
public class characterModelListManager : MonoBehaviour
|
||||
{
|
||||
[Header ("Main Setting")]
|
||||
[Space]
|
||||
|
||||
public string currentCharacterModelName;
|
||||
|
||||
[Space]
|
||||
|
||||
public List<characterModelInfo> characterModelInfoList = new List<characterModelInfo> ();
|
||||
|
||||
[Space]
|
||||
|
||||
public bool setCharacterModelOnStart;
|
||||
|
||||
public string characterModelOnStartName;
|
||||
|
||||
public bool useRandomCharacterModelOnStart;
|
||||
|
||||
[Space]
|
||||
|
||||
public bool ignoreSetInitialArmorClothSetOnChangeModel;
|
||||
|
||||
[Space]
|
||||
[Header ("Debug")]
|
||||
[Space]
|
||||
|
||||
public bool showDebugPrint;
|
||||
|
||||
public int currentCharacterModelIndex;
|
||||
|
||||
public int currentCharacterModelID;
|
||||
|
||||
[Space]
|
||||
[Header ("Event Settings")]
|
||||
[Space]
|
||||
|
||||
public bool useEventOnReplaceCharacterModel;
|
||||
public UnityEvent eventOnReplaceCharacterModel;
|
||||
|
||||
[Space]
|
||||
|
||||
public bool useEventToSendCurrentCharacterModelSelected;
|
||||
public eventParameters.eventToCallWithGameObject eventToSendCurrentCharacterModelSelected;
|
||||
|
||||
[Space]
|
||||
[Header ("Components")]
|
||||
[Space]
|
||||
|
||||
public buildPlayer mainBuildPlayer;
|
||||
public bodyMountPointsSystem mainBodyMountPointsSystem;
|
||||
public RuntimeAnimatorController originalRuntimeAnimatorController;
|
||||
public playerController mainPlayerController;
|
||||
public playerComponentsManager mainPlayerComponentsManager;
|
||||
|
||||
public ragdollBuilder mainRagdollBuilder;
|
||||
|
||||
|
||||
bool mainBuildPlayerLocated;
|
||||
|
||||
int previousCharacterModelIndex = -1;
|
||||
|
||||
void Start ()
|
||||
{
|
||||
if (setCharacterModelOnStart) {
|
||||
StartCoroutine (setCharacterModelOnStartCoroutine ());
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator setCharacterModelOnStartCoroutine ()
|
||||
{
|
||||
yield return new WaitForSeconds (0.01f);
|
||||
|
||||
string modelNameToUse = characterModelOnStartName;
|
||||
|
||||
if (useRandomCharacterModelOnStart) {
|
||||
int randomIndex = Random.Range (0, characterModelInfoList.Count);
|
||||
|
||||
modelNameToUse = characterModelInfoList [randomIndex].Name;
|
||||
}
|
||||
|
||||
replaceCharacterModel (modelNameToUse);
|
||||
}
|
||||
|
||||
public int getCurrentCharacterModelID ()
|
||||
{
|
||||
if (mainPlayerController != null) {
|
||||
return mainPlayerController.getCharacterModelID ();
|
||||
}
|
||||
|
||||
return currentCharacterModelID;
|
||||
}
|
||||
|
||||
public void replaceCharacterModelByID (int id)
|
||||
{
|
||||
int listIndex = characterModelInfoList.FindIndex (s => s.characterModelID.Equals (id));
|
||||
|
||||
if (showDebugPrint) {
|
||||
print ("replaceCharacterModelByID " + id + " " + listIndex);
|
||||
}
|
||||
|
||||
if (listIndex > -1) {
|
||||
replaceCharacterModel (characterModelInfoList [listIndex].Name);
|
||||
}
|
||||
}
|
||||
|
||||
public void replaceCharacterModel ()
|
||||
{
|
||||
//add a check to see if the play is active or not, to allow the change also on editor time, out of play mode
|
||||
|
||||
replaceCharacterModel (currentCharacterModelName);
|
||||
}
|
||||
|
||||
public void replaceCharacterModel (string name)
|
||||
{
|
||||
if (name == null || name == "") {
|
||||
return;
|
||||
}
|
||||
|
||||
int listIndex = characterModelInfoList.FindIndex (s => s.Name.Equals (name));
|
||||
|
||||
if (showDebugPrint) {
|
||||
print ("checking character name " + name + " " + listIndex);
|
||||
}
|
||||
|
||||
if (listIndex > -1) {
|
||||
if (currentCharacterModelIndex == listIndex) {
|
||||
print ("character model selected is already the current one, cancelling");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (previousCharacterModelIndex > -1) {
|
||||
characterModelInfo previousCharacterModelInfo = characterModelInfoList [previousCharacterModelIndex];
|
||||
|
||||
if (previousCharacterModelInfo.characterGameObject != null) {
|
||||
if (previousCharacterModelInfo.useEventOnSelectCharacterModel) {
|
||||
previousCharacterModelInfo.eventOnChangeToAnotherCharacterModel.Invoke ();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
previousCharacterModelIndex = currentCharacterModelIndex;
|
||||
|
||||
currentCharacterModelIndex = listIndex;
|
||||
|
||||
characterModelInfo currentCharacterModelInfo = characterModelInfoList [currentCharacterModelIndex];
|
||||
|
||||
if (currentCharacterModelInfo.characterGameObject == null) {
|
||||
currentCharacterModelInfo.characterGameObject = (GameObject)Instantiate (currentCharacterModelInfo.characterPrefab);
|
||||
}
|
||||
|
||||
characterModelElementInfo currentCharacterModelElementInfo = currentCharacterModelInfo.characterGameObject.GetComponent<characterModelElementInfo> ();
|
||||
|
||||
if (currentCharacterModelElementInfo == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!currentCharacterModelInfo.characterGameObject.activeSelf) {
|
||||
currentCharacterModelInfo.characterGameObject.SetActive (true);
|
||||
}
|
||||
|
||||
currentCharacterModelID = currentCharacterModelInfo.characterModelID;
|
||||
|
||||
currentCharacterModelElementInfo.mainAnimator.enabled = true;
|
||||
|
||||
|
||||
mainBuildPlayerLocated = mainBuildPlayer != null;
|
||||
|
||||
bool applicationisPlaying = Application.isPlaying;
|
||||
|
||||
if (mainBuildPlayerLocated) {
|
||||
inventoryCharacterCustomizationSystem currentInventoryCharacterCustomizationSystem = mainPlayerComponentsManager.getInventoryCharacterCustomizationSystem ();
|
||||
|
||||
if (currentInventoryCharacterCustomizationSystem != null) {
|
||||
if (applicationisPlaying) {
|
||||
currentInventoryCharacterCustomizationSystem.unequipAllCurrentArmorCloth ();
|
||||
}
|
||||
}
|
||||
|
||||
mainPlayerController.setCharacterModelID (currentCharacterModelInfo.characterModelID);
|
||||
|
||||
if (currentCharacterModelElementInfo.setNewAnimator) {
|
||||
mainPlayerController.setNewRuntimeAnimatorController (currentCharacterModelElementInfo.newRuntimeAnimatorController);
|
||||
} else {
|
||||
if (originalRuntimeAnimatorController != null) {
|
||||
mainPlayerController.setNewRuntimeAnimatorController (originalRuntimeAnimatorController);
|
||||
}
|
||||
}
|
||||
|
||||
mainRagdollBuilder.setCheckIfRagdollComponentsAlreadyAddedOnModelActiveState (true);
|
||||
|
||||
if (currentCharacterModelElementInfo.setRagdollBonesManually) {
|
||||
mainRagdollBuilder.setIgnoreStoreBonesByGetBoneTransformActiveState (true);
|
||||
|
||||
mainRagdollBuilder.setCharacterBones (currentCharacterModelElementInfo.head,
|
||||
currentCharacterModelElementInfo.rightLowerArm,
|
||||
currentCharacterModelElementInfo.leftLowerArm,
|
||||
currentCharacterModelElementInfo.rightUpperArm,
|
||||
currentCharacterModelElementInfo.leftUpperArm,
|
||||
currentCharacterModelElementInfo.middleSpine,
|
||||
currentCharacterModelElementInfo.pelvis,
|
||||
currentCharacterModelElementInfo.rightUpperLeg,
|
||||
currentCharacterModelElementInfo.leftUpperLeg,
|
||||
currentCharacterModelElementInfo.rightLowerLeg,
|
||||
currentCharacterModelElementInfo.leftLowerLeg);
|
||||
}
|
||||
|
||||
mainBuildPlayer.checkElementsBeforeReplacingCharacterModelInRuntime ();
|
||||
|
||||
mainBuildPlayer.setNewCharacterModelToReplaceInRuntime (currentCharacterModelInfo.characterGameObject);
|
||||
|
||||
mainBuildPlayer.setCharacterBones (
|
||||
currentCharacterModelElementInfo.head,
|
||||
currentCharacterModelElementInfo.neck,
|
||||
currentCharacterModelElementInfo.chest,
|
||||
currentCharacterModelElementInfo.spine,
|
||||
|
||||
currentCharacterModelElementInfo.hips,
|
||||
|
||||
currentCharacterModelElementInfo.rightLowerArm,
|
||||
currentCharacterModelElementInfo.leftLowerArm,
|
||||
currentCharacterModelElementInfo.rightHand,
|
||||
currentCharacterModelElementInfo.leftHand,
|
||||
|
||||
currentCharacterModelElementInfo.rightLowerLeg,
|
||||
currentCharacterModelElementInfo.leftLowerLeg,
|
||||
currentCharacterModelElementInfo.rightFoot,
|
||||
currentCharacterModelElementInfo.leftFoot,
|
||||
currentCharacterModelElementInfo.rightToes,
|
||||
currentCharacterModelElementInfo.leftToes);
|
||||
|
||||
if (currentCharacterModelElementInfo.setNewChestUpVectorValueOnRuntime) {
|
||||
mainBuildPlayer.setCustomChestUpVectorValue (currentCharacterModelElementInfo.chestUpVector);
|
||||
}
|
||||
|
||||
mainBuildPlayer.buildCharacterInRuntime ();
|
||||
|
||||
mainBuildPlayer.checkElementsAfterReplacingCharacterModelInRuntime ();
|
||||
|
||||
|
||||
if (currentCharacterModelElementInfo.setNewHeightOnCharacter) {
|
||||
if (currentCharacterModelInfo.mainAdjustCharacterHeightSystem != null) {
|
||||
currentCharacterModelInfo.mainAdjustCharacterHeightSystem.adjustHeightValueInRuntime ();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (currentInventoryCharacterCustomizationSystem != null) {
|
||||
currentInventoryCharacterCustomizationSystem.updateCharacterTransform ();
|
||||
|
||||
currentInventoryCharacterCustomizationSystem.updateCheckAssignCharacterAspectCustomizationUISystem ();
|
||||
|
||||
if (currentCharacterModelElementInfo.setNewArmorClothData) {
|
||||
currentInventoryCharacterCustomizationSystem.setNewArmorClothPieceTemplateData (currentCharacterModelElementInfo.mainArmorClothPieceTemplateData);
|
||||
currentInventoryCharacterCustomizationSystem.setNewFullArmorClothTemplateData (currentCharacterModelElementInfo.mainFullArmorClothTemplateData);
|
||||
}
|
||||
|
||||
bool setNewArmorClothSet = currentCharacterModelElementInfo.setNewArmorClothSet;
|
||||
|
||||
if (ignoreSetInitialArmorClothSetOnChangeModel) {
|
||||
currentInventoryCharacterCustomizationSystem.setInitialArmorClothPieceListState (false);
|
||||
} else {
|
||||
currentInventoryCharacterCustomizationSystem.setInitialArmorClothPieceListState (setNewArmorClothSet);
|
||||
}
|
||||
|
||||
currentInventoryCharacterCustomizationSystem.setUseCharacterAspectCustomizationTemplateState (setNewArmorClothSet);
|
||||
|
||||
if (setNewArmorClothSet) {
|
||||
currentInventoryCharacterCustomizationSystem.setInitialCharacterAspectCustomizationTemplate (
|
||||
currentCharacterModelElementInfo.initialCharacterAspectCustomizationTemplate);
|
||||
|
||||
bool setRandomArmorClothSet = currentCharacterModelElementInfo.setRandomArmorClothSet;
|
||||
|
||||
currentInventoryCharacterCustomizationSystem.setUseRandomCharacterAspectCustomizationTemplateState (setRandomArmorClothSet);
|
||||
|
||||
if (setRandomArmorClothSet) {
|
||||
currentInventoryCharacterCustomizationSystem.setCharacterAspectCustomizationTemplateList (
|
||||
currentCharacterModelElementInfo.characterAspectCustomizationTemplateList);
|
||||
}
|
||||
|
||||
if (applicationisPlaying) {
|
||||
currentInventoryCharacterCustomizationSystem.checkSetInitialArmorClothList ();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mainRagdollBuilder.setCheckIfRagdollComponentsAlreadyAddedOnModelActiveState (false);
|
||||
|
||||
mainRagdollBuilder.setIgnoreStoreBonesByGetBoneTransformActiveState (false);
|
||||
} else {
|
||||
for (int i = 0; i < characterModelInfoList.Count; i++) {
|
||||
if (i != currentCharacterModelIndex) {
|
||||
characterModelInfo characterInfo = characterModelInfoList [i];
|
||||
|
||||
if (characterInfo.characterGameObject != null) {
|
||||
if (characterInfo.characterGameObject.activeSelf) {
|
||||
characterInfo.characterGameObject.SetActive (false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (useEventOnReplaceCharacterModel) {
|
||||
eventOnReplaceCharacterModel.Invoke ();
|
||||
}
|
||||
|
||||
if (useEventToSendCurrentCharacterModelSelected) {
|
||||
eventToSendCurrentCharacterModelSelected.Invoke (currentCharacterModelInfo.characterGameObject);
|
||||
}
|
||||
|
||||
if (showDebugPrint) {
|
||||
print ("selecting " + currentCharacterModelInfo.Name);
|
||||
}
|
||||
|
||||
if (currentCharacterModelInfo.useEventOnSelectCharacterModel) {
|
||||
currentCharacterModelInfo.eventOnSelectCharacterModel.Invoke ();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setNextCharacterModel ()
|
||||
{
|
||||
setNextOrPreviousCharacterModel (true);
|
||||
}
|
||||
|
||||
public void setPreviousCharacterModel ()
|
||||
{
|
||||
setNextOrPreviousCharacterModel (false);
|
||||
}
|
||||
|
||||
public void setNextOrPreviousCharacterModel (bool state)
|
||||
{
|
||||
if (state) {
|
||||
currentCharacterModelIndex++;
|
||||
|
||||
if (currentCharacterModelIndex >= characterModelInfoList.Count) {
|
||||
currentCharacterModelIndex = 0;
|
||||
}
|
||||
} else {
|
||||
currentCharacterModelIndex--;
|
||||
|
||||
if (currentCharacterModelIndex < 0) {
|
||||
currentCharacterModelIndex = characterModelInfoList.Count - 1;
|
||||
}
|
||||
}
|
||||
|
||||
string characterModelNameToUse = characterModelInfoList [currentCharacterModelIndex].Name;
|
||||
|
||||
currentCharacterModelIndex = -1;
|
||||
|
||||
replaceCharacterModel (characterModelNameToUse);
|
||||
}
|
||||
|
||||
|
||||
[System.Serializable]
|
||||
public class characterModelInfo
|
||||
{
|
||||
[Header ("Main Setting")]
|
||||
[Space]
|
||||
|
||||
public string Name;
|
||||
|
||||
public int characterModelID;
|
||||
|
||||
[Space]
|
||||
[Header ("Components")]
|
||||
[Space]
|
||||
|
||||
public GameObject characterPrefab;
|
||||
public GameObject characterGameObject;
|
||||
|
||||
public adjustCharacterHeightSystem mainAdjustCharacterHeightSystem;
|
||||
|
||||
[Space]
|
||||
[Header ("Event Settings")]
|
||||
[Space]
|
||||
|
||||
public bool useEventOnSelectCharacterModel;
|
||||
public UnityEvent eventOnSelectCharacterModel;
|
||||
public UnityEvent eventOnChangeToAnotherCharacterModel;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bbb9bb4b290d1ce4c9608f2960e9051c
|
||||
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 FPS TPS Creator 3D +
|
||||
2.5D
|
||||
packageVersion: 3.77h
|
||||
assetPath: Assets/Game Kit Controller/Scripts/Player/Character Builder/characterModelListManager.cs
|
||||
uploadId: 889948
|
||||
@@ -13,7 +13,8 @@ MonoImporter:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 40995
|
||||
packageName: Game Kit Controller - Shooter Melee Adventure Creator 3D + 2.5D
|
||||
packageVersion: 3.77g
|
||||
packageName: Game Kit Controller - Shooter Melee Adventure FPS TPS Creator 3D +
|
||||
2.5D
|
||||
packageVersion: 3.77h
|
||||
assetPath: Assets/Game Kit Controller/Scripts/Player/Character Builder/characterSettingsTemplate.cs
|
||||
uploadId: 814740
|
||||
uploadId: 889948
|
||||
|
||||
@@ -85,6 +85,9 @@ public class ragdollBuilder : MonoBehaviour
|
||||
int direction;
|
||||
|
||||
|
||||
bool checkIfRagdollComponentsAlreadyAddedOnModelActive;
|
||||
|
||||
|
||||
public void getCharacterBonesFromEditor ()
|
||||
{
|
||||
getCharacterBones ();
|
||||
@@ -97,33 +100,69 @@ public class ragdollBuilder : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
public void setCharacterBones (Transform newHead,
|
||||
|
||||
Transform newRightElbow,
|
||||
Transform newLeftElbow,
|
||||
Transform newRightArm,
|
||||
Transform newLeftArm,
|
||||
|
||||
Transform newMiddleSpine,
|
||||
Transform newPelvis,
|
||||
|
||||
Transform newRightHips,
|
||||
Transform newLeftHips,
|
||||
Transform newRightKnee,
|
||||
Transform newLeftKnee)
|
||||
{
|
||||
|
||||
head = newHead;
|
||||
|
||||
rightElbow = newRightElbow;
|
||||
leftElbow = newLeftElbow;
|
||||
rightArm = newRightArm;
|
||||
leftArm = newLeftArm;
|
||||
|
||||
middleSpine = newMiddleSpine;
|
||||
pelvis = newPelvis;
|
||||
|
||||
rightHips = newRightHips;
|
||||
leftHips = newLeftHips;
|
||||
rightKnee = newRightKnee;
|
||||
leftKnee = newLeftKnee;
|
||||
}
|
||||
|
||||
bool ignoreStoreBonesByGetBoneTransformActive;
|
||||
|
||||
public void getCharacterBones ()
|
||||
{
|
||||
if (animator != null) {
|
||||
|
||||
bonesTransforms.Clear ();
|
||||
|
||||
pelvis = animator.GetBoneTransform (HumanBodyBones.Hips);
|
||||
if (!ignoreStoreBonesByGetBoneTransformActive) {
|
||||
pelvis = animator.GetBoneTransform (HumanBodyBones.Hips);
|
||||
|
||||
leftHips = animator.GetBoneTransform (HumanBodyBones.LeftUpperLeg);
|
||||
leftHips = animator.GetBoneTransform (HumanBodyBones.LeftUpperLeg);
|
||||
|
||||
leftKnee = animator.GetBoneTransform (HumanBodyBones.LeftLowerLeg);
|
||||
leftKnee = animator.GetBoneTransform (HumanBodyBones.LeftLowerLeg);
|
||||
|
||||
rightHips = animator.GetBoneTransform (HumanBodyBones.RightUpperLeg);
|
||||
rightHips = animator.GetBoneTransform (HumanBodyBones.RightUpperLeg);
|
||||
|
||||
rightKnee = animator.GetBoneTransform (HumanBodyBones.RightLowerLeg);
|
||||
rightKnee = animator.GetBoneTransform (HumanBodyBones.RightLowerLeg);
|
||||
|
||||
leftArm = animator.GetBoneTransform (HumanBodyBones.LeftUpperArm);
|
||||
leftArm = animator.GetBoneTransform (HumanBodyBones.LeftUpperArm);
|
||||
|
||||
leftElbow = animator.GetBoneTransform (HumanBodyBones.LeftLowerArm);
|
||||
leftElbow = animator.GetBoneTransform (HumanBodyBones.LeftLowerArm);
|
||||
|
||||
rightArm = animator.GetBoneTransform (HumanBodyBones.RightUpperArm);
|
||||
rightArm = animator.GetBoneTransform (HumanBodyBones.RightUpperArm);
|
||||
|
||||
rightElbow = animator.GetBoneTransform (HumanBodyBones.RightLowerArm);
|
||||
rightElbow = animator.GetBoneTransform (HumanBodyBones.RightLowerArm);
|
||||
|
||||
middleSpine = animator.GetBoneTransform (HumanBodyBones.Chest);
|
||||
middleSpine = animator.GetBoneTransform (HumanBodyBones.Chest);
|
||||
|
||||
head = animator.GetBoneTransform (HumanBodyBones.Head);
|
||||
head = animator.GetBoneTransform (HumanBodyBones.Head);
|
||||
}
|
||||
|
||||
//add every bone to a list
|
||||
addBonesTransforms ();
|
||||
@@ -277,7 +316,9 @@ public class ragdollBuilder : MonoBehaviour
|
||||
|
||||
GKC_Utils.updateComponent (mainRagdollActivator);
|
||||
|
||||
print ("Ragdoll Activator components assigned and updated");
|
||||
if (!Application.isPlaying) {
|
||||
print ("Ragdoll Activator components assigned and updated");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -330,7 +371,23 @@ public class ragdollBuilder : MonoBehaviour
|
||||
{
|
||||
Vector3 center = Vector3.zero;
|
||||
|
||||
removeRagdoll ();
|
||||
bool ignoreAddRagdollComponentsResult = false;
|
||||
|
||||
if (checkIfRagdollComponentsAlreadyAddedOnModelActive) {
|
||||
//check if the model has ragdoll elements on it already
|
||||
|
||||
if (pelvis != null) {
|
||||
if (pelvis.gameObject.GetComponent<BoxCollider> () != null) {
|
||||
ignoreAddRagdollComponentsResult = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//print ("ignoreAddRagdollComponentsResult " + ignoreAddRagdollComponentsResult);
|
||||
|
||||
if (!ignoreAddRagdollComponentsResult) {
|
||||
removeRagdoll ();
|
||||
}
|
||||
|
||||
for (int i = 0; i < bones.Count; i++) {
|
||||
//create capsule colliders
|
||||
@@ -376,7 +433,13 @@ public class ragdollBuilder : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
CapsuleCollider collider = bones [i].boneTransform.gameObject.AddComponent<CapsuleCollider> ();
|
||||
CapsuleCollider collider = null;
|
||||
|
||||
if (ignoreAddRagdollComponentsResult) {
|
||||
collider = bones [i].boneTransform.gameObject.GetComponent<CapsuleCollider> ();
|
||||
} else {
|
||||
collider = bones [i].boneTransform.gameObject.AddComponent<CapsuleCollider> ();
|
||||
}
|
||||
|
||||
collider.direction = direction;
|
||||
center = Vector3.zero;
|
||||
@@ -387,18 +450,31 @@ public class ragdollBuilder : MonoBehaviour
|
||||
}
|
||||
|
||||
//add rigidbodies
|
||||
bones [i].boneRigidbody = bones [i].boneTransform.gameObject.AddComponent<Rigidbody> ();
|
||||
if (ignoreAddRagdollComponentsResult) {
|
||||
bones [i].boneRigidbody = bones [i].boneTransform.gameObject.GetComponent<Rigidbody> ();
|
||||
} else {
|
||||
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> ();
|
||||
CharacterJoint joint = null;
|
||||
|
||||
if (ignoreAddRagdollComponentsResult) {
|
||||
joint = bones [i].boneTransform.gameObject.GetComponent<CharacterJoint> ();
|
||||
} else {
|
||||
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
|
||||
@@ -417,20 +493,40 @@ public class ragdollBuilder : MonoBehaviour
|
||||
|
||||
//add box colliders to the hips and spine
|
||||
Bounds boxColliderInfo;
|
||||
BoxCollider boxCollider;
|
||||
BoxCollider boxCollider = null;
|
||||
|
||||
boxColliderInfo = adjustColliderScale (getColliderSize (pelvis), pelvis, middleSpine, false);
|
||||
boxCollider = pelvis.gameObject.AddComponent<BoxCollider> ();
|
||||
|
||||
if (ignoreAddRagdollComponentsResult) {
|
||||
boxCollider = pelvis.gameObject.GetComponent<BoxCollider> ();
|
||||
} else {
|
||||
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> ();
|
||||
|
||||
if (ignoreAddRagdollComponentsResult) {
|
||||
boxCollider = middleSpine.gameObject.GetComponent<BoxCollider> ();
|
||||
} else {
|
||||
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> ();
|
||||
SphereCollider sphere = null;
|
||||
|
||||
if (ignoreAddRagdollComponentsResult) {
|
||||
sphere = head.gameObject.GetComponent<SphereCollider> ();
|
||||
} else {
|
||||
sphere = head.gameObject.AddComponent<SphereCollider> ();
|
||||
}
|
||||
|
||||
sphere.radius = radius;
|
||||
center = Vector3.zero;
|
||||
|
||||
@@ -638,6 +734,16 @@ public class ragdollBuilder : MonoBehaviour
|
||||
return direction;
|
||||
}
|
||||
|
||||
public void setCheckIfRagdollComponentsAlreadyAddedOnModelActiveState (bool state)
|
||||
{
|
||||
checkIfRagdollComponentsAlreadyAddedOnModelActive = state;
|
||||
}
|
||||
|
||||
public void setIgnoreStoreBonesByGetBoneTransformActiveState (bool state)
|
||||
{
|
||||
ignoreStoreBonesByGetBoneTransformActive = state;
|
||||
}
|
||||
|
||||
public void getAnimator (Animator anim)
|
||||
{
|
||||
animator = anim;
|
||||
@@ -651,6 +757,8 @@ public class ragdollBuilder : MonoBehaviour
|
||||
void updateComponent ()
|
||||
{
|
||||
GKC_Utils.updateComponent (this);
|
||||
|
||||
GKC_Utils.updateDirtyScene ("Update Ragdoll Builder", gameObject);
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
|
||||
@@ -13,7 +13,8 @@ MonoImporter:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 40995
|
||||
packageName: Game Kit Controller - Shooter Melee Adventure Creator 3D + 2.5D
|
||||
packageVersion: 3.77g
|
||||
packageName: Game Kit Controller - Shooter Melee Adventure FPS TPS Creator 3D +
|
||||
2.5D
|
||||
packageVersion: 3.77h
|
||||
assetPath: Assets/Game Kit Controller/Scripts/Player/Character Builder/ragdollBuilder.cs
|
||||
uploadId: 814740
|
||||
uploadId: 889948
|
||||
|
||||
Reference in New Issue
Block a user