Ejemplo n.º 1
0
    // INTERNALS

    public void UpdateEffector()
    {
        TSCollider2D[] colliders = TSPhysics2D.OverlapCircleAll(tsTransform2D.position, m_Radius, m_LayerMask);

        if (colliders != null)
        {
            if (colliders.Length > 0)
            {
                for (int index = 0; index < colliders.Length; ++index)
                {
                    TSCollider2D currentCollider = colliders[index];

                    if (currentCollider == null)
                    {
                        continue;
                    }

                    TSTransform2D transform2d = currentCollider.tsTransform;

                    TSVector2 direction = transform2d.position - tsTransform2D.position;
                    direction = direction.normalized;

                    TSRigidBody2D rigidbody = currentCollider.GetComponent <TSRigidBody2D>();
                    if (rigidbody != null)
                    {
                        rigidbody.AddForce(direction * m_ForceMagnitude);
                    }
                }
            }
        }
    }
Ejemplo n.º 2
0
    /**
     * @brief Initial setup when game is started.
     **/
    public override void OnSyncedStart()
    {
        tsRigidBody    = GetComponent <TSRigidBody2D>();
        animator       = GetComponent <Animator> ();
        spriteRenderer = GetComponent <SpriteRenderer> ();

        // Sets sprite and animator controller based on player's id
        if (owner.Id == 1)
        {
            animator.runtimeAnimatorController = animatorControllers [0];
            spriteRenderer.sprite = sprites [0];

            tsRigidBody.position = new TSVector2(1, 0);
        }
        else
        {
            animator.runtimeAnimatorController = animatorControllers [1];
            spriteRenderer.sprite = sprites [1];
            spriteRenderer.flipX  = true;

            TSVector2 offset = new TSVector2(-0.63f, -0.87f);
            tsRigidBody.GetComponent <TSCollider2D>().Center = offset;
            tsRigidBody.position = new TSVector2(-1 - offset.x, 0);
        }

        // stops Animation
        animator.Stop();
        // take control of the animation
        animator.StopPlayback();
    }
    private static Vector2 GetRigidbody2dVelocity(GameObject i_Go)
    {
        if (i_Go == null)
        {
            return(Vector2.zero);
        }

#if PHOTON_TRUE_SYNC
        TSRigidBody2D tsRigidbody2d = i_Go.GetComponent <TSRigidBody2D>();
        if (tsRigidbody2d != null)
        {
            TSVector2 velocity = tsRigidbody2d.velocity;
            return(velocity.ToVector());
        }
#else
        Rigidbody2D rigidbody2d = i_Go.GetComponent <Rigidbody2D>();
        if (rigidbody2d != null)
        {
            Vector2 velocity = rigidbody2d.velocity;
            return(velocity);
        }
#endif // PHOTON_TRUE_SYNC

        return(Vector2.zero);
    }
Ejemplo n.º 4
0
    /**
     * @brief Initial setup when game is started.
     **/
    public override void OnSyncedStart()
    {
        StateTracker.AddTracking(this);

        paddleCountText = (Instantiate(paddleCountPrefab) as GameObject).GetComponent <Text>();
        paddleCountText.transform.SetParent(GameObject.Find("Canvas").transform, false);

        tsRigidBody = GetComponent <TSRigidBody2D>();

        // If paddle's owner is the first player then place it on top side
        if (owner.Id == 1)
        {
            Material redMatter = Resources.Load("RedMatter", typeof(Material)) as Material;
            GetComponent <MeshRenderer>().material = redMatter;

            tsRigidBody.position = new TSVector2(0, 8);
            // Adds this PaddleController in the {@link #paddlesBySide} dictionary with key being true (top size)
            paddlesBySide[true] = this;
        }
        else
        {
            tsRigidBody.position = new TSVector2(0, -8);
            // Adds this PaddleController in the {@link #paddlesBySide} dictionary with key being false (bottom size)
            paddlesBySide[false] = this;
        }
    }
Ejemplo n.º 5
0
    // MonoBehaviour's interface

    void Awake()
    {
        m_Rigidbody2d = GetComponent <TSRigidBody2D>();

        // Set sort order.

        sortOrder = BehaviourSortOrder.s_SortOrder_Respawn;
    }
    // MonoBehaviour's interface

    private void Awake()
    {
        m_Collider  = GetComponent <TSCollider2D>();
        m_Rigidbody = GetComponent <TSRigidBody2D>();

        // Set sort order.

        sortOrder = BehaviourSortOrder.s_SortOrder_HoleTarget;
    }
Ejemplo n.º 7
0
    // MonoBehaviour's interface

    void Awake()
    {
        m_MeshRenderer = GetComponentInChildren <MeshRenderer>();
        m_Trail        = GetComponentInChildren <TrailRenderer>();

        m_Rididbody2D = GetComponent <TSRigidBody2D>();

        m_Respawn = GetComponent <tnRespawn>();
    }
    // MonoBehaviour's INTERFACE

    void Awake()
    {
        // Cache components.

        {
            m_Rigidbody2D = GetComponentInChildren <TSRigidBody2D>();

            m_CharacterInput = GetComponentInChildren <tnCharacterInput>();
            m_Respawn        = GetComponentInChildren <tnRespawn>();

            m_Animator = GetComponentInChildren <Animator>();
        }

        // Set sort order.

        sortOrder = BehaviourSortOrder.s_SortOrder_SubbuteoController;
    }
    // MonoBehaviour's INTERFACE

    void Awake()
    {
        // Transform, Rigidbody and collider.

        m_Rigidbody2D = GetComponent <TSRigidBody2D>();

        // Mesh.

        m_Mesh = GetComponentInChildren <MeshRenderer>();

        // Extra components.

        m_Respawn = GetComponent <tnRespawn>();

        // Set sort order.

        sortOrder = BehaviourSortOrder.s_SortOrder_Ball;
    }
    protected Vector2 GetVehicleVelocity(GameObject i_Go)
    {
        if (i_Go == null)
        {
            return(Vector2.zero);
        }

        TSRigidBody2D rigidbody2d = i_Go.GetComponent <TSRigidBody2D>();

        if (rigidbody2d != null)
        {
            TSVector2 tsVelocity = rigidbody2d.velocity;
            Vector2   velocity   = tsVelocity.ToVector();
            return(velocity);
        }

        return(Vector2.zero);
    }
    protected float GetVehicleSpeed(GameObject i_Go)
    {
        if (i_Go == null)
        {
            return(0f);
        }

        TSRigidBody2D rigidbody2d = i_Go.GetComponent <TSRigidBody2D>();

        if (rigidbody2d != null)
        {
            TSVector2 tsVelocity = rigidbody2d.velocity;
            FP        tsSpeed    = tsVelocity.magnitude;
            float     speed      = tsSpeed.AsFloat();
            return(speed);
        }

        return(0f);
    }
    // MonoBehaviour's INTERFACE

    void Awake()
    {
        // Cache components.

        {
            m_Rigidbody2D = GetComponent <TSRigidBody2D>();
            m_Collider2D  = GetComponent <TSCollider2D>();

            m_CharacterInput = GetComponent <tnCharacterInput>();
            m_StatsContainer = GetComponent <tnStatsContainer>();
            m_Energy         = GetComponent <tnEnergy>();
            m_Respawn        = GetComponent <tnRespawn>();
        }

        // Init data.

        {
            m_OriginalLayer = gameObject.layer;
            m_DashLayer     = LayerMask.NameToLayer("Charging");
        }

        // Force values refresh.

        {
            ComputeAppliedForce(FP.Zero);
            ComputeMass(FP.Zero);
            ComputeDrag(FP.Zero);
            ComputeMaxSpeed(FP.Zero);

            ComputeDashMass(FP.Zero);
            ComputeDashDrag(FP.Zero);
            ComputeDashAppliedForce(FP.Zero);
            ComputeDashCooldown(FP.Zero);
            ComputeDashDuration(FP.Zero);
            ComputeDashEnergyCost(FP.Zero);
        }

        // Set sort order.

        sortOrder = BehaviourSortOrder.s_SortOrder_CharacterController;
    }
Ejemplo n.º 13
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 override void OnSyncedCollisionEnter(TSCollision2D i_Collision)
    {
        int tick = TrueSyncManager.ticksMain;

        // Apply forces.

        TSRigidBody2D rigidbody2D = i_Collision.gameObject.GetComponent <TSRigidBody2D>();

        if (rigidbody2D != null)
        {
            // Clear velocity.

            rigidbody2D.velocity = TSVector2.zero;

            // Add bounce force.

            TSVector2 otherPosition = rigidbody2D.position;
            TSVector2 myPostion     = tsTransform2D.position;

            TSVector2 direction = otherPosition - myPostion;
            direction.Normalize();

            TSVector2 force = direction * m_Force;

            rigidbody2D.AddForce(force);
        }

        // Play effect.

        if (!m_EffectTicks.Contains(tick))
        {
            m_Animator.SetTrigger("Hit");
            EffectUtils.PlayEffect(m_Effect, transform);

            m_EffectTicks.Add(tick);
        }
    }
Ejemplo n.º 15
0
    /**
     * @brief Initial setup when game is started.
     **/
    public override void OnSyncedStart()
    {
        StateTracker.AddTracking(this);

        tsRigidBody = GetComponent <TSRigidBody2D>();
    }
Ejemplo n.º 16
0
    public override void OnSyncedUpdate()
    {
        base.OnSyncedUpdate();

        if (!m_IsActive || m_HoleIndex < 0)
        {
            return;
        }

        // Get Simulation info.

        int currentTick    = TrueSyncManager.ticksMain;
        int rollbackWindow = TrueSyncManager.rollbackWindowMain;

        // Check current collision

        TSVector2 myPosition = tsTransform2D.position;

        for (int targetIndex = 0; targetIndex < m_Targets.Count; ++targetIndex)
        {
            tnHoleTarget holeTarget = m_Targets[targetIndex];

            if (holeTarget == null)
            {
                continue;
            }

            TSTransform2D otherTransform = holeTarget.GetComponent <TSTransform2D>();

            if (otherTransform == null)
            {
                continue;
            }

            TSVector2 targetPosition = otherTransform.position;

            TSVector2 positionDelta = targetPosition - myPosition;

            FP distance2 = positionDelta.LengthSquared();
            if (distance2 < m_Threshold * m_Threshold)
            {
                // Notify collision.

                holeTarget.CollidingWithHole();

                // Add object to pending list.

                if (holeTarget.canEnterHole && !holeTarget.isTeleporting)
                {
                    Internal_CacheTarget(currentTick, holeTarget);
                }
            }
        }

        // Check pending objects.

        for (int index = 0; index < m_Pending.count; ++index)
        {
            int tick = m_Pending.GetKey(index);

            if (currentTick == tick + rollbackWindow)
            {
                List <tnHoleTarget> holeTargets = m_Pending.GetValue(tick);
                if (holeTargets != null)
                {
                    for (int targetIndex = 0; targetIndex < holeTargets.Count; ++targetIndex)
                    {
                        tnHoleTarget holeTarget = holeTargets[targetIndex];

                        if (holeTarget == null)
                        {
                            continue;
                        }

                        RespawnPoint respawnPoint = GetRandomSpawnPoint();

                        if (respawnPoint == null || respawnPoint.transform == null)
                        {
                            continue;
                        }

                        TSTransform2D targetTransform = holeTarget.tsTransform2D;
                        TSRigidBody2D targetRigidbody = holeTarget.GetComponent <TSRigidBody2D>();

                        // Snap position.

                        if (targetRigidbody != null)
                        {
                            targetRigidbody.MovePosition(tsTransform2D.position);
                        }
                        else
                        {
                            targetTransform.position = tsTransform2D.position;
                        }

                        // Set rigidbody velocity,

                        if (targetRigidbody != null)
                        {
                            targetRigidbody.velocity = TSVector2.zero;
                        }

                        // Eavluate force

                        TSVector2 forceDirection = respawnPoint.forceDirection;
                        forceDirection.Normalize();

                        if (MathFP.Abs(respawnPoint.errorAngle) > FP.Zero)
                        {
                            int random      = TSRandom.Range(0, 101);
                            FP  t           = ((FP)random) / 100;
                            FP  randomError = MathFP.Lerp(-respawnPoint.errorAngle, respawnPoint.errorAngle, t);
                            forceDirection = forceDirection.Rotate(randomError);
                        }

                        TSVector2 outForce = forceDirection * respawnPoint.forceIntensity;

                        // Teleport.

                        holeTarget.Teleport(m_HoleIndex, respawnPoint.respawnPosition, outForce, m_RespawnTime, m_InEffect, m_OutEffect);
                    }
                }
            }
        }

        // Remove old data from dictionary.

        for (int index = 0; index < m_Pending.count; ++index)
        {
            int tick          = m_Pending.GetKey(index);
            int executionTick = tick + rollbackWindow;

            bool isSafeTick = TrueSyncManager.IsTickOutOfRollbackMain(executionTick);
            if (isSafeTick)
            {
                m_Pending.Remove(tick);
                index = -1;
            }
        }
    }
Ejemplo n.º 17
0
 public void SetTarget(TSRigidBody2D i_Target)
 {
     m_Reference          = i_Target;
     m_ReferenceTransform = (m_Reference != null) ? m_Reference.GetComponent <TSTransform2D>() : null;
 }
    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;
    }
Ejemplo n.º 19
0
 public TSRaycastHit2D(TSCollider2D collider)
 {
     this.collider  = collider;
     this.rigidbody = collider.GetComponent <TSRigidBody2D>();
     this.transform = collider.GetComponent <TSTransform2D>();
 }
Ejemplo n.º 20
0
 /**
  * @brief Initial setup.
  **/
 void Start()
 {
     audioSource = GetComponent <AudioSource>();
     tsRigidBody = GetComponent <TSRigidBody2D>();
 }