Пример #1
0
        public void CollisionFilterTestLayerSelfCollision()
        {
            var filter0 = new CollisionFilter();

            var filter1 = new CollisionFilter
            {
                MaskBits     = 1,
                CategoryBits = 1
            };

            var filter2 = new CollisionFilter
            {
                MaskBits     = 0xffffffff,
                CategoryBits = 0xffffffff
            };

            Assert.IsFalse(CollisionFilter.IsCollisionEnabled(filter0, filter0));
            Assert.IsFalse(CollisionFilter.IsCollisionEnabled(CollisionFilter.Zero, CollisionFilter.Zero));
            Assert.IsTrue(filter0.Equals(CollisionFilter.Zero));

            Assert.IsTrue(CollisionFilter.IsCollisionEnabled(filter1, filter1));
            Assert.IsTrue(CollisionFilter.IsCollisionEnabled(filter2, filter2));
            Assert.IsTrue(CollisionFilter.IsCollisionEnabled(CollisionFilter.Default, CollisionFilter.Default));
            Assert.IsTrue(filter2.Equals(CollisionFilter.Default));
        }
Пример #2
0
        public void CollisionFilterTest_LayerSelfCollision()
        {
            var filter0 = new CollisionFilter();

            var filter1 = new CollisionFilter
            {
                BelongsTo    = 1,
                CollidesWith = 1
            };

            var filter2 = new CollisionFilter
            {
                BelongsTo    = 0xffffffff,
                CollidesWith = 0xffffffff
            };

            Assert.IsFalse(CollisionFilter.IsCollisionEnabled(filter0, filter0));
            Assert.IsFalse(CollisionFilter.IsCollisionEnabled(CollisionFilter.Zero, CollisionFilter.Zero));
            Assert.IsTrue(filter0.Equals(CollisionFilter.Zero));

            Assert.IsTrue(CollisionFilter.IsCollisionEnabled(filter1, filter1));
            Assert.IsTrue(CollisionFilter.IsCollisionEnabled(filter2, filter2));
            Assert.IsTrue(CollisionFilter.IsCollisionEnabled(CollisionFilter.Default, CollisionFilter.Default));
            Assert.IsTrue(filter2.Equals(CollisionFilter.Default));
        }
Пример #3
0
        /// <summary>
        /// creates and returns the pokemoon's PhysicsCollider
        /// </summary>
        /// <param name="pokemonName">Name of the pokemon</param>
        /// <returns>PhysicsCollider</returns>
        public static PhysicsCollider getPokemonPhysicsCollider(string pokemonName, PokemonEntityData ped,
                                                                CollisionFilter collisionFilter = new CollisionFilter(), float scale = 1f, Unity.Physics.Material material = new Unity.Physics.Material(),
                                                                int groupIndex = 1)
        {
            ///FUTURE UPDATE
            ///allow specific colliders to recieve specific filters and materials!

            //needs collision groups
            PhysicsCollider physicsCollider = new PhysicsCollider {
            };
            Quaternion rotation             = new quaternion();

            //if default collision filter is detected then create one realted to the pokemon
            if (collisionFilter.Equals(new CollisionFilter()))
            {
                Debug.Log("Creating new Collision Filter");
                collisionFilter = new CollisionFilter
                {
                    BelongsTo    = TriggerEventClass.Pokemon | TriggerEventClass.Collidable,
                    CollidesWith = TriggerEventClass.Collidable,
                    GroupIndex   = groupIndex
                };
            }
            if (material.Equals(new Unity.Physics.Material()))
            {
                material = GetPokemonColliderMaterial(StringToPokedexEntry(pokemonName));
            }
            switch (pokemonName)
            {
            case "Cubone":
                var colliders = new NativeArray <CompoundCollider.ColliderBlobInstance>(5, Allocator.Temp);
                colliders[0] = new CompoundCollider.ColliderBlobInstance
                {
                    Collider = Unity.Physics.SphereCollider.Create(new SphereGeometry {
                        Center = new float3(0, 0.27f, 0.03f), Radius = 0.225f
                    }, collisionFilter, material),
                    CompoundFromChild = new RigidTransform {
                        pos = new float3 {
                            x = 0, y = 0, z = 0
                        }, rot = quaternion.identity
                    }
                };
                var a = GenerateCapsuleData(float3.zero, Vector3.right, 0.1f, 0.3f);
                rotation.SetFromToRotation(Vector3.right, new Vector3(0, 90f, 0));
                colliders[1] = new CompoundCollider.ColliderBlobInstance
                {
                    Collider = Unity.Physics.CapsuleCollider.Create(new CapsuleGeometry {
                        Vertex0 = a.pointA, Vertex1 = a.pointB, Radius = 0.1f
                    }, collisionFilter, material),
                    CompoundFromChild = new RigidTransform {
                        pos = new float3(-0.17f, 0.19f, 0), rot = rotation
                    }
                };
                colliders[2] = new CompoundCollider.ColliderBlobInstance
                {
                    Collider = Unity.Physics.CapsuleCollider.Create(new CapsuleGeometry {
                        Vertex0 = a.pointA, Vertex1 = a.pointB, Radius = 0.1f
                    }, collisionFilter, material),
                    CompoundFromChild = new RigidTransform {
                        pos = new float3(0.17f, 0.19f, 0), rot = rotation
                    }
                };
                colliders[3] = new CompoundCollider.ColliderBlobInstance
                {
                    Collider = Unity.Physics.SphereCollider.Create(new SphereGeometry {
                        Center = float3.zero, Radius = 0.23f
                    }, collisionFilter, material),
                    CompoundFromChild = new RigidTransform {
                        pos = new float3(0, 0.75f, 0.03f), rot = rotation
                    }
                };
                a            = GenerateCapsuleData(float3.zero, Vector3.right, 0.1f, 0.3f);
                rotation     = Quaternion.Euler(0, 90f, 26f);
                colliders[4] = new CompoundCollider.ColliderBlobInstance
                {
                    Collider = Unity.Physics.CapsuleCollider.Create(new CapsuleGeometry {
                        Vertex0 = a.pointA, Vertex1 = a.pointB, Radius = 0.1f
                    }, collisionFilter, material),
                    CompoundFromChild = new RigidTransform {
                        pos = new float3(0, 0.63f, 0.33f), rot = rotation
                    }
                };
                physicsCollider = new PhysicsCollider {
                    Value = CompoundCollider.Create(colliders)
                };
                if (scale > 1f)
                {
                    Debug.LogWarning("Cannot scale Cubone");
                }
                colliders.Dispose();
                break;

            case "Electrode":
                Debug.Log("Creating PHysicwsCollider for Electrode");
                physicsCollider = new PhysicsCollider {
                    Value = Unity.Physics.SphereCollider.Create(new SphereGeometry
                    {
                        Center = float3.zero,
                        Radius = ped.Height / 2 * scale
                    },
                                                                collisionFilter,
                                                                material
                                                                )
                };
                break;

            default:
                Debug.LogError("Failed to find collider for pokemon \"" + pokemonName + "\"");
                physicsCollider = new PhysicsCollider
                {
                    Value = Unity.Physics.SphereCollider.Create(new SphereGeometry
                    {
                        Center = float3.zero,
                        Radius = ped.Height / 2 * scale
                    },
                                                                collisionFilter,
                                                                material
                                                                )
                };
                break;
            }
            //		Debug.Log("Returning Physics Collide for \""+pokemonName+"\"");
            return(physicsCollider);
        }