123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class TestRoute : MonoBehaviour
- {
- public Vector2 Interval = new Vector2(0, -0.02f);
- /// <summary>
- /// 旋转方向
- /// </summary>
- public Transform point;
- public List<Material> list_material;
- public Vector3 endPos;
- public Vector3 exitPos;
- public Transform A;
- public Transform B;
- private Material material;
- private Vector2 offset;
-
- void Start()
- {
- material = this.GetComponent<MeshRenderer>().material;
- offset = Vector2.zero;
- // Test();
- }
- // Update is called once per frame
- void Update()
- {
- offset -= Interval;
- material.SetTextureOffset("_MainTex", offset);
- }
- /// <summary>
- /// 设置Route 位置 长度 朝向 旋转
- /// </summary>
- /// <param name="endPos"></param>
- /// <param name="exitPos"></param>
- public void SetRoute( Vector3 endPos, Vector3 exitPos )
- {
- if (material == null)
- material = this.GetComponent<MeshRenderer>().material;
- this.endPos = endPos;
- this.exitPos = exitPos;
- transform.localScale += new Vector3(0, 0, Mathf.Abs( Vector3.Distance(endPos,exitPos) )/12f - (transform.localScale.x * 2));
- material.SetTextureScale("_MainTex", new Vector2(1, Mathf.Abs(Vector3.Distance(endPos, exitPos))*1.5f));
- Vector3 pos = endPos + (exitPos - endPos).normalized * (Vector3.Distance(endPos, exitPos));
- transform.position = (exitPos+endPos)/2.0f + new Vector3(0, -2f, 0);
- Debug.Log("Route " + endPos + " " + exitPos +" "+ transform.position);
- point.position = endPos + new Vector3(0, transform.position.y, 0);
- transform.LookAt(point);
- }
- public void SetRoute(Vector3 endPos, Vector3 exitPos ,int Index)
- {
- this.GetComponent<MeshRenderer>().material = list_material[Index];
- if (material == null)
- material = this.GetComponent<MeshRenderer>().material;
- this.endPos = endPos;
- this.exitPos = exitPos;
- // Debug.Log("Route " + endPos + " " + exitPos);
- transform.localScale += new Vector3(0, 0, Mathf.Abs(Vector3.Distance(endPos, exitPos))/12 -(transform.localScale.x*2));
- material.SetTextureScale("_MainTex", new Vector2(1, Mathf.Abs(Vector3.Distance(endPos, exitPos)) * 1.5f));
- Vector3 pos = endPos + (exitPos - endPos).normalized * (Vector3.Distance(endPos, exitPos));
- transform.position = (exitPos + endPos) / 2.0f + new Vector3(0, -2f, 0);
- point.position = endPos + new Vector3(0, transform.position.y, 0);
- transform.LookAt(point);
- }
- /// <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));
- }
-
- public void Test()
- {
- SetRoute(A.position, B.position);
- }
-
- }
|