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,807 @@
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using UnityEngine.Events;
using System;
public class cameraWaypointSystem : MonoBehaviour
{
public bool cameraWaypointEnabled = true;
public Transform currentCameraTransform;
public List<cameraWaypointInfo> waypointList = new List<cameraWaypointInfo> ();
public float waitTimeBetweenPoints;
public float movementSpeed;
public float rotationSpeed;
public Transform pointToLook;
public bool useEventOnEnd;
public UnityEvent eventOnEnd;
public bool showGizmo;
public Color gizmoLabelColor = Color.black;
public float gizmoRadius;
public bool useHandleForWaypoints;
public float handleRadius;
public Color handleGizmoColor;
public bool showWaypointHandles;
public float currentMovementSpeed;
public float currentRotationSpeed;
public bool useBezierCurve;
public BezierSpline spline;
public float bezierDuration = 10;
public bool useExternalProgress;
[NonSerialized]
public Func<float> externalProgress;
public bool snapCameraToFirstSplinePoint;
public bool searchPlayerOnSceneIfNotAssigned = true;
public bool resetCameraPositionOnEnd;
public float resetCameraPositionSpeed = 5;
public bool pausePlayerCameraEnabled;
public bool useMainCameraTransform;
public bool setThisTransformAsCameraParent;
public bool ignoreWaypointOnFreeCamera;
public bool ignoreWaypointOnLockedCamera;
public bool ignoreWaypointOnFBA;
public bool useEventToStopCutScene;
public UnityEvent eventToStopCutscene;
bool waypointInProcess;
bool customTransformToLookActive;
Transform customTransformToLook;
Coroutine resetCameraPositionCoroutine;
float currentWaitTime;
Vector3 targetDirection;
Coroutine movement;
Transform currentWaypoint;
int currentWaypointIndex;
int i;
List<Transform> currentPath = new List<Transform> ();
cameraWaypointInfo currentCameraWaypointInfo;
int previousWaypointIndex;
Vector3 targetPosition;
Quaternion targetRotation;
GameObject playerCameraGameObject;
Transform pivotDirection;
playerCamera currentPlayerCamera;
Transform previousCameraParent;
Vector3 previousCameraPosition;
Quaternion previousCameraRotation;
bool isCameraTypeFree;
bool isCameraTypeFBA;
public void setCurrentCameraTransform (GameObject cameraGameObject)
{
if (cameraGameObject == null) {
return;
}
currentCameraTransform = cameraGameObject.transform;
if (previousCameraParent == null) {
previousCameraParent = currentCameraTransform.parent;
previousCameraPosition = currentCameraTransform.localPosition;
previousCameraRotation = currentCameraTransform.localRotation;
}
}
public void findPlayerOnScene ()
{
if (searchPlayerOnSceneIfNotAssigned) {
GameObject currentPlayer = GKC_Utils.findMainPlayerOnScene ();
setCurrentPlayer (currentPlayer);
}
}
public void setCurrentPlayer (GameObject currentPlayer)
{
if (currentPlayer != null) {
playerComponentsManager mainPlayerComponentsManager = currentPlayer.GetComponent<playerComponentsManager> ();
if (mainPlayerComponentsManager != null) {
currentPlayerCamera = mainPlayerComponentsManager.getPlayerCamera ();
playerCameraGameObject = currentPlayerCamera.gameObject;
pivotDirection = currentPlayerCamera.getPivotCameraTransform ();
isCameraTypeFree = currentPlayerCamera.isCameraTypeFree ();
isCameraTypeFBA = currentPlayerCamera.isFullBodyAwarenessActive ();
if (useMainCameraTransform) {
if (isCameraTypeFree) {
setCurrentCameraTransform (currentPlayerCamera.getCameraTransform ().gameObject);
} else {
setCurrentCameraTransform (currentPlayerCamera.getCurrentLockedCameraTransform ().gameObject);
}
} else {
setCurrentCameraTransform (currentPlayerCamera.getMainCamera ().gameObject);
}
}
}
}
bool ignoreWaypointOnCurrentViewResult ()
{
if (ignoreWaypointOnFreeCamera) {
if (isCameraTypeFree) {
return true;
}
}
if (ignoreWaypointOnLockedCamera) {
if (!isCameraTypeFree) {
return true;
}
}
if (ignoreWaypointOnFBA) {
if (isCameraTypeFBA) {
return true;
}
}
return false;
}
//stop the platform coroutine movement and play again
public void checkMovementCoroutine (bool play)
{
if (!cameraWaypointEnabled) {
return;
}
if (ignoreWaypointOnCurrentViewResult ()) {
return;
}
stopMoveThroughWayPointsCoroutine ();
if (play) {
if (currentCameraTransform == null) {
findPlayerOnScene ();
if (currentCameraTransform == null) {
print ("WARNING: no current camera transform has been assigned on the camera waypoint system." +
" Make sure to use a trigger to activate the element or assign the player manually");
return;
}
}
currentWaypointIndex = 0;
previousWaypointIndex = -1;
//if the current path to move has waypoints, then
if (currentPath.Count == 0) {
for (i = 0; i < waypointList.Count; i++) {
currentPath.Add (waypointList [i].waypointTransform);
}
}
if (currentPath.Count > 0) {
if (pausePlayerCameraEnabled) {
currentPlayerCamera.pauseOrPlayCamera (false);
}
if (setThisTransformAsCameraParent) {
currentCameraTransform.SetParent (transform);
}
if (useBezierCurve) {
movement = StartCoroutine (moveAlongBezierCurve ());
} else {
movement = StartCoroutine (moveAlongWaypoints ());
}
}
}
}
public void stopMoveThroughWayPointsCoroutine ()
{
if (movement != null) {
StopCoroutine (movement);
}
waypointInProcess = false;
}
IEnumerator moveAlongWaypoints ()
{
waypointInProcess = true;
//move between every waypoint
foreach (Transform waypoint in currentPath) {
currentWaypoint = waypoint;
currentCameraWaypointInfo = waypointList [currentWaypointIndex];
//wait the amount of time configured
if (currentCameraWaypointInfo.useCustomWaitTimeBetweenPoint) {
currentWaitTime = currentCameraWaypointInfo.waitTimeBetweenPoints;
} else {
currentWaitTime = waitTimeBetweenPoints;
}
targetPosition = currentWaypoint.position;
targetRotation = currentWaypoint.rotation;
WaitForSeconds delay = new WaitForSeconds (currentWaitTime);
yield return delay;
//yield return new WaitForSeconds (currentWaitTime);
if (currentCameraWaypointInfo.useCustomMovementSpeed) {
currentMovementSpeed = currentCameraWaypointInfo.movementSpeed;
} else {
currentMovementSpeed = movementSpeed;
}
if (currentCameraWaypointInfo.useCustomRotationSpeed) {
currentRotationSpeed = currentCameraWaypointInfo.rotationSpeed;
} else {
currentRotationSpeed = rotationSpeed;
}
if (currentCameraWaypointInfo.smoothTransitionToNextPoint) {
bool targetReached = false;
float angleDifference = 0;
float currentDistance = 0;
bool checkAngleDifference = false;
if (currentCameraWaypointInfo.checkRotationIsReached) {
checkAngleDifference = true;
}
//while the platform moves from the previous waypoint to the next, then displace it
while (!targetReached) {
currentCameraTransform.position =
Vector3.MoveTowards (currentCameraTransform.position, targetPosition, Time.deltaTime * currentMovementSpeed);
if (currentCameraWaypointInfo.rotateCameraToNextWaypoint) {
targetDirection = targetPosition - currentCameraTransform.position;
}
if (currentCameraWaypointInfo.usePointToLook) {
if (customTransformToLookActive) {
targetDirection = customTransformToLook.position - currentCameraTransform.position;
} else {
targetDirection = currentCameraWaypointInfo.pointToLook.position - currentCameraTransform.position;
}
}
if (targetDirection != Vector3.zero) {
targetRotation = Quaternion.LookRotation (targetDirection);
currentCameraTransform.rotation =
Quaternion.Lerp (currentCameraTransform.rotation, targetRotation, Time.deltaTime * currentRotationSpeed);
}
angleDifference = Quaternion.Angle (currentCameraTransform.rotation, targetRotation);
currentDistance = GKC_Utils.distance (currentCameraTransform.position, targetPosition);
if (checkAngleDifference) {
if (currentDistance < .01f && angleDifference < 1) {
targetReached = true;
}
} else {
if (currentDistance < .01f) {
targetReached = true;
}
}
yield return null;
}
} else {
currentCameraTransform.position = targetPosition;
if (currentCameraWaypointInfo.rotateCameraToNextWaypoint) {
targetDirection = targetPosition - currentCameraTransform.position;
}
if (currentCameraWaypointInfo.usePointToLook) {
if (customTransformToLookActive) {
targetDirection = customTransformToLook.position - currentCameraTransform.position;
} else {
targetDirection = currentCameraWaypointInfo.pointToLook.position - currentCameraTransform.position;
}
}
if (!currentCameraWaypointInfo.rotateCameraToNextWaypoint && !currentCameraWaypointInfo.usePointToLook) {
currentCameraTransform.rotation = currentCameraWaypointInfo.waypointTransform.rotation;
} else {
if (targetDirection != Vector3.zero) {
currentCameraTransform.rotation = Quaternion.LookRotation (targetDirection);
}
}
//yield return new WaitForSeconds (currentCameraWaypointInfo.timeOnFixedPosition);
delay = new WaitForSeconds (currentCameraWaypointInfo.timeOnFixedPosition);
yield return delay;
}
if (currentCameraWaypointInfo.useEventOnPointReached) {
currentCameraWaypointInfo.eventOnPointReached.Invoke ();
}
//when the platform reaches the next waypoint
currentWaypointIndex++;
yield return null;
}
yield return null;
if (useEventOnEnd) {
eventOnEnd.Invoke ();
}
if (resetCameraPositionOnEnd) {
resetCameraPosition ();
}
waypointInProcess = false;
}
IEnumerator moveAlongBezierCurve ()
{
waypointInProcess = true;
if (!snapCameraToFirstSplinePoint) {
spline.setInitialSplinePoint (currentCameraTransform.position);
}
float progress = 0;
float progressTarget = 1;
bool targetReached = false;
while (!targetReached) {
if (previousWaypointIndex != currentWaypointIndex) {
if (previousWaypointIndex != -1) {
if (currentCameraWaypointInfo.useEventOnPointReached) {
currentCameraWaypointInfo.eventOnPointReached.Invoke ();
}
}
previousWaypointIndex = currentWaypointIndex;
currentCameraWaypointInfo = waypointList [currentWaypointIndex];
currentWaypoint = currentCameraWaypointInfo.waypointTransform;
//wait the amount of time configured
if (currentCameraWaypointInfo.useCustomWaitTimeBetweenPoint) {
currentWaitTime = currentCameraWaypointInfo.waitTimeBetweenPoints;
} else {
currentWaitTime = waitTimeBetweenPoints;
}
targetPosition = currentWaypoint.position;
targetRotation = currentWaypoint.rotation;
WaitForSeconds delay = new WaitForSeconds (currentWaitTime);
yield return delay;
if (currentCameraWaypointInfo.useCustomMovementSpeed) {
currentMovementSpeed = currentCameraWaypointInfo.movementSpeed;
} else {
currentMovementSpeed = movementSpeed;
}
if (currentCameraWaypointInfo.useCustomRotationSpeed) {
currentRotationSpeed = currentCameraWaypointInfo.rotationSpeed;
} else {
currentRotationSpeed = rotationSpeed;
}
}
currentWaypointIndex = spline.getPointIndex (progress);
if (useExternalProgress) {
if (externalProgress != null) {
progress = externalProgress ();
} else {
Debug.LogError ("useExternalProgress is set but no externalProgress func is assigned");
}
} else {
progress += Time.deltaTime / (bezierDuration * currentMovementSpeed);
}
Vector3 position = spline.GetPoint (progress);
currentCameraTransform.position = position;
if (currentCameraWaypointInfo.rotateCameraToNextWaypoint) {
targetDirection = targetPosition - currentCameraTransform.position;
}
if (currentCameraWaypointInfo.usePointToLook) {
if (customTransformToLookActive) {
targetDirection = customTransformToLook.position - currentCameraTransform.position;
} else {
targetDirection = currentCameraWaypointInfo.pointToLook.position - currentCameraTransform.position;
}
}
if (targetDirection != Vector3.zero) {
targetRotation = Quaternion.LookRotation (targetDirection);
currentCameraTransform.rotation = Quaternion.Lerp (currentCameraTransform.rotation, targetRotation, Time.deltaTime * currentRotationSpeed);
}
if (progress > progressTarget) {
targetReached = true;
}
yield return null;
}
yield return null;
if (useEventOnEnd) {
eventOnEnd.Invoke ();
}
if (resetCameraPositionOnEnd) {
resetCameraPosition ();
}
waypointInProcess = false;
}
public void stopWaypointsIfInProcess ()
{
if (waypointInProcess) {
stopMoveThroughWayPointsCoroutine ();
}
}
public void stopWaypointsAndResetCameraPosition ()
{
if (waypointInProcess) {
stopMoveThroughWayPointsCoroutine ();
if (resetCameraPositionOnEnd) {
resetCameraPosition ();
}
}
}
public void resetCameraPosition ()
{
if (ignoreWaypointOnCurrentViewResult ()) {
return;
}
if (resetCameraPositionCoroutine != null) {
StopCoroutine (resetCameraPositionCoroutine);
}
resetCameraPositionCoroutine = StartCoroutine (resetCameraCoroutine ());
}
IEnumerator resetCameraCoroutine ()
{
setCameraDirection ();
if (setThisTransformAsCameraParent) {
currentCameraTransform.SetParent (previousCameraParent);
}
Vector3 targetPosition = previousCameraPosition;
Quaternion targetRotation = previousCameraRotation;
Vector3 worldTargetPosition = previousCameraParent.position;
float dist = GKC_Utils.distance (currentCameraTransform.position, worldTargetPosition);
float duration = dist / resetCameraPositionSpeed;
float t = 0;
float movementTimer = 0;
bool targetReached = false;
float angleDifference = 0;
float currentDistance = 0;
while (!targetReached) {
t += Time.deltaTime / duration;
currentCameraTransform.localPosition = Vector3.Lerp (currentCameraTransform.localPosition, targetPosition, t);
currentCameraTransform.localRotation = Quaternion.Lerp (currentCameraTransform.localRotation, targetRotation, t);
angleDifference = Quaternion.Angle (currentCameraTransform.localRotation, targetRotation);
currentDistance = GKC_Utils.distance (currentCameraTransform.localPosition, targetPosition);
movementTimer += Time.deltaTime;
if (currentDistance < 0.001f && angleDifference < 0.01f) {
targetReached = true;
}
if (movementTimer > (duration + 1)) {
targetReached = true;
}
yield return null;
}
if (pausePlayerCameraEnabled) {
currentPlayerCamera.pauseOrPlayCamera (true);
}
}
public void setCameraDirection ()
{
playerCameraGameObject.transform.rotation = transform.rotation;
Quaternion newCameraRotation = pivotDirection.localRotation;
currentPlayerCamera.getPivotCameraTransform ().localRotation = newCameraRotation;
float newLookAngleValue = newCameraRotation.eulerAngles.x;
if (newLookAngleValue > 180) {
newLookAngleValue -= 360;
}
currentPlayerCamera.setLookAngleValue (new Vector2 (0, newLookAngleValue));
}
public void setCameraWaypointEnabledState (bool state)
{
cameraWaypointEnabled = state;
}
public void setCustomGameObjectToLook (GameObject newGameObject)
{
if (newGameObject != null) {
setCustomTransformToLook (newGameObject.transform);
} else {
setCustomTransformToLook (null);
}
}
public void setCustomTransformToLook (Transform newTransform)
{
customTransformToLook = newTransform;
customTransformToLookActive = customTransformToLook != null;
}
public void checkEventToStopCutscene ()
{
if (waypointInProcess) {
if (useEventToStopCutScene) {
eventToStopCutscene.Invoke ();
}
}
}
//EDITOR FUNCTIONS
//add a new waypoint
public void addNewWayPoint ()
{
Vector3 newPosition = transform.position;
if (waypointList.Count > 0) {
newPosition = waypointList [waypointList.Count - 1].waypointTransform.position + waypointList [waypointList.Count - 1].waypointTransform.forward;
}
GameObject newWayPoint = new GameObject ();
newWayPoint.transform.SetParent (transform);
newWayPoint.transform.position = newPosition;
newWayPoint.name = (waypointList.Count + 1).ToString ();
cameraWaypointInfo newCameraWaypointInfo = new cameraWaypointInfo ();
newCameraWaypointInfo.Name = newWayPoint.name;
newCameraWaypointInfo.waypointTransform = newWayPoint.transform;
newCameraWaypointInfo.rotateCameraToNextWaypoint = true;
waypointList.Add (newCameraWaypointInfo);
updateComponent ();
}
public void addNewWayPoint (int insertAtIndex)
{
GameObject newWayPoint = new GameObject ();
newWayPoint.transform.SetParent (transform);
newWayPoint.name = (waypointList.Count + 1).ToString ();
cameraWaypointInfo newCameraWaypointInfo = new cameraWaypointInfo ();
newCameraWaypointInfo.Name = newWayPoint.name;
newCameraWaypointInfo.waypointTransform = newWayPoint.transform;
newCameraWaypointInfo.rotateCameraToNextWaypoint = true;
if (waypointList.Count > 0) {
Vector3 lastPosition = waypointList [waypointList.Count - 1].waypointTransform.position + waypointList [waypointList.Count - 1].waypointTransform.forward;
newWayPoint.transform.localPosition = lastPosition + waypointList [waypointList.Count - 1].waypointTransform.forward * 2;
} else {
newWayPoint.transform.localPosition = Vector3.zero;
}
if (insertAtIndex > -1) {
if (waypointList.Count > 0) {
newWayPoint.transform.localPosition = waypointList [insertAtIndex].waypointTransform.localPosition + waypointList [insertAtIndex].waypointTransform.forward * 2;
}
waypointList.Insert (insertAtIndex + 1, newCameraWaypointInfo);
newWayPoint.transform.SetSiblingIndex (insertAtIndex + 1);
renameAllWaypoints ();
} else {
waypointList.Add (newCameraWaypointInfo);
}
updateComponent ();
}
public void renameAllWaypoints ()
{
for (int i = 0; i < waypointList.Count; i++) {
if (waypointList [i].waypointTransform != null) {
waypointList [i].waypointTransform.name = (i + 1).ToString ("000");
waypointList [i].Name = (i + 1).ToString ("000");
}
}
updateComponent ();
}
public void removeWaypoint (int index)
{
if (waypointList [index].waypointTransform != null) {
DestroyImmediate (waypointList [index].waypointTransform.gameObject);
}
waypointList.RemoveAt (index);
updateComponent ();
}
public void removeAllWaypoints ()
{
for (int i = 0; i < waypointList.Count; i++) {
if (waypointList [i].waypointTransform != null) {
DestroyImmediate (waypointList [i].waypointTransform.gameObject);
}
}
waypointList.Clear ();
updateComponent ();
}
public void updateComponent ()
{
GKC_Utils.updateComponent (this);
GKC_Utils.updateDirtyScene ("Update Camera Waypoin System", gameObject);
}
void OnDrawGizmos ()
{
if (!showGizmo) {
return;
}
if (GKC_Utils.isCurrentSelectionActiveGameObject (gameObject)) {
DrawGizmos ();
}
}
void OnDrawGizmosSelected ()
{
DrawGizmos ();
}
void DrawGizmos ()
{
if (showGizmo) {
if (waypointList.Count > 0) {
if (waypointList [0].waypointTransform != null) {
Gizmos.color = Color.white;
Gizmos.DrawLine (waypointList [0].waypointTransform.position, transform.position);
}
}
for (i = 0; i < waypointList.Count; i++) {
if (waypointList [i].waypointTransform != null) {
Gizmos.color = Color.yellow;
Gizmos.DrawSphere (waypointList [i].waypointTransform.position, gizmoRadius);
if (i + 1 < waypointList.Count) {
Gizmos.color = Color.white;
Gizmos.DrawLine (waypointList [i].waypointTransform.position, waypointList [i + 1].waypointTransform.position);
}
if (currentWaypoint != null) {
Gizmos.color = Color.red;
Gizmos.DrawSphere (currentWaypoint.position, gizmoRadius);
}
if (waypointList [i].usePointToLook && waypointList [i].pointToLook != null) {
Gizmos.color = Color.green;
Gizmos.DrawLine (waypointList [i].waypointTransform.position, waypointList [i].pointToLook.position);
Gizmos.color = Color.blue;
Gizmos.DrawSphere (waypointList [i].pointToLook.position, gizmoRadius);
}
}
}
}
}
[System.Serializable]
public class cameraWaypointInfo
{
public string Name;
public Transform waypointTransform;
public bool rotateCameraToNextWaypoint;
public bool usePointToLook;
public Transform pointToLook;
public bool smoothTransitionToNextPoint = true;
public bool useCustomMovementSpeed;
public float movementSpeed;
public bool useCustomRotationSpeed;
public float rotationSpeed;
public bool checkRotationIsReached;
public float timeOnFixedPosition;
public bool useCustomWaitTimeBetweenPoint;
public float waitTimeBetweenPoints;
public bool useEventOnPointReached;
public UnityEvent eventOnPointReached;
}
}

View File

@@ -0,0 +1,19 @@
fileFormatVersion: 2
guid: 6b41a39a12e974a4cbed96893647e2f1
timeCreated: 1533411804
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/Camera/Cutscene/cameraWaypointSystem.cs
uploadId: 814740

View File

@@ -0,0 +1,469 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
public class pauseOrResumePlayerControllerAndCameraSystem : MonoBehaviour
{
[Header ("Main Settings")]
[Space]
public bool searchPlayerOnSceneIfNotAssigned = true;
public bool assignPlayerManually;
public GameObject currentPlayer;
public GameObject playerCameraGameObject;
public bool unlockCursor;
public bool enableGamepadCursor;
public bool resumePlayerAfterDelay;
public float delayToResumePlayer;
public bool activatePlayerMeshModel = true;
public bool pauseEscapeMenu;
[Space]
[Header ("Time Scale Settings")]
[Space]
public bool setCustomTimeScale;
public float customTimeScale;
public bool pauseAIWhenOpenMenu;
public int pauseCharacterPriority = 1;
public bool ignoreChangeFixedDeltaTime;
[Space]
[Header ("Camera Settings")]
[Space]
public bool cameraIsMoved;
public float resetCameraPositionSpeed;
public bool setCameraDirectionAtEnd;
public Transform cameraDirection;
public Transform pivotDirection;
[Space]
public bool setNewCameraParent;
public Transform newCameraParent;
[Space]
[Header ("HUD Settings")]
[Space]
public bool disableSecondaryPlayerHUD;
public bool disableAllPlayerHUD = true;
public bool disableTouchControls = true;
public bool disableDynamiUIElements;
[Space]
[Header ("Debug")]
[Space]
public bool playerComponentsPaused;
[Space]
[Header ("Event Settings")]
[Space]
public bool useEventOnPause;
public UnityEvent eventOnPause;
public eventParameters.eventToCallWithGameObject eventToSendCamera;
public bool useEventOnResume;
public UnityEvent eventOnResume;
playerController playerControllerManager;
playerCamera playerCameraManager;
headBob headBobManager;
playerStatesManager statesManager;
menuPause pauseManager;
playerComponentsManager mainPlayerComponentsManager;
playerInputManager playerInput;
headTrack mainHeadTrack;
Transform previousCameraParent;
Vector3 previousCameraPosition;
Transform mainCamera;
Coroutine resetCameraPositionCoroutine;
bool playerIsDriving;
bool usingDevicePreviously;
bool headScaleChanged;
Coroutine resumePlayerCoroutine;
bool playerAssignedProperly;
void Start ()
{
if (assignPlayerManually) {
getCurrentPlayer (currentPlayer);
}
}
public void getCurrentPlayer (GameObject player)
{
if (playerComponentsPaused) {
return;
}
currentPlayer = player;
if (currentPlayer == null) {
return;
}
mainPlayerComponentsManager = currentPlayer.GetComponent<playerComponentsManager> ();
if (mainPlayerComponentsManager != null) {
playerControllerManager = mainPlayerComponentsManager.getPlayerController ();
playerCameraManager = mainPlayerComponentsManager.getPlayerCamera ();
playerCameraGameObject = playerCameraManager.gameObject;
mainCamera = playerCameraManager.getMainCamera ().transform;
headBobManager = mainPlayerComponentsManager.getHeadBob ();
statesManager = mainPlayerComponentsManager.getPlayerStatesManager ();
pauseManager = mainPlayerComponentsManager.getPauseManager ();
playerInput = mainPlayerComponentsManager.getPlayerInputManager ();
mainHeadTrack = mainPlayerComponentsManager.getHeadTrack ();
playerAssignedProperly = true;
}
}
public void pauseOrPlayPlayerComponents (bool state)
{
if (currentPlayer == null || !playerAssignedProperly) {
findPlayerOnScene ();
if (currentPlayer == null) {
print ("WARNING: no player controller has been assigned to the mission." +
" Make sure to use a trigger to activate the mission or assign the player manually");
return;
}
}
if (playerComponentsPaused == state) {
if (playerComponentsPaused) {
print ("Trying to pause the player when it is already paused, avoiding function call to keep the player in same state");
} else {
print ("Trying to resume the player when it is already resumed, avoiding function call to keep the player in same state");
}
return;
}
playerComponentsPaused = state;
playerIsDriving = playerControllerManager.isPlayerDriving ();
playerInput.setAvoidInputActiveState (state);
if (playerComponentsPaused) {
usingDevicePreviously = playerControllerManager.isUsingDevice ();
}
if (!playerIsDriving) {
if (!usingDevicePreviously) {
playerControllerManager.smoothChangeScriptState (!state);
mainHeadTrack.setSmoothHeadTrackDisableState (state);
playerControllerManager.setHeadTrackCanBeUsedState (!state);
playerControllerManager.setUsingDeviceState (state);
if (playerComponentsPaused) {
headBobManager.stopAllHeadbobMovements ();
}
headBobManager.playOrPauseHeadBob (!state);
statesManager.checkPlayerStates (false, true, false, true, false, false, true, true);
playerCameraManager.pauseOrPlayCamera (!state);
}
}
if (playerIsDriving) {
if (playerComponentsPaused) {
headScaleChanged = playerControllerManager.isHeadScaleChanged ();
if (headScaleChanged) {
playerControllerManager.changeHeadScale (false);
}
} else {
if (headScaleChanged) {
playerControllerManager.changeHeadScale (true);
}
}
} else {
checkCharacterMesh (state);
}
if (unlockCursor) {
pauseManager.showOrHideCursor (playerComponentsPaused);
pauseManager.usingDeviceState (playerComponentsPaused);
pauseManager.usingSubMenuState (playerComponentsPaused);
if (enableGamepadCursor) {
pauseManager.showOrHideMouseCursorController (playerComponentsPaused);
}
}
if (playerIsDriving) {
if (disableAllPlayerHUD) {
pauseManager.enableOrDisableVehicleHUD (!playerComponentsPaused);
}
} else {
if (!usingDevicePreviously) {
if (disableAllPlayerHUD) {
pauseManager.enableOrDisablePlayerHUD (!playerComponentsPaused);
} else {
if (disableSecondaryPlayerHUD) {
pauseManager.enableOrDisableSecondaryPlayerHUD (!playerComponentsPaused);
}
}
}
}
if (disableDynamiUIElements) {
pauseManager.enableOrDisableDynamicElementsOnScreen (!playerComponentsPaused);
}
if (disableTouchControls) {
if (!usingDevicePreviously) {
if (pauseManager.isUsingTouchControls ()) {
pauseManager.enableOrDisableTouchControlsExternally (!playerComponentsPaused);
}
}
}
if (!usingDevicePreviously) {
pauseManager.enableOrDisableDynamicElementsOnScreen (!playerComponentsPaused);
}
playerInput.setInputPausedForExternalComponentsState (playerComponentsPaused);
if (playerComponentsPaused) {
if (useEventOnPause) {
eventToSendCamera.Invoke (mainCamera.gameObject);
eventOnPause.Invoke ();
}
if (cameraIsMoved) {
previousCameraParent = mainCamera.parent;
previousCameraPosition = mainCamera.localPosition;
if (setNewCameraParent) {
mainCamera.SetParent (newCameraParent);
} else {
mainCamera.SetParent (null);
}
}
} else {
if (useEventOnResume) {
eventOnResume.Invoke ();
}
}
stopResumePlayerAfterTimeDelay ();
if (state) {
if (resumePlayerAfterDelay) {
resumePlayerAfterTimeDelay ();
}
}
if (pauseEscapeMenu) {
pauseManager.setPauseGameInputPausedState (state);
}
if (setCustomTimeScale) {
if (state) {
setTimeScale (customTimeScale);
} else {
setTimeScale (1);
}
}
if (pauseAIWhenOpenMenu) {
GKC_Utils.pauseOrResumeAIOnScene (state, pauseCharacterPriority);
}
}
public void setTimeScale (float newValue)
{
Time.timeScale = newValue;
if (!ignoreChangeFixedDeltaTime) {
if (newValue != 0) {
Time.fixedDeltaTime = newValue * 0.02f;
}
}
}
public void checkCharacterMesh (bool state)
{
if (activatePlayerMeshModel) {
bool firstCameraEnabled = playerCameraManager.isFirstPersonActive ();
if (firstCameraEnabled) {
playerControllerManager.setCharacterMeshGameObjectState (state);
}
if (usingDevicePreviously && !playerControllerManager.isFullBodyAwarenessActive ()) {
playerControllerManager.getGravityCenter ().gameObject.SetActive (state);
}
}
}
public void resetCameraPositionIfCharacterPaused ()
{
if (playerComponentsPaused) {
resetCameraPosition ();
}
}
public void resetCameraPositionIfCharacterPausedWithoutTransition ()
{
if (!playerComponentsPaused) {
return;
}
if (!cameraIsMoved) {
return;
}
setCameraDirection ();
mainCamera.SetParent (previousCameraParent);
mainCamera.localPosition = previousCameraPosition;
mainCamera.localRotation = Quaternion.identity;
pauseOrPlayPlayerComponents (false);
}
public void resetCameraPosition ()
{
if (!cameraIsMoved) {
return;
}
if (resetCameraPositionCoroutine != null) {
StopCoroutine (resetCameraPositionCoroutine);
}
resetCameraPositionCoroutine = StartCoroutine (resetCameraCoroutine ());
}
IEnumerator resetCameraCoroutine ()
{
setCameraDirection ();
mainCamera.SetParent (previousCameraParent);
Vector3 targetPosition = previousCameraPosition;
Quaternion targeRotation = Quaternion.identity;
Vector3 worldTargetPosition = previousCameraParent.position;
float dist = GKC_Utils.distance (mainCamera.position, worldTargetPosition);
float duration = dist / resetCameraPositionSpeed;
float t = 0;
float movementTimer = 0;
bool targetReached = false;
float angleDifference = 0;
float currentDistance = 0;
while (!targetReached) {
t += Time.deltaTime / duration;
mainCamera.localPosition = Vector3.Lerp (mainCamera.localPosition, targetPosition, t);
mainCamera.localRotation = Quaternion.Lerp (mainCamera.localRotation, targeRotation, t);
angleDifference = Quaternion.Angle (mainCamera.localRotation, targeRotation);
currentDistance = GKC_Utils.distance (mainCamera.localPosition, targetPosition);
movementTimer += Time.deltaTime;
if ((currentDistance < 0.001f && angleDifference < 0.1f) || movementTimer > (duration + 1)) {
targetReached = true;
}
yield return null;
}
pauseOrPlayPlayerComponents (false);
}
public void setCameraDirection ()
{
if (setCameraDirectionAtEnd) {
playerCameraGameObject.transform.rotation = cameraDirection.rotation;
Quaternion newCameraRotation = pivotDirection.localRotation;
playerCameraManager.getPivotCameraTransform ().localRotation = newCameraRotation;
float newLookAngleValue = newCameraRotation.eulerAngles.x;
if (newLookAngleValue > 180) {
newLookAngleValue -= 360;
}
playerCameraManager.setLookAngleValue (new Vector2 (0, newLookAngleValue));
}
}
public void resumePlayerAfterTimeDelay ()
{
stopResumePlayerAfterTimeDelay ();
resumePlayerCoroutine = StartCoroutine (resumePlayerAfterTimeDelayCoroutine ());
}
public void stopResumePlayerAfterTimeDelay ()
{
if (resumePlayerCoroutine != null) {
StopCoroutine (resumePlayerCoroutine);
}
}
IEnumerator resumePlayerAfterTimeDelayCoroutine ()
{
yield return new WaitForSeconds (delayToResumePlayer);
pauseOrPlayPlayerComponents (false);
}
public void findPlayerOnScene ()
{
if (searchPlayerOnSceneIfNotAssigned) {
getCurrentPlayer (GKC_Utils.findMainPlayerOnScene ());
}
}
}

View File

@@ -0,0 +1,19 @@
fileFormatVersion: 2
guid: 9e963d1ecb2c6aa479602abcd95ec639
timeCreated: 1533410237
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/Camera/Cutscene/pauseOrResumePlayerControllerAndCameraSystem.cs
uploadId: 814740

View File

@@ -0,0 +1,70 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class simpleShowHideMouseCursor : MonoBehaviour
{
[Header ("Main Settings")]
[Space]
public bool showOrHideMouseCursorEnabled = true;
public bool enableGamepadCursor;
[Space]
public bool searchMainPlayerOnSceneEnabled;
[Space]
[Header ("Debug")]
[Space]
public bool showMouseCursorActive;
[Space]
[Header ("Components")]
[Space]
public menuPause pauseManager;
public void showMouseCursor ()
{
showOrHideMouseCursor (true);
}
public void hideMouseCursor ()
{
showOrHideMouseCursor (false);
}
public void showOrHideMouseCursor (bool state)
{
if (showOrHideMouseCursorEnabled) {
if (showMouseCursorActive == state) {
return;
}
if (pauseManager == null) {
if (searchMainPlayerOnSceneEnabled) {
pauseManager = GKC_Utils.findMainPlayergetPauseManagerOnScene ();
if (pauseManager == null) {
return;
}
} else {
return;
}
}
showMouseCursorActive = state;
pauseManager.showOrHideCursor (showMouseCursorActive);
pauseManager.usingDeviceState (showMouseCursorActive);
pauseManager.usingSubMenuState (showMouseCursorActive);
if (enableGamepadCursor) {
pauseManager.showOrHideMouseCursorController (showMouseCursorActive);
}
}
}
}

View File

@@ -0,0 +1,19 @@
fileFormatVersion: 2
guid: 071ad3aa3c1a4744db2c63a5817b2e67
timeCreated: 1692077191
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/Camera/Cutscene/simpleShowHideMouseCursor.cs
uploadId: 814740