private static bool CheckSupporters()
    {
        bool errorOccurred = false;

        int supportersCount = 0;

        tnSupporterArea[] supportersArea = GameObject.FindObjectsOfType <tnSupporterArea>();

        for (int areaIndex = 0; areaIndex < supportersArea.Length; ++areaIndex)
        {
            tnSupporterArea area = supportersArea[areaIndex];
            supportersCount += area.maxSupporters;

            Collider2D collider2D = area.GetComponent <Collider2D>();

            if (collider2D == null)
            {
                errorOccurred |= true;

                LogWarning(area.gameObject.name + " missing collider.");
            }
            else
            {
                if (!collider2D.isTrigger)
                {
                    errorOccurred |= true;

                    LogWarning(area.gameObject.name + "'s collider is not a trigger.");
                }
            }

            errorOccurred |= CheckForLayer(area.gameObject, s_LayerDefault);
        }

        Debug.Log("Supporters:" + supportersCount + "/" + supportersArea.Length);

        if (supportersCount > s_MaxSupporters)
        {
            errorOccurred |= true;

            LogWarning("Too many supporters.");
        }

        return(errorOccurred);
    }
    private void CreateSupporters()
    {
        if (!m_CreateSupporters)
        {
            return;
        }

        tnTeamsModule teamsModule = GameModulesManager.GetModuleMain <tnTeamsModule>();

        if (teamsModule == null)
        {
            return;
        }

        System.Random random = new System.Random(m_Seed);

        string[] animatedResourceNames = new string[]
        {
            "Characters/Common/p_Supporter01_Animated",
            "Characters/Common/p_Supporter02_Animated",
            "Characters/Common/p_Supporter03_Animated",
        };

        string[] staticResourceNames = new string[]
        {
            "Characters/Common/p_Supporter01",
            "Characters/Common/p_Supporter02",
            "Characters/Common/p_Supporter03",
        };

        // Load animated resources.

        List <GameObject> animatedResources = new List <GameObject>();

        for (int resourceIndex = 0; resourceIndex < animatedResourceNames.Length; ++resourceIndex)
        {
            GameObject resourcePrefab = (GameObject)Resources.Load <GameObject>(animatedResourceNames[resourceIndex]);

            if (resourcePrefab == null)
            {
                continue;
            }

            animatedResources.Add(resourcePrefab);
        }

        // Load static resources.

        List <GameObject> staticResources = new List <GameObject>();

        for (int resourceIndex = 0; resourceIndex < staticResourceNames.Length; ++resourceIndex)
        {
            GameObject resourcePrefab = (GameObject)Resources.Load <GameObject>(staticResourceNames[resourceIndex]);

            if (resourcePrefab == null)
            {
                continue;
            }

            staticResources.Add(resourcePrefab);
        }

        // Iterate each supporter area.

        tnSupporterArea[] supportersAreas = FindObjectsOfType <tnSupporterArea>();

        for (int supporterAreaIndex = 0; supporterAreaIndex < supportersAreas.Length; ++supporterAreaIndex)
        {
            tnSupporterArea supporterArea = supportersAreas[supporterAreaIndex];

            if (supporterArea == null)
            {
                continue;
            }

            // Compute team colors for this area.

            List <Color> teamColors = new List <Color>();

            Vector3 boundsMin = supporterArea.boundsMin;
            Vector3 boundsMax = supporterArea.boundsMax;

            if (boundsMin.x < 0f || boundsMax.x < 0f)
            {
                // Assign to Team 0.

                tnTeamDescription teamDescription = teamsModule.GetTeamDescription(0);
                if (teamDescription != null)
                {
                    Color[] colorsToAdd = GetTeamColors(teamDescription.teamId);
                    teamColors.AddRange(colorsToAdd);
                }
            }

            if (boundsMin.x > 0f || boundsMax.x > 0f)
            {
                // Assign to Team 1.

                tnTeamDescription teamDescription = teamsModule.GetTeamDescription(1);
                if (teamDescription != null)
                {
                    Color[] colorsToAdd = GetTeamColors(teamDescription.teamId);
                    teamColors.AddRange(colorsToAdd);
                }
            }

            Color[] spawnColors = teamColors.ToArray();

            if (spawnColors.Length == 0)
            {
                continue;
            }

            // Spawn supporters.

            for (int supporterIndex = 0; supporterIndex < supporterArea.numPoints; ++supporterIndex)
            {
                GameObject supporterPrefab = null;

                if (supporterIndex < supporterArea.maxAnimators)
                {
                    // Select an animated resource.

                    int resourceIndex = random.Next(0, animatedResources.Count);
                    supporterPrefab = animatedResources[resourceIndex];
                }
                else
                {
                    // Select a static resource.

                    int resourceIndex = random.Next(0, staticResources.Count);
                    supporterPrefab = staticResources[resourceIndex];
                }

                if (supporterPrefab == null)
                {
                    continue;
                }

                Vector2 spawnPoint    = supporterArea.GetPoint(supporterIndex);
                Vector3 spawnPosition = new Vector3(spawnPoint.x, spawnPoint.y, 0f);

                GameObject supporterInstance = (GameObject)Instantiate(supporterPrefab, spawnPosition, Quaternion.identity);

                if (supporterInstance.transform.position.x > 0f)
                {
                    Vector3 flipScale = supporterInstance.transform.localScale;
                    flipScale.x *= -1f;

                    supporterInstance.transform.localScale = flipScale;
                }

                supporterInstance.transform.SetParent(supporterArea.transform, true);

                tnSupporter supporterComponent = supporterInstance.GetComponent <tnSupporter>();
                if (supporterComponent != null)
                {
                    int   randomIndex = random.Next(0, teamColors.Count);
                    Color randomColor = teamColors[randomIndex];
                    supporterComponent.SetColor(randomColor);
                }

                tnDepth2d depth2d = supporterInstance.GetComponent <tnDepth2d>();
                if (depth2d != null)
                {
                    float scale = 0.5f;
                    depth2d.SetScale(scale);

                    float depthLevel = supporterArea.transform.position.z;
                    depth2d.SetOffset(depthLevel);
                }
            }
        }
    }