add some extra assets FX and SFX

This commit is contained in:
Robii Aragon
2026-03-29 23:03:14 -07:00
parent 6ef3eb1535
commit 24dc66a81e
10142 changed files with 2535978 additions and 36608 deletions

View File

@@ -1,6 +1,7 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
public class pushObjectsPower : MonoBehaviour
{
@@ -9,11 +10,33 @@ public class pushObjectsPower : MonoBehaviour
public bool powerEnabled = true;
public LayerMask layer;
[Space]
public bool pushObjectsFromCenterPosition;
public bool pushObjectsFromPlayerForwardDirection;
public LayerMask layer;
[Space]
public bool useMaxAngleWithCameraFaceDirection;
public float maxAngleWithCameraFaceDirection;
[Space]
public bool useRaycastToPushObjects;
public LayerMask layerForRaycastSurfaceDetection;
public bool useMaxAngleWithPlayerFaceDirection;
public float maxAngleWithPlayerFaceDirection;
public float maxRaycastDistance;
[Space]
public List<string> ignoreTagList = new List<string> ();
@@ -60,6 +83,26 @@ public class pushObjectsPower : MonoBehaviour
public bool checkIfObjectInFrontOfPlayer;
[Space]
[Header ("Magnetize Objects To AI Settings")]
[Space]
public bool magnetizeObjectToCloseAIEnemies;
public string mountPointNameToMagnetize;
public float magnetizeForceAmount;
public float maxDistanceToMagnetize;
public bool magnetizeOnlyLockOnAI;
[Space]
public bool addLaunchedObjectComponentToDetectedObjects;
[Space]
public bool useEventsOnFoundObjectToMagnetizeResult;
public UnityEvent eventOnFoundObjectToMagnetize;
public UnityEvent eventOnNotFoundObjectToMagnetize;
[Space]
[Header ("Remote Events Settings")]
[Space]
@@ -79,6 +122,10 @@ public class pushObjectsPower : MonoBehaviour
public bool useOfPowerPaused;
public bool showGizmo;
public bool updateCoroutineActive;
[Space]
public List<Rigidbody> vehiclesRigidbodyFoundList = new List<Rigidbody> ();
@@ -96,6 +143,10 @@ public class pushObjectsPower : MonoBehaviour
public Transform pushObjectsCenter;
public Transform mainCameraTransform;
public playerCamera mainPlayerCamera;
public AIAroundManager mainAIAroundManager;
public Camera mainCamera;
Rigidbody objectToDamageMainRigidbody;
GameObject objectToPush;
@@ -106,6 +157,15 @@ public class pushObjectsPower : MonoBehaviour
bool componentsInitialized;
bool anyObjectToMagnetizeFound;
//bool anyObjectToPushFound;
Coroutine updateCoroutine;
bool mainPlayerCameraLocated;
void Start ()
{
if (!useCustomPushCenterDistance) {
@@ -118,15 +178,68 @@ public class pushObjectsPower : MonoBehaviour
centerPosition = transform;
}
}
mainPlayerCameraLocated = mainPlayerCamera != null;
}
void Update ()
//void Update ()
//{
// if (searchForObjectsOnUpdate) {
// activatePower ();
// }
//}
public void stopUpdateCoroutine ()
{
if (updateCoroutineActive) {
StopCoroutine (updateCoroutine);
}
updateCoroutineActive = false;
}
IEnumerator updateSystemCoroutine ()
{
var waitTime = new WaitForSecondsRealtime (0.0001f);
while (true) {
updateSystem ();
yield return waitTime;
}
}
void updateSystem ()
{
if (searchForObjectsOnUpdate) {
activatePower ();
}
}
public void activatePowerWithUpdate ()
{
if (searchForObjectsOnUpdate) {
if (powerEnabled) {
updateCoroutine = StartCoroutine (updateSystemCoroutine ());
updateCoroutineActive = true;
}
} else {
if (powerEnabled) {
activatePower ();
}
}
}
public void deactivatePowerWithUpdate ()
{
if (searchForObjectsOnUpdate) {
if (powerEnabled) {
stopUpdateCoroutine ();
}
}
}
public void activatePower ()
{
if (useOfPowerPaused) {
@@ -146,6 +259,10 @@ public class pushObjectsPower : MonoBehaviour
powersManager.createShootParticles ();
}
anyObjectToMagnetizeFound = false;
//anyObjectToPushFound = false;
//if the power selected is push objects, check the objects close to pushObjectsCenter and add force to them in camera forward direction
colliders = Physics.OverlapSphere (pushObjectsCenter.position, pushCenterDistance, layer);
@@ -156,6 +273,10 @@ public class pushObjectsPower : MonoBehaviour
checkObjectToApplyForce (objectToPush);
}
}
if (magnetizeObjectToCloseAIEnemies) {
checkEventsOnFoundObjectToMagnetizeResult (anyObjectToMagnetizeFound);
}
}
public void checkObjectToApplyForce (GameObject currentObject)
@@ -180,6 +301,12 @@ public class pushObjectsPower : MonoBehaviour
}
}
bool lockedCameraActive = false;
if (mainPlayerCameraLocated) {
lockedCameraActive = !mainPlayerCamera.isCameraTypeFree ();
}
Vector3 pushDirection = Vector3.zero;
if (pushObjectsFromCenterPosition) {
@@ -191,6 +318,14 @@ public class pushObjectsPower : MonoBehaviour
if (mainCameraTransform != null) {
pushDirection = mainCameraTransform.forward;
}
if (!lockedCameraActive && useMaxAngleWithCameraFaceDirection) {
float angle = Vector3.Angle (playerGameObject.transform.forward, mainCameraTransform.forward);
if (angle > maxAngleWithCameraFaceDirection) {
currentForceToApply = playerGameObject.transform.forward;
}
}
}
}
@@ -211,6 +346,8 @@ public class pushObjectsPower : MonoBehaviour
bool rigidbodyFound = false;
bool objectMagnetizedToAIResult = false;
if (canApplyForceToVehicles) {
if (objectToDamageMainRigidbody != null) {
@@ -229,21 +366,40 @@ public class pushObjectsPower : MonoBehaviour
}
if (pushObjectsFromCenterPosition) {
currentForceToApply = (objectToDamageMainRigidbody.position - centerPosition.position).normalized * finalExplosionForce;
currentForceToApply = (objectToDamageMainRigidbody.position - centerPosition.position).normalized;
} else {
if (pushObjectsFromPlayerForwardDirection) {
currentForceToApply = playerGameObject.transform.forward * finalExplosionForce;
currentForceToApply = playerGameObject.transform.forward;
} else {
currentForceToApply = mainCameraTransform.TransformDirection (Vector3.forward) * finalExplosionForce;
currentForceToApply = mainCameraTransform.TransformDirection (Vector3.forward);
if (!lockedCameraActive && useMaxAngleWithCameraFaceDirection) {
float angle = Vector3.Angle (playerGameObject.transform.forward, mainCameraTransform.forward);
if (angle > maxAngleWithCameraFaceDirection) {
currentForceToApply = playerGameObject.transform.forward;
}
}
}
}
currentForceToApply *= finalExplosionForce;
if (checkRagdollsDetected) {
if (applyDamage.isRagdollActive (currentObject)) {
// print ("ragdoll found");
currentForceToApply *= ragdollMultiplierForce;
} else {
// print ("Not found");
}
}
if (useRaycastToPushObjects) {
checkIfUseRaycastToPushObjects (objectToDamageMainRigidbody.gameObject);
}
if (magnetizeObjectToCloseAIEnemies) {
objectMagnetizedToAIResult = checkIfMagnetizeObjectToAI (objectToDamageMainRigidbody.gameObject);
if (showDebugPrint) {
print ("objectMagnetizedToAIResult " + objectMagnetizedToAIResult);
}
}
@@ -253,6 +409,14 @@ public class pushObjectsPower : MonoBehaviour
if (showDebugPrint) {
print ("object to apply force " + objectToDamageMainRigidbody.name + " " + currentForceToApply);
}
if (showGizmo) {
Debug.DrawRay (objectToDamageMainRigidbody.position, currentForceToApply.normalized * 10, Color.red, 3);
}
if (addLaunchedObjectComponentToDetectedObjects) {
checkIfAttackLaunchedObjectComponent (objectToDamageMainRigidbody.gameObject);
}
}
if (isVehicle) {
@@ -273,12 +437,34 @@ public class pushObjectsPower : MonoBehaviour
}
if (pushObjectsFromCenterPosition) {
currentForceToApply = (objectToDamageMainRigidbody.position - centerPosition.position).normalized * forceToApply;
currentForceToApply = (objectToDamageMainRigidbody.position - centerPosition.position).normalized;
} else {
if (pushObjectsFromPlayerForwardDirection) {
currentForceToApply = playerGameObject.transform.forward * forceToApply;
currentForceToApply = playerGameObject.transform.forward;
} else {
currentForceToApply = mainCameraTransform.TransformDirection (Vector3.forward) * forceToApply;
currentForceToApply = mainCameraTransform.TransformDirection (Vector3.forward);
if (!lockedCameraActive && useMaxAngleWithCameraFaceDirection) {
float angle = Vector3.Angle (playerGameObject.transform.forward, mainCameraTransform.forward);
if (angle > maxAngleWithCameraFaceDirection) {
currentForceToApply = playerGameObject.transform.forward;
}
}
}
}
currentForceToApply *= forceToApply;
if (useRaycastToPushObjects) {
checkIfUseRaycastToPushObjects (objectToDamageMainRigidbody.gameObject);
}
if (magnetizeObjectToCloseAIEnemies) {
objectMagnetizedToAIResult = checkIfMagnetizeObjectToAI (currentObject);
if (showDebugPrint) {
print ("objectMagnetizedToAIResult " + objectMagnetizedToAIResult);
}
}
@@ -286,6 +472,18 @@ public class pushObjectsPower : MonoBehaviour
objectToDamageMainRigidbody = currentObject.GetComponent<Rigidbody> ();
objectToDamageMainRigidbody.AddForce (currentForceToApply * objectToDamageMainRigidbody.mass, forceMode);
if (addLaunchedObjectComponentToDetectedObjects) {
checkIfAttackLaunchedObjectComponent (objectToDamageMainRigidbody.gameObject);
}
if (showDebugPrint) {
print ("object to apply force " + objectToDamageMainRigidbody.name + " " + currentForceToApply);
}
if (showGizmo) {
Debug.DrawRay (objectToDamageMainRigidbody.position, currentForceToApply.normalized * 10, Color.red, 3);
}
}
if (!callRemoteEventsBeforeApplyingForce) {
@@ -296,12 +494,200 @@ public class pushObjectsPower : MonoBehaviour
}
}
if (!rigidbodyFound) {
if (rigidbodyFound) {
if (magnetizeObjectToCloseAIEnemies) {
if (objectMagnetizedToAIResult) {
anyObjectToMagnetizeFound = true;
}
}
//anyObjectToPushFound = true;
} else {
checkRemoteEvent (currentObject);
}
}
}
bool checkIfMagnetizeObjectToAI (GameObject currentObject)
{
if (magnetizeObjectToCloseAIEnemies) {
Vector3 screenPoint;
float screenWidth = Screen.width;
float screenHeight = Screen.height;
List<Transform> charactersAround = mainAIAroundManager.getCharactersAround ();
if (charactersAround.Count == 0) {
return false;
}
if (charactersAround.Contains (currentObject.transform)) {
return false;
}
int charactersAroundCount = charactersAround.Count;
bool usingScreenSpaceCamera = mainPlayerCamera.isUsingScreenSpaceCamera ();
float minDistance = Mathf.Infinity;
int closestTargetIndex = -1;
Vector3 currentPosition = Vector3.zero;
Transform currentTargetToLook = mainPlayerCamera.getCurrentTargetToLook ();
if (pushObjectsFromCenterPosition) {
currentPosition = centerPosition.position;
} else {
if (pushObjectsFromPlayerForwardDirection) {
currentPosition = playerGameObject.transform.position;
} else {
if (mainCameraTransform != null) {
currentPosition = mainCameraTransform.position;
}
}
}
for (int i = 0; i < charactersAroundCount; i++) {
bool objectVisible = false;
bool targetOnScreen = false;
GameObject currentTarget = charactersAround [i].gameObject;
Vector3 targetPosition = currentTarget.transform.position;
Transform currentTargetPlaceToShoot = applyDamage.getPlaceToShoot (currentTarget);
if (currentTargetPlaceToShoot != null) {
targetPosition = currentTargetPlaceToShoot.position;
}
if (usingScreenSpaceCamera) {
screenPoint = mainCamera.WorldToViewportPoint (targetPosition);
targetOnScreen = screenPoint.z > 0 && screenPoint.x > 0 && screenPoint.x < 1 && screenPoint.y > 0 && screenPoint.y < 1;
} else {
screenPoint = mainCamera.WorldToScreenPoint (targetPosition);
targetOnScreen = screenPoint.z > 0 && screenPoint.x > 0 && screenPoint.x < screenWidth && screenPoint.y > 0 && screenPoint.y < screenHeight;
}
//the target is visible in the screen
if (targetOnScreen) {
objectVisible = true;
}
if (objectVisible) {
bool checkDistanceResult = true;
if (magnetizeOnlyLockOnAI) {
if (currentTargetToLook != null) {
if (currentTargetToLook != currentTarget) {
checkDistanceResult = false;
}
} else {
checkDistanceResult = false;
}
}
if (checkDistanceResult) {
float currentDistance = GKC_Utils.distance (currentPosition, targetPosition);
if (currentDistance < maxDistanceToMagnetize) {
if (currentDistance < minDistance) {
minDistance = currentDistance;
closestTargetIndex = i;
}
}
}
}
}
if (closestTargetIndex > -1) {
Transform currentMountPoint = GKC_Utils.getMountPointTransformByName (mountPointNameToMagnetize, charactersAround [closestTargetIndex]);
if (currentMountPoint != null) {
Vector3 pushDirection = (currentMountPoint.position - currentObject.transform.position).normalized;
currentForceToApply = pushDirection * magnetizeForceAmount;
}
return true;
} else {
return false;
}
}
return false;
}
void checkIfAttackLaunchedObjectComponent (GameObject currentObject)
{
if (addLaunchedObjectComponentToDetectedObjects) {
launchedObjects currentLaunchedObjects = currentObject.GetComponent<launchedObjects> ();
if (currentLaunchedObjects == null) {
currentLaunchedObjects = currentObject.AddComponent<launchedObjects> ();
}
if (currentLaunchedObjects != null) {
currentLaunchedObjects.setCurrentPlayer (playerGameObject);
}
}
}
void checkIfUseRaycastToPushObjects (GameObject currentObject)
{
if (useRaycastToPushObjects) {
bool lockedCameraActive = !mainPlayerCamera.isCameraTypeFree ();
if (useMaxAngleWithPlayerFaceDirection) {
if (!lockedCameraActive) {
float angle = Vector3.Angle (playerGameObject.transform.forward, mainPlayerCamera.transform.forward);
if (showDebugPrint) {
print ("useMaxAngleWithPlayerFaceDirection " + angle);
}
if (angle > maxAngleWithPlayerFaceDirection) {
return;
}
}
}
RaycastHit hit;
Vector3 raycastPosition = mainCameraTransform.position;
Vector3 raycastDirection = mainCameraTransform.forward;
if (lockedCameraActive) {
raycastPosition = playerGameObject.transform.position + playerGameObject.transform.up;
raycastDirection = playerGameObject.transform.forward;
}
Vector3 surfacePoint = Vector3.zero;
if (Physics.Raycast (raycastPosition, raycastDirection, out hit, maxRaycastDistance, layerForRaycastSurfaceDetection)) {
surfacePoint = hit.point;
if (showDebugPrint) {
print ("surface by raycast found");
}
} else {
surfacePoint = raycastPosition + raycastDirection * maxRaycastDistance;
if (showDebugPrint) {
print ("surface by raycast not found");
}
}
currentForceToApply = (surfacePoint - currentObject.transform.position).normalized * finalExplosionForce;
}
}
public void setPowerEnabledState (bool state)
{
powerEnabled = state;
@@ -311,6 +697,25 @@ public class pushObjectsPower : MonoBehaviour
if (powerEnabled) {
gameObjectsFoundList.Clear ();
}
if (searchForObjectsOnUpdate) {
if (powerEnabled) {
updateCoroutine = StartCoroutine (updateSystemCoroutine ());
updateCoroutineActive = true;
} else {
stopUpdateCoroutine ();
}
}
}
public void setPowerEnabledStateOneFrame ()
{
setPowerEnabledState (true);
activatePower ();
setPowerEnabledState (false);
}
public void cleanGameObjectFoundList ()
@@ -354,6 +759,17 @@ public class pushObjectsPower : MonoBehaviour
pushCenterDistance = newValue;
}
void checkEventsOnFoundObjectToMagnetizeResult (bool state)
{
if (useEventsOnFoundObjectToMagnetizeResult) {
if (state) {
eventOnFoundObjectToMagnetize.Invoke ();
} else {
eventOnNotFoundObjectToMagnetize.Invoke ();
}
}
}
void initializeComponents ()
{
if (componentsInitialized) {