123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- 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;
- }
- }
|