Not Conflicts

This commit is contained in:
Uamgl 2022-03-15 18:06:00 +02:00
commit 7ad754b56e
6 changed files with 288 additions and 11 deletions

View File

@ -20,10 +20,10 @@ public class CheatMenu : MonoBehaviour
private GameObject _itemsPrefab;
private List<GameObject> _buttons;
public void SetPlayerNData(Unit player, Data.Data data)
public void SetPlayerNData(Data.Data data)
{
_buttons = new List<GameObject>();
_player = player;
_player = (Unit)(HexManager.UnitCurrentCell.FirstOrDefault(unit => ((Unit)unit.Value.unit).IsPlayer).Value.unit);
_itemsPrefab = new GameObject("CheatedItems");
showButton.onClick.AddListener(() => scrollRect.SetActive(!scrollRect.activeSelf));
@ -56,11 +56,17 @@ public class CheatMenu : MonoBehaviour
_buttons.Add(playerGridGO);
var playerGrid = playerGridGO.GetComponentInChildren<GridLayoutGroup>();
playerGridGO.GetComponentInChildren<TMP_Text>().text = "Player";
AddButton(() =>
for (var i = 0; i < HexManager.UnitCurrentCell.Count; i++)
{
_player.BaseView.OnHit.Invoke(_player.UnitData.maxHP);
scrollRect.SetActive(false);
}, "Kill Player", playerGrid.gameObject);
var unit = HexManager.UnitCurrentCell.ElementAt(i).Value.unit;
AddButton(() =>
{
unit.BaseView.OnHit.Invoke(unit.maxHP);
scrollRect.SetActive(false);
}, $"Kill {unit.Color} unit", playerGrid.gameObject);
}
_buttons.Add(AddButton(() => scrollRect.SetActive(false), "CLOSE", grid).gameObject);
}
@ -79,4 +85,10 @@ public class CheatMenu : MonoBehaviour
scrollRect.SetActive(false);
_buttons.ForEach(Destroy);
}
public void OnEnemyDeath()
{
_buttons.ForEach(Destroy);
AddAllButtons();
}
}

View File

@ -0,0 +1,94 @@
using System;
using System.Collections.Generic;
using System.Linq;
using HexFiled;
using Items;
using TMPro;
using Units;
using UnityEngine;
using UnityEngine.UI;
public class CheatMenu : MonoBehaviour
{
[SerializeField] private Button showButton;
[SerializeField] private GameObject scrollRect;
[SerializeField] private GameObject grid;
[SerializeField] private Button buttonPrefab;
[SerializeField] private GameObject gridPrefab;
private Unit _player;
private Data.Data _data;
private GameObject _itemsPrefab;
private List<GameObject> _buttons;
public void SetPlayerNData(Data.Data data)
{
_buttons = new List<GameObject>();
_player = (Unit)(HexManager.UnitCurrentCell.FirstOrDefault(unit => ((Unit)unit.Value.unit).IsPlayer).Value.unit);
_itemsPrefab = new GameObject("CheatedItems");
showButton.onClick.AddListener(() => scrollRect.SetActive(!scrollRect.activeSelf));
_data = data;
AddAllButtons();
scrollRect.SetActive(false);
}
private void AddAllButtons()
{
var itemGridGo = Instantiate(gridPrefab, grid.transform);
_buttons.Add(itemGridGo);
var itemGrid = itemGridGo.GetComponentInChildren<GridLayoutGroup>();
itemGridGo.GetComponentInChildren<TMP_Text>().text = "Items";
_data.ItemsData.ItemInfos.ForEach(x =>
{
AddButton(() =>
{
var cell = HexManager.UnitCurrentCell[_player.Color].cell.GetListNeighbours()
.First(hexCell => hexCell != null);
x.Item.Spawn(cell, _itemsPrefab, ItemFabric.itemIcon[x.Item.Type]);
scrollRect.SetActive(false);
}, "Spawn " + x.Item.name, itemGrid.gameObject);
});
var playerGridGO = Instantiate(gridPrefab, grid.transform);
_buttons.Add(playerGridGO);
var playerGrid = playerGridGO.GetComponentInChildren<GridLayoutGroup>();
playerGridGO.GetComponentInChildren<TMP_Text>().text = "Player";
for (var i = 0; i < HexManager.UnitCurrentCell.Count; i++)
{
var unit = HexManager.UnitCurrentCell.ElementAt(i).Value.unit;
AddButton(() =>
{
unit.UnitView.OnHit.Invoke(unit.maxHP);
scrollRect.SetActive(false);
}, $"Kill {unit.Color} unit", playerGrid.gameObject);
}
_buttons.Add(AddButton(() => scrollRect.SetActive(false), "CLOSE", grid).gameObject);
}
private Button AddButton(Action onClickAction, string buttonText, GameObject parent)
{
var button = Instantiate(buttonPrefab, parent.transform);
button.onClick.AddListener(onClickAction.Invoke);
button.GetComponentInChildren<TMP_Text>().text = buttonText;
return button;
}
public void OnPlayerDeath()
{
showButton.onClick.RemoveAllListeners();
scrollRect.SetActive(false);
_buttons.ForEach(Destroy);
}
public void OnEnemyDeath()
{
_buttons.ForEach(Destroy);
AddAllButtons();
}
}

View File

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

View File

@ -1,8 +1,10 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using CamControl;
using Controller;
using Data;
using DefaultNamespace;
using DefaultNamespace.AI;
using GameUI;
using HexFiled;
@ -35,6 +37,7 @@ namespace Chars
public void SpawnList(List<UnitInfo> units)
{
units.ForEach(x => Spawn(x));
_uiController.CheatMenu.SetPlayerNData(_data);
}
public void Spawn(UnitInfo unitInfo, HexCell spawnHex = null)
@ -66,16 +69,16 @@ namespace Chars
_uiController.PlayerInventoryView);
_controllers.Add(playerControl);
};
player.OnSpawned += unit => _uiController.CheatMenu.SetPlayerNData((Unit)unit, _data);
player.OnDeath += unit1 => _controllers.Remove(playerControl);
player.OnDeath += u => playerControl.Dispose();
player.OnSpawned += unit => cameraControl.InitCameraControl(unit.Instance);
player.OnDeath += unit => _uiController.CheatMenu.OnPlayerDeath();
player.OnDeath += p => _uiController.AdsMob.ShowCanvas(unitInfo, this);
player.Spawn(spawnPos.coordinates, spawnPos);
spawnPos.isSpawnPos = false;
player.BaseView.SetBar(_data.UnitData.PlayerBarCanvas, _data.UnitData.AttackAimCanvas);
@ -86,6 +89,9 @@ namespace Chars
var enemy = new Unit(unitInfo,
_data.WeaponsData.WeaponsList[Random.Range(0, _data.WeaponsData.WeaponsList.Count - 1)], _hexGrid, _data);
enemy.OnDeath += unit => RandomSpawn(unitInfo);
if (unitInfo.isAI)
{
AIAgent agent = new AIAgent(enemy);
@ -93,11 +99,29 @@ namespace Chars
enemy.OnDeath += x => { _controllers.Remove(agent); };
}
enemy.OnDeath += x => _uiController.CheatMenu.OnEnemyDeath();
enemy.Spawn(spawnPos.coordinates, spawnPos);
spawnPos.isSpawnPos = false;
enemy.BaseView.SetBar(_data.UnitData.BotBarCanvas, _data.UnitData.AttackAimCanvas);
}
}
private void RandomSpawn(UnitInfo info)
{
TimerHelper.Instance.StartTimer(() =>
{
var cellToSpawn = HexManager.CellByColor[UnitColor.Grey].Where(cell => cell != null &&
cell.GetListNeighbours().TrueForAll(neighbour => neighbour == null || neighbour.Color == UnitColor.Grey)).ToList();
if (cellToSpawn.Count == 0)
{
RandomSpawn(info);
return;
}
Spawn(info, cellToSpawn[Random.Range(0, cellToSpawn.Count - 1)]);
_uiController.CheatMenu.OnEnemyDeath();
}, 1f);
}
}
}

View File

@ -0,0 +1,133 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using CamControl;
using Controller;
using Data;
using DefaultNamespace;
using DefaultNamespace.AI;
using GameUI;
using HexFiled;
using Runtime.Controller;
using Units;
using UnityEngine;
using Weapons;
namespace Chars
{
public class UnitFactory
{
private readonly HexGrid _hexGrid;
private readonly Weapon _chosenWeapon;
private readonly Data.Data _data;
private readonly Controllers _controllers;
private readonly UIController _uiController;
public Unit Player { get; private set; }
public UnitFactory(HexGrid grid, Data.Data data, UIController uiController, PaintedController paintedController,
Controllers controllers)
{
_hexGrid = grid;
_data = data;
_chosenWeapon = data.ChosenWeapon;
_uiController = uiController;
_controllers = controllers;
}
public void SpawnList(List<UnitInfo> units)
{
units.ForEach(x => Spawn(x));
_uiController.CheatMenu.SetPlayerNData(_data);
}
public void Spawn(UnitInfo unitInfo, HexCell spawnHex = null)
{
HexCell spawnPos;
if (spawnHex == null)
{
spawnPos = _hexGrid.spawnPoses.ToList().FirstOrDefault(x => x.isSpawnPos);
if (spawnPos == null)
return;
}
else
{
spawnPos = spawnHex;
}
if (unitInfo.isPlayer)
{
var player = new Unit(unitInfo, _chosenWeapon, _hexGrid, _data);
PlayerControl playerControl = null;
CameraControl cameraControl =
new CameraControl(Camera.main, _data.CameraData);
_controllers.Add(cameraControl);
player.OnSpawned += p =>
{
playerControl = new PlayerControl(player, _uiController.PlayerControlView,
_uiController.PlayerInventoryView);
_controllers.Add(playerControl);
};
player.OnDeath += unit1 => _controllers.Remove(playerControl);
player.OnDeath += u => playerControl.Dispose();
player.OnSpawned += unit => cameraControl.InitCameraControl(unit.Instance);
player.OnDeath += unit => _uiController.CheatMenu.OnPlayerDeath();
player.OnDeath += p => _uiController.AdsMob.ShowCanvas(unitInfo, this);
player.Spawn(spawnPos.coordinates, spawnPos);
spawnPos.isSpawnPos = false;
player.BaseView.SetBar(_data.UnitData.PlayerBarCanvas, _data.UnitData.AttackAimCanvas);
Player = player;
}
else
{
var enemy = new Unit(unitInfo,
_data.WeaponsData.WeaponsList[Random.Range(0, _data.WeaponsData.WeaponsList.Count - 1)], _hexGrid, _data);
enemy.OnDeath += unit => RandomSpawn(unitInfo);
if (unitInfo.isAI)
{
AIAgent agent = new AIAgent(enemy);
enemy.OnSpawned += x => _controllers.Add(agent);
enemy.OnDeath += x => { _controllers.Remove(agent); };
}
enemy.OnDeath += x => _uiController.CheatMenu.OnEnemyDeath();
enemy.Spawn(spawnPos.coordinates, spawnPos);
spawnPos.isSpawnPos = false;
<<<<<<< HEAD
enemy.BaseView.SetBar(_data.UnitData.BotBarCanvas, _data.UnitData.AttackAimCanvas);
=======
enemy.UnitView.SetBar(_data.UnitData.BotBarCanvas, _data.UnitData.AttackAimCanvas);
>>>>>>> abaf11d23750589a662b4fd2daa471f53d864cf7
}
}
private void RandomSpawn(UnitInfo info)
{
TimerHelper.Instance.StartTimer(() =>
{
var cellToSpawn = HexManager.CellByColor[UnitColor.Grey].Where(cell => cell != null &&
cell.GetListNeighbours().TrueForAll(neighbour => neighbour == null || neighbour.Color == UnitColor.Grey)).ToList();
if (cellToSpawn.Count == 0)
{
RandomSpawn(info);
return;
}
Spawn(info, cellToSpawn[Random.Range(0, cellToSpawn.Count - 1)]);
_uiController.CheatMenu.OnEnemyDeath();
}, 1f);
}
}
}

View File

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 83e52267c67416347a2e7e372e8ae0e4
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant: