fixed cheat menu

This commit is contained in:
dddushesss 2022-01-27 13:57:37 +03:00
parent f222ed4bec
commit 7e09b90397
14 changed files with 53 additions and 37 deletions

View File

@ -1,4 +1,5 @@
using System; using System;
using System.Collections.Generic;
using System.Linq; using System.Linq;
using HexFiled; using HexFiled;
using Items; using Items;
@ -16,12 +17,14 @@ public class CheatMenu : MonoBehaviour
[SerializeField] private GameObject gridPrefab; [SerializeField] private GameObject gridPrefab;
private Unit _player; private Unit _player;
private Data.Data _data; private Data.Data _data;
private GameObject ItemsPrefab; private GameObject _itemsPrefab;
private List<GameObject> _buttons;
public void SetPlayerNData(Unit player, Data.Data data) public void SetPlayerNData(Unit player, Data.Data data)
{ {
_buttons = new List<GameObject>();
_player = player; _player = player;
ItemsPrefab = new GameObject("CheatedItems"); _itemsPrefab = new GameObject("CheatedItems");
showButton.onClick.AddListener(() => scrollRect.SetActive(!scrollRect.activeSelf)); showButton.onClick.AddListener(() => scrollRect.SetActive(!scrollRect.activeSelf));
_data = data; _data = data;
@ -34,6 +37,7 @@ public class CheatMenu : MonoBehaviour
{ {
var itemGridGo = Instantiate(gridPrefab, grid.transform); var itemGridGo = Instantiate(gridPrefab, grid.transform);
_buttons.Add(itemGridGo);
var itemGrid = itemGridGo.GetComponentInChildren<GridLayoutGroup>(); var itemGrid = itemGridGo.GetComponentInChildren<GridLayoutGroup>();
itemGridGo.GetComponentInChildren<TMP_Text>().text = "Items"; itemGridGo.GetComponentInChildren<TMP_Text>().text = "Items";
_data.ItemsData.ItemInfos.ForEach(x => _data.ItemsData.ItemInfos.ForEach(x =>
@ -43,12 +47,13 @@ public class CheatMenu : MonoBehaviour
var cell = HexManager.UnitCurrentCell[_player.Color].cell.GetListNeighbours() var cell = HexManager.UnitCurrentCell[_player.Color].cell.GetListNeighbours()
.First(hexCell => hexCell != null); .First(hexCell => hexCell != null);
x.Item.Spawn(cell, ItemsPrefab, ItemFabric.itemIcon[x.Item.Type]); x.Item.Spawn(cell, _itemsPrefab, ItemFabric.itemIcon[x.Item.Type]);
scrollRect.SetActive(false); scrollRect.SetActive(false);
}, "Spawn " + x.Item.name, itemGrid.gameObject); }, "Spawn " + x.Item.name, itemGrid.gameObject);
}); });
var playerGridGO = Instantiate(gridPrefab, grid.transform); var playerGridGO = Instantiate(gridPrefab, grid.transform);
_buttons.Add(playerGridGO);
var playerGrid = playerGridGO.GetComponentInChildren<GridLayoutGroup>(); var playerGrid = playerGridGO.GetComponentInChildren<GridLayoutGroup>();
playerGridGO.GetComponentInChildren<TMP_Text>().text = "Player"; playerGridGO.GetComponentInChildren<TMP_Text>().text = "Player";
AddButton(() => AddButton(() =>
@ -56,7 +61,8 @@ public class CheatMenu : MonoBehaviour
_player.UnitView.OnHit.Invoke(_player.Data.maxHP); _player.UnitView.OnHit.Invoke(_player.Data.maxHP);
scrollRect.SetActive(false); scrollRect.SetActive(false);
}, "Kill Player", playerGrid.gameObject); }, "Kill Player", playerGrid.gameObject);
AddButton(() => scrollRect.SetActive(false), "CLOSE", grid);
_buttons.Add(AddButton(() => scrollRect.SetActive(false), "CLOSE", grid).gameObject);
} }
private Button AddButton(Action onClickAction, string buttonText, GameObject parent) private Button AddButton(Action onClickAction, string buttonText, GameObject parent)
@ -66,4 +72,11 @@ public class CheatMenu : MonoBehaviour
button.GetComponentInChildren<TMP_Text>().text = buttonText; button.GetComponentInChildren<TMP_Text>().text = buttonText;
return button; return button;
} }
public void OnPlayerDeath()
{
showButton.onClick.RemoveAllListeners();
scrollRect.SetActive(false);
_buttons.ForEach(Destroy);
}
} }

View File

@ -354,7 +354,7 @@ RectTransform:
m_AnchorMin: {x: 0, y: 0} m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 1, y: 1} m_AnchorMax: {x: 1, y: 1}
m_AnchoredPosition: {x: 0, y: 0} m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 979.82007, y: 1820.0002} m_SizeDelta: {x: 0, y: 0}
m_Pivot: {x: 0.5, y: 0.5} m_Pivot: {x: 0.5, y: 0.5}
--- !u!222 &838699094943604228 --- !u!222 &838699094943604228
CanvasRenderer: CanvasRenderer:
@ -1268,9 +1268,9 @@ RectTransform:
m_RootOrder: 0 m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0} m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0} m_AnchorMax: {x: 1, y: 1}
m_AnchoredPosition: {x: 540, y: 960} m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 1080, y: 1920} m_SizeDelta: {x: 0, y: 0}
m_Pivot: {x: 0.5, y: 0.5} m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &4936557783008875079 --- !u!114 &4936557783008875079
MonoBehaviour: MonoBehaviour:
@ -1400,10 +1400,10 @@ RectTransform:
m_Father: {fileID: 838699096359249966} m_Father: {fileID: 838699096359249966}
m_RootOrder: 0 m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0.5, y: 0.5} m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0.5, y: 0.5} m_AnchorMax: {x: 1, y: 1}
m_AnchoredPosition: {x: 0, y: 0} m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 100, y: 100} m_SizeDelta: {x: 0, y: 0}
m_Pivot: {x: 0.5, y: 0.5} m_Pivot: {x: 0.5, y: 0.5}
--- !u!1 &7241771076334068699 --- !u!1 &7241771076334068699
GameObject: GameObject:

View File

@ -31,6 +31,7 @@ public class AdsMob : MonoBehaviour
{ {
buttonExit.onClick.RemoveAllListeners(); buttonExit.onClick.RemoveAllListeners();
SceneManager.LoadScene(0); SceneManager.LoadScene(0);
Time.timeScale = 1f;
}); });
// //
} }
@ -50,7 +51,7 @@ public class AdsMob : MonoBehaviour
{ {
var player = _player; var player = _player;
player.spawnPos = player.spawnPos =
HexManager.CellByColor[UnitColor.GREY][Random.Range(0, HexManager.CellByColor[UnitColor.GREY].Count - 1)] HexManager.CellByColor[UnitColor.Grey][Random.Range(0, HexManager.CellByColor[UnitColor.Grey].Count - 1)]
.coordinates; .coordinates;
_factory.Spawn(player); _factory.Spawn(player);
@ -81,14 +82,14 @@ public class AdsMob : MonoBehaviour
public void Respawn(GameObject player) public void Respawn(GameObject player)
{ {
List<HexCell> cells = new List<HexCell>(); List<HexCell> cells = new List<HexCell>();
cells.AddRange(HexManager.CellByColor[UnitColor.GREY]); cells.AddRange(HexManager.CellByColor[UnitColor.Grey]);
// for (int i = 0; i < cells.Count; i++) // for (int i = 0; i < cells.Count; i++)
// { // {
// } // }
foreach (var cell in cells) foreach (var cell in cells)
{ {
if (cell.Color == UnitColor.GREY) if (cell.Color == UnitColor.Grey)
{ {
var randomCell = Random.Range(0, cells.Count); var randomCell = Random.Range(0, cells.Count);
Vector3 respawnPosition = cells[randomCell].transform.position; Vector3 respawnPosition = cells[randomCell].transform.position;

View File

@ -41,10 +41,10 @@ namespace DefaultNamespace.AI
currentPath.Clear(); currentPath.Clear();
} }
private void InitAgent(GameObject unit) private void InitAgent(Unit unit)
{ {
AIManager.Instance.AddAgent(this); AIManager.Instance.AddAgent(this);
HexManager.agents.Add(unit, this); HexManager.agents.Add(unit.Instance, this);
OnAgentInited?.Invoke(this); OnAgentInited?.Invoke(this);
} }

View File

@ -23,7 +23,7 @@ namespace Controller
new MusicController(); new MusicController();
new VFXController(); new VFXController();
MusicController.Instance.SetMusicData(data.MusicData); MusicController.Instance.SetMusicData(data.MusicData);
Time.timeScale = 1f;
var paintedController = new PaintedController(); var paintedController = new PaintedController();

View File

@ -41,7 +41,7 @@ namespace HexFiled
private void Awake() private void Awake()
{ {
_renderer = GetComponent<MeshRenderer>(); _renderer = GetComponent<MeshRenderer>();
_color = UnitColor.GREY; _color = UnitColor.Grey;
if (!HexManager.CellByColor.ContainsKey(_color)) if (!HexManager.CellByColor.ContainsKey(_color))
{ {
HexManager.CellByColor.Add(_color, new List<HexCell>(){this}); HexManager.CellByColor.Add(_color, new List<HexCell>(){this});
@ -90,7 +90,7 @@ namespace HexFiled
_color = color; _color = color;
HexManager.CellByColor[_color].Add(this); HexManager.CellByColor[_color].Add(this);
if(color == UnitColor.GREY) return; if(color == UnitColor.Grey) return;
var vfx = VFXController.Instance.PlayEffect(HexGrid.Colors[color].VFXCellCapturePrefab, transform.position + new Vector3(0,0.1f,0)); var vfx = VFXController.Instance.PlayEffect(HexGrid.Colors[color].VFXCellCapturePrefab, transform.position + new Vector3(0,0.1f,0));
MusicController.Instance.AddAudioSource(vfx); MusicController.Instance.AddAudioSource(vfx);

View File

@ -65,7 +65,7 @@ namespace HexFiled
position.z = z * (HexMetrics.outerRadius * 1.5f); position.z = z * (HexMetrics.outerRadius * 1.5f);
var cellGO = Object.Instantiate(_fieldData.cellPrefab); var cellGO = Object.Instantiate(_fieldData.cellPrefab);
HexCell cell = _cells[i] = cellGO.GetComponent<HexCell>(); HexCell cell = _cells[i] = cellGO.GetComponent<HexCell>();
cell.PaintHex(UnitColor.GREY); cell.PaintHex(UnitColor.Grey);
cell.transform.SetParent(_baseGameObject.transform, false); cell.transform.SetParent(_baseGameObject.transform, false);
cell.transform.localPosition = position; cell.transform.localPosition = position;
cell.coordinates = HexCoordinates.FromOffsetCoordinates(x, z); cell.coordinates = HexCoordinates.FromOffsetCoordinates(x, z);

View File

@ -19,7 +19,7 @@ namespace HexFiled
public void PaintOnDeath(Unit unit) public void PaintOnDeath(Unit unit)
{ {
HexManager.PaintHexList(HexManager.CellByColor[unit.Color], UnitColor.GREY); HexManager.PaintHexList(HexManager.CellByColor[unit.Color], UnitColor.Grey);
// #if UNITY_EDITOR // #if UNITY_EDITOR
// //
// //
@ -66,7 +66,7 @@ namespace HexFiled
}); });
} }
if (item.Value.Count >= 2 && item.Key != UnitColor.GREY && item.Key != cell.Color) if (item.Value.Count >= 2 && item.Key != UnitColor.Grey && item.Key != cell.Color)
{ {
item.Value.ForEach(neighbour => item.Value.ForEach(neighbour =>
{ {
@ -77,7 +77,7 @@ namespace HexFiled
var (hasPath, field) = HasPath(neighbour, HexManager.UnitCurrentCell[neighbour.Color].cell); var (hasPath, field) = HasPath(neighbour, HexManager.UnitCurrentCell[neighbour.Color].cell);
if (!hasPath) if (!hasPath)
{ {
field.ForEach(x => x.PaintHex(UnitColor.GREY)); field.ForEach(x => x.PaintHex(UnitColor.Grey));
} }
}); });

View File

@ -2,10 +2,10 @@
{ {
public enum UnitColor public enum UnitColor
{ {
GREEN, Green,
RED, Red,
GREY, Grey,
YELLOW, Yellow,
BLUE Blue
} }
} }

View File

@ -37,7 +37,7 @@ namespace Items
public void UpdateCellToOpenList(HexCell cell) public void UpdateCellToOpenList(HexCell cell)
{ {
if (cell.Color != UnitColor.GREY) if (cell.Color != UnitColor.Grey)
{ {
_openList.Add(cell); _openList.Add(cell);
} }

View File

@ -23,7 +23,7 @@ namespace Units
private AnimLength _animLength; private AnimLength _animLength;
private HexCell _cell; private HexCell _cell;
private HexGrid _hexGrid; private HexGrid _hexGrid;
public event Action<GameObject> OnPlayerSpawned; public event Action<Unit> OnPlayerSpawned;
private Animator _animator; private Animator _animator;
private UnitView _unitView; private UnitView _unitView;
private bool _isBusy; private bool _isBusy;
@ -111,7 +111,7 @@ namespace Units
{ {
DoTransit(direction); DoTransit(direction);
} }
else if (_cell.GetNeighbor(direction).Color != UnitColor.GREY) else if (_cell.GetNeighbor(direction).Color != UnitColor.Grey)
{ {
if (_mana - _hexGrid.HexHardCaptureCost <= 0) return; if (_mana - _hexGrid.HexHardCaptureCost <= 0) return;
_isHardToCapture = true; _isHardToCapture = true;
@ -210,7 +210,7 @@ namespace Units
BarCanvas.transform.position + _camera.transform.rotation * Vector3.back, BarCanvas.transform.position + _camera.transform.rotation * Vector3.back,
_camera.transform.rotation * Vector3.up); _camera.transform.rotation * Vector3.up);
_isBusy = false; _isBusy = false;
OnPlayerSpawned?.Invoke(_instance); OnPlayerSpawned?.Invoke(this);
} }
} }

View File

@ -54,13 +54,14 @@ namespace Chars
_uiController.PlayerInventoryView); _uiController.PlayerInventoryView);
_controllers.Add(playerControl); _controllers.Add(playerControl);
}; };
_uiController.CheatMenu.SetPlayerNData(player, _data);
player.OnPlayerSpawned += unit => _uiController.CheatMenu.SetPlayerNData(unit, _data);
player.OnDeath += unit1 => _controllers.Remove(playerControl); player.OnDeath += unit1 => _controllers.Remove(playerControl);
player.OnDeath += u => playerControl.Dispose(); player.OnDeath += u => playerControl.Dispose();
player.OnPlayerSpawned += cameraControl.InitCameraControl; player.OnPlayerSpawned += unit => cameraControl.InitCameraControl(unit.Instance);
player.OnDeath += unit => _uiController.CheatMenu.OnPlayerDeath();
player.OnDeath += p => _uiController.AdsMob.ShowCanvas(unitInfo, this); player.OnDeath += p => _uiController.AdsMob.ShowCanvas(unitInfo, this);
player.OnDeath += _paintedController.PaintOnDeath; player.OnDeath += _paintedController.PaintOnDeath;
player.Spawn(unitInfo.spawnPos); player.Spawn(unitInfo.spawnPos);

View File

@ -67,7 +67,7 @@ PlayerSettings:
preserveFramebufferAlpha: 0 preserveFramebufferAlpha: 0
disableDepthAndStencilBuffers: 0 disableDepthAndStencilBuffers: 0
androidStartInFullscreen: 1 androidStartInFullscreen: 1
androidRenderOutsideSafeArea: 1 androidRenderOutsideSafeArea: 0
androidUseSwappy: 1 androidUseSwappy: 1
androidBlitType: 0 androidBlitType: 0
defaultIsNativeResolution: 1 defaultIsNativeResolution: 1

File diff suppressed because one or more lines are too long