Ejemplo n.º 1
0
    public override void OnInspectorGUI()
    {
        base.OnInspectorGUI();

        if (EditorApplication.isPlaying)
        {
            tnBall ball = target as tnBall;

            if (ball == null)
            {
                return;
            }

            TSRigidBody2D rigidbody = ball.GetComponent <TSRigidBody2D>();
            TSVector2     velocity  = (rigidbody != null) ? rigidbody.velocity : TSVector2.zero;
            FP            speed     = velocity.magnitude;

            EditorGUILayout.Space();
            EditorGUILayout.LabelField("Speed: " + speed.ToString(2), EditorStyles.label);
        }
    }
 public void SetBall(tnBall i_BallInstance)
 {
     m_Ball = i_BallInstance;
 }
    public tnBall LoadAndGetBallPrefab()
    {
        tnBall prefab = Resources.Load <tnBall>(m_BallPrefabPath);

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