save position and cam rotation

This commit is contained in:
2026-04-15 21:33:36 -05:00
parent 46ec37309d
commit db47bc3768
12 changed files with 83 additions and 78 deletions
+1
View File
@@ -3142,6 +3142,7 @@ MonoBehaviour:
walkSpeed: 2 walkSpeed: 2
sprintMultiplier: 1.5 sprintMultiplier: 1.5
gravity: 1 gravity: 1
cameraController: {fileID: 5478143440182735446}
--- !u!114 &5478143440182735446 --- !u!114 &5478143440182735446
MonoBehaviour: MonoBehaviour:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
+13 -25
View File
@@ -1426,17 +1426,6 @@ MonoBehaviour:
m_Name: m_Name:
m_EditorClassIdentifier: Assembly-CSharp::SunRotation m_EditorClassIdentifier: Assembly-CSharp::SunRotation
offset: 270 offset: 270
--- !u!114 &415981849 stripped
MonoBehaviour:
m_CorrespondingSourceObject: {fileID: 6038027350876930962, guid: 0fd9b22e9158e474a96c42de5ee0d85f, type: 3}
m_PrefabInstance: {fileID: 7959480261809233915}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 70102eddcaad3044d9ac0ec62519caad, type: 3}
m_Name:
m_EditorClassIdentifier: Assembly-CSharp::GrappleGun
--- !u!1 &419915067 --- !u!1 &419915067
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@@ -3643,6 +3632,17 @@ RectTransform:
m_AnchoredPosition: {x: 0, y: 0} m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 0, y: 0} m_SizeDelta: {x: 0, y: 0}
m_Pivot: {x: 0, y: 0} m_Pivot: {x: 0, y: 0}
--- !u!114 &1733921841 stripped
MonoBehaviour:
m_CorrespondingSourceObject: {fileID: 5478143440182735446, guid: 0fd9b22e9158e474a96c42de5ee0d85f, type: 3}
m_PrefabInstance: {fileID: 7959480261809233915}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 34a2af7866b6ecc4ab5f2b6222f7dbe2, type: 3}
m_Name:
m_EditorClassIdentifier: Assembly-CSharp::CameraController
--- !u!1 &1735546792 --- !u!1 &1735546792
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@@ -4483,17 +4483,9 @@ PrefabInstance:
m_TransformParent: {fileID: 0} m_TransformParent: {fileID: 0}
m_Modifications: m_Modifications:
- target: {fileID: 1480974628599415149, guid: 0fd9b22e9158e474a96c42de5ee0d85f, type: 3} - target: {fileID: 1480974628599415149, guid: 0fd9b22e9158e474a96c42de5ee0d85f, type: 3}
propertyPath: tools.Array.size propertyPath: cameraController
value: 5
objectReference: {fileID: 0}
- target: {fileID: 1480974628599415149, guid: 0fd9b22e9158e474a96c42de5ee0d85f, type: 3}
propertyPath: 'tools.Array.data[4]'
value: value:
objectReference: {fileID: 415981849} objectReference: {fileID: 1733921841}
- target: {fileID: 5056434560497563343, guid: 0fd9b22e9158e474a96c42de5ee0d85f, type: 3}
propertyPath: m_LocalPosition.y
value: -0.78
objectReference: {fileID: 0}
- target: {fileID: 5526037850913171920, guid: 0fd9b22e9158e474a96c42de5ee0d85f, type: 3} - target: {fileID: 5526037850913171920, guid: 0fd9b22e9158e474a96c42de5ee0d85f, type: 3}
propertyPath: m_LocalPosition.x propertyPath: m_LocalPosition.x
value: -0.60945 value: -0.60945
@@ -4534,10 +4526,6 @@ PrefabInstance:
propertyPath: m_LocalEulerAnglesHint.z propertyPath: m_LocalEulerAnglesHint.z
value: 0 value: 0
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 5907675754202653673, guid: 0fd9b22e9158e474a96c42de5ee0d85f, type: 3}
propertyPath: ball
value:
objectReference: {fileID: 7664016258760507437, guid: 0b0365667a94c474bb3cc42312aac1db, type: 3}
- target: {fileID: 9054701043111961555, guid: 0fd9b22e9158e474a96c42de5ee0d85f, type: 3} - target: {fileID: 9054701043111961555, guid: 0fd9b22e9158e474a96c42de5ee0d85f, type: 3}
propertyPath: m_Name propertyPath: m_Name
value: Doug value: Doug
@@ -5,7 +5,7 @@
public class CameraController : MonoBehaviour public class CameraController : MonoBehaviour
{ {
private float camTargetRotation = 0; public float camTargetRotation { get; private set; } = 0;
private bool isCamRotating = false; private bool isCamRotating = false;
public Transform playerCamHome; public Transform playerCamHome;
@@ -28,6 +28,20 @@ public void RotateCam()
} }
} }
/// <summary>
/// Set cam rotation immediately
/// </summary>
public void SnapToRotation(float rotation)
{
playerCamHome.RotateAround(
transform.position,
Vector3.up,
rotation
);
camTargetRotation = rotation;
}
/// <summary> /// <summary>
/// Move cam to desired rotation (every frame) /// Move cam to desired rotation (every frame)
/// </summary> /// </summary>
+25 -37
View File
@@ -15,11 +15,12 @@ public class GameManager : MonoBehaviour
public Inventory Inventory { get; private set; } public Inventory Inventory { get; private set; }
public Storybools Storybools { get; private set; } public Storybools Storybools { get; private set; }
public PauseMenu PauseMenu { get; private set; } public PauseMenu PauseMenu { get; private set; }
public PlayerController PlayerController { get; private set; }
public Image BlackScreen { get; private set; }
// Are we currently in a scene transition? // Are we currently in a scene transition?
private bool isTransitioningScenes = false; private bool isTransitioningScenes = false;
private Image blackScreen;
private PlayerController playerController;
private void Awake() private void Awake()
{ {
@@ -38,7 +39,10 @@ private void Awake()
DontDestroyOnLoad(gameObject); DontDestroyOnLoad(gameObject);
ReloadReferences(); ReloadReferences();
}
private void Start()
{
SaveSystem.Load(); SaveSystem.Load();
SaveSystem.Save(); // save off any corruption fixes SaveSystem.Save(); // save off any corruption fixes
} }
@@ -48,8 +52,8 @@ private void Awake()
/// </summary> /// </summary>
private void ReloadReferences() private void ReloadReferences()
{ {
Instance.blackScreen = GameObject.FindWithTag("BlackScreen").GetComponent<Image>(); Instance.BlackScreen = GameObject.FindWithTag("BlackScreen").GetComponent<Image>();
Instance.playerController = GameObject.FindWithTag("Player").GetComponent<PlayerController>(); Instance.PlayerController = GameObject.FindWithTag("Player").GetComponent<PlayerController>();
Instance.DialogueManager = GetComponent<DialogueManager>(); Instance.DialogueManager = GetComponent<DialogueManager>();
Instance.DialogueManager.ReloadReferences(); Instance.DialogueManager.ReloadReferences();
@@ -77,7 +81,7 @@ public void GoToMapPoint(MapPoint mapPoint)
private IEnumerator GoToMapPointCoroutine(MapPoint mapPoint) private IEnumerator GoToMapPointCoroutine(MapPoint mapPoint)
{ {
Instance.isTransitioningScenes = true; Instance.isTransitioningScenes = true;
Instance.playerController.SetCharacterControl(false); Instance.PlayerController.SetCharacterControl(false);
// Fade to black // Fade to black
float fadeDuration = 0.2f; // how long to fade to/from black float fadeDuration = 0.2f; // how long to fade to/from black
@@ -88,7 +92,7 @@ private IEnumerator GoToMapPointCoroutine(MapPoint mapPoint)
while (fadeTime < fadeDuration) while (fadeTime < fadeDuration)
{ {
blackScreenColor.a = Mathf.Lerp(0, 1, fadeTime / fadeDuration); blackScreenColor.a = Mathf.Lerp(0, 1, fadeTime / fadeDuration);
blackScreen.color = blackScreenColor; Instance.BlackScreen.color = blackScreenColor;
fadeTime += Time.deltaTime; fadeTime += Time.deltaTime;
yield return null; yield return null;
} }
@@ -105,18 +109,18 @@ private IEnumerator GoToMapPointCoroutine(MapPoint mapPoint)
ReloadReferences(); ReloadReferences();
// Make sure screen is black in new scene // Make sure screen is black in new scene
blackScreen.color = blackScreenColor; Instance.BlackScreen.color = blackScreenColor;
if (Instance.playerController != null && GameSceneManager.Instance != null) if (Instance.PlayerController != null && GameSceneManager.Instance != null)
{ {
Instance.playerController.CharacterControllerMove(mapPoint.SpawnPosition - playerController.transform.position); Instance.PlayerController.CharacterControllerMove(mapPoint.SpawnPosition - PlayerController.transform.position);
} }
// Fade back in // Fade back in
while (fadeTime < fadeDuration) while (fadeTime < fadeDuration)
{ {
blackScreenColor.a = Mathf.Lerp(1, 0, fadeTime / fadeDuration); blackScreenColor.a = Mathf.Lerp(1, 0, fadeTime / fadeDuration);
Instance.blackScreen.color = blackScreenColor; Instance.BlackScreen.color = blackScreenColor;
fadeTime += Time.deltaTime; fadeTime += Time.deltaTime;
yield return null; yield return null;
@@ -132,7 +136,7 @@ private IEnumerator GoToMapPointCoroutine(MapPoint mapPoint)
fadeTime = 0; fadeTime = 0;
Instance.isTransitioningScenes = false; Instance.isTransitioningScenes = false;
Instance.playerController.SetCharacterControl(true); Instance.PlayerController.SetCharacterControl(true);
} }
#endregion #endregion
@@ -151,7 +155,7 @@ public void EnterSceneDoor(string scene, int door)
private IEnumerator EnterSceneDoorCoroutine(string scene, int doorId) private IEnumerator EnterSceneDoorCoroutine(string scene, int doorId)
{ {
Instance.isTransitioningScenes = true; Instance.isTransitioningScenes = true;
Instance.playerController.SetCharacterControl(false); Instance.PlayerController.SetCharacterControl(false);
// Fade to black // Fade to black
float fadeDuration = 0.2f; // how long to fade to/from black float fadeDuration = 0.2f; // how long to fade to/from black
@@ -162,7 +166,7 @@ private IEnumerator EnterSceneDoorCoroutine(string scene, int doorId)
while (fadeTime < fadeDuration) while (fadeTime < fadeDuration)
{ {
blackScreenColor.a = Mathf.Lerp(0, 1, fadeTime / fadeDuration); blackScreenColor.a = Mathf.Lerp(0, 1, fadeTime / fadeDuration);
blackScreen.color = blackScreenColor; Instance.BlackScreen.color = blackScreenColor;
fadeTime += Time.deltaTime; fadeTime += Time.deltaTime;
yield return null; yield return null;
} }
@@ -179,16 +183,16 @@ private IEnumerator EnterSceneDoorCoroutine(string scene, int doorId)
ReloadReferences(); ReloadReferences();
// Make sure screen is black in new scene // Make sure screen is black in new scene
blackScreen.color = blackScreenColor; Instance.BlackScreen.color = blackScreenColor;
SceneDoor door = GameSceneManager.Instance.GetDoorWithId(doorId); SceneDoor door = GameSceneManager.Instance.GetDoorWithId(doorId);
if (Instance.playerController != null && GameSceneManager.Instance != null) if (Instance.PlayerController != null && GameSceneManager.Instance != null)
{ {
if (door != null) if (door != null)
{ {
Instance.playerController.CharacterControllerMove(door.gameObject.transform.position - playerController.transform.position); Instance.PlayerController.CharacterControllerMove(door.gameObject.transform.position - PlayerController.transform.position);
Instance.playerController.DougBody.transform.rotation = door.gameObject.transform.rotation; Instance.PlayerController.DougBody.transform.rotation = door.gameObject.transform.rotation;
} }
} }
@@ -196,17 +200,17 @@ private IEnumerator EnterSceneDoorCoroutine(string scene, int doorId)
while (fadeTime < fadeDuration) while (fadeTime < fadeDuration)
{ {
blackScreenColor.a = Mathf.Lerp(1, 0, fadeTime / fadeDuration); blackScreenColor.a = Mathf.Lerp(1, 0, fadeTime / fadeDuration);
Instance.blackScreen.color = blackScreenColor; Instance.BlackScreen.color = blackScreenColor;
fadeTime += Time.deltaTime; fadeTime += Time.deltaTime;
Instance.playerController.WalkInDirection((door.WalkDirection.position - playerController.transform.position).normalized); Instance.PlayerController.WalkInDirection((door.WalkDirection.position - PlayerController.transform.position).normalized);
yield return null; yield return null;
} }
// move character a little more // move character a little more
while (fadeTime < moveDuration) while (fadeTime < moveDuration)
{ {
Instance.playerController.WalkInDirection((door.WalkDirection.position - playerController.transform.position).normalized); Instance.PlayerController.WalkInDirection((door.WalkDirection.position - PlayerController.transform.position).normalized);
fadeTime += Time.deltaTime; fadeTime += Time.deltaTime;
yield return null; yield return null;
} }
@@ -214,7 +218,7 @@ private IEnumerator EnterSceneDoorCoroutine(string scene, int doorId)
fadeTime = 0; fadeTime = 0;
Instance.isTransitioningScenes = false; Instance.isTransitioningScenes = false;
Instance.playerController.SetCharacterControl(true); Instance.PlayerController.SetCharacterControl(true);
} }
#endregion #endregion
@@ -226,22 +230,6 @@ public bool InSceneTransition()
return Instance.isTransitioningScenes; return Instance.isTransitioningScenes;
} }
/// <summary>
/// Get the blackscreen object reference
/// </summary>
public Image GetBlackScreen()
{
return Instance.blackScreen;
}
/// <summary>
/// Get the playerContoller object reference
/// </summary>
public PlayerController GetPlayerController()
{
return Instance.playerController;
}
#region Storybool Save/Load #region Storybool Save/Load
public void SaveStoryBools(ref StoryboolSaveData data) public void SaveStoryBools(ref StoryboolSaveData data)
{ {
@@ -4,7 +4,7 @@ MonoImporter:
externalObjects: {} externalObjects: {}
serializedVersion: 2 serializedVersion: 2
defaultReferences: [] defaultReferences: []
executionOrder: -1 executionOrder: -500
icon: {instanceID: 0} icon: {instanceID: 0}
userData: userData:
assetBundleName: assetBundleName:
@@ -15,8 +15,8 @@ public class PlayerController : MonoBehaviour
public float gravity = 10; public float gravity = 10;
Interactable nearestInteractable; Interactable nearestInteractable;
public CameraController cameraController;
private CharacterController characterController; private CharacterController characterController;
private CameraController cameraController;
private Vector3 moveDir; private Vector3 moveDir;
private bool hasControl = true; // set this to false if we want to stop reading player inputs private bool hasControl = true; // set this to false if we want to stop reading player inputs
private bool canUseTools = true; // set this to false if we want to stop reading player tool use private bool canUseTools = true; // set this to false if we want to stop reading player tool use
@@ -1,4 +1,5 @@
using UnityEngine; using UnityEngine;
using UnityEngine.SceneManagement;
// Handles scene-persistent player data // Handles scene-persistent player data
public class PlayerManager : MonoBehaviour public class PlayerManager : MonoBehaviour
@@ -9,11 +10,21 @@ public class PlayerManager : MonoBehaviour
public void SavePlayerData(ref PlayerSaveData data) public void SavePlayerData(ref PlayerSaveData data)
{ {
data.activeToolIndex = GameManager.Instance.PlayerManager.CurrentToolIndex; data.activeToolIndex = GameManager.Instance.PlayerManager.CurrentToolIndex;
data.camRotation = GameManager.Instance.PlayerController.cameraController.camTargetRotation;
data.dougPosition = GameManager.Instance.PlayerController.transform.position;
data.currentScene = SceneManager.GetActiveScene().name;
} }
public void LoadPlayerData(PlayerSaveData data) public void LoadPlayerData(PlayerSaveData data)
{ {
/*if (data.currentScene != null && data.currentScene != SceneManager.GetActiveScene().name)
{
SceneManager.LoadScene(data.currentScene);
}*/
GameManager.Instance.PlayerManager.CurrentToolIndex = data.activeToolIndex; GameManager.Instance.PlayerManager.CurrentToolIndex = data.activeToolIndex;
GameManager.Instance.PlayerController.cameraController.SnapToRotation(data.camRotation);
GameManager.Instance.PlayerController.transform.position = data.dougPosition;
} }
#endregion #endregion
} }
@@ -22,4 +33,7 @@ public void LoadPlayerData(PlayerSaveData data)
public struct PlayerSaveData public struct PlayerSaveData
{ {
public int activeToolIndex; public int activeToolIndex;
public float camRotation;
public Vector3 dougPosition;
public string currentScene;
} }
+2 -2
View File
@@ -41,7 +41,7 @@ IEnumerator EnterRoomCoroutine(RoomDoor door)
while (fadeTime < fadeDuration) while (fadeTime < fadeDuration)
{ {
blackScreenColor.a = Mathf.Lerp(0, 1, fadeTime / fadeDuration); blackScreenColor.a = Mathf.Lerp(0, 1, fadeTime / fadeDuration);
GameManager.Instance.GetBlackScreen().color = blackScreenColor; GameManager.Instance.BlackScreen.color = blackScreenColor;
fadeTime += Time.deltaTime; fadeTime += Time.deltaTime;
yield return null; yield return null;
} }
@@ -53,7 +53,7 @@ IEnumerator EnterRoomCoroutine(RoomDoor door)
while (fadeTime < fadeDuration) while (fadeTime < fadeDuration)
{ {
blackScreenColor.a = Mathf.Lerp(1, 0, fadeTime / fadeDuration); blackScreenColor.a = Mathf.Lerp(1, 0, fadeTime / fadeDuration);
GameManager.Instance.GetBlackScreen().color = blackScreenColor; GameManager.Instance.BlackScreen.color = blackScreenColor;
playerController.WalkInDirection((door.linkedDoor.WalkDirection.position - playerController.transform.position).normalized); playerController.WalkInDirection((door.linkedDoor.WalkDirection.position - playerController.transform.position).normalized);
fadeTime += Time.deltaTime; fadeTime += Time.deltaTime;
+1 -1
View File
@@ -13,7 +13,7 @@ public override void Use()
newBall.transform.position = transform.position; newBall.transform.position = transform.position;
Vector3 direction = transform.forward * shootForce; Vector3 direction = transform.forward * shootForce;
direction += GameManager.Instance.GetPlayerController().GetVelocity(); direction += GameManager.Instance.PlayerController.GetVelocity();
newBall.GetComponent<Rigidbody>().AddForce(direction, ForceMode.Impulse); newBall.GetComponent<Rigidbody>().AddForce(direction, ForceMode.Impulse);
+6 -6
View File
@@ -21,7 +21,7 @@ private void Start()
IEnumerator GoToTarget(Vector3 target) IEnumerator GoToTarget(Vector3 target)
{ {
GameManager.Instance.GetPlayerController().SetCharacterControl(false); GameManager.Instance.PlayerController.SetCharacterControl(false);
isMoving = true; isMoving = true;
Vector3 startPosition = hook.transform.position; Vector3 startPosition = hook.transform.position;
float elapsedTime = 0f; float elapsedTime = 0f;
@@ -45,7 +45,7 @@ IEnumerator GoToTarget(Vector3 target)
IEnumerator MovePlayerToTarget(Vector3 target) IEnumerator MovePlayerToTarget(Vector3 target)
{ {
Transform player = GameManager.Instance.GetPlayerController().transform; Transform player = GameManager.Instance.PlayerController.transform;
Vector3 startPosition = player.position; Vector3 startPosition = player.position;
float elapsedTime = 0f; float elapsedTime = 0f;
@@ -66,12 +66,12 @@ IEnumerator MovePlayerToTarget(Vector3 target)
isMoving = false; isMoving = false;
stuckInTarget = false; stuckInTarget = false;
GameManager.Instance.GetPlayerController().SetCharacterControl(true); GameManager.Instance.PlayerController.SetCharacterControl(true);
} }
IEnumerator ShootAndMiss() IEnumerator ShootAndMiss()
{ {
GameManager.Instance.GetPlayerController().SetCharacterControl(false); GameManager.Instance.PlayerController.SetCharacterControl(false);
isMoving = true; isMoving = true;
@@ -92,7 +92,7 @@ IEnumerator ShootAndMiss()
isMoving = false; isMoving = false;
stuckInTarget = false; stuckInTarget = false;
GameManager.Instance.GetPlayerController().SetCharacterControl(true); GameManager.Instance.PlayerController.SetCharacterControl(true);
} }
public override void Use() public override void Use()
@@ -105,7 +105,7 @@ public override void Use()
isMoving = false; isMoving = false;
stuckInTarget = false; stuckInTarget = false;
GameManager.Instance.GetPlayerController().SetCharacterControl(true); GameManager.Instance.PlayerController.SetCharacterControl(true);
} }
else else
{ {
+4 -4
View File
@@ -18,7 +18,7 @@ public class ThrowableHand : Tool
private void Update() private void Update()
{ {
if (GameManager.Instance.GetPlayerController() != null) if (GameManager.Instance.PlayerController != null)
{ {
SetGroundPlane(); SetGroundPlane();
DrawTargetProjection(); DrawTargetProjection();
@@ -29,10 +29,10 @@ private void SetGroundPlane()
{ {
if (handGroundPlane == null) if (handGroundPlane == null)
{ {
handGroundPlane = new Plane(Vector3.up, -GameManager.Instance.GetPlayerController().DougBody.transform.position.y); handGroundPlane = new Plane(Vector3.up, -GameManager.Instance.PlayerController.DougBody.transform.position.y);
} }
handGroundPlane.distance = -GameManager.Instance.GetPlayerController().DougBody.transform.position.y; handGroundPlane.distance = -GameManager.Instance.PlayerController.DougBody.transform.position.y;
handGroundPlane.normal = Vector3.up; handGroundPlane.normal = Vector3.up;
} }
@@ -73,7 +73,7 @@ public override void Use()
newBomb.transform.position = transform.position; newBomb.transform.position = transform.position;
Vector3 direction = transform.forward * throwForce * forceModifier; Vector3 direction = transform.forward * throwForce * forceModifier;
direction += GameManager.Instance.GetPlayerController().GetVelocity(); direction += GameManager.Instance.PlayerController.GetVelocity();
direction.y = loft; direction.y = loft;
newBomb.GetComponent<Rigidbody>().AddForce(direction, ForceMode.Impulse); newBomb.GetComponent<Rigidbody>().AddForce(direction, ForceMode.Impulse);