public tnBallData GetData(int i_Id)
    {
        tnBallData data = null;

        m_Data.TryGetValue(i_Id, out data);
        return(data);
    }
    // LOGIC

    public void Initialize(string i_DatabasePath)
    {
        tnBallsDatabase database = Resources.Load <tnBallsDatabase>(i_DatabasePath);

        if (database != null)
        {
            m_BallPrefabPath = database.ballPrefabPath;

            for (int index = 0; index < database.ballsCount; ++index)
            {
                tnBallDataEntry entry = database.GetBallDataEntry(index);
                if (entry != null)
                {
                    string key = entry.id;
                    tnBallDataDescriptor descriptor = entry.descriptor;
                    if (key != "" && descriptor != null)
                    {
                        int        hash = StringUtils.GetHashCode(key);
                        tnBallData data = new tnBallData(descriptor);

                        m_Data.Add(hash, data);
                        m_Keys.Add(hash);
                    }
                }
            }
        }
        else
        {
            LogManager.LogWarning(this, "Database not loaded.");
        }
    }
    private void InitBallSelector()
    {
        if (m_BallSelector == null)
        {
            return;
        }

        SelectorData selectorData = new SelectorData();

        List <int> ballKeys = tnGameData.GetBallsKeysMain();

        if (ballKeys != null)
        {
            for (int ballIndex = 0; ballIndex < ballKeys.Count; ++ballIndex)
            {
                int        ballId   = ballKeys[ballIndex];
                tnBallData ballData = tnGameData.GetBallDataMain(ballId);

                SelectorItem selectorItem = new SelectorItem(ballId, ballData.name, "", ballData.icon);
                selectorData.AddItem(selectorItem);
            }
        }

        m_BallSelector.SetData(selectorData);
    }
Example #4
0
    // Ball

    private void SetupBallSelector()
    {
        SelectorData selectorData = new SelectorData();

        List <int> ballKeys = tnGameData.GetBallsKeysMain();

        if (ballKeys != null)
        {
            for (int index = 0; index < ballKeys.Count; ++index)
            {
                int key = ballKeys[index];

                if (Hash.IsNullOrEmpty(key))
                {
                    continue;
                }

                tnBallData ballData = tnGameData.GetBallDataMain(key);

                if (ballData == null)
                {
                    continue;
                }

                SelectorItem selectorItem = new SelectorItem(key, ballData.name, "", ballData.icon);
                selectorData.AddItem(selectorItem);
            }
        }

        if (viewInstance != null)
        {
            viewInstance.SetBallSelectorData(selectorData);
        }
    }
    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;
    }