コード例 #1
0
        void OnCollision(SEntityEvent arg)
        {
            if (arg._event != EEntityEvent.ENTITY_EVENT_COLLISION)
            {
                Logger.LogError("Event passed into OnCollision was not a Collision.");
                return;
            }

            // As the only attached Entity event is the collision event, get physics of the collision.
            var collision = arg.GetEventPhysCollision();

            // Retrieve both entities which are part of the collision.
            var entOne = Env.EntitySystem.GetEntityFromPhysics(collision.GetFirstEntity());
            var entTwo = Env.EntitySystem.GetEntityFromPhysics(collision.GetSecondEntity());

            if (entOne == null || entTwo == null)
            {
                return;
            }

            IEntity collider;

            if (entOne.GetId() == GameObject.Id)
            {
                collider = entTwo;
            }
            else
            {
                collider = entOne;
            }

            OnCollide?.Invoke(new CollisionEvent(collision, collider));
        }
コード例 #2
0
        void OnCollision(SEntityEvent arg)
        {
            if (arg._event != EEntityEvent.ENTITY_EVENT_COLLISION)
            {
                return;
            }

            // As the only attached Entity event is the collision event, get physics of the collision.
            var collision = arg.GetEventPhysCollision();

            // Retrieve both entities which are part of the collision.
            var entOne = Global.gEnv.pEntitySystem.GetEntityFromPhysics(collision.GetFirstEntity());
            var entTwo = Global.gEnv.pEntitySystem.GetEntityFromPhysics(collision.GetSecondEntity());

            IEntity collider = null;

            if (entOne != null && entTwo != null)
            {
                if (entOne.GetId() == Entity.Id)
                {
                    collider = entTwo;
                }
                else
                {
                    collider = entOne;
                }
            }

            OnCollide?.Invoke(new CollisionEvent(this, collision, collider));
        }
コード例 #3
0
        /// <summary>
        /// Global event on entity collision. Forwards event to C# Entities.
        /// </summary>
        /// <param name="pEntity">CRYENGINE entity.</param>
        /// <param name="arg1">Collision information.</param>
        public override void OnEntityEvent(IEntity pEntity, SEntityEvent arg1)
        {
            // As the only attached Entity event is the collision event, get physics of the collision.
            EventPhysCollision collision = arg1.GetEventPhysCollision();

            // Retrieve both entities which are part of the collision.
            IEntity entOne = Global.gEnv.pEntitySystem.GetEntityFromPhysics(collision.GetFirstEntity());
            IEntity entTwo = Global.gEnv.pEntitySystem.GetEntityFromPhysics(collision.GetSecondEntity());

            if (entOne == null || entTwo == null)
            {
                return;
            }

            var e1 = Entity.Get(entOne.GetId());
            var e2 = Entity.Get(entTwo.GetId());

            e1.RaiseCollision(e2);
            e2.RaiseCollision(e1);
        }