Rigidbody ResetAndReturnPickup() { var r = CurrentlyHeldObject.GetComponent <Rigidbody>(); r.isKinematic = false; return(r); }
public override void Update(GameTime gameTime) { TouchCollection touches = TouchPanel.GetState(); foreach (TouchLocation touch in touches) { switch (touch.State) { case TouchLocationState.Pressed: Console.WriteLine("Touched, count=" + downButtonCount); lastMousePos = new Vector2 <float>(touch.Position.X, touch.Position.Y); _mouseDownListeners(downButtonCount); downButtonCount++; lastMousePos = new Vector2 <float>(touch.Position.X, touch.Position.Y); break; case TouchLocationState.Released: lastMousePos = new Vector2 <float>(touch.Position.X, touch.Position.Y); Console.WriteLine("Released, count=" + downButtonCount); downButtonCount--; Console.WriteLine("post --, count=" + downButtonCount); _mouseUpListeners(downButtonCount); if (downButtonCount == 0) { CurrentlyHeldObject = null; } break; case TouchLocationState.Moved: Vector2 <float> newPos = new Vector2 <float>(touch.Position.X, touch.Position.Y); if (newPos != lastMousePos) { Console.WriteLine("moved, move=" + newPos); if (downButtonCount == 1) { if (CurrentlyHeldObject != null) { CurrentlyHeldObject.DoDrag(newPos - lastMousePos); lastMousePos = newPos; } } else // scroll { _mouseScrollListeners((int)(lastMousePos.Y - newPos.Y)); lastMousePos = newPos; } } break; } } // pass update to drawspaces foreach (DrawspaceImpl ds in drawspaces) { ds.Update((long)(gameTime.ElapsedGameTime.TotalMilliseconds)); } }
private bool SnapToSlotIfPresent() { if (currentZone == null) { return(false); } CurrentlyHeldObject.GetComponent <Pickup>().SnapTo(currentZone); return(true); }
public override void Update(GameTime gameTime) { MouseState mouseState = Mouse.GetState(); // check for button state changes if (leftMouseDown != mouseState.LeftButton) { leftMouseDown = mouseState.LeftButton; if (mouseState.LeftButton == ButtonState.Pressed) { if (_mouseDownListeners != null) { _mouseDownListeners(0); } } else { CurrentlyHeldObject = null; // button up release component if (_mouseUpListeners != null) { _mouseUpListeners(0); } } } if (rightMouseDown != mouseState.RightButton) { rightMouseDown = mouseState.RightButton; if (mouseState.RightButton == ButtonState.Pressed) { if (_mouseDownListeners != null) { _mouseDownListeners(1); } } else { if (_mouseUpListeners != null) { _mouseUpListeners(1); } } } if (middleMouseDown != mouseState.MiddleButton) { middleMouseDown = mouseState.MiddleButton; if (mouseState.MiddleButton == ButtonState.Pressed) { if (_mouseDownListeners != null) { _mouseDownListeners(2); } } else { if (_mouseUpListeners != null) { _mouseUpListeners(2); } } } // check for mouse move if ((lastMousePos.X != mouseState.X) || (lastMousePos.Y != mouseState.Y)) { // drag held component if (CurrentlyHeldObject != null) { CurrentlyHeldObject.DoDrag(new Vector2 <float>(mouseState.X, mouseState.Y) - lastMousePos); } lastMousePos.X = mouseState.X; lastMousePos.Y = mouseState.Y; if (_mouseMoveListeners != null) { _mouseMoveListeners(lastMousePos); } } // check for scroll wheel if (lastWheelPos != mouseState.ScrollWheelValue) { lastWheelPos = mouseState.ScrollWheelValue; if (_mouseScrollListeners != null) { _mouseScrollListeners(lastWheelPos); } } // pass update to drawspaces foreach (DrawspaceImpl ds in drawspaces) { ds.Update((long)(gameTime.ElapsedGameTime.TotalMilliseconds)); } }