[TASK] Added main "game manager" to switch between the minigame and the map + added simple UI to show that a sticker was collected

This commit is contained in:
2019-08-28 01:11:46 +02:00
parent 9057c295da
commit c52392eacd
16 changed files with 2423 additions and 102 deletions

View File

@@ -0,0 +1,106 @@
using System;
using System.Collections;
using System.Collections.Generic;
using Boo.Lang;
using Mapbox.Map;
using UnityEngine;
using UnityEngine.Serialization;
public enum GameState
{
Map, Minigame, DuckCollectedScreen, StickerOverview
}
public class BadeendGoGameManager : MonoBehaviour
{
public GameObject profileButton;
public GameObject mainMap;
public CollectedStickersUI stickerDisplay;
public GameObject miniGame;
public GameObject minigameOverlay;
public DuckCollectedScreen duckCollectedScreen;
private GameState _gameState;
private CollectableDuckData _minigamePlayingForDuck;
public GameState GameState
{
get => _gameState;
set
{
_gameState = value;
mainMap.SetActive(value == GameState.Map || value == GameState.DuckCollectedScreen);
stickerDisplay.gameObject.SetActive(value == GameState.StickerOverview);
miniGame.SetActive(value == GameState.Minigame);
duckCollectedScreen.gameObject.SetActive(value == GameState.DuckCollectedScreen);
profileButton.SetActive(value == GameState.Map);
minigameOverlay.SetActive(value == GameState.Minigame);
}
}
private static BadeendGoGameManager _instance;
public static BadeendGoGameManager Instance
{
get { return _instance; }
private set { _instance = value; }
}
public BadeendGoGameManager()
{
if (Instance != null)
{
throw new Exception("An instance of BadeendGoGameManager already exists");
}
Instance = this;
}
private void Awake()
{
GameState = GameState.Map;
CollectableDuckManager.Instance.DuckClicked += OnDuckClicked;
CatchMinigameManager.Instance.MinigameFinished += OnMinigameFinished;
duckCollectedScreen.screenCloseClicked += DuckCollectedScreenOnScreenCloseClicked;
duckCollectedScreen.retryClicked += DuckCollectedScreenOnRetryClicked;
}
private void DuckCollectedScreenOnRetryClicked(object sender, EventArgs e)
{
GameState = GameState.Minigame;
CatchMinigameManager.Instance.ResetMinigame();
}
private void DuckCollectedScreenOnScreenCloseClicked(object sender, EventArgs e)
{
GameState = GameState.Map;
}
private void OnDuckClicked(object sender, CollectableDuckData duck)
{
GameState = GameState.Minigame;
CatchMinigameManager.Instance.ResetMinigame();
_minigamePlayingForDuck = duck;
}
private void OnMinigameFinished(object sender, MiniGameResult miniGameResult)
{
GameState = GameState.DuckCollectedScreen;
duckCollectedScreen.MiniGameResult = miniGameResult;
if (_minigamePlayingForDuck)
{
duckCollectedScreen.CollectedSticker = _minigamePlayingForDuck.StickerData;
}
if (miniGameResult == MiniGameResult.Success)
{
// Duck collected
DuckStickerManager.Instance.OnStickerCollected(_minigamePlayingForDuck.StickerData);
CollectableDuckManager.Instance.OnDuckCollected(_minigamePlayingForDuck);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 7839e0fb50a183c4f940215e4aa5df59
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,18 +1,32 @@
using System.Collections; using System;
using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using TMPro; using TMPro;
using UnityEngine; using UnityEngine;
using Random = UnityEngine.Random;
public class CatchMinigameController : MonoBehaviour public class CatchMinigameManager : MonoBehaviour
{ {
private int _score; private int _score;
public int Score public int Score
{ {
get { return _score; } get => _score;
set set
{ {
_score = value; _score = value;
scoreText.text = "Score: " + _score; scoreText.text = "Score: " + _score + " / " + minimalScore;
}
}
private int _netAttempts;
public int NetAttempts
{
get => _netAttempts;
set
{
_netAttempts = value;
netAttemptText.text = "Netten over: " + (maxNetAttempts - value) + " / " + maxNetAttempts;
} }
} }
@@ -25,10 +39,14 @@ public class CatchMinigameController : MonoBehaviour
public Collider duckCaughtCollider; public Collider duckCaughtCollider;
public TMP_Text scoreText; public TMP_Text scoreText;
public TMP_Text netAttemptText;
public float netCooldown = 0.5f; public float netCooldown = 0.5f;
public float netVelocity = 10f; public float netVelocity = 10f;
public Vector3 netDisplacement = Vector3.up * 4; public Vector3 netDisplacement = Vector3.up * 4;
public int maxNetAttempts = 5;
public int minimalScore = 20;
public GameObject net; public GameObject net;
@@ -43,6 +61,8 @@ public class CatchMinigameController : MonoBehaviour
public Transform duckCollectEffectParent; public Transform duckCollectEffectParent;
public FloatingDuckController floatingDuckPrefab; public FloatingDuckController floatingDuckPrefab;
public event EventHandler<MiniGameResult> MinigameFinished;
private List<FloatingDuckController> activeDucks = new List<FloatingDuckController>(); private List<FloatingDuckController> activeDucks = new List<FloatingDuckController>();
private Queue<FloatingDuckController> floatingDuckPool = new Queue<FloatingDuckController>(); private Queue<FloatingDuckController> floatingDuckPool = new Queue<FloatingDuckController>();
@@ -50,12 +70,27 @@ public class CatchMinigameController : MonoBehaviour
private bool _netMoving = false; private bool _netMoving = false;
private static CatchMinigameManager _instance;
public static CatchMinigameManager Instance
{
get { return _instance; }
private set { _instance = value; }
}
public CatchMinigameManager()
{
Instance = this;
}
public void ResetMinigame() public void ResetMinigame()
{ {
Score = 0; Score = 0;
NetAttempts = 0;
for (var i = 0; i < activeDucks.Count; i++) for (var i = 0; i < activeDucks.Count; i++)
{ {
floatingDuckPool.Enqueue(activeDucks[i]); floatingDuckPool.Enqueue(activeDucks[i]);
activeDucks[i].gameObject.SetActive(false);
} }
activeDucks.Clear(); activeDucks.Clear();
} }
@@ -126,8 +161,18 @@ public class CatchMinigameController : MonoBehaviour
if (Input.GetMouseButtonDown(0) && !_netMoving) if (Input.GetMouseButtonDown(0) && !_netMoving)
{ {
// Activate the net // Activate the net
NetAttempts++;
StartCoroutine(MoveNet()); StartCoroutine(MoveNet());
} }
if (!_netMoving && NetAttempts >= maxNetAttempts)
{
// Minigame finished
if (MinigameFinished != null)
{
MinigameFinished.Invoke(this, Score >= minimalScore ? MiniGameResult.Success : MiniGameResult.Failed);
}
}
} }
private IEnumerator PoolEffectWhenFinished(ParticleSystem effect) private IEnumerator PoolEffectWhenFinished(ParticleSystem effect)
@@ -179,3 +224,8 @@ public class CatchMinigameController : MonoBehaviour
_netMoving = false; _netMoving = false;
} }
} }
public enum MiniGameResult
{
Success, Failed
}

View File

@@ -29,7 +29,7 @@ public class CollectableDuck: MonoBehaviour
{ {
throw new Exception("Unknown duck clicked in '" + gameObject.name + "'"); throw new Exception("Unknown duck clicked in '" + gameObject.name + "'");
} }
CollectableDuckManager.Instance.DuckCollected(CollectableDuckData); CollectableDuckManager.Instance.OnDuckClicked(CollectableDuckData);
} }
} }
} }

View File

@@ -15,7 +15,10 @@ public class CollectableDuckManager : MonoBehaviour
public AbstractMap map; public AbstractMap map;
public Transform player; public Transform player;
public Transform collectableDuckParent;
public event EventHandler<CollectableDuckData> DuckClicked;
/// <summary> /// <summary>
/// Spawn distance in meters (i.e. how close should the player be to a duck before it spawns on the map /// Spawn distance in meters (i.e. how close should the player be to a duck before it spawns on the map
/// </summary> /// </summary>
@@ -24,6 +27,7 @@ public class CollectableDuckManager : MonoBehaviour
public CollectableDuck duckSpawnPrefab; public CollectableDuck duckSpawnPrefab;
private static CollectableDuckManager _instance; private static CollectableDuckManager _instance;
public static CollectableDuckManager Instance public static CollectableDuckManager Instance
{ {
get { return _instance; } get { return _instance; }
@@ -86,7 +90,7 @@ public class CollectableDuckManager : MonoBehaviour
{ {
// Spawn the duck // Spawn the duck
var duckSpawn = Instantiate(duckSpawnPrefab, map.GeoToWorldPosition(duck.LatitudeLongitude), var duckSpawn = Instantiate(duckSpawnPrefab, map.GeoToWorldPosition(duck.LatitudeLongitude),
Quaternion.identity, transform); Quaternion.identity, collectableDuckParent);
duckSpawn.CollectableDuckData = duck; duckSpawn.CollectableDuckData = duck;
var duckModel = Instantiate(duck.ModelPrefab, duckSpawn.transform); var duckModel = Instantiate(duck.ModelPrefab, duckSpawn.transform);
duckModel.transform.localPosition = Vector3.zero; duckModel.transform.localPosition = Vector3.zero;
@@ -113,14 +117,20 @@ public class CollectableDuckManager : MonoBehaviour
} }
} }
public void DuckCollected(CollectableDuckData duck) public void OnDuckClicked(CollectableDuckData duck)
{
if (DuckClicked != null)
{
DuckClicked.Invoke(this, duck);
}
}
public void OnDuckCollected(CollectableDuckData duck)
{ {
_collectedDucks.Add(duck); _collectedDucks.Add(duck);
PlayerPrefs.SetInt("duck." + duck.Id, 1); PlayerPrefs.SetInt("duck." + duck.Id, 1);
DuckStickerManager.Instance.OnStickerCollected(duck.StickerData);
RemoveDuck(duck); RemoveDuck(duck);
} }
} }

View File

@@ -0,0 +1,20 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
public class DuckCollectedFailedScreen : MonoBehaviour
{
public UnityEvent retryButtonClicked;
public UnityEvent cancelButtonClicked;
public void OnRetryButtonClicked()
{
retryButtonClicked?.Invoke();
}
public void OnCancelButtonClicked()
{
cancelButtonClicked?.Invoke();
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 17d4517ebd095b340a5ee5d9346d6407
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,49 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Serialization;
public class DuckCollectedScreen : MonoBehaviour
{
public DuckCollectedSuccessScreen successScreen;
public DuckCollectedFailedScreen failedScreen;
public event EventHandler screenCloseClicked;
public event EventHandler retryClicked;
private MiniGameResult _miniGameResult;
public MiniGameResult MiniGameResult
{
get => _miniGameResult;
set
{
_miniGameResult = value;
successScreen.gameObject.SetActive(value == MiniGameResult.Success);
failedScreen.gameObject.SetActive(value == MiniGameResult.Failed);
}
}
private DuckStickerData _collectedSticker;
public DuckStickerData CollectedSticker
{
get => _collectedSticker;
set
{
_collectedSticker = value;
successScreen.Sticker = value;
}
}
public void OnScreenCloseClicked()
{
screenCloseClicked?.Invoke(this, EventArgs.Empty);
}
public void OnRetryClicked()
{
retryClicked?.Invoke(this, EventArgs.Empty);
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: cc70bbfe7145ec343b5dd7910349d852
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,31 @@
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;
public class DuckCollectedSuccessScreen : MonoBehaviour
{
public Image stickerImage;
public TMP_Text stickerName;
public UnityEvent OkButtonClicked;
private DuckStickerData _sticker;
public DuckStickerData Sticker
{
get => _sticker;
set {
_sticker = value;
stickerImage.sprite = _sticker.StickerSprite;
stickerName.text = _sticker.Label;
}
}
public void OnOkButtonClicked()
{
OkButtonClicked?.Invoke();
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 84b2ba1059f29284b911771c5c9f6675
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

BIN
Assets/GUI/sad-duck.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 718 KiB

View File

@@ -0,0 +1,127 @@
fileFormatVersion: 2
guid: 3592a89853953854e834afc8e110bfbf
TextureImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 10
mipmaps:
mipMapMode: 0
enableMipMap: 0
sRGBTexture: 1
linearTexture: 0
fadeOut: 0
borderMipMap: 0
mipMapsPreserveCoverage: 0
alphaTestReferenceValue: 0.5
mipMapFadeDistanceStart: 1
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: 0.25
normalMapFilter: 0
isReadable: 0
streamingMipmaps: 0
streamingMipmapsPriority: 0
grayScaleToAlpha: 0
generateCubemap: 6
cubemapConvolution: 0
seamlessCubemap: 0
textureFormat: 1
maxTextureSize: 2048
textureSettings:
serializedVersion: 2
filterMode: -1
aniso: -1
mipBias: -100
wrapU: 1
wrapV: 1
wrapW: -1
nPOTScale: 0
lightmap: 0
compressionQuality: 50
spriteMode: 1
spriteExtrude: 1
spriteMeshType: 1
alignment: 0
spritePivot: {x: 0.5, y: 0.5}
spritePixelsToUnits: 100
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spriteGenerateFallbackPhysicsShape: 1
alphaUsage: 1
alphaIsTransparency: 1
spriteTessellationDetail: -1
textureType: 8
textureShape: 1
singleChannelComponent: 0
maxTextureSizeSet: 0
compressionQualitySet: 0
textureFormatSet: 0
platformSettings:
- serializedVersion: 3
buildTarget: DefaultTexturePlatform
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
- serializedVersion: 3
buildTarget: Standalone
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
- serializedVersion: 3
buildTarget: Android
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
- serializedVersion: 3
buildTarget: WebGL
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
spriteSheet:
serializedVersion: 2
sprites: []
outline: []
physicsShape: []
bones: []
spriteID:
internalID: 0
vertices: []
indices:
edges: []
weights: []
secondaryTextures: []
spritePackingTag:
pSDRemoveMatte: 0
pSDShowRemoveMatteOption: 0
userData:
assetBundleName:
assetBundleVariant:

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,3 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:Boolean x:Key="/Default/UserDictionary/Words/=Badeend/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Minigame/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>