void OnMouseDrag() { if (!isDragging && isDraggingEnabled) { mMouseCurr.x = Input.mousePosition.x; mMouseCurr.y = Input.mousePosition.y; mDragDist = mMouseDown - mMouseCurr; if (mDragDist.magnitude > 30 && _creatures.Count > 0) { StartDrag(); } } else if (isDragging) { // update the drag group position Vector3 currPos = new Vector3(Input.mousePosition.x, Input.mousePosition.y, 0); Vector3 worldPos = Camera.main.ScreenToWorldPoint(currPos); worldPos.z = 0.0f; // clamp worldPos to stay within the bounds of the display worldPos.x = Mathf.Clamp(worldPos.x, CameraUtils.cameraRect.xMin + dragGroup.GetComponent <SpriteRenderer>().bounds.extents.x, CameraUtils.cameraRect.xMax - dragGroup.GetComponent <SpriteRenderer>().bounds.extents.x); worldPos.y = Mathf.Clamp(worldPos.y, CameraUtils.cameraRect.yMin + dragGroup.GetComponent <SpriteRenderer>().bounds.extents.y, CameraUtils.cameraRect.yMax - dragGroup.GetComponent <SpriteRenderer>().bounds.extents.x); if (dragGroup != null) { dragGroup.transform.position = worldPos; } // check for bounding box intersections between group and place value subtraction car // show hover state Bounds dragGroupBounds = dragGroup.GetComponent <SpriteRenderer>().bounds; int dragValue = dragGroup.GetComponent <DragGroup>().value; bool placement = dragGroupBounds.Intersects(column.bounds); bool placementConvert = !placement && convertColumn != null && dragGroupBounds.Intersects(convertColumn.bounds) && (convertColumn.numCreatures + value) <= convertColumn.creatureMax && convertColumn.allowDragConvert; //if (placement && column.numCreatures < column.creatureMax) if (value == 1) { column.UpdateDragOver(placement, dragGroup.GetComponent <DragGroup>().numOnes); } else if (value == 10) { column.UpdateDragOver(placement, dragGroup.GetComponent <DragGroup>().numTens); if (convertColumn != null) { convertColumn.UpdateDragOver(placementConvert, dragGroup.GetComponent <DragGroup>().numTens * 10); } } } }
void OnMouseDrag() { if (!isDragging) { return; } Vector3 currPos = new Vector3(Input.mousePosition.x - mDragOffset.x, Input.mousePosition.y - mDragOffset.y, mDragDist.z); Vector3 worldPos = Camera.main.ScreenToWorldPoint(currPos); // clamp worldPos to stay within the bounds of the display worldPos.x = Mathf.Clamp(worldPos.x, CameraUtils.cameraRect.xMin + this.GetComponent <SpriteRenderer>().bounds.extents.x, CameraUtils.cameraRect.xMax - this.GetComponent <SpriteRenderer>().bounds.extents.x); worldPos.y = Mathf.Clamp(worldPos.y, CameraUtils.cameraRect.yMin + this.GetComponent <SpriteRenderer>().bounds.extents.y, CameraUtils.cameraRect.yMax - this.GetComponent <SpriteRenderer>().bounds.extents.x); this.transform.position = worldPos; PlaceValueCtrl ones = container.controller.screen.GetComponent <MyScreen>().onesColumn; PlaceValueCtrl tens = container.controller.screen.GetComponent <MyScreen>().tensColumn; // check for bounding box intersections between group and place value columns bool onesPlacement = this.GetComponent <SpriteRenderer>().bounds.Intersects(ones.bounds) && (ones.numCreatures + numOnes + numTens * 10) <= ones.creatureMax && (!isMultipleOfTen || ones.allowDragConvert); bool tensPlacement = this.GetComponent <SpriteRenderer>().bounds.Intersects(tens.bounds) && (tens.numCreatures + numTens) <= tens.creatureMax && !onesPlacement; // force a show of drop states if the number will be distributed between both columns if (numOnes != 0 && numTens != 0) { onesPlacement = tensPlacement = onesPlacement || tensPlacement; } // update place value column over states ones.UpdateDragOver(onesPlacement, (numOnes == 0 ? numTens * 10 : numOnes)); if (numTens != 0) { tens.UpdateDragOver(tensPlacement, numTens); } }
void OnMouseUp() { if (!isDragging) { return; } StopDrag(); PlaceValueCtrl ones = container.controller.screen.GetComponent <MyScreen>().onesColumn; PlaceValueCtrl tens = container.controller.screen.GetComponent <MyScreen>().tensColumn; // update place value column over states ones.UpdateDragOver(false, (numOnes == 0 ? numTens * 10 : numOnes)); tens.UpdateDragOver(false, numTens); // check for bounding box intersections between group and place value columns bool onesPlacement = this.GetComponent <SpriteRenderer>().bounds.Intersects(ones.bounds) && (ones.numCreatures + numOnes + numTens * 10) <= ones.creatureMax && (!isMultipleOfTen || ones.allowDragConvert); bool tensPlacement = this.GetComponent <SpriteRenderer>().bounds.Intersects(tens.bounds) && (tens.numCreatures + numTens) <= tens.creatureMax && !onesPlacement; if ((onesPlacement || tensPlacement) && !isMultipleOfTen && isGreaterThanNine) { //NOTE: this probably doesn't happen any more, should confirm //Genie.instance.LogEvent(OE_INTERACT.Create(OE_INTERACT.Type.DROP, "gameplay.eitherColumn"); Genie.I.LogEvent(OE_INTERACT.Create(OE_INTERACT.Type.DROP, "gameplay.eitherColumn")); ones.ForceDragOverFalse(value); RemoveFromContainerDistributeToPlaceValue(); } else if (onesPlacement && !tensPlacement && isLessThanTen) { //Genie.instance.LogEvent(OE_INTERACT.Create(OE_INTERACT.Type.DROP, "gameplay.onesColumn"); Genie.I.LogEvent(OE_INTERACT.Create(OE_INTERACT.Type.DROP, "gameplay.onesColumn")); // if on the correct place-value column, snap to place-value column (remove from queue) // try to place in ones column ones.ForceDragOverFalse(value); RemoveFromContainerAddToPlaceValue(ones); } else if (tensPlacement && !onesPlacement && isMultipleOfTen) { //Genie.instance.LogEvent(OE_INTERACT.Create(OE_INTERACT.Type.DROP, "gameplay.tensColumn"); Genie.I.LogEvent(OE_INTERACT.Create(OE_INTERACT.Type.DROP, "gameplay.tensColumn")); // try to place in tens column tens.ForceDragOverFalse(value); RemoveFromContainerAddToPlaceValue(tens); } else if (tensPlacement && !onesPlacement && !isMultipleOfTen) { //Genie.instance.LogEvent(OE_INTERACT.Create(OE_INTERACT.Type.DROP, "gameplay.tensColumn"); Genie.I.LogEvent(OE_INTERACT.Create(OE_INTERACT.Type.DROP, "gameplay.tensColumn")); // highlight tens column as incorrect placement (reminder) tens.ShowIncorrectFeedback(); SoundManager.instance.PlayOneShot(SoundManager.instance.chickenSnapBack); // try to place in ones column ones.ForceDragOverFalse(value); RemoveFromContainerAddToPlaceValue(ones, true); } else if (onesPlacement && isMultipleOfTen && ones.numCreatures < 10 && ones.allowDragConvert) { //Genie.instance.LogEvent(OE_INTERACT.Create(OE_INTERACT.Type.DROP, "gameplay.onesColumn"); Genie.I.LogEvent(OE_INTERACT.Create(OE_INTERACT.Type.DROP, "gameplay.onesColumn")); EnlearnInstance.I.LogActions(EnlearnInstance.Action.AddNestToOnes); // place a 10s in 1s column ones.ForceDragOverFalse(value); CreatureCtrl[] children = this.GetComponentsInChildren <CreatureCtrl>(); bool bIsBrown = children[0].color == CreatureCtrl.COLOR_BROWN; SoundManager.instance.PlayOneShot(SoundManager.instance.chickenConvertToOnes); ones.Add(10, bIsBrown); // add explosion effects container.controller.screen.Poof(); Cleanup(); } else { if (onesPlacement) { // update place value column over states ones.ForceDragOverFalse(value); ones.GetComponent <Animator>().SetTrigger("correct"); } if (tensPlacement) { tens.ForceDragOverFalse(value); tens.GetComponent <Animator>().SetTrigger("correct"); } // else, if we're overlapping with both or neither // snap back to QueueContainer //SnapBack(); CreatureCtrl[] children = this.GetComponentsInChildren <CreatureCtrl>(); children[0].Drop(); Cleanup(); } }