fiexed rounding/cutting.

This commit is contained in:
dddushesss 2022-01-03 19:48:44 +03:00
parent def871faed
commit 38749a4a95
2 changed files with 184 additions and 120 deletions

View File

@ -7924,7 +7924,7 @@ RectTransform:
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: 319, y: -226}
m_AnchoredPosition: {x: 294, y: -126}
m_SizeDelta: {x: 482.9315, y: 577.5637}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!1 &92667329
@ -20077,10 +20077,10 @@ RectTransform:
m_Father: {fileID: 1844323541}
m_RootOrder: 2
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 1}
m_AnchorMax: {x: 0, y: 1}
m_AnchoredPosition: {x: 408.28363, y: -279.12}
m_SizeDelta: {x: 816.56726, y: 180}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 0, y: 180}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!1 &223373605
GameObject:
@ -21943,7 +21943,7 @@ RectTransform:
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0.427, y: 1}
m_AnchorMax: {x: 0, y: 0}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 0, y: 0}
m_Pivot: {x: 0.5, y: 0.5}
@ -22033,10 +22033,10 @@ RectTransform:
m_Father: {fileID: 1844323541}
m_RootOrder: 6
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 1}
m_AnchorMax: {x: 0, y: 1}
m_AnchoredPosition: {x: 408.28363, y: -657.36}
m_SizeDelta: {x: 816.56726, y: 180}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 0, y: 180}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!1 &323737875
GameObject:
@ -26924,10 +26924,10 @@ RectTransform:
m_Father: {fileID: 1844323541}
m_RootOrder: 3
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 1}
m_AnchorMax: {x: 0, y: 1}
m_AnchoredPosition: {x: 408.28363, y: -373.68}
m_SizeDelta: {x: 816.56726, y: 4}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 0, y: 4}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &329939466
MonoBehaviour:
@ -57570,7 +57570,7 @@ GameObject:
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 0
m_IsActive: 1
--- !u!224 &644244602
RectTransform:
m_ObjectHideFlags: 0
@ -57590,9 +57590,9 @@ RectTransform:
m_Father: {fileID: 2102651775}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 1}
m_AnchorMax: {x: 0, y: 1}
m_AnchoredPosition: {x: 270, y: -153.85}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 490, y: 130.7746}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &644244603
@ -74941,9 +74941,9 @@ RectTransform:
m_Father: {fileID: 1342282033}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0.5}
m_AnchorMax: {x: 0, y: 0.5}
m_AnchoredPosition: {x: -1797, y: -291}
m_AnchorMin: {x: 1, y: 0.5}
m_AnchorMax: {x: 1, y: 0.5}
m_AnchoredPosition: {x: 389, y: -85}
m_SizeDelta: {x: 761.9927, y: 761.9927}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &744371852
@ -80794,10 +80794,10 @@ RectTransform:
m_Father: {fileID: 1844323541}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 1}
m_AnchorMax: {x: 0, y: 1}
m_AnchoredPosition: {x: 408.28363, y: -90}
m_SizeDelta: {x: 816.56726, y: 180}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 0, y: 180}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!1 &831510121
GameObject:
@ -80831,10 +80831,10 @@ RectTransform:
m_Father: {fileID: 1844323541}
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 1}
m_AnchorMax: {x: 0, y: 1}
m_AnchoredPosition: {x: 408.28363, y: -184.56}
m_SizeDelta: {x: 816.56726, y: 4}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 0, y: 4}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &831510123
MonoBehaviour:
@ -81916,6 +81916,7 @@ MonoBehaviour:
type: 3}
grid: {fileID: 1361972682}
dataFilePath: ChosenWeapon.json
chosenWeapon: {fileID: 0}
--- !u!114 &936591823
MonoBehaviour:
m_ObjectHideFlags: 0
@ -88697,7 +88698,7 @@ GameObject:
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 0
m_IsActive: 1
--- !u!224 &1013893794
RectTransform:
m_ObjectHideFlags: 0
@ -88777,8 +88778,10 @@ MonoBehaviour:
musicOnSprite: {fileID: 21300000, guid: eb165af05aa2e4ab2bcad217611774b8, type: 3}
musicOffSprite: {fileID: 21300000, guid: b1f42bbbfffc44202b66381ab8b622ee, type: 3}
sfxImage: {fileID: 1844205148}
sfxOnSprite: {fileID: 21300000, guid: 901d64fc6ad9d44799c2ad0fd4f182d2, type: 3}
sfxOffSprite: {fileID: 21300000, guid: 78757b0623f3b4309b7cc69c4769ae37, type: 3}
sfxOnSprite: {fileID: -9015007665768789201, guid: 4121167a6423ec74381c7b130b40092b,
type: 3}
sfxOffSprite: {fileID: -8419751542767139993, guid: 4121167a6423ec74381c7b130b40092b,
type: 3}
--- !u!1 &1014179672
GameObject:
m_ObjectHideFlags: 0
@ -101175,10 +101178,10 @@ RectTransform:
m_Father: {fileID: 1844323541}
m_RootOrder: 4
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 1}
m_AnchorMax: {x: 0, y: 1}
m_AnchoredPosition: {x: 408.28363, y: -468.24}
m_SizeDelta: {x: 816.56726, y: 180}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 0, y: 180}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!1 &1151852833
GameObject:
@ -108557,7 +108560,7 @@ RectTransform:
m_RootOrder: 2
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 1}
m_AnchorMax: {x: 0, y: 0}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 100, y: 100}
m_Pivot: {x: 0.5, y: 0.5}
@ -109146,10 +109149,10 @@ RectTransform:
m_Father: {fileID: 1037253823}
m_RootOrder: 2
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 1}
m_AnchorMax: {x: 0, y: 1}
m_AnchoredPosition: {x: 549, y: -386}
m_SizeDelta: {x: -3240, y: 772}
m_AnchorMin: {x: 1, y: 0.5}
m_AnchorMax: {x: 1, y: 0.5}
m_AnchoredPosition: {x: -540, y: 439}
m_SizeDelta: {x: -1080, y: 873.5664}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!222 &1342282034
CanvasRenderer:
@ -133324,6 +133327,7 @@ GameObject:
- component: {fileID: 1547182935}
- component: {fileID: 1547182937}
- component: {fileID: 1547182936}
- component: {fileID: 1547182938}
m_Layer: 5
m_Name: Attack
m_TagString: Untagged
@ -133393,6 +133397,21 @@ CanvasRenderer:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1547182934}
m_CullTransparentMesh: 1
--- !u!114 &1547182938
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1547182934}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: a2920b048f18f5946b93c003a602952b, type: 3}
m_Name:
m_EditorClassIdentifier:
attackText: {fileID: 1033038899}
reloadText: {fileID: 985521934}
chosenWeaponDataPath: ChosenWeapon.json
--- !u!1 &1550290323
GameObject:
m_ObjectHideFlags: 0
@ -134211,7 +134230,7 @@ RectTransform:
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 1}
m_AnchorMax: {x: 0, y: 0}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 0, y: 0}
m_Pivot: {x: 0.5, y: 0.5}
@ -134449,10 +134468,10 @@ RectTransform:
m_Father: {fileID: 1844323541}
m_RootOrder: 5
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 1}
m_AnchorMax: {x: 0, y: 1}
m_AnchoredPosition: {x: 408.28363, y: -562.8}
m_SizeDelta: {x: 816.56726, y: 4}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 0, y: 4}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &1579181538
MonoBehaviour:
@ -138844,7 +138863,7 @@ RectTransform:
m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: 0, y: 464.06}
m_SizeDelta: {x: 816.56726, y: 747.36}
m_SizeDelta: {x: 816.56726, y: 0}
m_Pivot: {x: 0.5, y: 1}
--- !u!114 &1844323542
MonoBehaviour:
@ -139210,8 +139229,8 @@ RectTransform:
m_Father: {fileID: 597565997}
m_RootOrder: 2
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0.427, y: 0}
m_AnchorMax: {x: 0.427, y: 1}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 100, y: 100}
m_Pivot: {x: 0.5, y: 0.5}
@ -140304,7 +140323,7 @@ RectTransform:
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: -434, y: -47}
m_AnchoredPosition: {x: -453, y: 200}
m_SizeDelta: {x: 177, y: 188}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &1936347083
@ -141647,7 +141666,7 @@ GameObject:
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 0
m_IsActive: 1
--- !u!224 &2008867880
RectTransform:
m_ObjectHideFlags: 0
@ -141667,9 +141686,9 @@ RectTransform:
m_Father: {fileID: 2102651775}
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 1}
m_AnchorMax: {x: 0, y: 1}
m_AnchoredPosition: {x: 270, y: -198.275}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 490, y: 130.7746}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &2008867881
@ -142631,7 +142650,7 @@ GameObject:
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 0
m_IsActive: 1
--- !u!224 &2102651775
RectTransform:
m_ObjectHideFlags: 0
@ -142650,7 +142669,7 @@ RectTransform:
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: 270, y: 0}
m_AnchoredPosition: {x: -562, y: -44}
m_SizeDelta: {x: 540, y: 663.1}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &2102651776
@ -142671,7 +142690,7 @@ MonoBehaviour:
m_Top: 0
m_Bottom: 0
m_ChildAlignment: 4
m_Spacing: -130
m_Spacing: 0
m_ChildForceExpandWidth: 1
m_ChildForceExpandHeight: 1
m_ChildControlWidth: 0

View File

@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Linq;
using Data;
using UnityEngine;
@ -27,44 +28,28 @@ namespace HexFiled
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].curent);
if (!path.hasPath)
{
path.field.ForEach(x => x.PaintHex(UnitColor.GREY));
}
}
}
}
if (item.Key == cell.Color && item.Value.Count >= 2 && item.Value.Count < 6 &&
UnitCurrentCell.ContainsKey(cell.Color))
UnitCurrentCell.ContainsKey(cell.Color))
{
HexDirection direction = new HexDirection();
HexDirection openDirection = new HexDirection();
HexDirection closeDirection = new HexDirection();
for (int i = 0; i < 6; i++)
{
var neighbour = UnitCurrentCell[cell.Color].previos.GetNeighbor((HexDirection)i);
if (neighbour == UnitCurrentCell[cell.Color].curent)
{
direction = (HexDirection)i;
}
}
openDirection = direction.PlusSixtyDeg();
closeDirection = direction.MinusSixtyDeg();
var path = HasPath(
var openDirection = direction.PlusSixtyDeg();
var closeDirection = direction.MinusSixtyDeg();
var path = Round(
UnitCurrentCell[cell.Color].previos.GetNeighbor(closeDirection),
UnitCurrentCell[cell.Color].previos.GetNeighbor(openDirection)
);
);
if (!path.hasPath)
{
@ -72,7 +57,7 @@ namespace HexFiled
}
else
{
path = HasPath(
path = Round(
UnitCurrentCell[cell.Color].previos.GetNeighbor(openDirection),
UnitCurrentCell[cell.Color].previos.GetNeighbor(closeDirection)
);
@ -82,9 +67,23 @@ namespace HexFiled
}
}
}
if (item.Value.Count > 0 && item.Key != UnitColor.GREY && item.Key != cell.Color)
{
foreach (var path in from cellNeighbour in item.Value
where UnitCurrentCell.ContainsKey(item.Key)
select HasPath(cellNeighbour, UnitCurrentCell[item.Key].curent)
into path
where !path.hasPath
select path)
{
path.field.ForEach(x => x.PaintHex(UnitColor.GREY));
}
}
}
}
private Dictionary<UnitColor, List<HexCell>> DifferentHexByColor(List<HexCell> cellsList)
{
Dictionary<UnitColor, List<HexCell>> resultDict = new Dictionary<UnitColor, List<HexCell>>();
@ -102,59 +101,40 @@ namespace HexFiled
return resultDict;
}
private ( bool hasPath, List<HexCell> field ) HasPath(HexCell start, HexCell end)
private (bool hasPath, List<HexCell> field) Round(HexCell start, HexCell end)
{
if (start.Color == _cell.Color || end.Color == _cell.Color)
{
return (true, null);
}
List<HexCell> closedList = new List<HexCell>();
HexCell currentCell = start;
Stack<HexCell> stackIteators = new Stack<HexCell>();
stackIteators.Push(currentCell);
Stack<HexCell> stackIterators = new Stack<HexCell>();
stackIterators.Push(currentCell);
closedList.Add(currentCell);
while (stackIteators.Count >= 0)
while (stackIterators.Count >= 0)
{
if (currentCell == end)
return (true, closedList);
List<HexCell> openList = new List<HexCell>();
if(end.Color != UnitColor.GREY)
foreach (var neighbour in currentCell.GetListNeighbours())
{
if (end.Color != start.Color)
if (neighbour == null)
{
return (true, null);
}
for (int i = 0; i < 6; i++)
{
HexCell neighbour = currentCell.GetNeighbor((HexDirection)i);
if (neighbour == null)
{
return (true, null);
}
if (!closedList.Contains(neighbour) && neighbour.Color == start.Color)
{
openList.Add(neighbour);
}
}
}
else
{
for (int i = 0; i < 6; i++)
if (closedList.Contains(neighbour) || neighbour.Color == _cell.Color) continue;
openList.Add(neighbour);
if (neighbour.GetListNeighbours().Contains(end))
{
HexCell neighbour = currentCell.GetNeighbor((HexDirection)i);
if (neighbour == null)
{
return (true, null);
}
if (!closedList.Contains(neighbour) &&
neighbour.Color != _cell.Color)
{
openList.Add(neighbour);
}
return (true, null);
}
}
@ -162,16 +142,81 @@ namespace HexFiled
{
currentCell = openList[Random.Range(0, openList.Count - 1)];
closedList.Add(currentCell);
stackIteators.Push(currentCell);
stackIterators.Push(currentCell);
}
else
{
if (stackIteators.Count == 0)
if (stackIterators.Count == 0)
{
return (false, closedList);
}
currentCell = stackIteators.Pop();
currentCell = stackIterators.Pop();
}
if (currentCell.GetListNeighbours().Contains(end))
{
return (true, null);
}
}
return (false, closedList);
}
private ( bool hasPath, List<HexCell> field ) HasPath(HexCell start, HexCell end)
{
if (start.Color == _cell.Color || end.Color == _cell.Color)
{
return (true, null);
}
List<HexCell> closedList = new List<HexCell>();
HexCell currentCell = start;
Stack<HexCell> stackIterators = new Stack<HexCell>();
stackIterators.Push(currentCell);
closedList.Add(currentCell);
while (stackIterators.Count >= 0)
{
if (currentCell == end)
return (true, null);
List<HexCell> openList = new List<HexCell>();
foreach (var neighbour in currentCell.GetListNeighbours())
{
if (neighbour == null)
{
return (true, null);
}
if (closedList.Contains(neighbour) || neighbour.Color != start.Color) continue;
openList.Add(neighbour);
if (neighbour.GetListNeighbours().Contains(end))
{
return (true, null);
}
}
if (openList.Count > 0)
{
currentCell = openList[Random.Range(0, openList.Count - 1)];
closedList.Add(currentCell);
stackIterators.Push(currentCell);
}
else
{
if (stackIterators.Count == 0)
{
return (false, closedList);
}
currentCell = stackIterators.Pop();
}
if (currentCell.GetListNeighbours().Contains(end))