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,139 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
public class checkpointElement : MonoBehaviour
{
[Header ("Main Settings")]
[Space]
public int checkpointID;
public bool overwriteThisCheckpoint;
public bool saveFirstTimeCheckpointElementFound = true;
public bool saveInEveryTriggerEnter;
[Space]
[Header ("Transform Settings")]
[Space]
public bool useCustomSaveTransform;
public Transform customSaveTransform;
public bool useCustomCameraTransform;
public Transform customCameraTransform;
public Transform customCameraPivotTransform;
[Space]
[Header ("Other Settings")]
[Space]
public List<string> tagToSave = new List<string> ();
[Space]
[Header ("Debug")]
[Space]
public bool checkpointAlreadyFound;
[Space]
[Header ("Event Settings")]
[Space]
public bool useEventOnCheckpointActivated;
public UnityEvent eventOnCheckpointActivated;
[Space]
[Header ("Components")]
[Space]
public checkpointSystem checkpointManager;
public Collider mainCollider;
void Awake ()
{
StartCoroutine (activateTriggers ());
}
IEnumerator activateTriggers ()
{
if (mainCollider != null) {
mainCollider.enabled = false;
yield return new WaitForSeconds (1);
mainCollider.enabled = true;
}
}
public void setCheckPointManager (checkpointSystem manager)
{
checkpointManager = manager;
updateComponent ();
}
public void OnTriggerEnter (Collider col)
{
if (!checkpointManager.isCheckpointSystemEnabled ()) {
return;
}
if ((!checkpointAlreadyFound || saveInEveryTriggerEnter || saveFirstTimeCheckpointElementFound) && tagToSave.Contains (col.tag)) {
bool saveGameResult = false;
if (checkpointAlreadyFound) {
if (saveInEveryTriggerEnter) {
saveGameResult = true;
}
} else {
if (saveFirstTimeCheckpointElementFound) {
saveGameResult = true;
}
}
checkpointAlreadyFound = true;
if (checkpointManager == null) {
checkpointManager = FindObjectOfType<checkpointSystem> ();
}
if (saveGameResult) {
playerComponentsManager currentPlayerComponentsManager = col.gameObject.GetComponent<playerComponentsManager> ();
if (currentPlayerComponentsManager != null) {
saveGameSystem currentSaveGameSystem = currentPlayerComponentsManager.getSaveGameSystem ();
if (checkpointManager != null) {
currentSaveGameSystem.setSavingGameManuallyActiveState (true);
if (useCustomSaveTransform) {
currentSaveGameSystem.saveGameCheckpoint (customSaveTransform, checkpointID, checkpointManager.checkpointSceneID, overwriteThisCheckpoint, false, true);
} else {
currentSaveGameSystem.saveGameCheckpoint (null, checkpointID, checkpointManager.checkpointSceneID, overwriteThisCheckpoint, false, true);
}
currentSaveGameSystem.setSavingGameManuallyActiveState (false);
}
}
}
checkpointManager.setCurrentCheckpointElement (transform);
if (useEventOnCheckpointActivated) {
eventOnCheckpointActivated.Invoke ();
}
}
}
public void updateComponent ()
{
GKC_Utils.updateComponent (this);
GKC_Utils.updateDirtyScene ("Update Checkpoint Element Info", gameObject);
}
}

View File

@@ -0,0 +1,19 @@
fileFormatVersion: 2
guid: 6d1be9437ad75df4884011214c944426
timeCreated: 1522544869
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/Checkpoint/checkpointElement.cs
uploadId: 814740

View File

@@ -0,0 +1,258 @@
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class checkpointSystem : MonoBehaviour
{
public bool checkpointSystemEnabled = true;
public int checkpointSceneID;
public GameObject checkPointPrefab;
public LayerMask layerToPlaceNewCheckpoints;
public Vector3 checkpointsPositionOffset;
public Vector3 triggerScale;
public LayerMask layerToRespawn;
public List<Transform> checkPointList = new List<Transform> ();
public deathLoadCheckpoint deathLoackCheckpointType;
public enum deathLoadCheckpoint
{
reloadScene,
respawn,
none
}
public bool showGizmo;
public Color gizmoLabelColor = Color.black;
public float gizmoRadius;
public bool useHandleForVertex;
public float handleRadius;
public Color handleGizmoColor;
public List<checkpointElement> checkPoinElementtList = new List<checkpointElement> ();
public checkpointElement currentCheckpointElement;
RaycastHit hit;
public void setCurrentCheckpointElement (Transform currentCheckpoint)
{
for (int i = 0; i < checkPointList.Count; i++) {
if (checkPointList [i] == currentCheckpoint) {
currentCheckpointElement = checkPoinElementtList [i];
}
}
}
public void respawnPlayer (GameObject currentPlayer)
{
if (!thereIsLastCheckpoint ()) {
print ("WARNING, NO CHECKPOINT STORED");
return;
}
Vector3 respawnPosition = currentCheckpointElement.transform.position;
Quaternion respawnRotation = currentCheckpointElement.transform.rotation;
if (currentCheckpointElement.useCustomSaveTransform) {
respawnPosition = currentCheckpointElement.customSaveTransform.position;
respawnRotation = currentCheckpointElement.customSaveTransform.rotation;
}
if (Physics.Raycast (respawnPosition + Vector3.up, -Vector3.up, out hit, Mathf.Infinity, layerToRespawn)) {
respawnPosition = hit.point;
}
playerController currentPlayerController = currentPlayer.GetComponent<playerController> ();
if (currentPlayerController != null) {
currentPlayerController.changeScriptState (false);
currentPlayerController.changeScriptState (true);
currentPlayerController.setPlayerVelocityToZero ();
currentPlayerController.setLastTimeFalling ();
GameObject playerCameraGameObject = currentPlayerController.getPlayerCameraGameObject ();
playerCameraGameObject.transform.position = respawnPosition;
playerCameraGameObject.transform.rotation = respawnRotation;
}
currentPlayer.transform.position = respawnPosition;
currentPlayer.transform.rotation = respawnRotation;
}
public bool thereIsLastCheckpoint ()
{
return currentCheckpointElement != null;
}
public void disableCheckPoint (int checkpointID)
{
for (int i = 0; i < checkPoinElementtList.Count; i++) {
if (checkPoinElementtList [i].checkpointID == checkpointID) {
checkPoinElementtList [i].gameObject.SetActive (false);
} else {
checkPoinElementtList [i].gameObject.SetActive (true);
}
}
}
public void setCheckpointSystemEnabledState (bool state)
{
checkpointSystemEnabled = state;
}
public bool isCheckpointSystemEnabled ()
{
return checkpointSystemEnabled;
}
public bool checkCheckpointStateOnCharacterGetUp (ragdollActivator currentRagdollActivator, GameObject characterGameObject)
{
bool usingCheckPoint = false;
if (thereIsLastCheckpoint ()) {
usingCheckPoint = true;
if (deathLoackCheckpointType == deathLoadCheckpoint.respawn) {
currentRagdollActivator.quickGetUp ();
respawnPlayer (characterGameObject);
} else if (deathLoackCheckpointType == deathLoadCheckpoint.reloadScene) {
playerComponentsManager currentPlayerControllerManager = characterGameObject.GetComponent<playerComponentsManager> ();
if (currentPlayerControllerManager != null) {
saveGameSystem currentSaveGameSystem = currentPlayerControllerManager.getSaveGameSystem ();
if (currentSaveGameSystem != null) {
currentSaveGameSystem.reloadLastCheckpoint ();
}
}
} else if (deathLoackCheckpointType == deathLoadCheckpoint.none) {
currentRagdollActivator.getUp ();
}
}
return usingCheckPoint;
}
public bool isDeathLoadCheckpointRespawnActivee ()
{
return deathLoackCheckpointType == deathLoadCheckpoint.respawn;
}
//EDITOR FUNCTIONS
//add a new checkpoint
public void addNewCheckpoint ()
{
Vector3 newPosition = transform.position;
if (checkPointList.Count > 0) {
newPosition = checkPointList [checkPointList.Count - 1].position + checkPointList [checkPointList.Count - 1].forward;
}
Camera currentCameraEditor = GKC_Utils.getCameraEditor ();
if (currentCameraEditor != null) {
Vector3 editorCameraPosition = currentCameraEditor.transform.position;
Vector3 editorCameraForward = currentCameraEditor.transform.forward;
RaycastHit hit;
if (Physics.Raycast (editorCameraPosition, editorCameraForward, out hit, Mathf.Infinity, layerToPlaceNewCheckpoints)) {
newPosition = hit.point + Vector3.right * checkpointsPositionOffset.x + Vector3.up * checkpointsPositionOffset.y + Vector3.forward * checkpointsPositionOffset.z;
}
}
GameObject newWayPoint = Instantiate (checkPointPrefab);
newWayPoint.transform.SetParent (transform);
newWayPoint.transform.position = newPosition;
newWayPoint.name = "Checkpoint " + (checkPointList.Count + 1);
newWayPoint.GetComponent<BoxCollider> ().size = triggerScale;
checkPointList.Add (newWayPoint.transform);
checkpointElement newCheckpointElement = newWayPoint.GetComponent<checkpointElement> ();
newCheckpointElement.setCheckPointManager (this);
newCheckpointElement.checkpointID = checkPointList.Count;
checkPoinElementtList.Add (newCheckpointElement);
updateComponent ();
}
public void removeCheckpoint (int checkpointIndex)
{
DestroyImmediate (checkPointList [checkpointIndex].gameObject);
checkPointList.RemoveAt (checkpointIndex);
checkPoinElementtList.RemoveAt (checkpointIndex);
updateComponent ();
}
public void removeAllCheckpoints ()
{
for (int i = 0; i < checkPointList.Count; i++) {
if (checkPointList [i].gameObject != null) {
DestroyImmediate (checkPointList [i].gameObject);
}
}
checkPointList.Clear ();
checkPoinElementtList.Clear ();
updateComponent ();
}
public void updateComponent ()
{
GKC_Utils.updateComponent (this);
GKC_Utils.updateDirtyScene ("Update Checkpoint System Info", gameObject);
}
void OnDrawGizmos ()
{
if (!showGizmo) {
return;
}
if (GKC_Utils.isCurrentSelectionActiveGameObject (gameObject)) {
DrawGizmos ();
}
}
void OnDrawGizmosSelected ()
{
DrawGizmos ();
}
void DrawGizmos ()
{
if (showGizmo) {
for (int i = 0; i < checkPointList.Count; i++) {
if (checkPointList [i] != null) {
Gizmos.color = Color.yellow;
Gizmos.DrawSphere (checkPointList [i].position, gizmoRadius);
if (i + 1 < checkPointList.Count) {
Gizmos.color = Color.white;
Gizmos.DrawLine (checkPointList [i].position, checkPointList [i + 1].position);
}
}
}
}
}
}

View File

@@ -0,0 +1,19 @@
fileFormatVersion: 2
guid: 63c4df5eaa11cf14c852ab5bcbc9dd46
timeCreated: 1522542386
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/Checkpoint/checkpointSystem.cs
uploadId: 814740