Answer the question
In order to leave comments, you need to log in
How to make normal code out of this method?
How to make normal, beautiful, readable and generally the best code out of this?
PS Added C# to the tag, since special knowledge of Unity is not needed here
public List<Cell> CalculateVariants(List<Vector2> movevariants, List<Vector2> attackvariants)
{
var variants = new List<Cell>();
foreach (Vector2 offset in movevariants)
{
if (GridRepository.Cells.Find(cell => cell.Position == cell.Position + offset && cell.Unit == null) != null)
{
variants.Add(GridRepository.Cells.Find(cell => cell.Position == cell.Position + offset && cell.Unit == null));
}
}
foreach (Vector2 offset in attackvariants)
{
if (GridRepository.Cells.Find(cell => cell.Position == cell.Position + offset && cell.Unit != null) != null)
{
variants.Add(GridRepository.Cells.Find(cell => cell.Position == cell.Position + offset && cell.Unit == null));
}
}
return variants;
}
Answer the question
In order to leave comments, you need to log in
Get rid of duplicates in the form of Find, at least. Cache as much as possible.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question