Items #3
@ -22,5 +22,16 @@ MonoBehaviour:
|
||||
type: 3}
|
||||
CoordinatesCanvas: {fileID: 4726489279989878083, guid: f31e0880dd078104bb31dc0fd7ef9f19,
|
||||
type: 3}
|
||||
HexMeshPrefab: {fileID: 2988988380115025501, guid: efd47cbd22ddfee4aa2b1391914116fc,
|
||||
type: 3}
|
||||
DefaultTexture: {fileID: 0}
|
||||
colors:
|
||||
- _unitColor: 0
|
||||
_texture: {fileID: 2800000, guid: 0298dfcb0756f534a9a125d510461c7a, type: 3}
|
||||
_vfxPreab: {fileID: 8021195855904498788, guid: 2f6d0540c8fd7bb46b356ff86962379c,
|
||||
type: 3}
|
||||
- _unitColor: 1
|
||||
_texture: {fileID: 2800000, guid: 3b75368df991b164583e8cede390e24e, type: 3}
|
||||
_vfxPreab: {fileID: 442387583353148024, guid: 53959bc898e9a644daad0282881d596a,
|
||||
type: 3}
|
||||
- _unitColor: 2
|
||||
_texture: {fileID: 2800000, guid: 983242f4b4db7a841af48234cf0021b8, type: 3}
|
||||
_vfxPreab: {fileID: 0}
|
||||
|
@ -19,5 +19,7 @@ MonoBehaviour:
|
||||
type: 3}
|
||||
joystickView: {fileID: 4385872142190176059, guid: 4df6913b39f4979429158c344680d83f,
|
||||
type: 3}
|
||||
Tick: 0.5
|
||||
hexTexture: {fileID: 2800000, guid: 0298dfcb0756f534a9a125d510461c7a, type: 3}
|
||||
vfxPrefab: {fileID: 8021195855904498788, guid: 2f6d0540c8fd7bb46b356ff86962379c,
|
||||
type: 3}
|
||||
color: 0
|
||||
|
@ -11,6 +11,7 @@ namespace Chars
|
||||
{
|
||||
public float Move;
|
||||
}
|
||||
|
||||
public class Player : IUnit
|
||||
{
|
||||
private HexCoordinates spawnPos;
|
||||
@ -25,9 +26,11 @@ namespace Chars
|
||||
private Animator _animator;
|
||||
private PlayerView _playerView;
|
||||
private bool _isMoving;
|
||||
private GameObject _vfxPrefab;
|
||||
private UnitColor _color;
|
||||
private static readonly int Moving = Animator.StringToHash("isMoving");
|
||||
private static readonly int Move1 = Animator.StringToHash("Move");
|
||||
private float _tick = 0.8f;
|
||||
|
||||
public bool IsMoving => _isMoving;
|
||||
public GameObject PlayerInstance => _instance;
|
||||
|
||||
@ -37,14 +40,13 @@ namespace Chars
|
||||
prefab = playerData.playerPrefab;
|
||||
_isAlive = false;
|
||||
_hexGrid = hexGrid;
|
||||
_texture = playerData.hexTexture;
|
||||
_isMoving = false;
|
||||
_color = playerData.color;
|
||||
}
|
||||
|
||||
|
||||
public void Move(HexDirection direction)
|
||||
{
|
||||
_tick = Time.time;
|
||||
if (_cell.GetNeighbor(direction))
|
||||
{
|
||||
_isMoving = true;
|
||||
@ -55,21 +57,19 @@ namespace Chars
|
||||
_playerView.OnStep += () =>
|
||||
{
|
||||
_isMoving = false;
|
||||
_cell.PaintHex(_texture);
|
||||
_tick = Time.time - _tick;
|
||||
_animator.SetBool(Moving, _isMoving);
|
||||
_cell.PaintHex(_color);
|
||||
|
||||
_animator.SetBool(Moving, _isMoving);
|
||||
};
|
||||
|
||||
_instance.transform.DOMove(_cell.transform.position, _animLength.Move);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private void SetAnimLength()
|
||||
{
|
||||
AnimationClip[] clips = _animator.runtimeAnimatorController.animationClips;
|
||||
foreach(var clip in clips)
|
||||
foreach (var clip in clips)
|
||||
{
|
||||
_animLength.Move = clip.name switch
|
||||
{
|
||||
@ -84,10 +84,10 @@ namespace Chars
|
||||
if (!_isAlive)
|
||||
{
|
||||
_cell = _hexGrid.GetCellFromCoord(spawnPos);
|
||||
_cell.PaintHex(_texture);
|
||||
_cell.PaintHex(_color);
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
_cell.GetNeighbor((HexDirection)i).PaintHex(_texture);
|
||||
_cell.GetNeighbor((HexDirection)i).PaintHex(_color);
|
||||
}
|
||||
|
||||
_instance = Object.Instantiate(prefab, _cell.transform.parent);
|
||||
|
@ -1,4 +1,5 @@
|
||||
using HexFiled;
|
||||
using System.Collections.Generic;
|
||||
using HexFiled;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
@ -17,5 +18,6 @@ namespace Runtime.Data
|
||||
public TMP_Text cellLabelPrefab;
|
||||
public GameObject CoordinatesCanvas;
|
||||
public Texture DefaultTexture;
|
||||
public List<CellColor> colors;
|
||||
}
|
||||
}
|
@ -10,6 +10,6 @@ namespace Data
|
||||
public HexCoordinates spawnPos;
|
||||
public GameObject playerPrefab;
|
||||
public PlayerControlView joystickView;
|
||||
public Texture hexTexture;
|
||||
public UnitColor color;
|
||||
}
|
||||
}
|
22
Assets/Scripts/HexFiled/CellColor.cs
Normal file
22
Assets/Scripts/HexFiled/CellColor.cs
Normal file
@ -0,0 +1,22 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace HexFiled
|
||||
{
|
||||
[Serializable]
|
||||
public struct CellColor
|
||||
{
|
||||
[SerializeField] private UnitColor _unitColor;
|
||||
[SerializeField] private Texture _texture;
|
||||
[SerializeField] private GameObject _vfxPrefab;
|
||||
|
||||
public UnitColor UnitColor => _unitColor;
|
||||
public Texture Texture => _texture;
|
||||
public GameObject VFXPrefab => _vfxPrefab;
|
||||
|
||||
public bool Equals(CellColor obj)
|
||||
{
|
||||
return obj._unitColor == _unitColor;
|
||||
}
|
||||
}
|
||||
}
|
3
Assets/Scripts/HexFiled/CellColor.cs.meta
Normal file
3
Assets/Scripts/HexFiled/CellColor.cs.meta
Normal file
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 154669d65ce642ef881c9655fda24558
|
||||
timeCreated: 1640030907
|
@ -1,33 +1,54 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace HexFiled
|
||||
{
|
||||
public class HexCell : MonoBehaviour
|
||||
{
|
||||
public class HexCell : MonoBehaviour
|
||||
{
|
||||
public HexCoordinates coordinates;
|
||||
public Action<HexCell> onHexPainted;
|
||||
|
||||
public HexCoordinates coordinates;
|
||||
public Color color;
|
||||
public Action<HexCell> OnHexPainted;
|
||||
[SerializeField] private HexCell[] neighbors;
|
||||
private UnitColor _color;
|
||||
private MeshRenderer _renderer;
|
||||
private Dictionary<UnitColor, CellColor> _cellColor;
|
||||
|
||||
[SerializeField] private HexCell[] neighbors;
|
||||
private static readonly int Player = Shader.PropertyToID("player");
|
||||
private void Awake()
|
||||
{
|
||||
_renderer = GetComponent<MeshRenderer>();
|
||||
PaintHex(UnitColor.GREY);
|
||||
}
|
||||
|
||||
public HexCell GetNeighbor(HexDirection direction)
|
||||
{
|
||||
return neighbors[(int)direction];
|
||||
}
|
||||
public void SetDictionary(Dictionary<UnitColor, CellColor> colors)
|
||||
{
|
||||
_cellColor = colors;
|
||||
}
|
||||
|
||||
public void SetNeighbor(HexDirection direction, HexCell cell)
|
||||
{
|
||||
neighbors[(int)direction] = cell;
|
||||
cell.neighbors[(int)direction.Opposite()] = this;
|
||||
}
|
||||
public HexCell GetNeighbor(HexDirection direction)
|
||||
{
|
||||
return neighbors[(int)direction];
|
||||
}
|
||||
|
||||
public void PaintHex(Texture texture)
|
||||
{
|
||||
gameObject.GetComponent<MeshRenderer>().material.mainTexture = texture;
|
||||
OnHexPainted?.Invoke(this);
|
||||
}
|
||||
}
|
||||
public void SetNeighbor(HexDirection direction, HexCell cell)
|
||||
{
|
||||
neighbors[(int)direction] = cell;
|
||||
cell.neighbors[(int)direction.Opposite()] = this;
|
||||
}
|
||||
|
||||
public void PaintHex(UnitColor color)
|
||||
{
|
||||
if (color == _color) return;
|
||||
if(color == UnitColor.GREY)
|
||||
{
|
||||
_renderer.material.mainTexture = _cellColor[color].Texture;
|
||||
_color = color;
|
||||
return;
|
||||
}
|
||||
_renderer.material.mainTexture = _cellColor[color].Texture;
|
||||
onHexPainted?.Invoke(this);
|
||||
_color = color;
|
||||
Instantiate(_cellColor[color].VFXPrefab, transform);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Runtime.Controller;
|
||||
using Runtime.Data;
|
||||
using TMPro;
|
||||
@ -11,31 +12,30 @@ namespace HexFiled
|
||||
{
|
||||
private int _width;
|
||||
private int _height;
|
||||
private Color _defaultColor = Color.white;
|
||||
private Color _touchedColor = Color.magenta;
|
||||
private GameObject _cellPrefab;
|
||||
private TMP_Text _cellLabelPrefab;
|
||||
private Camera _camera;
|
||||
private HexCell[] _cells;
|
||||
private Canvas _gridCanvas;
|
||||
private GameObject _baseGameObject;
|
||||
public Action<HexCell> OnHexPainted;
|
||||
public Action OnGridLoaded;
|
||||
private Dictionary<UnitColor, CellColor> _colors;
|
||||
|
||||
public HexGrid(FieldData fieldData)
|
||||
{
|
||||
_width = fieldData.width;
|
||||
_height = fieldData.height;
|
||||
_defaultColor = fieldData.defaultColor;
|
||||
_touchedColor = fieldData.touchedColor;
|
||||
_cellPrefab = fieldData.cellPrefab;
|
||||
_cellLabelPrefab = fieldData.cellLabelPrefab;
|
||||
_camera = Camera.main;
|
||||
_baseGameObject = new GameObject("HexGrid");
|
||||
_colors = new Dictionary<UnitColor, CellColor>(fieldData.colors.Count);
|
||||
foreach (var color in fieldData.colors)
|
||||
{
|
||||
_colors.Add(color.UnitColor, color);
|
||||
}
|
||||
|
||||
_gridCanvas = Object.Instantiate(fieldData.CoordinatesCanvas, _baseGameObject.transform)
|
||||
.GetComponent<Canvas>();
|
||||
|
||||
}
|
||||
|
||||
public HexCell GetCellFromCoord(HexCoordinates coordinates)
|
||||
@ -48,15 +48,6 @@ namespace HexFiled
|
||||
return _cells[i - 1];
|
||||
}
|
||||
|
||||
private void PaintHex(Color color, HexCoordinates coordinates)
|
||||
{
|
||||
int index = coordinates.X + coordinates.Z * _width + coordinates.Z / 2;
|
||||
HexCell cell = _cells[index];
|
||||
|
||||
cell.color = color;
|
||||
cell.gameObject.GetComponent<MeshRenderer>().material.color = color;
|
||||
OnHexPainted.Invoke(_cells[index]);
|
||||
}
|
||||
|
||||
void CreateCell(int x, int z, int i)
|
||||
{
|
||||
@ -66,36 +57,43 @@ namespace HexFiled
|
||||
position.z = z * (HexMetrics.outerRadius * 1.5f);
|
||||
var cellGO = Object.Instantiate(_cellPrefab);
|
||||
HexCell cell = _cells[i] = cellGO.GetComponent<HexCell>();
|
||||
cell.SetDictionary(_colors);
|
||||
cell.PaintHex(UnitColor.GREY);
|
||||
cell.transform.SetParent(_baseGameObject.transform, false);
|
||||
cell.transform.localPosition = position;
|
||||
cell.coordinates = HexCoordinates.FromOffsetCoordinates(x, z);
|
||||
cell.color = _defaultColor;
|
||||
cell.OnHexPainted += OnHexPainted;
|
||||
cell.onHexPainted += OnHexPainted;
|
||||
|
||||
if (x > 0) {
|
||||
if (x > 0)
|
||||
{
|
||||
cell.SetNeighbor(HexDirection.W, _cells[i - 1]);
|
||||
}
|
||||
|
||||
if (z > 0) {
|
||||
if ((z & 1) == 0) {
|
||||
if (z > 0)
|
||||
{
|
||||
if ((z & 1) == 0)
|
||||
{
|
||||
cell.SetNeighbor(HexDirection.SE, _cells[i - _width]);
|
||||
if (x > 0) {
|
||||
if (x > 0)
|
||||
{
|
||||
cell.SetNeighbor(HexDirection.SW, _cells[i - _width - 1]);
|
||||
}
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
cell.SetNeighbor(HexDirection.SW, _cells[i - _width]);
|
||||
if (x < _width - 1) {
|
||||
if (x < _width - 1)
|
||||
{
|
||||
cell.SetNeighbor(HexDirection.SE, _cells[i - _width + 1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
#if UNITY_EDITOR
|
||||
#if UNITY_EDITOR
|
||||
TMP_Text label = Object.Instantiate(_cellLabelPrefab, _gridCanvas.transform, false);
|
||||
label.rectTransform.anchoredPosition =
|
||||
new Vector2(position.x, position.z);
|
||||
label.text = cell.coordinates.ToStringOnSeparateLines();
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
public void Init()
|
||||
@ -113,6 +111,5 @@ namespace HexFiled
|
||||
// _hexMesh.Triangulate(_cells);
|
||||
OnGridLoaded.Invoke();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
9
Assets/Scripts/HexFiled/UnitColor.cs
Normal file
9
Assets/Scripts/HexFiled/UnitColor.cs
Normal file
@ -0,0 +1,9 @@
|
||||
namespace HexFiled
|
||||
{
|
||||
public enum UnitColor
|
||||
{
|
||||
GREEN,
|
||||
RED,
|
||||
GREY
|
||||
}
|
||||
}
|
3
Assets/Scripts/HexFiled/UnitColor.cs.meta
Normal file
3
Assets/Scripts/HexFiled/UnitColor.cs.meta
Normal file
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b3c5f2a8422b4c3b81178ae5cf8597b0
|
||||
timeCreated: 1640030929
|
@ -8,6 +8,7 @@ using UnityEngine.UI;
|
||||
public class FadeIn : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private float duration;
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
var back = GetComponent<Image>();
|
||||
|
14
Assets/Scripts/VFXController.cs
Normal file
14
Assets/Scripts/VFXController.cs
Normal file
@ -0,0 +1,14 @@
|
||||
using HexFiled;
|
||||
using UnityEngine;
|
||||
|
||||
namespace DefaultNamespace
|
||||
{
|
||||
public class VFXController
|
||||
{
|
||||
void HexCaptured(HexCell cell)
|
||||
{
|
||||
ParticleSystem system;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
3
Assets/Scripts/VFXController.cs.meta
Normal file
3
Assets/Scripts/VFXController.cs.meta
Normal file
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e5124914ee2c478bb47f35353a0669fb
|
||||
timeCreated: 1640027806
|
Loading…
x
Reference in New Issue
Block a user