Пример #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);
                    }
                }
            }
        }
    }
    // INTERNALS

    private bool Kick(LayerMask i_Mask, FP i_AppliedForce, FP i_DeltaTime, bool i_InvertVelocity = false)
    {
        bool kickedAnything = false;

        TSCollider2D[] colliders = TSPhysics2D.OverlapCircleAll(tsTransform2D.position, m_Radius, i_Mask);

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

                if (currentCollider == null)
                {
                    continue;
                }

                GameObject currentGo = currentCollider.gameObject;

                if (m_CharacterController != null)
                {
                    int currentLayer = m_CharacterController.currentLayer;

                    if (currentLayer == m_ChargingLayer)
                    {
                        continue;
                    }
                }

                tnKickable kickable = currentGo.GetComponent <tnKickable>();

                if (kickable == null)
                {
                    continue;
                }

                TSTransform2D kickableTransform = kickable.tsTransform2D;

                if (kickableTransform == null)
                {
                    continue;
                }

                TSVector2 kickablePosition = kickableTransform.position;

                kickedAnything = true;

                // Evaluate force.

                TSVector2 direction = kickablePosition - tsTransform2D.position;
                direction.Normalize();

                TSVector2 force = direction * i_AppliedForce;

                if (i_InvertVelocity)
                {
                    if (i_DeltaTime > FP.Zero)
                    {
                        FP        otherMass     = kickable.mass;
                        TSVector2 otherVelocity = kickable.currentVelocity;

                        TSVector2 oppositeForce = (otherMass * otherVelocity) / i_DeltaTime;
                        oppositeForce = oppositeForce * -FP.One;
                        force        += oppositeForce;
                    }
                }

                // Kick.

                kickable.Kick(force, gameObject);

                // Notify listeners.

                if (m_KickEvent != null)
                {
                    m_KickEvent(kickable);
                }
            }
        }

        return(kickedAnything);
    }