Skip to content

Commit

Permalink
GameStructure: Level CoinTarget property and LevelManager GameWonWhen…
Browse files Browse the repository at this point in the history
…TargetCoinsReached auto win option
  • Loading branch information
FlipWebApps committed Jan 14, 2017
1 parent 5974699 commit 0b0331a
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 5 deletions.
17 changes: 13 additions & 4 deletions Scripts/GameStructure/Levels/Editor/LevelEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public class LevelEditor : GameItemEditor
SerializedProperty _star4TargetProperty;
SerializedProperty _timeTargetProperty;
SerializedProperty _scoreTargetProperty;
SerializedProperty _coinTargetProperty;

protected override void OnEnable()
{
Expand All @@ -49,6 +50,7 @@ protected override void OnEnable()
_star4TargetProperty = serializedObject.FindProperty("_star4Target");
_timeTargetProperty = serializedObject.FindProperty("_timeTarget");
_scoreTargetProperty = serializedObject.FindProperty("_scoreTarget");
_coinTargetProperty = serializedObject.FindProperty("_coinTarget");
}


Expand All @@ -67,12 +69,19 @@ protected void DrawLevelProperties()
EditorGUILayout.LabelField("Level Properties", EditorStyles.boldLabel);
EditorGUI.indentLevel += 1;
EditorGUILayout.PropertyField(_starTotalCountProperty);
EditorGUILayout.PropertyField(_star1TargetProperty);
EditorGUILayout.PropertyField(_star2TargetProperty);
EditorGUILayout.PropertyField(_star3TargetProperty);
EditorGUILayout.PropertyField(_star4TargetProperty);
EditorGUI.indentLevel += 1;
if (_starTotalCountProperty.intValue >= 1)
EditorGUILayout.PropertyField(_star1TargetProperty);
if (_starTotalCountProperty.intValue >= 2)
EditorGUILayout.PropertyField(_star2TargetProperty);
if (_starTotalCountProperty.intValue >= 3)
EditorGUILayout.PropertyField(_star3TargetProperty);
if (_starTotalCountProperty.intValue >= 4)
EditorGUILayout.PropertyField(_star4TargetProperty);
EditorGUI.indentLevel -= 1;
EditorGUILayout.PropertyField(_timeTargetProperty);
EditorGUILayout.PropertyField(_scoreTargetProperty);
EditorGUILayout.PropertyField(_coinTargetProperty);
EditorGUI.indentLevel -= 1;
EditorGUILayout.EndVertical();
}
Expand Down
11 changes: 10 additions & 1 deletion Scripts/GameStructure/Levels/LevelManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ public class LevelManager : Singleton<LevelManager>
[Tooltip("Whether the user should automatically win the game once the levels target score is reached")]
public bool GameWonWhenTargetScoreReached;

/// <summary>
/// Whether the user should automatically win the game once the levels target coins is reached
/// </summary>
[Tooltip("Whether the user should automatically win the game once the levels target coins is reached")]
public bool GameWonWhenTargetCoinsReached;

/// <summary>
/// Time when the level was started.
/// </summary>
Expand Down Expand Up @@ -141,6 +147,8 @@ void Start()
MyDebug.LogWarningF("You have enabled the option 'GameOverWhenTargetTimeReached' in LevelManager however the current level has a configured TimeTarget of 0 and so will end immediately. Consider using Level resource configuration files and setting this value.");
if (GameWonWhenTargetScoreReached && Mathf.Approximately(Level.ScoreTarget, 0))
MyDebug.LogWarningF("You have enabled the option 'GameWonWhenTargetScoreReached' in LevelManager however the current level has a configured ScoreTarget of 0 and so will end immediately. Consider using Level resource configuration files and setting this value.");
if (GameWonWhenTargetCoinsReached && Mathf.Approximately(Level.CoinTarget, 0))
MyDebug.LogWarningF("You have enabled the option 'GameWonWhenTargetCoinsReached' in LevelManager however the current level has a configured CoinTarget of 0 and so will end immediately. Consider using Level resource configuration files and setting this value.");
#endif

if (AutoStart)
Expand Down Expand Up @@ -236,7 +244,8 @@ void Update()

// check for gameover (win) conditions.
if ((GameWonWhenAllStarsGot && Level.StarTotalCount == Level.StarsWonCount && StartStarsWon != Level.StarsWon) ||
GameWonWhenTargetScoreReached && Level.Score >= Level.ScoreTarget)
GameWonWhenTargetScoreReached && Level.Score >= Level.ScoreTarget ||
GameWonWhenTargetCoinsReached && Level.Coins >= Level.CoinTarget)
GameOver(true, ShowGameOverDialogDelay);
}

Expand Down
18 changes: 18 additions & 0 deletions Scripts/GameStructure/Levels/ObjectModel/Level.cs
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,24 @@ public int ScoreTarget
[SerializeField]
int _scoreTarget;

/// <summary>
/// A field that you can set from json, extensions or code that represents a target coins for completing the level
/// </summary>
/// You can also use StarxTarget if you want individual scores for winning different stars.
public int CoinTarget
{
get
{
return _coinTarget;
}
set
{
_coinTarget = value;
}
}
[Tooltip("The coins target for completing the level.")]
[SerializeField]
int _coinTarget;
#endregion Editor Parameters

/// <summary>
Expand Down

0 comments on commit 0b0331a

Please sign in to comment.