using System; using UnityEngine; public class TeamUtil { public enum Team { None = 0, Blue = 1, Red = 2, Yellow = 3 } private static Color[] TeamColors = {new Color(0.2f, 0.2f, 0.2f), new Color(0.3f, 0.5f, 1f), new Color(255f/255f, 64f/255f, 64f/255f), new Color(242f/255f, 156f/255f, 0f/255f)}; public static Color GetTeamColor(int index) { if(index < 0 || index >= TeamColors.Length) { return TeamColors[TeamUtil.Team.None.GetHashCode()]; } return TeamColors[index]; } public static string GetTeamColorString(int index) { Color color = GetTeamColor(index); string str = "#"; str += ((int)(color.r*255f)).ToString("x2"); str += ((int)(color.g*255f)).ToString("x2"); str += ((int)(color.b*255f)).ToString("x2"); str += ((int)(color.a*255f)).ToString("x2"); return str; } public static string GetTeamColorString(Team team) { return GetTeamColorString(team.GetHashCode()); } public static Color[] GetTeamColors() { return TeamColors; } public static string GetTeamName(Team team) { return Language.GetStr("Team", "team"+team.GetHashCode()); } private static Team[] TeamList = {Team.None, Team.Blue, Team.Red, Team.Yellow}; public static Team GetTeam(int index) { if(index < 0 || index >= TeamList.Length) { return TeamUtil.Team.None; } return TeamList[index]; } public static Team GetOpponentTeam(Team team) { if(team.Equals(Team.Blue)) { return Team.Red; } else if(team.Equals(Team.Red)) { return Team.Blue; } return Team.None; } public static Team GetOpponentTeam(int teamId) { Team team = GetTeam(teamId); if(team.Equals(Team.Blue)) { return Team.Red; } else if(team.Equals(Team.Red)) { return Team.Blue; } return Team.None; } public static AStarNode.Type GetAStarNodeType(Team team) { if(team == Team.Blue) return AStarNode.Type.BlueWall; else if(team == Team.Red) return AStarNode.Type.RedWall; return AStarNode.Type.YellowWall; } public static Team GetTeamByAstarNodeType(AStarNode.Type astarNodeType) { if(astarNodeType == AStarNode.Type.BlueWall) return Team.Blue; else if(astarNodeType == AStarNode.Type.RedWall) return Team.Red; else if(astarNodeType == AStarNode.Type.YellowWall) return Team.Yellow; return Team.None; } }