Exemplo n.º 1
0
    private void CreateMatchController()
    {
        tnMatchSettingsModule matchSettingsModule = GameModulesManager.GetModuleMain <tnMatchSettingsModule>();

        if (matchSettingsModule == null)
        {
            return;
        }

        int gameModeId = matchSettingsModule.gameModeId;
        tnMatchController matchControllerInstance = tnGameModeFactory.CreateMatchController(gameModeId);

        if (matchControllerInstance != null)
        {
            matchControllerInstance.gameObject.name = "MultiplayerMatchController";
            matchControllerInstance.SetSeed(m_SharedSeed);

            matchControllerInstance.SetCamera(m_GameCameraGO);
        }

        m_MatchController = matchControllerInstance;

        if (m_TrueSyncManager != null)
        {
            m_TrueSyncManager.RegisterTrueSyncObject(m_MatchController.gameObject);
        }
    }
        private void SetupMatchSettingsModule()
        {
            tnMatchSettingsModule module = GameModulesManager.GetModuleMain <tnMatchSettingsModule>();

            if (module == null)
            {
                return;
            }

            module.Clear();

            // Game mode.

            {
                module.SetGameModeId(gameMode.Value);
            }

            // Stadium.

            {
                int stadiumKey = -1;
                GetRandomStadiumKey(gameMode.Value, out stadiumKey);

                module.SetStadiumId(stadiumKey);
            }

            // Ball.

            {
                int ballKey = -1;
                GetRandomBallKey(out ballKey);

                module.SetBallId(ballKey);
            }

            // Ai level.

            {
                module.SetAILevelIndex(tnGameData.aiLevelCountMain - 1);
            }

            // Options.

            {
                tnGameModeData gameModeData = tnGameData.GetGameModeDataMain(gameMode.Value);
                if (gameModeData != null)
                {
                    tnGameModeConfig gameModeConfig = tnGameData.GetConfigDataMain(gameModeData.optionsConfigId);
                    if (gameModeConfig != null)
                    {
                        module.SetMatchDurationOption(gameModeConfig.matchDurationOption);
                        module.SetRefereeOption(gameModeConfig.refereeOption);
                    }
                }
            }
        }
Exemplo n.º 3
0
    private void CreateCharacters()
    {
        // Cache character prefab path.

        tnMatchSettingsModule matchSettingsModule = GameModulesManager.GetModuleMain <tnMatchSettingsModule>();

        if (matchSettingsModule != null)
        {
            int gameModeId = matchSettingsModule.gameModeId;
            m_GameModeId = gameModeId;
            tnGameModeData gameModeData = tnGameData.GetGameModeDataMain(gameModeId);

            if (gameModeData != null)
            {
                m_CharacterPrefab = gameModeData.LoadAndGetCharacterPrefabPath();
            }
        }

        // Create teams.

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

        if (teamsModule == null)
        {
            return;
        }

        for (int teamIndex = 0; teamIndex < teamsModule.teamsCount; ++teamIndex)
        {
            List <GameObject> team = new List <GameObject>();
            m_Teams.Add(team);
        }

        for (int teamIndex = 0; teamIndex < teamsModule.teamsCount; ++teamIndex)
        {
            List <tnAIInputFiller> aiList = new List <tnAIInputFiller>();
            m_LocalAI.Add(aiList);
        }

        for (int teamIndex = 0; teamIndex < teamsModule.teamsCount; ++teamIndex)
        {
            tnTeamDescription teamDescription = teamsModule.GetTeamDescription(teamIndex);

            if (teamDescription == null)
            {
                continue;
            }

            ProceesTeam(teamIndex, teamDescription);
        }

        // Disable Input

        DisableInput();
    }
        public override void OnEnter()
        {
            tnMatchSettingsModule matchSettingsModule = GameModulesManager.GetModuleMain<tnMatchSettingsModule>();

            if (matchSettingsModule != null)
            {
                matchSettingsModule.Clear();
            }

            Finish();
        }
    // INTERNALS

    private void SpawnScorePanel()
    {
        tnMatchSettingsModule matchSettingsModule = GameModulesManager.GetModuleMain <tnMatchSettingsModule>();

        if (matchSettingsModule == null)
        {
            return;
        }

        GameObject scorePanelSpawnPointGo = GameObject.Find(s_ScorePanelSpawnPoint);

        if (scorePanelSpawnPointGo == null)
        {
            return;
        }

        int           stadiumId   = matchSettingsModule.stadiumId;
        tnStadiumData stadiumData = tnGameData.GetStadiumDataMain(stadiumId);

        if (stadiumData == null)
        {
            return;
        }

        int gameModeId = matchSettingsModule.gameModeId;

        GameObject scorePanelPrefab = stadiumData.LoadAndGetScorePanelPrefab(gameModeId);

        if (scorePanelPrefab == null)
        {
            return;
        }

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

        GameObject scorePanelInstance = Instantiate <GameObject>(scorePanelPrefab);

        scorePanelInstance.name = "ScorePanel";

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

        tnUIStandardScorePanel scorePanel = scorePanelInstance.GetComponentInChildren <tnUIStandardScorePanel>();

        if (scorePanel != null)
        {
            scorePanel.Bind(this);
        }
    }
Exemplo n.º 6
0
        public override void OnEnter()
        {
            tnMatchSettingsModule module = GameModulesManager.GetModuleMain <tnMatchSettingsModule>();

            if (module != null)
            {
                int gameModeId = module.gameModeId;

                if (storeResult != null && !storeResult.IsNone)
                {
                    storeResult.Value = gameModeId;
                }
            }

            Finish();
        }
Exemplo n.º 7
0
    private IEnumerator LoadMap()
    {
        tnMatchSettingsModule matchSettingsModule = GameModulesManager.GetModuleMain <tnMatchSettingsModule>();

        if (matchSettingsModule != null)
        {
            int           stadiumId   = matchSettingsModule.stadiumId;
            tnStadiumData stadiumData = tnGameData.GetStadiumDataMain(stadiumId);
            if (stadiumData != null)
            {
                string      sceneName = stadiumData.sceneName;
                IEnumerator loadScene = LoadSceneAdditiveAsync(sceneName);
                yield return(StartCoroutine(loadScene));
            }
        }
    }
    // INTERNALS

    private void ShowInfo()
    {
        tnMatchSettingsModule matchSettingsModule = GameModulesManager.GetModuleMain <tnMatchSettingsModule>();

        if (matchSettingsModule == null || viewInstance == null)
        {
            return;
        }

        // stadium

        int           stadiumId   = matchSettingsModule.stadiumId;
        tnStadiumData stadiumData = tnGameData.GetStadiumDataMain(stadiumId);

        if (stadiumData != null)
        {
            viewInstance.SetStadiumImage(stadiumData.icon);
            viewInstance.SetStadiumName(stadiumData.name);
            viewInstance.SetStadiumMinPlayers(stadiumData.onlineTeamSize.min * 2);
        }

        // game mode

        int            gameMode     = matchSettingsModule.gameModeId;
        tnGameModeData gameModeData = tnGameData.GetGameModeDataMain(gameMode);

        if (gameModeData != null)
        {
            viewInstance.SetGameMode(gameModeData.name);
        }

        // golden goal, referee, match duration

        string goldengol;

        tnGameData.TryGetGoldenGoalValueMain(matchSettingsModule.goldenGoalOption, out goldengol);

        string referee;

        tnGameData.TryGetGoldenGoalValueMain(matchSettingsModule.refereeOption, out referee);

        float matchDuration;

        tnGameData.TryGetMatchDurationValueMain(matchSettingsModule.matchDurationOption, out matchDuration);

        viewInstance.SetOtherSettings(goldengol == "ON", referee == "ON", matchDuration);
    }
    private void SetStadium(tnMatchSettingsModule i_Module)
    {
        if (i_Module == null)
        {
            return;
        }

        if (m_StadiumSelector == null || m_StadiumSelector.currentItem == null)
        {
            return;
        }

        int stadiumId = m_StadiumSelector.currentItem.id;

        i_Module.SetStadiumId(stadiumId);

        LogManager.Log(this, LogContexts.FSM, "Stadium : " + m_StadiumSelector.currentItem.label + " " + "[" + m_StadiumSelector.currentItem.id + "]");
    }
    private void SetReferee(tnMatchSettingsModule i_Module)
    {
        if (i_Module == null)
        {
            return;
        }

        if (m_RefereeSelector == null || m_RefereeSelector.currentItem == null)
        {
            return;
        }

        int refereeOptionId = m_RefereeSelector.currentItem.id;

        i_Module.SetRefereeOption(refereeOptionId);

        LogManager.Log(this, LogContexts.FSM, "Referee : " + m_RefereeSelector.currentItem.label + " " + "[" + m_RefereeSelector.currentItem.id + "]");
    }
    private void SetAILevelIndex(tnMatchSettingsModule i_Module)
    {
        if (i_Module == null)
        {
            return;
        }

        if (m_AILevelSelector == null || m_AILevelSelector.currentItem == null)
        {
            return;
        }

        int aiLevelIndex = m_AILevelSelector.currentItem.id;

        i_Module.SetAILevelIndex(aiLevelIndex);

        LogManager.Log(this, LogContexts.FSM, "Ai Level : " + m_AILevelSelector.currentItem.label + " " + "[" + m_AILevelSelector.currentItem.id + "]");
    }
    private void SetBall(tnMatchSettingsModule i_Module)
    {
        if (i_Module == null)
        {
            return;
        }

        if (m_BallSelector == null || m_BallSelector.currentItem == null)
        {
            return;
        }

        int ballId = m_BallSelector.currentItem.id;

        i_Module.SetBallId(ballId);

        LogManager.Log(this, LogContexts.FSM, "Ball : " + m_BallSelector.currentItem.label + " " + "[" + m_BallSelector.currentItem.id + "]");
    }
    private void SetGoldenGoal(tnMatchSettingsModule i_Module)
    {
        if (i_Module == null)
        {
            return;
        }

        if (m_GoldenGoalSelector == null || m_GoldenGoalSelector.currentItem == null)
        {
            return;
        }

        int goldenGoalOptionId = m_GoldenGoalSelector.currentItem.id;

        i_Module.SetGoldenGoalOption(goldenGoalOptionId);

        LogManager.Log(this, LogContexts.FSM, "Golden Goal : " + m_GoldenGoalSelector.currentItem.label + " " + "[" + m_GoldenGoalSelector.currentItem.id + "]");
    }
    private void SetMatchDuration(tnMatchSettingsModule i_Module)
    {
        if (i_Module == null)
        {
            return;
        }

        if (m_MatchDurationSelector == null || m_MatchDurationSelector.currentItem == null)
        {
            return;
        }

        int matchDurationKey = m_MatchDurationSelector.currentItem.id;

        i_Module.SetMatchDurationOption(matchDurationKey);

        LogManager.Log(this, LogContexts.FSM, "Match Duration : " + m_MatchDurationSelector.currentItem.label + " " + "[" + m_MatchDurationSelector.currentItem.id + "]");
    }
    private void SetGameModeId(tnMatchSettingsModule i_Module)
    {
        if (i_Module == null)
        {
            return;
        }

        if (m_GameModeSelector == null || m_GameModeSelector.currentItem == null)
        {
            return;
        }

        int gameModeId = m_GameModeSelector.currentItem.id;

        i_Module.SetGameModeId(gameModeId);

        LogManager.Log(this, LogContexts.FSM, "Game Mode : " + m_GameModeSelector.currentItem.label + " " + "[" + m_GameModeSelector.currentItem.id + "]");
    }
    // BUSINESS LOGIC

    public void UpdateModule()
    {
        tnMatchSettingsModule matchSettingsModule = GameModulesManager.GetModuleMain <tnMatchSettingsModule>();

        if (matchSettingsModule == null)
        {
            return;
        }

        matchSettingsModule.Clear();

        SetGameModeId(matchSettingsModule);     // Set Game Mode.
        SetMatchDuration(matchSettingsModule);  // Set Match Duration.
        SetReferee(matchSettingsModule);        // Set Referee On/Off.
        SetGoldenGoal(matchSettingsModule);     // Set Golden Goal.
        SetAILevelIndex(matchSettingsModule);   // Set AI Level Index.
        SetBall(matchSettingsModule);           // Set Ball type.
        SetStadium(matchSettingsModule);        // Set Stadium.
    }
        public override void OnEnter()
        {
            tnMatchSettingsModule module = GameModulesManager.GetModuleMain <tnMatchSettingsModule>();

            if (module != null)
            {
                int           stadiumId   = module.stadiumId;
                tnStadiumData stadiumData = tnGameData.GetStadiumDataMain(stadiumId);

                if (stadiumData != null)
                {
                    if (storeResult != null && !storeResult.IsNone)
                    {
                        storeResult.Value = stadiumData.sceneName;
                    }
                }
            }

            Finish();
        }
        public override void OnEnter()
        {
            tnMatchSettingsModule module = GameModulesManager.GetModuleMain <tnMatchSettingsModule>();

            if (module == null)
            {
                module = GameModulesManager.AddModuleMain <tnMatchSettingsModule>();
            }

            module.Clear();

            module.SetGameModeId(gameModeId.Value);
            module.SetStadiumId(stadiumId.Value);
            module.SetBallId(ballId.Value);
            module.SetMatchDurationOption(matchDurationOption.Value);
            module.SetRefereeOption(refereeOption.Value);
            module.SetGoldenGoalOption(goldenGoalOption.Value);

            Finish();
        }
    // INTERNALS

    private void ConfigureMatch()
    {
        tnMatchSettingsModule matchSettingsModule = GameModulesManager.GetModuleMain <tnMatchSettingsModule>();

        if (matchSettingsModule == null)
        {
            return;
        }

        // Match duration

        int matchDurationOptionId = matchSettingsModule.matchDurationOption;

        float matchDuration = 180f; // Default value.

        float time;

        if (tnGameData.TryGetMatchDurationValueMain(matchDurationOptionId, out time))
        {
            matchDuration = time;
        }

        m_MatchDuration = matchDuration;

        // Golden goal

        int goldenGoalOptionId = matchSettingsModule.goldenGoalOption;

        bool goldenGoal = false; // Defualt value.

        string goldenGoalValue;

        if (tnGameData.TryGetGoldenGoalValueMain(goldenGoalOptionId, out goldenGoalValue))
        {
            goldenGoal = (goldenGoalValue == "ON");
        }

        m_GoldenGoalEnabled = goldenGoal;
    }
    private void Internal_FillMatchSettingsModule()
    {
        tnMatchSettingsModule module = GameModulesManager.GetModuleMain <tnMatchSettingsModule>();

        if (module == null)
        {
            return;
        }

        string gameModeId            = GetGameModeId(m_GameMode);
        string ballId                = GetBallId(m_Ball);
        string stadiumId             = GetStadiumId(m_Stadium);
        string matchDurationOptionId = GetMatchDurationOptionId(m_MatchDuration);
        string goldenGoalOptionId    = GetGoldenGoalOptionId(m_GoldenGoal);
        string refereeOptionId       = GetRefereeOptionId(m_Referee);

        module.SetGameModeId(gameModeId);
        module.SetBallId(ballId);
        module.SetStadiumId(stadiumId);
        module.SetMatchDurationOption(matchDurationOptionId);
        module.SetGoldenGoalOption(goldenGoalOptionId);
        module.SetRefereeOption(refereeOptionId);
    }
        public override void OnEnter()
        {
            tnMatchSettingsModule module = GameModulesManager.GetModuleMain <tnMatchSettingsModule>();

            if (module != null)
            {
                int            gameModeId   = module.gameModeId;
                tnGameModeData gameModeData = tnGameData.GetGameModeDataMain(gameModeId);

                if (gameModeData != null)
                {
                    int          camerasSetId = gameModeData.camerasSetId;
                    tnCamerasSet camerasSet   = tnGameData.GetCameraSetMain(camerasSetId);

                    if (camerasSet != null)
                    {
                        int           stadiumId   = module.stadiumId;
                        tnStadiumData stadiumData = tnGameData.GetStadiumDataMain(stadiumId);

                        if (stadiumData != null)
                        {
                            GameObject cameraPrefab = camerasSet.GetCamera(stadiumData.cameraId);

                            if (cameraPrefab != null)
                            {
                                if (storeResult != null && !storeResult.IsNone)
                                {
                                    storeResult.Value = cameraPrefab.gameObject;
                                }
                            }
                        }
                    }
                }
            }

            Finish();
        }
    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);
        }
    }
    private void SpawnBall()
    {
        tnMatchSettingsModule matchSettingsModule = GameModulesManager.GetModuleMain <tnMatchSettingsModule>();

        if (matchSettingsModule == null)
        {
            return;
        }

        int ballId = matchSettingsModule.ballId;

        m_BallId = ballId;

        tnBallData ballData = tnGameData.GetBallDataMain(m_BallId);

        if (ballData == null)
        {
            return;
        }

        tnBall ballPrefab = tnGameData.LoadAndGetBallPrefabMain();

        if (ballPrefab == null)
        {
            return;
        }

        GameObject ballSpawnPointGo = GameObject.Find(s_BallSpawnPoint);

        if (ballSpawnPointGo == null)
        {
            return;
        }

        TSTransform2D ballSpawnPointTransform = ballSpawnPointGo.GetComponent <TSTransform2D>();

        if (ballSpawnPointTransform == null)
        {
            return;
        }

        Vector3    spawnPosition = ballSpawnPointTransform.position.ToVector();
        Quaternion spawnRotation = Quaternion.Euler(0f, 0f, ballSpawnPointTransform.rotation.AsFloat());

        // Spawn ball.

        tnBall ballInstance = Instantiate <tnBall>(ballPrefab);

        ballInstance.gameObject.name = "Ball";

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

        // Can rotate?

        ballInstance.SetCanRotate(ballData.canRotate);

        // Configure TSTransform

        TSTransform2D tsTransform = ballInstance.GetComponent <TSTransform2D>();

        if (tsTransform != null)
        {
            tsTransform.position = ballSpawnPointTransform.position;
            tsTransform.rotation = ballSpawnPointTransform.rotation;
        }

        // Set ball texture and material.

        tnBallView ballView = ballInstance.GetComponent <tnBallView>();

        if (ballView != null)
        {
            Texture ballTexture = ballData.texture;
            ballView.SetTexture(ballTexture);

            ballView.SetTrailMaterial(ballData.trailMaterial);
            ballView.SetParticleEffect(ballData.particleEffect);
        }

        // Set depth level

        tnDepth2d depth2d = ballInstance.GetComponent <tnDepth2d>();

        if (depth2d != null)
        {
            depth2d.SetOffset(ballSpawnPointGo.transform.position.z);
        }

        // Register True Sync Obejct.

        TrueSyncManager.RegisterTrueSyncObjectMain(ballInstance.gameObject);

        // Bind to camera.

        if (cameraGo != null)
        {
            tnGameCamera gameCamera = cameraGo.GetComponent <tnGameCamera>();
            if (gameCamera != null)
            {
                gameCamera.SetTarget(ballInstance.transform);
            }
        }

        // Bind to slow motion controller.

        if (m_SlowMotionController != null)
        {
            TSRigidBody2D ballRigidbody = ballInstance.GetComponent <TSRigidBody2D>();
            if (ballRigidbody != null)
            {
                m_SlowMotionController.SetTarget(ballRigidbody);
            }
        }

        // Set Bounds of field for respown if ball go out of the field.

        GameObject topLeft     = GameObject.Find(s_TopLeft_Bound);
        GameObject bottomRight = GameObject.Find(s_BottomRight_Bound);

        if (topLeft != null && bottomRight != null)
        {
            TSTransform2D tsTransformTopLeft     = topLeft.GetComponent <TSTransform2D>();
            TSTransform2D tsTransformBottomRight = bottomRight.GetComponent <TSTransform2D>();

            if (tsTransformTopLeft != null && tsTransformBottomRight != null)
            {
                FP minX = tsTransformTopLeft.position.x;
                FP minY = tsTransformBottomRight.position.y;
                FP maxX = tsTransformBottomRight.position.x;
                FP maxY = tsTransformTopLeft.position.y;

                TSVector2 min = new TSVector2(minX, minY);
                TSVector2 max = new TSVector2(maxX, maxY);

                ballInstance.SetBoundLimits(min, max);
                ballInstance.SetSafeRespawnOutField(true);
            }
        }

        // Save instance.

        m_Ball = ballInstance;
    }
Exemplo n.º 24
0
    private void CreateCamera()
    {
        GameObject spawnPointGo = GameObject.Find(s_Camera_SpawnPoint_Name);

        Vector3 spawnPointPosition = (spawnPointGo != null) ? spawnPointGo.transform.position : Vector3.zero;

        spawnPointPosition.z = -15f;

        tnMatchSettingsModule matchSettingsModule = GameModulesManager.GetModuleMain <tnMatchSettingsModule>();

        if (matchSettingsModule == null)
        {
            return;
        }

        int            gameModeId   = matchSettingsModule.gameModeId;
        tnGameModeData gameModeData = tnGameData.GetGameModeDataMain(gameModeId);

        if (gameModeData == null)
        {
            return;
        }

        int          cameraSetId = gameModeData.camerasSetId;
        tnCamerasSet cameraSet   = tnGameData.GetCameraSetMain(cameraSetId);

        if (cameraSet == null)
        {
            return;
        }

        int           stadiumId   = matchSettingsModule.stadiumId;
        tnStadiumData stadiumData = tnGameData.GetStadiumDataMain(stadiumId);

        if (stadiumData == null)
        {
            return;
        }

        GameObject cameraPrefab = cameraSet.GetCamera(stadiumData.cameraId);

        if (cameraPrefab == null)
        {
            return;
        }

        m_GameCameraGO      = Instantiate <GameObject>(cameraPrefab);
        m_GameCameraGO.name = "GameCamera";
        m_GameCameraGO.tag  = "GameCamera";

        tnGameCamera gameCamera = m_GameCameraGO.GetComponent <tnGameCamera>();

        if (gameCamera != null)
        {
            gameCamera.SetPosition(spawnPointPosition);
        }
        else
        {
            m_GameCameraGO.transform.position = spawnPointPosition;
        }

        m_GameCameraGO.transform.rotation = Quaternion.identity;
    }
    private void SpawnReferee()
    {
        tnMatchSettingsModule matchSettingsModule = GameModulesManager.GetModuleMain <tnMatchSettingsModule>();

        if (matchSettingsModule == null)
        {
            return;
        }

        int refereeOptionId = matchSettingsModule.refereeOption;

        m_HasReferee = false;

        string refereeOption;

        if (tnGameData.TryGetRefereeValueMain(refereeOptionId, out refereeOption))
        {
            m_HasReferee = (refereeOption == "ON");
            if (m_HasReferee)
            {
                GameObject refereeSpawnPointGo = GameObject.Find(s_RefereeSpawnPoint);

                if (refereeSpawnPointGo == null)
                {
                    return;
                }

                TSTransform2D refereeSpawnPointTransform = refereeSpawnPointGo.GetComponent <TSTransform2D>();

                if (refereeSpawnPointTransform == null)
                {
                    return;
                }

                GameObject refereePrefab = Resources.Load <GameObject>(s_ResourcePath_Referee);
                if (refereePrefab != null)
                {
                    Vector3    spawnPosition = refereeSpawnPointTransform.position.ToVector();
                    Quaternion spawnRotation = Quaternion.Euler(0f, 0f, refereeSpawnPointTransform.rotation.AsFloat());

                    GameObject refereeInstance = Instantiate <GameObject>(refereePrefab);
                    refereeInstance.gameObject.name = "Referee";

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

                    // Configure TSTransform

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

                    // Configure input filler and tnCharacterInput.

                    if (PhotonNetwork.isMasterClient)
                    {
                        tnRefereeInputFiller inputFiller = new tnRefereeInputFiller(refereeInstance);
                        inputFiller.SetBall(m_Ball);

                        tnInputController inputController = new tnInputController(inputFiller);
                        AddInputController(inputController);

                        tnCharacterInput characterInput = refereeInstance.GetComponent <tnCharacterInput>();
                        if (characterInput != null)
                        {
                            characterInput.Bind(inputController);
                        }

                        RegisterObjectOnInputCollector(refereeInstance, 0);
                    }

                    // Configure depth2d.

                    tnDepth2d depth2d = refereeInstance.GetComponent <tnDepth2d>();
                    if (depth2d != null)
                    {
                        depth2d.SetOffset(refereeSpawnPointGo.transform.position.z);
                    }

                    // Setup true sync object.

                    TrueSyncObject trueSyncObject = refereeInstance.GetComponent <TrueSyncObject>();
                    if (trueSyncObject != null)
                    {
                        int ownerId = 0;
                        if (!PhotonNetwork.offlineMode && (PhotonNetwork.masterClient != null))
                        {
                            ownerId = PhotonNetwork.masterClient.ID;
                        }

                        trueSyncObject.SetOwnerId(ownerId);

                        TrueSyncManager.RegisterTrueSyncObjectMain(trueSyncObject);
                    }

                    m_RefereeInstance = refereeInstance;
                }
            }
        }
    }
Exemplo n.º 26
0
    private void SpawnCharacter(int i_TeamIndex, int i_TeamSize, int i_SpawnIndex, int i_PhotonPlayerId, tnCharacterDescription i_CharacterDescription)
    {
        if (m_CharacterPrefab == null || i_CharacterDescription == null)
        {
            return;
        }

        int descriptorCharacterId       = i_CharacterDescription.characterId;
        int descriptorOnlinePlayerIndex = i_CharacterDescription.onlinePlayerIndex;
        int descriptorPlayerId          = i_CharacterDescription.playerId;

        string[] spawnPointsNames = SpawnPoints.GetSpawnPoints(i_TeamIndex, i_TeamSize);

        if (spawnPointsNames == null)
        {
            return;
        }

        if (i_SpawnIndex < 0 || i_SpawnIndex >= spawnPointsNames.Length)
        {
            return;
        }

        string     spawnPointName = spawnPointsNames[i_SpawnIndex];
        GameObject spawnPointGo   = GameObject.Find(spawnPointName);

        if (spawnPointGo == null)
        {
            return;
        }

        TSTransform2D spawnPoint = spawnPointGo.GetComponent <TSTransform2D>();

        if (spawnPoint == null)
        {
            return;
        }

        tnCharacterData characterData = tnGameData.GetCharacterDataMain(descriptorCharacterId);

        if (characterData == null)
        {
            return;
        }

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

        if (teamsModule == null)
        {
            return;
        }

        tnTeamDescription teamDescription = teamsModule.GetTeamDescription(i_TeamIndex);

        if (teamDescription == null)
        {
            return;
        }

        int   teamId    = teamDescription.teamId;
        Color teamColor = teamDescription.teamColor;

        tnTeamData teamData = tnGameData.GetTeamDataMain(teamId);

        if (teamData == null)
        {
            return;
        }

        bool isLocal = (PhotonNetwork.offlineMode) ? true : tnGameModulesUtils.IsLocalPlayer(descriptorOnlinePlayerIndex);
        bool isHuman = (PhotonNetwork.offlineMode) ? (descriptorPlayerId != Hash.s_NULL) : (descriptorOnlinePlayerIndex >= 0);

        Vector3    spawnPosition = spawnPoint.position.ToVector();
        Quaternion spawnRotation = Quaternion.Euler(0f, 0f, spawnPoint.rotation.AsFloat());

        // Spawn character.

        GameObject characterInstance = Instantiate <GameObject>(m_CharacterPrefab);

        characterInstance.name = characterData.displayName;

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

        // Configure TSTransform

        TSTransform2D tsTransform = characterInstance.GetComponent <TSTransform2D>();

        if (tsTransform != null)
        {
            tsTransform.position = spawnPoint.position;
            tsTransform.rotation = spawnPoint.rotation;
        }

        // Configure depth2d.

        tnDepth2d depth2d = characterInstance.GetComponent <tnDepth2d>();

        if (depth2d != null)
        {
            depth2d.SetOffset(spawnPointGo.transform.position.z);
        }

        // Configure character stats database.

        tnStatsDatabase teamStats = teamData.teamStats;

        tnStatsContainer statsContainer = characterInstance.GetComponent <tnStatsContainer>();

        if (statsContainer != null)
        {
            statsContainer.SetStatsDatabase(teamStats);
        }

        // Configure character view.

        tnCharacterViewController characterViewController = characterInstance.GetComponent <tnCharacterViewController>();

        if (characterViewController != null)
        {
            // Base color.

            characterViewController.SetBaseColor(teamColor);

            // Charging force bar.

            characterViewController.SetChargingForceBarColor(teamColor);

            // Energy bar.

            characterViewController.SetEnergyBarColor(teamColor);

            // Flag.

            characterViewController.SetFlagSprite(teamData.baseSprite);

            // Animator

            characterViewController.SetAnimatorController(characterData.animatorController);

            // Set facing right.

            characterViewController.SetFacingRight((spawnPoint.position.x < 0f));

            // Player color.

            characterViewController.TurnOffColor();
            characterViewController.SetArrowVisible(false);
            characterViewController.SetArrowColor(Color.white);

            if (isLocal)
            {
                if (PhotonNetwork.offlineMode)
                {
                    if (isHuman)
                    {
                        tnPlayerData playerData = tnGameData.GetPlayerDataMain(descriptorPlayerId);
                        if (playerData != null)
                        {
                            Color playerColor = playerData.color;

                            characterViewController.SetPlayerColor(playerColor);

                            characterViewController.SetArrowVisible(true);
                            characterViewController.SetArrowColor(playerColor);
                        }
                    }
                }
                else
                {
                    List <int> onlinePlayersKeys = tnGameData.GetOnlinePlayersKeysMain();
                    if (onlinePlayersKeys != null)
                    {
                        if (descriptorOnlinePlayerIndex >= 0 && descriptorOnlinePlayerIndex < onlinePlayersKeys.Count)
                        {
                            int onlinePlayerKey = onlinePlayersKeys[descriptorOnlinePlayerIndex];
                            tnOnlinePlayerData onlinePlayerData = tnGameData.GetOnlinePlayerDataMain(onlinePlayerKey);
                            if (onlinePlayerData != null)
                            {
                                Color playerColor = onlinePlayerData.color;

                                characterViewController.SetPlayerColor(playerColor);

                                characterViewController.SetArrowVisible(true);
                                characterViewController.SetArrowColor(playerColor);
                            }
                        }
                    }
                }
            }
        }

        // Input: NOTE that current aiFacotry assumes that all AI are handled by the same client.
        // If you want to support AI in multiplayer you should change the ai factory implementation.
        // Now multiplayer isn't implemented, so now, if you're using AI, you are playing offline --> All AIs are yours.

        if (isLocal)
        {
            tnInputFiller      inputFiller      = null;
            tnRumbleController rumbleController = null;

            int  localPlayerIndex;
            bool localPlayerIndexFound = tnGameModulesUtils.OnlineToLocalPlayerIndex(descriptorOnlinePlayerIndex, out localPlayerIndex);
            if (localPlayerIndexFound || PhotonNetwork.offlineMode)
            {
                tnLocalPartyModule localPartyModule = GameModulesManager.GetModuleMain <tnLocalPartyModule>();

                int          playerId   = (PhotonNetwork.offlineMode) ? descriptorPlayerId : ((localPartyModule != null) ? localPartyModule.GetPlayerId(localPlayerIndex) : Hash.s_NULL);
                tnPlayerData playerData = tnGameData.GetPlayerDataMain(playerId);

                if (playerData != null)
                {
                    string playerInputName     = playerData.playerInputName;
                    string wifiPlayerInputName = playerData.wifiPlayerInputName;

                    PlayerInput     playerInput     = InputSystem.GetPlayerByNameMain(playerInputName);
                    WiFiPlayerInput wifiPlayerInput = WiFiInputSystem.GetPlayerByNameMain(wifiPlayerInputName);

                    if (playerInput != null)
                    {
                        inputFiller      = new tnPlayerInputFiller(playerInput);
                        rumbleController = new tnRumbleController(playerInput);

                        m_LocalPlayersInput.Add(playerInput);
                    }
                    else
                    {
                        if (wifiPlayerInput != null)
                        {
                            inputFiller = new tnWiFiPlayerInputFiller(wifiPlayerInput);

                            m_LocalWifiPlayersInput.Add(wifiPlayerInput);
                        }
                    }
                }
                else
                {
                    tnAIInputFiller aiInputFiller = CreateAIInputFiller(i_TeamIndex, i_SpawnIndex, characterInstance);
                    inputFiller = aiInputFiller;

                    List <tnAIInputFiller> aiList = m_LocalAI[i_TeamIndex];
                    aiList.Add(aiInputFiller);
                }
            }

            // Bind input filler to character instance.

            if (inputFiller != null)
            {
                tnInputController inputController = new tnInputController(inputFiller);
                inputController.SetRumbleController(rumbleController);

                AddInputController(inputController);

                tnCharacterInput characterInput = characterInstance.GetComponent <tnCharacterInput>();
                if (characterInput != null)
                {
                    characterInput.Bind(inputController);
                }
            }

            // Add rumble component.

            if (isHuman)
            {
                tnRumbleParams rumbleParams = Resources.Load <tnRumbleParams>(s_RumbleParams_ResourcePath);

                if (rumbleParams != null)
                {
                    tnRumble rumbleComponent = characterInstance.GetComponent <tnRumble>();
                    if (rumbleComponent == null)
                    {
                        rumbleComponent = characterInstance.AddComponent <tnRumble>();
                    }

                    rumbleComponent.SetParams(rumbleParams);
                }
            }

            // Input Delay.

            int delay = (TrueSyncManager.isOfflineMain) ? m_OfflinePlayerInputDelay : 0;

            if (!isHuman)
            {
                tnMatchSettingsModule matchSettingsModule = GameModulesManager.GetModuleMain <tnMatchSettingsModule>();
                int       aiLevelIndex = (matchSettingsModule != null) ? matchSettingsModule.aiLevelIndex : (tnGameData.aiLevelCountMain / 2);
                tnAILevel aiLevel      = tnGameData.GetAILevelMain(aiLevelIndex);
                if (aiLevel != null)
                {
                    delay = aiLevel.inputDelay;
                }
            }

            // Register on player input collector.

            RegisterObjectOnInputCollector(characterInstance, delay);
        }

        // Configure character info.

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

        if (characterInfo == null)
        {
            characterInfo = characterInstance.AddComponent <tnCharacterInfo>();
        }

        int characterIndex = m_Characters.Count;

        characterInfo.SetCharacterIndex(characterIndex);
        characterInfo.SetCharacterId(descriptorCharacterId);
        characterInfo.SetTeamIndex(i_TeamIndex);
        characterInfo.SetTeamId(teamId);
        characterInfo.SetTeamColor(teamColor);

        // Callback.

        OnCharacterSpawned(i_TeamIndex, characterIndex, characterInstance);

        // Add characters to lists.

        m_Characters.Add(characterInstance);
        if (isLocal)
        {
            m_LocalCharacters.Add(characterInstance);
        }

        List <GameObject> team = m_Teams[i_TeamIndex];

        team.Add(characterInstance);

        // Create character result.

        tnCharacterResults characterResults = CreateCharacterResults(descriptorCharacterId);

        characterResults.isHuman = isHuman;

        tnTeamResults teamResults = GetTeamResultsByIndex(i_TeamIndex);

        if (teamResults != null)
        {
            teamResults.AddCharacterResults(characterResults);
        }

        m_CharactersResults.Add(characterResults);

        // Track character result.

        StateTracker.AddTracking(characterResults);

        // Configure TrueSyncObject.

        TrueSyncObject trueSyncObject = characterInstance.GetComponent <TrueSyncObject>();

        if (trueSyncObject != null)
        {
            trueSyncObject.SetOwnerId(i_PhotonPlayerId);
            TrueSyncManager.RegisterTrueSyncObjectMain(trueSyncObject);
        }
    }