private IEnumerator DragObject() { while (Input.GetMouseButton(0)) { // Position on the near clipping plane of the camera in world space Vector3 newMousePos = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, 0)); // Position relative to the eye-point of the camera newMousePos -= Camera.main.transform.position; if (Input.GetKey(KeyCode.LeftShift) && m_object.layer != LayerMask.NameToLayer("Path")) { float cellWidth = m_grid.transform.GetComponent <SpriteRenderer>().bounds.size.x / 20.2f; float cellHeight = m_grid.transform.GetComponent <SpriteRenderer>().bounds.size.y / 20.2f; float newX = Mathf.Round((Mathf.Abs(m_grid.GetComponent <SpriteRenderer>().bounds.min.x) + newMousePos.x) / cellWidth); newX = m_grid.GetComponent <SpriteRenderer>().bounds.min.x + 0.05f + (newX * cellWidth); float newY = Mathf.Round((Mathf.Abs(m_grid.GetComponent <SpriteRenderer>().bounds.min.y) + newMousePos.y) / cellHeight); newY = m_grid.GetComponent <SpriteRenderer>().bounds.min.y + (newY * cellHeight); m_object.transform.position = new Vector3(newX, newY, 0); m_curMousePos = new Vector2(newX, newY); } else { if (m_object.name == "Arrow Collider") { m_object = LineScript.GetCurrentLine().GetComponentsInChildren <SphereCollider>()[0].gameObject; } else if (m_object.name == "Line") { m_object = LineScript.GetCurrentLine(); } float diffX = m_lastMouse.x - m_curMousePos.x; float diffY = m_lastMouse.y - m_curMousePos.y; Debug.Log(diffX + "\n" + diffY); //Vector3 oldPos = m_object.transform.position; //m_object.transform.position = new Vector3(m_curMousePos.x, m_curMousePos.y, 0); m_object.transform.SetPositionAndRotation(new Vector3(m_object.transform.position.x - diffX, m_object.transform.position.y - diffY, m_object.transform.position.z), Quaternion.identity); //Transform g = GameObject.Find("Guard L").transform; //float xAdded = oldPos.x - m_object.transform.position.x; //g.SetPositionAndRotation(new Vector3(g.position.x - xAdded, g.position.y - (oldPos.y - m_object.transform.position.y)), Quaternion.identity); m_curMousePos = newMousePos; if (m_object.layer == LayerMask.NameToLayer("Path")) { LineScript.ModifyLine(m_object); } else { LineScript.SetCurrentLine(null); } } yield return(0); } m_object = null; }
static public void Redo(GameObject _gO) { m_undoPos++; UndoItem uItem = m_undoObjects[m_undoPos - 1]; _gO = uItem.GetObj(); if (_gO.GetComponent <Rigidbody>() == null) { if (_gO.activeSelf) { _gO.SetActive(false); } else { _gO.SetActive(true); } return; } Vector2 temp = _gO.transform.position; _gO.transform.SetPositionAndRotation(new Vector3(uItem.GetPos().x, uItem.GetPos().y, 0), Quaternion.identity); uItem.SetPos(temp); if (_gO.layer == LayerMask.NameToLayer("Path")) { LineScript.ModifyLine(_gO); } }