本文整理汇总了C#中UnityEngine.PolygonCollider2D.GetPath方法的典型用法代码示例。如果您正苦于以下问题:C# PolygonCollider2D.GetPath方法的具体用法?C# PolygonCollider2D.GetPath怎么用?C# PolygonCollider2D.GetPath使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UnityEngine.PolygonCollider2D
的用法示例。
在下文中一共展示了PolygonCollider2D.GetPath方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetVerts
public List<Vector2> GetVerts()
{
polygon = GetComponent<PolygonCollider2D>();
List<Vector2> verts = new List<Vector2>(polygon.GetPath(0));
//transform to world space
for(int i = 0; i < verts.Count; ++i)
{
verts[i] = transform.TransformPoint((Vector3)verts[i]);
}
return verts;
}
示例2: Start
// Use this for initialization
void Start()
{
polygon = GetComponent<PolygonCollider2D> ();
Vector2[] points = polygon.GetPath (0);
// Get sides
sides = InitializeSides (points);
// Set up game object with mesh;
gameObject.AddComponent(typeof(MeshRenderer));
MeshFilter filter = gameObject.AddComponent(typeof(MeshFilter)) as MeshFilter;
Triangulator tr = new Triangulator(points);
filter.mesh = tr.GenerateMesh ();
}
示例3: OnDrawGizmos
void OnDrawGizmos()
{
polygon = GetComponent<PolygonCollider2D> ();
Vector2[] points = polygon.GetPath (0);
Vector2 prevPoint = transform.TransformPoint(points[points.Length-1]);
Vector2 nextPoint;
foreach(Vector2 point in points) {
nextPoint = transform.TransformPoint (point);
Gizmos.DrawLine (prevPoint, nextPoint);
prevPoint = nextPoint;
}
}
示例4: OptimizePolygonCollider2D
void OptimizePolygonCollider2D(GameObject gameobject, PolygonCollider2D polygonCollider2D)
{
int origVertCount = 0;
int cleanVertCount = 0;
float angleThreshold = 90.0f;
List<Vector2> newVerts = new List<Vector2>();
for (int i = 0; i < polygonCollider2D.pathCount; i++)
{
newVerts.Clear();
Vector2[] path = polygonCollider2D.GetPath(i);
if (path.Length < 4) { continue; }
origVertCount += path.Length;
float angle1 = 0;
float angle2 = 0;
newVerts.Clear();
int mx = path.Length;
Vector2 currentDir = (path[0] - path[1]).normalized;
angle1 = Vector2.Angle(path[0] - path[1], currentDir);
for (int j = 0; j < mx; j++)
{
int sPrev = (((j - 1) % mx) + mx) % mx;
int sNext = (((j + 1) % mx) + mx) % mx;
angle1 = Vector2.Angle(path[sPrev] - path[j], currentDir);
angle2 = Vector2.Angle(path[j] - path[sNext], currentDir);
if (angle1 > angleThreshold || angle2 > angleThreshold)
{
currentDir = (path[j] - path[sNext]).normalized;
newVerts.Add(path[j]);
}
}
polygonCollider2D.SetPath(i, newVerts.ToArray());
cleanVertCount += newVerts.Count;
}
}
开发者ID:daujiv,项目名称:ProceduralAssetGeneration-PolygonColliderOptimization-Unity2D-Csharp,代码行数:42,代码来源:PCG_OptimizePolygonCollider2D.cs
示例5: GetNearestToMesh
private Vector2 GetNearestToMesh(Vector2 vertex, PolygonCollider2D poly)
{
// Test to make sure starting on the collision mesh
RaycastHit2D hit = Physics2D.Raycast (vertex - new Vector2 (0.005f, 0f), new Vector2 (1f, 0f), 0.01f, 1 << KickStarter.sceneSettings.navMesh.gameObject.layer);
if (!hit)
{
Transform t = KickStarter.sceneSettings.navMesh.transform;
float minDistance = -1;
Vector2 nearestPoint = vertex;
for (int i=0; i<poly.pathCount; i++)
{
Vector2[] path = poly.GetPath (i);
for (int j=0; j<path.Length; j++)
{
Vector2 startPoint = t.TransformPoint (path[j]);
Vector2 endPoint = Vector2.zero;
if (j==path.Length-1)
{
endPoint = t.TransformPoint (path[0]);
}
else
{
endPoint = t.TransformPoint (path[j+1]);
}
Vector2 direction = endPoint - startPoint;
for (float k=0f; k<=1f; k+=0.1f)
{
float distance = Vector2.Distance (vertex, startPoint + (direction * k));
if (distance < minDistance || minDistance < 0f)
{
minDistance = distance;
nearestPoint = startPoint + (direction * k);
}
}
}
}
return nearestPoint;
}
return (vertex);
}
示例6: CreateVertexArray
private Vector2[] CreateVertexArray(PolygonCollider2D poly)
{
List <Vector2> vertexData = new List<Vector2>();
Transform t = KickStarter.sceneSettings.navMesh.transform;
for (int i=0; i<poly.pathCount; i++)
{
Vector2[] _vertices = poly.GetPath (i);
foreach (Vector2 _vertex in _vertices)
{
Vector3 vertex3D = t.TransformPoint (new Vector3 (_vertex.x, _vertex.y, t.position.z));
vertexData.Add (new Vector2 (vertex3D.x, vertex3D.y));
}
}
return vertexData.ToArray ();
}
示例7: RebuildVertexArray
private void RebuildVertexArray(Transform navMeshTransform, PolygonCollider2D poly)
{
List<Vector2> _vertexData = new List<Vector2>();
for (int i=0; i<poly.pathCount; i++)
{
Vector2[] _vertices = poly.GetPath (i);
foreach (Vector2 _vertex in _vertices)
{
Vector3 vertex3D = navMeshTransform.TransformPoint (new Vector3 (_vertex.x, _vertex.y, navMeshTransform.position.z));
_vertexData.Add (new Vector2 (vertex3D.x, vertex3D.y));
}
}
vertexData = _vertexData.ToArray ();
}
示例8: FromPolygonCollider
public static void FromPolygonCollider(VLSObstructor _obstructor, PolygonCollider2D _collider, int _pathIndex = 0)
{
pntCount = _collider.GetPath(_pathIndex).Length;
for (int i = pntCount - 1; i >= 0; i--)
_obstructor.LocalVertex(10000, _collider.GetPath(_pathIndex)[i]);
if (!_obstructor.VertsAreCounterClockwise())
_obstructor.ReverseNormals();
}
示例9: getPoints
/// <summary>
/// generates a list of points from a polygon collider
/// </summary>
/// <param name="collider">source polygon collider</param>
/// <returns>list of points</returns>
private static List<Vector2> getPoints(PolygonCollider2D collider)
{
List<Vector2> points = new List<Vector2>();
foreach (Vector2 point in collider.GetPath(0))
{
points.Add(point);
}
return points;
}