void Update() { if (_goToTargetRoutine == null && Time.time - _lastClickTime > _clickWaitTime) { SetTargetPos(transform.position + Random.insideUnitSphere * _wanderDist); } Vector3 toDude = (transform.position - Planet.instance.transform.position).normalized; Vector3 toCamera = (UIManager.GetPanel <BreedPanel>().GetViewRect().position - Planet.instance.transform.position).normalized; float edgeDot = Vector3.Dot(toDude, toCamera); _spriteRenderer.enabled = edgeDot > _cullDot; _shadow.GetShadow().enabled = edgeDot > _cullDot; }
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(); } }