using System.Collections; using System.Collections.Generic; using System.Net; using Unity.Mathematics; using Unity.VisualScripting; using UnityEngine; using UnityEngine.EventSystems; using XCharts.Runtime; public class LinePathUnit : MonoBehaviour { public string startPos; public string endPos; public GameObject lineRenderer; void Start() { } public void SetPath(Vector3 start, Vector3 end) { this.transform.position = start; Vector3 direction = end - start; Vector3 up = Vector3.up; // (0,1,0) // 计算夹角 float angle = Vector3.Angle(direction, up); // 使用叉积来判断方向 Vector3 crossProduct = Vector3.Cross(direction, up); if (crossProduct.z < 0) { angle = 360 - angle; } //print(angle); float distance = Vector3.Distance(end, start) * 1.02f; this.transform.localScale = new Vector3(1, distance / 2, 1); this.transform.eulerAngles = new Vector3(1, 1, -angle); } public void SetColor(Color color,Color color1) { this.lineRenderer.GetComponent().material.SetColor("_Color1",color); this.lineRenderer.GetComponent().material.SetColor("_Color2", color1); } private void Update() { if (CameraManager.instance.secondCamera != null) { float dyScale = CameraManager.instance.secondCamera.GetComponent().currentDistance / 14; dyScale = math.clamp(dyScale, 0.5f, 5f); this.transform.localScale = new Vector3(dyScale, this.transform.localScale.y, dyScale); this.lineRenderer.GetComponent().material.SetTextureScale("_MainTex", new Vector2(1, this.transform.localScale.y * 10 / this.transform.localScale.x)); } } }