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 enum LineDir { Out, In }; public enum ZYTime { Before, After, }; public class LinePath : MonoBehaviour { public LineDir lineDir; public string startPos; public string endPos; public string linePathContent; public int manNum; public int homeNum; public int completeNum; public string dateTime; public GameObject lineRenderer; public Material firMat; public Material secMat; 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); this.transform.localScale = new Vector3(1,distance / 2,1); this.transform.eulerAngles = new Vector3(1, 1, -angle); } public void OnShow() { if (RKZYLayer.lineInfoStatic) { if (!RKZYLayer.lineInfoStatic.linePaths.Contains(this)) { RKZYLayer.lineInfoStatic.SetData(this); RKZYLayer.lineInfoStatic.GetComponent().anchoredPosition = Input.mousePosition; RKZYLayer.lineInfoStatic.linePaths.Add(this); this.lineRenderer.GetComponent().material = secMat; } } } public void UnShow() { RKZYLayer.lineInfoStatic.linePaths.Remove(this); this.lineRenderer.GetComponent().material = firMat; } private void Update() { if (CameraManager.instance.secondCamera != null) { float dyScale = CameraManager.instance.secondCamera.GetComponent().currentDistance / 6; dyScale = math.clamp(dyScale, 1, 12); 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)); } } }