public void Update(LineData data) { //var start = _parentTransform.position + data.Start; //var end = _parentTransform.position + data.End; var start = data.Start; var end = data.End; var vec = end - start; var arrowLength = Mathf.Clamp(vec.magnitude * 0.5f, 0, data.Width * 4); vec.Normalize(); Vector3 midPoint = end - vec * arrowLength; _line.SetColors(data.Color, data.Color); _line.SetWidth(data.Width, data.Width); _arrowHead.SetColors(data.Color, data.Color); _arrowHead.SetWidth(data.Width * 3, 0); _line.useWorldSpace = data.UseWorldSpace; _arrowHead.useWorldSpace = data.UseWorldSpace; _line.SetPosition(0, start); _line.SetPosition(1, midPoint); _arrowHead.SetPosition(0, midPoint); _arrowHead.SetPosition(1, end); _line.enabled = true; _arrowHead.enabled = true; }
public void AddLine(LineData data) { if (!_lineDataDisplay.ContainsKey(data)) { var display = new LineDisplay(_shaderMaterial, transform); _lineDataDisplay[data] = display; } }
private void UpdateRigHelper(Transform parentTransform, Vector3 offset) { if (parentTransform == null) { return; } var parentPos = parentTransform.position + offset; var count = parentTransform.childCount; for (int i = 0; i < count; i++) { var childTransform = parentTransform.GetChild(i); var childPos = childTransform.position + offset; LineData data = null; if (!_transformLineData.TryGetValue(childTransform, out data)) { data = new LineData(parentPos, childPos, Color.green) { UseWorldSpace = true, }; _transformLineData[childTransform] = data; LineOverlay.AddLine(data); } data.Start = parentPos; data.End = childPos; UpdateRigHelper(childTransform, offset); } }
public void RemoveLine(LineData data) { _lineDataDisplay.Remove(data); }