plantilla base para movimiento básico
This commit is contained in:
Robii Aragon
2026-02-05 05:07:55 -08:00
parent 195b696771
commit 779f2c8b20
14443 changed files with 23840465 additions and 452 deletions

View File

@@ -0,0 +1,416 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
public class cuttingModeSystem : MonoBehaviour
{
[Header ("Main Settings")]
[Space]
public float cuttingPanelRotationSpeed = 5;
public float cuttingSpeed = 10;
public bool playerCanMoveOnCuttingModeActive = true;
public bool useCameraStateOnCuttingMode;
public string cameraStateNameOnCuttingMode;
public bool setBulletTime;
public float bulletTimeScale;
public float delayToSetBulletTime;
public bool canToggleCameraRotation;
public bool pauseCameraRotationAtStartOnCutModeActive = true;
[Space]
[Header ("Animation Settings")]
[Space]
public int cuttingModeStateID = 50000;
public string cuttingModeActionActiveName = "Action Active Upper Body";
public string cuttingModeActionIDName = "Action ID";
public string horizontalAnimatorName = "Horizontal Action";
public string verticalAnimatorName = "Vertical Action";
[Space]
[Header ("Stamina Settings")]
[Space]
public bool useStaminaOnSliceEnabled = true;
public string sliceStaminaState = "Slice Object";
public float staminaToUseOnSlice = 10;
public float customRefillStaminaDelayAfterSlice;
public float generalStaminaUseMultiplier = 1;
[Space]
[Header ("Other")]
[Space]
public float headTrackBodyWeightOnAim = 1;
public string customAimReticleName = "Reticle 1";
[Space]
[Header ("Debug")]
[Space]
public bool cuttingModeActive;
[Space]
[Header ("Events Settings")]
[Space]
public UnityEvent eventOnCuttingModeStart;
public UnityEvent eventOnCuttingModeEnd;
public UnityEvent eventOnCutting;
[Space]
[Header ("Components")]
[Space]
public Transform cutParticlesParent;
public GameObject cuttingPanelGameObject;
public Transform cuttingPanelTransform;
public Transform cuttingPanelTransformReference;
public Transform cuttingPanelFirstReferenceTransform;
public Transform cuttingPanelSecondReferenceTransform;
public Transform cuttingDirectionTransform;
public playerController mainPlayerController;
public playerCamera mainPlayerCamera;
public playerInputManager mainPlayerInputManager;
public timeBullet timeBulletManager;
public staminaSystem mainStaminaSystem;
public Animator mainAnimator;
public headTrack mainHeadTrack;
string previousCameraStateName;
Vector2 axisValues;
int horizontalAnimatorID;
int verticalAnimatorID;
float horizontalRotationValue;
float verticalRotationValue;
float cutDirection = 1;
Coroutine moveReferencePanelOnCutCoroutine;
Coroutine bulletTimeCoroutine;
bool cutPanelRotationActive = true;
bool sliceInputPausedForStamina;
float horizontalOffset = 0.3f;
float verticalOffset = 0.18f;
Vector2 rotationValues;
bool isPlayerMovingOn3dWorld;
bool isCameraTypeFree;
bool checkBodyAimStateActive;
void Update ()
{
if (cuttingModeActive) {
if (mainPlayerCamera.cameraCanBeUsedActive ()) {
if (cutPanelRotationActive) {
axisValues = mainPlayerInputManager.getPlayerMouseAxis ();
} else {
axisValues = Vector2.zero;
}
cuttingPanelTransform.localEulerAngles += new Vector3 (0, 0, -axisValues.x * cuttingPanelRotationSpeed);
cuttingPanelTransformReference.localEulerAngles = cuttingPanelTransform.localEulerAngles;
cuttingPanelSecondReferenceTransform.position = cuttingPanelFirstReferenceTransform.position;
horizontalRotationValue = Mathf.Clamp (cuttingPanelSecondReferenceTransform.localPosition.x + horizontalOffset, -1, 1);
verticalRotationValue = Mathf.Clamp (cuttingPanelSecondReferenceTransform.localPosition.y + verticalOffset, -1, 1);
rotationValues = new Vector2 (horizontalRotationValue, verticalRotationValue);
rotationValues = Vector2.ClampMagnitude (rotationValues, 1);
mainAnimator.SetFloat (horizontalAnimatorID, rotationValues.x);
mainAnimator.SetFloat (verticalAnimatorID, rotationValues.y);
}
}
}
public void setSliceInputPausedForStaminaState (bool state)
{
sliceInputPausedForStamina = state;
}
public void inputToggleCameraRotation ()
{
if (cuttingModeActive) {
if (canToggleCameraRotation) {
cutPanelRotationActive = !cutPanelRotationActive;
mainPlayerCamera.changeCameraRotationState (!cutPanelRotationActive);
}
}
}
public void inputActivateCut ()
{
if (cuttingModeActive) {
// stopActivateCutCoroutine ();
if (sliceInputPausedForStamina) {
// print ("Not enough stamina");
return;
}
if (cuttingInProcess) {
return;
}
if (useStaminaOnSliceEnabled) {
mainStaminaSystem.activeStaminaStateWithCustomAmount (sliceStaminaState, staminaToUseOnSlice * generalStaminaUseMultiplier, customRefillStaminaDelayAfterSlice);
}
moveReferencePanelOnCutCoroutine = StartCoroutine (activateCutCoroutine ());
cutParticlesParent.localEulerAngles += Vector3.forward * 180;
cuttingDirectionTransform.localEulerAngles += Vector3.up * 180;
eventOnCutting.Invoke ();
}
}
public void setCuttingModeActiveState (bool state)
{
cuttingModeActive = state;
if (cuttingModeActive) {
horizontalAnimatorID = Animator.StringToHash (horizontalAnimatorName);
verticalAnimatorID = Animator.StringToHash (verticalAnimatorName);
cuttingPanelTransform.localEulerAngles = Vector3.zero;
cuttingPanelTransformReference.localEulerAngles = cuttingPanelTransform.localEulerAngles;
stopActivateCutCoroutine ();
cutDirection = 1;
cuttingPanelFirstReferenceTransform.localPosition = Vector3.right * cutDirection * 1.3f;
cutParticlesParent.localEulerAngles = Vector3.zero;
cuttingDirectionTransform.localEulerAngles = Vector3.zero;
cutPanelRotationActive = true;
}
cuttingPanelGameObject.SetActive (cuttingModeActive);
if (useCameraStateOnCuttingMode) {
if (cuttingModeActive) {
previousCameraStateName = mainPlayerCamera.getCurrentStateName ();
mainPlayerCamera.setCameraStateExternally (cameraStateNameOnCuttingMode);
} else {
mainPlayerCamera.setCameraStateExternally (previousCameraStateName);
previousCameraStateName = "";
}
}
if (cuttingModeActive) {
mainAnimator.SetInteger (cuttingModeActionIDName, cuttingModeStateID);
} else {
mainAnimator.SetInteger (cuttingModeActionIDName, 0);
}
mainAnimator.SetBool (cuttingModeActionActiveName, cuttingModeActive);
if (pauseCameraRotationAtStartOnCutModeActive) {
mainPlayerCamera.changeCameraRotationState (!cuttingModeActive);
}
if (!playerCanMoveOnCuttingModeActive) {
if (cuttingModeActive) {
mainPlayerController.smoothChangeScriptState (false);
mainPlayerController.setCanMoveState (false);
mainPlayerController.resetPlayerControllerInput ();
mainPlayerController.resetOtherInputFields ();
} else {
mainPlayerController.setCanMoveState (true);
}
}
checkSetBulletTime ();
if (cuttingModeActive) {
eventOnCuttingModeStart.Invoke ();
} else {
eventOnCuttingModeEnd.Invoke ();
}
isPlayerMovingOn3dWorld = mainPlayerController.isPlayerMovingOn3dWorld ();
isCameraTypeFree = mainPlayerCamera.isCameraTypeFree ();
if (!isPlayerMovingOn3dWorld || !isCameraTypeFree) {
checkBodyAimState (state);
}
}
public void checkSetBulletTime ()
{
if (setBulletTime) {
stopCheckSetBulletTimeCoroutine ();
if (cuttingModeActive) {
bulletTimeCoroutine = StartCoroutine (checkSetBulletTimeCoroutine ());
} else {
timeBulletManager.setBulletTimeState (false, 1);
}
}
}
public void stopCheckSetBulletTimeCoroutine ()
{
if (bulletTimeCoroutine != null) {
StopCoroutine (bulletTimeCoroutine);
}
}
IEnumerator checkSetBulletTimeCoroutine ()
{
yield return new WaitForSeconds (delayToSetBulletTime);
timeBulletManager.setBulletTimeState (true, bulletTimeScale);
}
bool cuttingInProcess;
public void stopActivateCutCoroutine ()
{
if (moveReferencePanelOnCutCoroutine != null) {
StopCoroutine (moveReferencePanelOnCutCoroutine);
}
}
IEnumerator activateCutCoroutine ()
{
cuttingInProcess = true;
float movementSpeed = cuttingSpeed;
bool targetReached = false;
float positionDifference = 0;
cutDirection *= (-1);
Vector3 targetPosition = Vector3.right * (cutDirection * 1.3f);
float dist = GKC_Utils.distance (cuttingPanelFirstReferenceTransform.localPosition, targetPosition);
float duration = dist / movementSpeed;
float t = 0;
float movementTimer = 0;
while (!targetReached) {
t += Time.deltaTime / duration;
cuttingPanelFirstReferenceTransform.localPosition =
Vector3.Lerp (cuttingPanelFirstReferenceTransform.localPosition, targetPosition, t);
positionDifference = GKC_Utils.distance (cuttingPanelFirstReferenceTransform.localPosition, targetPosition);
movementTimer += Time.deltaTime;
if (positionDifference < 0.01f || movementTimer > (duration + 1)) {
targetReached = true;
}
yield return null;
}
cuttingInProcess = false;
}
public void setGeneralStaminaUseMultiplierValue (float newValue)
{
generalStaminaUseMultiplier = newValue;
}
public void setUseStaminaOnSliceEnabledState (bool state)
{
useStaminaOnSliceEnabled = state;
}
void checkBodyAimState (bool state)
{
if (mainHeadTrack == null) {
mainHeadTrack = GKC_Utils.getCharacterHeadTrack (mainPlayerController.gameObject);
}
if (mainHeadTrack == null) {
return;
}
if (checkBodyAimStateActive == state) {
return;
}
checkBodyAimStateActive = state;
if (state) {
mainHeadTrack.setCameraBodyWeightValue (headTrackBodyWeightOnAim);
} else {
mainHeadTrack.setOriginalCameraBodyWeightValue ();
}
mainHeadTrack.setHeadTrackActiveWhileAimingState (state);
mainHeadTrack.setCanUseHeadTrackOnLockedCameraActiveState (state);
mainPlayerController.enableOrDisableAiminig (state);
mainPlayerCamera.setManualAimStateOnLockedCamera (state);
if (state) {
mainPlayerCamera.enableCustomReticle (customAimReticleName);
} else {
mainPlayerCamera.disableAllCustomReticle ();
}
if (state) {
if (canToggleCameraRotation) {
cutPanelRotationActive = false;
mainPlayerCamera.changeCameraRotationState (!cutPanelRotationActive);
}
}
}
}

View File

@@ -0,0 +1,20 @@
fileFormatVersion: 2
guid: 5bff1467ec1ae8f418e1948a0080b3ca
timeCreated: 1594982617
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/Combat System/Melee Combat System/Slice
System/cuttingModeSystem.cs
uploadId: 814740

View File

@@ -0,0 +1,175 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
public class runtimeShatterRecursive : MonoBehaviour
{
[Header ("Main Settings")]
[Space]
public bool shatterEnabled = true;
public Material crossSectionMaterial;
public int numberOfShatters;
public bool addSliceComponentToPieces;
[Space]
[Header ("Objects To Shatter List Settings")]
[Space]
public List<GameObject> objectsToShatter;
public bool useCustomShatterPosition;
public Transform customShatterPosition;
[Space]
[Header ("Tag and Layer Settings")]
[Space]
public bool setNewTagOnCut;
public string newTagOnCut;
public bool setNewLayerOnCut;
public string newLayerOnCut;
[Space]
[Header ("Physics Settings")]
[Space]
public bool applyForceOnShatter;
public ForceMode forceMode;
public float forceToApplyToCutPart;
[Space]
[Header ("Others Settings")]
[Space]
public bool activateShatterAtStart;
[Space]
[Header ("Debug")]
[Space]
public bool showDebugPrint;
[Space]
[Header ("Events Settings")]
[Space]
public bool useEventOnShatter;
public UnityEvent eventOnShatter;
void Start ()
{
if (activateShatterAtStart) {
activateShatterOnObject ();
}
}
public void activateShatterOnObject ()
{
if (!shatterEnabled) {
return;
}
for (int i = 0; i < objectsToShatter.Count; i++) {
if (objectsToShatter [i] != null) {
if (objectsToShatter [i].transform.parent != null) {
objectsToShatter [i].transform.SetParent (null);
}
}
}
for (int i = 0; i < numberOfShatters; i++) {
randomShatter ();
}
checkEventOnShatter ();
if (showDebugPrint) {
print ("activate shatter on object " + gameObject.name);
}
}
public void randomShatter ()
{
List<GameObject> adders = new List<GameObject> ();
List<GameObject> removals = new List<GameObject> ();
foreach (GameObject objectToShatter in objectsToShatter) {
GameObject [] shatters = randomShatterSingle (objectToShatter);
if (shatters != null) {
foreach (GameObject add in shatters) {
adders.Add (add);
}
removals.Add (objectToShatter);
}
}
foreach (GameObject rem in removals) {
objectsToShatter.Remove (rem);
}
foreach (GameObject add in adders) {
objectsToShatter.Add (add);
}
}
public GameObject [] randomShatterSingle (GameObject objectToShatter)
{
Vector3 shatterPosition = objectToShatter.transform.position;
if (useCustomShatterPosition) {
shatterPosition = customShatterPosition.position;
}
GameObject [] shatters = sliceSystemUtils.shatterObject (objectToShatter, shatterPosition, crossSectionMaterial);
if (shatters != null && shatters.Length > 0) {
objectToShatter.SetActive (false);
Vector3 cutPosition = objectToShatter.transform.position;
// add rigidbodies and colliders
foreach (GameObject shatteredObject in shatters) {
shatteredObject.AddComponent<MeshCollider> ().convex = true;
if (applyForceOnShatter) {
Rigidbody currentObjectRigidbody = shatteredObject.AddComponent<Rigidbody> ();
currentObjectRigidbody.AddExplosionForce (forceToApplyToCutPart, cutPosition, 10, 1, forceMode);
} else {
shatteredObject.AddComponent<Rigidbody> ();
}
if (addSliceComponentToPieces) {
surfaceToSlice newSurfaceToSlice = shatteredObject.AddComponent<surfaceToSlice> ();
newSurfaceToSlice.setCrossSectionMaterial (crossSectionMaterial);
}
if (setNewLayerOnCut) {
shatteredObject.layer = LayerMask.NameToLayer (newLayerOnCut);
}
if (setNewTagOnCut) {
shatteredObject.tag = newTagOnCut;
}
}
}
return shatters;
}
public void checkEventOnShatter ()
{
if (useEventOnShatter) {
eventOnShatter.Invoke ();
}
}
}

View File

@@ -0,0 +1,20 @@
fileFormatVersion: 2
guid: 7c2ab5e2b6f547043ab73b6932dd3da6
timeCreated: 1650697508
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/Combat System/Melee Combat System/Slice
System/runtimeShatterRecursive.cs
uploadId: 814740

View File

@@ -0,0 +1,245 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
public class simpleSliceSystem : MonoBehaviour
{
[Header ("Main Settings")]
[Space]
public bool sliceEnabled = true;
public GameObject objectToSlice;
public GameObject alternatePrefab;
public Material infillMaterial;
public surfaceToSlice mainSurfaceToSlice;
public Transform[] severables = new Transform[0];
[Space]
[Header ("Slice Ragdoll Settings")]
[Space]
public string prefabsPath = "";
public Material sliceMaterial;
public bool setTagOnSkeletonRigidbodies = true;
public string tagOnSkeletonRigidbodies = "box";
[Space]
[Header ("Physics Settings")]
[Space]
public bool ignoreUpdateLastObjectSpeed;
[Space]
[Header ("Other Settings")]
[Space]
public bool ignoreDestroyOriginalObject;
public UnityEvent eventsOnIgnoreDestroyOriginalObject;
[Space]
public bool setCustomIDOnSliceSpieces;
[Space]
[Header ("Debug")]
[Space]
public bool showDebugPrint;
public bool sliceInitialized;
const string glyphs = "abcdefghijklmnopqrstuvwxyz0123456789";
string randomString = "";
public string getRandomString ()
{
return randomString;
}
public void setRandomString (string newValue)
{
if (randomString.Equals ("")) {
randomString = newValue;
}
}
public void setRandomString ()
{
if (setCustomIDOnSliceSpieces) {
if (randomString.Equals ("")) {
int charAmount = UnityEngine.Random.Range (10, 20); //set those to the minimum and maximum length of your string
for (int i = 0; i < charAmount; i++) {
randomString += glyphs [UnityEngine.Random.Range (0, glyphs.Length)];
}
}
}
}
public void destroyAllSlicedPiecesByRandomString ()
{
if (setCustomIDOnSliceSpieces && randomString != "") {
sliceSystemUtils.destroyAllSlicedPiecesByRandomString (randomString, gameObject);
}
}
void Awake ()
{
if (sliceEnabled) {
initializeValuesOnHackableComponent ();
}
}
public void initializeValuesOnHackableComponent ()
{
if (sliceInitialized) {
return;
}
sliceSystemUtils.initializeValuesOnHackableComponent (gameObject, this);
sliceInitialized = true;
}
public void setDestructionPending (bool state)
{
sliceSystemUtils.setDestructionPending (gameObject, state);
}
public void activateSlice (Collider objectCollider, Vector3 newNormalInWorldSpaceValue,
Vector3 positionInWorldSpace, Vector3 slicePosition, bool updateLastObjectSpeed, Vector3 lastSpeed)
{
if (!sliceEnabled) {
return;
}
Vector3 point = objectCollider.ClosestPointOnBounds (positionInWorldSpace);
if (mainSurfaceToSlice.useParticlesOnSlice) {
Quaternion particlesRotation = Quaternion.LookRotation (newNormalInWorldSpaceValue);
Instantiate (mainSurfaceToSlice.particlesOnSlicePrefab, slicePosition, particlesRotation);
}
sliceSystemUtils.sliceCharacter (objectToSlice, point, newNormalInWorldSpaceValue, updateLastObjectSpeed, lastSpeed);
if (showDebugPrint) {
print ("Activate Slice on Character " + objectToSlice.name);
}
}
public void searchBodyParts ()
{
if (objectToSlice == null) {
objectToSlice = gameObject;
}
List<GameObject> bodyPartsList = new List<GameObject> ();
Component[] childrens = objectToSlice.GetComponentsInChildren (typeof(Rigidbody));
int childrensLength = childrens.Length;
for (int i = 0; i < childrensLength; i++) {
Rigidbody child = childrens [i] as Rigidbody;
Collider currentCollider = child.GetComponent<Collider> ();
if (currentCollider != null && !currentCollider.isTrigger) {
bodyPartsList.Add (child.gameObject);
}
}
severables = new Transform[bodyPartsList.Count];
for (int i = 0; i < bodyPartsList.Count; i++) {
severables [i] = bodyPartsList [i].transform;
}
if (!Application.isPlaying) {
updateComponent ();
}
}
public void setTagOnBodyParts (string newTag)
{
for (int i = 0; i < severables.Length; i++) {
if (severables [i] != null) {
severables [i].tag = newTag;
}
}
}
public GameObject getMainAlternatePrefab ()
{
return alternatePrefab;
}
public Transform[] getSeverables ()
{
return severables;
}
public void setNewSeverablesList (GameObject newObject)
{
if (newObject != null) {
genericRagdollBuilder currentGenericRagdollBuilder = newObject.GetComponent<genericRagdollBuilder> ();
if (currentGenericRagdollBuilder != null) {
int bonesCount = currentGenericRagdollBuilder.bones.Count;
severables = new Transform[bonesCount];
for (int i = 0; i < bonesCount; i++) {
severables [i] = currentGenericRagdollBuilder.bones [i].anchor;
}
}
}
}
public void createRagdollPrefab ()
{
if (alternatePrefab == null) {
prefabsPath = pathInfoValues.getSliceObjectsPrefabsPath ();
alternatePrefab = GKC_Utils.createSliceRagdollPrefab (objectToSlice, prefabsPath, sliceMaterial, setTagOnSkeletonRigidbodies, tagOnSkeletonRigidbodies);
}
}
public void setSliceEnabledState (bool state)
{
sliceEnabled = state;
if (sliceEnabled) {
initializeValuesOnHackableComponent ();
}
}
public void setSliceEnabledStateFromEditor (bool state)
{
sliceEnabled = state;
updateComponent ();
}
void updateComponent ()
{
GKC_Utils.updateComponent (this);
GKC_Utils.updateDirtyScene ("Update Simple Slice System " + gameObject.name, gameObject);
}
}

View File

@@ -0,0 +1,20 @@
fileFormatVersion: 2
guid: c9863965be858744cb7a238ad41d989d
timeCreated: 1596432143
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/Combat System/Melee Combat System/Slice
System/simpleSliceSystem.cs
uploadId: 814740

View File

@@ -0,0 +1,789 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class sliceSystem : MonoBehaviour
{
[Header ("Main Settings")]
[Space]
public Vector3 cutOverlapBoxSize = new Vector3 (5, 0.1f, 5);
public bool activateRigidbodiesOnNewObjects;
public float minDelayToSliceSameObject = 0.3f;
[Space]
[Header ("Objects To Affect Settings")]
[Space]
public LayerMask targetToDamageLayer;
public bool useObjectsToIgnoreList;
public List<GameObject> objectsToIgnoreList = new List<GameObject> ();
[Space]
[Header ("Force Settings")]
[Space]
public float forceToApplyToCutPart;
public ForceMode forceMode;
public float forceRadius;
public float forceUp;
[Space]
[Header ("Damage Settings")]
[Space]
public bool activateDamageOnSlice;
public float damageAmountToApplyOnSlice;
public bool ignoreShieldOnDamage = true;
public bool canActivateReactionSystemTemporally;
public int damageReactionID = -1;
public int damageTypeID = -1;
[Space]
[Header ("Physics Settings")]
[Space]
public bool updateLastObjectSpeed;
public bool applyForcesOnObjectsDetected;
public float addForceMultiplier;
public bool applyImpactForceToVehicles;
public float impactForceToVehiclesMultiplier;
public bool checkObjectLayerAndTagToApplyForces;
public LayerMask targetToApplyForceLayer;
public List<string> tagetToApplyForceTagList = new List<string> ();
[Space]
[Header ("Slice Transform Values Settings")]
[Space]
public List<sliceTransformValuesInfo> sliceTransformValuesInfoList = new List<sliceTransformValuesInfo> ();
[Space]
[Header ("Bullet Time Settings")]
[Space]
public bool ignoreTimeBulletOnRegularSlice;
[Space]
[Header ("Gizmo Settings")]
[Space]
public bool showGizmo;
public Color gizmoColor = Color.red;
public bool showDebugPrint;
[Space]
[Header ("Components")]
[Space]
public GameObject playerGameObject;
public Material defaultSliceMaterial;
public Transform cutPositionTransform;
public Transform cutDirectionTransform;
public Transform planeDefiner1;
public Transform planeDefiner2;
public Transform planeDefiner3;
bool usingCustomCutValues;
surfaceToSlice currentSurfaceToSlice;
Collider [] hits;
List<GameObject> hitsGameObjectList = new List<GameObject> ();
bool collidersListSent;
Vector3 currentCutPosition;
Quaternion currentCutRotation;
Vector3 currentCutUp;
Vector3 currentCutForward;
Vector3 currentCutDirection;
Vector3 currentPlaneDefiner1;
Vector3 currentPlaneDefiner2;
Vector3 currentPlaneDefiner3;
Vector3 currentCutOverlapBoxSize;
bool objectsDetectedOnLastSlice;
float lastTimeSliceActivated;
public void setCustomSliceTransformValues (string sliceInfoName)
{
int sliceIndex = sliceTransformValuesInfoList.FindIndex (a => a.Name == sliceInfoName);
if (sliceIndex > -1) {
sliceTransformValuesInfo currentSliceTransformValuesInfo = sliceTransformValuesInfoList [sliceIndex];
if (currentSliceTransformValuesInfo.sliceInfoEnabled) {
setCustomCutTransformValues (currentSliceTransformValuesInfo.cutOverlapBoxSize,
currentSliceTransformValuesInfo.cutPositionTransform,
currentSliceTransformValuesInfo.cutDirectionTransform,
currentSliceTransformValuesInfo.planeDefiner1,
currentSliceTransformValuesInfo.planeDefiner2,
currentSliceTransformValuesInfo.planeDefiner3);
activateCut ();
}
}
}
public void setCustomCutTransformValues (Vector3 newCutOverlapBoxSize,
Transform newcutPositionTransform,
Transform newCutDirectionTransform,
Transform newPlaneDefiner1,
Transform newPlaneDefiner2,
Transform newPlaneDefiner3)
{
usingCustomCutValues = true;
currentCutPosition = newcutPositionTransform.position;
currentCutRotation = newcutPositionTransform.rotation;
currentCutUp = newcutPositionTransform.up;
currentCutForward = newcutPositionTransform.forward;
currentCutDirection = newCutDirectionTransform.right;
currentPlaneDefiner1 = newPlaneDefiner1.position;
currentPlaneDefiner2 = newPlaneDefiner2.position;
currentPlaneDefiner3 = newPlaneDefiner3.position;
currentCutOverlapBoxSize = newCutOverlapBoxSize;
}
void setCurrentCutTransformValues ()
{
if (usingCustomCutValues) {
usingCustomCutValues = false;
return;
}
currentCutPosition = cutPositionTransform.position;
currentCutRotation = cutPositionTransform.rotation;
currentCutUp = cutPositionTransform.up;
currentCutForward = cutPositionTransform.forward;
currentCutDirection = cutDirectionTransform.right;
currentPlaneDefiner1 = planeDefiner1.position;
currentPlaneDefiner2 = planeDefiner2.position;
currentPlaneDefiner3 = planeDefiner3.position;
currentCutOverlapBoxSize = cutOverlapBoxSize;
}
bool currentSliceActivatedExternally;
public void activateCutExternally ()
{
currentSliceActivatedExternally = true;
activateCut ();
}
public void activateCut ()
{
if (lastTimeSliceActivated > 0) {
if (Time.time > lastTimeSliceActivated + 0.7f) {
currentSliceActivatedExternally = false;
lastTimeSliceActivated = 0;
}
}
objectsDetectedOnLastSlice = false;
setCurrentCutTransformValues ();
hits = Physics.OverlapBox (currentCutPosition, currentCutOverlapBoxSize, currentCutRotation, targetToDamageLayer);
if (hits.Length > 0) {
for (int i = 0; i < hits.Length; i++) {
Collider currentCollider = hits [i];
processObject (currentCollider.gameObject, currentCollider, hits [i].ClosestPointOnBounds (currentCutPosition));
}
}
collidersListSent = false;
lastTimeSliceActivated = Time.time;
}
public List<GameObject> getLastCollidersListDetected ()
{
hitsGameObjectList.Clear ();
if (!collidersListSent) {
if (hits.Length > 0) {
for (int i = 0; i < hits.Length; i++) {
hitsGameObjectList.Add (hits [i].gameObject);
}
}
}
collidersListSent = true;
return hitsGameObjectList;
}
public void processObject (GameObject obj, Collider objectCollider, Vector3 slicePosition)
{
if (useObjectsToIgnoreList) {
if (objectsToIgnoreList.Contains (obj)) {
return;
}
}
currentSurfaceToSlice = obj.GetComponent<surfaceToSlice> ();
if (currentSurfaceToSlice == null) {
currentSurfaceToSlice = sliceSystemUtils.getSurfaceToSlice (obj);
}
bool isVehicle = applyDamage.isVehicle (obj);
if (isVehicle) {
GameObject currentVehicle = applyDamage.getVehicle (obj);
if (currentVehicle != null) {
currentSurfaceToSlice = currentVehicle.GetComponent<surfaceToSlice> ();
if (currentSurfaceToSlice != null) {
obj = currentVehicle;
}
}
}
bool objectIsSliceSurfaceDisabled = false;
bool objectCanBeSliced = false;
if (showDebugPrint) {
print ("processing object " + obj.name);
}
bool ignoreRegularDamageIfCutSurfaceNotEnabled = false;
bool isIgnoreDamageIfSliceNotActivatedActive = false;
if (currentSurfaceToSlice != null) {
bool isCutSurfaceEnabled = currentSurfaceToSlice.isCutSurfaceEnabled ();
bool sliceCanBeActivated = currentSurfaceToSlice.sliceCanBeActivated (minDelayToSliceSameObject);
bool checkSliceDirectionResult = currentSurfaceToSlice.checkSliceDirectionResult (cutPositionTransform.right, cutPositionTransform.up);
isIgnoreDamageIfSliceNotActivatedActive = currentSurfaceToSlice.isIgnoreDamageIfSliceNotActivatedActive ();
if (showDebugPrint) {
print ("Surface cut enabled state " + isCutSurfaceEnabled +
" can activate slice " + sliceCanBeActivated +
"check Slice Direction Result " + checkSliceDirectionResult);
}
if (isCutSurfaceEnabled && sliceCanBeActivated && checkSliceDirectionResult) {
Material crossSectionMaterial = currentSurfaceToSlice.getCrossSectionMaterial ();
if (crossSectionMaterial == null) {
crossSectionMaterial = defaultSliceMaterial;
}
sliceCurrentObject (obj, objectCollider, crossSectionMaterial, slicePosition);
objectsDetectedOnLastSlice = true;
objectCanBeSliced = true;
} else {
if (isVehicle && isCutSurfaceEnabled) {
objectCanBeSliced = true;
}
}
if (!isCutSurfaceEnabled) {
objectIsSliceSurfaceDisabled = true;
ignoreRegularDamageIfCutSurfaceNotEnabled = currentSurfaceToSlice.isIgnoreRegularDamageIfCutSurfaceNotEnabled ();
}
} else {
if (showDebugPrint) {
print ("Surface to slice not found on " + obj.name);
}
}
if (!objectCanBeSliced && !ignoreRegularDamageIfCutSurfaceNotEnabled) {
if (activateDamageOnSlice && !isIgnoreDamageIfSliceNotActivatedActive) {
Vector3 damagePosition = currentCutPosition;
if (applyDamage.checkIfDead (obj)) {
damagePosition = obj.transform.position;
}
applyDamage.checkCanBeDamaged (gameObject, obj, damageAmountToApplyOnSlice, -currentCutForward, damagePosition,
playerGameObject, true, true, ignoreShieldOnDamage, false, true,
canActivateReactionSystemTemporally, damageReactionID, damageTypeID);
}
if (applyForcesOnObjectsDetected && !objectIsSliceSurfaceDisabled) {
if (!checkObjectLayerAndTagToApplyForces ||
((1 << obj.layer & targetToApplyForceLayer.value) == 1 << obj.layer && tagetToApplyForceTagList.Contains (obj.tag))) {
checkForceToApplyOnObject (obj);
}
}
}
}
public void sliceCurrentObject (GameObject obj, Collider objectCollider, Material crossSectionMaterial, Vector3 slicePosition)
{
if (showDebugPrint) {
print ("\n\n");
print ("CHECKING IF OBJECT IS CHARACTER " + currentSurfaceToSlice.isObjectCharacter ());
}
// slice the provided object using the transforms of this object
if (currentSurfaceToSlice.isObjectCharacter ()) {
bool isCharacterOrVehicle = applyDamage.getCharacterOrVehicle (obj) != null;
bool objectIsDead = applyDamage.checkIfDead (obj);
if (isCharacterOrVehicle && !objectIsDead) {
if (showDebugPrint) {
print ("CONFIRMED " + obj.name + " can be sliced and is not dead, PROCESSING CHARACTER");
}
processCharacter (obj);
return;
}
if (showDebugPrint) {
print ("SLICING " + obj.name + " is character " + isCharacterOrVehicle + " is dead " + objectIsDead);
}
Rigidbody mainObject = obj.GetComponent<Rigidbody> ();
bool mainObjectHasRigidbody = mainObject != null;
Vector3 lastSpeed = Vector3.zero;
if (mainObjectHasRigidbody) {
lastSpeed = mainObject.linearVelocity;
}
currentSurfaceToSlice.checkEventBeforeSlice ();
currentSurfaceToSlice.getMainSimpleSliceSystem ().activateSlice (objectCollider, positionInWorldSpace,
normalInWorldSpace, slicePosition, updateLastObjectSpeed, lastSpeed);
currentSurfaceToSlice.checkEventOnCut ();
bool canCheckTimeBulletResult = true;
if (!currentSliceActivatedExternally) {
if (ignoreTimeBulletOnRegularSlice) {
canCheckTimeBulletResult = false;
}
}
if (canCheckTimeBulletResult) {
currentSurfaceToSlice.checkTimeBulletOnCut ();
}
} else {
bool objectSliced = false;
GameObject object1 = null;
GameObject object2 = null;
currentSurfaceToSlice.checkEventBeforeSlice ();
obj = currentSurfaceToSlice.getMainSurfaceToSlice ();
sliceSystemUtils.sliceObject (currentCutPosition, obj, currentCutUp, crossSectionMaterial, ref objectSliced, ref object1, ref object2);
Vector3 objectPosition = obj.transform.position;
Quaternion objectRotation = obj.transform.rotation;
Transform objectParent = obj.transform.parent;
if (objectSliced) {
if (currentSurfaceToSlice.useParticlesOnSlice) {
Quaternion particlesRotation = Quaternion.LookRotation (positionInWorldSpace);
Instantiate (currentSurfaceToSlice.particlesOnSlicePrefab, slicePosition, particlesRotation);
}
currentSurfaceToSlice.checkEventOnCut ();
bool canCheckTimeBulletResult = true;
if (!currentSliceActivatedExternally) {
if (ignoreTimeBulletOnRegularSlice) {
canCheckTimeBulletResult = false;
}
}
if (canCheckTimeBulletResult) {
currentSurfaceToSlice.checkTimeBulletOnCut ();
}
Rigidbody mainObject = obj.GetComponent<Rigidbody> ();
bool mainObjectHasRigidbody = mainObject != null;
object1.transform.position = objectPosition;
object1.transform.rotation = objectRotation;
object2.transform.position = objectPosition;
object2.transform.rotation = objectRotation;
if (objectParent != null) {
object1.transform.SetParent (objectParent);
object2.transform.SetParent (objectParent);
}
surfaceToSlice newSurfaceToSlice1 = object1.AddComponent<surfaceToSlice> ();
surfaceToSlice newSurfaceToSlice2 = object2.AddComponent<surfaceToSlice> ();
currentSurfaceToSlice.copySurfaceInfo (newSurfaceToSlice1);
currentSurfaceToSlice.copySurfaceInfo (newSurfaceToSlice2);
newSurfaceToSlice1.checkDestroySlicedPartsAfterDelay ();
newSurfaceToSlice2.checkDestroySlicedPartsAfterDelay ();
float distance1 = GKC_Utils.distance (obj.transform.position, object1.transform.position);
float distance2 = GKC_Utils.distance (obj.transform.position, object2.transform.position);
float currentForceToApply = forceToApplyToCutPart;
ForceMode currentForceMode = forceMode;
if (currentSurfaceToSlice.useCustomForceMode) {
currentForceMode = currentSurfaceToSlice.customForceMode;
}
if (mainObjectHasRigidbody || activateRigidbodiesOnNewObjects) {
if (currentSurfaceToSlice.useCustomForceAmount) {
currentForceToApply = currentSurfaceToSlice.customForceAmount;
}
Rigidbody object1Rigidbody = object1.AddComponent<Rigidbody> ();
Rigidbody object2Rigidbody = object2.AddComponent<Rigidbody> ();
object1Rigidbody.interpolation = RigidbodyInterpolation.Interpolate;
object2Rigidbody.interpolation = RigidbodyInterpolation.Interpolate;
object2Rigidbody.AddExplosionForce (currentForceToApply, currentCutPosition, forceRadius, forceUp, currentForceMode);
object1Rigidbody.AddExplosionForce (currentForceToApply, currentCutPosition, forceRadius, forceUp, currentForceMode);
} else {
if (currentSurfaceToSlice.useCustomForceAmount) {
currentForceToApply = currentSurfaceToSlice.customForceAmount;
}
if (distance1 < distance2) {
Rigidbody object2Rigidbody = object2.AddComponent<Rigidbody> ();
object2Rigidbody.interpolation = RigidbodyInterpolation.Interpolate;
object2Rigidbody.AddExplosionForce (currentForceToApply, currentCutPosition, forceRadius, forceUp, currentForceMode);
} else {
Rigidbody object1Rigidbody = object1.AddComponent<Rigidbody> ();
object1Rigidbody.interpolation = RigidbodyInterpolation.Interpolate;
object1Rigidbody.AddExplosionForce (currentForceToApply, currentCutPosition, forceRadius, forceUp, currentForceMode);
}
}
if (currentSurfaceToSlice.useBoxCollider) {
object1.AddComponent<BoxCollider> ();
object2.AddComponent<BoxCollider> ();
} else {
MeshCollider object1Collider = object1.AddComponent<MeshCollider> ();
MeshCollider object2Collider = object2.AddComponent<MeshCollider> ();
object1Collider.convex = true;
object2Collider.convex = true;
}
if (currentSurfaceToSlice.setNewLayerOnCut) {
object1.layer = LayerMask.NameToLayer (currentSurfaceToSlice.newLayerOnCut);
object2.layer = LayerMask.NameToLayer (currentSurfaceToSlice.newLayerOnCut);
}
if (currentSurfaceToSlice.setNewTagOnCut) {
object1.tag = currentSurfaceToSlice.tag;
object2.tag = currentSurfaceToSlice.tag;
}
obj.SetActive (false);
}
}
}
public void checkForceToApplyOnObject (GameObject objectToDamage)
{
Rigidbody objectToDamageRigidbody = objectToDamage.GetComponent<Rigidbody> ();
Vector3 forceDirection = currentCutDirection;
float forceAmount = addForceMultiplier;
float forceToVehiclesMultiplier = impactForceToVehiclesMultiplier;
if (applyImpactForceToVehicles) {
Rigidbody objectToDamageMainRigidbody = applyDamage.applyForce (objectToDamage);
if (objectToDamageMainRigidbody) {
Vector3 force = forceAmount * forceDirection;
bool isVehicle = applyDamage.isVehicle (objectToDamage);
if (isVehicle) {
force *= forceToVehiclesMultiplier;
}
objectToDamageMainRigidbody.AddForce (objectToDamageMainRigidbody.mass * force, forceMode);
}
} else {
if (applyDamage.canApplyForce (objectToDamage)) {
if (showDebugPrint) {
print (objectToDamage.name);
}
Vector3 force = forceAmount * forceDirection;
if (objectToDamageRigidbody == null) {
objectToDamageRigidbody = objectToDamage.GetComponent<Rigidbody> ();
}
objectToDamageRigidbody.AddForce (objectToDamageRigidbody.mass * force, forceMode);
}
}
}
private Vector3 positionInWorldSpace
{
get
{
return (currentPlaneDefiner1 + currentPlaneDefiner2 + currentPlaneDefiner3) / 3f;
}
}
private Vector3 normalInWorldSpace
{
get
{
Vector3 t0 = currentPlaneDefiner1;
Vector3 t1 = currentPlaneDefiner2;
Vector3 t2 = currentPlaneDefiner3;
Vector3 vectorValue;
vectorValue.x = t0.y * (t1.z - t2.z) + t1.y * (t2.z - t0.z) + t2.y * (t0.z - t1.z);
vectorValue.y = t0.z * (t1.x - t2.x) + t1.z * (t2.x - t0.x) + t2.z * (t0.x - t1.x);
vectorValue.z = t0.x * (t1.y - t2.y) + t1.x * (t2.y - t0.y) + t2.x * (t0.y - t1.y);
return vectorValue;
}
}
void processCharacter (GameObject currentCharacter)
{
StartCoroutine (processCharacterCoroutine (currentCharacter));
}
List<Collider> colliders = new List<Collider> ();
IEnumerator processCharacterCoroutine (GameObject currentCharacter)
{
applyDamage.pushCharacterWithoutForceAndPauseGetUp (currentCharacter);
if (showDebugPrint) {
print ("ragdoll " + currentCharacter.name);
}
yield return new WaitForEndOfFrame ();
List<Collider> temporalHitsList = new List<Collider> ();
if (hits.Length > 0) {
for (int i = 0; i < hits.Length; i++) {
temporalHitsList.Add (hits [i]);
}
}
Collider [] temporalHits = Physics.OverlapBox (currentCutPosition, currentCutOverlapBoxSize, currentCutRotation, targetToDamageLayer);
bool bodyPartFound = false;
if (showDebugPrint) {
print ("activating ragdoll on " + currentCharacter.name);
}
if (showDebugPrint) {
print ("\n\n");
}
if (temporalHits.Length > 0) {
bool ragdollCollidersFoundOnCharacter = false;
colliders = null;
ragdollActivator currentRagdollActivator = currentCharacter.GetComponent<ragdollActivator> ();
if (currentRagdollActivator != null) {
colliders = currentRagdollActivator.getBodyColliderList ();
if (colliders != null && colliders.Count > 0) {
ragdollCollidersFoundOnCharacter = true;
}
}
Collider colliderToCheck = null;
float minDistance = 1000;
for (int i = 0; i < temporalHits.Length; i++) {
Collider currentCollider = temporalHits [i];
if (showDebugPrint) {
print ("checking " + currentCollider.name);
}
if (!temporalHitsList.Contains (currentCollider)) {
bool canActivateSliceResult = false;
if (ragdollCollidersFoundOnCharacter) {
if (showDebugPrint) {
print ("ragoll detected");
}
if (colliders.Contains (currentCollider)) {
canActivateSliceResult = true;
if (showDebugPrint) {
print ("ragdoll part found");
}
}
} else {
canActivateSliceResult = true;
}
if (canActivateSliceResult) {
if (showDebugPrint) {
print (currentCollider.name + " body part when killing");
}
if (applyDamage.isCharacter (currentCollider.gameObject)) {
bodyPartFound = true;
float currentDistance = GKC_Utils.distance (currentCutPosition, currentCollider.transform.position);
if (currentDistance < minDistance) {
minDistance = currentDistance;
colliderToCheck = currentCollider;
}
}
}
} else {
if (showDebugPrint) {
print (currentCollider.name + " already on temporal hist list");
}
}
}
if (bodyPartFound) {
if (currentCharacter != null) {
applyDamage.killCharacter (currentCharacter);
}
processObject (colliderToCheck.gameObject, colliderToCheck, currentCutPosition);
}
}
if (showDebugPrint) {
print (temporalHits.Length + " " + bodyPartFound);
}
}
public bool anyObjectDetectedOnLastSlice ()
{
return objectsDetectedOnLastSlice;
}
#if UNITY_EDITOR
void OnDrawGizmos ()
{
if (!showGizmo) {
return;
}
if (GKC_Utils.isCurrentSelectionActiveGameObject (gameObject)) {
DrawGizmos ();
}
}
void OnDrawGizmosSelected ()
{
DrawGizmos ();
}
void DrawGizmos ()
{
if (showGizmo) {
if (usingCustomCutValues) {
GKC_Utils.drawRectangleGizmo (currentCutPosition, currentCutRotation,
Vector3.zero, currentCutOverlapBoxSize, gizmoColor);
} else {
GKC_Utils.drawRectangleGizmo (cutPositionTransform.position, cutPositionTransform.rotation,
Vector3.zero, cutOverlapBoxSize, gizmoColor);
}
}
}
#endif
[System.Serializable]
public class sliceTransformValuesInfo
{
public string Name;
public bool sliceInfoEnabled;
public Vector3 cutOverlapBoxSize = new Vector3 (5, 0.1f, 5);
public Transform cutPositionTransform;
public Transform cutDirectionTransform;
public Transform planeDefiner1;
public Transform planeDefiner2;
public Transform planeDefiner3;
}
}

View File

@@ -0,0 +1,20 @@
fileFormatVersion: 2
guid: 6f57840be6508904eb0570cc3ca3289b
timeCreated: 1594988061
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/Combat System/Melee Combat System/Slice
System/sliceSystem.cs
uploadId: 814740

View File

@@ -0,0 +1,434 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
//using EzySlice;
//using NobleMuffins.LimbHacker.Guts;
//using NobleMuffins.LimbHacker;
public class sliceSystemUtils : MonoBehaviour
{
public static void sliceObject (Vector3 slicePosition, GameObject objectToSlice, Vector3 cutDirection, Material crossSectionMaterial, ref bool objectSliced, ref GameObject object1, ref GameObject object2)
{
//SlicedHull hull = objectToSlice.SliceObject (slicePosition, cutDirection, crossSectionMaterial);
//if (hull != null) {
// objectSliced = true;
// object1 = hull.CreateLowerHull (objectToSlice, crossSectionMaterial);
// object2 = hull.CreateUpperHull (objectToSlice, crossSectionMaterial);
//}
}
public static surfaceToSlice getSurfaceToSlice (GameObject currentSurface)
{
//ChildOfHackable currentChildOfHackable = currentSurface.GetComponent<ChildOfHackable> ();
//if (currentChildOfHackable != null) {
// return currentChildOfHackable.parentHackable.mainSurfaceToSlice;
//}
return null;
}
public static void initializeValuesOnHackableComponent (GameObject objectToUse, simpleSliceSystem currentSimpleSliceSystem)
{
//Hackable currentHackable = objectToUse.GetComponent<Hackable> ();
//if (currentHackable == null) {
// currentHackable = objectToUse.AddComponent<Hackable> ();
//}
//currentHackable.mainSurfaceToSlice = currentSimpleSliceSystem.mainSurfaceToSlice;
//currentHackable.alternatePrefab = currentSimpleSliceSystem.getMainAlternatePrefab ();
//currentHackable.objectToSlice = currentSimpleSliceSystem.objectToSlice;
//currentHackable.infillMaterial = currentSimpleSliceSystem.infillMaterial;
//currentHackable.severables = currentSimpleSliceSystem.getSeverables ();
//currentHackable.ignoreUpdateLastObjectSpeed = currentSimpleSliceSystem.ignoreUpdateLastObjectSpeed;
//currentHackable.ignoreDestroyOriginalObject = currentSimpleSliceSystem.ignoreDestroyOriginalObject;
//currentHackable.eventsOnIgnoreDestroyOriginalObject = currentSimpleSliceSystem.eventsOnIgnoreDestroyOriginalObject;
//currentHackable.setCustomIDOnSliceSpieces = currentSimpleSliceSystem.setCustomIDOnSliceSpieces;
//if (currentSimpleSliceSystem.setCustomIDOnSliceSpieces) {
// currentSimpleSliceSystem.setRandomString ();
// currentHackable.setRandomString (currentSimpleSliceSystem.getRandomString ());
//}
//currentHackable.initializeValues ();
}
public static void setDestructionPending (GameObject objectToUse, bool state)
{
//Hackable currentHackable = objectToUse.GetComponent<Hackable> ();
//if (currentHackable == null) {
// currentHackable = objectToUse.AddComponent<Hackable> ();
//}
//if (currentHackable != null) {
// currentHackable.setDestructionPending (state);
//}
}
public static void sliceCharacter (GameObject objectToSlice, Vector3 point, Vector3 newNormalInWorldSpaceValue,
bool updateLastObjectSpeed, Vector3 lastSpeed)
{
if (objectToSlice == null) {
return;
}
//Hackable currentHackable = objectToSlice.GetComponent<Hackable> ();
//if (currentHackable != null) {
// currentHackable.activateSlice (objectToSlice, point, newNormalInWorldSpaceValue, updateLastObjectSpeed, lastSpeed);
//}
}
public static GameObject[] shatterObject (GameObject obj, Vector3 shatterPosition, Material crossSectionMaterial = null, bool shaterActive = true)
{
//if (shaterActive) {
// return obj.SliceInstantiate (getRandomPlane (shatterPosition, obj.transform.localScale),
// new TextureRegion (0.0f, 0.0f, 1.0f, 1.0f),
// crossSectionMaterial);
//}
return null;
}
//public static EzySlice.Plane getRandomPlane (Vector3 positionOffset, Vector3 scaleOffset)
//{
// Vector3 randomPosition = Random.insideUnitSphere;
// Vector3 randomDirection = Random.insideUnitSphere.normalized;
// return new EzySlice.Plane (randomPosition, randomDirection);
//}
public static void destroyAllSlicedPiecesByRandomString (string stringValue, GameObject mainObjectToIgnore)
{
//Hackable[] HackableList = FindObjectsOfType<Hackable> ();
//int HackableListLength = HackableList.Length;
//for (int i = 0; i < HackableListLength; i++) {
// Hackable currentHackable = HackableList [i] as Hackable;
// if (mainObjectToIgnore != currentHackable.gameObject && currentHackable.getRandomString ().Equals (stringValue)) {
// Destroy (currentHackable.gameObject);
// }
//}
}
public static void processObjectToSlice (GameObject objectToCheck, Collider objectCollider,
Vector3 slicePosition, Quaternion sliceRotation,
float minDelayToSliceSameObject, Vector3 sliceUpDirection,
Vector3 sliceRightDirection, Vector3 sliceForwardDirection,
float forceToApplyToCutPart, LayerMask targetToDamageLayer,
bool randomSliceDirection, bool showSliceGizmo,
bool activateRigidbodiesOnNewObjects)
{
surfaceToSlice currentSurfaceToSlice = objectToCheck.GetComponent<surfaceToSlice> ();
if (currentSurfaceToSlice == null) {
currentSurfaceToSlice = sliceSystemUtils.getSurfaceToSlice (objectToCheck);
}
if (currentSurfaceToSlice != null) {
bool isCutSurfaceEnabled = currentSurfaceToSlice.isCutSurfaceEnabled ();
if (isCutSurfaceEnabled && currentSurfaceToSlice.sliceCanBeActivated (minDelayToSliceSameObject)) {
sliceCurrentObject (currentSurfaceToSlice, objectToCheck, objectCollider,
currentSurfaceToSlice.getCrossSectionMaterial (),
slicePosition, sliceRotation, sliceUpDirection, sliceRightDirection,
sliceForwardDirection, forceToApplyToCutPart, minDelayToSliceSameObject,
targetToDamageLayer, randomSliceDirection, showSliceGizmo, activateRigidbodiesOnNewObjects);
}
}
}
public static void sliceCurrentObject (surfaceToSlice currentSurfaceToSlice, GameObject objectToCheck,
Collider objectCollider, Material crossSectionMaterial,
Vector3 slicePosition, Quaternion sliceRotation,
Vector3 sliceUpDirection, Vector3 sliceRightDirection, Vector3 sliceForwardDirection,
float forceToApplyToCutPart, float minDelayToSliceSameObject,
LayerMask targetToDamageLayer, bool randomSliceDirection, bool showSliceGizmo,
bool activateRigidbodiesOnNewObjects)
{
if (currentSurfaceToSlice.isObjectCharacter ()) {
if (applyDamage.getCharacterOrVehicle (objectToCheck) != null && !applyDamage.checkIfDead (objectToCheck)) {
processCharacter (objectToCheck, slicePosition, sliceRotation,
minDelayToSliceSameObject, sliceUpDirection,
sliceRightDirection, sliceForwardDirection, forceToApplyToCutPart,
targetToDamageLayer, randomSliceDirection, showSliceGizmo, activateRigidbodiesOnNewObjects);
return;
}
Rigidbody mainObject = objectToCheck.GetComponent<Rigidbody> ();
bool mainObjectHasRigidbody = mainObject != null;
Vector3 lastSpeed = Vector3.zero;
if (mainObjectHasRigidbody) {
lastSpeed = mainObject.linearVelocity;
}
Vector3 planeDefiner1 = slicePosition - 0.2f * sliceForwardDirection;
Vector3 planeDefiner2 = slicePosition + 0.2f * sliceRightDirection;
Vector3 planeDefiner3 = slicePosition - 0.2f * sliceRightDirection;
Vector3 positionInWorldSpace = (planeDefiner1 + planeDefiner2 + planeDefiner3) / 3f;
Vector3 normalInWorldSpace = Vector3.zero;
Vector3 t0 = planeDefiner1;
Vector3 t1 = planeDefiner2;
Vector3 t2 = planeDefiner3;
normalInWorldSpace.x = t0.y * (t1.z - t2.z) + t1.y * (t2.z - t0.z) + t2.y * (t0.z - t1.z);
normalInWorldSpace.y = t0.z * (t1.x - t2.x) + t1.z * (t2.x - t0.x) + t2.z * (t0.x - t1.x);
normalInWorldSpace.z = t0.x * (t1.y - t2.y) + t1.x * (t2.y - t0.y) + t2.x * (t0.y - t1.y);
if (showSliceGizmo) {
Vector3 rayDirection1 = slicePosition;
Vector3 rayDirection2 = sliceForwardDirection;
Debug.DrawRay (rayDirection1, rayDirection2, Color.blue, 5);
rayDirection1 = slicePosition + sliceForwardDirection + sliceRightDirection;
rayDirection2 = sliceRightDirection;
Debug.DrawRay (rayDirection1, rayDirection2, Color.blue, 5);
rayDirection1 = slicePosition - sliceForwardDirection + sliceRightDirection;
rayDirection2 = sliceRightDirection;
Debug.DrawRay (rayDirection1, rayDirection2, Color.blue, 5);
}
currentSurfaceToSlice.checkEventBeforeSlice ();
currentSurfaceToSlice.getMainSimpleSliceSystem ().activateSlice (objectCollider, positionInWorldSpace,
normalInWorldSpace, slicePosition, true, lastSpeed);
currentSurfaceToSlice.checkEventOnCut ();
currentSurfaceToSlice.checkTimeBulletOnCut ();
} else {
bool objectSliced = false;
GameObject object1 = null;
GameObject object2 = null;
Vector3 sliceDirection = sliceUpDirection;
if (randomSliceDirection) {
sliceDirection = Quaternion.Euler (Random.Range (0, 361) * sliceForwardDirection) * sliceDirection;
}
currentSurfaceToSlice.checkEventBeforeSlice ();
objectToCheck = currentSurfaceToSlice.getMainSurfaceToSlice ();
sliceSystemUtils.sliceObject (slicePosition, objectToCheck, sliceDirection, crossSectionMaterial, ref objectSliced, ref object1, ref object2);
Vector3 objectPosition = objectToCheck.transform.position;
Quaternion objectRotation = objectToCheck.transform.rotation;
Transform objectParent = objectToCheck.transform.parent;
if (objectSliced) {
if (currentSurfaceToSlice.useParticlesOnSlice) {
Vector3 planeDefiner1 = slicePosition - 0.2f * sliceForwardDirection;
Vector3 planeDefiner2 = slicePosition + 0.2f * sliceRightDirection;
Vector3 planeDefiner3 = slicePosition - 0.2f * sliceRightDirection;
Vector3 positionInWorldSpace = (planeDefiner1 + planeDefiner2 + planeDefiner3) / 3f;
Quaternion particlesRotation = Quaternion.LookRotation (positionInWorldSpace);
Instantiate (currentSurfaceToSlice.particlesOnSlicePrefab, slicePosition, particlesRotation);
}
currentSurfaceToSlice.checkEventOnCut ();
currentSurfaceToSlice.checkTimeBulletOnCut ();
Rigidbody mainObject = objectToCheck.GetComponent<Rigidbody> ();
bool mainObjectHasRigidbody = mainObject != null;
object1.transform.position = objectPosition;
object1.transform.rotation = objectRotation;
object2.transform.position = objectPosition;
object2.transform.rotation = objectRotation;
if (objectParent != null) {
object1.transform.SetParent (objectParent);
object2.transform.SetParent (objectParent);
}
surfaceToSlice newSurfaceToSlice1 = object1.AddComponent<surfaceToSlice> ();
surfaceToSlice newSurfaceToSlice2 = object2.AddComponent<surfaceToSlice> ();
currentSurfaceToSlice.copySurfaceInfo (newSurfaceToSlice1);
currentSurfaceToSlice.copySurfaceInfo (newSurfaceToSlice2);
newSurfaceToSlice1.checkDestroySlicedPartsAfterDelay ();
newSurfaceToSlice2.checkDestroySlicedPartsAfterDelay ();
float currentForceToApply = forceToApplyToCutPart;
ForceMode currentForceMode = ForceMode.Impulse;
if (currentSurfaceToSlice.useCustomForceMode) {
currentForceMode = currentSurfaceToSlice.customForceMode;
}
if (mainObjectHasRigidbody || activateRigidbodiesOnNewObjects) {
if (currentSurfaceToSlice.useCustomForceAmount) {
currentForceToApply = currentSurfaceToSlice.customForceAmount;
}
Rigidbody object1Rigidbody = object1.AddComponent<Rigidbody> ();
Rigidbody object2Rigidbody = object2.AddComponent<Rigidbody> ();
object2Rigidbody.AddExplosionForce (currentForceToApply, slicePosition, 10, 1, currentForceMode);
object1Rigidbody.AddExplosionForce (currentForceToApply, slicePosition, 10, 1, currentForceMode);
} else {
if (currentSurfaceToSlice.useCustomForceAmount) {
currentForceToApply = currentSurfaceToSlice.customForceAmount;
}
Rigidbody object2Rigidbody = object2.AddComponent<Rigidbody> ();
object2Rigidbody.AddExplosionForce (currentForceToApply, slicePosition, 10, 1, currentForceMode);
Rigidbody object1Rigidbody = object1.AddComponent<Rigidbody> ();
object1Rigidbody.AddExplosionForce (currentForceToApply, slicePosition, 10, 1, currentForceMode);
}
if (currentSurfaceToSlice.useBoxCollider) {
object1.AddComponent<BoxCollider> ();
object2.AddComponent<BoxCollider> ();
} else {
MeshCollider object1Collider = object1.AddComponent<MeshCollider> ();
MeshCollider object2Collider = object2.AddComponent<MeshCollider> ();
object1Collider.convex = true;
object2Collider.convex = true;
}
if (currentSurfaceToSlice.setNewLayerOnCut) {
object1.layer = LayerMask.NameToLayer (currentSurfaceToSlice.newLayerOnCut);
object2.layer = LayerMask.NameToLayer (currentSurfaceToSlice.newLayerOnCut);
}
if (currentSurfaceToSlice.setNewTagOnCut) {
object1.tag = currentSurfaceToSlice.newTagOnCut;
object2.tag = currentSurfaceToSlice.newTagOnCut;
}
objectToCheck.SetActive (false);
}
}
}
public static void processCharacter (GameObject currentCharacter, Vector3 slicePosition, Quaternion sliceRotation,
float minDelayToSliceSameObject, Vector3 sliceUpDirection,
Vector3 sliceRightDirection, Vector3 sliceForwardDirection,
float forceToApplyToCutPart, LayerMask targetToDamageLayer,
bool randomSliceDirection, bool showSliceGizmo,
bool activateRigidbodiesOnNewObjects)
{
applyDamage.pushCharacterWithoutForceAndPauseGetUp (currentCharacter);
Collider[] temporalHits = Physics.OverlapBox (slicePosition, new Vector3 (0.2f, 0.2f, 0.2f), sliceRotation,
targetToDamageLayer);
if (showSliceGizmo) {
Vector3 rayDirection1 = slicePosition;
Vector3 rayDirection2 = sliceForwardDirection;
Debug.DrawRay (rayDirection1, rayDirection2, Color.blue, 5);
rayDirection1 = slicePosition + sliceForwardDirection + sliceRightDirection;
rayDirection2 = sliceRightDirection;
Debug.DrawRay (rayDirection1, rayDirection2, Color.blue, 5);
rayDirection1 = slicePosition - sliceForwardDirection + sliceRightDirection;
rayDirection2 = sliceRightDirection;
Debug.DrawRay (rayDirection1, rayDirection2, Color.blue, 5);
}
bool bodyPartFound = false;
if (temporalHits.Length > 0) {
if (showSliceGizmo) {
print ("objects detected amount " + temporalHits.Length);
for (int i = 0; i < temporalHits.Length; i++) {
print (temporalHits [i].name);
}
}
Collider colliderToCheck = null;
float minDistance = 1000;
for (int i = 0; i < temporalHits.Length; i++) {
Collider currentCollider = temporalHits [i];
if (applyDamage.isCharacter (currentCollider.gameObject)) {
bodyPartFound = true;
float currentDistance = GKC_Utils.distance (slicePosition, currentCollider.transform.position);
if (currentDistance < minDistance) {
minDistance = currentDistance;
colliderToCheck = currentCollider;
}
}
}
if (bodyPartFound) {
if (currentCharacter != null) {
applyDamage.killCharacter (currentCharacter);
}
if (showSliceGizmo) {
print ("body part detected " + colliderToCheck.name);
}
processObjectToSlice (colliderToCheck.gameObject, colliderToCheck,
slicePosition, sliceRotation,
minDelayToSliceSameObject, sliceUpDirection,
sliceRightDirection, sliceForwardDirection,
forceToApplyToCutPart, targetToDamageLayer, randomSliceDirection, showSliceGizmo,
activateRigidbodiesOnNewObjects);
}
}
}
}

View File

@@ -0,0 +1,20 @@
fileFormatVersion: 2
guid: 30cb00ac6203f75449414e05cf26c702
timeCreated: 1603579394
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/Combat System/Melee Combat System/Slice
System/sliceSystemUtils.cs
uploadId: 814740