private Point DefinePosition(MovingItem item, Direction direction, int count) { Point currentPoint; switch (direction) { case Direction.Up: currentPoint = Point.FromRelative(item.Position.X, item.Position.Y - count); break; case Direction.Down: currentPoint = Point.FromRelative(item.Position.X, item.Position.Y + count); break; case Direction.Left: currentPoint = Point.FromRelative(item.Position.X - count, item.Position.Y); break; case Direction.Right: currentPoint = Point.FromRelative(item.Position.X + count, item.Position.Y); break; default: throw new ArgumentException("unknown direction"); } return(currentPoint); }
private bool TestStep(MovingItem item) { var currentPoint = DefinePosition(item, item.CurrentDirection, 1); var result = CheckCell(item.Type, currentPoint); return(result); }
private void DestroyMovingItem() { Destroy(currentItem.gameObject); currentItem = null; CurrentStatus = Status.EMPTY; outputDirection = -1; receivingDir = -1; }
private bool Move(MovingItem item) { if (IsFullyInCell(item.Position) && !TestStep(item)) { return(false); } item.Move(); return(true); }
private void InitMovingItem(Package <ItemStack> package, int dir) { outputDirection = -1; receivingDir = dir; currentItem = Instantiate(MovingItemPrefab, transform); currentItem.Package = package; currentItem.StartLocation = GetComponent <TileObject>().GetPointOnTileSide(dir); currentItem.MovementSpeed = MovementSpeed; CurrentStatus = Status.MOVING_1; }
private void SetGrabbedObject(Rigidbody setGrabbedObject) { if (setGrabbedObject == null) { grabbing = false; joint.connectedBody = null; AnimateArmsIn(); } if (grabbedObject != null) { grabbedObject.gameObject.GetComponent <QuickOutline.Outline>().enabled = false; MovingItem movingItem = grabbedObject.GetComponentInParent <MovingItem>(); if (movingItem != null) { movingItem.SetGrabbed(false); } grabbedObject = null; } grabbedObject = setGrabbedObject; grabbing = grabbedObject != null; if (grabbedObject != null) { joint.connectedBody = grabbedObject; // Outline the grabbed object. QuickOutline.Outline outline = grabbedObject.gameObject.GetComponent <QuickOutline.Outline>(); if (outline == null) { outline = grabbedObject.gameObject.AddComponent <QuickOutline.Outline>(); } outline.OutlineColor = new Color(0.9f, 0.45f, 0f); outline.OutlineWidth = 10f; outline.enabled = true; AnimateArmsOut(); grabAudioSources[currentGrabAudioSource].Play(); currentGrabAudioSource++; if (currentGrabAudioSource >= grabAudioSources.Count) { currentGrabAudioSource = 0; } } }
private void AttemptGrab() { grabbedObject = null; grabbing = false; Vector3 moveDirNorm = moveDir.normalized; RaycastHit[] hits = Physics.SphereCastAll(transform.position - moveDirNorm * 1f, 1f, moveDirNorm, 4f).OrderBy(h => h.distance).ToArray(); foreach (RaycastHit hit in hits) { MovingItem movingItem = hit.collider.gameObject.GetComponentInParent <MovingItem>(); if (movingItem != null) { SetGrabbedObject(movingItem.GetComponent <Rigidbody>()); break; } } }