spawn, adsmob, ai, respawn

This commit is contained in:
dddushesss 2022-01-09 00:37:09 +03:00
parent b197f6d8b2
commit 722b8da02b
27 changed files with 62555 additions and 128 deletions

View File

@ -103,10 +103,10 @@ MonoBehaviour:
VFXGameObject: {fileID: 2957420090356197408, guid: 5d1244f7b80cadd428a70173a01ce889,
type: 3}
modifiedDamage: 0
damage: 15
speed: 10
damage: 100
speed: 1
disnatce: 6
reloadTime: 6
reloadTime: 1
shots: 4
shotSound: {fileID: 8300000, guid: 9ea918c6c23577f4e885a8490d2f2046, type: 3}
hitSound: {fileID: 8300000, guid: 6c42231c18643dc4d9d8f8d15bc4735b, type: 3}
@ -120,7 +120,7 @@ CapsuleCollider:
m_Material: {fileID: 0}
m_IsTrigger: 0
m_Enabled: 1
m_Radius: 31.906784
m_Height: 63.813572
m_Radius: 30
m_Height: 60
m_Direction: 1
m_Center: {x: 0, y: 0, z: 0}

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 77902a8be59fd3e47a2cc059b107eb71
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

File diff suppressed because it is too large Load Diff

View File

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

File diff suppressed because it is too large Load Diff

View File

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

File diff suppressed because it is too large Load Diff

View File

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

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: a0921af500122a94e8cbcc72874ff141
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

File diff suppressed because it is too large Load Diff

View File

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

File diff suppressed because it is too large Load Diff

View File

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

View File

@ -20,7 +20,7 @@ MonoBehaviour:
spawnablePrefab: {fileID: 4774919592469818776, guid: 0dbed8f974ba44a42af9d8fcae504ce0,
type: 3}
values:
spawnChance: 0.2
spawnChance: 1
- prefab: {fileID: 3197816592181874056, guid: 2704c4f795b0d7748a3e3fa53be4d893,
type: 3}
isInstantUse: 1
@ -28,7 +28,7 @@ MonoBehaviour:
icon: {fileID: 21300000, guid: caf8bc0311dd2fc4ca1528a82a063754, type: 3}
spawnablePrefab: {fileID: 0}
values: 0300000064000000
spawnChance: 0.516
spawnChance: 0
- prefab: {fileID: 8639522512577941448, guid: 7b6a7f64e52da514d88aa97ad8f863df,
type: 3}
isInstantUse: 1
@ -36,6 +36,6 @@ MonoBehaviour:
icon: {fileID: 21300000, guid: 35be128594dcdce48b5d8e5317b38ed9, type: 3}
spawnablePrefab: {fileID: 0}
values: 0a0000001e000000
spawnChance: 0.797
spawnChance: 0
fromTimeSpawn: 3
toTimeSpawn: 10

View File

@ -19,4 +19,4 @@ MonoBehaviour:
type: 3}
inventoryView: {fileID: 1527356263590969195, guid: ff3bc3b17ddefd14eb798b22cf0a854f,
type: 3}
_add: {fileID: 7017227080055577099, guid: 1328a0e1e252d60408278772275bf560, type: 3}
adsMob: {fileID: 7017227080055577099, guid: 1328a0e1e252d60408278772275bf560, type: 3}

View File

@ -37,8 +37,8 @@ MonoBehaviour:
inventoryCapacity: 4
- isPlayer: 0
spawnPos:
x: 3
z: 10
x: -1
z: 42
unitPrefa: {fileID: 742650227762578155, guid: 97b4a76c55741764e880b63d6e1514a9,
type: 3}
color: 0

View File

@ -267,7 +267,7 @@ Camera:
far clip plane: 1000
field of view: 60
orthographic: 1
orthographic size: 12
orthographic size: 15
m_Depth: -1
m_CullingMask:
serializedVersion: 2

View File

@ -35,15 +35,13 @@ public class AdsMob : MonoBehaviour
private void HandleUser(object sender, Reward reward)
{
//ExtraLife life;
int lifeCount = ExtraLife.lifeCount;
//ShowAd();
lifeCount += 1;
ExtraLife.lifeCount = lifeCount;
ExtraLife life = FindObjectOfType<ExtraLife>();
life.health += 1;
//Respawn(life.gameObject);
_player.Spawn();
_player.Spawn(HexManager.CellByColor[UnitColor.GREY][Random.Range(0, HexManager.CellByColor[UnitColor.GREY].Count - 1)].coordinates);
}
@ -87,8 +85,7 @@ public class AdsMob : MonoBehaviour
}
}
}
private void OnDisable() {
_ad.OnUserEarnedReward -= HandleUser;

View File

@ -40,6 +40,7 @@ namespace AI
_agents = new List<AIAgent>();
_pathToPatrol = new Dictionary<AIAgent, Queue<HexCell>>();
Instance = this;
HexManager.agents = new Dictionary<GameObject, AIAgent>();
}
public void AddAgent(AIAgent agent)

View File

@ -1,9 +1,11 @@
using System;
using System.Collections.Generic;
using System.Timers;
using AI;
using CamControl;
using Chars;
using DefaultNamespace;
using DefaultNamespace.AI;
using GameUI;
using HexFiled;
using Items;
@ -20,6 +22,8 @@ namespace Controller
public GameInit(Controllers controllers, Data.Data data)
{
AIManager aiManager = new AIManager();
controllers.Add(aiManager);
new GameObject("Timer").AddComponent<TimerHelper>();
var hexGrid = new HexGrid(data.FieldData);
@ -62,10 +66,13 @@ namespace Controller
var enemyController = new EnemyController(unit, enemy);
controllers.Add(enemyController);
units.Add(enemy);
AIAgent agent = new AIAgent(unit, enemy);
aiManager.AddAgent(agent);
enemy.onPlayerSpawned += agent.InitAgent;
}
});
var unitFactory = new UnitFactory(units);
var unitFactory = new UnitFactory(units, hexGrid);
hexGrid.OnGridLoaded += unitFactory.Spawn;
@ -74,6 +81,7 @@ namespace Controller
hexGrid.OnHexPainted += paintedController.SetHexColors;
hexGrid.OnHexPainted += itemFabric.UpdateCellToOpenList;
hexGrid.OnHexPainted += paintedController.CheckDeath;
}
private List<Type> SetUpItems()

View File

@ -11,12 +11,12 @@ namespace Data
[SerializeField] private List<GameObject> _objectsToSpawn;
[SerializeField] private PlayerControlView joystickView;
[SerializeField] private PlayerInventoryView inventoryView;
[SerializeField] private AdsMob _add;
[SerializeField] private AdsMob adsMob;
public List<GameObject> ObjectsToSpawn => _objectsToSpawn;
public PlayerControlView PlayerControlView => joystickView;
public PlayerInventoryView InventoryView => inventoryView;
public AdsMob Add => _add;
public AdsMob AdsMob => adsMob;
}
}

View File

@ -28,7 +28,7 @@ namespace GameUI
_playerControlView = Object.Instantiate(_uiData.PlayerControlView, canvasGroup.transform);
_inventoryView = Object.Instantiate(_uiData.InventoryView, canvasGroup.transform);
_adsMob = Object.Instantiate(_uiData.Add, canvasGroup.transform);
_adsMob = Object.Instantiate(_uiData.AdsMob, canvasGroup.transform);
//_add.enabled = false;
_uiData.ObjectsToSpawn.ForEach(x => Object.Instantiate(x, canvasGroup.transform));

View File

@ -1,8 +1,11 @@
using System;
using System.Collections.Generic;
using AI;
using DefaultNamespace;
using DefaultNamespace.AI;
using Units;
using UnityEngine;
using Random = UnityEngine.Random;
namespace HexFiled
{
@ -21,7 +24,7 @@ namespace HexFiled
var tmp = end;
do
{
end = tmp.Neighbors[Random.Range(0, 5)];
end = tmp.Neighbors[Random.Range(0, 6)];
itters++;
} while (end == null && itters < 5);
@ -33,80 +36,18 @@ namespace HexFiled
}
}
public static void PaintHexList(List<HexCell> field, UnitColor color)
{
List<Action<UnitColor>> actions = new List<Action<UnitColor>>();
field.ForEach(x => actions.Add(x.PaintHex));
TimerHelper.Instance.StartTimer(actions, 0.05f, color);
}
// public static ( bool hasPath, List<HexCell> field ) HasPath(UnitColor color)
// {
// var start = UnitCurrentCell[color];
// var end = start;
// List<HexCell> neighboursCells = new List<HexCell>();
// while (end.Color == color)
// {
// neighboursCells.AddRange(end.Neighbors);
// neighboursCells.ForEach(cell =>
// {
// if (cell.Color != color)
// {
// end = cell;
// }
// });
// }
//
// List<HexCell> closedList = new List<HexCell>();
// HexCell currentCell = start;
//
// Stack<HexCell> stackIterators = new Stack<HexCell>();
// stackIterators.Push(currentCell);
//
// closedList.Add(currentCell);
//
//
// while (stackIterators.Count >= 0)
// {
// if (currentCell == end)
// return (true, null);
//
// List<HexCell> openList = new List<HexCell>();
//
// foreach (var neighbour in currentCell.GetListNeighbours())
// {
// if (neighbour == null)
// {
// return (true, null);
// }
//
//
// if (closedList.Contains(neighbour) || neighbour.Color != start.Color) continue;
// openList.Add(neighbour);
// if (neighbour.GetListNeighbours().Contains(end))
// {
// return (true, null);
// }
// }
//
//
// if (openList.Count > 0)
// {
// currentCell = openList[Random.Range(0, openList.Count - 1)];
// closedList.Add(currentCell);
// stackIterators.Push(currentCell);
// }
// else
// {
// if (stackIterators.Count == 0)
// {
// return (false, closedList);
// }
//
// currentCell = stackIterators.Pop();
// }
//
// if (currentCell.GetListNeighbours().Contains(end))
// {
// return (true, null);
// }
// }
//
// return (false, closedList);
// }
}
}

View File

@ -1,7 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using DefaultNamespace;
using Units;
using Random = UnityEngine.Random;
@ -19,20 +17,17 @@ namespace HexFiled
public void CheckDeath(HexCell cell)
{
foreach (var cells in HexManager.UnitCurrentCell)
foreach (var cells in HexManager.UnitCurrentCell.Where(cells => HexManager.CellByColor[cells.Key].Count < 2 || (cells.Value.cell == cell && cells.Value.unit.Color != cell.Color)))
{
if (cells.Value.cell == cell && cells.Value.unit.Color != cell.Color)
{
cells.Value.unit.Death();
}
cells.Value.unit.Death();
}
}
public void SetHexColors(HexCell cell)
{
_cell = cell;
List<HexCell> cells = new List<HexCell>();
var cells = new List<HexCell>();
for (int i = 0; i < 6; i++)
for (var i = 0; i < 6; i++)
{
cells.Add(cell.GetNeighbor((HexDirection)i));
}
@ -48,7 +43,9 @@ namespace HexFiled
{
if (x != null && x.Color != cell.Color)
{
PaintHexList(Round(x, null), cell.Color);
var path = Round(x, null);
if(!path.hasPath)
HexManager.PaintHexList(path.field, cell.Color);
}
});
}
@ -62,24 +59,15 @@ namespace HexFiled
where !path.hasPath
select path)
{
PaintHexList(path, UnitColor.GREY);
if(!path.hasPath)
HexManager.PaintHexList(path.field, UnitColor.GREY);
}
}
}
}
private void PaintHexList((bool hasPath, List<HexCell> field) path, UnitColor color)
{
if (path.hasPath) return;
List<Action<UnitColor>> actions = new List<Action<UnitColor>>();
path.field.ForEach(x => actions.Add(x.PaintHex));
TimerHelper.Instance.StartTimer(actions, 0.05f, color);
}
private Dictionary<UnitColor, List<HexCell>> DifferentHexByColor(List<HexCell> cellsList)
{

View File

@ -3,7 +3,6 @@ using System.Collections.Generic;
using System.IO;
using DefaultNamespace.Weapons;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;
using Weapons;

View File

@ -47,6 +47,8 @@ namespace Units
public Action<Unit> OnDeath;
public BarCanvas BarCanvas => _barCanvas;
public UnitInfo Data => _data;
public Unit(UnitInfo unitData, Weapon weapon, HexGrid hexGrid)
{
_weapon = weapon;
@ -82,7 +84,8 @@ namespace Units
public void Move(HexDirection direction)
{
if (!_cell.GetNeighbor(direction) || _isBusy) return;
if (!_cell.GetNeighbor(direction) || _isBusy || _cell.GetNeighbor(direction).Color != UnitColor.GREY &&
HexManager.UnitCurrentCell[_cell.GetNeighbor(direction).Color].cell == _cell.GetNeighbor(direction)) return;
_unitView.StopHardCapture();
if (_cell.GetNeighbor(direction).Color == _data.color)
{
@ -142,11 +145,11 @@ namespace Units
}
}
public void Spawn()
public void Spawn(HexCoordinates hexCoordinates)
{
if (!_isAlive)
{
_cell = _hexGrid.GetCellFromCoord(_data.spawnPos);
_cell = _hexGrid.GetCellFromCoord(hexCoordinates);
_cell.PaintHex(_data.color);
_inventory = new List<Item>();
for (int i = 0; i < 6; i++)
@ -166,7 +169,7 @@ namespace Units
_instance = Object.Instantiate(_data.unitPrefa, _cell.transform.parent);
_instance.transform.localPosition = _cell.transform.localPosition;
onPlayerSpawned?.Invoke(_instance);
_isAlive = true;
_animator = _instance.GetComponent<Animator>();
_unitView = _instance.GetComponent<UnitView>();
@ -178,6 +181,7 @@ namespace Units
_mana = _data.maxMana;
_hp = _data.maxHP;
SetUpActions();
onPlayerSpawned?.Invoke(_instance);
}
}
@ -289,10 +293,13 @@ namespace Units
_unitView.OnAttack -= Attacking;
_unitView.OnHit -= Damage;
_isAlive = false;
HexManager.UnitCurrentCell.Remove(Color);
_animator.SetTrigger("Death");
OnDeath?.Invoke(this);
MusicController.Instance.PlayAudioClip(MusicController.Instance.MusicData.SfxMusic.Death, _instance);
MusicController.Instance.RemoveAudioSource(_instance);
HexManager.PaintHexList(HexManager.CellByColor[Color], UnitColor.GREY);
Object.Destroy(_instance);
}

View File

@ -1,4 +1,5 @@
using System.Collections.Generic;
using HexFiled;
using Units;
namespace Chars
@ -6,15 +7,17 @@ namespace Chars
public class UnitFactory
{
private List<Unit> _units;
public UnitFactory(List<Unit> units)
public UnitFactory(List<Unit> units, HexGrid grid)
{
_units = units;
}
public void Spawn()
{
_units.ForEach(x => x.Spawn());
_units.ForEach(x => x.Spawn(x.Data.spawnPos));
}
}
}