Esempio n. 1
0
        private bool UpdateCache(GameObject i_Go)
        {
            if (i_Go == null)
            {
                return(false);
            }

            if (m_Target == null || m_CachedGameObject != i_Go)
            {
                m_Target           = i_Go.GetComponent <tnGameCamera>();
                m_CachedGameObject = i_Go;
            }

            return(m_Target != null);
        }
    void Awake()
    {
        m_MatchController = FindObjectOfType <tnMatchController>();

        if (m_MatchController == null)
        {
            Debug.LogWarning("[tnCameraZoom] Missing MatchController.");
        }

        m_GameCamera = FindObjectOfType <tnGameCamera>();

        if (m_GameCamera == null)
        {
            Debug.LogWarning("[tnCameraZoom] Missing GameCamera.");
        }
    }
    protected override void OnGoal(tnGoalEventParams i_Params)
    {
        base.OnGoal(i_Params);

        int currentTick = TrueSyncManager.ticksMain;

        if (!m_GoalEffectsTicks.Contains(currentTick))
        {
            // Play effects.

            SfxPlayer.PlayMain(m_GoalSfx);

            // Play celebration animation and screen shake.

            tnScreenShake screenShake = null;
            tnGameCamera  gameCamera  = cameraGo.GetComponent <tnGameCamera>();
            if (gameCamera != null)
            {
                screenShake = gameCamera.GetComponentInChildren <tnScreenShake>();
            }

            if (m_CelebrationPanel != null)
            {
                m_CelebrationPanel.SetCelebrationText(i_Params.scorerId);
                m_CelebrationPanel.StartCelebration();
            }

            if (screenShake != null)
            {
                screenShake.ForceShake(m_CelebrationShakeTime, m_CelebrationShakeAmount, ShakeMode.Interruput);
            }

            m_GoalEffectsTicks.Add(currentTick);
        }

        // Update results.

        for (int teamResultsIndex = 0; teamResultsIndex < teamsCount; ++teamResultsIndex)
        {
            tnStandardMatchTeamResults teamResults = (tnStandardMatchTeamResults)GetTeamResultsByIndex(teamResultsIndex);
            if (teamResults != null)
            {
                if (teamResults.id != i_Params.teamId) // Assign a score to the team.
                {
                    ++teamResults.score;
                }
            }
        }

        if (i_Params.hasValidScorer)
        {
            if (!i_Params.isOwnGoal)
            {
                tnStandardMatchCharacterResults characterResults = (tnStandardMatchCharacterResults)GetCharacterResultsById(i_Params.scorerId);
                if (characterResults != null)
                {
                    ++characterResults.goalScored;
                }
            }
        }
    }
Esempio n. 4
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;
    }
    protected override void LateSyncedUpdate()
    {
        base.LateSyncedUpdate();

        // Get delta time.

        FP  deltaTime      = TrueSyncManager.deltaTimeMain;
        int rollbackWindow = Mathf.Max(1, TrueSyncManager.rollbackWindowMain); // Max handle cases with zero rollback.
        int currentTick    = TrueSyncManager.ticksMain;

        // Check for end game request.

        if (m_EndGameRequestTick > 0)
        {
            if (currentTick == m_EndGameRequestTick + rollbackWindow)
            {
                m_EndGameRequestTick = 0;
                RequestEndGame();
            }

            return;
        }

        // Check for kick off.

        if (m_Waiting)
        {
            if (m_KickOffRequestTick > 0)
            {
                if (currentTick == m_KickOffRequestTick + rollbackWindow)
                {
                    Debug.Log("Kick off: " + TrueSyncManager.ticksMain + " (" + m_KickOffRequestTick + ")");

                    m_KickOffRequestTick = 0;

                    // Kick off.

                    KickOff();

                    // Enable player behaviours

                    SetPlayerBehavioursEnabled(true);
                }
            }

            // Check waiting for go.

            if (m_WaitingForGo)
            {
                m_WaitForGoTimer -= deltaTime;
                if (m_WaitForGoTimer < FP.Zero)
                {
                    m_WaitForGoTimer = FP.Zero;
                    m_WaitingForGo   = false;

                    // Set ready for kick off.

                    m_KickOffRequestTick = TrueSyncManager.ticksMain;
                }
            }

            if (m_ResetFieldRequestTick > 0)
            {
                if (currentTick == m_ResetFieldRequestTick + rollbackWindow)
                {
                    Debug.Log("Reset field: " + TrueSyncManager.ticksMain + " (" + m_ResetFieldRequestTick + ")");

                    m_ResetFieldRequestTick = 0;

                    // Disable input.

                    DisableInput();

                    // Reset field.

                    ResetField();

                    // Disable player behaviours

                    SetPlayerBehavioursEnabled(false);

                    // Reset camera position.

                    tnGameCamera gameCamera = (cameraGo != null) ? cameraGo.GetComponent <tnGameCamera>() : null;
                    if (gameCamera != null)
                    {
                        gameCamera.ResetPosition();
                    }

                    // Set waiting for go.

                    m_WaitingForGo   = true;
                    m_WaitForGoTimer = m_WaitBetweenResetAndGo;
                }
            }

            // Check celbration.

            if (m_Celebrating)
            {
                // Check timer.

                m_CelebrationTimer -= deltaTime;
                if (m_CelebrationTimer < FP.Zero)
                {
                    m_CelebrationTimer = FP.Zero;
                    m_Celebrating      = false;

                    // Check if game is ended or it should be continue.

                    if (m_GoldenGoal)
                    {
                        // Game is ended.

                        m_EndGameRequestTick = TrueSyncManager.ticksMain;
                    }
                    else
                    {
                        // Request reset field.

                        m_ResetFieldRequestTick = TrueSyncManager.ticksMain;
                    }
                }
            }

            return;
        }

        // Check for goal.

        if (m_GoalTick > 0)
        {
            if (currentTick == m_GoalTick + rollbackWindow)
            {
                // Reset goal tick.

                m_GoalTick = 0;

                // Disable slow motion controller.

                SetSlowMotionEnabled(false);

                // Stop.

                m_Waiting = true;

                m_Celebrating      = true;
                m_CelebrationTimer = m_CelebrationDuration;

                // Disable AI input (local).

                DisableAIInput();

                // Callback.

                OnGoal(m_GoalParamsCache);

                // Raise event.

                Messenger.Broadcast <tnGoalEventParams>(s_ValidatedGoal_MessengerEvent, m_GoalParamsCache);

                return;
            }
        }

        if (m_InfiniteTime)
        {
            return;
        }

        // Update match timer.

        m_MatchTime += deltaTime;

        // Check match time for ending.

        if (m_MatchTime > m_MatchDuration)
        {
            if (!Draw())
            {
                m_EndGameRequestTick = TrueSyncManager.ticksMain;
            }
            else
            {
                if (!m_GoldenGoalEnabled)
                {
                    m_EndGameRequestTick = TrueSyncManager.ticksMain;
                }
                else
                {
                    if (!m_GoldenGoal)
                    {
                        m_GoldenGoal = true;

                        OnGoldenGoalStart();
                    }
                }
            }
        }
    }
    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;
    }