public override void Update(float deltaTime) { _time = _time + deltaTime; position = _camera.GetScreenPosition(_behaviour.worldPosition) + _camera.worldContainer.GetPosition() + new Vector2(0f, 48f); // + Mathf.Sin(_time * 12f) * 0.5f); if (_time * SpeechSpeed < _text.Length + 1) { _label.text = _text.Substring(0, (int)(_time * SpeechSpeed)); } _rect.size = _label.textRect.size; if (_time > _duration) { float factor = Mathf.Clamp01(_time - _duration); if (factor < 1f) { container.alpha = Mathf.Clamp01(1f - factor); } else { RemoveSelf(); } } base.Update(deltaTime); }
public virtual void RenderUpdate(SpriteLeaser spriteLeaser, WorldCamera camera) { if (world != null) { FSprite sprite = spriteLeaser.sprites[0]; if (element != null) { sprite.isVisible = true; sprite.element = element; } else { sprite.isVisible = false; } sprite.SetPosition(camera.GetScreenPosition(worldPosition) + _positionOffset); sprite.rotation = _rotation; sprite.scaleX = scale.x; sprite.scaleY = scale.y; if (doesFlip) { sprite.scaleX *= (camera.GetFlipXByViewAngle(viewAngle) ? -1f : 1f); } sprite.sortZ = camera.GetSortZ(worldPosition) + sortZOffset; sprite.color = color; // new Color(worldPosition.x, worldPosition.y, worldPosition.z); } else { spriteLeaser.Erase(); } }
public override void Update(float deltaTime) { _time += deltaTime; if (_time > 5f) { RemoveSelf(); } Vector2 targetScreenPosition = _camera.GetScreenPosition(_positionable.worldPosition) + _camera.worldContainer.GetPosition(); Vector2 offset = new Vector2(0f, Mathf.Sqrt(_time * 4f) * 16f); Vector2 shakeoffset = Random.insideUnitCircle * Mathf.Max((0.5f - _time) * 10f, 0f); Vector2 position = targetScreenPosition + offset + shakeoffset; _label.position = position; _label.alpha = Mathf.Clamp01(1.5f - _time); if (_time < 0.5f) { _label.color = _colors[Random.Range(0, 3)]; } else { _label.color = _colors[0]; } base.Update(deltaTime); }
public void SetConstructionGuide(WorldCamera worldCamera, Player player, Vector3 worldPosition, Vector3 hitDirection, bool inRange) { _previewSprite.SetPosition(worldCamera.GetScreenPosition(worldPosition + hitDirection)); _previewSprite.sortZ = worldCamera.GetSortZ(worldPosition) + 0.1f; _previewSprite.color = inRange ? Color.cyan : Color.red; _previewSprite.alpha = Mathf.Sin(menu.time * Mathf.PI) * 0.25f + 0.5f; _previewSprite.element = player.pickItemStack.item.element; }
public void SetSpriteByTile(FSprite target, Tile tile, WorldCamera camera, bool optimizeColor = false) { Vector3 spritePosition = tile.coordination + Vector3.one * 0.5f; target.SetPosition(camera.GetScreenPosition(spritePosition)); target.sortZ = camera.GetSortZ(spritePosition); if (optimizeColor) { target.color = new Color(tile.coordination.x, tile.coordination.y, tile.coordination.z); } }
public void SetConstructionGuide(WorldCamera worldCamera, Player player, Vector3Int tilePosition, bool inRange, float progress) { Vector3 worldPosition = tilePosition + Vector3.one * 0.5f; _previewSprite.SetPosition(worldCamera.GetScreenPosition(worldPosition)); _previewSprite.sortZ = worldCamera.GetSortZ(worldPosition) + 0.1f; // _previewSprite.color = Color.Lerp(inRange ? Color.cyan : Color.red, Color.black, progress); // _previewSprite.alpha = Mathf.Sin(menu.time * Mathf.PI) * 0.25f + 0.5f; _previewSprite.alpha = progress > 0f ? 1f : 0f; _previewSprite.element = _destroyElements[Mathf.FloorToInt(Mathf.Clamp01(progress) * 7f)]; }
public override void CursorUpdate(World world, Player player, Vector2 cursorPosition) { WorldCamera camera = world.worldCamera; List <ITarget> targets = world.targets; ITarget nearestTarget = null; Vector2 screenPositionA, screenPositionB; screenPositionA = new Vector2(1920f, 1080f); for (int index = 0; index < targets.Count; index++) { screenPositionB = camera.GetScreenPosition(targets[index].worldPosition) + camera.worldContainer.GetPosition(); float sqrMagnitude = (screenPositionB - cursorPosition).sqrMagnitude; //if ((screenPositionB.x > Menu.screenWidth * 0.5f || screenPositionB.x < Menu.screenWidth * -0.5f) || // (screenPositionB.y > Menu.screenHeight * 0.5f || screenPositionB.y < Menu.screenHeight * -0.5f)) if (sqrMagnitude > 4096f) { continue; } else if ((screenPositionA - cursorPosition).sqrMagnitude > sqrMagnitude) { nearestTarget = targets[index]; screenPositionA = screenPositionB; } } if (_currentTarget != nearestTarget) { _lastScreenPosition = position; _lastSize = size; _currentTarget = nearestTarget; _lastTime = menu.time; _targetInspector.InspectTarget(_currentTarget); } if (_currentTarget != null) { _targetScreenPosition = screenPositionA + nearestTarget.boundRect.position; _targetSize = nearestTarget.boundRect.size; if (Input.GetKey(KeyCode.Mouse0)) { player.UseItem(_currentTarget.worldPosition, Input.GetKeyDown(KeyCode.Mouse0)); } } else { _targetScreenPosition = cursorPosition; _targetSize = new Vector2(12f, 12f); if (Input.GetKey(KeyCode.Mouse0)) { RayTrace rayTrace = camera.GetRayAtScreenPosition(cursorPosition - camera.worldContainer.GetPosition()); Vector3 targetPosition = new Vector3(rayTrace.hitPosition.x, player.worldPosition.y, rayTrace.hitPosition.z); if (rayTrace.hit) { player.UseItem(targetPosition, Input.GetKeyDown(KeyCode.Mouse0)); } } } }