add camera position switching for static view rooms

This commit is contained in:
2026-01-12 21:15:03 -06:00
parent 8eea154717
commit 6baa6956bf
23 changed files with 11034 additions and 26 deletions
+68
View File
@@ -0,0 +1,68 @@
using UnityEngine;
public class CameraController : MonoBehaviour
{
private float moveSpeed = 50.0f;
private float zoomSpeed = 20.0f;
private bool isTracking = false; // don't track when parented
private bool returningHome = false; // cam is on its way home
private float baseCamSize = 5; // this is how "zoomed" the ortho cam is
public Transform playerCamHome; // camera's home base
public GameObject cameraObj;
private Camera cameraComponent;
private Vector3 currentCamPosition;
private float desiredCamSize;
public void SetCurrentPosition(Vector3 currentCamPosition, float desiredCamSize)
{
isTracking = true;
returningHome = false;
cameraObj.transform.parent = null;
this.currentCamPosition = currentCamPosition;
this.desiredCamSize = desiredCamSize;
}
public void ReturnCameraToHome()
{
isTracking = false;
returningHome = true;
currentCamPosition = playerCamHome.position;
desiredCamSize = baseCamSize;
}
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
cameraComponent = cameraObj.GetComponent<Camera>();
ReturnCameraToHome();
}
// Update is called once per frame
void Update()
{
if (isTracking)
{
cameraObj.transform.position = Vector3.MoveTowards(cameraObj.transform.position, currentCamPosition, Time.deltaTime * moveSpeed);
cameraComponent.orthographicSize = Mathf.MoveTowards(cameraComponent.orthographicSize, desiredCamSize, Time.deltaTime * zoomSpeed);
}
if (returningHome)
{
currentCamPosition = playerCamHome.position;
cameraObj.transform.position = Vector3.MoveTowards(cameraObj.transform.position, currentCamPosition, Time.deltaTime * moveSpeed);
cameraComponent.orthographicSize = Mathf.MoveTowards(cameraComponent.orthographicSize, desiredCamSize, Time.deltaTime * zoomSpeed);
if (Vector3.Distance(cameraObj.transform.position, currentCamPosition) < 0.1f)
{
cameraObj.transform.parent = playerCamHome;
cameraObj.transform.localPosition = Vector3.zero;
cameraComponent.orthographicSize = baseCamSize;
returningHome = false;
}
}
}
}
+2
View File
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 34a2af7866b6ecc4ab5f2b6222f7dbe2
+3 -2
View File
@@ -5,6 +5,7 @@ public class GameManager : MonoBehaviour
{
public static GameManager Instance { get; private set; }
public DialogueManager DialogueManager { get; private set; }
public Inventory Inventory { get; private set; }
public Storybools Storybools { get; private set; }
private void Awake()
@@ -21,6 +22,8 @@ private void Awake()
DontDestroyOnLoad(gameObject);
DialogueManager = GetComponent<DialogueManager>();
Inventory = GetComponent<Inventory>();
SaveSystem.Load();
}
}
@@ -43,8 +46,6 @@ public void LoadStoryBools(StoryboolSaveData data)
}
}
#endregion
public int StarShards = 0; // will replace with inventory system
}
[System.Serializable]
+7 -1
View File
@@ -4,5 +4,11 @@
public class Item : MonoBehaviour
{
public string itemName;
public int id;
public ItemIdEnum id;
public int maxStack = 10;
}
public enum ItemIdEnum
{
STAR_SHARD = 1
}
+6 -5
View File
@@ -7,11 +7,12 @@ public class PickupableItem : Interactable
public override void Interact()
{
GameManager.Instance.StarShards++; // REMOVE, JUST HERE FOR TESTING BEFORE ADDING INVENTORY SYSTEM
Debug.Log("Picked up " + item.itemName + "!");
MoveOutsideRange(); // I don't love this but if we destroy the object we probably need to do this first
Destroy(gameObject);
if (GameManager.Instance.Inventory.AddItem(item))
{
Debug.Log("Picked up " + item.itemName + "!");
MoveOutsideRange(); // I don't love this but if we destroy the object we probably need to do this first
Destroy(gameObject);
}
}
public override void MoveInsideRange()
+1 -1
View File
@@ -41,7 +41,7 @@ private void Awake()
// QID1_1_hasEnoughStarshards
QID1_List[0] = new QuestBool(() =>
{
return GameManager.Instance.StarShards > 2;
return GameManager.Instance.Inventory.GetItemQuantity(ItemIdEnum.STAR_SHARD) > 2;
});
// QID1_2_hasHelpedSam
+3
View File
@@ -11,6 +11,7 @@ public struct SaveData
{
public QuestSaveData QuestData;
public StoryboolSaveData StoryboolData;
public InventorySaveData InventorySaveData;
}
public static string SaveFileName()
@@ -41,6 +42,7 @@ public static void Save()
private static void HandleSaveData()
{
GameManager.Instance.SaveStoryBools(ref _saveData.StoryboolData);
GameManager.Instance.Inventory.SaveInventory(ref _saveData.InventorySaveData);
QuestRegistry.Instance.SaveQuestData(ref _saveData.QuestData);
}
@@ -78,6 +80,7 @@ public static void Load()
public static void HandleLoadData()
{
GameManager.Instance.LoadStoryBools(_saveData.StoryboolData);
GameManager.Instance.Inventory.LoadInventory(_saveData.InventorySaveData);
QuestRegistry.Instance.LoadQuestData(_saveData.QuestData);
}
}
+47
View File
@@ -0,0 +1,47 @@
using UnityEngine;
public class StaticCamRoom : MonoBehaviour
{
// these will be hidden when room is entered
public Transform camPosition;
public Transform[] objectsToHide;
public float camZoom = 5f;
private void RoomEnter()
{
foreach (var obj in objectsToHide)
{
obj.gameObject.SetActive(false);
}
}
private void RoomExit()
{
foreach (var obj in objectsToHide)
{
obj.gameObject.SetActive(true);
}
}
private void OnTriggerEnter(Collider other)
{
CameraController controller = other.gameObject.GetComponent<CameraController>();
if (controller != null)
{
controller.SetCurrentPosition(camPosition.position, camZoom);
RoomEnter();
}
}
private void OnTriggerExit(Collider other)
{
CameraController controller = other.gameObject.GetComponent<CameraController>();
if (controller != null)
{
controller.ReturnCameraToHome();
RoomExit();
}
}
}
+2
View File
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 35d74944899dd8b4c9659da46cd64278
+2 -1
View File
@@ -53,7 +53,8 @@ void DetermineDialogue()
}
else
{
currentQuest.CheckComplete();
if (currentQuest.hasStarted)
currentQuest.CheckComplete(); // don't check for completion before asking player for help
currentDialogue = new Dialogue();
currentDialogue.charName = defaultDialogue.charName;