Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using HexagonSurvive.Managers;
- using HexagonSurvive.Map.Models;
- using JetBrains.Annotations;
- using UnityEngine;
- namespace HexagonSurvive.Navigation
- {
- public class PathUnit : IComparable<PathUnit>
- {
- public int F => G + H;
- public int G;
- public int H;
- [CanBeNull]
- public PathUnit prior;
- public readonly HexUnit hexUnit;
- private HexUnit _destination;
- public PathUnit(HexUnit hexUnit, HexUnit destination)
- {
- this.hexUnit = hexUnit;
- _destination = destination;
- G = 0;
- H = 0;
- prior = null;
- }
- public override int GetHashCode() =>
- hexUnit.GetHashCode();
- public override bool Equals(object obj) =>
- obj != null && obj.GetHashCode() == GetHashCode();
- public int CompareTo(PathUnit other)
- {
- if (hexUnit.coordinate == other.hexUnit.coordinate) return 0;
- if (F < other.F) return -1;
- if (F == other.F && H < other.H) return -1;
- return 1;
- }
- public List<PathUnit> GetNeighbours()
- {
- var m = EnvironmentManager.Instance.targetMap;
- var c = hexUnit.coordinate;
- return new List<PathUnit>
- {
- new(m.GetUnit(c + new Vector3Int(1, 0, -1)), _destination),
- new(m.GetUnit(c + new Vector3Int(0, 1, -1)), _destination),
- new(m.GetUnit(c + new Vector3Int(-1, 1, 0)), _destination),
- new(m.GetUnit(c + new Vector3Int(-1, 0, 1)), _destination),
- new(m.GetUnit(c + new Vector3Int(0, -1, 1)), _destination),
- new(m.GetUnit(c + new Vector3Int(1, -1, 0)), _destination)
- };
- }
- }
- }
Add Comment
Please, Sign In to add comment