using System.Collections; using System.Collections.Generic; using UnityEngine; public class Route : MonoBehaviour { private Vector2 Interval = new Vector2(0, 0.05f); public List ListLineMat; /// /// 旋转方向 /// public Transform Point; public Vector3 EndPos; public Vector3 StartPos; public Material material_High; private Material material; private MeshRenderer meshRenderer; private Vector2 offset; void Start() { meshRenderer = this.GetComponent(); material = meshRenderer.material; offset = Vector2.zero; StartCoroutine(SetOffset()); } void Update() { } private IEnumerator SetOffset() { while(true) { yield return new WaitForSeconds(0.04f); offset -= Interval; material.SetTextureOffset("_MainTex", offset); material_High.SetTextureOffset("_MainTex", offset); } } private IEnumerator setMaterial() { yield return new WaitForSeconds(0.3f); // meshRenderer.material = material_High; material.SetTextureScale("_MainTex", new Vector2(1, transform.localScale.z/transform.localScale.x)); } public void setHighLight( bool isHigh) { // material. if (isHigh) meshRenderer.material = material_High; else meshRenderer.material = material; } /// /// 设置Route 位置 长度 朝向 旋转 /// /// /// public void SetRoute(Vector3 endPos, Vector3 startPos, int Index) { this.GetComponent().material = ListLineMat[Index]; if (material == null) material = this.GetComponent().material; this.EndPos = endPos; this.StartPos = startPos; // Debug.Log("Route " + endPos + " " + exitPos); transform.localScale += new Vector3(0, 0, Mathf.Abs(Vector3.Distance(EndPos, StartPos)) / 12 - (transform.localScale.x * 2)); material.SetTextureScale("_MainTex", new Vector2(1, Mathf.Abs(Vector3.Distance(EndPos, StartPos)) * 1.5f)); transform.localPosition = (StartPos + EndPos) / 2.0f; Point.localPosition = StartPos + new Vector3(0, transform.localPosition.y, 0); transform.LookAt(Point); } /// /// 设置Route 位置 长度 朝向 旋转 /// /// /// public void SetRoute(Vector3 endPos, Vector3 startPos, int Index , Transform point) { this.GetComponent().material = ListLineMat[Index]; if (material == null) material = this.GetComponent().material; this.EndPos = endPos; this.StartPos = startPos; // Debug.Log("Route " + endPos + " " + exitPos); // transform.localScale += new Vector3(0, 0, Mathf.Abs(Vector3.Distance(EndPos, StartPos)) / 12 - (transform.localScale.x * 2)); // 根据世界场景的尺寸进行换算比例 transform.localScale = new Vector3(transform.localScale.x, transform.localScale.y, Mathf.Abs(Vector3.Distance(EndPos, StartPos) / 4)- transform.localScale.x * 2); material.SetTextureScale("_MainTex", new Vector2(1, Mathf.Abs(Vector3.Distance(EndPos, StartPos)) * 1.5f)); transform.position = (StartPos + EndPos) / 2.0f; //transform.LookAt(point); StartCoroutine(setMaterial()); } /// /// 3DMapRoute /// /// /// public void SetMapRoute() { if (material == null) material = this.GetComponent().material; material.SetTextureScale("_MainTex", new Vector2(1, 2f)); } public void SetMapRoute(Vector3 endPos, Vector3 exitPos) { if (material == null) material = this.GetComponent().material; material.SetTextureScale("_MainTex", new Vector2(1, Mathf.Abs(Vector3.Distance(endPos, exitPos)) * 0.7f)); } }