In the ‘FindOffensiveCover’ method I am trying to iterate through the appropriate list based on the ‘CoverType’ enum.
Is there a cleaner way of doing this than the way I am doing it?
I don’t like using the new keyword to initialize the temp. list.
Enum:
public enum CoverType
{
Standing,
Crouching,
Proning
}
My Class:
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
public class CoverManager : MonoBehaviour
{
public static CoverManager instance { get; private set; }
private List<CoverNode> standingNodes;
private List<CoverNode> crouchingNodes;
private List<CoverNode> proningNodes;
private void Awake()
{
instance = this;
standingNodes = new List<CoverNode>();
crouchingNodes = new List<CoverNode>();
proningNodes = new List<CoverNode>();
}
public void AddNode(CoverNode node, CoverType type)
{
if (type == CoverType.Standing)
{
standingNodes.Add(node);
}
else if (type == CoverType.Crouching)
{
crouchingNodes.Add(node);
}
else if (type == CoverType.Proning)
{
proningNodes.Add(node);
}
}
public void FindOffensiveCover(CoverType type)
{
List<CoverNode> list = new List<CoverNode>();
if (type == CoverType.Standing)
{
list = standingNodes;
}
else if (type == CoverType.Crouching)
{
list = crouchingNodes;
}
else if (type == CoverType.Proning)
{
list = proningNodes;
}
for (i = 0; i < list.Count; i++)
{
//do stuff
}
}
}