Example #1
0
    public void RegisterVolumeExited(Collider2D collision)
    {
        Rigidbody2D rigidBody = collision.GetComponent <Rigidbody2D>();

        if (rigidBody == null || !storedConfigs.ContainsKey(rigidBody.gameObject))
        {
            return;
        }

        RigidBodyConfig config = storedConfigs[rigidBody.gameObject];

        config.Apply(rigidBody);


        if (queuedRegistrations[rigidBody.gameObject].Count > 0)
        {
            RigidBodyConfig queuedConfig = queuedRegistrations[rigidBody.gameObject].Dequeue();
            queuedConfig.Apply(rigidBody);
        }
        else
        {
            storedConfigs.Remove(rigidBody.gameObject);
            queuedRegistrations.Remove(rigidBody.gameObject);
        }
    }
Example #2
0
    public void RegisterVolumeEntered(Collider2D collision, RigidBodyConfig underwaterConfig)
    {
        Rigidbody2D rigidBody = collision.GetComponent <Rigidbody2D>();

        if (rigidBody == null)
        {
            return;
        }

        bool isAlreadyRegistered = storedConfigs.ContainsKey(rigidBody.gameObject);

        if (isAlreadyRegistered)
        {
            queuedRegistrations[rigidBody.gameObject].Enqueue(underwaterConfig);
        }
        else
        {
            StoreRigidBodyConfig(rigidBody);
            CreateQueueForRigidBody(rigidBody);

            underwaterConfig.Apply(rigidBody);
        }
    }