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,216 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class grapplingHookEffect : MonoBehaviour
{
[Header ("Main Settings")]
[Space]
[Tooltip ("The speed of the entire effect.")]
public float Speed = 3f;
[Tooltip ("The speed of the spiral offset (relative to 'Speed').")]
public float SpiralSpeed = 4f;
[Tooltip ("The speed that the end of the line moves to the target point (relative to 'Speed')")]
public float DistanceSpeed = 2f;
[Tooltip ("A multiplier for the pull of gravity.")]
public float Gravity = 0.5f;
[Tooltip ("The number of points to be drawn by the line renderer. \nUpdates every time the effect is triggered.")]
public int Segments = 100;
public LayerMask layerMask;
[Space]
[Header ("Spiral Settings")]
[Space]
[Tooltip ("The strength of the spiral.")]
public Vector2 Magnitude = Vector2.one;
[Tooltip ("The number of 'Curve' repetitions per world-unit.")]
public float Frequency = 0.5f;
[Tooltip ("The amount the horizontal part of the spiral is offset along 'Curve.' \nIf 'Curve' is a sine wave, 0.25 will result in a perfect spiral.")]
public float HorizontalOffset = 0.25f;
[Space]
[Header ("Noise Settings")]
[Space]
[Tooltip ("The strength of the noise.")]
public float Strength = 0.5f;
[Tooltip ("The scale of the noise samples. \nHigher = smoother.")]
public float Scale = 0.25f;
[Space]
[Header ("Curves Settings")]
[Space]
[Tooltip ("The base curve that the points will be offset along. \nA sine wave will make it look like a grapple spiral.")]
public AnimationCurve Curve = new AnimationCurve ();
[Tooltip ("The strength of the spiral and noise over time.")]
public AnimationCurve MagnitudeOverTime = new AnimationCurve ();
[Tooltip ("The strength of the spiral and noise from the start to current end point within a 0 to 1 range.")]
public AnimationCurve MagnitudeOverDistance = new AnimationCurve ();
[Tooltip ("The vertical offset applied in world space to the line from the start to current end point within a 0 to 1 range.")]
public AnimationCurve GravityOverDistance = new AnimationCurve ();
[Tooltip ("The strength of the gravity over time.")]
public AnimationCurve GravityOverTime = new AnimationCurve ();
[Space]
[Header ("Debug")]
[Space]
public bool showGizmo;
public bool grapplingHookEffectActive;
public bool fixedUpdateActive;
[Space]
[Header ("Components")]
[Space]
public LineRenderer lineRenderer;
public Transform mainCameraTransform;
public Transform lineRendererOriginPositionTransform;
public Transform lineRendererTargetPositionTransform;
public Transform playerControllerTransform;
float scaledTimeOffset = 0f;
float spiralTimeOffset = 0f;
float lastGrappleTime = 0f;
Vector3 grapplePoint;
RaycastHit hit;
Vector3 currentPosition;
public void activateGrapplingHookEffect (Vector3 raycastDirection)
{
if (Physics.Raycast (mainCameraTransform.position, raycastDirection, out hit, Mathf.Infinity, layerMask)) {
lineRenderer.enabled = true;
DoGrapple (hit.point);
grapplingHookEffectActive = true;
}
if (showGizmo) {
Debug.DrawLine (mainCameraTransform.position, mainCameraTransform.position + raycastDirection * 1000, Color.red, 5);
}
}
public void activateGrapplingHookEffect ()
{
if (Physics.Raycast (mainCameraTransform.position, mainCameraTransform.forward, out hit, Mathf.Infinity, layerMask)) {
lineRenderer.enabled = true;
DoGrapple (hit.point);
grapplingHookEffectActive = true;
}
}
public void deactivateGrapplingHookEffect ()
{
grapplingHookEffectActive = false;
lineRenderer.enabled = false;
for (int i = 0; i < lineRenderer.positionCount; i++) {
lineRenderer.SetPosition (i, lineRendererOriginPositionTransform.position);
}
}
public void DoGrapple (Vector3 newWrapplePoint)
{
grapplePoint = newWrapplePoint;
scaledTimeOffset = spiralTimeOffset = 0f;
if (lineRenderer.positionCount != Segments)
lineRenderer.positionCount = Segments;
lastGrappleTime = Time.time * 10f;
}
public void setFixedUpdateActiveState (bool state)
{
fixedUpdateActive = state;
}
void Update ()
{
if (!fixedUpdateActive) {
updateEffect ();
}
}
void FixedUpdate ()
{
if (fixedUpdateActive) {
updateEffect ();
}
}
void updateEffect ()
{
if (grapplingHookEffectActive) {
if (lineRendererTargetPositionTransform == null) {
deactivateGrapplingHookEffect ();
return;
}
grapplePoint = lineRendererTargetPositionTransform.position;
lineRendererOriginPositionTransform.LookAt (grapplePoint);
var difference = grapplePoint - lineRendererOriginPositionTransform.position;
var direction = difference.normalized;
var distanceMultiplier = Mathf.Clamp01 (scaledTimeOffset * DistanceSpeed);
var distance = difference.magnitude * distanceMultiplier;
scaledTimeOffset += Speed * Time.deltaTime;
if (distanceMultiplier < 1f) {
spiralTimeOffset += Speed * SpiralSpeed * Time.deltaTime;
}
for (int i = 0; i < lineRenderer.positionCount; i++) {
var t = (float)i / lineRenderer.positionCount;
currentPosition = lineRendererOriginPositionTransform.position;
var forwardOffset = direction * (t * distance);
currentPosition += forwardOffset;
var curveSamplePosition = forwardOffset.magnitude * Frequency - spiralTimeOffset;
var verticalOffset = lineRendererOriginPositionTransform.up * Curve.Evaluate (curveSamplePosition);
var horizontalOffset = lineRendererOriginPositionTransform.right * Curve.Evaluate (curveSamplePosition + HorizontalOffset);
verticalOffset *= Magnitude.y;
horizontalOffset *= Magnitude.x;
var noiseSamplePosition = -t * Scale + scaledTimeOffset + lastGrappleTime;
verticalOffset += lineRendererOriginPositionTransform.up * ((Mathf.PerlinNoise (0f, noiseSamplePosition) - 0.5f) * 2f * Strength);
horizontalOffset += lineRendererOriginPositionTransform.right * ((Mathf.PerlinNoise (noiseSamplePosition, 0f) - 0.5f) * 2f * Strength);
var magnitude = MagnitudeOverTime.Evaluate (scaledTimeOffset) * MagnitudeOverDistance.Evaluate (t);
verticalOffset *= magnitude;
horizontalOffset *= magnitude;
currentPosition += verticalOffset;
currentPosition += horizontalOffset;
currentPosition += Vector3.up * (GravityOverDistance.Evaluate (t) * GravityOverTime.Evaluate (scaledTimeOffset) * Gravity);
lineRenderer.SetPosition (i, currentPosition);
}
}
}
public void changeLineRendererOriginPositionParent (Transform newParent)
{
lineRendererOriginPositionTransform.SetParent (newParent);
lineRendererOriginPositionTransform.localPosition = Vector3.zero;
}
public void setNewlineRendererTargetPositionTransform (Transform newObject)
{
lineRendererTargetPositionTransform = newObject;
}
}

View File

@@ -0,0 +1,20 @@
fileFormatVersion: 2
guid: 8a55238d07af02149ac7ad442bf3acca
timeCreated: 1581945381
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/Abilities System/Custom Abilities/Grappling
Hook System/grapplingHookEffect.cs
uploadId: 814740

View File

@@ -0,0 +1,20 @@
fileFormatVersion: 2
guid: 12e8b09b03a5ec14faa0cfc3861a18fd
timeCreated: 1581811914
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/Abilities System/Custom Abilities/Grappling
Hook System/grapplingHookSystem.cs
uploadId: 814740

View File

@@ -0,0 +1,170 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
public class grapplingHookTarget : MonoBehaviour
{
[Header ("Main Settings")]
[Space]
public bool grapplingHookTargetEnabled = true;
public List<string> tagsToCheck = new List<string> ();
public LayerMask layermaskToCheck;
[Space]
[Header ("Custom Hook Transform Settings")]
[Space]
public bool useCustomTransformTarget;
public Transform customTransformTarget;
[Space]
[Header ("Event Settings")]
[Space]
public bool useEventOnHookReceived;
public UnityEvent eventOnHookReceived;
[Space]
public bool useEventOnSwingReceived;
public UnityEvent eventOnSwingReceived;
[Space]
[Header ("Gizmo Settings")]
[Space]
public bool showGizmo;
public Color gizmoLabelColor = Color.green;
public Color gizmoColor = Color.white;
public float gizmoRadius = 0.3f;
[Space]
[Header ("Components")]
[Space]
public SphereCollider mainSphereCollider;
Transform targetTransform;
void OnTriggerEnter (Collider col)
{
checkTriggerInfo (col, true);
}
void OnTriggerExit (Collider col)
{
checkTriggerInfo (col, false);
}
public void checkTriggerInfo (Collider col, bool isEnter)
{
if (!grapplingHookTargetEnabled) {
return;
}
if ((1 << col.gameObject.layer & layermaskToCheck.value) == 1 << col.gameObject.layer) {
if (isEnter) {
if (tagsToCheck.Contains (col.tag)) {
GameObject currentPlayer = col.gameObject;
playerComponentsManager currentPlayerComponentsManager = currentPlayer.GetComponent<playerComponentsManager> ();
if (currentPlayerComponentsManager != null) {
grapplingHookTargetsSystem currentGrapplingHookTargetsSystem = currentPlayerComponentsManager.getGrapplingHookTargetsSystem ();
if (currentGrapplingHookTargetsSystem != null) {
if (targetTransform == null) {
if (useCustomTransformTarget) {
targetTransform = customTransformTarget;
} else {
targetTransform = transform;
}
}
currentGrapplingHookTargetsSystem.addNewGrapplingHookTarget (targetTransform);
}
}
}
} else {
if (tagsToCheck.Contains (col.tag)) {
GameObject currentPlayer = col.gameObject;
playerComponentsManager currentPlayerComponentsManager = currentPlayer.GetComponent<playerComponentsManager> ();
if (currentPlayerComponentsManager != null) {
grapplingHookTargetsSystem currentGrapplingHookTargetsSystem = currentPlayerComponentsManager.getGrapplingHookTargetsSystem ();
if (currentGrapplingHookTargetsSystem != null) {
if (targetTransform == null) {
if (useCustomTransformTarget) {
targetTransform = customTransformTarget;
} else {
targetTransform = transform;
}
}
currentGrapplingHookTargetsSystem.removeNewGrapplingHookTarget (targetTransform);
}
}
}
}
}
}
public void checkEventOnHookReceived ()
{
if (useEventOnHookReceived) {
eventOnHookReceived.Invoke ();
}
}
public void checkEventOnSwingReceived ()
{
if (useEventOnSwingReceived) {
eventOnSwingReceived.Invoke ();
}
}
void OnDrawGizmos ()
{
if (!showGizmo) {
return;
}
if (GKC_Utils.isCurrentSelectionActiveGameObject (gameObject)) {
DrawGizmos ();
}
}
void OnDrawGizmosSelected ()
{
DrawGizmos ();
}
void DrawGizmos ()
{
if (showGizmo) {
Gizmos.color = gizmoColor;
if (useCustomTransformTarget) {
Gizmos.DrawWireSphere (customTransformTarget.position, gizmoRadius);
} else {
Gizmos.DrawWireSphere (transform.position, gizmoRadius);
}
if (mainSphereCollider != null) {
mainSphereCollider.radius = gizmoRadius;
}
}
}
}

View File

@@ -0,0 +1,20 @@
fileFormatVersion: 2
guid: 5976360ec5494bf4cb381f61cab8b332
timeCreated: 1583300762
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/Abilities System/Custom Abilities/Grappling
Hook System/grapplingHookTarget.cs
uploadId: 814740

View File

@@ -0,0 +1,352 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class grapplingHookTargetsSystem : MonoBehaviour
{
[Header ("Main Settings")]
[Space]
public bool showGrapplingHookTargetsActive = true;
public LayerMask layerForThirdPerson;
public LayerMask layerForFirstPerson;
public bool checkObstaclesToGrapplingHookTargets;
[Space]
public List<grapplingHookSystem> grapplingHookSystemList = new List<grapplingHookSystem> ();
[Space]
[Header ("Debug")]
[Space]
public bool showGrapplingHookTargetsPaused;
public Transform closestTarget;
public List<grapplingHookTargetInfo> grapplingHookTargetInfoList = new List<grapplingHookTargetInfo> ();
[Space]
[Header ("Components")]
[Space]
public GameObject grapplingHookTargetIconPrefab;
public Camera mainCamera;
public Transform mainCameraTransform;
public GameObject playerGameObject;
public playerCamera mainPlayerCamera;
public Transform grapplingHookTargetIconsParent;
public playerTeleportSystem mainPlayerTeleportSystem;
Vector3 screenPoint;
Vector3 currentPosition;
Vector3 mainCameraPosition;
Vector3 direction;
float distanceToMainCamera;
bool layerForThirdPersonAssigned;
bool layerForFirstPersonAssigned;
LayerMask currentLayer;
bool activeIcon;
Vector2 mainCanvasSizeDelta;
Vector2 halfMainCanvasSizeDelta;
Vector2 iconPosition2d;
Vector3 currentTargetPosition;
bool usingScreenSpaceCamera;
bool targetOnScreen;
float screenWidth;
float screenHeight;
grapplingHookTargetInfo currentGrapplingHookTargetInfo;
Transform previousClosestTarget;
Vector3 centerScreen;
float currentDistanceToTarget;
float minDistanceToTarget;
[HideInInspector] public grapplingHookTargetInfo closestTargetInfo;
grapplingHookTargetInfo previousClosestTargetInfo;
bool hookTargetsDetected;
int grapplingHookTargetInfoListCount;
void Start ()
{
mainCanvasSizeDelta = mainPlayerCamera.getMainCanvasSizeDelta ();
halfMainCanvasSizeDelta = mainCanvasSizeDelta * 0.5f;
usingScreenSpaceCamera = mainPlayerCamera.isUsingScreenSpaceCamera ();
if (mainCamera == null) {
mainCamera = mainPlayerCamera.getMainCamera ();
}
}
void LateUpdate ()
{
if (!showGrapplingHookTargetsActive || showGrapplingHookTargetsPaused || !hookTargetsDetected) {
return;
}
if (mainPlayerCamera.isFirstPersonActive ()) {
if (!layerForThirdPersonAssigned) {
currentLayer = layerForFirstPerson;
layerForThirdPersonAssigned = true;
layerForFirstPersonAssigned = false;
}
} else {
if (!layerForFirstPersonAssigned) {
currentLayer = layerForThirdPerson;
layerForFirstPersonAssigned = true;
layerForThirdPersonAssigned = false;
}
}
if (!usingScreenSpaceCamera) {
screenWidth = Screen.width;
screenHeight = Screen.height;
}
mainCameraPosition = mainCameraTransform.position;
minDistanceToTarget = Mathf.Infinity;
centerScreen = new Vector3 (screenWidth / 2, screenHeight / 2, 0);
bool anyTargetVisible = false;
grapplingHookTargetInfoListCount = grapplingHookTargetInfoList.Count;
for (int i = 0; i < grapplingHookTargetInfoListCount; i++) {
currentGrapplingHookTargetInfo = grapplingHookTargetInfoList [i];
if (currentGrapplingHookTargetInfo.targetCanBeShown) {
currentPosition = currentGrapplingHookTargetInfo.targetTransform.position;
currentTargetPosition = currentPosition + currentGrapplingHookTargetInfo.positionOffset;
if (usingScreenSpaceCamera) {
screenPoint = mainCamera.WorldToViewportPoint (currentTargetPosition);
targetOnScreen = screenPoint.z > 0 && screenPoint.x > 0 && screenPoint.x < 1 && screenPoint.y > 0 && screenPoint.y < 1;
} else {
screenPoint = mainCamera.WorldToScreenPoint (currentTargetPosition);
targetOnScreen = screenPoint.z > 0 && screenPoint.x > 0 && screenPoint.x < screenWidth && screenPoint.y > 0 && screenPoint.y < screenHeight;
}
if (targetOnScreen) {
if (currentGrapplingHookTargetInfo.iconCurrentlyEnabled) {
if (usingScreenSpaceCamera) {
iconPosition2d = new Vector2 ((screenPoint.x * mainCanvasSizeDelta.x) - halfMainCanvasSizeDelta.x, (screenPoint.y * mainCanvasSizeDelta.y) - halfMainCanvasSizeDelta.y);
currentGrapplingHookTargetInfo.targetRectTransform.anchoredPosition = iconPosition2d;
} else {
currentGrapplingHookTargetInfo.targetRectTransform.position = new Vector3 (screenPoint.x, screenPoint.y, 0);
}
}
if (checkObstaclesToGrapplingHookTargets) {
//set the direction of the raycast
direction = currentTargetPosition - mainCameraPosition;
direction = direction / direction.magnitude;
activeIcon = false;
distanceToMainCamera = GKC_Utils.distance (mainCameraPosition, currentTargetPosition);
//if the raycast find an obstacle between the enemy and the camera, disable the icon
//if the distance from the camera to the enemy is higher than 100, disable the raycast and the icon
if (Physics.Raycast (currentTargetPosition, -direction, distanceToMainCamera, currentLayer)) {
activeIcon = false;
} else {
//else, the raycast reachs the camera, so enable the pick up icon
activeIcon = true;
}
currentGrapplingHookTargetInfo.targetVisible = activeIcon;
} else {
currentGrapplingHookTargetInfo.targetVisible = true;
}
if (currentGrapplingHookTargetInfo.targetVisible) {
screenPoint = mainCamera.WorldToScreenPoint (currentPosition);
currentDistanceToTarget = GKC_Utils.distance (screenPoint, centerScreen);
if (currentDistanceToTarget < minDistanceToTarget) {
minDistanceToTarget = currentDistanceToTarget;
closestTargetInfo = currentGrapplingHookTargetInfo;
}
anyTargetVisible = true;
}
} else {
currentGrapplingHookTargetInfo.targetVisible = false;
}
} else {
currentGrapplingHookTargetInfo.targetVisible = false;
}
}
if (anyTargetVisible) {
if (closestTargetInfo != null) {
closestTarget = closestTargetInfo.targetTransform;
if (closestTarget != previousClosestTarget) {
previousClosestTarget = closestTarget;
if (previousClosestTargetInfo != null) {
if (previousClosestTargetInfo.iconCurrentlyEnabled) {
previousClosestTargetInfo.targetRectTransform.gameObject.SetActive (false);
previousClosestTargetInfo.iconCurrentlyEnabled = false;
}
}
previousClosestTargetInfo = closestTargetInfo;
closestTargetInfo.targetRectTransform.gameObject.SetActive (true);
closestTargetInfo.iconCurrentlyEnabled = true;
for (int i = 0; i < grapplingHookSystemList.Count; i++) {
if (grapplingHookSystemList [i] != null) {
grapplingHookSystemList [i].setGrapplingHookTarget (closestTarget);
}
}
mainPlayerTeleportSystem.setTeleportHookTarget (closestTarget);
}
}
} else {
if (closestTargetInfo != null && closestTargetInfo.targetRectTransform != null) {
closestTargetInfo.targetRectTransform.gameObject.SetActive (false);
closestTargetInfo.iconCurrentlyEnabled = false;
closestTargetInfo = null;
closestTarget = null;
previousClosestTarget = null;
for (int i = 0; i < grapplingHookSystemList.Count; i++) {
if (grapplingHookSystemList [i] != null) {
grapplingHookSystemList [i].setGrapplingHookTarget (null);
}
}
mainPlayerTeleportSystem.setTeleportHookTarget (null);
}
}
}
public void setCurrentGrapplingHookTargetState (bool state)
{
currentGrapplingHookTargetInfo.targetRectTransform.gameObject.SetActive (state);
currentGrapplingHookTargetInfo.iconCurrentlyEnabled = state;
}
public void disableGrapplingHookTargets ()
{
enableOrDisableGrapplingHookTargets (false);
}
public void enableGrapplingHookTargets ()
{
enableOrDisableGrapplingHookTargets (true);
}
public void enableOrDisableGrapplingHookTargets (bool state)
{
for (int i = 0; i < grapplingHookTargetInfoList.Count; i++) {
currentGrapplingHookTargetInfo = grapplingHookTargetInfoList [i];
if (currentGrapplingHookTargetInfo.targetTransform != null) {
currentGrapplingHookTargetInfo.targetTransform.gameObject.SetActive (state);
currentGrapplingHookTargetInfo.iconCurrentlyEnabled = state;
}
}
}
public void addNewGrapplingHookTarget (Transform targetTransform)
{
grapplingHookTargetInfo newGrapplingHookTargetInfo = new grapplingHookTargetInfo ();
GameObject grapplingHookTargetGameObject = Instantiate (grapplingHookTargetIconPrefab);
grapplingHookTargetGameObject.name = "Grappling Hook Target " + grapplingHookTargetInfoList.Count;
grapplingHookTargetGameObject.transform.SetParent (grapplingHookTargetIconsParent);
grapplingHookTargetGameObject.transform.localScale = Vector3.one;
grapplingHookTargetGameObject.transform.localPosition = Vector3.zero;
grapplingHookTargetGameObject.transform.localRotation = Quaternion.identity;
newGrapplingHookTargetInfo.targetTransform = targetTransform;
newGrapplingHookTargetInfo.iconCurrentlyEnabled = false;
newGrapplingHookTargetInfo.targetRectTransform = grapplingHookTargetGameObject.GetComponent<RectTransform> ();
grapplingHookTargetInfoList.Add (newGrapplingHookTargetInfo);
hookTargetsDetected = true;
}
public void removeNewGrapplingHookTarget (Transform targetTransform)
{
for (int i = 0; i < grapplingHookTargetInfoList.Count; i++) {
if (grapplingHookTargetInfoList [i].targetTransform == targetTransform) {
grapplingHookTargetInfoList [i].iconCurrentlyEnabled = false;
Destroy (grapplingHookTargetInfoList [i].targetRectTransform.gameObject);
grapplingHookTargetInfoList.RemoveAt (i);
if (grapplingHookTargetInfoList.Count == 0) {
for (int j = 0; j < grapplingHookSystemList.Count; j++) {
if (grapplingHookSystemList [i] != null) {
grapplingHookSystemList [j].setGrapplingHookTarget (null);
}
}
mainPlayerTeleportSystem.setTeleportHookTarget (null);
hookTargetsDetected = false;
}
return;
}
}
}
public void pauseOrResumeShowGrapplingHookTargets (bool state)
{
showGrapplingHookTargetsPaused = state;
grapplingHookTargetIconsParent.gameObject.SetActive (!showGrapplingHookTargetsPaused);
}
[System.Serializable]
public class grapplingHookTargetInfo
{
public Transform targetTransform;
public RectTransform targetRectTransform;
public bool targetCanBeShown = true;
public Vector3 positionOffset;
public bool targetVisible;
public bool iconCurrentlyEnabled;
}
}

View File

@@ -0,0 +1,20 @@
fileFormatVersion: 2
guid: 13b53c5db8fa6b149835cb3bece40846
timeCreated: 1583300680
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/Abilities System/Custom Abilities/Grappling
Hook System/grapplingHookTargetsSystem.cs
uploadId: 814740

View File

@@ -0,0 +1,369 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
public class objectToAttractWithGrapplingHook : MonoBehaviour
{
[Header ("Main Settings")]
[Space]
public bool attractObjectEnabled = true;
public bool attractPlayerEnabled;
public bool enableGravityOnDeactivateAttract = true;
public bool useReducedVelocityOnDisableAttract;
public float maxReducedSpeed;
public float reducedSpeedDuration;
public float newSpeedAfterReducedDurationMultiplier = 1;
public bool ignoreApplySpeedOnHookStopOnPlayer;
public bool resetPlayerSpeedOnHookStop;
[Space]
[Header ("Auto Grab Settings")]
[Space]
public bool autoGrabObjectOnCloseDistance;
public float minDistanceToAutoGrab;
[Space]
[Header ("Activate Interaction Action Settings")]
[Space]
public bool activateInteractionActionWithObject;
public float minDistanceToActivateInteractionActionWithObject;
public GameObject objectToActivate;
[Space]
[Header ("Offset Position Settings")]
[Space]
public bool useHookTargetPostionOffset;
public Vector3 hookTargetPositionOffset;
public bool useObjectTargetPositionTransform;
public Transform objectTargetPositionTransform;
[Space]
[Header ("Rigidbody Elements")]
[Space]
public Rigidbody mainRigidbody;
public bool useRigidbodyList;
public List<Rigidbody> rigidbodyList = new List<Rigidbody> ();
[Space]
[Header ("Custom Settings")]
[Space]
public bool useCustomForceAttractionValues;
public float customMinDistanceToStopAttractObject = 5;
public bool customAddUpForceForAttraction;
public float customUpForceForAttraction;
public float customAddUpForceForAttractionDuration;
[Space]
[Header ("Debug")]
[Space]
public bool attractingObjectActive;
[Space]
[Header ("Event Settings")]
[Space]
public bool useEventsOnAttractState;
public UnityEvent eventOnActivateAttract;
public UnityEvent eventOnDeactivateAttract;
public bool useEventAfterReduceSpeed;
public UnityEvent eventAfterReduceSpeed;
[Space]
[Header ("Remote Event Settings")]
[Space]
public bool useRemoteEventsOnStateChange;
public List<string> remoteEventNameListOnStart = new List<string> ();
public List<string> remoteEventNameListOnEnd = new List<string> ();
[Space]
[Header ("Components")]
[Space]
public Transform mainTransform;
[Space]
[Header ("Gizmo Settings")]
[Space]
public bool showGizmo;
public Color gizmoLabelColor = Color.green;
public Color gizmoColor = Color.white;
public float gizmoRadius = 0.3f;
Coroutine reduceSpeedCoroutine;
bool attractionHookRemovedByDistance;
bool reducedSpeedInProcess;
Vector3 speedDirection;
Vector3 previousAngularVelocity;
float previousSpeed;
public void setAttractionHookRemovedByDistanceState (bool state)
{
attractionHookRemovedByDistance = state;
}
public bool setAttractObjectState (bool state)
{
if (attractObjectEnabled) {
attractingObjectActive = state;
if (enableGravityOnDeactivateAttract) {
if (useRigidbodyList) {
for (int i = 0; i < rigidbodyList.Count; i++) {
if (rigidbodyList [i] != null) {
rigidbodyList [i].useGravity = !state;
}
}
} else {
mainRigidbody.useGravity = !state;
}
}
if (useEventsOnAttractState) {
if (attractingObjectActive) {
eventOnActivateAttract.Invoke ();
} else {
eventOnDeactivateAttract.Invoke ();
}
}
if (!attractingObjectActive) {
checkToReduceSpeed ();
}
return attractingObjectActive;
} else {
return false;
}
}
public Rigidbody getRigidbodyToAttract ()
{
return mainRigidbody;
}
public void checkToReduceSpeed ()
{
if (useReducedVelocityOnDisableAttract) {
if (gameObject.activeInHierarchy) {
stopCheckToReduceSpeed ();
reduceSpeedCoroutine = StartCoroutine (checkToReduceSpeedCoroutine ());
}
}
}
public void stopCheckToReduceSpeed ()
{
if (reduceSpeedCoroutine != null) {
StopCoroutine (reduceSpeedCoroutine);
}
}
IEnumerator checkToReduceSpeedCoroutine ()
{
if (!attractionHookRemovedByDistance) {
yield return null;
} else {
reducedSpeedInProcess = true;
previousSpeed = mainRigidbody.linearVelocity.magnitude;
speedDirection = mainRigidbody.linearVelocity.normalized;
previousAngularVelocity = mainRigidbody.angularVelocity;
float t = 0;
bool targetReached = false;
while (!targetReached) {
t += Time.deltaTime;
if (t >= reducedSpeedDuration) {
targetReached = true;
}
if (useRigidbodyList) {
for (int i = 0; i < rigidbodyList.Count; i++) {
if (rigidbodyList [i] != null) {
rigidbodyList [i].linearVelocity = speedDirection * maxReducedSpeed;
rigidbodyList [i].angularVelocity = previousAngularVelocity * maxReducedSpeed;
}
}
} else {
mainRigidbody.linearVelocity = speedDirection * maxReducedSpeed;
mainRigidbody.angularVelocity = previousAngularVelocity * maxReducedSpeed;
}
yield return null;
}
resumeSpeed ();
}
if (useEventAfterReduceSpeed) {
eventAfterReduceSpeed.Invoke ();
}
attractionHookRemovedByDistance = false;
reducedSpeedInProcess = false;
}
public void stopGrapplingHookAndResumeValuesWithoutForce ()
{
speedDirection = Vector3.zero;
previousAngularVelocity = Vector3.zero;
previousSpeed = 0;
stopGrapplingHookAndResumeValues ();
}
public void stopGrapplingHookAndResumeValues ()
{
if (!reducedSpeedInProcess) {
return;
}
stopCheckToReduceSpeed ();
resumeSpeed ();
if (useEventAfterReduceSpeed) {
eventAfterReduceSpeed.Invoke ();
}
attractionHookRemovedByDistance = false;
reducedSpeedInProcess = false;
}
public void stopGrapplingHookIfActiveOnGrabObject ()
{
if (!reducedSpeedInProcess) {
return;
}
stopCheckToReduceSpeed ();
attractionHookRemovedByDistance = false;
reducedSpeedInProcess = false;
speedDirection = Vector3.zero;
previousAngularVelocity = Vector3.zero;
previousSpeed = 0;
}
void resumeSpeed ()
{
if (useRigidbodyList) {
for (int i = 0; i < rigidbodyList.Count; i++) {
if (rigidbodyList [i] != null) {
rigidbodyList [i].linearVelocity = speedDirection * (previousSpeed * newSpeedAfterReducedDurationMultiplier);
}
}
} else {
mainRigidbody.linearVelocity = speedDirection * (previousSpeed * newSpeedAfterReducedDurationMultiplier);
mainRigidbody.angularVelocity = previousAngularVelocity * newSpeedAfterReducedDurationMultiplier;
}
speedDirection = Vector3.zero;
previousAngularVelocity = Vector3.zero;
previousSpeed = 0;
}
public void searchRigidbodyElements ()
{
useRigidbodyList = true;
rigidbodyList.Clear ();
mainRigidbody = null;
if (mainTransform == null) {
mainTransform = transform;
}
Component[] childrens = mainTransform.GetComponentsInChildren (typeof(Rigidbody));
foreach (Rigidbody child in childrens) {
if (child.transform != mainTransform) {
Collider currentCollider = child.GetComponent<Collider> ();
if (currentCollider != null && !currentCollider.isTrigger) {
if (mainRigidbody == null) {
mainRigidbody = child;
}
rigidbodyList.Add (child);
}
}
}
updateComponent ();
}
public void updateComponent ()
{
GKC_Utils.updateComponent (this);
GKC_Utils.updateDirtyScene ("Update Object To Attract with Grappling Hook", gameObject);
}
void OnDrawGizmos ()
{
if (!showGizmo) {
return;
}
if (GKC_Utils.isCurrentSelectionActiveGameObject (gameObject)) {
DrawGizmos ();
}
}
void OnDrawGizmosSelected ()
{
DrawGizmos ();
}
void DrawGizmos ()
{
if (showGizmo) {
Gizmos.color = gizmoColor;
if (useHookTargetPostionOffset) {
if (mainTransform == null) {
mainTransform = transform;
}
if (mainTransform != null) {
Gizmos.DrawWireSphere (mainTransform.position + hookTargetPositionOffset, gizmoRadius);
}
}
}
}
}

View File

@@ -0,0 +1,20 @@
fileFormatVersion: 2
guid: 3439ef56462ca91469ca7959ad11fc4c
timeCreated: 1585265866
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/Abilities System/Custom Abilities/Grappling
Hook System/objectToAttractWithGrapplingHook.cs
uploadId: 814740