123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class Route : MonoBehaviour
- {
- private Vector2 Interval = new Vector2(0, 0.05f);
- public List<Material> ListLineMat;
- /// <summary>
- /// 旋转方向
- /// </summary>
- 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<MeshRenderer>();
- 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;
-
- }
- /// <summary>
- /// 设置Route 位置 长度 朝向 旋转
- /// </summary>
- /// <param name="endPos"></param>
- /// <param name="exitPos"></param>
- public void SetRoute(Vector3 endPos, Vector3 startPos, int Index)
- {
- this.GetComponent<MeshRenderer>().material = ListLineMat[Index];
- if (material == null)
- material = this.GetComponent<MeshRenderer>().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);
- }
- /// <summary>
- /// 设置Route 位置 长度 朝向 旋转
- /// </summary>
- /// <param name="endPos"></param>
- /// <param name="exitPos"></param>
- public void SetRoute(Vector3 endPos, Vector3 startPos, int Index , Transform point)
- {
- this.GetComponent<MeshRenderer>().material = ListLineMat[Index];
- if (material == null)
- material = this.GetComponent<MeshRenderer>().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());
- }
- /// <summary>
- /// 3DMapRoute
- /// </summary>
- /// <param name="endPos"></param>
- /// <param name="exitPos"></param>
- public void SetMapRoute()
- {
- if (material == null)
- material = this.GetComponent<MeshRenderer>().material;
- material.SetTextureScale("_MainTex", new Vector2(1, 2f));
- }
- public void SetMapRoute(Vector3 endPos, Vector3 exitPos)
- {
- if (material == null)
- material = this.GetComponent<MeshRenderer>().material;
- material.SetTextureScale("_MainTex", new Vector2(1, Mathf.Abs(Vector3.Distance(endPos, exitPos)) * 0.7f));
- }
- }
|