예제 #1
0
        public void Trigger(ActionUsingNode node, string eventName)
        {
            var    entity    = node.Entity;
            var    cmdTarget = entity.Get <CommandTarget>();
            Entity target;

            if (cmdTarget != null && cmdTarget.Target != null)
            {
                target = cmdTarget.Target;
            }
            else
            {
                target = node.Entity;
            }
            if (target == null)
            {
                return;
            }
            var sourceNode = entity.FindNode <CollidableNode>();
            var targetNode = target.FindNode <CollidableNode>();

            if (sourceNode == null || targetNode == null)
            {
                return;
            }
            CollisionExtensions.GenerateHitLocDir(sourceNode.Tr, targetNode.Tr, targetNode.Collider, out var hitPoint, out var dir);
            var ce = new CollisionEvent(entity, sourceNode, targetNode, hitPoint, dir);

            target.Post(ce);
            entity.Post(new PerformedCollisionEvent(sourceNode, targetNode, ce.HitPoint, ce.HitNormal));
            var stateEvent = new ActionStateEvent(node.Entity, ce.Target.Entity, ce.HitPoint, Quaternion.LookRotation(ce.HitNormal), StateEvent);

            node.Entity.Post(stateEvent);
        }
예제 #2
0
        public override bool CanResolve(ActionCommand cmd)
        {
            var target = cmd.Owner.Target.TargetChar != null ? cmd.Owner.Target.TargetChar : cmd.Owner;

            CollisionExtensions.GenerateHitLocDir(cmd.Owner.Tr, target.Tr, target.Collider, out var hitPoint, out var dir);
            var hitRot = Quaternion.LookRotation(dir);
            var hit    = new HitData(CollisionResult.Hit, target, hitPoint, dir);

            cmd.ProcessHit(hit, hitRot);
            return(true);
        }
예제 #3
0
 public void Start(Entity entity)
 {
     if (Owner.Target?.Target == null)
     {
         Owner.DefaultPostAdvance(this);
         return;
     }
     CollisionExtensions.GenerateHitLocDir(entity, Owner.Target.Target, out var hitpnt, out var dir);
     Owner.Target.Target.Post(new CollisionEvent(entity, Owner.Target.Target, hitpnt, dir, Owner.CurrentData));
     Owner.PostAdvance(Owner.Target.Target, hitpnt, Quaternion.Euler(dir), StateEvent);
 }
예제 #4
0
 private static void CheckColliderList(Entity originEntity, Entity ignoreEntity, Vector3 position, int limit, bool limitEnemy)
 {
     for (int i = 0; i < limit; i++)
     {
         if (originEntity.IsDestroyed())
         {
             return;
         }
         var collider  = _colliders[i];
         var hitEntity = EntityController.GetEntity(UnityToEntityBridge.GetEntityId(collider));
         if (hitEntity == ignoreEntity || hitEntity == null)
         {
             continue;
         }
         if (IsValidCollision(originEntity, limitEnemy, hitEntity, collider, out var sourceNode, out var targetNode))
         {
             CollisionExtensions.GenerateHitLocDir(position, hitEntity, collider, out var hitPnt, out var hitNormal);
             var ce = new CollisionEvent(originEntity, sourceNode, targetNode, hitPnt, hitNormal);
             hitEntity.Post(ce);
             originEntity.Post(new PerformedCollisionEvent(sourceNode, targetNode, hitPnt, hitNormal));
         }
     }
 }