public void GiveTarget(Selectable target) { // First we'll try to resolve 'target' as either a Unit or a Tile. SelectableCell targetCell = target as SelectableCell; SelectableUnit targetUnit; if (targetCell == null) // it's not a SelectableTile, maybe it's a SelectableUnit { targetUnit = target as SelectableUnit; } else if (targetCell.IsOccupied()) // it IS a SelectableTile, and it's occupied! { targetUnit = GetComponentInChildren <SelectableUnit>(); } else // it is a non-occupied SelectableTile { unit.MoveTo(targetCell.GetCell()); return; } if (targetUnit != null) // it is a SelectableUnit, try to attack it. { if (IsValidTarget(targetUnit)) { unit.Attack(targetUnit.GetUnit()); // Let Unit figure out whether it's in range of weapon and such } else { Debug.Log("Other Unit not a valid target"); } } }
private void CreateRegion(byte[,] region, bool[,] emptyCells, Vector2 pos) { int height = region.GetLength(0); int width = region.GetLength(1); for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { Vector3 position = new Vector3(j + pos.y, i + pos.x, 0); GameObject cellObj = Instantiate(cellPrefab, position, Quaternion.identity, transform); Cell cell = cellObj.GetComponent <Cell>(); SelectableCell selCell = cellObj.GetComponent <SelectableCell>(); selCell.onClick.AddListener(Click); SetSelectableCellCoords(selCell, new Vector2(pos.x / width, pos.y / height), new Vector2(i, j)); cells.Add(cellObj); if (emptyCells[i, j] == false) { cell.SetText(region[i, j]); selCell.enabled = false; } else { cell.SetTextColor(selCell.textColor); cell.HideText(); selectableCells.Add(selCell); } } } }
protected override void Cell_OnCellPress(SelectableCell <AssignShipToDockCellData> cell) { base.Cell_OnCellPress(cell); cell.data.dock.AssignShip(shipToAssign); InstitutionsUIManager.Instance.ManufactoryUIManager.PopTopViewController(); Manufactory.RemoveShipFromStorage(shipToAssign); }
private void DeselectAllExcept(SelectableCell cell) { foreach (var item in selectableCells) { if (item != cell) { item.Select(false); } } }
protected override void Cell_OnCellPress(SelectableCell <StudyCellData> cell) { base.Cell_OnCellPress(cell); pressedStudyCell = cell; print(cell.data.study.studyType); print(cell.data.study.GetCode()); CreateUnlockPopUp(cell.data.study); }
// Show an arrow in selectables cells private void showSelector(IsoUnity.Cell cell, EventTypes eventType, CallbackSelector callback = null) { SelectableCell selectableCell = cell.transform.gameObject.AddComponent <SelectableCell>(); selectableCell.arrow = arrow; selectableCell.selectedCellEvent = selectedCellEvent; selectableCell.previousTexture = cell.Properties.faces[cell.Properties.faces.Length - 1].TextureMapping; selectableCell.cell = cell; selectableCell.eventType = eventType; selectableCell.callback = callback; }
internal void Configure(SelectableCell cell, HostedGameCellData cellInfo) { this._cell = cell; this._cellInfo = cellInfo; this._background = cell.transform.Find("Background").GetComponent <ImageView>(); if (_enabled) { OnEnable(); } }
private void Click(SelectableCell cell) { DeselectAllExcept(cell); bool hasActiveCell = IsActive(); onClick.Invoke(hasActiveCell); if (hasActiveCell) { ActiveCell = cell; } else { ActiveCell = null; } }
static bool Prefix(SelectableCell selectableCell, SelectableCell.TransitionType transitionType, object changeOwner, ref int ____selectedCellNumber, Action <SegmentedControl, int> ___didSelectCellEvent, Dictionary <int, Action <int> > ____callbacks, SegmentedControl __instance) { if (____selectedCellNumber == -1) { SegmentedControlCell segmentedControlCell = (SegmentedControlCell)selectableCell; ____selectedCellNumber = segmentedControlCell.cellNumber; ___didSelectCellEvent?.Invoke(__instance, segmentedControlCell.cellNumber); if (____callbacks.TryGetValue(segmentedControlCell.cellNumber, out Action <int> value)) { value?.Invoke(segmentedControlCell.cellNumber); } return(false); } return(true); }
protected override void Cell_OnCellPress(SelectableCell <DocksCellData> cell) { base.Cell_OnCellPress(cell); switch (cell.data.dock.DockState) { case DockState.Unlocked: CosmicPortUIManager.DocksViewController.ShowBuildDockView(); break; case DockState.Empty: CosmicPortUIManager.DocksViewController.ShowAssignShipView(); break; case DockState.Occupied: CosmicPortUIManager.ShowSendShipView(GetSelectedCell().data.dock); break; } }
public void ClearSelection() { if (CurrentSelection != null) { CurrentSelection.OnDeselect(); CurrentSelection = null; } if (SelectionCursor != null) { SelectionCursor.SetActive(false); } CurrentBuilder = null; if (HoverCell != null) { HoverCell.OnDeselect(); HoverCell = null; } CurrentMode = SelectionMode.Normal; }
private void OnHighlightDidChange(SelectableCell cell, SelectableCell.TransitionType transition) { }
protected override void Cell_OnCellPress(SelectableCell <FactoryCellData> cell) { base.Cell_OnCellPress(cell); InstitutionsUIManager.Instance.ManufactoryUIManager.FactoryViewController.ShowBuildShipView(cell.data.shipRecipe); }
private void SetSelectableCellCoords(SelectableCell cell, Vector2 gridPos, Vector2 regionPos) { cell.gridPos = gridPos; cell.regionPos = regionPos; }
private void OnSelectionDidChange(SelectableCell cell, SelectableCell.TransitionType transition, object _) { UpdateCellBackground(); }
protected override void Cell_OnCellPress(SelectableCell <StorageCellData> cell) { base.Cell_OnCellPress(cell); OnCellPressed(cell.data.ship.shipType); }
private void OnHighlightDidChange(SelectableCell cell, SelectableCell.TransitionType transition) { RefreshBackground(); }
private void OnSelectionDidChange(SelectableCell cell, SelectableCell.TransitionType transition, object _) { RefreshBackground(); RefreshContent(); }
void Update() { if (Input.GetKey(KeyCode.Escape)) { ClearSelection(); } // Handle Selection with left click if (CurrentMode == SelectionMode.Normal || CurrentMode == SelectionMode.GivingOrder) { // First: Left mouse button to select a target unit if (Input.GetMouseButtonDown(0)) // Left mouse button { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); Debug.DrawRay(ray.origin, ray.direction * float.MaxValue, Color.cyan, 10f); // Debug our ray! RaycastHit hitInfo; if (Physics.Raycast(ray, out hitInfo)) { SelectableUnit leftClickedObj = hitInfo.collider.GetComponentInParent <SelectableUnit>(); if (leftClickedObj != null) { ClearSelection(); // Deselect previous object if (leftClickedObj.CanBeSelected()) { SelectUnit(leftClickedObj); } else { Debug.Log("Unit not selectable by you!"); } } else { Debug.Log("Clicked object not a selectable unit!"); } } } } if (CurrentMode == SelectionMode.GivingOrder) { // Right mouse button to give a target to our current selection if (Input.GetMouseButtonDown(1)) // Right mouse button { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hitInfo; if (Physics.Raycast(ray, out hitInfo)) { Selectable rightClickedObj = hitInfo.collider.GetComponentInParent <Selectable>(); if (rightClickedObj != null) { CurrentSelection.GiveTarget(rightClickedObj); ClearSelection(); } } } } if (CurrentMode == SelectionMode.PlacingUnit) { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hitInfo; if (Physics.Raycast(ray, out hitInfo)) { SelectableCell newHoverCell = hitInfo.collider.GetComponentInParent <SelectableCell>(); if (HoverCell != newHoverCell) { if (HoverCell != null) { HoverCell.OnDeselect(); } HoverCell = newHoverCell; // Can also be null! if (HoverCell != null) { HoverCell.OnSelect(); } } } else // Moused over nothing { if (HoverCell != null) { HoverCell.OnDeselect(); HoverCell = null; } } if (Input.GetMouseButton(0)) // Place with left mouse button { if (HoverCell != null) { CurrentBuilder.SpawnUnit(HoverCell.GetCell()); ClearSelection(); } } if (Input.GetMouseButton(1)) // cancel with right { ClearSelection(); } } }