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
+138
View File
@@ -0,0 +1,138 @@
using System.Collections.Generic;
using UnityEngine;
public class Inventory : MonoBehaviour
{
public ItemSlot[] itemSlots;
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
}
// we'll set this up to only try to add one item to the inventory at a time for now
// there won't be stacked items in the wild for right now
public bool AddItem(Item item)
{
// first try to stack
for (int i = 0; i < itemSlots.Length; i++)
{
if (itemSlots[i] != null)
{
if (itemSlots[i].item == item.id && itemSlots[i].quantity < item.maxStack)
{
itemSlots[i].quantity += 1;
return true;
}
}
}
// no stack to add to, try to find an empty slot
for (int i = 0; i < itemSlots.Length; i++)
{
if (itemSlots[i] == null)
{
itemSlots[i] = new ItemSlot();
itemSlots[i].quantity = 1;
itemSlots[i].item = item.id;
return true;
}
}
// no open slots, no open stacks, we can't add the item
return false;
}
public bool RemoveItemQuantity(ItemIdEnum itemId, int quantity)
{
if (GetItemQuantity(itemId) >= quantity)
{
int currentQuantity = quantity;
for (int i = 0; i < itemSlots.Length; i++)
{
if (itemSlots[i] != null && itemSlots[i].item == itemId)
{
// we are trying to remove less items than what exists in the current
// stack, so just subtract from the stack
if (currentQuantity < itemSlots[i].quantity)
{
itemSlots[i].quantity -= currentQuantity;
break;
}
else if (currentQuantity == itemSlots[i].quantity)
{
// we have exactly enough in the current slot, so nullify it and
// exit
itemSlots[i] = null;
break;
}
else
{
// we don't have enough in the stack, but we DO have enough in our
// inventory. nullify the stack, subtract that number from the current
// count, and move to the next item
currentQuantity -= itemSlots[i].quantity;
itemSlots[i] = null;
}
}
}
return true;
}
else
{
return false;
}
}
public int GetItemQuantity(ItemIdEnum itemId)
{
int itemCount = 0;
foreach (ItemSlot slot in itemSlots)
{
if (slot != null && slot.item == itemId)
{
itemCount += slot.quantity;
}
}
return itemCount;
}
#region Inventory Save/Load
public void SaveInventory(ref InventorySaveData data)
{
data.itemSlots = itemSlots;
}
public void LoadInventory(InventorySaveData data)
{
if (data.itemSlots != null)
{
itemSlots = data.itemSlots;
}
else
{
Debug.Log("new slots");
itemSlots = new ItemSlot[8];
}
}
#endregion
}
[System.Serializable]
public class ItemSlot
{
public int quantity;
public ItemIdEnum item;
}
[System.Serializable]
public struct InventorySaveData
{
public ItemSlot[] itemSlots;
}
+2
View File
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 40e5d5183cb59cf4d8603dca70c1a9b5
File diff suppressed because it is too large Load Diff
+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 static GameManager Instance { get; private set; }
public DialogueManager DialogueManager { get; private set; } public DialogueManager DialogueManager { get; private set; }
public Inventory Inventory { get; private set; }
public Storybools Storybools { get; private set; } public Storybools Storybools { get; private set; }
private void Awake() private void Awake()
@@ -21,6 +22,8 @@ private void Awake()
DontDestroyOnLoad(gameObject); DontDestroyOnLoad(gameObject);
DialogueManager = GetComponent<DialogueManager>(); DialogueManager = GetComponent<DialogueManager>();
Inventory = GetComponent<Inventory>();
SaveSystem.Load(); SaveSystem.Load();
} }
} }
@@ -43,8 +46,6 @@ public void LoadStoryBools(StoryboolSaveData data)
} }
} }
#endregion #endregion
public int StarShards = 0; // will replace with inventory system
} }
[System.Serializable] [System.Serializable]
+7 -1
View File
@@ -4,5 +4,11 @@
public class Item : MonoBehaviour public class Item : MonoBehaviour
{ {
public string itemName; public string itemName;
public int id; public ItemIdEnum id;
public int maxStack = 10;
}
public enum ItemIdEnum
{
STAR_SHARD = 1
} }
+3 -2
View File
@@ -7,12 +7,13 @@ public class PickupableItem : Interactable
public override void Interact() public override void Interact()
{ {
GameManager.Instance.StarShards++; // REMOVE, JUST HERE FOR TESTING BEFORE ADDING INVENTORY SYSTEM if (GameManager.Instance.Inventory.AddItem(item))
{
Debug.Log("Picked up " + item.itemName + "!"); 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 MoveOutsideRange(); // I don't love this but if we destroy the object we probably need to do this first
Destroy(gameObject); Destroy(gameObject);
} }
}
public override void MoveInsideRange() public override void MoveInsideRange()
{ {
+1 -1
View File
@@ -41,7 +41,7 @@ private void Awake()
// QID1_1_hasEnoughStarshards // QID1_1_hasEnoughStarshards
QID1_List[0] = new QuestBool(() => QID1_List[0] = new QuestBool(() =>
{ {
return GameManager.Instance.StarShards > 2; return GameManager.Instance.Inventory.GetItemQuantity(ItemIdEnum.STAR_SHARD) > 2;
}); });
// QID1_2_hasHelpedSam // QID1_2_hasHelpedSam
+3
View File
@@ -11,6 +11,7 @@ public struct SaveData
{ {
public QuestSaveData QuestData; public QuestSaveData QuestData;
public StoryboolSaveData StoryboolData; public StoryboolSaveData StoryboolData;
public InventorySaveData InventorySaveData;
} }
public static string SaveFileName() public static string SaveFileName()
@@ -41,6 +42,7 @@ public static void Save()
private static void HandleSaveData() private static void HandleSaveData()
{ {
GameManager.Instance.SaveStoryBools(ref _saveData.StoryboolData); GameManager.Instance.SaveStoryBools(ref _saveData.StoryboolData);
GameManager.Instance.Inventory.SaveInventory(ref _saveData.InventorySaveData);
QuestRegistry.Instance.SaveQuestData(ref _saveData.QuestData); QuestRegistry.Instance.SaveQuestData(ref _saveData.QuestData);
} }
@@ -78,6 +80,7 @@ public static void Load()
public static void HandleLoadData() public static void HandleLoadData()
{ {
GameManager.Instance.LoadStoryBools(_saveData.StoryboolData); GameManager.Instance.LoadStoryBools(_saveData.StoryboolData);
GameManager.Instance.Inventory.LoadInventory(_saveData.InventorySaveData);
QuestRegistry.Instance.LoadQuestData(_saveData.QuestData); 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 else
{ {
currentQuest.CheckComplete(); if (currentQuest.hasStarted)
currentQuest.CheckComplete(); // don't check for completion before asking player for help
currentDialogue = new Dialogue(); currentDialogue = new Dialogue();
currentDialogue.charName = defaultDialogue.charName; currentDialogue.charName = defaultDialogue.charName;
+5 -1
View File
@@ -64,6 +64,8 @@ MeshRenderer:
m_RayTracingAccelStructBuildFlagsOverride: 0 m_RayTracingAccelStructBuildFlagsOverride: 0
m_RayTracingAccelStructBuildFlags: 1 m_RayTracingAccelStructBuildFlags: 1
m_SmallMeshCulling: 1 m_SmallMeshCulling: 1
m_ForceMeshLod: -1
m_MeshLodSelectionBias: 0
m_RenderingLayerMask: 1 m_RenderingLayerMask: 1
m_RendererPriority: 0 m_RendererPriority: 0
m_Materials: m_Materials:
@@ -85,6 +87,7 @@ MeshRenderer:
m_AutoUVMaxDistance: 0.5 m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89 m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0} m_LightmapParameters: {fileID: 0}
m_GlobalIlluminationMeshLod: 0
m_SortingLayerID: 0 m_SortingLayerID: 0
m_SortingLayer: 0 m_SortingLayer: 0
m_SortingOrder: 0 m_SortingOrder: 0
@@ -115,7 +118,8 @@ MonoBehaviour:
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
itemName: Star Shard itemName: Star Shard
id: 0 id: 1
maxStack: 10
--- !u!135 &7654873247549649761 --- !u!135 &7654873247549649761
SphereCollider: SphereCollider:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
+8
View File
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 59296355e319f8c47b8c7acaa657a45f
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
File diff suppressed because it is too large Load Diff
+7
View File
@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: b7501630d71d83a47afdce8750b0196e
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
+125
View File
@@ -0,0 +1,125 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!29 &1
OcclusionCullingSettings:
m_ObjectHideFlags: 0
serializedVersion: 2
m_OcclusionBakeSettings:
smallestOccluder: 5
smallestHole: 0.25
backfaceThreshold: 100
m_SceneGUID: 00000000000000000000000000000000
m_OcclusionCullingData: {fileID: 0}
--- !u!104 &2
RenderSettings:
m_ObjectHideFlags: 0
serializedVersion: 10
m_Fog: 0
m_FogColor: {r: 0.5, g: 0.5, b: 0.5, a: 1}
m_FogMode: 3
m_FogDensity: 0.01
m_LinearFogStart: 0
m_LinearFogEnd: 300
m_AmbientSkyColor: {r: 0.212, g: 0.227, b: 0.259, a: 1}
m_AmbientEquatorColor: {r: 0.114, g: 0.125, b: 0.133, a: 1}
m_AmbientGroundColor: {r: 0.047, g: 0.043, b: 0.035, a: 1}
m_AmbientIntensity: 1
m_AmbientMode: 0
m_SubtractiveShadowColor: {r: 0.42, g: 0.478, b: 0.627, a: 1}
m_SkyboxMaterial: {fileID: 10304, guid: 0000000000000000f000000000000000, type: 0}
m_HaloStrength: 0.5
m_FlareStrength: 1
m_FlareFadeSpeed: 3
m_HaloTexture: {fileID: 0}
m_SpotCookie: {fileID: 10001, guid: 0000000000000000e000000000000000, type: 0}
m_DefaultReflectionMode: 0
m_DefaultReflectionResolution: 128
m_ReflectionBounces: 1
m_ReflectionIntensity: 1
m_CustomReflection: {fileID: 0}
m_Sun: {fileID: 0}
m_UseRadianceAmbientProbe: 0
--- !u!157 &3
LightmapSettings:
m_ObjectHideFlags: 0
serializedVersion: 13
m_BakeOnSceneLoad: 0
m_GISettings:
serializedVersion: 2
m_BounceScale: 1
m_IndirectOutputScale: 1
m_AlbedoBoost: 1
m_EnvironmentLightingMode: 0
m_EnableBakedLightmaps: 1
m_EnableRealtimeLightmaps: 0
m_LightmapEditorSettings:
serializedVersion: 12
m_Resolution: 2
m_BakeResolution: 40
m_AtlasSize: 1024
m_AO: 0
m_AOMaxDistance: 1
m_CompAOExponent: 1
m_CompAOExponentDirect: 0
m_ExtractAmbientOcclusion: 0
m_Padding: 2
m_LightmapParameters: {fileID: 0}
m_LightmapsBakeMode: 1
m_TextureCompression: 1
m_ReflectionCompression: 2
m_MixedBakeMode: 2
m_BakeBackend: 2
m_PVRSampling: 1
m_PVRDirectSampleCount: 32
m_PVRSampleCount: 512
m_PVRBounces: 2
m_PVREnvironmentSampleCount: 256
m_PVREnvironmentReferencePointCount: 2048
m_PVRFilteringMode: 1
m_PVRDenoiserTypeDirect: 1
m_PVRDenoiserTypeIndirect: 1
m_PVRDenoiserTypeAO: 1
m_PVRFilterTypeDirect: 0
m_PVRFilterTypeIndirect: 0
m_PVRFilterTypeAO: 0
m_PVREnvironmentMIS: 1
m_PVRCulling: 1
m_PVRFilteringGaussRadiusDirect: 1
m_PVRFilteringGaussRadiusIndirect: 1
m_PVRFilteringGaussRadiusAO: 1
m_PVRFilteringAtrousPositionSigmaDirect: 0.5
m_PVRFilteringAtrousPositionSigmaIndirect: 2
m_PVRFilteringAtrousPositionSigmaAO: 1
m_ExportTrainingData: 0
m_TrainingDataDestination: TrainingData
m_LightProbeSampleCountMultiplier: 4
m_LightingDataAsset: {fileID: 20201, guid: 0000000000000000f000000000000000, type: 0}
m_LightingSettings: {fileID: 0}
--- !u!196 &4
NavMeshSettings:
serializedVersion: 2
m_ObjectHideFlags: 0
m_BuildSettings:
serializedVersion: 3
agentTypeID: 0
agentRadius: 0.5
agentHeight: 2
agentSlope: 45
agentClimb: 0.4
ledgeDropHeight: 0
maxJumpAcrossDistance: 0
minRegionArea: 2
manualCellSize: 0
cellSize: 0.16666667
manualTileSize: 0
tileSize: 256
buildHeightMesh: 0
maxJobWorkers: 0
preserveTilesOutsideBounds: 0
debug:
m_Flags: 0
m_NavMeshData: {fileID: 0}
--- !u!1660057539 &9223372036854775807
SceneRoots:
m_ObjectHideFlags: 0
m_Roots: []
+7
View File
@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: f7743426c65aebf45a5f8d5945ac0dd5
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
File diff suppressed because it is too large Load Diff
+7
View File
@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 3e3c760154aad7c4a90627f4915e897b
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
File diff suppressed because it is too large Load Diff
+7
View File
@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 47f0d7760444f874e8bcb58acb76e330
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant: