public void DecreaseCamera() { float localScale = eyeCamera.orthographicSize; float scale = localScale + zoomFactor; Scale2D.SetCameraOrthographicSize(scale, eyeCamera); }
void Awake() { Scale2D.Update(); DataScale2D = DataManager.Instance.getData("Scale2D"); spriteSize = spriteRenderer.sprite.bounds.size; DataScale2D.Bind(UpdateSize); }
// Use this for initialization public void EnlargeCamera() { float localScale = eyeCamera.orthographicSize; float scale = localScale - zoomFactor; Scale2D.SetCameraOrthographicSize(scale, eyeCamera); }
private void DisplayPanel(GameObject panel) { print("Display panel: " + panel.name); animations.Add( Scale2D.On(panel) .From(Vector3.zero) .To(Vector3.one) .For(0.5f) .Over(Curve.CubicEaseOut) .Start() ); }
protected override void UpdateCameraSize() { #if !UNITY_EDITOR && (UNITY_IOS || UNITY_ANDROID) return; #endif float scaleNow = Input.GetAxis("Mouse ScrollWheel"); if (scaleNow == 0) { return; } touchCenter = Input.mousePosition; worldCenter = eyeCamera.ViewportToWorldPoint(eyeCamera.ScreenToViewportPoint(touchCenter)); //放大因子, 一个像素按 0.01倍来算(100可调整) float scaleFactor = scaleNow / zoomFactor; float localScale = eyeCamera.orthographicSize; float scale = localScale + scaleFactor; if (scale < minScale) { scale = minScale; } else if (scale > maxScale) { scale = maxScale; } Scale2D.SetCameraOrthographicSize(scale, eyeCamera); Vector3 nowWorldCenter = eyeCamera.ViewportToWorldPoint(eyeCamera.ScreenToViewportPoint(touchCenter)); transform.position = transform.position + (worldCenter - nowWorldCenter); if (Bounds) { var x = transform.position.x; var y = transform.position.y; var cameraHalfWidth = eyeCamera.orthographic ? Scale2D.cameraSize.x / 2 : 0; var cameraHalfHeight = eyeCamera.orthographic ? Scale2D.cameraSize.y / 2 : 0; //保证不会移除包围盒 // Debug.Log(transform.position); x = Mathf.Clamp(x, minVec3.x + cameraHalfWidth, maxVec3.x - cameraHalfWidth); y = Mathf.Clamp(y, minVec3.y + cameraHalfHeight, maxVec3.y - cameraHalfHeight); transform.position = new Vector3(x, y, transform.position.z); } touchCenter = Input.mousePosition; worldCenter = eyeCamera.ViewportToWorldPoint(eyeCamera.ScreenToViewportPoint(touchCenter)); }
private void HidePanel(List <string> excluding) { foreach (KeyValuePair <string, GameObject> entry in panels) { if (!excluding.Contains(entry.Key) && entry.Value.activeSelf) { print("Hide panel: " + entry.Value.name); animations.Add( Scale2D.On(entry.Value) .From(Vector3.one) .To(Vector3.zero) .For(0.5f) .Over(Curve.CubicEaseOut) .AndThen(() => { //entry.Value.transform.localScale = Vector3.zero; entry.Value.SetActive(false); }) .Start() ); } } }
protected virtual void UpdateCameraSize() { if (Input.touchCount != 2) { return; } for (int i = 0; i < Input.touchCount; ++i) { if (EventSystem.current.IsPointerOverGameObject(Input.GetTouch(i).fingerId)) { return; } } //多点触摸, 放大缩小 Touch newTouch1 = Input.GetTouch(0); Touch newTouch2 = Input.GetTouch(1); for (int i = 0; i < Input.touchCount; ++i) { if (Input.GetTouch(i).phase == TouchPhase.Began || Input.GetTouch(i).phase == TouchPhase.Canceled || Input.GetTouch(i).phase == TouchPhase.Ended) { oldTouch2 = newTouch2; oldTouch1 = newTouch1; touchCenter = (oldTouch1.position + oldTouch2.position) / 2; worldCenter = eyeCamera.ViewportToWorldPoint(eyeCamera.ScreenToViewportPoint(touchCenter)); return; } } //计算老的两点距离和新的两点间距离,变大要放大模型,变小要缩放模型 float oldDistance = Vector2.Distance(oldTouch1.position, oldTouch2.position); float newDistance = Vector2.Distance(newTouch1.position, newTouch2.position); //两个距离之差,为正表示放大手势, 为负表示缩小手势 float offset = oldDistance - newDistance; //放大因子, 一个像素按 0.01倍来算(100可调整) float scaleFactor = offset / zoomFactor; float localScale = eyeCamera.orthographicSize; float scale = localScale + scaleFactor; if (scale < minScale) { scale = minScale; } else if (scale > maxScale) { scale = maxScale; } Scale2D.SetCameraOrthographicSize(scale, eyeCamera); Vector3 nowWorldCenter = eyeCamera.ViewportToWorldPoint(eyeCamera.ScreenToViewportPoint(touchCenter)); transform.position = transform.position + (worldCenter - nowWorldCenter); if (Bounds) { var x = transform.position.x; var y = transform.position.y; var cameraHalfWidth = eyeCamera.orthographic ? Scale2D.cameraSize.x / 2 : 0; var cameraHalfHeight = eyeCamera.orthographic ? Scale2D.cameraSize.y / 2 : 0; //保证不会移除包围盒 // Debug.Log(transform.position); x = Mathf.Clamp(x, minVec3.x + cameraHalfWidth, maxVec3.x - cameraHalfWidth); y = Mathf.Clamp(y, minVec3.y + cameraHalfHeight, maxVec3.y - cameraHalfHeight); transform.position = new Vector3(x, y, transform.position.z); } //记住最新的触摸点,下次使用 oldTouch1 = newTouch1; oldTouch2 = newTouch2; touchCenter = (oldTouch1.position + oldTouch2.position) / 2; worldCenter = eyeCamera.ViewportToWorldPoint(eyeCamera.ScreenToViewportPoint(touchCenter)); }
// >>> TO XNA /// <summary> /// Convers a <see cref="Scale2D"/> into to a <see cref="XnaVector2"/>. /// </summary> /// <param name="source">Source <see cref="Scale2D"/>.</param> /// <returns>The <see cref="XnaVector2"/>.</returns> public static XnaVector2 ToXnaVector2(this Scale2D source) => new XnaVector2(source.Horizontal, source.Vertical);
void Awake() { Scale2D.Update(); DataScale2D = DataManager.Instance.getData("Scale2D"); DataScale2D.Bind(UpdateSize); }