TeamUtil.cs 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. using System;
  2. using UnityEngine;
  3. public class TeamUtil
  4. {
  5. public enum Team
  6. {
  7. None = 0,
  8. Blue = 1,
  9. Red = 2,
  10. Yellow = 3
  11. }
  12. 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)};
  13. public static Color GetTeamColor(int index)
  14. {
  15. if(index < 0 || index >= TeamColors.Length)
  16. {
  17. return TeamColors[TeamUtil.Team.None.GetHashCode()];
  18. }
  19. return TeamColors[index];
  20. }
  21. public static string GetTeamColorString(int index)
  22. {
  23. Color color = GetTeamColor(index);
  24. string str = "#";
  25. str += ((int)(color.r*255f)).ToString("x2");
  26. str += ((int)(color.g*255f)).ToString("x2");
  27. str += ((int)(color.b*255f)).ToString("x2");
  28. str += ((int)(color.a*255f)).ToString("x2");
  29. return str;
  30. }
  31. public static string GetTeamColorString(Team team)
  32. {
  33. return GetTeamColorString(team.GetHashCode());
  34. }
  35. public static Color[] GetTeamColors()
  36. {
  37. return TeamColors;
  38. }
  39. public static string GetTeamName(Team team)
  40. {
  41. return Language.GetStr("Team", "team"+team.GetHashCode());
  42. }
  43. private static Team[] TeamList = {Team.None, Team.Blue, Team.Red, Team.Yellow};
  44. public static Team GetTeam(int index)
  45. {
  46. if(index < 0 || index >= TeamList.Length)
  47. {
  48. return TeamUtil.Team.None;
  49. }
  50. return TeamList[index];
  51. }
  52. public static Team GetOpponentTeam(Team team)
  53. {
  54. if(team.Equals(Team.Blue))
  55. {
  56. return Team.Red;
  57. }
  58. else if(team.Equals(Team.Red))
  59. {
  60. return Team.Blue;
  61. }
  62. return Team.None;
  63. }
  64. public static Team GetOpponentTeam(int teamId)
  65. {
  66. Team team = GetTeam(teamId);
  67. if(team.Equals(Team.Blue))
  68. {
  69. return Team.Red;
  70. }
  71. else if(team.Equals(Team.Red))
  72. {
  73. return Team.Blue;
  74. }
  75. return Team.None;
  76. }
  77. public static AStarNode.Type GetAStarNodeType(Team team)
  78. {
  79. if(team == Team.Blue)
  80. return AStarNode.Type.BlueWall;
  81. else if(team == Team.Red)
  82. return AStarNode.Type.RedWall;
  83. return AStarNode.Type.YellowWall;
  84. }
  85. public static Team GetTeamByAstarNodeType(AStarNode.Type astarNodeType)
  86. {
  87. if(astarNodeType == AStarNode.Type.BlueWall)
  88. return Team.Blue;
  89. else if(astarNodeType == AStarNode.Type.RedWall)
  90. return Team.Red;
  91. else if(astarNodeType == AStarNode.Type.YellowWall)
  92. return Team.Yellow;
  93. return Team.None;
  94. }
  95. }