protected override void OnConfigureStats()
    {
        base.OnConfigureStats();

        for (int characterIndex = 0; characterIndex < charactersCount; ++characterIndex)
        {
            GameObject characterInstance = GetCharacterByIndex(characterIndex);

            if (characterInstance == null)
            {
                continue;
            }

            tnCharacterInfo characterInfo = characterInstance.GetComponent <tnCharacterInfo>();

            if (characterInfo == null)
            {
                continue;
            }

            tnCharacterStats characterStats = characterInstance.GetComponent <tnCharacterStats>();

            if (characterStats == null)
            {
                continue;
            }

            // Bind results.

            {
                int characterId = characterInfo.characterId;
                tnBaseMatchCharacterResults characterResults = (tnBaseMatchCharacterResults)GetCharacterResultsById(characterId);

                characterStats.SetResults(characterResults);
            }

            // Bind references.

            {
                int characterTeamIndex = characterInfo.teamIndex;

                for (int teamIndex = 0; teamIndex < teamsCount; ++teamIndex)
                {
                    if (teamIndex == characterTeamIndex)
                    {
                        continue;
                    }

                    tnGoal goal = GetGoal(teamIndex);
                    if (goal != null)
                    {
                        characterStats.SetOpponentGoal(goal);
                        break;
                    }
                }
            }
        }
    }
    /*
     *
     * public void SetGoal(tnGoal i_Goal)
     * {
     *  m_Goal = i_Goal;
     * }
     *
     */

    public void SetOpponentGoal(tnGoal i_OpponentGoal)
    {
        m_OpponentGoal = i_OpponentGoal;
    }
    protected override void OnConfigureAI()
    {
        base.OnConfigureAI();

        GameObject topLeft     = GameObject.Find(s_TopLeft_Corner);
        GameObject bottomRight = GameObject.Find(s_BottomRight_Corner);

        GameObject midfield = GameObject.Find(s_Midfield);

        GameObject goalTop    = GameObject.Find(s_GoalTop);
        GameObject goalBottom = GameObject.Find(s_GoalBottom);

        GameObject areaTop    = GameObject.Find(s_AreaTop);
        GameObject areaBottom = GameObject.Find(s_AreaBottom);

        for (int aiTeamIndex = 0; aiTeamIndex < teamsCount; ++aiTeamIndex)
        {
            int aiCount = GetAICount(aiTeamIndex);

            for (int aiIndex = 0; aiIndex < aiCount; ++aiIndex)
            {
                tnBaseAIInputFiller aiInputFiller = (tnBaseAIInputFiller)GetAI(aiTeamIndex, aiIndex);

                if (aiInputFiller != null)
                {
                    tnBaseAIData aiData = new tnBaseAIData();

                    // Fill teammates and opponents.

                    {
                        for (int teamIndex = 0; teamIndex < teamsCount; ++teamIndex)
                        {
                            int teamSize = GetTeamSize(teamIndex);

                            for (int characterIndex = 0; characterIndex < teamSize; ++characterIndex)
                            {
                                GameObject characterInstance = GetCharacter(teamIndex, characterIndex);
                                if (characterInstance != null)
                                {
                                    if (teamIndex == aiTeamIndex) // Teammate.
                                    {
                                        aiData.AddMyTeamCharacter(characterInstance.transform);
                                    }
                                    else // Opponent.
                                    {
                                        aiData.AddOpponentTeamCharacter(characterInstance.transform);
                                    }
                                }
                            }
                        }
                    }

                    // Fill ball.

                    if (m_Ball != null)
                    {
                        aiData.SetBall(m_Ball.transform);
                    }

                    // Fill goal.

                    if (m_Goals != null)
                    {
                        if (aiTeamIndex < m_Goals.Count)
                        {
                            tnGoal goal = m_Goals[aiTeamIndex];
                            aiData.SetGoal(goal.transform);
                        }
                    }

                    // Fill opponent goal.

                    if (m_Goals != null)
                    {
                        for (int teamIndex = 0; teamIndex < teamsCount; ++teamIndex)
                        {
                            if (teamIndex == aiTeamIndex)
                            {
                                continue;
                            }

                            if (teamIndex < m_Goals.Count)
                            {
                                tnGoal goal = m_Goals[teamIndex];
                                aiData.SetOpponentGoal(goal.transform);

                                break; // NOTE: Only the first opponent goal will be linked to the AI.
                            }
                        }
                    }

                    // Fill reference position.

                    {
                        Vector3 selfPosition = aiInputFiller.self.transform.position;
                        aiData.SetReferencePosition(selfPosition);
                    }

                    // Anchors.

                    {
                        if (topLeft != null)
                        {
                            aiData.SetTopLeftAnchor(topLeft.transform);
                        }

                        if (bottomRight != null)
                        {
                            aiData.SetBottomRightAnchor(bottomRight.transform);
                        }

                        if (midfield != null)
                        {
                            aiData.SetMidfieldAnchor(midfield.transform);
                        }

                        if (goalTop != null)
                        {
                            aiData.SetGoalTop(goalTop.transform);
                        }

                        if (goalBottom != null)
                        {
                            aiData.SetGoalBottom(goalBottom.transform);
                        }

                        if (areaTop != null)
                        {
                            aiData.SetAreaTop(areaTop.transform);
                        }

                        if (areaBottom != null)
                        {
                            aiData.SetAreaBottom(areaBottom.transform);
                        }
                    }

                    aiInputFiller.Setup(aiData);
                }
            }
        }
    }
    private void SpawnGoals()
    {
        tnMatchSettingsModule matchSettingsModule = GameModulesManager.GetModuleMain <tnMatchSettingsModule>();

        if (matchSettingsModule == null)
        {
            return;
        }

        int stadiumId = matchSettingsModule.stadiumId;

        m_StadiumId = stadiumId;

        tnStadiumData stadiumData = tnGameData.GetStadiumDataMain(stadiumId);

        if (stadiumData == null)
        {
            return;
        }

        tnGoal goalPrefab = stadiumData.LoadAndGetGoalPrefab();

        if (goalPrefab == null)
        {
            return;
        }

        for (int teamIndex = 0; teamIndex < teamsCount; ++teamIndex)
        {
            if (teamIndex >= s_GoalSpawnPoints.Length)
            {
                break;
            }

            int teamId = GetTeamId(teamIndex);

            string     goalSpawnPointName = s_GoalSpawnPoints[teamIndex];
            GameObject goalSpawnPointGo   = GameObject.Find(goalSpawnPointName);

            if (goalSpawnPointGo == null)
            {
                continue;
            }

            TSTransform2D goalSpawnPointTransform = goalSpawnPointGo.GetComponent <TSTransform2D>();

            if (goalSpawnPointTransform == null)
            {
                continue;
            }

            Vector3    spawnPosition = goalSpawnPointGo.transform.position;
            Quaternion spawnRotation = goalSpawnPointGo.transform.rotation;

            tnGoal goalInstance = Instantiate <tnGoal>(goalPrefab);
            goalInstance.gameObject.name = "Goal_" + teamIndex;

            goalInstance.transform.position = spawnPosition;
            goalInstance.transform.rotation = spawnRotation;

            // Configure TSTransform

            TSTransform2D tsTransform = goalInstance.GetComponent <TSTransform2D>();
            if (tsTransform != null)
            {
                tsTransform.position = goalSpawnPointTransform.position;
                tsTransform.rotation = goalSpawnPointTransform.rotation;
            }

            // Rotate.

            if (goalInstance.transform.position.x > 0f)
            {
                goalInstance.Rotate();
            }

            // Setup goal.

            goalInstance.SetTeamId(teamId);

            // Register on TrueSyncController.

            TrueSyncManager.RegisterTrueSyncObjectMain(goalInstance.gameObject);

            // Set data on slow motion controller.

            if (m_SlowMotionController != null)
            {
                m_SlowMotionController.AddSegment(goalInstance.slowMotionPivotA, goalInstance.slowMotionPivotB);
            }

            // Add to goal list.

            m_Goals.Add(goalInstance);
        }
    }
Beispiel #5
0
    public tnGoal LoadAndGetGoalPrefab()
    {
        tnGoal prefab = Resources.Load <tnGoal>(m_GoalPrefabPath);

        return(prefab);
    }