- 最后登录
- 2016-8-29
- 注册时间
- 2012-8-25
- 阅读权限
- 90
- 积分
- 23585
  
- 纳金币
- 20645
- 精华
- 62
|
- using UnityEngine;
- using System.Collections;
- using System.Collections.Generic;
- public class TwoPointLineWihtTerrain : MonoBehaviour {
- public Transform startPoint;
- public Transform endPoint;
- List<Vector3> pointList = new List<Vector3 > (777);
- // Use this for initialization
- void Start ()
- {
- ToLinePahtHelp (startPoint.position, endPoint.position).ForEach (a => pointList.Add (a));
- DrawLineY.Get1 ().Instance2 ().DLine (ref pointList);//个人画线函数
- }
- /// <summary>
- /// 两点之间直线的坐标计算.
- /// </summary>
- /// <returns>The line paht help.</returns>
- /// <param name="startPoint">起点.</param>
- /// <param name="endPoint">终点.</param>
- /// <param name="per">从起点到终点每间隔几米划分一个点.</param>
- public static List<Vector3> ToLinePahtHelp(Vector3 startPoint,Vector3 endPoint,float per=0.27f)
- {
- List<Vector3> pointList = new List<Vector3 > (777);
- Vector3 dir = (endPoint - startPoint).normalized;
- Vector3 currentPoint = Vector3.zero;;
- float distance = Vector3.Distance(endPoint , startPoint);
- int number =(int)( distance / per);
- for (int i = 1; i < number + 1; i++)
- {
- currentPoint = startPoint+ dir * (float)(i*per);
- pointList.Add (currentPoint);
- }
- return pointList;
- }
- }
复制代码 |
|