void SelectPlacable(HexCellPlaceable mechanism) { Debug.Log("Selecting " + mechanism); selectedPlacables.Add(mechanism); mechanism.selected = true; OnSelectionChange(selectedPlacables); }
void ToggleSelectMechanism(HexCellPlaceable mechanism) { if (selectedPlacables.Contains(mechanism)) { DeselectMechanism(mechanism); } else { SelectPlacable(mechanism); } }
public void ClearLevel() { // clear targets? (they get overridden if necessary) // clear all hexcellplacables foreach (HexCell hc in GridManager.instance.GetAllCells()) { HexCellPlaceable placeable = hc.placedPlaceable; if (placeable != null) { hc.placedPlaceable = null; ObjectPoolManager.DestroyObject(placeable); } } }
void DeselectMechanism(HexCellPlaceable mechanism) { selectedPlacables.Remove(mechanism); mechanism.selected = false; }
public void SelectUniqueMechanism(HexCellPlaceable mechanism) { ClearSelectionSilently(); SelectPlacable(mechanism); }
public void HandleRay(Ray inputRay, ControlState pressState, ControlState dragState) { debugDrawColor = Input.GetMouseButton(0) ? Color.green : Color.red; // if (Input.GetMouseButtonDown(0)) // { // Debug.Log("Input.GetMouseButtonDown(0)"); // } // Debug.DrawRay(inputRay.origin, inputRay.direction*1000f, debugDrawColor, 1f); RaycastHit hitInfo = new RaycastHit(); if (Physics.Raycast(inputRay, out hitInfo, 1000, 1 << LayerMask.NameToLayer("Hex Cell"))) { OverCell = true; ClosestHexCell = hitInfo.collider.gameObject.GetComponent <HexCell>(); } else { OverCell = false; foreach (HexCell outsideCell in GridManager.instance.GetOutsideCells()) { ClosestHexCell = ClosestHexCell ?? outsideCell; float distanceToOutsideCell = Vector3.Distance(outsideCell.transform.position, inputRay.origin); float closestDistance = Vector3.Distance(ClosestHexCell.transform.position, inputRay.origin); ClosestHexCell = distanceToOutsideCell < closestDistance ? outsideCell : ClosestHexCell; } } _debug_ClosestHexCell = ClosestHexCell; _debug_OverHexCell = OverHexCell; _debug_OverHexCellMechanism = OverHexCell == null?null:OverHexCell.placedPlaceable; if (Input.GetMouseButtonDown(0)) { if (OverHexCell != null) { if (OverHexCell.placedPlaceable != null) { SelectUniqueMechanism(OverHexCell.placedPlaceable); } else { ClearSelection(); } } StartDragging(); } if (Input.GetMouseButton(0)) { } if (Input.GetMouseButtonUp(0)) { StopDragging(); } if (!Input.GetMouseButton(0)) { StopDragging(); } Debug.DrawLine(inputRay.origin, ClosestHexCell.transform.position, debugDrawColor, 1f); // Debug.Log(closestHexCell.location.x+":"+closestHexCell.location.y); }