private void InputMove() { GearEntity gear = gears[currentGear_]; // Get the gear positions in Vector2 so the z coordinate will always be 0 Vector2 uiPosition = Input.mousePosition; Vector2 worldPosition = camera_.ScreenToWorldPoint(uiPosition); // Set the gear positions gear.ui.position = uiPosition; gear.world.transform.position = worldPosition; // Changes the visible gear whether the input is in or outside the inventory gear.VisibleGear(RectTransformUtility.RectangleContainsScreenPoint(inventory, uiPosition)); }
/// <summary> /// configures the gear using the destination information. /// </summary> /// <param name="gearIndex"> Which gear? </param> /// <param name="destinyIndex"> The index of the destination. </param> /// <param name="inInventory"> Is the destiny an inventory slot (true) or a gear placement (false)? </param> private void GearArrived(int gearIndex, int destinyIndex, bool inInventory) { GearEntity gear = gears[gearIndex]; // Sets the new origin information up gear.origin.location = inInventory ? GearLocation.SlotUI : GearLocation.WorldPlacement; gear.origin.index = destinyIndex; // Clears up the destiny information gear.destiny.Clear(); Vector2 position; // Positions the gear and applies the default settings from where it is if (inInventory) { gear.ui.position = slots[destinyIndex].position; position = camera_.ScreenToWorldPoint(gear.ui.position); gear.world.transform.position = position; gear.world.transform.rotation = worldGearsRotation_; } else { gear.world.transform.position = gearPlacements[destinyIndex].transform.position; position = camera_.WorldToScreenPoint(gear.world.transform.position); gear.ui.position = position; gear.ui.sizeDelta = uiToWorldSize_; } // Returns the world gear to the default sorting order, switchs the visibilities and stops the gear. At last, checks if all gears are in position gear.world.sortingOrder = 0; gear.currentScale = gear.ui.sizeDelta; gear.VisibleGear(inInventory); gear.moving = false; gears[gearIndex] = gear; AllGearsPositioned(); }
private void InputUp() { // If there's no input, just leave if (!Input.GetMouseButtonUp(0)) { return; } GearEntity gear = gears[currentGear_]; // Gets if the input was inside of somewhere. If not, the gear returns to its origin, else it gets the coordinates of the new destiny GearLocation location = InputInsideSomewhere(Input.mousePosition, out int index); if (location == GearLocation.Nowhere) { gear.destiny = gear.origin; } else { gear.destiny.location = location; gear.destiny.index = index; // Checks if there was another gear at the new destiny int g = GearInsideLocation(location, index); // If it was, then determines the destiny of this another gear to be the origin of the moving gear if (g >= 0) { gears[g].destiny = gear.origin; SetGear(g); } } gears[currentGear_] = gear; SetGear(currentGear_); // Empties the holder and lock the inputs currentGear_ = -1; lock_ = true; }