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,483 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;
public class attrackObjectsSystem : MonoBehaviour
{
[Header ("Main Settings")]
[Space]
public bool attractionEnabled;
public bool attractionApplyForce = true;
public bool attractionActive;
public float attractionRadius = 20;
public LayerMask layerToSearch;
public float attractionVelocity = 10;
public float attractionForce = 1000;
public ForceMode forceMode;
public float maxThrowForce = 3500;
public float increaseThrowForceSpeed = 1500;
public List<string> tagToLocate = new List<string> ();
public LayerMask layerToDamage;
[Space]
[Header ("Remote Events Settings")]
[Space]
public bool useRemoteEventOnObjectsFound;
public List<string> remoteEventNameListOnGrabObject = new List<string> ();
public List<string> remoteEventNameListOnDropObject = new List<string> ();
[Space]
[Header ("Debug")]
[Space]
public bool carryingObjects;
[Space]
[Header ("Events Settings")]
[Space]
public UnityEvent eventsOnActivateAttraction;
public UnityEvent eventOnDeactivateAttraction;
[Space]
[Header ("Components")]
[Space]
public Slider powerSlider;
public Transform mainCameraTransform;
public Transform attractionPosition;
public Collider playerCollider;
public GameObject playerGameObject;
public playerWeaponSystem mainPlayerWeaponSystem;
float currentForceToLaunchObjects;
Rigidbody currentRigidbody;
Vector3 attractDirection;
Vector3 currentPosition;
RaycastHit hit;
List<grabbedObject> grabbedObjectList = new List<grabbedObject> ();
float lastTimeActivateAttraction;
Vector3 nextObjectHeldPosition;
Vector3 currentObjectHeldPosition;
Coroutine grabObjectsCoroutine;
bool componentsInitialized;
void Awake ()
{
if (mainCameraTransform == null) {
mainCameraTransform = transform;
}
if (playerGameObject == null) {
playerGameObject = gameObject;
}
}
void FixedUpdate ()
{
if (attractionActive) {
if (!carryingObjects) {
return;
}
currentPosition = attractionPosition.position;
for (int i = 0; i < grabbedObjectList.Count; i++) {
if (grabbedObjectList [i].objectToMove != null) {
currentRigidbody = grabbedObjectList [i].mainRigidbody;
if (currentRigidbody != null) {
if (attractionApplyForce) {
attractDirection = currentPosition - currentRigidbody.position;
currentRigidbody.AddForce (attractDirection.normalized * (attractionForce * currentRigidbody.mass * Time.fixedDeltaTime), forceMode);
} else {
nextObjectHeldPosition = currentPosition + attractionPosition.forward;
currentObjectHeldPosition = currentRigidbody.position;
currentRigidbody.linearVelocity = (nextObjectHeldPosition - currentObjectHeldPosition) * attractionVelocity;
}
}
}
}
}
}
public void setAttractionEnabledState (bool state)
{
attractionEnabled = state;
}
public void checkGrabObject ()
{
if (grabObjectsCoroutine != null) {
StopCoroutine (grabObjectsCoroutine);
}
grabObjectsCoroutine = StartCoroutine (checkGrabObjectCoroutine ());
}
IEnumerator checkGrabObjectCoroutine ()
{
yield return new WaitForSeconds (0.05f);
if (attractionEnabled && !carryingObjects) {
lastTimeActivateAttraction = Time.time;
initializeComponents ();
attractionActive = true;
grabCloseObjects ();
if (carryingObjects) {
eventsOnActivateAttraction.Invoke ();
}
}
}
public void inputGrabObjects ()
{
checkGrabObject ();
}
public void inputHoldToLaunchObject ()
{
if (!attractionEnabled) {
return;
}
if (carryingObjects) {
if (Time.time > lastTimeActivateAttraction + 0.5f) {
addForceToLaunchObjects ();
}
}
}
public void inputReleaseToLaunchObject ()
{
if (!attractionEnabled) {
return;
}
if (carryingObjects) {
if (Time.time > lastTimeActivateAttraction + 0.5f) {
dropObjects ();
attractionActive = false;
eventOnDeactivateAttraction.Invoke ();
}
}
}
public void grabCloseObjects ()
{
//if the player has not grabbedObjects, store them
if (grabbedObjectList.Count == 0) {
//check in a radius, the close objects which can be grabbed
currentPosition = attractionPosition.position;
int ignoreRaycastLayerIndex = LayerMask.NameToLayer ("Ignore Raycast");
Collider[] objects = Physics.OverlapSphere (currentPosition, attractionRadius, layerToSearch);
foreach (Collider currentCollider in objects) {
Rigidbody currentRigidbody = currentCollider.GetComponent<Rigidbody> ();
if (tagToLocate.Contains (currentCollider.tag) && currentRigidbody != null) {
if (currentRigidbody.isKinematic) {
currentRigidbody.isKinematic = false;
}
grabbedObject newGrabbedObject = new grabbedObject ();
//removed tag and layer after store them, so the camera can still use raycast properly
GameObject currentObject = currentCollider.gameObject;
newGrabbedObject.objectToMove = currentObject;
newGrabbedObject.objectTag = currentObject.tag;
newGrabbedObject.objectLayer = currentObject.layer;
newGrabbedObject.mainRigidbody = currentRigidbody;
if (useRemoteEventOnObjectsFound) {
remoteEventSystem currentRemoteEventSystem = currentObject.GetComponent<remoteEventSystem> ();
if (currentRemoteEventSystem != null) {
for (int i = 0; i < remoteEventNameListOnGrabObject.Count; i++) {
currentRemoteEventSystem.callRemoteEvent (remoteEventNameListOnGrabObject [i]);
}
}
}
currentObject.tag = "Untagged";
currentObject.layer = ignoreRaycastLayerIndex;
currentRigidbody.useGravity = false;
//get the distance from every object to left and right side of the player, to set every side as parent of every object
//disable collisions between the player and the objects, to avoid issues
if (playerCollider != null) {
Physics.IgnoreCollision (currentCollider, playerCollider, true);
}
//if any object grabbed has its own gravity, paused the script to move the object properly
artificialObjectGravity currentArtificialObjectGravity = currentObject.GetComponent<artificialObjectGravity> ();
if (currentArtificialObjectGravity != null) {
currentArtificialObjectGravity.setActiveState (false);
}
grabObjectProperties currentGrabObjectProperties = currentObject.GetComponent<grabObjectProperties> ();
if (currentGrabObjectProperties != null) {
currentGrabObjectProperties.checkEventsOnGrabObject ();
}
grabbedObjectState currentGrabbedObjectState = currentObject.GetComponent<grabbedObjectState> ();
if (currentGrabbedObjectState == null) {
currentGrabbedObjectState = currentObject.AddComponent<grabbedObjectState> ();
}
objectToPlaceSystem currentObjectToPlaceSystem = currentObject.GetComponent<objectToPlaceSystem> ();
if (currentObjectToPlaceSystem != null) {
currentObjectToPlaceSystem.setObjectInGrabbedState (true);
}
//if any object is pickable and is inside an opened chest, activate its trigger or if it has been grabbed by the player, remove of the list
pickUpObject currentPickUpObject = currentObject.GetComponent<pickUpObject> ();
if (currentPickUpObject) {
currentPickUpObject.activateObjectTrigger ();
}
deviceStringAction currentDeviceStringAction = currentObject.GetComponentInChildren<deviceStringAction> ();
if (currentDeviceStringAction != null) {
currentDeviceStringAction.setIconEnabledState (false);
}
if (currentGrabbedObjectState != null) {
currentGrabbedObjectState.setCurrentHolder (gameObject);
currentGrabbedObjectState.setGrabbedState (true);
}
grabbedObjectList.Add (newGrabbedObject);
}
}
//if there are not any object close to the player, cancel
if (grabbedObjectList.Count > 0) {
carryingObjects = true;
} else {
attractionActive = false;
}
powerSlider.maxValue = maxThrowForce;
currentForceToLaunchObjects = 0;
}
}
//drop or throw the current grabbed objects
public void dropObjects ()
{
//get the point at which the camera is looking, to throw the objects in that direction
Vector3 hitDirection = Vector3.zero;
bool surfaceFound = false;
if (Physics.Raycast (mainCameraTransform.position, mainCameraTransform.forward, out hit, Mathf.Infinity, layerToDamage)) {
if (hit.collider != playerCollider) {
surfaceFound = true;
} else {
if (Physics.Raycast (hit.point + mainCameraTransform.forward, mainCameraTransform.forward, out hit, Mathf.Infinity, layerToDamage)) {
surfaceFound = true;
}
}
}
if (surfaceFound) {
hitDirection = hit.point;
}
for (int j = 0; j < grabbedObjectList.Count; j++) {
dropObject (grabbedObjectList [j], hitDirection);
}
carryingObjects = false;
grabbedObjectList.Clear ();
powerSlider.value = 0;
}
public void addForceToLaunchObjects ()
{
if (currentForceToLaunchObjects < maxThrowForce) {
//enable the power slider in the center of the screen
currentForceToLaunchObjects += Time.deltaTime * increaseThrowForceSpeed;
if (currentForceToLaunchObjects > 300) {
powerSlider.value = currentForceToLaunchObjects;
}
}
}
public void dropObject (grabbedObject currentGrabbedObject, Vector3 launchDirection)
{
GameObject currentObject = currentGrabbedObject.objectToMove;
Rigidbody currentRigidbody = currentGrabbedObject.mainRigidbody;
if (useRemoteEventOnObjectsFound) {
remoteEventSystem currentRemoteEventSystem = currentObject.GetComponent<remoteEventSystem> ();
if (currentRemoteEventSystem != null) {
for (int i = 0; i < remoteEventNameListOnDropObject.Count; i++) {
currentRemoteEventSystem.callRemoteEvent (remoteEventNameListOnDropObject [i]);
}
}
}
currentObject.transform.SetParent (null);
currentObject.tag = currentGrabbedObject.objectTag;
currentObject.layer = currentGrabbedObject.objectLayer;
//drop the objects, because the grab objects button has been pressed quickly
if (currentForceToLaunchObjects < 300) {
if (playerCollider != null) {
Physics.IgnoreCollision (currentObject.GetComponent<Collider> (), playerCollider, false);
}
}
//launch the objects according to the amount of time that the player has held the buttton
if (currentForceToLaunchObjects > 300) {
//if the objects are launched, add the script launchedObject, to damage any enemy that the object would touch
currentObject.AddComponent<launchedObjects> ().setCurrentPlayerAndCollider (playerGameObject, playerCollider);
//if there are any collider in from of the camera, use the hit point, else, use the camera direciton
if (launchDirection != Vector3.zero) {
Vector3 throwDirection = launchDirection - currentObject.transform.position;
throwDirection = throwDirection / throwDirection.magnitude;
currentRigidbody.AddForce (throwDirection * currentForceToLaunchObjects * currentRigidbody.mass);
} else {
currentRigidbody.AddForce (mainCameraTransform.TransformDirection (Vector3.forward) * currentForceToLaunchObjects * currentRigidbody.mass);
}
}
//set again the custom gravity of the object
artificialObjectGravity currentArtificialObjectGravity = currentObject.GetComponent<artificialObjectGravity> ();
if (currentArtificialObjectGravity != null) {
currentArtificialObjectGravity.setActiveState (true);
}
grabObjectProperties currentGrabObjectProperties = currentObject.GetComponent<grabObjectProperties> ();
if (currentGrabObjectProperties != null) {
currentGrabObjectProperties.checkEventsOnDropObject ();
}
deviceStringAction currentDeviceStringAction = currentObject.GetComponentInChildren<deviceStringAction> ();
if (currentDeviceStringAction != null) {
currentDeviceStringAction.setIconEnabledState (true);
}
objectToPlaceSystem currentObjectToPlaceSystem = currentObject.GetComponent<objectToPlaceSystem> ();
if (currentObjectToPlaceSystem != null) {
currentObjectToPlaceSystem.setObjectInGrabbedState (false);
}
grabbedObjectState currentGrabbedObjectState = currentObject.GetComponent<grabbedObjectState> ();
if (currentGrabbedObjectState != null) {
bool currentObjectWasInsideGravityRoom = currentGrabbedObjectState.isInsideZeroGravityRoom ();
currentGrabbedObjectState.checkGravityRoomState ();
currentGrabbedObjectState.setGrabbedState (false);
if (!currentObjectWasInsideGravityRoom) {
currentGrabbedObjectState.removeGrabbedObjectComponent ();
currentRigidbody.useGravity = true;
}
}
}
public void checkIfDropObject (GameObject objectToCheck)
{
for (int j = 0; j < grabbedObjectList.Count; j++) {
if (grabbedObjectList [j].objectToMove == objectToCheck) {
dropObject (grabbedObjectList [j], Vector3.zero);
grabbedObjectList [j].objectToMove = null;
return;
}
}
}
void initializeComponents ()
{
if (componentsInitialized) {
return;
}
if (mainPlayerWeaponSystem != null) {
playerGameObject = mainPlayerWeaponSystem.getPlayerWeaponsManger ().gameObject;
playerComponentsManager mainPlayerComponentsManager = playerGameObject.GetComponent<playerComponentsManager> ();
if (mainPlayerComponentsManager != null) {
playerCollider = mainPlayerComponentsManager.getPlayerController ().getMainCollider ();
mainCameraTransform = mainPlayerComponentsManager.getPlayerCamera ().getCameraTransform ();
}
}
componentsInitialized = true;
}
[System.Serializable]
public class grabbedObject
{
public GameObject objectToMove;
public string objectTag;
public int objectLayer;
public Rigidbody mainRigidbody;
}
}

View File

@@ -0,0 +1,19 @@
fileFormatVersion: 2
guid: 7c4ed1378b9b48f4baad80588ea81c88
timeCreated: 1561244023
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/Weapons/New Weapon Behaviors/attrackObjectsSystem.cs
uploadId: 814740

View File

@@ -0,0 +1,295 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
public class dragObjectSystem : MonoBehaviour
{
[Header ("Main Settings")]
[Space]
public float distanceToPlayer;
public float checkObstacleRaycastDistance;
public float dragObjectSpeed = 36;
public bool obstacleFound;
public float minDistanceToDropObject = 1;
public float playerDistance;
public float adjustObjectPositionSpeed = 5;
[Space]
[Header ("Debug")]
[Space]
public bool showDebugPrint;
public bool objectGrabbed;
[Space]
[Header ("Event Settings")]
[Space]
public UnityEvent eventOnFarFromObject;
[Space]
[Header ("Components")]
[Space]
public Rigidbody mainRigidbody;
public Transform playerDragPosition;
public Transform rightIKHandPosition;
public Transform leftIKHandPosition;
public Transform mainTransform;
public Collider obstacleTrigger;
Transform currentPlayerTransform;
Vector2 axisValues;
playerInputManager playerInput;
Ray ray;
Vector3 rigidbodyPosition;
Vector3 currentPoint;
Vector3 objectPosition;
Vector3 objectDirection;
Vector3 objectRotation;
float objectXPosition;
float objectZPosition;
Coroutine objectMovement;
bool adjustingObjectPosition;
float extraAngle;
Coroutine mainUpdateCoroutine;
public void stopUpdateCoroutine ()
{
if (mainUpdateCoroutine != null) {
StopCoroutine (mainUpdateCoroutine);
}
}
IEnumerator updateCoroutine ()
{
var waitTime = new WaitForFixedUpdate ();
while (true) {
if (objectGrabbed) {
dragObject ();
}
yield return waitTime;
}
}
public void dragObject ()
{
if (adjustingObjectPosition) {
return;
}
ray = new Ray (currentPlayerTransform.position, currentPlayerTransform.forward);
axisValues = playerInput.getPlayerMovementAxis ();
currentPoint = ray.GetPoint (distanceToPlayer);
objectPosition = new Vector3 (currentPoint.x, mainTransform.position.y, currentPoint.z);
objectDirection = Quaternion.Euler (currentPlayerTransform.eulerAngles) * new Vector3 (axisValues.x, 0, axisValues.y);
ray = new Ray (mainTransform.position, objectDirection);
currentPoint = ray.GetPoint (checkObstacleRaycastDistance);
if (objectDirection.magnitude > 0) {
obstacleTrigger.transform.position = currentPoint;
} else {
obstacleTrigger.transform.localPosition = Vector3.zero;
}
rigidbodyPosition = mainRigidbody.position;
objectXPosition = Mathf.Clamp (rigidbodyPosition.x - objectPosition.x, -0.1f, 0.1f);
objectZPosition = Mathf.Clamp (rigidbodyPosition.z - objectPosition.z, -0.1f, 0.1f);
objectPosition = new Vector3 (objectPosition.x + objectXPosition, mainTransform.position.y, objectPosition.z + objectZPosition);
mainRigidbody.position = Vector3.Lerp (mainTransform.position, objectPosition, dragObjectSpeed * Time.fixedDeltaTime);
objectRotation = mainTransform.eulerAngles;
objectRotation.y = (currentPlayerTransform.eulerAngles).y + extraAngle;
mainTransform.eulerAngles = objectRotation;
playerDistance = GKC_Utils.distance (playerDragPosition.position, currentPlayerTransform.position);
if (playerDistance >= minDistanceToDropObject) {
eventOnFarFromObject.Invoke ();
}
}
public void setCurrentPlayer (GameObject newPlayer)
{
currentPlayerTransform = newPlayer.transform;
playerInput = currentPlayerTransform.GetComponent<playerInputManager> ();
}
public void grabObject ()
{
translateObjectToGrabPosition ();
if (mainTransform == null) {
mainTransform = transform;
}
objectGrabbed = true;
stopUpdateCoroutine ();
mainUpdateCoroutine = StartCoroutine (updateCoroutine ());
}
public void dropObject ()
{
objectGrabbed = false;
if (adjustingObjectPosition) {
stopTranslateObjectToGrabPosition ();
adjustingObjectPosition = false;
}
stopUpdateCoroutine ();
}
public void setObstacleFoundState (bool state)
{
obstacleFound = state;
mainRigidbody.isKinematic = state;
}
public void translateObjectToGrabPosition ()
{
stopTranslateObjectToGrabPosition ();
objectMovement = StartCoroutine (translateObjectToGrabPositionCoroutine ());
}
public void stopTranslateObjectToGrabPosition ()
{
if (objectMovement != null) {
StopCoroutine (objectMovement);
}
}
IEnumerator translateObjectToGrabPositionCoroutine ()
{
float dist = GKC_Utils.distance (mainTransform.position, currentPlayerTransform.position);
float duration = dist / adjustObjectPositionSpeed;
float t = 0;
float movementTimer = 0;
bool targetReached = false;
adjustingObjectPosition = true;
ray = new Ray (currentPlayerTransform.position, currentPlayerTransform.forward);
currentPoint = ray.GetPoint (distanceToPlayer);
objectPosition = new Vector3 (currentPoint.x, mainTransform.position.y, currentPoint.z);
rigidbodyPosition = mainRigidbody.position;
objectXPosition = Mathf.Clamp (rigidbodyPosition.x - objectPosition.x, -0.1f, 0.1f);
objectZPosition = Mathf.Clamp (rigidbodyPosition.z - objectPosition.z, -0.1f, 0.1f);
objectPosition = new Vector3 (objectPosition.x + objectXPosition, mainTransform.position.y, objectPosition.z + objectZPosition);
Vector3 currentPlayerPosition = currentPlayerTransform.position;
currentPlayerPosition.y = 0;
Vector3 currentObjectPosition = mainTransform.position;
currentObjectPosition.y = 0;
Vector3 playerDirection = (currentObjectPosition - currentPlayerPosition).normalized;
if (showDebugPrint) {
print (playerDirection);
}
extraAngle = Vector3.SignedAngle (playerDirection, mainTransform.forward, Vector3.up);
if (showDebugPrint) {
print (extraAngle);
}
int orientation = (extraAngle > 0) ? 1 : -1;
float extraAngleABS = Mathf.Abs (extraAngle);
if (showDebugPrint) {
print (extraAngleABS);
}
if (extraAngleABS < 45) {
extraAngle = 0;
}
if (extraAngleABS > 45 && extraAngleABS < 135) {
extraAngle = 90;
}
if (extraAngleABS > 135 && extraAngleABS < 235) {
extraAngle = 180;
}
if (extraAngleABS > 235) {
extraAngle = 270;
}
extraAngle *= orientation;
if (showDebugPrint) {
print (extraAngle);
}
Vector3 targetEuler = currentPlayerTransform.eulerAngles + mainTransform.up * extraAngle;
Quaternion targetRotation = Quaternion.Euler (targetEuler);
while (!targetReached) {
t += Time.deltaTime * duration;
mainTransform.position = Vector3.Lerp (mainTransform.position, objectPosition, t);
mainTransform.rotation = Quaternion.Slerp (mainTransform.rotation, targetRotation, t);
movementTimer += Time.deltaTime;
if (GKC_Utils.distance (mainTransform.position, objectPosition) < 0.01f || movementTimer > (duration + 1)) {
targetReached = true;
}
yield return null;
}
adjustingObjectPosition = false;
playerDragPosition.position = currentPlayerTransform.position;
}
}

View File

@@ -0,0 +1,19 @@
fileFormatVersion: 2
guid: a9208c9ad3a1f1744ab44dc960e0dc49
timeCreated: 1559702019
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/Weapons/New Weapon Behaviors/dragObjectSystem.cs
uploadId: 814740

View File

@@ -0,0 +1,359 @@
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using GameKitController.Audio;
using UnityEngine.Events;
public class flamethrowerWeapon : MonoBehaviour
{
[Space]
[Header ("Main Settings")]
[Space]
public bool useEnergyEnabled = true;
public float useEnergyRate;
public int amountEnergyUsed;
[Space]
[Header ("Sound Settings")]
[Space]
public float playSoundRate;
public float minDelayToPlaySound;
[Space]
public AudioClip soundEffect;
public AudioElement soundEffectAudioElement;
public AudioClip startSoundEffect;
public AudioElement startSoundEffectAudioElement;
public AudioClip endSoundEffect;
public AudioElement endSoundEffectAudioElement;
[Space]
[Header ("Debug")]
[Space]
public bool weaponEnabled;
public bool reloading;
public bool updateCoroutineActive;
[Space]
[Header ("Events Settings")]
[Space]
public bool useEventsOnWeaponStateChange;
public UnityEvent eventOnWeaponEnabled;
public UnityEvent eventOnWeaponDisabled;
[Space]
[Header ("Components")]
[Space]
public bool configuredOnWeapon = true;
public playerWeaponSystem weaponManager;
public ParticleSystem mainParticleSystem;
public AudioSource mainAudioSource;
public AudioSource startAudioSource;
public AudioSource endAudioSource;
float lastTimeUsed;
float lastTimeSoundPlayed;
bool initialSoundWaitChecked;
Coroutine updateCoroutine;
bool ignoreDisableCoroutine;
bool canPlaySound;
bool isWeaponReloading;
bool remainAmmoInClip;
bool soundEffectAudioElementLocated;
bool startSoundEffectAudioElementLocated;
bool endSoundEffectAudioElementLocated;
public void stopUpdateCoroutine ()
{
if (updateCoroutine != null) {
StopCoroutine (updateCoroutine);
}
updateCoroutineActive = false;
}
IEnumerator updateSystemCoroutine ()
{
var waitTime = new WaitForFixedUpdate ();
while (true) {
updateSystem ();
yield return waitTime;
}
}
void updateSystem ()
{
canPlaySound = true;
if (configuredOnWeapon) {
isWeaponReloading = weaponManager.isWeaponReloading ();
remainAmmoInClip = weaponManager.remainAmmoInClip ();
if (reloading) {
if (remainAmmoInClip && weaponManager.carryingWeapon () && !isWeaponReloading) {
reloading = false;
} else {
return;
}
}
if (reloading) {
return;
}
if (!weaponEnabled) {
return;
}
if(useEnergyEnabled){
if (Time.time > lastTimeUsed + useEnergyRate) {
if (remainAmmoInClip && !isWeaponReloading) {
lastTimeUsed = Time.time;
weaponManager.useAmmo (amountEnergyUsed);
weaponManager.checkToUpdateInventoryWeaponAmmoTextFromWeaponSystem ();
}
if (!remainAmmoInClip || isWeaponReloading) {
ignoreDisableCoroutine = true;
setWeaponState (false);
ignoreDisableCoroutine = false;
reloading = true;
return;
}
}
}
if (!remainAmmoInClip || isWeaponReloading) {
canPlaySound = false;
}
}
if (weaponEnabled && canPlaySound) {
if (Time.time > lastTimeSoundPlayed + playSoundRate) {
if (initialSoundWaitChecked || Time.time > lastTimeSoundPlayed + minDelayToPlaySound) {
lastTimeSoundPlayed = Time.time;
playWeaponSoundEffect ();
initialSoundWaitChecked = true;
}
}
}
}
public void enableWeapon ()
{
setWeaponState (true);
}
public void disableWeapon ()
{
setWeaponState (false);
reloading = false;
}
public void setWeaponState (bool state)
{
if (reloading) {
bool weaponEnabledPreviously = weaponEnabled;
weaponEnabled = false;
if (!weaponEnabledPreviously) {
return;
} else {
if (!state) {
weaponEnabled = true;
}
}
}
initializeComponents ();
if (weaponEnabled == state) {
return;
}
weaponEnabled = state;
if (mainParticleSystem != null) {
if (weaponEnabled) {
mainParticleSystem.Play ();
} else {
mainParticleSystem.Stop ();
}
}
if (weaponEnabled) {
playWeaponStartSoundEffect ();
} else {
playWeaponEndSoundEffect ();
}
checkEventsOnStateChange (weaponEnabled);
initialSoundWaitChecked = false;
lastTimeSoundPlayed = 0;
if (!weaponEnabled) {
stopWeaponSoundEffect ();
}
if (ignoreDisableCoroutine) {
return;
}
if (weaponEnabled) {
updateCoroutine = StartCoroutine (updateSystemCoroutine ());
updateCoroutineActive = true;
} else {
stopUpdateCoroutine ();
}
}
public void stopUpdateCoroutineIfActive ()
{
if (updateCoroutineActive) {
stopUpdateCoroutine ();
}
}
void playWeaponSoundEffect ()
{
if (soundEffectAudioElementLocated) {
AudioPlayer.PlayOneShot (soundEffectAudioElement, gameObject);
}
}
void stopWeaponSoundEffect ()
{
if (soundEffectAudioElementLocated) {
AudioPlayer.Stop (soundEffectAudioElement, gameObject);
}
}
void playWeaponStartSoundEffect ()
{
if (startSoundEffectAudioElementLocated) {
AudioPlayer.PlayOneShot (startSoundEffectAudioElement, gameObject);
}
}
void playWeaponEndSoundEffect ()
{
if (endSoundEffectAudioElementLocated) {
AudioPlayer.PlayOneShot (endSoundEffectAudioElement, gameObject);
}
}
void checkEventsOnStateChange (bool state)
{
if (useEventsOnWeaponStateChange) {
if (state) {
eventOnWeaponEnabled.Invoke ();
} else {
eventOnWeaponDisabled.Invoke ();
}
}
}
bool componentsInitialized;
void initializeComponents ()
{
if (componentsInitialized) {
return;
}
setObjectParentSystem mainSetObjectParentSystem = GetComponent<setObjectParentSystem> ();
if (mainSetObjectParentSystem != null) {
if (mainSetObjectParentSystem.getParentTransform () == null) {
if (weaponManager != null) {
playerWeaponsManager mainPlayerWeaponsManager = weaponManager.getPlayerWeaponsManger ();
GameObject playerControllerGameObject = mainPlayerWeaponsManager.gameObject;
playerComponentsManager mainPlayerComponentsManager = playerControllerGameObject.GetComponent<playerComponentsManager> ();
if (mainPlayerComponentsManager != null) {
playerController mainPlayerController = mainPlayerComponentsManager.getPlayerController ();
if (mainPlayerController != null) {
GameObject playerParentGameObject = mainPlayerController.getPlayerManagersParentGameObject ();
if (playerParentGameObject != null) {
mainSetObjectParentSystem.setParentTransform (playerParentGameObject.transform);
}
}
}
}
}
}
if (soundEffect != null) {
soundEffectAudioElement.clip = soundEffect;
soundEffectAudioElementLocated = true;
}
if (mainAudioSource != null) {
soundEffectAudioElement.audioSource = mainAudioSource;
}
if (startSoundEffect != null) {
startSoundEffectAudioElement.clip = startSoundEffect;
startSoundEffectAudioElementLocated = true;
}
if (startAudioSource != null) {
startSoundEffectAudioElement.audioSource = startAudioSource;
}
if (endSoundEffect != null) {
endSoundEffectAudioElement.clip = endSoundEffect;
endSoundEffectAudioElementLocated = true;
}
if (endAudioSource != null) {
endSoundEffectAudioElement.audioSource = endAudioSource;
}
componentsInitialized = true;
}
}

View File

@@ -0,0 +1,19 @@
fileFormatVersion: 2
guid: a7eed63f9b871f940ac453a7c425e4e0
timeCreated: 1627291084
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/Weapons/New Weapon Behaviors/flamethrowerWeapon.cs
uploadId: 814740

View File

@@ -0,0 +1,347 @@
using System.Collections;
using System.Collections.Generic;
using GameKitController.Audio;
using UnityEngine;
using UnityEngine.UI;
public class flashlight : MonoBehaviour
{
[Header ("Main Settings")]
[Space]
public bool flashlightEnabled = true;
public bool infiniteEnergy;
public float useEnergyRate;
public int amountEnergyUsed;
public float lightRotationSpeed = 10;
public bool usedThroughWeaponSystem = true;
[Space]
[Header ("Intensity Settings")]
[Space]
public bool useHighIntentity;
public float highIntensityAmount;
[Space]
[Header ("Sound Settings")]
[Space]
public bool useSound;
public AudioClip turnOnSound;
public AudioElement turnOnAudioElement;
public AudioClip turnOffSound;
public AudioElement turnOffAudioElement;
[Space]
[Header ("UI Settings")]
[Space]
public bool useFlashlightIndicatorPanel;
public Slider mainSlider;
public GameObject flahslightIndicatorPanel;
[Space]
[Header ("Debug")]
[Space]
public bool isActivated;
public bool reloading;
public bool usingFlashlight;
public bool flashLightInputPausedState;
[Space]
[Header ("Components")]
[Space]
public playerWeaponsManager weaponsManager;
public playerWeaponSystem weaponManager;
public GameObject mainLight;
public Light mainFlashlight;
public AudioSource mainAudioSource;
public GameObject flashlightMeshes;
bool highIntensityActivated;
float lastTimeUsed;
Transform mainCameraTransform;
float originalIntensity;
Quaternion targetRotation;
bool UIElementsLocated;
private void InitializeAudioElements ()
{
if (mainAudioSource == null) {
mainAudioSource = GetComponent<AudioSource> ();
}
if (mainAudioSource != null) {
turnOnAudioElement.audioSource = mainAudioSource;
turnOffAudioElement.audioSource = mainAudioSource;
}
if (turnOnSound != null) {
turnOnAudioElement.clip = turnOnSound;
}
if (turnOffSound != null) {
turnOffAudioElement.clip = turnOffSound;
}
}
void Start ()
{
InitializeAudioElements ();
if (weaponManager == null) {
weaponManager = GetComponent<playerWeaponSystem> ();
}
if (mainFlashlight == null) {
mainFlashlight = mainLight.GetComponent<Light> ();
}
originalIntensity = mainFlashlight.intensity;
if (!flashlightEnabled) {
enableOrDisableFlashlightMeshes (false);
}
}
void Update ()
{
if (usedThroughWeaponSystem) {
if (isActivated) {
if (mainCameraTransform != null) {
if (!weaponManager.weaponIsMoving () && (weaponManager.aimingInThirdPerson || weaponManager.carryingWeaponInFirstPerson)
&& !weaponsManager.isEditinWeaponAttachments ()) {
targetRotation = Quaternion.LookRotation (mainCameraTransform.forward);
mainLight.transform.rotation = Quaternion.Slerp (mainLight.transform.rotation, targetRotation, Time.deltaTime * lightRotationSpeed);
//mainLight.transform.rotation = targetRotation;
} else {
targetRotation = Quaternion.identity;
mainLight.transform.localRotation = Quaternion.Slerp (mainLight.transform.localRotation, targetRotation, Time.deltaTime * lightRotationSpeed);
//mainLight.transform.localRotation = targetRotation;
}
} else {
mainCameraTransform = weaponManager.getMainCameraTransform ();
}
if (infiniteEnergy) {
return;
}
if (Time.time > lastTimeUsed + useEnergyRate) {
if (weaponManager.remainAmmoInClip () && !weaponManager.isWeaponReloading ()) {
lastTimeUsed = Time.time;
weaponManager.useAmmo (amountEnergyUsed);
weaponManager.checkToUpdateInventoryWeaponAmmoTextByWeaponNumberKey ();
}
if (!weaponManager.remainAmmoInClip () || weaponManager.isWeaponReloading ()) {
setFlashlightState (false);
reloading = true;
}
}
} else {
if (reloading) {
if (weaponManager.remainAmmoInClip () && weaponManager.carryingWeapon () && !weaponManager.isWeaponReloading ()) {
setFlashlightState (true);
reloading = false;
}
}
}
if (usingFlashlight) {
if (useFlashlightIndicatorPanel) {
if (!infiniteEnergy) {
if (UIElementsLocated) {
mainSlider.value = weaponManager.getWeaponClipSize ();
}
}
}
}
}
}
public bool checkIfEnoughBattery ()
{
if (infiniteEnergy) {
return true;
}
if (usedThroughWeaponSystem) {
if (!weaponManager.remainAmmoInClip ()) {
return false;
}
}
return true;
}
public void changeFlashLightState ()
{
if (flashLightInputPausedState) {
return;
}
setFlashlightState (!isActivated);
}
public void setFlashlightState (bool state)
{
if (state) {
if (!checkIfEnoughBattery ()) {
return;
}
if (!flashlightEnabled) {
return;
}
}
initializeComponents ();
isActivated = state;
playSound (isActivated);
if (mainLight.activeSelf != isActivated) {
mainLight.SetActive (isActivated);
}
}
public void turnOn ()
{
if (!checkIfEnoughBattery ()) {
return;
}
if (!flashlightEnabled) {
return;
}
isActivated = true;
playSound (isActivated);
}
public void turnOff ()
{
isActivated = false;
playSound (isActivated);
}
public void playSound (bool state)
{
if (useSound) {
GKC_Utils.checkAudioSourcePitch (mainAudioSource);
if (state) {
AudioPlayer.PlayOneShot (turnOnAudioElement, gameObject);
} else {
AudioPlayer.PlayOneShot (turnOffAudioElement, gameObject);
}
}
}
public void changeLightIntensity (bool state)
{
if (useHighIntentity) {
highIntensityActivated = state;
if (highIntensityActivated) {
mainFlashlight.intensity = highIntensityAmount;
} else {
mainFlashlight.intensity = originalIntensity;
}
}
}
public void setHighIntensity ()
{
if (usedThroughWeaponSystem) {
if (weaponsManager.isFullBodyAwarenessActive ()) {
if (!weaponsManager.isAimModeInputPressed ()) {
return;
}
}
}
changeLightIntensity (true);
}
public void setOriginalIntensity ()
{
changeLightIntensity (false);
}
public void enableOrDisableFlashlightMeshes (bool state)
{
if (flashlightMeshes != null) {
if (state) {
if (!flashlightEnabled) {
return;
}
}
if (flashlightMeshes.activeSelf != state) {
flashlightMeshes.SetActive (state);
}
}
}
public void setFlashLightInputPausedState (bool state)
{
flashLightInputPausedState = state;
}
public void enableOrDisableFlashlightIndicator (bool state)
{
usingFlashlight = state;
if (useFlashlightIndicatorPanel) {
if (flahslightIndicatorPanel != null) {
if (flahslightIndicatorPanel.activeSelf != state) {
flahslightIndicatorPanel.SetActive (state);
}
}
if (mainSlider != null) {
if (usedThroughWeaponSystem) {
mainSlider.maxValue = weaponManager.getMagazineSize ();
}
UIElementsLocated = true;
}
}
}
bool componentsInitialized;
void initializeComponents ()
{
if (componentsInitialized) {
return;
}
if (usedThroughWeaponSystem) {
if (weaponsManager == null) {
weaponsManager = weaponManager.getPlayerWeaponsManger ();
}
}
componentsInitialized = true;
}
}

View File

@@ -0,0 +1,19 @@
fileFormatVersion: 2
guid: 050620af76d73374d8e2a8dd20482d64
timeCreated: 1523826769
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/Weapons/New Weapon Behaviors/flashlight.cs
uploadId: 814740

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,19 @@
fileFormatVersion: 2
guid: c0aa790bce1c533499283fa87d92dd8c
timeCreated: 1561104315
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/Weapons/New Weapon Behaviors/gravityGun.cs
uploadId: 814740

View File

@@ -0,0 +1,436 @@
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using UnityEngine;
public class healerWeapon : MonoBehaviour
{
[Header ("Main Settings")]
[Space]
public LayerMask layer;
public bool canHeal;
public float healRate;
public float healtAmount;
[Space]
public bool canDamage;
public float damageRate;
public float damageAmount;
[Space]
public bool canRefillEnergy;
public float energyRate;
public float energyAmount;
[Space]
public bool canRefillFuel;
public float fuelRate;
public float fuelAmount;
[Space]
public bool canGatherHealth;
public bool canGatherEnergy;
public bool canGatherFuel;
[Space]
public bool useWithVehicles;
public bool useWithCharacters;
[Space]
[Header ("Other Settings")]
[Space]
public bool ignoreShield;
public int damageTypeID = -1;
public bool damageCanBeBlocked = true;
public bool canActivateReactionSystemTemporally;
public int damageReactionID = -1;
[Space]
[Header ("Debug")]
[Space]
public bool showDebugPrint;
public GameObject currentObjectToCheck;
public GameObject currentHealthElement;
public bool targetFound;
public bool searchingTargets;
public bool healModeActive;
[Space]
[Header ("Components")]
[Space]
public Transform mainCameraTransform;
public playerWeaponSystem weaponManager;
float lastTime;
RaycastHit hit;
Coroutine updateCoroutine;
public void stopUpdateCoroutine ()
{
if (updateCoroutine != null) {
StopCoroutine (updateCoroutine);
}
}
IEnumerator updateSystemCoroutine ()
{
var waitTime = new WaitForFixedUpdate ();
while (true) {
updateSystem ();
yield return waitTime;
}
}
void updateSystem ()
{
if (searchingTargets) {
if (Physics.Raycast (mainCameraTransform.position, mainCameraTransform.TransformDirection (Vector3.forward), out hit, Mathf.Infinity, layer)) {
currentObjectToCheck = hit.collider.gameObject;
if (!targetFound) {
checkTarget (currentObjectToCheck);
print (currentObjectToCheck.name);
} else {
if (currentHealthElement != currentObjectToCheck) {
changeTriggerState (false, null, 0);
print ("removed");
}
}
} else {
targetFound = false;
}
}
if (targetFound && currentHealthElement != null) {
if (healModeActive) {
if (canHeal) {
if (Time.time > lastTime + healRate) {
//while the object is not fully healed, then
if (!applyDamage.checkIfMaxHealth (currentHealthElement) && weaponManager.remainAmmoInClip ()) {
//heal it
applyDamage.setHeal (healtAmount, currentHealthElement);
lastTime = Time.time;
if (canGatherHealth) {
int amountOfAmmo = (int)Mathf.Round (healtAmount);
weaponManager.useAmmo (amountOfAmmo);
weaponManager.checkToUpdateInventoryWeaponAmmoTextFromWeaponSystem ();
}
} else {
//else, stop healing it
changeTriggerState (false, null, 0);
return;
}
}
}
if (canRefillFuel) {
if (Time.time > lastTime + fuelRate) {
//while the vehicle has not the max fuel amount, then
if (!applyDamage.checkIfMaxFuel (currentHealthElement) && weaponManager.remainAmmoInClip ()) {
//fill it
applyDamage.setFuel (fuelAmount, currentHealthElement);
lastTime = Time.time;
if (canGatherFuel) {
int amountOfAmmo = (int)Mathf.Round (fuelAmount);
weaponManager.useAmmo (amountOfAmmo);
weaponManager.checkToUpdateInventoryWeaponAmmoTextFromWeaponSystem ();
}
} else {
//else, stop refill it
changeTriggerState (false, null, 0);
return;
}
}
}
if (canRefillEnergy) {
if (Time.time > lastTime + energyRate) {
//while the vehicle has not the max fuel amount, then
if (!applyDamage.checkIfMaxEnergy (currentHealthElement) && weaponManager.remainAmmoInClip ()) {
//fill it
applyDamage.setEnergy (energyAmount, currentHealthElement);
lastTime = Time.time;
if (canGatherEnergy) {
int amountOfAmmo = (int)Mathf.Round (energyAmount);
weaponManager.useAmmo (amountOfAmmo);
weaponManager.checkToUpdateInventoryWeaponAmmoTextFromWeaponSystem ();
}
} else {
//else, stop refill it
changeTriggerState (false, null, 0);
return;
}
}
}
} else {
//apply damage or heal it accordint to the time rate
if (Time.time > lastTime + damageRate) {
if (canDamage) {
//if the object inside the trigger is dead, stop applying damage
if (applyDamage.checkIfDead (currentHealthElement)) {
changeTriggerState (false, null, 0);
return;
}
if (!canGatherHealth) {
if (!weaponManager.remainAmmoInClip ()) {
changeTriggerState (false, null, 0);
return;
}
}
//if the trigger damages
//apply damage
applyDamage.checkHealth (gameObject, currentHealthElement, damageAmount, Vector3.zero,
currentHealthElement.transform.position + currentHealthElement.transform.up, gameObject,
true, true, ignoreShield, false, damageCanBeBlocked, canActivateReactionSystemTemporally, damageReactionID, damageTypeID);
lastTime = Time.time;
if (canGatherHealth) {
weaponManager.getAndUpdateAmmo ((int)Mathf.Round (damageAmount));
} else {
int amountOfAmmo = (int)Mathf.Round (damageAmount);
weaponManager.useAmmo (amountOfAmmo);
weaponManager.checkToUpdateInventoryWeaponAmmoTextFromWeaponSystem ();
}
}
}
if (canRefillFuel) {
if (Time.time > lastTime + fuelRate) {
//while the vehicle has not the max fuel amount, then
if (applyDamage.getCurrentFuelAmount (currentHealthElement) > 0) {
//fill it
applyDamage.removeFuel (fuelAmount, currentHealthElement);
lastTime = Time.time;
if (canGatherFuel) {
weaponManager.getAndUpdateAmmo ((int)Mathf.Round (fuelAmount));
}
} else {
//else, stop refill it
changeTriggerState (false, null, 0);
return;
}
}
}
if (canRefillEnergy) {
if (Time.time > lastTime + energyRate) {
//while the vehicle has not the max fuel amount, then
if (applyDamage.getCurrentEnergyAmount (currentHealthElement) > 0) {
//fill it
applyDamage.removeEnergy (energyAmount, currentHealthElement);
lastTime = Time.time;
if (canGatherEnergy) {
weaponManager.getAndUpdateAmmo ((int)Mathf.Round (energyAmount));
}
} else {
//else, stop refill it
changeTriggerState (false, null, 0);
return;
}
}
}
}
}
}
public void changeMode ()
{
initializeComponents ();
healModeActive = !healModeActive;
}
public void checkTarget (GameObject target)
{
//else, if a vehicle is inside the trigger and it can be used with vehicles, them
if (applyDamage.isVehicle (target) && useWithVehicles) {
changeTriggerState (true, target, Time.time);
return;
}
if (applyDamage.isCharacter (target) && useWithCharacters) {
changeTriggerState (true, target, Time.time);
return;
}
}
//stop or start the heal or damage action
void changeTriggerState (bool inside, GameObject obj, float time)
{
targetFound = inside;
currentHealthElement = obj;
lastTime = time;
if (showDebugPrint) {
print ("target found result " + targetFound);
}
}
public void downButtonAction ()
{
initializeComponents ();
searchingTargets = true;
stopUpdateCoroutine ();
updateCoroutine = StartCoroutine (updateSystemCoroutine ());
}
public void upButtonAction ()
{
initializeComponents ();
searchingTargets = false;
changeTriggerState (false, null, 0);
stopUpdateCoroutine ();
}
bool componentsInitialized;
void initializeComponents ()
{
if (componentsInitialized) {
return;
}
if (weaponManager != null) {
mainCameraTransform = weaponManager.getMainCameraTransform ();
}
componentsInitialized = true;
}
public void setCanHealState (bool state)
{
canHeal = state;
if (state) {
canDamage = false;
canRefillEnergy = false;
canRefillFuel = false;
}
}
public void setCanDamageState (bool state)
{
canDamage = state;
if (state) {
canHeal = false;
canRefillEnergy = false;
canRefillFuel = false;
}
}
public void setCanRefillEnergyState (bool state)
{
canRefillEnergy = state;
if (state) {
canHeal = false;
canDamage = false;
canRefillFuel = false;
}
}
public void setCanRefillFuelState (bool state)
{
canRefillFuel = state;
if (state) {
canHeal = false;
canDamage = false;
canRefillEnergy = false;
}
}
public void setCanGatherHealthState (bool state)
{
canGatherHealth = state;
}
public void setCanGatherEnergyState (bool state)
{
canGatherEnergy = state;
}
public void setCanGatherFuelState (bool state)
{
canGatherFuel = state;
}
public void setHealModeActiveState (bool state)
{
healModeActive = state;
}
}

View File

@@ -0,0 +1,19 @@
fileFormatVersion: 2
guid: f1c002ea53029eb4e864fa39b9fdcd48
timeCreated: 1520367247
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/Weapons/New Weapon Behaviors/healerWeapon.cs
uploadId: 814740

View File

@@ -0,0 +1,131 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
public class plasmaCutterSystem : MonoBehaviour
{
[Header ("Main Settings")]
[Space]
public Transform mainRotor;
public float initialRotorRotation;
public bool useFixedVerticalHorizontalRotations;
public float angleRotationAmount;
public float rotationSpeed;
public float manualRotationAmount;
[Space]
[Header ("Events Settings")]
[Space]
public UnityEvent eventOnFireWeapon;
public UnityEvent eventOnRotateWeapon;
bool rotating;
bool rotationToggleState;
Coroutine rotationCoroutine;
void Start ()
{
mainRotor.localEulerAngles = new Vector3 (0, 0, initialRotorRotation);
}
public void firePlasmaCutter ()
{
eventOnFireWeapon.Invoke ();
}
public void rotateRotorToRight ()
{
mainRotor.Rotate (manualRotationAmount * Vector3.forward);
}
public void rotateRotorToLeft ()
{
mainRotor.Rotate (manualRotationAmount * (-Vector3.forward));
}
public void changeRotorRotation ()
{
if (rotating) {
return;
}
float rotationAmount = 0;
if (useFixedVerticalHorizontalRotations) {
rotationToggleState = !rotationToggleState;
if (rotationToggleState) {
rotationAmount = 90;
} else {
rotationAmount = 0;
}
} else {
rotationAmount += angleRotationAmount;
if (rotationAmount > 360) {
rotationAmount = 360 - rotationAmount;
}
}
eventOnRotateWeapon.Invoke ();
stopChangeRotorRotation ();
rotationCoroutine = StartCoroutine (stopChangeRotorRotationCoroutine (rotationAmount));
}
public void stopChangeRotorRotation ()
{
if (rotationCoroutine != null) {
StopCoroutine (rotationCoroutine);
}
}
IEnumerator stopChangeRotorRotationCoroutine (float rotationAmount)
{
rotating = true;
Vector3 eulerTarget = Vector3.zero;
eulerTarget.z = rotationAmount;
Quaternion rotationTarget = Quaternion.Euler (eulerTarget);
float t = 0;
float movementTimer = 0;
bool targetReached = false;
float angleDifference = 0;
while (!targetReached) {
t += Time.deltaTime * rotationSpeed;
mainRotor.localRotation = Quaternion.Lerp (mainRotor.localRotation, rotationTarget, t);
movementTimer += Time.deltaTime;
angleDifference = Quaternion.Angle (mainRotor.localRotation, rotationTarget);
movementTimer += Time.deltaTime;
if (angleDifference < 0.2f || movementTimer > 2) {
targetReached = true;
}
yield return null;
}
rotating = false;
}
}

View File

@@ -0,0 +1,19 @@
fileFormatVersion: 2
guid: 903868009044f3041913a3269e050ba1
timeCreated: 1576806352
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/Weapons/New Weapon Behaviors/plasmaCutterSystem.cs
uploadId: 814740

View File

@@ -0,0 +1,294 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
public class simpleChainSaw : MonoBehaviour
{
[Header ("Main Settings")]
[Space]
public Transform mainRotationPivot;
public float initialPivotRotation;
public bool useFixedVerticalHorizontalRotations;
public float angleRotationAmount;
public float rotationSpeed;
public float manualRotationAmount;
public float maxRotationAngle = 80;
public float minRotationAngle = -10;
[Space]
[Header ("Weapon Settings")]
[Space]
public bool useFuelEnabled = true;
public float useFuelRate;
public int amountFuelUsed;
[Space]
[Header ("Debug")]
[Space]
public bool chainsawActive;
[Space]
[Header ("Events Settings")]
[Space]
public UnityEvent eventOnActivateChainsaw;
public UnityEvent eventOnDeactivateChainsaw;
public UnityEvent eventOnRotateWeapon;
[Space]
[Header ("Components")]
[Space]
public playerWeaponSystem weaponManager;
bool rotating;
bool rotationToggleState;
Coroutine rotationCoroutine;
Coroutine updateCoroutine;
bool isWeaponReloading;
bool remainAmmoInClip;
bool reloading;
float lastTimeUsed;
bool ignoreDisableCoroutine;
void Start ()
{
mainRotationPivot.localEulerAngles = new Vector3 (0, 0, initialPivotRotation);
}
public void stopUpdateCoroutine ()
{
if (updateCoroutine != null) {
StopCoroutine (updateCoroutine);
}
}
IEnumerator updateSystemCoroutine ()
{
var waitTime = new WaitForFixedUpdate ();
while (true) {
updateSystem ();
yield return waitTime;
}
}
void updateSystem ()
{
isWeaponReloading = weaponManager.isWeaponReloading ();
remainAmmoInClip = weaponManager.remainAmmoInClip ();
if (reloading) {
if (remainAmmoInClip && weaponManager.carryingWeapon () && !isWeaponReloading) {
reloading = false;
} else {
return;
}
}
if (reloading) {
return;
}
if (!chainsawActive) {
return;
}
if (useFuelEnabled) {
if (Time.time > lastTimeUsed + useFuelRate) {
if (remainAmmoInClip && !isWeaponReloading) {
lastTimeUsed = Time.time;
weaponManager.useAmmo (amountFuelUsed);
weaponManager.checkToUpdateInventoryWeaponAmmoTextFromWeaponSystem ();
}
if (!remainAmmoInClip || isWeaponReloading) {
ignoreDisableCoroutine = true;
activateOrDeactivateChainsaw (false);
ignoreDisableCoroutine = false;
reloading = true;
return;
}
}
}
}
public void activateChainSaw ()
{
activateOrDeactivateChainsaw (true);
}
public void deactivateChainSaw ()
{
activateOrDeactivateChainsaw (false);
}
void activateOrDeactivateChainsaw (bool state)
{
if (chainsawActive == state) {
return;
}
chainsawActive = state;
if (chainsawActive) {
eventOnActivateChainsaw.Invoke ();
} else {
eventOnDeactivateChainsaw.Invoke ();
}
if (ignoreDisableCoroutine) {
return;
}
if (chainsawActive) {
updateCoroutine = StartCoroutine (updateSystemCoroutine ());
} else {
stopUpdateCoroutine ();
}
}
public void rotatePivotToRight ()
{
mainRotationPivot.Rotate (manualRotationAmount * Vector3.forward);
checkMainRotationPivotMaxRotationAngle ();
}
public void rotatePivotToLeft ()
{
mainRotationPivot.Rotate (manualRotationAmount * (-Vector3.forward));
checkMainRotationPivotMaxRotationAngle ();
}
void checkMainRotationPivotMaxRotationAngle ()
{
if (maxRotationAngle == 0) {
return;
}
Vector3 mainRotationPivotEulerAngles = mainRotationPivot.localEulerAngles;
float newZAngle = mainRotationPivotEulerAngles.z;
if (newZAngle > 0 && newZAngle < 180) {
newZAngle = Mathf.Clamp (newZAngle, 0, maxRotationAngle);
} else {
if (newZAngle > 180) {
newZAngle -= 360;
}
newZAngle = Mathf.Clamp (newZAngle, minRotationAngle, 0);
}
mainRotationPivot.localEulerAngles = new Vector3 (mainRotationPivotEulerAngles.x, mainRotationPivotEulerAngles.y, newZAngle);
}
public void changePivotRotation ()
{
if (rotating) {
return;
}
float rotationAmount = 0;
if (useFixedVerticalHorizontalRotations) {
rotationToggleState = !rotationToggleState;
if (rotationToggleState) {
rotationAmount = 90;
} else {
rotationAmount = 0;
}
} else {
rotationAmount += angleRotationAmount;
if (rotationAmount > 360) {
rotationAmount = 360 - rotationAmount;
}
}
eventOnRotateWeapon.Invoke ();
stopChangePivotRotation ();
rotationCoroutine = StartCoroutine (stopChangePivotRotationCoroutine (rotationAmount));
}
public void stopChangePivotRotation ()
{
if (rotationCoroutine != null) {
StopCoroutine (rotationCoroutine);
}
}
IEnumerator stopChangePivotRotationCoroutine (float rotationAmount)
{
rotating = true;
Vector3 eulerTarget = Vector3.zero;
eulerTarget.z = rotationAmount;
Quaternion rotationTarget = Quaternion.Euler (eulerTarget);
float t = 0;
float movementTimer = 0;
bool targetReached = false;
float angleDifference = 0;
while (!targetReached) {
t += Time.deltaTime * rotationSpeed;
mainRotationPivot.localRotation = Quaternion.Lerp (mainRotationPivot.localRotation, rotationTarget, t);
movementTimer += Time.deltaTime;
angleDifference = Quaternion.Angle (mainRotationPivot.localRotation, rotationTarget);
movementTimer += Time.deltaTime;
if (angleDifference < 0.2f || movementTimer > 2) {
targetReached = true;
}
yield return null;
}
rotating = false;
}
}

View File

@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: d77a00adcb007cd4393701fa78c2acf3
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 40995
packageName: Game Kit Controller - Shooter Melee Adventure Creator 3D + 2.5D
packageVersion: 3.77g
assetPath: Assets/Game Kit Controller/Scripts/Weapons/New Weapon Behaviors/simpleChainSaw.cs
uploadId: 814740

View File

@@ -0,0 +1,832 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class sliceObject : MonoBehaviour
{
[Header ("Main Settings")]
[Space]
public bool sliceActive;
public bool disableSliceAfterFirstCutEnabled = true;
public Material defaultSliceMaterial;
public Vector3 cutOverlapBoxSize = new Vector3 (5, 0.1f, 5);
public float minDelayToSliceSameObject = 0.3f;
public bool activateRigidbodiesOnNewObjects = true;
[Space]
public bool sliceRegularObjectsEnabled = true;
public bool sliceCharactersEnabled = true;
[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 float forceToApplyToCutPart;
public ForceMode forceMode;
public float forceRadius;
public float forceUp;
public float disableTimeAfterCollision;
public LayerMask targetToDamageLayer;
[Space]
[Space]
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 ("Other Settings")]
[Space]
public bool cutMultipleTimesActive = true;
public bool ignoreObjectsAlreadySlice;
public float minWaitTimeToActivateSlice = 0.4f;
[Space]
[Space]
public bool useObjectsToIgnoreList;
public List<GameObject> objectsToIgnoreList = new List<GameObject> ();
[Space]
[Header ("Bullet Time Settings")]
[Space]
public bool ignoreTimeBulletOnRegularSlice;
[Space]
[Header ("Remote Events Settings")]
[Space]
public bool useRemoteEventOnObjectsFound;
public List<string> remoteEventNameList = new List<string> ();
[Space]
[Header ("Debug")]
[Space]
public bool showDebugPrint;
public bool showDebugWaitTimePrint;
public List<GameObject> objectsDetected = new List<GameObject> ();
public List<Collider> collidersToIgnoreList = new List<Collider> ();
[Space]
[Header ("Gizmo Settings")]
[Space]
public bool showGizmo;
public Color gizmoColor = Color.red;
[Space]
[Header ("Components")]
[Space]
public Collider mainCollider;
public Collider triggerCollider;
public Transform cutPositionTransform;
public Transform cutDirectionTransform;
public Transform planeDefiner1;
public Transform planeDefiner2;
public Transform planeDefiner3;
surfaceToSlice currentSurfaceToSlice;
Collider currentColliderFound;
Coroutine disableSliceCoroutine;
float lastTimeSlice;
Vector3 currentCutPosition;
Quaternion currentCutRotation;
Vector3 currentCutUp;
Vector3 currentCutForward;
Vector3 currentCutDirection;
Vector3 currentPlaneDefiner1;
Vector3 currentPlaneDefiner2;
Vector3 currentPlaneDefiner3;
Vector3 currentCutOverlapBoxSize;
void setCurrentCutTransformValues ()
{
if (cutPositionTransform != null) {
currentCutPosition = cutPositionTransform.position;
currentCutRotation = cutPositionTransform.rotation;
currentCutUp = cutPositionTransform.up;
currentCutForward = cutPositionTransform.forward;
} else {
currentCutPosition = cutDirectionTransform.position;
currentCutRotation = cutDirectionTransform.rotation;
currentCutUp = cutDirectionTransform.up;
currentCutForward = cutDirectionTransform.forward;
}
if (cutDirectionTransform != null) {
currentCutDirection = cutDirectionTransform.right;
}
if (planeDefiner1 != null) {
currentPlaneDefiner1 = planeDefiner1.position;
}
if (planeDefiner2 != null) {
currentPlaneDefiner2 = planeDefiner2.position;
}
if (planeDefiner3 != null) {
currentPlaneDefiner3 = planeDefiner3.position;
}
currentCutOverlapBoxSize = cutOverlapBoxSize;
}
public void processObject (GameObject obj, Collider objectCollider, Vector3 slicePosition)
{
if (cutMultipleTimesActive) {
if (!ignoreObjectsAlreadySlice && objectsDetected.Contains (obj)) {
return;
}
}
if (minWaitTimeToActivateSlice > 0 && lastTimeSlice != 0) {
if (showDebugWaitTimePrint) {
print ("checking object to process with last time slice");
}
if (Time.time < lastTimeSlice + minWaitTimeToActivateSlice) {
if (showDebugWaitTimePrint) {
print ("not enough wait time, cancelling check");
}
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);
}
if (isCutSurfaceEnabled && sliceCanBeActivated && checkSliceDirectionResult) {
Material crossSectionMaterial = currentSurfaceToSlice.getCrossSectionMaterial ();
if (crossSectionMaterial == null) {
crossSectionMaterial = defaultSliceMaterial;
}
sliceCurrentObject (obj, objectCollider, crossSectionMaterial, slicePosition);
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 (showDebugPrint) {
print (objectCanBeSliced + " " + ignoreRegularDamageIfCutSurfaceNotEnabled + " " +
activateDamageOnSlice + " " + isIgnoreDamageIfSliceNotActivatedActive);
}
if (!objectCanBeSliced && !ignoreRegularDamageIfCutSurfaceNotEnabled) {
if (activateDamageOnSlice && !isIgnoreDamageIfSliceNotActivatedActive) {
Vector3 damagePosition = currentCutPosition;
if (applyDamage.checkIfDead (obj)) {
damagePosition = obj.transform.position;
}
applyDamage.checkCanBeDamaged (gameObject, obj, damageAmountToApplyOnSlice, -currentCutForward, damagePosition,
gameObject, 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);
}
}
}
if (useRemoteEventOnObjectsFound) {
remoteEventSystem currentRemoteEventSystem = obj.GetComponent<remoteEventSystem> ();
if (currentRemoteEventSystem == null) {
playerComponentsManager currentPlayerComponentsManager = obj.GetComponent<playerComponentsManager> ();
if (currentPlayerComponentsManager != null) {
currentRemoteEventSystem = currentPlayerComponentsManager.getRemoteEventSystem ();
}
}
if (currentRemoteEventSystem != null) {
for (int i = 0; i < remoteEventNameList.Count; i++) {
currentRemoteEventSystem.callRemoteEvent (remoteEventNameList [i]);
}
}
}
}
void OnTriggerEnter (Collider col)
{
if (sliceActive) {
currentColliderFound = col;
checkObjectDetected (currentColliderFound);
if (disableSliceAfterFirstCutEnabled) {
disableSliceActiveWithDelay ();
}
}
}
public void toggleSliceActiveState ()
{
setSliceActiveState (!sliceActive);
}
public void setSliceActiveState (bool state)
{
sliceActive = state;
if (showDebugPrint) {
print ("setSliceActiveState " + sliceActive);
}
stopDisableSliceActiveWithDelay ();
if (sliceActive) {
if (mainCollider != null) {
mainCollider.enabled = false;
}
if (triggerCollider != null) {
triggerCollider.enabled = true;
}
} else {
disableIgnoreCollisionList ();
}
}
public void checkObjectDetected (Collider col)
{
if ((1 << col.gameObject.layer & targetToDamageLayer.value) == 1 << col.gameObject.layer) {
if (useObjectsToIgnoreList) {
if (objectsToIgnoreList.Contains (col.gameObject)) {
return;
}
}
setCurrentCutTransformValues ();
Collider currentCollider = col.GetComponent<Collider> ();
if (currentCollider != null) {
processObject (currentCollider.gameObject, currentCollider, currentCutPosition);
}
}
}
public void sliceCurrentObject (GameObject obj, Collider objectCollider, Material crossSectionMaterial, Vector3 slicePosition)
{
// slice the provided object using the transforms of this object
if (currentSurfaceToSlice.isObjectCharacter ()) {
if (sliceCharactersEnabled) {
bool isCharacterOrVehicle = applyDamage.getCharacterOrVehicle (obj) != null;
bool objectIsDead = applyDamage.checkIfDead (obj);
if (isCharacterOrVehicle && !objectIsDead) {
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 (ignoreTimeBulletOnRegularSlice) {
canCheckTimeBulletResult = false;
}
if (canCheckTimeBulletResult) {
currentSurfaceToSlice.checkTimeBulletOnCut ();
}
lastTimeSlice = Time.time;
}
return;
}
if (sliceRegularObjectsEnabled) {
bool objectSliced = false;
GameObject object1 = null;
GameObject object2 = null;
currentSurfaceToSlice.checkEventBeforeSlice ();
obj = currentSurfaceToSlice.getMainSurfaceToSlice ();
// slice the provided object using the transforms of this object
sliceSystemUtils.sliceObject (transform.position, 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 ();
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;
Vector3 lastSpeed = Vector3.zero;
if (mainObjectHasRigidbody) {
lastSpeed = mainObject.linearVelocity;
}
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> ();
if (updateLastObjectSpeed) {
if (lastSpeed != Vector3.zero) {
object1Rigidbody.linearVelocity = lastSpeed;
object2Rigidbody.linearVelocity = lastSpeed;
}
}
object2Rigidbody.AddExplosionForce (currentForceToApply, transform.position, forceRadius, forceUp, currentForceMode);
object1Rigidbody.AddExplosionForce (currentForceToApply, transform.position, forceRadius, forceUp, currentForceMode);
} else {
if (currentSurfaceToSlice.useCustomForceAmount) {
currentForceToApply = currentSurfaceToSlice.customForceAmount;
}
if (distance1 < distance2) {
Rigidbody object2Rigidbody = object2.AddComponent<Rigidbody> ();
object2Rigidbody.AddExplosionForce (currentForceToApply, transform.position, forceRadius, forceUp, currentForceMode);
} else {
Rigidbody object1Rigidbody = object1.AddComponent<Rigidbody> ();
object1Rigidbody.AddExplosionForce (currentForceToApply, transform.position, 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;
}
Collider collider1 = object1.GetComponent<Collider> ();
Collider collider2 = object2.GetComponent<Collider> ();
if (collider1 != null) {
collidersToIgnoreList.Add (collider1);
if (showDebugPrint) {
print (collider1.name);
}
}
if (collider2 != null) {
collidersToIgnoreList.Add (collider2);
if (showDebugPrint) {
print (collider2.name);
}
}
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;
}
if (cutMultipleTimesActive) {
if (!objectsDetected.Contains (object1)) {
objectsDetected.Add (object1);
}
if (!objectsDetected.Contains (object2)) {
objectsDetected.Add (object2);
}
}
obj.SetActive (false);
// obj.SetActive (false);
lastTimeSlice = Time.time;
}
}
}
public void stopDisableSliceActiveWithDelay ()
{
if (disableSliceCoroutine != null) {
StopCoroutine (disableSliceCoroutine);
}
}
public void disableSliceActiveWithDelay ()
{
stopDisableSliceActiveWithDelay ();
disableSliceCoroutine = StartCoroutine (disableSliceActiveWithDelayCoroutine ());
}
IEnumerator disableSliceActiveWithDelayCoroutine ()
{
WaitForSeconds delay = new WaitForSeconds (0.5f);
yield return delay;
delay = new WaitForSeconds (disableTimeAfterCollision);
yield return delay;
if (mainCollider != null) {
mainCollider.enabled = true;
}
sliceActive = false;
disableIgnoreCollisionList ();
}
public void disableIgnoreCollisionList ()
{
collidersToIgnoreList.Clear ();
if (triggerCollider != null) {
triggerCollider.enabled = false;
}
objectsDetected.Clear ();
}
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);
yield return new WaitForEndOfFrame ();
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;
}
}
for (int i = 0; i < temporalHits.Length; i++) {
if (!bodyPartFound) {
Collider currentCollider = temporalHits [i];
if (showDebugPrint) {
print ("checking " + currentCollider.name);
}
if (showDebugPrint) {
print (currentCollider.name + " body part when killing");
}
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 (applyDamage.isCharacter (currentCollider.gameObject)) {
bodyPartFound = true;
}
if (currentCharacter != null) {
applyDamage.killCharacter (currentCharacter);
}
processObject (currentCollider.gameObject, currentCollider, currentCutPosition);
}
}
}
}
}
void OnDrawGizmos ()
{
if (!showGizmo) {
return;
}
if (GKC_Utils.isCurrentSelectionActiveGameObject (gameObject)) {
DrawGizmos ();
}
}
void OnDrawGizmosSelected ()
{
DrawGizmos ();
}
void DrawGizmos ()
{
if (showGizmo) {
if (cutPositionTransform != null) {
GKC_Utils.drawRectangleGizmo (cutPositionTransform.position, cutPositionTransform.rotation, Vector3.zero, cutOverlapBoxSize, gizmoColor);
}
}
}
}

View File

@@ -0,0 +1,19 @@
fileFormatVersion: 2
guid: 4fb9e2e7524b1794fb3ce4954555c88b
timeCreated: 1578995500
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/Weapons/New Weapon Behaviors/sliceObject.cs
uploadId: 814740

View File

@@ -0,0 +1,462 @@
using System.Collections;
using System.Collections.Generic;
using GameKitController.Audio;
using UnityEngine;
using UnityEngine.Events;
public class smartphoneDevice : MonoBehaviour
{
[Header ("Main Settings")]
[Space]
public bool canMakePhotos;
public bool usePhotoSound;
public AudioClip photoSound;
public AudioElement photoAudioElement;
public bool canUseFlash;
public float flashDuration = 0.1f;
public bool storeCapturesEnabled = true;
[Space]
[Header ("Raycast Detection Settings")]
[Space]
public bool useCapsuleRaycast;
public float capsuleCastRadius;
[Space]
[Header ("Zoom Settings")]
[Space]
public bool canUseZoom;
public float maxZoomAmout;
public float minZoomAmount;
public float zoomSpeed;
[Space]
[Header ("Check Objects On Capture Settings")]
[Space]
public bool checkObjectFoundOnCapture;
public LayerMask layerToCheckObjectFound;
public float rayDistanceToCheckObjectFound;
public Transform raycastTransform;
public bool useOverrideSystemOnCapture;
public bool sendObjectOnCapture;
public GameObject objectToSendOnCapture;
[Space]
[Header ("Events Settings")]
[Space]
public bool useEventOnCapture;
public UnityEvent eventOnCapture;
public bool useEventsOnCameraViewChange;
public UnityEvent eventOnCameraViewChangeToThirdPerson;
public UnityEvent eventOnCameraViewChangeToFirstPerson;
public bool useEventsOnSmartphoneTurnOnOff;
public UnityEvent eventOnSmartphoneTurnedOn;
public UnityEvent eventOnSmartphoneTurnedOff;
[Space]
[Header ("Debug")]
[Space]
public bool showDebugPrint;
public bool firstPersonActive;
public bool isActivated;
public bool perspectiveSystemLocated;
[Space]
[Header ("Smartphone Components")]
[Space]
public GameObject smartphoneCamera;
public GameObject smartphoneScreenCanvas;
public GameObject smartphoneScreenCenter;
public GameObject cameraFlash;
public Transform mainScreenCenter;
public Transform screenCenter;
public AudioSource mainAudioSource;
public Camera smartphoneMainCamera;
[Space]
[Header ("Player Components")]
[Space]
public Transform playerCameraTransform;
public playerWeaponSystem weaponManager;
public playerWeaponsManager mainPlayerWeaponsManager;
public cameraCaptureSystem cameraCaptureManager;
public overrideElementControlSystem mainOverrideElementControlSystem;
public eventObjectFoundOnRaycastSystem mainEventObjectFoundOnRaycastSystem;
RaycastHit hit;
bool changingZoom;
float currentFov;
float zoomDirection = -1;
cameraPerspectiveSystem currentPerspectiveSystem;
Coroutine flashCoroutine;
bool cameraCaptureManagerLocated;
RaycastHit[] hits;
Coroutine updateCoroutine;
private void Start ()
{
if (photoSound != null) {
photoAudioElement.clip = photoSound;
}
if (mainAudioSource != null) {
photoAudioElement.audioSource = mainAudioSource;
}
}
public void stopUpdateCoroutine ()
{
if (updateCoroutine != null) {
StopCoroutine (updateCoroutine);
}
}
IEnumerator updateSystemCoroutine ()
{
var waitTime = new WaitForFixedUpdate ();
while (true) {
updateSystem ();
yield return waitTime;
}
}
void updateSystem ()
{
if (isActivated) {
if (canUseZoom && changingZoom) {
currentFov = smartphoneMainCamera.fieldOfView + Time.deltaTime * zoomSpeed * zoomDirection;
if (zoomDirection == -1) {
if (currentFov < minZoomAmount) {
zoomDirection = 1;
}
} else {
if (currentFov > maxZoomAmout) {
zoomDirection = -1;
}
}
smartphoneMainCamera.fieldOfView = currentFov;
}
}
}
public void takePhoto ()
{
if (canMakePhotos) {
playSound ();
checkFlash ();
if (storeCapturesEnabled) {
if (cameraCaptureManagerLocated) {
cameraCaptureManager.takeCapture (smartphoneMainCamera);
}
}
if (perspectiveSystemLocated) {
currentPerspectiveSystem.checkCurrentPlayerPosition (playerCameraTransform, weaponManager.getMainCameraTransform (), smartphoneMainCamera);
}
if (showDebugPrint) {
print ("Take Photo");
}
if (checkObjectFoundOnCapture) {
if (Physics.Raycast (raycastTransform.position, raycastTransform.forward, out hit, rayDistanceToCheckObjectFound, layerToCheckObjectFound)) {
if (useCapsuleRaycast) {
Vector3 currentRayOriginPosition = raycastTransform.position;
Vector3 currentRayTargetPosition = hit.point;
float distanceToTarget = GKC_Utils.distance (currentRayOriginPosition, currentRayTargetPosition);
Vector3 rayDirection = currentRayOriginPosition - currentRayTargetPosition;
rayDirection = rayDirection / rayDirection.magnitude;
Debug.DrawLine (currentRayTargetPosition, (rayDirection * distanceToTarget) + currentRayTargetPosition, Color.red, 2);
Vector3 point1 = currentRayOriginPosition - rayDirection * capsuleCastRadius;
Vector3 point2 = currentRayTargetPosition + rayDirection * capsuleCastRadius;
hits = Physics.CapsuleCastAll (point1, point2, capsuleCastRadius, rayDirection, 0, layerToCheckObjectFound);
for (int i = 0; i < hits.Length; i++) {
GameObject currentSurfaceGameObjectFound = hits [i].collider.gameObject;
checkObjectDetected (currentSurfaceGameObjectFound);
}
} else {
checkObjectDetected (hit.collider.gameObject);
}
}
}
changingZoom = false;
if (useEventOnCapture) {
eventOnCapture.Invoke ();
if (showDebugPrint) {
print ("Send Event On Capture");
}
}
if (useOverrideSystemOnCapture) {
if (mainOverrideElementControlSystem != null) {
mainOverrideElementControlSystem.checkElementToControl (raycastTransform);
}
}
}
}
void checkObjectDetected (GameObject newObject)
{
if (showDebugPrint) {
print ("Object Detected On Photo " + newObject.name);
}
eventObjectFoundOnCaptureSystem currentEventObjectFoundOnCaptureSystem = newObject.GetComponent<eventObjectFoundOnCaptureSystem> ();
if (currentEventObjectFoundOnCaptureSystem != null) {
currentEventObjectFoundOnCaptureSystem.callEventOnCapture ();
if (sendObjectOnCapture) {
currentEventObjectFoundOnCaptureSystem.callEventOnCaptureWithGameObject (objectToSendOnCapture);
}
}
}
public void checkFlash ()
{
if (!canUseFlash) {
return;
}
if (flashCoroutine != null) {
StopCoroutine (flashCoroutine);
}
flashCoroutine = StartCoroutine (flashCoroutineCoroutine ());
}
IEnumerator flashCoroutineCoroutine ()
{
cameraFlash.SetActive (true);
yield return new WaitForSeconds (flashDuration);
cameraFlash.SetActive (false);
yield return null;
}
public void changeZoom ()
{
changingZoom = !changingZoom;
}
public void turnOn ()
{
isActivated = true;
setSmartphoneState (isActivated);
}
public void turnOff ()
{
isActivated = false;
setSmartphoneState (isActivated);
}
public void changeSmartphoneState ()
{
setSmartphoneState (!isActivated);
}
public void setSmartphoneState (bool state)
{
isActivated = state;
smartphoneScreenCanvas.SetActive (isActivated);
smartphoneScreenCenter.SetActive (isActivated);
smartphoneCamera.SetActive (isActivated);
changingZoom = false;
initializeComponents ();
if (isActivated) {
if (mainPlayerWeaponsManager != null) {
mainPlayerWeaponsManager.setWeaponPartLayer (smartphoneScreenCanvas);
mainPlayerWeaponsManager.setWeaponPartLayer (smartphoneScreenCenter);
}
}
if (useEventsOnSmartphoneTurnOnOff) {
if (isActivated) {
eventOnSmartphoneTurnedOn.Invoke ();
} else {
eventOnSmartphoneTurnedOff.Invoke ();
}
}
if (isActivated) {
updateCoroutine = StartCoroutine (updateSystemCoroutine ());
} else {
stopUpdateCoroutine ();
}
}
public void playSound ()
{
if (usePhotoSound) {
if (mainAudioSource != null)
GKC_Utils.checkAudioSourcePitch (mainAudioSource);
AudioPlayer.PlayOneShot (photoAudioElement, gameObject);
}
}
public void setCurrentPerspectiveSystem (cameraPerspectiveSystem perspective)
{
currentPerspectiveSystem = perspective;
perspectiveSystemLocated = currentPerspectiveSystem != null;
}
public void removeCurrentPerspectiveSystem ()
{
currentPerspectiveSystem = null;
perspectiveSystemLocated = false;
}
public Camera getSmarthphoneMainCamera ()
{
return smartphoneMainCamera;
}
public void setUseEventOnCaptureState (bool state)
{
useEventOnCapture = state;
}
public void setStoreCapturesEnabledState (bool state)
{
storeCapturesEnabled = state;
}
public void setUseOverrideSystemOnCaptureState (bool state)
{
useOverrideSystemOnCapture = state;
}
public void rotateScreenToRight ()
{
mainScreenCenter.localEulerAngles = Vector3.zero;
screenCenter.localEulerAngles = Vector3.zero;
smartphoneCamera.transform.localEulerAngles = Vector3.zero;
}
public void rotateScreenToLeft ()
{
mainScreenCenter.localEulerAngles = new Vector3 (0, 0, 180);
screenCenter.localEulerAngles = new Vector3 (0, 0, 180);
smartphoneCamera.transform.localEulerAngles = new Vector3 (0, 0, 180);
}
public void setFirstOrThirdPersonViewState (bool state)
{
firstPersonActive = state;
if (useEventsOnCameraViewChange) {
if (firstPersonActive) {
eventOnCameraViewChangeToFirstPerson.Invoke ();
} else {
eventOnCameraViewChangeToThirdPerson.Invoke ();
}
}
}
bool componentsInitialized;
void initializeComponents ()
{
if (componentsInitialized) {
return;
}
if (mainPlayerWeaponsManager == null) {
mainPlayerWeaponsManager = weaponManager.getPlayerWeaponsManger ();
}
GameObject playerControllerGameObject = mainPlayerWeaponsManager.getPlayerGameObject ();
playerComponentsManager mainPlayerComponentsManager = playerControllerGameObject.GetComponent<playerComponentsManager> ();
if (mainPlayerComponentsManager != null) {
cameraCaptureManager = mainPlayerComponentsManager.getCameraCaptureSystem ();
if (cameraCaptureManager != null) {
cameraCaptureManagerLocated = true;
}
playerCamera mainPlayerCamera = mainPlayerComponentsManager.getPlayerCamera ();
playerCameraTransform = mainPlayerCamera.transform;
raycastTransform = mainPlayerCamera.getMainCamera ().transform;
mainOverrideElementControlSystem = mainPlayerComponentsManager.getOverrideElementControlSystem ();
if (mainEventObjectFoundOnRaycastSystem != null) {
mainEventObjectFoundOnRaycastSystem.setRaycastTransform (raycastTransform);
}
Canvas mainSmartphoneCanvas = smartphoneScreenCanvas.GetComponent<Canvas> ();
if (mainSmartphoneCanvas != null) {
if (mainSmartphoneCanvas.worldCamera == null) {
mainSmartphoneCanvas.worldCamera = mainPlayerCamera.getMainCamera ();
}
}
}
componentsInitialized = true;
}
}

View File

@@ -0,0 +1,19 @@
fileFormatVersion: 2
guid: 323c0278c308c1640b72811d317c0915
timeCreated: 1524511111
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/Weapons/New Weapon Behaviors/smartphoneDevice.cs
uploadId: 814740

View File

@@ -0,0 +1,390 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
public class surfaceToSlice : MonoBehaviour
{
[Header ("Main Settings")]
[Space]
public bool cutSurfaceEnabled = true;
public bool useCustomForceAmount;
public float customForceAmount;
public bool useCustomForceMode;
public ForceMode customForceMode;
[Space]
public bool useBoxCollider;
public bool ignoreRegularDamageIfCutSurfaceNotEnabled;
[Space]
public GameObject mainSurfaceToSlice;
[Space]
[Header ("Material Settings")]
[Space]
public Material crossSectionMaterial;
[Space]
[Header ("Tag and Layer Settings")]
[Space]
public bool setNewTagOnCut;
public string newTagOnCut;
public bool setNewLayerOnCut;
public string newLayerOnCut;
[Space]
[Header ("Particle Settings")]
[Space]
public bool useParticlesOnSlice;
public GameObject particlesOnSlicePrefab;
[Space]
[Header ("Slice Limit Settings")]
[Space]
public bool cutMultipleTimesActive = true;
public bool useLimitedNumberOfCuts;
public int limitedNumberOfCuts;
[Space]
[Header ("Slice Direction Settings")]
[Space]
public bool checkForCustomSliceDirection;
public float maxSliceDirectionAngle;
public Transform customSliceDirectionUp;
public bool allowReverseSliceDirection;
[Space]
[Header ("Character Settings")]
[Space]
public bool objectIsCharacter;
[Space]
public bool ignoreDamageIfSliceNotActivated;
[Space]
public simpleSliceSystem mainSimpleSliceSystem;
[Space]
[Header ("Bullet Time Settings")]
[Space]
public bool useTimeBulletOnSliceEnabled;
public float timeBulletDuration = 3;
public float timeScale = 0.2f;
[Space]
[Header ("Debug")]
[Space]
public bool destroySlicedPartsAfterDelay;
public float delayToDestroySlicedParts;
[Space]
[Header ("Debug")]
[Space]
public bool showDebugPrint;
public bool mainSimpleSliceSystemAssigned;
[Space]
[Header ("Events Settings")]
[Space]
public bool useEventOnCut;
public UnityEvent eventOnCut;
public bool copyEventOnSlicedObjects;
[Space]
public bool useEventBeforeCut;
public UnityEvent eventBeforeCut;
float lastTimeSliced;
destroyGameObject mainDestroyGameObject;
bool mainDestroyGameObjectAssigned;
public void checkEventBeforeSlice ()
{
if (useEventBeforeCut) {
eventBeforeCut.Invoke ();
}
}
public void checkEventOnCut ()
{
if (useEventOnCut) {
eventOnCut.Invoke ();
}
}
public void copySurfaceInfo (surfaceToSlice surfaceToCopy)
{
lastTimeSliced = Time.time;
surfaceToCopy.setCrossSectionMaterial (crossSectionMaterial);
surfaceToCopy.setNewTagOnCut = setNewTagOnCut;
surfaceToCopy.newTagOnCut = newTagOnCut;
surfaceToCopy.setNewLayerOnCut = setNewLayerOnCut;
surfaceToCopy.newLayerOnCut = newLayerOnCut;
if (useParticlesOnSlice) {
surfaceToCopy.useParticlesOnSlice = useParticlesOnSlice;
surfaceToCopy.particlesOnSlicePrefab = particlesOnSlicePrefab;
}
surfaceToCopy.cutMultipleTimesActive = cutMultipleTimesActive;
if (useLimitedNumberOfCuts) {
surfaceToCopy.useLimitedNumberOfCuts = useLimitedNumberOfCuts;
surfaceToCopy.limitedNumberOfCuts = limitedNumberOfCuts - 1;
}
surfaceToCopy.useCustomForceAmount = useCustomForceAmount;
surfaceToCopy.customForceAmount = customForceAmount;
surfaceToCopy.useCustomForceMode = useCustomForceMode;
surfaceToCopy.customForceMode = customForceMode;
surfaceToCopy.useBoxCollider = useBoxCollider;
surfaceToCopy.lastTimeSliced = lastTimeSliced;
surfaceToCopy.destroySlicedPartsAfterDelay = destroySlicedPartsAfterDelay;
surfaceToCopy.delayToDestroySlicedParts = delayToDestroySlicedParts;
surfaceToCopy.copyEventOnSlicedObjects = copyEventOnSlicedObjects;
if (copyEventOnSlicedObjects) {
surfaceToCopy.useEventOnCut = useEventOnCut;
surfaceToCopy.eventOnCut = eventOnCut;
}
}
public bool isObjectCharacter ()
{
return objectIsCharacter;
}
public bool isIgnoreDamageIfSliceNotActivatedActive ()
{
return ignoreDamageIfSliceNotActivated;
}
public bool isCutSurfaceEnabled ()
{
return cutSurfaceEnabled;
}
public void setCutSurfaceEnabledState (bool state)
{
cutSurfaceEnabled = state;
if (showDebugPrint) {
print ("Set Cut Surface Enabled State " + cutSurfaceEnabled);
}
}
public void setIgnoreRegularDamageIfCutSurfaceNotEnabledState (bool state)
{
ignoreRegularDamageIfCutSurfaceNotEnabled = state;
}
public bool isIgnoreRegularDamageIfCutSurfaceNotEnabled ()
{
return ignoreRegularDamageIfCutSurfaceNotEnabled;
}
public float getLastTimeSliced ()
{
return lastTimeSliced;
}
public bool sliceCanBeActivated (float minDelayToSliceSameObject)
{
if (useLimitedNumberOfCuts) {
if (limitedNumberOfCuts <= 0) {
return false;
}
}
if (Time.time > lastTimeSliced + minDelayToSliceSameObject) {
return true;
}
return false;
}
public bool checkSliceDirectionResult (Vector3 sliceDirectionRight, Vector3 sliceDirectionUp)
{
if (checkForCustomSliceDirection) {
float sliceAngleRight =
Vector3.SignedAngle (sliceDirectionRight, customSliceDirectionUp.right,
customSliceDirectionUp.forward);
float sliceAngleRightABS = Mathf.Abs (sliceAngleRight);
float sliceAngleUp =
Vector3.SignedAngle (sliceDirectionUp, customSliceDirectionUp.up,
customSliceDirectionUp.forward);
float sliceAngleUpABS = Mathf.Abs (sliceAngleUp);
if (showDebugPrint) {
print ("checkSliceDirectionResult " + sliceDirectionRight + " " + sliceAngleRight);
print (sliceDirectionUp + " " + sliceAngleUp);
}
if (allowReverseSliceDirection) {
float oppositeRightAngle = (180 - sliceAngleRightABS);
if (oppositeRightAngle < maxSliceDirectionAngle) {
return true;
} else {
if (oppositeRightAngle < 90) {
float oppositeUpAngle = (180 - sliceAngleUpABS);
if (oppositeUpAngle < maxSliceDirectionAngle) {
return true;
}
}
}
}
if (sliceAngleRightABS <= maxSliceDirectionAngle) {
return true;
} else {
if (sliceAngleRightABS < 90) {
if (sliceAngleUpABS <= maxSliceDirectionAngle) {
return true;
}
}
}
return false;
}
return true;
}
public simpleSliceSystem getMainSimpleSliceSystem ()
{
return mainSimpleSliceSystem;
}
public void setMainSimpleSliceSystem (GameObject newObject)
{
if (newObject != null) {
mainSimpleSliceSystem = newObject.GetComponent<simpleSliceSystem> ();
}
}
public void setDestructionPending (bool state)
{
if (!mainSimpleSliceSystemAssigned) {
mainSimpleSliceSystemAssigned = mainSimpleSliceSystem != null;
}
if (mainSimpleSliceSystemAssigned) {
mainSimpleSliceSystem.setDestructionPending (state);
}
}
public void setUseTimeBulletValue (bool state)
{
useTimeBulletOnSliceEnabled = state;
}
public void checkTimeBulletOnCut ()
{
if (useTimeBulletOnSliceEnabled) {
GKC_Utils.activateTimeBulletXSeconds (timeBulletDuration, timeScale);
}
}
public Material getCrossSectionMaterial ()
{
return crossSectionMaterial;
}
public void setCrossSectionMaterial (Material newMaterial)
{
crossSectionMaterial = newMaterial;
}
public void checkDestroySlicedPartsAfterDelay ()
{
if (destroySlicedPartsAfterDelay && !objectIsCharacter) {
mainDestroyGameObjectAssigned = mainDestroyGameObject != null;
if (!mainDestroyGameObjectAssigned) {
mainDestroyGameObject = gameObject.AddComponent<destroyGameObject> ();
mainDestroyGameObjectAssigned = true;
}
if (mainDestroyGameObjectAssigned) {
mainDestroyGameObject.setTimer (delayToDestroySlicedParts);
}
}
}
public void setMainSurfaceToSlice (GameObject newObject)
{
mainSurfaceToSlice = newObject;
}
public GameObject getMainSurfaceToSlice ()
{
if (mainSurfaceToSlice == null) {
mainSurfaceToSlice = gameObject;
}
return mainSurfaceToSlice;
}
//EDITOR FUNCTIONS
public void setCutSurfaceEnabledStateFromEditor (bool state)
{
setCutSurfaceEnabledState (state);
updateComponent ();
}
void updateComponent ()
{
GKC_Utils.updateComponent (this);
GKC_Utils.updateDirtyScene ("Update Surface To Slice", gameObject);
}
}

View File

@@ -0,0 +1,19 @@
fileFormatVersion: 2
guid: ec517ad904783e044a7e6bdc3c783099
timeCreated: 1576821048
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/Weapons/New Weapon Behaviors/surfaceToSlice.cs
uploadId: 814740

View File

@@ -0,0 +1,528 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class vacuumGun : MonoBehaviour
{
[Header ("Main Settings")]
[Space]
public bool vacuumEnabled = true;
public LayerMask layerToDetect;
public bool ignoreObjectsTag;
public List<string> tagsToIgnore = new List<string> ();
public string layerToSetOnObjectsFound = "Ignore Raycast";
public float maxDistanceGrab;
public bool storeObjectsOnInventory;
public float minDistanceToStoreObjects;
public float vacuumSpeed = 10;
public float holdDistance = 3;
public bool destroyAllObjectsOnReachPosition = true;
[Space]
[Header ("Expel Object Settings")]
[Space]
public bool expelEnabled;
public Transform expelTransformPosition;
public float expelRate = 0.5f;
public float expelForce = 20;
public bool expelObjectsOneByOne;
[Space]
[Header ("Ignore Expel Object Settings")]
[Space]
public bool ignoreInventoryObjectListToExpel;
public List<string> ignoreInventoryObjectListToExpelList = new List<string> ();
public bool ignoreInventoryObjectCategoryListToExpel;
public List<string> ignoreInventoryObjectCategoryListToExpelList = new List<string> ();
[Space]
[Header ("Other Settings")]
[Space]
public bool useRotor = true;
public Transform rotor;
public float rotorRotationSpeed = 10;
[Space]
[Header ("Debug")]
[Space]
public bool expelActive;
public bool vacuumActive;
public List<Rigidbody> rigidbodyList = new List<Rigidbody> ();
public List<rigidbodyInfo> rigidbodyInfoList = new List<rigidbodyInfo> ();
[Space]
[Header ("Remote Events Settings")]
[Space]
public bool useRemoteEvents;
public List<string> removeEventNameList = new List<string> ();
[Space]
[Header ("Components")]
[Space]
public inventoryManager mainInventoryManager;
public playerController playerControllerManager;
public playerCamera playerCameraManager;
public playerWeaponSystem mainPlayerWeaponSystem;
public Transform mainCameraTransform;
Coroutine updateCoroutine;
bool componentsInitialized;
RaycastHit hit;
GameObject currentObjectToGrabFound;
Vector3 nextObjectHeldPosition;
Vector3 currentObjectHeldPosition;
Transform currentHoldTransform;
float orignalHoldDistance;
float lastTimeExpel;
public void stopUpdateCoroutine ()
{
if (updateCoroutine != null) {
StopCoroutine (updateCoroutine);
}
}
IEnumerator updateSystemCoroutine ()
{
var waitTime = new WaitForFixedUpdate ();
while (true) {
updateSystem ();
yield return waitTime;
}
}
void updateSystem ()
{
if (vacuumActive) {
if (Physics.Raycast (mainCameraTransform.position, mainCameraTransform.TransformDirection (Vector3.forward), out hit, maxDistanceGrab, layerToDetect)) {
if (currentObjectToGrabFound != hit.collider.gameObject) {
currentObjectToGrabFound = hit.collider.gameObject;
bool checkObjectResult = true;
if (ignoreObjectsTag) {
if (tagsToIgnore.Contains (currentObjectToGrabFound.tag)) {
checkObjectResult = false;
}
}
if (!checkObjectResult) {
return;
}
Rigidbody newRigidbody = currentObjectToGrabFound.GetComponent<Rigidbody> ();
if (newRigidbody != null) {
if (!rigidbodyList.Contains (newRigidbody)) {
rigidbodyList.Add (newRigidbody);
rigidbodyInfo newRigidbodyInfo = new rigidbodyInfo ();
newRigidbodyInfo.mainGameObject = currentObjectToGrabFound;
newRigidbodyInfo.objectLayer = currentObjectToGrabFound.layer;
rigidbodyInfoList.Add (newRigidbodyInfo);
newRigidbody.gameObject.layer = LayerMask.NameToLayer (layerToSetOnObjectsFound);
}
}
if (useRemoteEvents) {
remoteEventSystem currentRemoteEventSystem = currentObjectToGrabFound.GetComponent<remoteEventSystem> ();
if (currentRemoteEventSystem != null) {
for (int i = 0; i < removeEventNameList.Count; i++) {
currentRemoteEventSystem.callRemoteEvent (removeEventNameList [i]);
}
}
}
}
}
if (rigidbodyList.Count > 0) {
currentHoldTransform = mainCameraTransform;
if (playerCameraManager.is2_5ViewActive ()) {
currentHoldTransform = playerCameraManager.getCurrentLookDirection2_5d ();
holdDistance = 0;
}
if (playerCameraManager.useTopDownView) {
currentHoldTransform = playerCameraManager.getCurrentLookDirectionTopDown ();
holdDistance = 0;
}
for (int i = 0; i < rigidbodyList.Count; i++) {
Rigidbody currentRigidbody = rigidbodyList [i];
if (currentRigidbody != null) {
nextObjectHeldPosition = currentHoldTransform.position + mainCameraTransform.forward * holdDistance;
currentObjectHeldPosition = currentRigidbody.position;
currentRigidbody.linearVelocity = (nextObjectHeldPosition - currentObjectHeldPosition) * vacuumSpeed;
if (storeObjectsOnInventory) {
if (GKC_Utils.distance (mainCameraTransform.position, currentRigidbody.position) < minDistanceToStoreObjects) {
pickUpObject currentPickupObject = currentRigidbody.GetComponent<pickUpObject> ();
if (currentPickupObject != null) {
string inventoryObjectName = currentPickupObject.getPickupObjectName ();
// print ("checking " + inventoryObjectName);
if (inventoryObjectName != "") {
int inventoryObjectAmount = (int)currentPickupObject.getAmountPicked ();
// print ("checking " + inventoryObjectAmount);
removeRigidbodyFromList (currentRigidbody);
if (applyDamage.giveInventoryObjectToCharacter (playerControllerManager.gameObject,
inventoryObjectName,
inventoryObjectAmount, null,
0, 0,
ForceMode.Impulse, 0, false, false, false)) {
Destroy (currentRigidbody.gameObject);
}
checkNullObjects ();
return;
} else {
if (destroyAllObjectsOnReachPosition) {
Destroy (currentRigidbody.gameObject);
checkNullObjects ();
return;
} else {
removeRigidbodyFromList (currentRigidbody);
checkNullObjects ();
return;
}
}
} else {
if (destroyAllObjectsOnReachPosition) {
Destroy (currentRigidbody.gameObject);
checkNullObjects ();
return;
} else {
removeRigidbodyFromList (currentRigidbody);
checkNullObjects ();
return;
}
}
}
} else {
if (destroyAllObjectsOnReachPosition) {
Destroy (currentRigidbody.gameObject);
checkNullObjects ();
return;
} else {
removeRigidbodyFromList (currentRigidbody);
checkNullObjects ();
return;
}
}
} else {
removeRigidbodyFromList (currentRigidbody);
checkNullObjects ();
return;
}
}
}
}
if (expelActive) {
if (Time.time > lastTimeExpel + expelRate) {
if (!mainInventoryManager.isInventoryEmpty ()) {
inventoryInfo currentInventoryInfo = mainInventoryManager.getRandomInventoryInfo ();
if (currentInventoryInfo != null) {
bool canExpelObjectResult = true;
if (!currentInventoryInfo.canBeDropped) {
canExpelObjectResult = false;
}
if (canExpelObjectResult) {
if (ignoreInventoryObjectListToExpel) {
if (ignoreInventoryObjectListToExpelList.Contains (currentInventoryInfo.Name)) {
canExpelObjectResult = false;
}
}
if (canExpelObjectResult) {
if (ignoreInventoryObjectCategoryListToExpel) {
if (ignoreInventoryObjectCategoryListToExpelList.Contains (currentInventoryInfo.categoryName)) {
canExpelObjectResult = false;
}
}
}
}
if (canExpelObjectResult) {
int amountToDrop = 0;
if (expelObjectsOneByOne) {
amountToDrop = 1;
} else {
amountToDrop = currentInventoryInfo.amount;
}
mainInventoryManager.dropObjectByName (currentInventoryInfo.Name, amountToDrop, true, false, false);
GameObject lastObjectDropped = mainInventoryManager.getLastObjectDropped ();
if (lastObjectDropped != null && previousObjectDropped != lastObjectDropped) {
lastObjectDropped.transform.position = expelTransformPosition.position;
Rigidbody currentObjectRigidbody = lastObjectDropped.GetComponent<Rigidbody> ();
if (currentObjectRigidbody != null) {
currentObjectRigidbody.AddForce (expelTransformPosition.forward * expelForce, ForceMode.Impulse);
}
previousObjectDropped = lastObjectDropped;
}
lastTimeExpel = Time.time;
}
}
} else {
enableOrDisableExpel (false);
}
}
}
if (useRotor) {
rotor.Rotate (0, 0, Time.deltaTime * rotorRotationSpeed);
}
}
GameObject previousObjectDropped;
void checkNullObjects ()
{
for (int i = rigidbodyList.Count - 1; i >= 0; i--) {
if (rigidbodyList [i] == null) {
rigidbodyList.RemoveAt (i);
}
}
}
void removeRigidbodyFromList (Rigidbody currentRigidbody)
{
if (currentRigidbody == null) {
return;
}
if (rigidbodyList.Contains (currentRigidbody)) {
rigidbodyList.Remove (currentRigidbody);
int currentIndex = rigidbodyInfoList.FindIndex (s => s.mainGameObject == currentRigidbody.gameObject);
if (currentIndex > -1) {
rigidbodyInfo newRigidbodyInfo = rigidbodyInfoList [currentIndex];
if (newRigidbodyInfo.mainGameObject != null) {
newRigidbodyInfo.mainGameObject.layer = newRigidbodyInfo.objectLayer;
}
rigidbodyInfoList.RemoveAt (currentIndex);
}
}
}
public void setVacuumEnabledState (bool state)
{
if (!state) {
if (vacuumActive) {
enableOrDisableVacuum (false);
}
}
vacuumEnabled = state;
}
public void enableVacuum ()
{
enableOrDisableVacuum (true);
}
public void disableVacuum ()
{
enableOrDisableVacuum (false);
}
public void enableOrDisableVacuum (bool state)
{
if (!vacuumEnabled) {
return;
}
vacuumActive = state;
mainInventoryManager.setEquipWeaponsWhenPickedPausedState (state);
if (state) {
initializeComponents ();
holdDistance = orignalHoldDistance;
updateCoroutine = StartCoroutine (updateSystemCoroutine ());
expelActive = false;
} else {
stopUpdateCoroutine ();
currentObjectToGrabFound = null;
rigidbodyList.Clear ();
for (int i = 0; i < rigidbodyInfoList.Count; i++) {
rigidbodyInfo newRigidbodyInfo = rigidbodyInfoList [i];
if (newRigidbodyInfo.mainGameObject != null) {
newRigidbodyInfo.mainGameObject.layer = newRigidbodyInfo.objectLayer;
}
}
rigidbodyInfoList.Clear ();
}
}
public void setExpelEnabledState (bool state)
{
if (!state) {
if (expelActive) {
enableOrDisableExpel (false);
}
}
expelEnabled = state;
}
public void enableOrDisableExpel (bool state)
{
if (!expelEnabled) {
return;
}
expelActive = state;
previousObjectDropped = null;
lastTimeExpel = Time.time;
if (state) {
initializeComponents ();
updateCoroutine = StartCoroutine (updateSystemCoroutine ());
if (vacuumActive) {
mainInventoryManager.setEquipWeaponsWhenPickedPausedState (false);
vacuumActive = false;
}
} else {
stopUpdateCoroutine ();
}
}
void initializeComponents ()
{
if (componentsInitialized) {
return;
}
if (mainPlayerWeaponSystem != null) {
GameObject playerControllerGameObject = mainPlayerWeaponSystem.getPlayerWeaponsManger ().gameObject;
playerComponentsManager mainPlayerComponentsManager = playerControllerGameObject.GetComponent<playerComponentsManager> ();
if (mainPlayerComponentsManager != null) {
playerControllerManager = mainPlayerComponentsManager.getPlayerController ();
playerCameraManager = mainPlayerComponentsManager.getPlayerCamera ();
mainCameraTransform = playerCameraManager.getCameraTransform ();
}
}
orignalHoldDistance = holdDistance;
componentsInitialized = true;
}
[System.Serializable]
public class rigidbodyInfo
{
public GameObject mainGameObject;
public int objectLayer;
}
}

View File

@@ -0,0 +1,19 @@
fileFormatVersion: 2
guid: fbd2c141967e2f242ac26019a57a7652
timeCreated: 1696540501
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/Weapons/New Weapon Behaviors/vacuumGun.cs
uploadId: 814740

View File

@@ -0,0 +1,456 @@
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using GameKitController.Audio;
public class weaponLaser : laser
{
[Space]
[Header ("Main Settings")]
[Space]
public bool weaponLaserEnabled;
public float laserDamage = 0.3f;
public LayerMask layer;
public laserDevice.laserType lasertype;
public int reflactionLimit = 10;
public float useEnergyRate;
public int amountEnergyUsed;
public bool useMinTimeToUseLaserDamageRate;
public float minTimeToUseLaserDamageRate;
public float laserDamageRate;
[Space]
[Header ("Sound Settings")]
[Space]
public AudioClip laserEffect;
public AudioElement laserEffectAudioElement;
public float playSoundRate;
[Space]
[Header ("Debug")]
[Space]
public bool reloading;
public GameObject currentLaser;
[Space]
[Header ("Components")]
[Space]
public playerWeaponSystem weaponManager;
public Transform mainCameraTransform;
public AudioSource mainAudioSource;
public GameObject hitSmoke;
public GameObject hitSparks;
public GameObject laserLight;
public GameObject player;
float lastTimeLaserActive;
bool laserActivePreviously;
float lastTimeLaserDamage;
Vector3 inDirection;
Vector3 laserHitPosition;
RaycastHit hit;
Ray ray;
int nPoints;
Renderer currentLaserRenderer;
float lastTimeUsed;
float lastTimeSoundPlayed;
bool canDamage;
int propertyNameID;
private void InitializeAudioElements ()
{
if (laserEffect != null) {
laserEffectAudioElement.clip = laserEffect;
}
if (mainAudioSource != null) {
laserEffectAudioElement.audioSource = mainAudioSource;
}
}
void Start ()
{
InitializeAudioElements ();
propertyNameID = Shader.PropertyToID ("_TintColor");
StartCoroutine (laserAnimation ());
reflactionLimit++;
lRenderer.positionCount = 0;
}
void Update ()
{
if (reloading) {
if (weaponManager.remainAmmoInClip () && weaponManager.carryingWeapon () && !weaponManager.isWeaponReloading ()) {
reloading = false;
} else {
return;
}
}
if (!weaponLaserEnabled) {
return;
}
if (Time.time > lastTimeUsed + useEnergyRate) {
if (weaponManager.remainAmmoInClip () && !weaponManager.isWeaponReloading ()) {
lastTimeUsed = Time.time;
weaponManager.useAmmo (amountEnergyUsed);
weaponManager.checkToUpdateInventoryWeaponAmmoTextFromWeaponSystem ();
}
if (!weaponManager.remainAmmoInClip () || weaponManager.isWeaponReloading ()) {
setWeaponLaserState (false);
reloading = true;
return;
}
}
if (Time.time > lastTimeSoundPlayed + playSoundRate) {
lastTimeSoundPlayed = Time.time;
playWeaponSoundEffect ();
}
//the player's laser can be reflected, so the linerenderer has reflactionLimit vertex
if (lasertype == laserDevice.laserType.refraction) {
reflactionLimit = Mathf.Clamp (reflactionLimit, 1, reflactionLimit);
ray = new Ray (mainCameraTransform.position, mainCameraTransform.TransformDirection (Vector3.forward));
nPoints = reflactionLimit;
//make the lineRenderer have nPoints
lRenderer.positionCount = reflactionLimit;
//set the first point of the line it its current positions
lRenderer.SetPosition (0, transform.position);
for (int i = 0; i < reflactionLimit; i++) {
//if the ray has not be reflected yet
if (i == 0) {
//check if the ray has hit something
if (Physics.Raycast (ray.origin, ray.direction, out hit, Mathf.Infinity, layer)) {
//the reflection direction is the reflection of the current ray direction flipped at the hit normal
inDirection = Vector3.Reflect (ray.direction, hit.normal);
//cast the reflected ray, using the hit point as the origin and the reflected direction as the direction
ray = new Ray (hit.point, inDirection);
//if the number of reflections is set to 1
if (reflactionLimit == 1) {
//add a new vertex to the line renderer
lRenderer.positionCount = nPoints++;
}
//set the position of the next vertex at the line renderer to be the same as the hit point
lRenderer.SetPosition (i + 1, hit.point);
laserDistance = hit.distance;
if (hit.collider.gameObject != player) {
damageTarget (hit.collider.gameObject, -ray.direction, hit.point);
}
} else {
//if the rays does not hit anything, set as a single straight line in the camera direction and disable the smoke
laserDistance = 1000;
transform.rotation = mainCameraTransform.rotation;
hitSmoke.SetActive (false);
hitSparks.SetActive (false);
lRenderer.positionCount = 2;
lRenderer.SetPosition (0, transform.position);
lRenderer.SetPosition (1, (laserDistance * transform.forward));
}
} else if (i > 0) {
//check if the ray has hit something
if (Physics.Raycast (ray.origin, ray.direction, out hit, Mathf.Infinity, layer)) {
//the refletion direction is the reflection of the ray's direction at the hit normal
inDirection = Vector3.Reflect (inDirection, hit.normal);
//cast the reflected ray, using the hit point as the origin and the reflected direction as the direction
ray = new Ray (hit.point, inDirection);
lRenderer.positionCount = nPoints++;
//set the position of the next vertex at the line renderer to be the same as the hit point
lRenderer.SetPosition (i + 1, hit.point);
if (i + 1 == reflactionLimit) {
//if this linerenderer vertex is the last, set the smoke in its position and check for a refraction cube or a laser receiver
hitSparks.SetActive (true);
hitSmoke.SetActive (true);
hitSmoke.transform.position = hit.point;
hitSmoke.transform.rotation = Quaternion.identity;
hitSparks.transform.rotation = Quaternion.LookRotation (hit.normal, transform.up);
if (hit.collider.GetComponent<laserReceiver> () || hit.collider.GetComponent<refractionCube> ()) {
connectLasers (hit.collider.gameObject);
}
//check if the laser hits an object with a health component different from the player
}
if (hit.collider.gameObject != player) {
damageTarget (hit.collider.gameObject, -ray.direction, hit.point);
}
laserDistance = hit.distance;
}
}
}
}
//the player's laser cannot be reflected, so the linerenderer only has 2 vertex
if (lasertype == laserDevice.laserType.simple) {
animateLaser ();
if (Physics.Raycast (mainCameraTransform.position, mainCameraTransform.TransformDirection (Vector3.forward), out hit, Mathf.Infinity, layer)) {
//set the direction of the laser in the hit point direction
transform.LookAt (hit.point);
//check with a raycast if the laser hits a receiver, a refraction cube or a gameObject with a health component or a vehicle damage receiver
//Debug.DrawRay (mainCameraTransform.position, mainCameraTransform.TransformDirection (Vector3.forward)*hit.distance, Color.yellow);
if (hit.collider.GetComponent<laserReceiver> () || hit.collider.GetComponent<refractionCube> ()) {
connectLasers (hit.collider.gameObject);
}
if (hit.collider.gameObject != player) {
damageTarget (hit.collider.gameObject, -ray.direction, hit.point);
}
//get the hit position to set the particles of smoke and sparks
laserDistance = hit.distance;
hitSparks.SetActive (true);
hitSmoke.SetActive (true);
hitSmoke.transform.position = hit.point - transform.forward * 0.02f;
hitSmoke.transform.rotation = Quaternion.identity;
hitSparks.transform.rotation = Quaternion.LookRotation (hit.normal, transform.up);
lRenderer.positionCount = 2;
lRenderer.SetPosition (0, transform.position);
lRenderer.SetPosition (1, hit.point);
//set the laser size
} else {
//set the direction of the laser in the camera forward
Quaternion lookDir = Quaternion.LookRotation (mainCameraTransform.TransformDirection (Vector3.forward));
transform.rotation = lookDir;
hitSmoke.SetActive (false);
hitSparks.SetActive (false);
laserDistance = 1000;
lRenderer.positionCount = 2;
lRenderer.SetPosition (0, transform.position);
lRenderer.SetPosition (1, (laserDistance * transform.forward));
}
}
}
public void damageTarget (GameObject objectToDamage, Vector3 laserDirection, Vector3 hitPoint)
{
canDamage = false;
if (useMinTimeToUseLaserDamageRate) {
if (Time.time > lastTimeLaserActive + minTimeToUseLaserDamageRate &&
Time.time > lastTimeLaserDamage + laserDamageRate) {
lastTimeLaserDamage = Time.time;
canDamage = true;
}
} else {
canDamage = true;
}
if (canDamage) {
applyDamage.checkHealth (gameObject, objectToDamage, laserDamage, -laserDirection, hitPoint, player, true, true,
weaponManager.weaponSettings.ignoreShield, false, weaponManager.weaponSettings.damageCanBeBlocked, false, -1,
weaponManager.weaponSettings.damageTypeID);
}
}
void connectLasers (GameObject hitObject)
{
//check if the object touched with the laser is a laser receiver, to check if the current color of the laser is equal to the color needed
//in the laser receiver
laserReceiver currentLaserReceiver = hitObject.GetComponent<laserReceiver> ();
refractionCube currentRefractionCube = hitObject.GetComponent<refractionCube> ();
if (currentLaserReceiver != null) {
if (currentLaserReceiver.colorNeeded == mainRenderer.material.GetColor (propertyNameID)) {
currentLaserReceiver.laserConnected (mainRenderer.material.GetColor (propertyNameID));
} else {
//else the laser is not reflected
return;
}
}
//if the object is not a laser receiver or a refraction cube, the laser is not refrated
else if (currentRefractionCube == null) {
return;
} else {
//if the cube is already being used by another laser, cancel the action
if (currentRefractionCube.isRefracting ()) {
return;
}
}
gameObject.SetActive (false);
//deflect the laser and enable the laser connector
GameObject baseLaserConnector = currentLaser.GetComponent<laserDevice> ().laserConnector;
baseLaserConnector.SetActive (true);
baseLaserConnector.transform.position = laserHitPosition;
baseLaserConnector.transform.LookAt (hitObject.transform.position);
laserConnector currentLaserConnector = baseLaserConnector.GetComponent<laserConnector> ();
if (currentRefractionCube != null) {
//if the hitted objects is a cube refraction, enable the laser inside it
if (!currentRefractionCube.isRefracting ()) {
baseLaserConnector.GetComponent<laserConnector> ().setCubeRefractionLaser (hitObject);
currentRefractionCube.cubeLaserDeviceGameObject.transform.rotation = baseLaserConnector.transform.rotation;
currentRefractionCube.setRefractingLaserState (true);
} else {
baseLaserConnector.SetActive (false);
currentRefractionCube.setRefractingLaserState (false);
return;
}
}
//stop the laser that hits the player from detect any other collision, to deflect it
currentLaser.SendMessage ("assignLaser");
currentLaserConnector.setCurrentLaser (currentLaser);
currentLaserConnector.setColor ();
currentLaser = null;
}
//set the color of the laser according to the color of the laser device
void setColor ()
{
if (currentLaserRenderer.material.HasProperty (propertyNameID)) {
Color c = currentLaserRenderer.material.GetColor (propertyNameID);
mainRenderer.material.SetColor (propertyNameID, c);
}
}
public void setLaserInfo (laserDevice.laserType type, GameObject laser, Vector3 pos)
{
//get the position where the lasers hits the player,
laserHitPosition = pos;
//get the laser that it is hitting the player
currentLaser = laser;
if (currentLaserRenderer == null) {
currentLaserRenderer = currentLaser.GetComponent<Renderer> ();
}
setColor ();
lasertype = type;
if (lasertype == laserDevice.laserType.refraction) {
//lRenderer.useWorldSpace=true;
} else {
lRenderer.positionCount = 2;
lRenderer.SetPosition (0, Vector3.zero);
//lRenderer.useWorldSpace=false;
}
}
public void removeLaserInfo ()
{
currentLaserRenderer = null;
}
public void enableWeaponLaser ()
{
setWeaponLaserState (true);
}
public void disableWeaponLaser ()
{
setWeaponLaserState (false);
}
public void setWeaponLaserState (bool state)
{
if (reloading) {
weaponLaserEnabled = false;
return;
}
initializeComponents ();
weaponLaserEnabled = state;
if (laserActivePreviously != weaponLaserEnabled) {
if (weaponLaserEnabled) {
lastTimeLaserActive = Time.time;
}
laserActivePreviously = weaponLaserEnabled;
}
laserLight.SetActive (weaponLaserEnabled);
if (weaponLaserEnabled) {
hitSmoke.transform.SetParent (null);
} else {
lRenderer.positionCount = 0;
hitSparks.SetActive (false);
hitSmoke.SetActive (false);
hitSmoke.transform.SetParent (transform);
}
}
void playWeaponSoundEffect ()
{
if (laserEffectAudioElement != null) {
AudioPlayer.PlayOneShot (laserEffectAudioElement, gameObject);
}
}
bool componentsInitialized;
void initializeComponents ()
{
if (componentsInitialized) {
return;
}
if (weaponManager != null) {
GameObject playerControllerGameObject = weaponManager.getPlayerWeaponsManger ().gameObject;
playerComponentsManager mainPlayerComponentsManager = playerControllerGameObject.GetComponent<playerComponentsManager> ();
if (mainPlayerComponentsManager != null) {
player = mainPlayerComponentsManager.getPlayerController ().gameObject;
mainCameraTransform = mainPlayerComponentsManager.getPlayerCamera ().getCameraTransform ();
}
}
componentsInitialized = true;
}
}

View File

@@ -0,0 +1,19 @@
fileFormatVersion: 2
guid: f9f43eec15676c945a3c3c4b20725ec4
timeCreated: 1537381416
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/Weapons/New Weapon Behaviors/weaponLaser.cs
uploadId: 814740