diff --git a/Assets/Resources/Data/FieldData.asset b/Assets/Resources/Data/FieldData.asset index 37c73b00..af40b2a7 100644 --- a/Assets/Resources/Data/FieldData.asset +++ b/Assets/Resources/Data/FieldData.asset @@ -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} diff --git a/Assets/Resources/Data/PlayerData.asset b/Assets/Resources/Data/PlayerData.asset index 1a06e80e..b3d3cada 100644 --- a/Assets/Resources/Data/PlayerData.asset +++ b/Assets/Resources/Data/PlayerData.asset @@ -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 diff --git a/Assets/Scripts/Chars/Player.cs b/Assets/Scripts/Chars/Player.cs index 371e6bf5..877f2094 100644 --- a/Assets/Scripts/Chars/Player.cs +++ b/Assets/Scripts/Chars/Player.cs @@ -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; + _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); diff --git a/Assets/Scripts/Data/FieldData.cs b/Assets/Scripts/Data/FieldData.cs index 7c79a0c9..bd7e0869 100644 --- a/Assets/Scripts/Data/FieldData.cs +++ b/Assets/Scripts/Data/FieldData.cs @@ -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 colors; } } \ No newline at end of file diff --git a/Assets/Scripts/Data/PlayerData.cs b/Assets/Scripts/Data/PlayerData.cs index a08d2fb7..29dbd603 100644 --- a/Assets/Scripts/Data/PlayerData.cs +++ b/Assets/Scripts/Data/PlayerData.cs @@ -10,6 +10,6 @@ namespace Data public HexCoordinates spawnPos; public GameObject playerPrefab; public PlayerControlView joystickView; - public Texture hexTexture; + public UnitColor color; } } \ No newline at end of file diff --git a/Assets/Scripts/HexFiled/CellColor.cs b/Assets/Scripts/HexFiled/CellColor.cs new file mode 100644 index 00000000..bedd2d8d --- /dev/null +++ b/Assets/Scripts/HexFiled/CellColor.cs @@ -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; + } + } +} \ No newline at end of file diff --git a/Assets/Scripts/HexFiled/CellColor.cs.meta b/Assets/Scripts/HexFiled/CellColor.cs.meta new file mode 100644 index 00000000..23be88fa --- /dev/null +++ b/Assets/Scripts/HexFiled/CellColor.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 154669d65ce642ef881c9655fda24558 +timeCreated: 1640030907 \ No newline at end of file diff --git a/Assets/Scripts/HexFiled/HexCell.cs b/Assets/Scripts/HexFiled/HexCell.cs index eb89b8f2..6d0ba16f 100644 --- a/Assets/Scripts/HexFiled/HexCell.cs +++ b/Assets/Scripts/HexFiled/HexCell.cs @@ -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 onHexPainted; - public HexCoordinates coordinates; - public Color color; - public Action OnHexPainted; + [SerializeField] private HexCell[] neighbors; + private UnitColor _color; + private MeshRenderer _renderer; + private Dictionary _cellColor; - [SerializeField] private HexCell[] neighbors; - private static readonly int Player = Shader.PropertyToID("player"); + private void Awake() + { + _renderer = GetComponent(); + PaintHex(UnitColor.GREY); + } - public HexCell GetNeighbor(HexDirection direction) - { - return neighbors[(int)direction]; - } + public void SetDictionary(Dictionary 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().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); + } + } +} \ No newline at end of file diff --git a/Assets/Scripts/HexFiled/HexGrid.cs b/Assets/Scripts/HexFiled/HexGrid.cs index d876a50b..0d78c9e6 100644 --- a/Assets/Scripts/HexFiled/HexGrid.cs +++ b/Assets/Scripts/HexFiled/HexGrid.cs @@ -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 OnHexPainted; public Action OnGridLoaded; + private Dictionary _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(fieldData.colors.Count); + foreach (var color in fieldData.colors) + { + _colors.Add(color.UnitColor, color); + } _gridCanvas = Object.Instantiate(fieldData.CoordinatesCanvas, _baseGameObject.transform) .GetComponent(); - } 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().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(); + 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; - - if (x > 0) { + cell.onHexPainted += OnHexPainted; + + 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(); } - } } \ No newline at end of file diff --git a/Assets/Scripts/HexFiled/UnitColor.cs b/Assets/Scripts/HexFiled/UnitColor.cs new file mode 100644 index 00000000..008a5133 --- /dev/null +++ b/Assets/Scripts/HexFiled/UnitColor.cs @@ -0,0 +1,9 @@ +namespace HexFiled +{ + public enum UnitColor + { + GREEN, + RED, + GREY + } +} \ No newline at end of file diff --git a/Assets/Scripts/HexFiled/UnitColor.cs.meta b/Assets/Scripts/HexFiled/UnitColor.cs.meta new file mode 100644 index 00000000..e4be2080 --- /dev/null +++ b/Assets/Scripts/HexFiled/UnitColor.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: b3c5f2a8422b4c3b81178ae5cf8597b0 +timeCreated: 1640030929 \ No newline at end of file diff --git a/Assets/Scripts/MainMenu/FadeIn.cs b/Assets/Scripts/MainMenu/FadeIn.cs index 5fa0d5e2..3ad491ae 100644 --- a/Assets/Scripts/MainMenu/FadeIn.cs +++ b/Assets/Scripts/MainMenu/FadeIn.cs @@ -8,6 +8,7 @@ using UnityEngine.UI; public class FadeIn : MonoBehaviour { [SerializeField] private float duration; + private void OnEnable() { var back = GetComponent(); diff --git a/Assets/Scripts/VFXController.cs b/Assets/Scripts/VFXController.cs new file mode 100644 index 00000000..29200172 --- /dev/null +++ b/Assets/Scripts/VFXController.cs @@ -0,0 +1,14 @@ +using HexFiled; +using UnityEngine; + +namespace DefaultNamespace +{ + public class VFXController + { + void HexCaptured(HexCell cell) + { + ParticleSystem system; + + } + } +} \ No newline at end of file diff --git a/Assets/Scripts/VFXController.cs.meta b/Assets/Scripts/VFXController.cs.meta new file mode 100644 index 00000000..6cf34c5e --- /dev/null +++ b/Assets/Scripts/VFXController.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: e5124914ee2c478bb47f35353a0669fb +timeCreated: 1640027806 \ No newline at end of file