void MakeGrid2() { List <Vector2> points2 = new List <Vector2>(); Rect realRect = DrawHelper.GetRealRect(camera2d); float xMin = realRect.xMin; float xMax = realRect.xMax; List <float> widths = new List <float>(); int startX = (int)xMin % gridUnit == 0? (int)xMin : ((int)xMin / gridUnit) * gridUnit; for (float x = startX; x <= xMax; x = x + gridUnit) { float pixelX = (x - xMin) / DrawHelper.Scale; points2.Add(new Vector2(pixelX, 0)); points2.Add(new Vector2(pixelX, camera2d.pixelHeight - 1)); if (Mathf.Approximately(x, 0)) { widths.Add(4.0f); } else { widths.Add(1.0f); } } float yMin = realRect.yMin; float yMax = realRect.yMax; int startY = (int)yMin % gridUnit == 0? (int)yMin : ((int)yMin / gridUnit) * gridUnit; for (float y = startY; y <= yMax; y = y + gridUnit) { float pixelY = (y - yMin) / DrawHelper.Scale; points2.Add(new Vector2(0, pixelY)); points2.Add(new Vector2(camera2d.pixelWidth - 1, pixelY)); if (Mathf.Approximately(y, 0)) { widths.Add(4.0f); } else { widths.Add(1.0f); } } gridLine.Resize(points2.Count); for (int i = 0; i < points2.Count; i++) { gridLine.points2[i] = points2[i]; } gridLine.SetWidths(widths); gridLine.SetColor(Color.gray); gridLine.Draw(); }
public void ResizeLine(VectorLine vl, Vector2 p1, Vector2 p2) { Vector3[] v = new Vector3[2]; v [0] = p1; v [1] = p2; vl.Resize(v); }
public void CreateLine(Color lineColor, int lineSize) { if (myLine != null) { return; } this.lineColor = lineColor; this.lineSize = lineSize; if (LurePosition == null) { LurePosition = LureController.Instance.gameObject.transform; } points = new Vector3[2] { RodController.Instance.rodTip.position, LurePosition.position }; myLine = VectorLine.SetLine3D(lineColor, points); if (lineMat == null) { lineMat = Resources.Load("lineMat") as Material; } myLine.joins = Joins.Fill; myLine.material = lineMat; if (lineMat == null) { Debug.LogError("lineMaterial ==null"); } SetLineWidth(lineSize, lineColor); myLine.Resize(N); this.UpdateEndPoints(); isCreated = true; }
/// <summary> /// 绘制批注线 /// </summary> /// <param name="_vStart"></param> /// <param name="_vEnd"></param> private void DrawLine(Vector2 _vStart, Vector2 _vEnd) { points[0] = _vStart; points[1] = _vEnd; m_curline.Resize(points); m_curline.Draw(); }
public void Update() { //NOTE: needs optimization - check for change if (_Model.Path != null && _Model.Path.Count > 0) { List <Vector2> pathPoints = ShanghaiUtils.GetScreenCoordsFromCellKeys(_Model.Path, _Model.CellPositions); if (pathPoints.Count >= 2) { _ColourPath.Resize(pathPoints.ToArray()); _OutlinePath.Resize(pathPoints.ToArray()); _ColourPathMaterial.SetColor("_TintColor", ShanghaiUtils.GetColour(_Model.PathColour)); _ColourPath.active = true; _ColourPath.Draw(); _OutlinePath.active = true; _OutlinePath.Draw(); } } else { _ColourPath.active = false; _ColourPath.Draw(); _OutlinePath.active = false; _OutlinePath.Draw(); } }
void AddPoint() { // Don't do anything if adding a new point would exceed the max number of vertices per mesh if (line.points2.Count + controlLine.points2.Count + segments + 4 > 16383) { return; } // Make the first anchor and control points of the new curve be the same as the second anchor/control points of the previous curve controlLine.points2.Add(controlLine.points2[pointIndex - 2]); controlLine.points2.Add(controlLine.points2[pointIndex - 1]); // Make the second anchor/control points of the new curve be offset a little ways from the first var offset = (controlLine.points2[pointIndex - 2] - controlLine.points2[pointIndex - 4]) * .25f; controlLine.points2.Add(controlLine.points2[pointIndex - 2] + offset); controlLine.points2.Add(controlLine.points2[pointIndex - 1] + offset); // If that made the new anchor point go off the screen, offset them the opposite way if (controlLine.points2[pointIndex + 2].x > Screen.width || controlLine.points2[pointIndex + 2].y > Screen.height || controlLine.points2[pointIndex + 2].x < 0 || controlLine.points2[pointIndex + 2].y < 0) { controlLine.points2[pointIndex + 2] = controlLine.points2[pointIndex - 2] - offset; controlLine.points2[pointIndex + 3] = controlLine.points2[pointIndex - 1] - offset; } // For the next control point, make the initial position offset from the anchor point the opposite way as the second control point in the curve var controlPointPos = controlLine.points2[pointIndex - 1] + (controlLine.points2[pointIndex] - controlLine.points2[pointIndex - 1]) * 2; pointIndex++; // Skip the next anchor point, since we want the second anchor point of one curve and the first anchor point of the next curve // to move together (this is handled in UpdateLine) controlLine.points2[pointIndex] = controlPointPos; // Make another control point var controlObject = Instantiate(controlPoint, cam.ScreenToViewportPoint(controlPointPos), Quaternion.identity) as GameObject; controlObject.GetComponent <CurvePointControl>().objectNumber = pointIndex++; // For the last anchor object that was made, make a reference to this control point so they can move together anchorObject.GetComponent <CurvePointControl>().controlObject2 = controlObject; // Then make another anchor/control point group AddControlObjects(); // Update the control lines controlLine.Draw(); // Update the curve with the new points line.Resize((segments + 1) * ++numberOfCurves); line.MakeCurve(controlLine.points2[pointIndex - 4], controlLine.points2[pointIndex - 3], controlLine.points2[pointIndex - 2], controlLine.points2[pointIndex - 1], segments, (segments + 1) * (numberOfCurves - 1)); line.Draw(); }
// Update is called once per frame void Update() { Vector3[] v = new Vector3[2]; v [0] = this.transform.position + (Vector3)p1; v [1] = this.transform.position + (Vector3)p2; vl.Resize(v); }
// manually updated by ActiveMissionsViewController public void Update() { // Stop drawing once the ID reaches the last point if (_ActMission.CurrentCellID < _ColourPathPoints.Count - 1) { _TrackPath.Resize(GetTrackPoints()); } _TrackPath.Draw(); }
void SetupOutLine(VectorLine outline, List <Vector2> list) { int startIndex = outline.points3.Count; outline.Resize(startIndex + (list.Count - 1) * 2); for (int i = 0, j = startIndex; i < list.Count - 1; i++, j = j + 2) { outline.points3[j] = DrawHelper.Vector2To3(list[i]); outline.points3[j + 1] = DrawHelper.Vector2To3(list[i + 1]); } }
void LineSetup(bool resize) { if (resize) { lineColors = null; line.Resize(numberOfPoints); } for (int i = 0; i < line.points3.Count; i++) { line.points3[i] = new Vector3(Random.Range(-5.0f, 5.0f), Random.Range(-5.0f, 5.0f), Random.Range(-5.0f, 5.0f)); } SetLineColors(); }
void CreateLine(Color lineColor, int lineSize) { points = new Vector3[2] { RodControllerTest.Instance.rodTip.position, LurePosition.position }; myLine = VectorLine.SetLine3D(lineColor, points); myLine.joins = Joins.Fill; myLine.material = lineMat; SetLineWidth(lineSize, lineColor); /*VectorLine.SetLineParameters (lineColor, null, lineSize, 1, * 1, LineType.Continuous, Joins.Fill); * myLine.Resize(N);*/ myLine.Resize(N); if (myLine == null) { Debug.Log("CreateLine null"); } this.UpdateEndPoints(); }
void MakeGrid() { int numberOfGridPoints = ((Screen.width / gridPixels + 1) + (Screen.height / gridPixels + 1)) * 2; gridLine.Resize(numberOfGridPoints); int index = 0; for (int x = 0; x < Screen.width; x += gridPixels) { gridLine.points2[index++] = new Vector2(x, 0); gridLine.points2[index++] = new Vector2(x, Screen.height - 1); } for (int y = 0; y < Screen.height; y += gridPixels) { gridLine.points2[index++] = new Vector2(0, y); gridLine.points2[index++] = new Vector2(Screen.width - 1, y); } gridLine.Draw(); }
void MakeGrid() { //int numberOfGridPoints = ((Screen.width / gridPixels + 1) + (Screen.height / gridPixels + 1)) * 2; int numberOfGridPoints = (1601 + 1601) * 2; gridLine.Resize(numberOfGridPoints); //gridLine.drawTransform = tf; int w = -(Screen.width / 2); int index = 0; /* * for (int x = 0; x < Screen.width; x += gridPixels) * { * gridLine.points2[index++] = new Vector2(x, 0); * gridLine.points2[index++] = new Vector2(x, Screen.height - 1); * } */ for (int x = -800; x < 801; x += gridPixels) { gridLine.points2[index++] = new Vector2(x, -800f); gridLine.points2[index++] = new Vector2(x, 801f); } int h = -(Screen.height / 2); /*for (int y = 0; y < Screen.height; y += gridPixels) * { * gridLine.points2[index++] = new Vector2(0, y); * gridLine.points2[index++] = new Vector2(Screen.width - 1, y); * }*/ for (int y = -800; y < 801; y += gridPixels) { gridLine.points2[index++] = new Vector2(-800f, y); gridLine.points2[index++] = new Vector2(801f, y); } gridLine.matrix = mat; gridLine.Draw(); }
void Update() { // Don't allow clicking in the left-most 50 pixels (where the slider is), or if the spheres are currently fading if (Input.GetMouseButtonDown(0) && Input.mousePosition.x > 50 && !fading) { // If neither shift key is down, reset selection if (!(Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift)) && selectIndex > 0) { ResetSelection(true); } // See if we clicked on an object (the room is set to the IgnoreRaycast layer, so we can't select it) if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit)) { spheres[selectIndex] = hit.collider.gameObject; spheres[selectIndex].layer = ignoreLayer; // So it can't be clicked again (unless reset) spheres[selectIndex].GetComponent <Renderer>().material.EnableKeyword("_EMISSION"); // So changing emission color will work at runtime selectIndex++; line.Resize(selectIndex * 10); } } // Draw a square for each selected object for (int i = 0; i < selectIndex; i++) { // Make the size of the square larger or smaller depending on the object's Z distance from the camera var squareSize = (Screen.height * selectionSize) / Camera.main.transform.InverseTransformPoint(spheres[i].transform.position).z; var screenPoint = Camera.main.WorldToScreenPoint(spheres[i].transform.position); var thisSquare = new Rect(screenPoint.x - squareSize, screenPoint.y - squareSize, squareSize * 2, squareSize * 2); line.MakeRect(thisSquare, i * 10); // Make a line connecting from the midpoint of the square's left edge to the energyLevel slider position line.points2[i * 10 + 8] = new Vector2(thisSquare.x - lineWidth * .25f, thisSquare.y + squareSize); line.points2[i * 10 + 9] = new Vector2(35, Mathf.Lerp(65, Screen.height - 25, energyLevel)); // Change color of selected objects spheres[i].GetComponent <Renderer>().material.SetColor("_EmissionColor", new Color(energyLevel, energyLevel, energyLevel)); } }
void SetupOutLine(VectorLine outline, List<Vector2> list) { int startIndex = outline.points3.Count; outline.Resize(startIndex + (list.Count-1)*2); for(int i = 0, j=startIndex; i < list.Count-1; i++, j=j+2){ outline.points3[j] = DrawHelper.Vector2To3(list[i]); outline.points3[j+1] = DrawHelper.Vector2To3(list[i+1]); } }
public static void MakeTextInLine(VectorLine line, string text, Vector3 startPos, float size, float charSpacing, float lineSpacing, bool uppercaseOnly) { if (line.continuousLine) { LogError ("Vector: MakeTextInLine can only be used with a discrete line"); return; } int pointsLength = GetPointsLength (line); int charPointsLength = 0; // Get total number of points needed for all characters in the string for (int i = 0; i < text.Length; i++) { int charNum = System.Convert.ToInt32(text[i]); if (charNum == 32 || charNum == 10) continue; if (VectorChar.data[charNum] == null) { LogError ("Vector.MakeTextInLine: no data found for character '" + text[i] + "'"); return; } if (charNum < 0 || charNum > VectorChar.numberOfCharacters) { LogError ("Vector.MakeTextInLine: Character '" + text[i] + "' is not valid"); return; } if (uppercaseOnly && charNum >= 97 && charNum <= 122) { charNum -= 32; } charPointsLength += VectorChar.data[charNum].Length; } if (charPointsLength > pointsLength) { line.Resize (charPointsLength); } else if (charPointsLength < pointsLength) { ZeroPointsInLine (line, charPointsLength); } float charPos = 0.0f; float linePos = 0.0f; int idx = 0; var scaleVector = new Vector2(size, size); var useVector2 = line.points3 == null; for (int i = 0; i < text.Length; i++) { int charNum = System.Convert.ToInt32(text[i]); // Newline if (charNum == 10) { linePos -= lineSpacing; charPos = 0.0f; } // Space else if (charNum == 32) { charPos += charSpacing; } // Character else { if (uppercaseOnly && charNum >= 97 && charNum <= 122) { charNum -= 32; } int end = VectorChar.data[charNum].Length; if (useVector2) { for (int j = 0; j < end; j++) { line.points2[idx++] = Vector2.Scale(VectorChar.data[charNum][j] + new Vector2(charPos, linePos), scaleVector) + (Vector2)startPos; } } else { for (int j = 0; j < end; j++) { line.points3[idx++] = Vector3.Scale((Vector3)VectorChar.data[charNum][j] + new Vector3(charPos, linePos, 0.0f), scaleVector) + startPos; } } charPos += charSpacing; } } }
public static void MakeTextInLine (VectorLine line, string text, Vector2 startPos, float size, float charSpacing, float lineSpacing, bool uppercaseOnly) { if (line.continuousLine) { LogError ("Vector: MakeTextInLine can only be used with a discrete line"); return; } Vector2 scaleVector = new Vector2(size, size); int idx = 0; int pointsLength = 0; while (true) { pointsLength = GetPointsLength (line); idx = 0; float charPos = 0.0f; float linePos = 0.0f; int charNum = 0; bool addChar = false; Vector2[] useArray = VectorChar.data[0]; for (int i = 0; i < text.Length; i++) { charNum = System.Convert.ToInt32(text[i]); addChar = false; if (charNum < 0 || charNum > VectorChar.numberOfCharacters) { LogError ("Vector.MakeTextInLine: Character " + charNum + " out of range"); return; } // Newline else if (charNum == 10) { linePos -= lineSpacing; charPos = 0.0f; } // Space else if (charNum == 32) { charPos += charSpacing; } // Character else { if (uppercaseOnly && charNum >= 97 && charNum <= 122) { charNum -= 32; } useArray = VectorChar.data[charNum]; addChar = useArray != null; } if (addChar) { // See if it would exceed array length...if so, keep going so we can add up the total needed if (idx + useArray.Length > pointsLength) { idx += useArray.Length; } else { if (line.points2 != null) { for (int j = 0; j < useArray.Length; j++) { line.points2[idx] = useArray[j] + new Vector2(charPos, linePos); line.points2[idx] = Vector2.Scale(line.points2[idx], scaleVector); line.points2[idx++] += startPos; } } else { for (int j = 0; j < useArray.Length; j++) { line.points3[idx] = (Vector3)useArray[j] + new Vector3(charPos, linePos, 0.0f); line.points3[idx] = Vector2.Scale(line.points3[idx], scaleVector); line.points3[idx++] += (Vector3)startPos; } } } charPos += charSpacing; } } if (idx > pointsLength) { System.Array.Resize(ref line.points3, idx); line.Resize(idx); } else { break; } } // Zero out any unused space in the array, in case there was any previous data if (idx < pointsLength) { ZeroPointsInLine (line, idx); } }
public static void MakeWireframeInLine(VectorLine line, Mesh mesh) { if (line.continuous) { LogError ("Vector: MakeWireframeInLine only works with a discrete line"); return; } if (line.points2 != null) { LogError ("Vector: MakeWireframeInLine only works with Vector3 points"); return; } if (mesh == null) { LogError ("Vector: MakeWireframeInLine can't use a null mesh"); return; } var meshTris = mesh.triangles; var meshVertices = mesh.vertices; var pairs = new Dictionary<Vector3Pair, bool>(); var linePoints = new List<Vector3>(); for (int i = 0; i < meshTris.Length; i += 3) { CheckPairPoints (pairs, meshVertices[meshTris[i]], meshVertices[meshTris[i+1]], linePoints); CheckPairPoints (pairs, meshVertices[meshTris[i+1]], meshVertices[meshTris[i+2]], linePoints); CheckPairPoints (pairs, meshVertices[meshTris[i+2]], meshVertices[meshTris[i]], linePoints); } if (linePoints.Count > line.points3.Length) { System.Array.Resize (ref line.points3, linePoints.Count); line.Resize (linePoints.Count); } else if (linePoints.Count < line.points3.Length) { ZeroPointsInLine (line, linePoints.Count); } System.Array.Copy (linePoints.ToArray(), line.points3, linePoints.Count); }
void Update() { segmentFill.Clear(); segmentOutline.Resize(0); var savedWall = Home.Get().Walls; found.Clear(); for (int i = 0; i < savedWall.Count; i++) { Wall2D start = savedWall[i]; if (found.Contains(start)) { continue; } toDraw.Clear(); toDraw.Add(start); AddWallsJoined(toDraw, start); found.AddRange(toDraw); // if(wall.WallAtEnd != null && wall.WallAtEnd == start){ // } // else{ // } segmentFill.SetupSegment(toDraw, wallThick, segmentOutline, mParallel); } segmentFill.Draw(); segmentOutline.SetColor(Color.black); segmentOutline.Draw3D(); if (mState != State2D.Draw) { return; } Rect rect = camera2d.pixelRect; Vector2 current = Input.mousePosition; if (!rect.Contains(current)) { return; } if (Input.GetMouseButtonDown(0)) { if (drawBreak) { drawBreak = false; wall[0] = wall[1] = DrawHelper.PixelToReal(camera2d, current); walls.Clear(); drawStartIndex = walls.Count; } else { if (isContinue) { Wall2D newWall = new Wall2D(wall[0], wall[1]); //////////////// if (walls.Count >= 1) { newWall.WallAtStart = walls[walls.Count - 1]; Vector2 target = walls[0].StartPos; Vector2 delta = SnapPoint(newWall.EndPos, target); newWall.EndPos += delta; if (delta != Vector2.zero) { newWall.WallAtEnd = walls[0]; drawBreak = true; } } Home.Get().AddWall(newWall); /////////////// walls.Add(newWall); wall[0] = wall[1]; } else { wall[1] = DrawHelper.PixelToReal(camera2d, current); Wall2D newWall = new Wall2D(wall[0], wall[1]); if (walls.Count >= 1) { newWall.WallAtStart = walls[walls.Count - 1]; } Home.Get().AddWall(newWall); walls.Add(newWall); wall[0] = wall[1]; } } } if (Input.GetMouseButtonDown(1)) { drawBreak = true; // Vector3[] room = DiscreteToContinue(walls, drawStartIndex); // if(room != null){ // DrawWall(room); // } } if (Input.GetMouseButton(0) || Input.GetMouseButton(1)) { Vector2 delta = current - lastMousePos; // if(mState == State2D.Idle){ // OnDrag(delta); // } // if(mState == State2D.Draw){ // wall[1] = PixelToReal(camera2d, current); // walls.Add(wall); // } lastMousePos = current; } //stop draw line; if (Input.GetMouseButtonDown(2)) { drawBreak = true; } if (!drawBreak) { wall[1] = DrawHelper.PixelToReal(camera2d, current); } if (!isContinue) { var wallSaved = Home.Get().Walls; drawLine.Resize(wallSaved.Count * 2 + 2); widths.Clear(); int i = 0; for (; i < wallSaved.Count; i++) { Wall2D line = wallSaved[i]; drawLine.points3[i * 2] = DrawHelper.Vector2To3(line.StartPos); drawLine.points3[i * 2 + 1] = DrawHelper.Vector2To3(line.EndPos); widths.Add(wallThick * DrawHelper.unitPixels); } //walls[walls.Count-1][1] = wall[1]; drawLine.points3[i * 2] = DrawHelper.Vector2To3(wall[0]); drawLine.points3[i * 2 + 1] = DrawHelper.Vector2To3(wall[1]); //drawLine.SetWidths(widths); drawLine.color = Color.black; drawLine.Draw3D(); } else { drawLine.Resize(walls.Count + 2); widths.Clear(); int i = 0; for (; i < walls.Count; i++) { Wall2D line = walls[i]; drawLine.points3[i] = DrawHelper.Vector2To3(line.StartPos); widths.Add(wallThick * DrawHelper.unitPixels); } if (i == 0) { drawLine.points3[i] = DrawHelper.Vector2To3(wall[0]); } else { drawLine.points3[i] = DrawHelper.Vector2To3(walls[i - 1].EndPos); } drawLine.points3[i + 1] = DrawHelper.Vector2To3(wall[1]); //drawLine.SetWidths(widths); drawLine.color = Color.black; drawLine.Draw3D(); } //draw ruler; List <Vector2> ruler = mParallel.GetRuler(wall, 0.1f, false); rulerLine.Resize(2); rulerLine.points3[0] = DrawHelper.Vector2To3(ruler[0]); rulerLine.points3[1] = DrawHelper.Vector2To3(ruler[1]); rulerLine.SetColor(Color.blue); rulerLine.Draw3D(); }