Update Project
This commit is contained in:
+43
@@ -0,0 +1,43 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Zenject.Asteroids
|
||||
{
|
||||
public class AudioHandler : IInitializable, IDisposable
|
||||
{
|
||||
readonly SignalBus _signalBus;
|
||||
readonly Settings _settings;
|
||||
readonly AudioSource _audioSource;
|
||||
|
||||
public AudioHandler(
|
||||
AudioSource audioSource,
|
||||
Settings settings,
|
||||
SignalBus signalBus)
|
||||
{
|
||||
_signalBus = signalBus;
|
||||
_settings = settings;
|
||||
_audioSource = audioSource;
|
||||
}
|
||||
|
||||
public void Initialize()
|
||||
{
|
||||
_signalBus.Subscribe<ShipCrashedSignal>(OnShipCrashed);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_signalBus.Unsubscribe<ShipCrashedSignal>(OnShipCrashed);
|
||||
}
|
||||
|
||||
void OnShipCrashed()
|
||||
{
|
||||
_audioSource.PlayOneShot(_settings.CrashSound);
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class Settings
|
||||
{
|
||||
public AudioClip CrashSound;
|
||||
}
|
||||
}
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 24cbab5eaeb84b44481d817f66ea7b27
|
||||
timeCreated: 1461797898
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+218
@@ -0,0 +1,218 @@
|
||||
using System;
|
||||
using ModestTree;
|
||||
using UnityEngine;
|
||||
|
||||
#pragma warning disable 649
|
||||
|
||||
namespace Zenject.Asteroids
|
||||
{
|
||||
public class GuiHandler : MonoBehaviour, IDisposable, IInitializable
|
||||
{
|
||||
GameController _gameController;
|
||||
|
||||
[SerializeField]
|
||||
GUIStyle _titleStyle;
|
||||
|
||||
[SerializeField]
|
||||
GUIStyle _instructionsStyle;
|
||||
|
||||
[SerializeField]
|
||||
GUIStyle _timeStyle;
|
||||
|
||||
[SerializeField]
|
||||
float _gameOverFadeInTime;
|
||||
|
||||
[SerializeField]
|
||||
float _gameOverStartFadeTime;
|
||||
|
||||
[SerializeField]
|
||||
float _restartTextStartFadeTime;
|
||||
|
||||
[SerializeField]
|
||||
float _restartTextFadeInTime;
|
||||
|
||||
float _gameOverElapsed;
|
||||
SignalBus _signalBus;
|
||||
|
||||
[Inject]
|
||||
public void Construct(
|
||||
GameController gameController, SignalBus signalBus)
|
||||
{
|
||||
_gameController = gameController;
|
||||
_signalBus = signalBus;
|
||||
}
|
||||
|
||||
void OnGUI()
|
||||
{
|
||||
GUILayout.BeginArea(new Rect(0, 0, Screen.width, Screen.height));
|
||||
{
|
||||
switch (_gameController.State)
|
||||
{
|
||||
case GameStates.WaitingToStart:
|
||||
{
|
||||
StartGui();
|
||||
break;
|
||||
}
|
||||
case GameStates.Playing:
|
||||
{
|
||||
PlayingGui();
|
||||
break;
|
||||
}
|
||||
case GameStates.GameOver:
|
||||
{
|
||||
PlayingGui();
|
||||
GameOverGui();
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
Assert.That(false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
GUILayout.EndArea();
|
||||
}
|
||||
|
||||
void GameOverGui()
|
||||
{
|
||||
_gameOverElapsed += Time.deltaTime;
|
||||
|
||||
if (_gameOverElapsed > _gameOverStartFadeTime)
|
||||
{
|
||||
var px = Mathf.Min(1.0f, (_gameOverElapsed - _gameOverStartFadeTime) / _gameOverFadeInTime);
|
||||
_titleStyle.normal.textColor = new Color(1, 1, 1, px);
|
||||
}
|
||||
else
|
||||
{
|
||||
_titleStyle.normal.textColor = new Color(1, 1, 1, 0);
|
||||
}
|
||||
|
||||
if (_gameOverElapsed > _restartTextStartFadeTime)
|
||||
{
|
||||
var px = Mathf.Min(1.0f, (_gameOverElapsed - _restartTextStartFadeTime) / _restartTextFadeInTime);
|
||||
_instructionsStyle.normal.textColor = new Color(1, 1, 1, px);
|
||||
}
|
||||
else
|
||||
{
|
||||
_instructionsStyle.normal.textColor = new Color(1, 1, 1, 0);
|
||||
}
|
||||
|
||||
GUILayout.BeginHorizontal();
|
||||
{
|
||||
GUILayout.FlexibleSpace();
|
||||
GUILayout.BeginVertical();
|
||||
{
|
||||
GUILayout.FlexibleSpace();
|
||||
GUILayout.BeginVertical();
|
||||
{
|
||||
GUILayout.FlexibleSpace();
|
||||
|
||||
GUILayout.BeginHorizontal();
|
||||
{
|
||||
GUILayout.FlexibleSpace();
|
||||
GUILayout.Label("GAME OVER", _titleStyle);
|
||||
GUILayout.FlexibleSpace();
|
||||
}
|
||||
GUILayout.EndHorizontal();
|
||||
|
||||
GUILayout.Space(60);
|
||||
|
||||
GUILayout.BeginHorizontal();
|
||||
{
|
||||
GUILayout.FlexibleSpace();
|
||||
|
||||
GUILayout.Label("Click to restart", _instructionsStyle);
|
||||
|
||||
GUILayout.FlexibleSpace();
|
||||
}
|
||||
GUILayout.EndHorizontal();
|
||||
}
|
||||
GUILayout.EndVertical();
|
||||
|
||||
GUILayout.FlexibleSpace();
|
||||
}
|
||||
|
||||
GUILayout.EndVertical();
|
||||
GUILayout.FlexibleSpace();
|
||||
}
|
||||
GUILayout.EndHorizontal();
|
||||
}
|
||||
|
||||
void PlayingGui()
|
||||
{
|
||||
GUILayout.BeginVertical();
|
||||
{
|
||||
GUILayout.Space(30);
|
||||
GUILayout.BeginHorizontal();
|
||||
{
|
||||
GUILayout.Space(30);
|
||||
GUILayout.Label("Time: " + _gameController.ElapsedTime.ToString("0.##"), _timeStyle);
|
||||
GUILayout.FlexibleSpace();
|
||||
}
|
||||
GUILayout.EndHorizontal();
|
||||
}
|
||||
GUILayout.EndVertical();
|
||||
}
|
||||
|
||||
void StartGui()
|
||||
{
|
||||
GUILayout.BeginHorizontal();
|
||||
{
|
||||
GUILayout.FlexibleSpace();
|
||||
GUILayout.BeginVertical();
|
||||
{
|
||||
GUILayout.Space(100);
|
||||
GUILayout.FlexibleSpace();
|
||||
GUILayout.BeginVertical();
|
||||
{
|
||||
GUILayout.FlexibleSpace();
|
||||
|
||||
GUILayout.BeginHorizontal();
|
||||
{
|
||||
GUILayout.FlexibleSpace();
|
||||
GUILayout.Label("ASTEROIDS", _titleStyle);
|
||||
GUILayout.FlexibleSpace();
|
||||
}
|
||||
GUILayout.EndHorizontal();
|
||||
|
||||
GUILayout.Space(60);
|
||||
|
||||
GUILayout.BeginHorizontal();
|
||||
{
|
||||
GUILayout.FlexibleSpace();
|
||||
|
||||
GUILayout.Label("Click to start", _instructionsStyle);
|
||||
|
||||
GUILayout.FlexibleSpace();
|
||||
}
|
||||
GUILayout.EndHorizontal();
|
||||
}
|
||||
GUILayout.EndVertical();
|
||||
|
||||
GUILayout.FlexibleSpace();
|
||||
}
|
||||
|
||||
GUILayout.EndVertical();
|
||||
GUILayout.FlexibleSpace();
|
||||
}
|
||||
GUILayout.EndHorizontal();
|
||||
}
|
||||
|
||||
public void Initialize()
|
||||
{
|
||||
_signalBus.Subscribe<ShipCrashedSignal>(OnShipCrashed);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_signalBus.Unsubscribe<ShipCrashedSignal>(OnShipCrashed);
|
||||
}
|
||||
|
||||
void OnShipCrashed()
|
||||
{
|
||||
_gameOverElapsed = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 79984cb687438fd469b84d7e916d0574
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
+57
@@ -0,0 +1,57 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace Zenject.Asteroids
|
||||
{
|
||||
public class LevelHelper
|
||||
{
|
||||
readonly Camera _camera;
|
||||
|
||||
public LevelHelper(
|
||||
[Inject(Id = "Main")]
|
||||
Camera camera)
|
||||
{
|
||||
_camera = camera;
|
||||
}
|
||||
|
||||
public float Bottom
|
||||
{
|
||||
get { return -ExtentHeight; }
|
||||
}
|
||||
|
||||
public float Top
|
||||
{
|
||||
get { return ExtentHeight; }
|
||||
}
|
||||
|
||||
public float Left
|
||||
{
|
||||
get { return -ExtentWidth; }
|
||||
}
|
||||
|
||||
public float Right
|
||||
{
|
||||
get { return ExtentWidth; }
|
||||
}
|
||||
|
||||
public float ExtentHeight
|
||||
{
|
||||
get { return _camera.orthographicSize; }
|
||||
}
|
||||
|
||||
public float Height
|
||||
{
|
||||
get { return ExtentHeight * 2.0f; }
|
||||
}
|
||||
|
||||
public float ExtentWidth
|
||||
{
|
||||
get { return _camera.aspect * _camera.orthographicSize; }
|
||||
}
|
||||
|
||||
public float Width
|
||||
{
|
||||
get { return ExtentWidth * 2.0f; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 439c34e98ba09b546be28d2b13fda970
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
using UnityEngine;
|
||||
|
||||
#pragma warning disable 649
|
||||
|
||||
namespace Zenject.Asteroids
|
||||
{
|
||||
public class TilingBackground : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
float _speed;
|
||||
|
||||
Vector2 _offset;
|
||||
Renderer _renderer;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
_renderer = GetComponent<Renderer>();
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
_offset.y += _speed * Time.deltaTime;
|
||||
_renderer.material.mainTextureOffset = _offset;
|
||||
}
|
||||
}
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d72ecc6be0485ff4f96c39e24aea61f3
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
Reference in New Issue
Block a user