//画网格线 void DrawGridLine(string name, Vector3 posStart, Vector3 posEnd) { // Make Vector2 array; in this case we just use 2 elements... List <Vector3> linePoints = new List <Vector3>(); linePoints.Add(posStart); linePoints.Add(posEnd); // Make a VectorLine object using the above points and the default material, with a width of 2 pixels VectorLine line = new VectorLine(name, linePoints, lineWidth); line.Draw3D(); GameObject objLine = line.GetObj(); objLine.transform.parent = this.gameObject.transform; objLine.transform.localPosition = Vector3.zero; // Renderer rd = objLine.GetComponent<Renderer>(); // if (rd != null) // { // Debug.Log("line bound size= " + rd.bounds.size); // } Rigidbody2D bd = objLine.AddComponent <Rigidbody2D>(); bd.collisionDetectionMode = CollisionDetectionMode2D.Continuous; bd.bodyType = RigidbodyType2D.Static; listLine.Add(line); // bd.useGravity = false; }
//画网格线 void DrawGridLine(string name, Vector3 posStart, Vector3 posEnd) { // Make Vector2 array; in this case we just use 2 elements... List <Vector3> linePoints = new List <Vector3>(); linePoints.Add(posStart); linePoints.Add(posEnd); // Make a VectorLine object using the above points and the default material, with a width of 2 pixels VectorLine line = new VectorLine(name, linePoints, lineWidth); line.Draw3D(); GameObject objLine = line.GetObj(); objLine.transform.parent = this.gameObject.transform; objLine.transform.localPosition = Vector3.zero; }
//实际显示大小 public float GetWorldLineWidth() { float ret = Common.ScreenToWorldWidth(mainCam, lineWidth); return(ret); if (listLine.Count != 0) { VectorLine line = listLine[0] as VectorLine; GameObject obj = line.GetObj(); Renderer rd = obj.GetComponent <Renderer>(); if (rd != null) { ret = Mathf.Min(rd.bounds.size.x, rd.bounds.size.y); Debug.Log("line real = " + ret + " w=" + Common.ScreenToWorldWidth(mainCam, lineWidth) + " h=" + Common.ScreenToWorldHeight(mainCam, lineWidth)); } } return(ret); }