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));
        }
Beispiel #2
0
 public override void OnEntityEvent(IEntity pEntity, SEntityEvent entityEvent)
 {
     callbacks
     .Where(x => x.Trigger == entityEvent._event)
     .ToList()
     .ForEach(x => x.Callback(entityEvent));
 }
Beispiel #3
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));
        }
 /// <summary>
 /// Translate 'OnEvent' callback to managed 'Event' event.
 /// </summary>
 public override void OnEvent(IEntity pEntity, SEntityEvent arg1)
 {
     if (Event != null)
     {
         Event(pEntity, arg1);
     }
 }
Beispiel #5
0
        /// <summary>
        /// Called when CRYENGINE's entity system issues an entity event. If a managed CESharp entity instance exists the event will be forwarded to it.
        /// </summary>
        private static void OnEvent(IEntity pEntity, SEntityEvent arg1)
        {
            EntityId id = pEntity.GetId();

            if (!s_managedEntities.ContainsKey(id))
            {
                return;
            }

            s_managedEntities[id].OnEvent(arg1);
        }
Beispiel #6
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);
        }
Beispiel #7
0
        /// <summary>
        /// Called when CRYENGINE's entity system issues an event.
        /// </summary>
        public virtual void OnEvent(SEntityEvent arg)
        {
            switch (arg._event)
            {
            case EEntityEvent.ENTITY_EVENT_EDITOR_PROPERTY_CHANGED:
            {
                var propertyHandler = EntityClass.NativeClass.GetPropertyHandler();
                if (propertyHandler != null)
                {
                    foreach (var property in EntityClass.Properties)
                    {
                        var propertyValue = propertyHandler.GetProperty(NativeHandle, property.Key);

                        property.Value.Set(this, propertyValue);
                    }
                }
            }
            break;
            }

            _components.ForEach(x => x.OnEvent(arg));
        }
Beispiel #8
0
 public virtual void OnEvent(SEntityEvent arg)
 {
 }
Beispiel #9
0
 /// <summary>
 /// Called when CRYENGINE's entity system issues an event.
 /// </summary>
 public virtual void OnEvent(SEntityEvent arg)
 {
     _components.ForEach(x => x.Value.NotifyEvent(arg));
 }
Beispiel #10
0
 /// <summary>
 /// Called when the game starts or ends, and when AI/Physics simulation starts and ends in Sandbox.
 /// </summary>
 /// <param name="arg"></param>
 public virtual void OnStart(SEntityEvent arg)
 {
     Logger.LogInfo("OnStart");
     handlers.ForEach(x => x.Start());
 }
Beispiel #11
0
 /// <summary>
 /// Called by the Entity Framework(?). Fired when this GameObject's native Entity recieves an Entity event. If overriding, you must call the base method.
 /// </summary>
 public override void OnEvent(SEntityEvent arg)
 {
     handlers.ToList().ForEach(x => x.NotifyEvent(arg));
 }
Beispiel #12
0
 protected virtual void OnEvent(SEntityEvent arg)
 {
 }
Beispiel #13
0
 void IEntityComponentHandler.NotifyEvent(SEntityEvent arg)
 {
     Logger.LogInfo("Event: {0}", arg._event);
     OnEvent(arg);
 }
Beispiel #14
0
 void IGameObjectEventHandler.NotifyEvent(SEntityEvent arg)
 {
     Logger.LogInfo("Event: {0}", arg._event);
     OnEvent(arg);
 }