예제 #1
0
        protected override void Executing(ISceneSnapshot ss)
        {
            var snapshot = (SceneSnapshot)ss;

            var colliding = new Colliding(snapshot, ContextState);
            var emanager  = ContextState.GetEntityManager();

            foreach (var ev in snapshot.InputSnapshot.Events)
            {
                switch (ev)
                {
                case CaptureTargetUnderMouseCameraCommand capture:
                    if (colliding.TryToColliding(capture.ScreenPosition, out var collidedWith))
                    {
                        var entity = emanager.GetEntity(collidedWith.With);
                        var has    = entity.GetComponents <ManipulatableComponent>();
                        if (has.Any() && !entity.Has <CapturedToManipulateComponent>())
                        {
                            entity.AddComponent(new CapturedToManipulateComponent()
                            {
                                CapturePointWorld = collidedWith.IntersectionPositionWorld,
                            });
                            snapshot.InputSnapshot.RemoveEvent(ev);
                        }
                    }
                    break;
                }
            }

            foreach (var entity in emanager.GetEntities())
            {
                foreach (var com in entity.GetComponents <ICollidableComponent>())
                {
                    switch (com)
                    {
                    case CollidingWithScreenRayComponent byRay:
                        try {
                            if (colliding.TryToColliding(byRay.ScreenPosition, out var collidedWith))
                            {
                                entity.AddComponent(collidedWith);
                            }
                        } finally {
                            entity.RemoveComponent(byRay);
                        }
                        break;
                    }
                }
            }
        }
예제 #2
0
        public void Update(ElapsedTime elapsedTime)
        {
            if (!Enabled || Unphysical || IsFreeze || Parent.IsFreeze)
            {
                return;
            }

            int i = 0;

            while (i < CollisionDepth && _colliderManager.ResolveOneCollision(this, out Collision collision))
            {
                Colliding?.Invoke(collision);
                ParentNode.Position += collision.Correction;
                Collided?.Invoke(collision);
                i++;
            }
        }
예제 #3
0
 // Use this for initialization
 void Start()
 {
     rb        = GetComponent <Rigidbody>();
     colliding = GetComponent <Colliding>();
 }