void DrawLineToMouse() { lineTarget = new Vector2(Input.mousePosition.x, Input.mousePosition.y) - (Vector2)gameObject.transform.position; lineRenderer.Points[endIndex] = lineTarget; var xDist = lineRenderer.Points[endIndex].x - lineRenderer.Points[startIndex].x; var tempHandleOffset = xDist / 3; lineRenderer.Points[startHandle] = lineRenderer.Points[startIndex] + new Vector2(tempHandleOffset, 0); lineRenderer.Points[endHandle] = lineRenderer.Points[endIndex] - new Vector2(tempHandleOffset, 0); lineRenderer.SetAllDirty(); }
public void Update() { if (pathActive) { float canvasScale = Screen.width / RecipeTreeMaster.myCanvas.GetComponent <CanvasScaler>().referenceResolution.x; //canvasScale = 1; //canvasScale = 1f / canvasScale; float localScale = 1 / myRend.transform.lossyScale.x; //print(canvasScale); Vector3 startWorldPoint = /*RecipeTreeMaster.mainCam.ScreenToWorldPoint*/ (lineConnectionPoint.position - myRend.transform.position) * localScale /*+ Vector3.forward*5*/; Vector3 endWorldPoint = /*RecipeTreeMaster.mainCam.ScreenToWorldPoint*/ (myConnection.lineConnectionPoint.position - myRend.transform.position) * localScale /*+ Vector3.forward*5*/; float pushDistance = Mathf.Abs(startWorldPoint.x - endWorldPoint.x) / 2f; Vector3[] knots = new[] { startWorldPoint, startWorldPoint + (isInput ? Vector3.left : Vector3.right) * pushDistance, endWorldPoint + (!isInput ? Vector3.left : Vector3.right) * pushDistance, endWorldPoint }; /*Debug.DrawLine(lineConnectionPoint.position, lineConnectionPoint.position+Vector3.up); * Debug.DrawLine(lineConnectionPoint.position + (isInput? Vector3.left : Vector3.right), lineConnectionPoint.position + (isInput? Vector3.left : Vector3.right)+Vector3.up); * Debug.DrawLine(myConnection.lineConnectionPoint.position + (isInput? Vector3.left : Vector3.right), myConnection.lineConnectionPoint.position + (isInput? Vector3.left : Vector3.right)+Vector3.up); * Debug.DrawLine(myConnection.lineConnectionPoint.position, myConnection.lineConnectionPoint.position+Vector3.up);*/ path.SetControlVerts(knots); for (int i = 0; i <= resolution; i++) { Vector3 pos = path.GetPoint(((float)i) / (float)resolution); myRend.m_points[i] = new Vector2(pos.x, pos.y); } myRend.SetAllDirty(); } }
// 必須 public void AddPoint(float time, float value) { value = Mathf.Clamp(value, grpMin, grpMax); points.Add(new Vector2(grpStep * time, (value - grpMin) * rect.height / grpRange)); if (points.Count >= grpMaxPoint) { points.RemoveAt(0); } Vector2 offset = new Vector2(marginLeft, marginBottom); Vector2[] PointArr = new Vector2[grpAxes.Length / 2 + points.Count * 2]; int n = 0; for (int i = 0; i < grpAxes.Length; i++) { PointArr[n++] = new Vector2(grpAxes[i].x * rect.width, grpAxes[i].y * rect.height) + offset; } float last_x = 0; for (int i = 1; i < points.Count; i++) { PointArr[n++] = new Vector2(last_x, points[i - 1].y) + offset; PointArr[n++] = new Vector2(last_x + points[i].x, points[i].y) + offset; last_x += points[i].x; } lineRenderer.Points = PointArr; lineRenderer.SetAllDirty(); }
private int DrawLine(UILineRenderer lineRenderer, LineDataSet dataSet, int dataSetIndex, int currentIndicatorPosition) { List <LineEntry> entries = dataSet.GetSortedEntries(); Color32 lineColor = dataSet.LineColor; lineRenderer.lineThickness = dataSet.LineThickness; lineRenderer.color = lineColor; lineRenderer.m_points = dataSet.UseBezier ? bezierPoints[dataSetIndex] : entriesPoints[dataSetIndex]; lineRenderer.BezierSegmentsPerCurve = BEZIER_LINE_SEGMENTS; lineRenderer.BezierMode = dataSet.UseBezier ? UILineRenderer.BezierType.Basic : UILineRenderer.BezierType.None; lineRenderer.SetAllDirty(); if (Config.ShowValueIndicators) { return(UpdateCirclesAtPosition(entriesPoints[dataSetIndex], entries.ToArray(), lineColor, currentIndicatorPosition, dataSetIndex)); } else { return(0); } }
public void Init() { wasShot = false; wasPressed = false; rb = GetComponent <Rigidbody2D>(); rb.bodyType = RigidbodyType2D.Kinematic; rb.gravityScale = 0f; startPosition = transform.TransformPoint(Vector3.zero); transform.position = startPosition; Rect parentRect = transform.parent.GetComponent <RectTransform>().rect; aimPosTransform = transform.parent.Find("AimPoint").transform; line = transform.parent.GetComponentInChildren <UILineRenderer>(); points.Add(new Vector2(parentRect.xMin, parentRect.yMax)); points.Add(transform.localPosition); points.Add(new Vector2(parentRect.xMax, parentRect.yMax)); line.Points = points.ToArray(); line.SetAllDirty(); shotArea = transform.parent.Find("ShotArea").GetComponent <CircleCollider2D>(); myCollider = GetComponent <CircleCollider2D>(); myScore = 0; myRect = GetComponent <RectTransform>(); }
public void Deform(float totalLength, float maxDeform) { if (lineRenderer.Points.Length <= MaxCurvePoints) { elapsedAnimationTime += Time.deltaTime; if (elapsedAnimationTime > AddControlPointTime) { setupNewCurvePoints(lineRenderer.Points.Length + 1); elapsedAnimationTime = 0; } } // check if current line at max // // if true add point // grow line for missing percentage t += Time.deltaTime * AnimationSpeed; for (int i = deformStartIndex; i <= lineRenderer.Points.Length - deformStartIndex; i++) { lineRenderer.Points[i].y = maxDeformDiff[i].y + oscillate(t, i * 0.1f * AnimationSpeed, maxDeformY); lineRenderer.Points[i].x = maxDeformDiff[i].x + oscillate(t, (deformEndIndex - i + 1) * 0.1f * AnimationSpeed, maxDeformX); } //Update curve lineRenderer.SetAllDirty(); }
private void LateUpdate() { if (showGUIInfo) { Vector2 zeroPosition = Camera.main.WorldToScreenPoint(transform.position); Vector2 diff = throwForce * forceFactor * (currentPosition - initialPosition).normalized; float v0x = diff.x; float v0y = diff.y; float fTime = 0f; float increment = 0.1f; Vector2[] points = new Vector2[maxNumberOfPoints]; for (int i = 0; i < maxNumberOfPoints; i++) { Vector2 r = new Vector2(v0x * fTime + zeroPosition.x, 0.5f * Physics2D.gravity.y * fTime * fTime + v0y * fTime + zeroPosition.y); points[i] = r; fTime += increment; if (Physics2D.OverlapPoint(Camera.main.ScreenToWorldPoint(r), obstacleMask)) { Array.Resize(ref points, i); break; } } lineRenderer.Points = points; lineRenderer.SetAllDirty(); } }
public void UpdateLine() { if (line) { line.Points = points.ToArray(); line.SetAllDirty(); } }
public void UpdateLines() { lineRenderer.Points = new Vector2[fruits.Count]; for (int i = 0; i < fruits.Count; i++) { lineRenderer.Points[i] = transform.InverseTransformPoint(fruits[i].transform.position); } lineRenderer.SetAllDirty(); }
protected void Render(float[] data) { UILineRenderer lineRenderer = gameObject.GetComponent <UILineRenderer>(); Vector2[] posisions = Data2Positions(AveragingData(data, (int)width)); lineRenderer.SetPoints(posisions); lineRenderer.SetAllDirty(); //なぜかこれで再描画できる }
//met à jour l'affichage de la courbe private void UpdateLineRender() { if (rend == null) { return; } for (int i = 0; i < rend.Points.Length; i++) { rend.Points[i].y = CurveToScreenY(CurrentCurve.Get(rend.Points[i].x * TimeSpan)); } rend.SetAllDirty(); }
void Update() { Vector2 screenPos = cam.WorldToScreenPoint(target.position); int marginX = Screen.width / 2 - 200; int marginY = Screen.height / 2 - 100; Vector2 center = new Vector2(Screen.width / 2, Screen.height / 2); line.m_points[0] = screenPos - center; line.m_points[1] = Vec2Clamp(line.m_points[0] + line.m_points[0].normalized * lineLength, -marginX, marginX, -marginY, marginY); line.m_points[2] = line.m_points[1] + new Vector2(line.m_points[0].x > 0 ? 100 : -100, 0); line.SetAllDirty(); text.rectTransform.position = line.m_points[2] + new Vector2(line.m_points[0].x > 0 ? text.preferredWidth / 2 + 10 : -text.preferredWidth / 2 - 10, 0) + center; }
public void ShowLine(Direction direction, float value) { var size = ((RectTransform)VerticalRenderer.transform.parent).rect.size; switch (direction) { case Direction.Vertical: VerticalRenderer.enabled = true; VerticalRenderer.Points = new[] { new Vector2(value, 0), new Vector2(value, size.y) }; VerticalRenderer.SetAllDirty(); break; case Direction.Horizontal: HorizontalRenderer.enabled = true; HorizontalRenderer.Points = new[] { new Vector2(0, size.y + value), new Vector2(size.x, size.y + value) }; HorizontalRenderer.SetAllDirty(); break; } }
void Update() { var ms = MusicManager.MusicState; _rms.AddValue(ms.RMS); _peak.AddValue(ms.Peak); RMS.value = _rms.GetValue(); Peak.value = _peak.GetValue(); var p = LineRenderer.Points; var pLength = ms.Wavelength.Length / STEP; if (p == null || p.Length != pLength) { p = new Vector2[pLength]; } int pCounter = 0; for (var i = 0; i < ms.Wavelength.Length; i += STEP) { if (pCounter >= p.Length) { break; } var w = ms.Wavelength[i]; if (w < _wMin) { _wMin = w; } if (w > _wMax) { _wMax = w; } var x = i / (float)ms.Wavelength.Length; var y = (w - _wMin) / (_wMax - _wMin); p[pCounter] = new Vector2(x, y); pCounter++; } LineRenderer.Points = p; LineRenderer.SetAllDirty(); }
public void OnPositionUpdated() { if (pathActive) { float canvasScale = Screen.width / myMaster.myViewer.myCanvas.GetComponent <CanvasScaler>().referenceResolution.x; //canvasScale = 1; //canvasScale = 1f / canvasScale; float localScale = 1 / myRend.transform.lossyScale.x; //print(canvasScale); Vector3 startWorldPoint = /*RecipeTreeMaster.mainCam.ScreenToWorldPoint*/ (lineConnectionPoint.position - myRend.transform.position) * localScale /*+ Vector3.forward*5*/; Vector3 endWorldPoint = /*RecipeTreeMaster.mainCam.ScreenToWorldPoint*/ (connectedPortGfx.lineConnectionPoint.position - myRend.transform.position) * localScale /*+ Vector3.forward*5*/; float pushDistance = Mathf.Abs(Vector3.Distance(startWorldPoint, endWorldPoint)) / 2f; //pushDistance = Mathf.Max(pushDistance, 50f*localScale); Vector3[] knots = new[] { startWorldPoint, startWorldPoint + (myAdapterGroup.isLeftAdapter ? Vector3.left : Vector3.right) * pushDistance, endWorldPoint + (!myAdapterGroup.isLeftAdapter ? Vector3.left : Vector3.right) * pushDistance, endWorldPoint }; resolution = Mathf.CeilToInt(pushDistance / 7f); /*Debug.DrawLine(lineConnectionPoint.position, lineConnectionPoint.position+Vector3.up); * Debug.DrawLine(lineConnectionPoint.position + (isInput? Vector3.left : Vector3.right), lineConnectionPoint.position + (isInput? Vector3.left : Vector3.right)+Vector3.up); * Debug.DrawLine(connectedPortGfx.lineConnectionPoint.position + (isInput? Vector3.left : Vector3.right), connectedPortGfx.lineConnectionPoint.position + (isInput? Vector3.left : Vector3.right)+Vector3.up); * Debug.DrawLine(connectedPortGfx.lineConnectionPoint.position, connectedPortGfx.lineConnectionPoint.position+Vector3.up);*/ path.SetControlVerts(knots); var points = new Vector2[resolution + 1]; for (int i = 0; i <= resolution; i++) { Vector3 pos = path.GetPoint(((float)i) / (float)resolution); points[i] = new Vector2(pos.x, pos.y); } myRend.Points = points; myRend.SetAllDirty(); } }
void UpdateMeasure() { if (amountOfPoints == 2) { //position left arrow var pos = cam.WorldToScreenPoint(firstPoint); leftArrow.anchoredPosition = new Vector2(pos.x, pos.y); //position right arrow pos = cam.WorldToScreenPoint(secondPoint); rightArrow.anchoredPosition = new Vector2(pos.x, pos.y); //angle left arrow var arrowVector = rightArrow.anchoredPosition - leftArrow.anchoredPosition; var angle = Vector3.SignedAngle(Vector3.right, arrowVector, Vector3.forward); leftArrow.rotation = Quaternion.Euler(0, 0, angle); //angle right arrow rightArrow.rotation = Quaternion.Euler(0, 0, angle + 180f); //position line line.Points[0] = leftArrow.anchoredPosition; line.Points[1] = rightArrow.anchoredPosition; line.SetAllDirty(); //position text textTransform.anchoredPosition = new Vector2( (leftArrow.anchoredPosition.x + rightArrow.anchoredPosition.x) / 2f, (leftArrow.anchoredPosition.y + rightArrow.anchoredPosition.y) / 2f); //angle text if (angle > 90 || angle < -90) { angle += 180; } textTransform.rotation = Quaternion.Euler(0, 0, angle); } else { measure.SetActive(false); } }
protected void Update() { UpdateCoordinatesLabel(); var cameraAxis = new[] { _camera.forward, -_camera.forward, _camera.up, -_camera.up, _camera.right, -_camera.right, }; XLine.Points[1] = _camera.right * Scale; YLine.Points[1] = _camera.up * Scale; ZLine.Points[1] = -_camera.forward * Scale; // force redraw XLine.SetAllDirty(); YLine.SetAllDirty(); ZLine.SetAllDirty(); for (int i = 0; i < 6; i++) { AxisLabels[i].anchoredPosition = cameraAxis[i] * Scale; if (cameraAxis[i].z > 0) { AxisLabels[i].SetAsLastSibling(); AxisLabels[i].sizeDelta = new Vector2(MarkerSize, MarkerSize); } else { AxisLabels[i].sizeDelta = new Vector2(MarkerSize * 0.75f, MarkerSize * 0.75f); } } }
void SetLinePos() { points[1] = transform.localPosition; line.Points = points.ToArray(); line.SetAllDirty(); }
public void ClearPoints() { LineRenderer.Points = new Vector2[0]; LineRenderer.SetAllDirty(); }
private void RefreshLine() { lineRenderer.Points = points.ToArray(); lineRenderer.SetAllDirty(); }
public void Update() { // Reset main button if (Input.GetKeyDown(KeyCode.R) && Input.GetKey(KeyCode.LeftControl)) { PoolManager.Instance.ResetPools(); GameManager.Instance.State = GameState.Loading; SceneManager.LoadScene("main"); return; } if (Input.GetKeyDown(KeyCode.Escape)) { Application.Quit(); } // TEMP #if UNITY_EDITOR if (Input.GetKeyDown(KeyCode.C)) { Coins = Mathf.Clamp(Coins + 10, 0f, CoinMax); Mana = Mathf.Clamp(Mana + 10, 0f, ManaMax); if (UIController) { UIController.RefreshBars(); } } if (Input.GetKeyDown(KeyCode.I)) { EndMatch(Victory.Fixer); } if (Input.GetKeyDown(KeyCode.O)) { EndMatch(Victory.Destructor); } #endif var dt = Time.deltaTime; var scene = SceneManager.GetActiveScene(); if (scene.name == "main" && State != GameState.Match && State != GameState.VictoryScreen) { State = GameState.Match; StartCoroutine(StartMatch()); } if (scene.name == "menu") { State = GameState.Menu; } if (State == GameState.Match) { Mana = Mathf.Clamp(Mana + ManaRegenRate * dt, 0f, ManaMax); _refreshManaBarTimer += dt; if (_refreshManaBarTimer > 1f) { _refreshManaBarTimer = 0f; if (UIController) { UIController.RefreshManaBar(); } } CursorTrail.enabled = true; for (var i = 1; i < CursorTrail.Points.Length; i++) { CursorTrail.Points[i - 1] = CursorTrail.Points[i]; } var xt = Mathf.Clamp01(Input.mousePosition.x / Screen.width); var yt = Mathf.Clamp01(Input.mousePosition.y / Screen.height); var pos = new Vector2(Input.mousePosition.x * _trailCanvasScaler.referenceResolution.x / Screen.width, Input.mousePosition.y * _trailCanvasScaler.referenceResolution.y / Screen.height); CursorTrail.Points[CursorTrail.Points.Length - 1] = pos; CursorTrail.SetAllDirty(); } else { CursorTrail.enabled = false; } // Update cursor clicking if (Input.GetMouseButtonDown(0)) { Cursor.SetCursor(CursorPressedImage, Vector2.zero, CursorMode.ForceSoftware); } if (Input.GetMouseButtonUp(0)) { Cursor.SetCursor(CursorImage, Vector2.zero, CursorMode.ForceSoftware); } // Win/lose condition _victoryTimer += dt; if (_victoryTimer > 5f && State == GameState.Match) { var destroyedCount = 0; var maxRepairables = 0; foreach (var destructible in Destructibles) { if (destructible.Repairable) { maxRepairables += 1; if (destructible.Intact == false) { destroyedCount += 1; } } } if (destroyedCount == 0) { EndMatch(Victory.Fixer); } else if (destroyedCount == maxRepairables) { EndMatch(Victory.Destructor); } } // Mana regen update ManaRegenRate += dt * 0.015f; }
protected void SetLineRendererMousePoint(Vector2 point) { uiLineRenderer.Points[uiLineRenderer.Points.Length - 1] = point; uiLineRenderer.SetAllDirty(); // We have to set dirty because setting at an index doesn't do it for us }
private void LateUpdate() { Vector2[] points = new Vector2[] { initialPosition, currentPosition }; lineRenderer.Points = points; lineRenderer.SetAllDirty(); }