diff --git a/Assets/ExternalDependencyManager.meta b/Assets/ExternalDependencyManager.meta new file mode 100644 index 00000000..5a266cf2 --- /dev/null +++ b/Assets/ExternalDependencyManager.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 84d861162f8d1ad49a87400ae042a3c6 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/ExternalDependencyManager/Editor.meta b/Assets/ExternalDependencyManager/Editor.meta new file mode 100644 index 00000000..2f9c5229 --- /dev/null +++ b/Assets/ExternalDependencyManager/Editor.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 02c5b57c6632922478f72d4aefe978d7 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/ExternalDependencyManager/Editor/1.2.167.meta b/Assets/ExternalDependencyManager/Editor/1.2.167.meta new file mode 100644 index 00000000..c3e6a36a --- /dev/null +++ b/Assets/ExternalDependencyManager/Editor/1.2.167.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: d025c6b2800003849830ede3e207eb4a +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Prefab/PauseMenu.prefab b/Assets/Prefab/PauseMenu.prefab index e32fb3ab..7dfa2e85 100644 --- a/Assets/Prefab/PauseMenu.prefab +++ b/Assets/Prefab/PauseMenu.prefab @@ -32,7 +32,7 @@ RectTransform: m_Children: - {fileID: 3205969477031557256} m_Father: {fileID: 7535381195931813741} - m_RootOrder: 0 + m_RootOrder: 1 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0.5, y: 0.5} m_AnchorMax: {x: 0.5, y: 0.5} @@ -151,7 +151,7 @@ RectTransform: m_LocalScale: {x: 1, y: 1, z: 1} m_Children: [] m_Father: {fileID: 7535381195931813741} - m_RootOrder: 3 + m_RootOrder: 4 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0.5, y: 0.5} m_AnchorMax: {x: 0.5, y: 0.5} @@ -316,7 +316,7 @@ Canvas: m_OverrideSorting: 0 m_OverridePixelPerfect: 0 m_SortingBucketNormalizedSize: 0 - m_AdditionalShaderChannelsFlag: 0 + m_AdditionalShaderChannelsFlag: 25 m_SortingLayerID: 0 m_SortingOrder: 1 m_TargetDisplay: 0 @@ -409,7 +409,7 @@ RectTransform: m_Children: - {fileID: 3258995203638363845} m_Father: {fileID: 7535381195931813741} - m_RootOrder: 1 + m_RootOrder: 2 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0.5, y: 0.5} m_AnchorMax: {x: 0.5, y: 0.5} @@ -530,7 +530,7 @@ RectTransform: m_Children: - {fileID: 216367779017151113} m_Father: {fileID: 7535381195931813741} - m_RootOrder: 2 + m_RootOrder: 3 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0.5, y: 0.5} m_AnchorMax: {x: 0.5, y: 0.5} @@ -1011,6 +1011,81 @@ MonoBehaviour: m_hasFontAssetChanged: 0 m_baseMaterial: {fileID: 0} m_maskOffset: {x: 0, y: 0, z: 0, w: 0} +--- !u!1 &5443873379656075396 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 5855551985023584753} + - component: {fileID: 3505714345849204007} + - component: {fileID: 6130419704230661871} + m_Layer: 5 + m_Name: Back + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!224 &5855551985023584753 +RectTransform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 5443873379656075396} + m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: [] + m_Father: {fileID: 7535381195931813741} + m_RootOrder: 0 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} + m_AnchorMin: {x: 0, y: 0} + m_AnchorMax: {x: 1, y: 1} + m_AnchoredPosition: {x: 0, y: 0} + m_SizeDelta: {x: 0, y: 1670} + m_Pivot: {x: 0.5, y: 0.5} +--- !u!222 &3505714345849204007 +CanvasRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 5443873379656075396} + m_CullTransparentMesh: 1 +--- !u!114 &6130419704230661871 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 5443873379656075396} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: fe87c0e1cc204ed48ad3b37840f39efc, type: 3} + m_Name: + m_EditorClassIdentifier: + m_Material: {fileID: 0} + m_Color: {r: 0, g: 0, b: 0, a: 0.14117648} + m_RaycastTarget: 1 + m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0} + m_Maskable: 1 + m_OnCullStateChanged: + m_PersistentCalls: + m_Calls: [] + m_Sprite: {fileID: 0} + m_Type: 0 + m_PreserveAspect: 0 + m_FillCenter: 1 + m_FillMethod: 4 + m_FillAmount: 1 + m_FillClockwise: 1 + m_FillOrigin: 0 + m_UseSpriteMesh: 0 + m_PixelsPerUnitMultiplier: 1 --- !u!1 &6038652171774885714 GameObject: m_ObjectHideFlags: 0 @@ -1040,6 +1115,7 @@ RectTransform: m_LocalPosition: {x: 0, y: 0, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} m_Children: + - {fileID: 5855551985023584753} - {fileID: 5093098141183363274} - {fileID: 5296751824509684347} - {fileID: 5296751824694007057} diff --git a/Assets/Scripts/Controller/GameInit.cs b/Assets/Scripts/Controller/GameInit.cs index 27e5f75a..b4e87339 100644 --- a/Assets/Scripts/Controller/GameInit.cs +++ b/Assets/Scripts/Controller/GameInit.cs @@ -51,7 +51,11 @@ namespace Controller var unitFactory = new UnitFactory(units); hexGrid.OnGridLoaded += unitFactory.Spawn; - + + var paintedController = new PaintedController(); + + hexGrid.OnHexPainted += paintedController.SetHexColors; + } diff --git a/Assets/Scripts/HexFiled/HexCell.cs b/Assets/Scripts/HexFiled/HexCell.cs index 6b31a579..3ac02e11 100644 --- a/Assets/Scripts/HexFiled/HexCell.cs +++ b/Assets/Scripts/HexFiled/HexCell.cs @@ -51,10 +51,10 @@ namespace HexFiled } _renderer.material.mainTexture = _cellColor[color].Texture; - onHexPainted?.Invoke(this); + _color = color; Instantiate(_cellColor[color].VFXPrefab, transform); - + onHexPainted?.Invoke(this); } } diff --git a/Assets/Scripts/HexFiled/HexGrid.cs b/Assets/Scripts/HexFiled/HexGrid.cs index c965e61f..3a8c861e 100644 --- a/Assets/Scripts/HexFiled/HexGrid.cs +++ b/Assets/Scripts/HexFiled/HexGrid.cs @@ -101,6 +101,7 @@ namespace HexFiled } } + #if UNITY_EDITOR TMP_Text label = Object.Instantiate(_cellLabelPrefab, _gridCanvas.transform, false); label.rectTransform.anchoredPosition = @@ -109,7 +110,8 @@ namespace HexFiled #endif } - public void Init() + + public void Init() { _cells = new HexCell[_height * _width]; diff --git a/Assets/Scripts/HexFiled/PaintedController.cs b/Assets/Scripts/HexFiled/PaintedController.cs new file mode 100644 index 00000000..812d04fd --- /dev/null +++ b/Assets/Scripts/HexFiled/PaintedController.cs @@ -0,0 +1,179 @@ +using System.Collections.Generic; +using UnityEngine; + +namespace HexFiled +{ + + public class PaintedController + { + public static Dictionary unitCurrentCell; + + private HexCell _cell; + + public PaintedController() + { + unitCurrentCell = new Dictionary(); + } + + public void SetHexColors(HexCell cell) + { + _cell = cell; + List cells = new List(); + + for(int i = 0 ; i < 6 ; i++) + { + cells.Add(cell.GetNeighbor((HexDirection)i)); + } + + var hexByColorDict = DifferentHexByColor(cells); + foreach (var item in hexByColorDict) + { + if(item.Value.Count > 0 && item.Key != UnitColor.GREY && item.Key != cell.Color ) + { + foreach(var cellNeighbour in item.Value) + { + if(unitCurrentCell.ContainsKey(item.Key)) + { + var path = HasPath(cellNeighbour, unitCurrentCell[item.Key]); + if(!path.hasPath) + { + path.field.ForEach(x => x.PaintHex(UnitColor.GREY)); + } + } + } + } + else if (item.Key == UnitColor.GREY) + { + + } + } + + } + + private Dictionary> DifferentHexByColor(List cellsList) + { + Dictionary> resultDict = new Dictionary>(); + cellsList.ForEach(cell => { + + if(cell != null && resultDict.ContainsKey(cell.Color)) + { + resultDict[cell.Color].Add(cell); + } + else if(cell != null) + { + resultDict.Add(cell.Color, new List{cell}); + } + + } ); + return resultDict; + } + + private ( bool hasPath , List field ) HasPath(HexCell start, HexCell end) + { + List closedList = new List(); + HexCell currentCell = start; + + Stack stackIteators = new Stack(); + stackIteators.Push(currentCell); + + closedList.Add(currentCell); + + + + while(stackIteators.Count >= 0 ) + { + if(currentCell == end) + return ( true, closedList); + + List openList = new List(); + for(int i = 0 ; i < 6; i++) + { + HexCell neighbour = currentCell.GetNeighbor( (HexDirection)i ); + if(!closedList.Contains(neighbour) && neighbour.Color == end.Color) + { + openList.Add(neighbour); + } + } + + if(openList.Count > 0) + { + currentCell = openList[Random.Range(0, openList.Count -1 )]; + closedList.Add(currentCell); + stackIteators.Push(currentCell); + } + else + { + if (stackIteators.Count == 0) + { + return ( false, closedList); + } + currentCell = stackIteators.Pop(); + } + } + return ( false, closedList); + + } + } +} +/* + if(start == end) + return true; + + if(currentCell.Cell.coordinates.Y < end.coordinates.Y) + { + var cellNeighbour = currentCell.Cell.GetNeighbor(HexDirection.W); + if (!closedList.Contains(cellNeighbour) && cellNeighbour.Color == end.Color) + { + stackIteators.Push(currentCell); + + currentCell = new HexIterator(cellNeighbour, true, currentCell.Cell); + + closedList.Add(currentCell.Cell); + continue; + } + } + else if(currentCell.Cell.coordinates.Y > end.coordinates.Y) + { + var cellNeighbour = currentCell.Cell.GetNeighbor(HexDirection.E); + if(!closedList.Contains(cellNeighbour) && cellNeighbour.Color == end.Color) + { + stackIteators.Push(currentCell); + currentCell = new HexIterator(cellNeighbour, true, currentCell.Cell); + + closedList.Add(currentCell.Cell); + continue; + } + } + // Z + + if(currentCell.Cell.coordinates.Z > end.coordinates.Z) + { + var cellNeighbour = currentCell.Cell.GetNeighbor(HexDirection.SE); + if (!closedList.Contains(cellNeighbour) && cellNeighbour.Color == end.Color) + { + stackIteators.Push(currentCell); + + currentCell = new HexIterator(cellNeighbour, true, currentCell.Cell); + + closedList.Add(currentCell.Cell); + continue; + } + } + else if(currentCell.Cell.coordinates.Z < end.coordinates.Z) + { + var cellNeighbour = currentCell.Cell.GetNeighbor(HexDirection.NW); + if(!closedList.Contains(cellNeighbour) && cellNeighbour.Color == end.Color) + { + stackIteators.Push(currentCell); + currentCell = new HexIterator(cellNeighbour, true, currentCell.Cell); + + closedList.Add(currentCell.Cell); + continue; + } + } + + currentCell = stackIteators.Pop(); + + if(stackIteators.Count == 0) + return false; + */ \ No newline at end of file diff --git a/Assets/Scripts/HexFiled/PaintedController.cs.meta b/Assets/Scripts/HexFiled/PaintedController.cs.meta new file mode 100644 index 00000000..460d35fc --- /dev/null +++ b/Assets/Scripts/HexFiled/PaintedController.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: b502c0a16ec749f44829b362121008b6 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Units/Unit.cs b/Assets/Scripts/Units/Unit.cs index 0d02615e..73cfab4a 100644 --- a/Assets/Scripts/Units/Unit.cs +++ b/Assets/Scripts/Units/Unit.cs @@ -88,6 +88,7 @@ namespace Units private void CaptureHex() { _cell.PaintHex(_data.color); + PaintedController.unitCurrentCell[_data.color] =_cell; } private void SetAnimLength() @@ -120,6 +121,10 @@ namespace Units _cell.GetNeighbor((HexDirection)i)?.PaintHex(_data.color); } + // + PaintedController.unitCurrentCell.Add(_data.color, _cell); + // + _instance = Object.Instantiate(_data.unitPrefa, _cell.transform.parent); _instance.transform.localPosition = _cell.transform.localPosition; onPlayerSpawned?.Invoke(_instance); diff --git a/Assets/Scripts/Units/Views/UnitView.cs b/Assets/Scripts/Units/Views/UnitView.cs index c1fa77ba..9de5a17c 100644 --- a/Assets/Scripts/Units/Views/UnitView.cs +++ b/Assets/Scripts/Units/Views/UnitView.cs @@ -50,7 +50,7 @@ public class UnitView : MonoBehaviour { captureBar.gameObject.SetActive(true); _sequence = DOTween.Sequence(); - _sequence.Append(captureBar.DOFillAmount(1f, 3f).OnComplete(() => + _sequence.Append(captureBar.DOFillAmount(1f, 0f).OnComplete(() => { _capureHex.Invoke(); captureBar.DOFillAmount(0f, 0f).SetEase(Ease.Linear);