12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- 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<MeshRenderer>().material.SetColor("_Color1",color);
- this.lineRenderer.GetComponent<MeshRenderer>().material.SetColor("_Color2", color1);
- }
- private void Update()
- {
- if (CameraManager.instance.secondCamera != null)
- {
- float dyScale = CameraManager.instance.secondCamera.GetComponent<CameraBirdSec>().currentDistance / 14;
- dyScale = math.clamp(dyScale, 0.5f, 5f);
- this.transform.localScale = new Vector3(dyScale, this.transform.localScale.y, dyScale);
- this.lineRenderer.GetComponent<MeshRenderer>().material.SetTextureScale("_MainTex", new Vector2(1, this.transform.localScale.y * 10 / this.transform.localScale.x));
- }
- }
- }
|