Example #1
0
 [DllImport("MassParticle")] public static extern void mpRemoveCollider(int context, ref MPColliderProperties props);
Example #2
0
 [DllImport("MassParticle")] public static extern void mpAddCapsuleCollider(int context, ref MPColliderProperties props, ref Vector3 pos1, ref Vector3 pos2, float radius);
Example #3
0
 public static extern void mpAddBoxCollider(int context, ref MPColliderProperties props, ref Matrix4x4 transform, ref Vector3 center, ref Vector3 size);
Example #4
0
    void UpdateMPObjects()
    {
        colliders.Clear();
        if (include3DColliders)
        {
            Collider[] colliders3d = Physics.OverlapSphere(transform.position, transform.localScale.magnitude);
            for (int i = 0; i < colliders3d.Length; ++i)
            {
                Collider col = colliders3d[i];
                if (col.isTrigger)
                {
                    continue;
                }

                MPColliderProperties cprops;
                bool recv = false;
                var  attr = col.gameObject.GetComponent <MPColliderAttribute>();
                if (attr)
                {
                    if (!attr.sendCollision)
                    {
                        continue;
                    }
                    attr.UpdateColliderProperties();
                    recv   = attr.receiveCollision;
                    cprops = attr.cprops;
                }
                else
                {
                    cprops = new MPColliderProperties();
                    cprops.SetDefaultValues();
                }
                int id = colliders.Count;
                cprops.owner_id = recv ? id : -1;
                colliders.Add(col.gameObject);

                SphereCollider  sphere  = col as SphereCollider;
                CapsuleCollider capsule = col as CapsuleCollider;
                BoxCollider     box     = col as BoxCollider;
                if (sphere)
                {
                    Vector3 pos = sphere.transform.position;
                    MPAPI.mpAddSphereCollider(ref cprops, ref pos, sphere.radius * col.gameObject.transform.localScale.magnitude * 0.5f);
                }
                else if (capsule)
                {
                    Vector3 e = Vector3.zero;
                    float   h = Mathf.Max(0.0f, capsule.height - capsule.radius * 2.0f);
                    float   r = capsule.radius * capsule.transform.localScale.x;
                    switch (capsule.direction)
                    {
                    case 0: e.Set(h * 0.5f, 0.0f, 0.0f); break;

                    case 1: e.Set(0.0f, h * 0.5f, 0.0f); break;

                    case 2: e.Set(0.0f, 0.0f, h * 0.5f); break;
                    }
                    Vector4 pos1 = new Vector4(e.x, e.y, e.z, 1.0f);
                    Vector4 pos2 = new Vector4(-e.x, -e.y, -e.z, 1.0f);
                    pos1 = capsule.transform.localToWorldMatrix * pos1;
                    pos2 = capsule.transform.localToWorldMatrix * pos2;
                    Vector3 pos13 = pos1;
                    Vector3 pos23 = pos2;
                    MPAPI.mpAddCapsuleCollider(ref cprops, ref pos13, ref pos23, r);
                }
                else if (box)
                {
                    Matrix4x4 mat  = box.transform.localToWorldMatrix;
                    Vector3   size = box.size;
                    MPAPI.mpAddBoxCollider(ref cprops, ref mat, ref size);
                }
            }
        }

        if (include2DColliders)
        {
            Vector2      xy          = new Vector2(transform.position.x, transform.position.y);
            Collider2D[] colliders2d = Physics2D.OverlapCircleAll(xy, transform.localScale.magnitude);
            for (int i = 0; i < colliders2d.Length; ++i)
            {
                Collider2D col = colliders2d[i];
                if (col.isTrigger)
                {
                    continue;
                }

                MPColliderProperties cprops;
                bool recv = false;
                var  attr = col.gameObject.GetComponent <MPColliderAttribute>();
                if (attr)
                {
                    if (!attr.sendCollision)
                    {
                        continue;
                    }
                    attr.UpdateColliderProperties();
                    recv   = attr.receiveCollision;
                    cprops = attr.cprops;
                }
                else
                {
                    cprops = new MPColliderProperties();
                    cprops.SetDefaultValues();
                }
                int id = colliders.Count;
                cprops.owner_id = recv ? id : -1;
                colliders.Add(col.gameObject);

                CircleCollider2D sphere = col as CircleCollider2D;
                BoxCollider2D    box    = col as BoxCollider2D;
                if (sphere)
                {
                    Vector3 pos = sphere.transform.position;
                    MPAPI.mpAddSphereCollider(ref cprops, ref pos, sphere.radius * col.gameObject.transform.localScale.x);
                }
                else if (box)
                {
                    Matrix4x4 mat  = box.transform.localToWorldMatrix;
                    Vector3   size = new Vector3(box.size.x, box.size.y, box.size.x);
                    MPAPI.mpAddBoxCollider(ref cprops, ref mat, ref size);
                }
            }
        }

        foreach (MPCollider col in MPCollider.instances)
        {
            if (!col.sendCollision)
            {
                continue;
            }
            col.MPUpdate();
            col.cprops.owner_id = colliders.Count;
            colliders.Add(col.gameObject);
        }
        foreach (MPForce force in MPForce.instances)
        {
            force.MPUpdate();
        }
        foreach (MPEmitter emitter in MPEmitter.instances)
        {
            emitter.MPUpdate();
        }

        mprenderer.MPUpdate();
    }
Example #5
0
 [DllImport("MassParticle")] public static extern void mpAddSphereCollider(int context, ref MPColliderProperties props, ref Vector3 center, float radius);
Example #6
0
 public static extern void mpRemoveCollider(int context, ref MPColliderProperties props);
Example #7
0
 public static extern void mpAddSphereCollider(int context, ref MPColliderProperties props, ref Vector3 center, float radius);
Example #8
0
 public static extern void mpAddCapsuleCollider(int context, ref MPColliderProperties props, ref Vector3 pos1, ref Vector3 pos2, float radius);
Example #9
0
 public static extern void mpAddBoxCollider(int context, ref MPColliderProperties props, ref Matrix4x4 transform, ref Vector3 center, ref Vector3 size);
Example #10
0
 [DllImport("MassParticle")] public static extern void mpAddBoxCollider(ref MPColliderProperties props, ref Matrix4x4 transform, ref Vector3 size);