private void Start() { camera = GetComponent <Camera>(); if (camera.orthographic) { Debug.LogWarning("The camera should be perspective mode for the zoom to work"); } startPos = transform.position; zoomOn = null; zoomLevel = 0; }
public void UnZoom() { if (zoomOn != null) { zoomOn.SetActive(false); zoomOn = null; } zoomLevel = startLevel; targetPos = startPos; startDistance = Vector3.Distance(transform.position, targetPos); timeLeft = zoomPeriod; }
private void SetZoomable() { gameObject.AddComponent <Zoomable>(); Zoomable zoomableScript = GetComponent <Zoomable>(); Zoomable.Config config; config.startPos = zoomablePos; config.maxZoomIn = maxZoomIn; config.maxZoomOut = maxZoomOut; zoomableScript.Init(config); }
public void ZoomAt(Zoomable zoomOn, float scale) { if (zoomLevel == houseLevel) { return; } this.zoomOn = zoomOn; zoomLevel++; Vector3 zoomOnPos = zoomOn.transform.position; targetPos = new Vector3(zoomOnPos.x, zoomOnPos.y, transform.position.z + (zoomOnPos.z - transform.position.z) * (scale - 1) / scale); startDistance = Vector3.Distance(transform.position, targetPos); timeLeft = zoomPeriod; }
private void Update() { if (timeLeft > 0) { transform.position = Vector3.MoveTowards(transform.position, targetPos, startDistance * Time.deltaTime / zoomPeriod); timeLeft -= Time.deltaTime; if (timeLeft < 0 && zoomOn != null) { zoomOn.SetActive(true); if (zoomOn.scene != "") { SceneManager.LoadScene(zoomOn.scene); } } } if (Input.GetMouseButtonUp(0)) { Ray ray = camera.ScreenPointToRay(Input.mousePosition); RaycastHit[] hit = Physics.RaycastAll(ray); foreach (var target in hit) { Zoomable zoomAtObj = target.transform.GetComponent <Zoomable>(); if (zoomLevel + 1 == zoomAtObj.zoomLevel) { ZoomAt(zoomAtObj, zoomScale); break; } } } if (zoomLevel > 0 && Input.GetKeyUp(KeyCode.Escape)) { UnZoom(); } }
private void Awake() { mainCamera = GetComponent <Camera>(); zoomable = GetComponent <Zoomable>(); IsAiming = false; }
private void ProcessZoom(GameTime gameTime, Zoomable zoomable, MouseStateExtended mouseState) { zoomable.Zoom -= (float)gameTime.ElapsedGameTime.TotalSeconds * 0.015f * mouseState.DeltaScrollWheelValue; }