private void setConfig(Vector3 position1, Vector3 position2) { Vector3 displacement = position1 - position2; Vector3 scale = new Vector3(); float angle = Mathf.Abs(displacement.x) < Util.EPSILON ? ((displacement.y > 0) ? 90f : -90f) : Util.GetAngleFromVectorFloat(displacement); scale.z = 0f; scale.x = this.trans.localScale.x; float distance = Vector3.Distance(position2, position1); scale.y = distance / heightMultiplier; this.trans.localScale = scale; Vector3 newpos = (position1 + position2) / 2f; newpos.z = 0; this.trans.position = newpos; float newangle = (angle - 90f + 720f) % 360f; this.trans.localEulerAngles = new Vector3(0f, 0f, newangle); //configure the forces float prev = velocity.velocity.magnitude; float speed = distance * 5f; velocity.velocity = new Vector3(Mathf.Cos(Mathf.Deg2Rad * angle), Mathf.Sin(Mathf.Deg2Rad * angle)).normalized *speed; if (!(Mathf.Abs(prev - velocity.velocity.magnitude) < Util.EPSILON)) { propertiesAreaScript.CoerceAdjustValues(6); } if (!(Mathf.Abs(prevangle - angle) < Util.EPSILON)) { propertiesAreaScript.CoerceAdjustValues(7); prevangle = angle; } }
// Update is called once per frame void Update() { if (!(Mathf.Abs(trans.position.z) < Util.EPSILON)) { trans.position = new Vector3(trans.position.x, trans.position.y, 0); } if (Input.GetMouseButtonDown(0)) { if (Input.touchCount == 1) { Vector3 screenpos = Input.mousePosition; screenpos.z = 0; touchStart = Camera.main.ScreenToWorldPoint(screenpos); touchStart.z = 0; if (Util.ColliderContains(col, touchStart, 0) && Util.OnCanvas(screenpos)) { onSprite = true; PropertiesEditable.focusedObject = this.gameObject; touchStart.z = 0; Util.objectDragged = true; Util.draggedObject = this.gameObject; ReplayControl.focusedObject = this.gameObject; } } } if (Input.touchCount == 1 && onSprite && PropertiesEditable.focusedObject == this.gameObject) { if (lastTouchCnt == 2) { touchStart = Camera.main.ScreenToWorldPoint(Input.mousePosition); } if (Input.GetMouseButton(0)) { Vector3 touch = Camera.main.ScreenToWorldPoint(Input.mousePosition); touch.z = 0; trans.position += touch - touchStart; touchStart = touch; } if (Input.GetMouseButtonUp(0)) { onSprite = false; Util.objectDragged = false; Util.draggedObject = null; } lastTouchCnt = 1; } else if (Input.touchCount == 2 && onSprite && PropertiesEditable.focusedObject == this.gameObject) { Touch touchZero = Input.GetTouch(0); Touch touchOne = Input.GetTouch(1); Vector3 pos1 = Camera.main.ScreenToWorldPoint(touchZero.position); Vector3 pos2 = Camera.main.ScreenToWorldPoint(touchOne.position); Vector3 pos1prev = Camera.main.ScreenToWorldPoint(touchZero.position - touchZero.deltaPosition); Vector3 pos2prev = Camera.main.ScreenToWorldPoint(touchOne.position - touchOne.deltaPosition); float angle = Util.GetAngleFromVectorFloat(pos2 - pos1); float prevangle = Util.GetAngleFromVectorFloat(pos2prev - pos1prev); float angledelta = angle - prevangle; transform.eulerAngles += new Vector3(0, 0, angledelta); if (!(Mathf.Abs(angleprev - transform.eulerAngles.z) < Util.EPSILON)) { propertiesAreaScript.CoerceAdjustValues(7); angleprev = transform.eulerAngles.z; } Vector3 averagePosPrev = (pos2prev + pos1prev) / 2f; averagePosPrev.z = 0; Vector3 averagePos = (pos1 + pos2) / 2f; averagePos.z = 0; transform.position += (averagePos - averagePosPrev); lastTouchCnt = 2; } }