Implement UpgradeManager

This commit is contained in:
Denis-Cosmin Nutiu 2019-06-22 17:37:26 +03:00
parent 70f2ab0eb2
commit ae09d98a3b
16 changed files with 247 additions and 17 deletions

View file

@ -0,0 +1,121 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &4585348266300200282
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 4585348266300200286}
- component: {fileID: 4585348266300200285}
- component: {fileID: 4585348266300200284}
- component: {fileID: 4585348266300200283}
m_Layer: 0
m_Name: TestUpgrade
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &4585348266300200286
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4585348266300200282}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!61 &4585348266300200285
BoxCollider2D:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4585348266300200282}
m_Enabled: 1
m_Density: 1
m_Material: {fileID: 0}
m_IsTrigger: 1
m_UsedByEffector: 0
m_UsedByComposite: 0
m_Offset: {x: 0, y: 0}
m_SpriteTilingProperty:
border: {x: 0, y: 0, z: 0, w: 0}
pivot: {x: 0, y: 0}
oldSize: {x: 1, y: 1}
newSize: {x: 1, y: 1}
adaptiveTilingThreshold: 0.5
drawMode: 0
adaptiveTiling: 0
m_AutoTiling: 0
serializedVersion: 2
m_Size: {x: 1, y: 1}
m_EdgeRadius: 0
--- !u!212 &4585348266300200284
SpriteRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4585348266300200282}
m_Enabled: 1
m_CastShadows: 0
m_ReceiveShadows: 0
m_DynamicOccludee: 1
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
- {fileID: 10754, guid: 0000000000000000f000000000000000, type: 0}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
m_StaticBatchRoot: {fileID: 0}
m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_PreserveUVs: 0
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 0
m_SelectedEditorRenderState: 0
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 10
m_Sprite: {fileID: 21300000, guid: 753e29d30d8044605aede9853c9308c7, type: 3}
m_Color: {r: 0.0509078, g: 0.36098272, b: 0.9811321, a: 1}
m_FlipX: 0
m_FlipY: 0
m_DrawMode: 0
m_Size: {x: 1, y: 1}
m_AdaptiveModeThreshold: 0.5
m_SpriteTileMode: 0
m_WasSpriteAssigned: 1
m_MaskInteraction: 0
m_SpriteSortPoint: 0
--- !u!114 &4585348266300200283
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4585348266300200282}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: daf1c278fd544eae9246c4abe6bf611e, type: 3}
m_Name:
m_EditorClassIdentifier:

View file

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 2ea1eb2b6b05340a4a99948a6eb818b2
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -11,6 +11,7 @@ GameObject:
- component: {fileID: 158905820630581587}
- component: {fileID: 158905820630581586}
- component: {fileID: 158905820630581596}
- component: {fileID: 6316647355651322741}
m_Layer: 0
m_Name: GameManager
m_TagString: Untagged
@ -66,3 +67,15 @@ MonoBehaviour:
enemiesPrefab:
- {fileID: 4346602752014574748, guid: e719de70e335f4e49ae40cc6731309d4, type: 3}
- {fileID: 7795087027144463245, guid: fe8fb4e4a7e127648b306469b723d81e, type: 3}
--- !u!114 &6316647355651322741
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 158905820630581597}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: e64481d2e18e4b6ca4f22926a5061450, type: 3}
m_Name:
m_EditorClassIdentifier:

View file

@ -404,7 +404,7 @@ Transform:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 519420028}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 10.72334, y: -4.0430503, z: -10}
m_LocalPosition: {x: 10.75168, y: -4.0430503, z: -10}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
@ -562,6 +562,17 @@ PrefabInstance:
m_Modification:
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: 6316647355651322741, guid: fdaa7451ab31b477b930076bbc888bab,
type: 3}
propertyPath: upgradePrefabs.Array.size
value: 1
objectReference: {fileID: 0}
- target: {fileID: 6316647355651322741, guid: fdaa7451ab31b477b930076bbc888bab,
type: 3}
propertyPath: upgradePrefabs.Array.data[0]
value:
objectReference: {fileID: 4585348266300200282, guid: 2ea1eb2b6b05340a4a99948a6eb818b2,
type: 3}
- target: {fileID: 158905820630581597, guid: fdaa7451ab31b477b930076bbc888bab,
type: 3}
propertyPath: m_Name
@ -719,11 +730,6 @@ PrefabInstance:
m_Modification:
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: 7054975846833851214, guid: f064c0737a3e54f1fadc75fc09919760,
type: 3}
propertyPath: m_Name
value: Grid
objectReference: {fileID: 0}
- target: {fileID: 7054975846833851208, guid: f064c0737a3e54f1fadc75fc09919760,
type: 3}
propertyPath: m_LocalPosition.x
@ -779,6 +785,11 @@ PrefabInstance:
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 7054975846833851214, guid: f064c0737a3e54f1fadc75fc09919760,
type: 3}
propertyPath: m_Name
value: Grid
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: f064c0737a3e54f1fadc75fc09919760, type: 3}
--- !u!1001 &9082059503859367018

View file

@ -11,7 +11,8 @@ public class DumbEnemy : EnemyBase
protected new void FixedUpdate()
{
if (transform.position.x == Mathf.Floor(transform.position.x) && transform.position.y == Mathf.Floor(transform.position.y))
if (transform.position.x == Mathf.Floor(transform.position.x) &&
transform.position.y == Mathf.Floor(transform.position.y))
{
if (RandomChange())
{
@ -19,27 +20,26 @@ public class DumbEnemy : EnemyBase
}
else
{
Rigidbody2d.MovePosition(Rigidbody2d.position + Direction * Speed * Time.deltaTime);
Rigidbody2d.MovePosition(Rigidbody2d.position + Speed * Time.deltaTime * Direction);
}
}
else
{
Rigidbody2d.MovePosition(Rigidbody2d.position + Direction * Speed * Time.deltaTime);
Rigidbody2d.MovePosition(Rigidbody2d.position + Speed * Time.deltaTime * Direction);
}
}
private bool RandomChange()
{
System.Random random = new System.Random();
int randomNumber = random.Next(0, 100);
var random = new System.Random();
var randomNumber = random.Next(0, 100);
return randomNumber <= 25;
}
private void HandleChangeDirection()
{
DebugHelper.LogInfo("Direction randomly changed");
Direction = ChooseRandomExceptCertainDirection(Direction);
MoveToCenterOfTheCell();
Rigidbody2d.MovePosition(Rigidbody2d.position + Direction * Speed * Time.deltaTime);
Rigidbody2d.MovePosition(Rigidbody2d.position + Speed * Time.deltaTime * Direction);
}
}

View file

@ -8,7 +8,7 @@ namespace src.Helpers
{
public static T ChoseRandom<T>(this T[] arr)
{
var randomIndex = Mathf.FloorToInt(Random.Range(0, arr.Length));
var randomIndex = Random.Range(0, arr.Length);
return arr[randomIndex];
}
@ -17,7 +17,7 @@ namespace src.Helpers
T value;
do
{
var randomIndex = Mathf.FloorToInt(Random.Range(0, arr.Length));
var randomIndex = Random.Range(0, arr.Length);
value = arr[randomIndex];
} while (exceptValue.Equals(value));
@ -29,7 +29,7 @@ namespace src.Helpers
T value;
do
{
var randomIndex = Mathf.FloorToInt(Random.Range(0, arr.Length));
var randomIndex = Random.Range(0, arr.Length);
value = arr[randomIndex];
} while (exceptValue.Contains(value));

View file

@ -0,0 +1,10 @@
using UnityEngine;
namespace src.Interfaces
{
public interface IUpgrade
{
void PerformUpgrade();
void OnTriggerEnter2D(Collider2D other);
}
}

View file

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 527ddc9d1a334e739b995e82c8e96d10
timeCreated: 1561210723

View file

@ -6,6 +6,7 @@ namespace src.Managers
{
public static GameManager Instance;
private LevelManager _levelManager;
private UpgradeManager _upgradeManager;
public void Awake()
{
@ -22,10 +23,16 @@ namespace src.Managers
DontDestroyOnLoad(gameObject);
_levelManager = GetComponent<LevelManager>();
_upgradeManager = GetComponent<UpgradeManager>();
InitGame();
}
public UpgradeManager GetUpgradeManager()
{
return _upgradeManager;
}
private void InitGame()
{
_levelManager.InitLevel();

View file

@ -0,0 +1,16 @@
using src.Base;
using src.Helpers;
using UnityEngine;
namespace src.Managers
{
public class UpgradeManager : GameplayComponent
{
public GameObject[] upgradePrefabs;
public GameObject GetUpgradePrefab()
{
return upgradePrefabs.ChoseRandom();
}
}
}

View file

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: e64481d2e18e4b6ca4f22926a5061450
timeCreated: 1561211937

View file

@ -1,6 +1,7 @@
using src.Ammo;
using src.Base;
using src.Helpers;
using src.Interfaces;
using UnityEngine;
namespace src.Player

View file

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: ce5704d616e542aa9e6b98025b958d84
timeCreated: 1561212967

View file

@ -0,0 +1,23 @@
using src.Base;
using src.Helpers;
using src.Interfaces;
using UnityEngine;
namespace src.Upgrade
{
public class TestUpgrade : GameplayComponent, IUpgrade
{
public void PerformUpgrade()
{
DebugHelper.LogError("Test upgrade works.");
}
public void OnTriggerEnter2D(Collider2D other)
{
if (!other.CompareTag("Player")) return;
DebugHelper.LogWarning("TestUpgrade WORKS!");
Destroy(gameObject);
}
}
}

View file

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: daf1c278fd544eae9246c4abe6bf611e
timeCreated: 1561212975

View file

@ -1,7 +1,9 @@
using System;
using UnityEngine;
using src.Base;
using src.Helpers;
using src.Managers;
namespace src.Wall
{
@ -9,9 +11,15 @@ namespace src.Wall
{
private bool _spawnExit;
private bool _spawnUpgrade;
private UpgradeManager _upgradeManager;
public GameObject explosionPrefab;
public GameObject exitDoorPrefab;
private void Start()
{
_upgradeManager = GameManager.Instance.GetUpgradeManager();
}
public void SpawnsExit()
{
_spawnExit = true;
@ -38,7 +46,8 @@ namespace src.Wall
else if (_spawnUpgrade)
{
DebugHelper.LogInfo($"Destructible spawned upgrade {transform.position}");
// TODO: Get and instantiate upgrade from manager
var upgrade = _upgradeManager.GetUpgradePrefab();
Instantiate(upgrade, currentPosition, Quaternion.identity);
}
}