One of the first things I implemented was an indepth camera that would move around the screen exactly as I wished.
// Switch statement connected to an enum of camera states
switch (m_cameraState)
{
//On nothing do nothing
case CameraState.Nothing:
break;
//Getting the normal state of right behind the player
case CameraState.Normal:
if (m_Grid.m_GridPathArray != null)
{
m_CreatureTheCameraIsOn = m_Creature.ModelInGame.transform.position;
transform.position = Vector3.Lerp(transform.position, new Vector3(
m_CreatureTheCameraIsOn.transform.position.x + NormalOffset.x,
m_CreatureTheCameraIsOn.transform.position.y + NormalOffset.y,
m_CreatureTheCameraIsOn.transform.position.z - NormalOffset.z), Time.deltaTime * 2);
}
PlayerUiSelection();
break;
//When a player moves the camera follows
case CameraState.PlayerMovement:
transform.position = Vector3.Lerp(transform.position, new Vector3(
m_Creature.ModelInGame.transform.position.x + MovementOffset.x,
m_Creature.ModelInGame.transform.position.y + MovementOffset.y,
m_Creature.ModelInGame.transform.position.z - MovementOffset.z), Time.deltaTime * 2);
break;
//When the player is attacking
case CameraState.PlayerAttack:
transform.position = Vector3.Lerp(transform.position, new Vector3(
m_Creature.ModelInGame.transform.position.x + MovementOffset.x,
m_Creature.ModelInGame.transform.position.y + MovementOffset.y,
m_Creature.ModelInGame.transform.position.z - MovementOffset.z), Time.deltaTime * 2);
break;
//When the enemy moves
case CameraState.EnemyMovement:
if (m_Grid.m_GridPathArray != null)
{
transform.position = Vector3.Lerp(transform.position, new Vector3(
m_Creature.ModelInGame.transform.position.x + MovementOffset.x,
m_Creature.ModelInGame.transform.position.y + MovementOffset.y,
m_Creature.ModelInGame.transform.position.z - MovementOffset.z), Time.deltaTime * 2);
}
break;
case CameraState.EnemyAttack:
break;
}
//Takes in an Enum type as an argument such as Screen.CommandBoard
public void PushScreen(Screen aScreen)
{
//Gets the screen from the list like dicitionary
UiScreen screenToAdd = m_UiScreens[(int)aScreen];
//We tell the screen to do its push
screenToAdd.OnPush();
Debug.Log(screenToAdd.ToString());
//Add this screen to the stack for easy removal and management
m_ScreenStack.Add(new KeyValuePair(aScreen, screenToAdd));
m_ScreenStack[m_ScreenStack.Count - 1].Value.m_InputActive = true;
}
--------------------------------------------------------------------------------------------
//Pop Takes in no arguements because we want to remove whatever is on top without knowing whats on top
public void PopScreen()
{
if (m_LastScreen.Count > 1)
{
m_LastScreen.RemoveAt(0);
}
//Keeping track of what was the last screen that was removed
m_LastScreen.Add(m_ScreenStack[m_ScreenStack.Count - 1].Key);
//Telling the top of the stack to do its pop method
m_ScreenStack[m_ScreenStack.Count - 1].Value.OnPop();
//Finally remove the screen from the stack
m_ScreenStack.RemoveAt(m_ScreenStack.Count - 1);
}
A turn based strategy game is mostly User interface so creating a strong manager was something I set out to accomplish. The Ui Manager is a singleton that has a reference to each of the different Ui screens. Attached in a Dicitionary like list a key of an enum is placed of each ui screen and a value of the screen we are pushing.