add camera position switching for static view rooms
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 34a2af7866b6ecc4ab5f2b6222f7dbe2
|
||||
@@ -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]
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 35d74944899dd8b4c9659da46cd64278
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user