public void AssignBlock(Block block) { foreach (var kvp in block.GetSpriteToSlotMap()) { BitSlotWidget slot = kvp.Value; slot.used = true; Transform spriteParent = new GameObject(gameObject.name + "SpriteRoot").transform; spriteParent.localScale = block.transform.localScale; spriteParent.SetParent(slot.transform); float slotAlpha = _bitSlots.IndexOf(slot) / (float)_bitSlots.Count; spriteParent.position = slot.transform.position + -Camera.main.transform.forward * _slotOffsetRange.Lerp(slotAlpha); SpriteRenderer sprite = kvp.Key; sprite.transform.SetParent(spriteParent); sprite.transform.localPosition = Vector3.zero; sprite.GetComponent <Collider>().enabled = false; } string soundName = "SFX_BlockPlacement" + (Mathf.Clamp(_addedBlockTypes.Count, 0, 3) + 1); GameSound placeSound = (GameSound)System.Enum.Parse(typeof(GameSound), soundName); GameSounds.PostEvent2D(placeSound); _addedBlockTypes.Add(block.GetBlockType()); if (_addedBlockTypes.Count > 1) { _combineButton.gameObject.SetActive(true); } }
void OnMouseDrag() { if (_activeInputLens != null) { Vector2 screenMin = Vector2.zero; Vector2 screenMax = new Vector2(Screen.width, Screen.height); Vector3 mousePos = ((Vector3)WadeUtils.Clamp((Vector2)Input.mousePosition, screenMin, screenMax)).SetZ(Input.mousePosition.z); Vector2 screenBoundDiff = screenMax - screenMin; screenMin += screenBoundDiff * 0.001f; screenMax -= screenBoundDiff * 0.001f; mousePos = ((Vector3)WadeUtils.Clamp((Vector2)mousePos, screenMin, screenMax)).SetZ(mousePos.z); Vector3 worldPos = Camera.main.ScreenToWorldPoint(mousePos); Vector3 rotatePivotOffset = _rotatePivot.position - transform.position; transform.position = worldPos + Camera.main.transform.forward * _selectedCamOffset - rotatePivotOffset; bool uiOverlap = RectTransformUtility.RectangleContainsScreenPoint(GetBreed().GetBreedRect(), mousePos, Camera.main); if (uiOverlap != _prevUIOverlap) { if (_changeScaleRoutine != null) { StopCoroutine(_changeScaleRoutine); } _changeScaleRoutine = StartCoroutine(ChangeScaleRoutine(uiOverlap)); _groundShadow.GetShadow().gameObject.SetActive(!uiOverlap); _prevUIOverlap = uiOverlap; } if (!uiOverlap) { if (Physics.Raycast(worldPos, Camera.main.transform.forward - Camera.main.transform.up * 0.17f, out _hitInfo, Mathf.Infinity, _planetLayer, QueryTriggerInteraction.Ignore)) { _groundShadow.SetPos(_hitInfo.point); } } bool leftOverlap = RectTransformUtility.RectangleContainsScreenPoint(GetBreed().GetLeftRotateRect(), mousePos, Camera.main); if (leftOverlap != _prevLeftOverlap) { if (leftOverlap) { GameSounds.PostEvent2D(GameSound.SFX_BlockRotateCounterClockwise); if (_rotateRoutine != null) { StopCoroutine(_rotateRoutine); } _rotateRoutine = StartCoroutine(RotateRoutine(false)); } _prevLeftOverlap = leftOverlap; } bool rightOverlap = RectTransformUtility.RectangleContainsScreenPoint(GetBreed().GetRightRotateRect(), mousePos, Camera.main); if (rightOverlap != _prevRightOverlap) { if (rightOverlap) { GameSounds.PostEvent2D(GameSound.SFX_BlockRotateClockwise); if (_rotateRoutine != null) { StopCoroutine(_rotateRoutine); } _rotateRoutine = StartCoroutine(RotateRoutine(true)); } _prevRightOverlap = rightOverlap; } _spriteToSlotMap.Clear(); List <BitSlotWidget> bitSlots = GetBreed().GetBitSlots(); for (int i = 0; i < bitSlots.Count; i++) { bitSlots[i].SetHighlight(false); } for (int i = 0; i < _bitSprites.Length; i++) { SpriteRenderer bitSprite = _bitSprites[i]; Vector3 spriteViewPos = Camera.main.WorldToViewportPoint(bitSprite.transform.position); for (int j = 0; j < bitSlots.Count; j++) { BitSlotWidget bitSlot = bitSlots[j]; if (!bitSlot.used) { Vector3 slotViewPos = Camera.main.WorldToViewportPoint(bitSlot.transform.position); if (Vector2.Distance(spriteViewPos, slotViewPos) < _gridSlotMaxDist) { // Temp-mark used so slots are distinct bitSlot.used = true; bitSlot.SetHighlight(true); _spriteToSlotMap.Add(bitSprite, bitSlot); break; } } } } // Unmark temp-used slots foreach (var kvp in _spriteToSlotMap) { kvp.Value.used = false; } ResetFadeoutTimer(); } }