Ejemplo n.º 1
0
 public bool DoTouchMachineConveyor(TouchInfo touch, TouchPick touchPick)
 {
     if (GetPickerPosition(touch.now.position, PickMask.Construct, out Vector3 pickerPosition, out Pickable pickable) && touchPick.startingTile == pickerPosition.RoundDown())
     {
         SelectionState interfaceState = InterfaceSelectionManager.instance.state;
         if (interfaceState.selectionMode == SelectionMode.Machine)
         {
             Machine machine = MachineSystem.instance.GetMachine(pickerPosition.RoundDown());
             if (!machine)
             {
                 Bounds3Int bounds = pickerPosition.PositionBottomToBounds(interfaceState.machineInfo.size);
                 machine = MachineSystem.instance.CreateMachine(interfaceState.machineInfo, bounds);
             }
             if (machine)
             {
                 machine.Drop();
                 TileSelectionManager.instance.SetSelection(machine);
                 return(true);
             }
         }
         else if (interfaceState.selectionMode == SelectionMode.Conveyor)
         {
             // If we selected a neighbor and tapped here it might be because we mistapped a ConveyorButton
             // Link them anyway like a conveyor button
             Conveyor       conveyor  = null;
             SelectionState selection = TileSelectionManager.instance.selectionState;
             if (selection.isSelected)
             {
                 foreach ((Vector3Int outerTile, Vector3Int innerTile) in selection.bounds.EnumeratePerimeter())
                 {
                     if (outerTile == pickerPosition.RoundDown())
                     {
                         conveyor = ConveyorSystem.instance.GetOrCreateConveyor(lastMouseDragPosition, pickerPosition.RoundDown(), ConveyorCreateFlags.SelectConveyor | ConveyorCreateFlags.PanRelative);
                         return(true);
                     }
                 }
             }
             if (!conveyor)
             {
                 conveyor = ConveyorSystem.instance.CreateConveyor(pickerPosition.RoundDown(), ConveyorCreateFlags.SelectConveyor);
                 return(true);
             }
         }
     }
     return(false);
 }
Ejemplo n.º 2
0
    bool ConsumeTouchMachineConveyor(TouchInfo touch)
    {
        if (!touch.canvas)
        {
            if (touch.now.phase == TouchPhase.Began && GetPickerTile(touch.now.position, PickMask.Construct, out Vector3Int pickerTile))
            {
                TouchInput.inputMode = InputMode.Touch;
                touchPicks.Add(new TouchPick
                {
                    fingerId     = touch.now.fingerId,
                    startingTile = pickerTile
                });
                return(false);
            }

            if (touch.now.phase == TouchPhase.Moved)
            {
                if (TouchPicksContain(touch.now.fingerId, out int touchPickIndex) && GetPickerTile(touch.now.position, PickMask.Construct, out pickerTile))
                {
                    TouchPick touchPick = touchPicks[touchPickIndex];
                    if (pickerTile != touchPick.startingTile)
                    {
                        RemoveTouchPick(touch.now.fingerId);
                        return(false);
                    }
                }
            }

            if (touch.now.phase == TouchPhase.Ended)
            {
                if (TouchPicksContain(touch.now.fingerId, out int touchPickIndex))
                {
                    TouchPick touchPick = touchPicks[touchPickIndex];
                    RemoveTouchPick(touch.now.fingerId);
                    return(DoTouchMachineConveyor(touch, touchPick));
                }
            }
        }
        RemoveTouchPick(touch.now.fingerId);
        return(false);
    }