private void SortInventory() { inventory.Sort(SortUnitByCharacterArchetype); inventoryCards.Sort(SortCardByCharacterArchetype); foreach (var card in inventoryCards) { InventCharButton element = card.GetComponent <InventCharButton>(); if (element.showDetails) { element.ToggleDetails(); } } if (!inventoryScreen) { for (int i = 0; i < inventory.Count; i++) { float xValue = 100.0f * i - (100f * 4) * Mathf.Floor((float)i / 4); float yValue = -90.0f * Mathf.Floor((float)i / 4); Vector3 cardPosition = inventoryCardPlacer.position + new Vector3(xValue, yValue, 0); inventoryCards[i].LeanMove(cardPosition, 0.2f); } } else { for (int i = 0; i < inventory.Count; i++) { float xValue = 120.0f * i - (120f * 6) * Mathf.Floor((float)i / 6); float yValue = -90.0f * Mathf.Floor((float)i / 6); Vector3 cardPosition = inventoryCardPlacer.position + new Vector3(xValue, yValue, 0); inventoryCards[i].LeanMove(cardPosition, 0.2f); } } }
private void UnitDrag(Vector3 target) { RaycastHit hit; Ray ray = Camera.main.ScreenPointToRay(target); if (Physics.Raycast(ray, out hit, 100.0f, castMask)) { Tile hitTile = hit.transform.gameObject.GetComponent <Tile>(); if (hitTile.heldUnit != null && hitTile.isYours) { originTile = hit.transform.gameObject.GetComponent <Tile>(); fromTile = true; holdingUnit = true; } } List <RaycastResult> castHits = new List <RaycastResult>(); PointerEventData eventPoint = new PointerEventData(eventSystem); eventPoint.position = target; gRayCaster.Raycast(eventPoint, castHits); if (castHits.Count > 0) { for (int i = 0; i < castHits.Count; i++) { InventCharButton element = castHits[i].gameObject.GetComponentInParent <InventCharButton>(); if (element != null) { // take unit from inventory if (element.showDetails) { inventoryManager.ToggleInventoryDetails(element.gameObject); } if (Input.mousePosition.x < Screen.width - 250) { TakeUnitFromInventory(element); } else { inventoryHover.HoldThis(element.gameObject); } break; } } } }
IEnumerator waitToConfirmDrag(float waitTime, Vector3 pointerPosition) { showingDetails = false; detailShower.SetActive(false); yield return(new WaitForSeconds(waitTime)); if (Input.GetMouseButton(0)) { UnitDrag(pointerPosition); } else { // Debug.Log("I was only clicked"); List <RaycastResult> castHits = new List <RaycastResult>(); PointerEventData eventPoint = new PointerEventData(eventSystem); eventPoint.position = pointerPosition; gRayCaster.Raycast(eventPoint, castHits); if (castHits.Count > 0) { for (int i = 0; i < castHits.Count; i++) { // Debug.Log("I hit " + castHits[i].gameObject.name); InventCharButton element = castHits[i].gameObject.GetComponentInParent <InventCharButton>(); if (element != null) { inventoryManager.ToggleInventoryDetails(element.gameObject); break; } } } else { RaycastHit hit; Ray ray = Camera.main.ScreenPointToRay(pointerPosition); if (Physics.Raycast(ray, out hit, 100.0f, castMask)) { Tile target = hit.transform.GetComponent <Tile>(); if (target.heldUnit != null) { ShowDetails(target.heldUnit); } } } } }
// Update is called once per frame void Update() { if (Input.GetMouseButtonDown(0) && inventoryScreen) { List <RaycastResult> castHits = new List <RaycastResult>(); PointerEventData eventPoint = new PointerEventData(eventSystem); eventPoint.position = Input.mousePosition; gRayCaster.Raycast(eventPoint, castHits); if (castHits.Count > 0) { for (int i = 0; i < castHits.Count; i++) { // Debug.Log("I hit " + castHits[i].gameObject.name); InventCharButton element = castHits[i].gameObject.GetComponentInParent <InventCharButton>(); if (element != null) { // show details ShowUnit(element.charIndex, false); break; } } } } }
public void TakeUnitFromInventory(InventCharButton element) { heldUnit = inventoryManager.TakeFromInventory(element.gameObject).GetComponent <Character>(); holdingUnit = true; }