本文整理汇总了C#中UnityEngine.PolygonCollider2D.SetPath方法的典型用法代码示例。如果您正苦于以下问题:C# PolygonCollider2D.SetPath方法的具体用法?C# PolygonCollider2D.SetPath怎么用?C# PolygonCollider2D.SetPath使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UnityEngine.PolygonCollider2D
的用法示例。
在下文中一共展示了PolygonCollider2D.SetPath方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Start
void Start()
{
Debug.Log("Started");
gameObject.AddComponent<LineRenderer>();
classpc = gameObject.AddComponent<PolygonCollider2D>();
classpc.SetPath(0, new Vector2[] { });
//classpc.SetPath(1, new Vector2[] { });
}
示例2: addPolygonCollider
public void addPolygonCollider(PolygonCollider2D polyCollider)
{
if (type < 1) return;
if (type > 14) return;
Vector2[] points = null;
Vector2 nodeOffset = new Vector2(nodePosition.x - polyCollider.transform.localPosition.x, nodePosition.y - polyCollider.transform.localPosition.y);
if ((type >=1) && (type <=12)) {
points = new Vector2[vertices.Length];
for (int i=0; i<vertices.Length; i++) {
points[i] = new Vector2(vertices[i].x, vertices[i].y) + nodeOffset;
}
polyCollider.SetPath(polyCollider.pathCount-1, points);
polyCollider.pathCount = polyCollider.pathCount+1;
}
if ((type == 13) || (type == 14)) {
points = new Vector2[3];
for (int i=0; i<3; i++) {
points[i] = new Vector2(vertices[i].x, vertices[i].y) + nodeOffset;
}
polyCollider.SetPath(polyCollider.pathCount-1, points);
polyCollider.pathCount = polyCollider.pathCount+1;
points = new Vector2[3];
for (int i=3; i<6; i++) {
points[i-3] = new Vector2(vertices[i].x, vertices[i].y) + nodeOffset;
}
polyCollider.SetPath(polyCollider.pathCount-1, points);
polyCollider.pathCount = polyCollider.pathCount+1;
}
}
示例3: PasteTo
public void PasteTo( PolygonCollider2D polygonCollider )
{
polygonCollider.pathCount = paths.Count;
for ( int i = 0; i < paths.Count; i++ ) {
polygonCollider.SetPath( i, paths[ i ] );
}
polygonCollider.isTrigger = isTrigger;
polygonCollider.offset = offset;
polygonCollider.sharedMaterial = sharedMaterial;
polygonCollider.usedByEffector = usedByEffector;
polygonCollider.enabled = enabled;
}
示例4: ResetCell
internal void ResetCell(Site site)
{
this.site = site;
// add polygon
polygon = gameObject.GetComponent<PolygonCollider2D>();
polygon.SetPath (0, site.Vertices.ToArray ());
// TODO: Use a MeshCollider instead
// MeshCollider myMC = GetComponent<MeshCollider>();
// Mesh newMesh = new Mesh();
// newMesh.vertices = newverts;
// newMesh.triangles = newtris;
// newMesh.RecalculateBounds();
// myMC.sharedMesh = newMesh;
gameObject.name = ToString ();
}
示例5: CopyVertices
public void CopyVertices(PolygonCollider2D a_rPolygonCollider2DTo)
{
// Clear
a_rPolygonCollider2DTo.points = new Vector2[0];
if(shapes == null)
{
return;
}
a_rPolygonCollider2DTo.pathCount = shapes.Count;
int iShapeIndex = 0;
foreach(Uni2DMeshShape2D rShape in shapes)
{
a_rPolygonCollider2DTo.SetPath(iShapeIndex, rShape.vertices);
++iShapeIndex;
}
}
示例6: 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
示例7: Awake
//************
//
// Private Unity Methods
//
//************
private void Awake()
{
//create an object and mesh for the trail
GameObject trail = new GameObject("Trail", new[] { typeof(MeshRenderer), typeof(MeshFilter), typeof(PolygonCollider2D) });
mesh = trail.GetComponent<MeshFilter>().mesh = new Mesh();
trail.GetComponent<Renderer>().material = trailMaterial;
//get and set the polygon collider on this trail.
collider = trail.GetComponent<PolygonCollider2D>();
collider.isTrigger = colliderIsTrigger;
collider.SetPath(0, null);
//get the transform of the object this script is attatched to
trans = base.transform;
//set the first center position as the current position
centerPositions = new LinkedList<Vector3>();
centerPositions.AddFirst(trans.position);
leftVertices = new LinkedList<Vertex>();
rightVertices = new LinkedList<Vertex>();
}
示例8: AddCharHoles
private void AddCharHoles(PolygonCollider2D navPoly, AC.Char charToExclude, CharacterEvasion characterEvasion)
{
ResetHoles (KickStarter.sceneSettings.navMesh, false);
Vector2 navPosition = navPoly.transform.position;
AC.Char[] characters = GameObject.FindObjectsOfType (typeof (AC.Char)) as AC.Char[];
foreach (AC.Char character in characters)
{
CircleCollider2D circleCollider2D = character.GetComponent <CircleCollider2D>();
if (circleCollider2D != null &&
(character.charState == CharState.Idle || characterEvasion == CharacterEvasion.AllCharacters) &&
(charToExclude == null || character != charToExclude) &&
Physics2D.OverlapPointNonAlloc (character.transform.position, NavigationEngine_PolygonCollider.results, 1 << KickStarter.sceneSettings.navMesh.gameObject.layer) != 0)
{
circleCollider2D.isTrigger = true;
List<Vector2> newPoints3D = new List<Vector2>();
#if UNITY_5
Vector2 centrePoint = character.transform.TransformPoint (circleCollider2D.offset);
#else
Vector2 centrePoint = character.transform.TransformPoint (circleCollider2D.center);
#endif
float radius = circleCollider2D.radius * character.transform.localScale.x;
newPoints3D.Add (centrePoint + Vector2.up * radius);
newPoints3D.Add (centrePoint + Vector2.right * radius);
newPoints3D.Add (centrePoint - Vector2.up * radius);
newPoints3D.Add (centrePoint - Vector2.right * radius);
navPoly.pathCount ++;
List<Vector2> newPoints = new List<Vector2>();
for (int i=0; i<newPoints3D.Count; i++)
{
// Only add a point if it is on the NavMesh
if (Physics2D.OverlapPointNonAlloc (newPoints3D[i], NavigationEngine_PolygonCollider.results, 1 << KickStarter.sceneSettings.navMesh.gameObject.layer) != 0)
{
newPoints.Add (newPoints3D[i] - navPosition);
}
else
{
Vector2 altPoint = GetLineIntersect (newPoints3D[i], centrePoint);
if (altPoint != Vector2.zero)
{
newPoints.Add (altPoint - navPosition);
}
}
}
if (newPoints.Count > 1)
{
navPoly.SetPath (navPoly.pathCount-1, newPoints.ToArray ());
}
}
}
RebuildVertexArray (navPoly.transform, navPoly);
}
示例9: Update
void Update()
{
//if(Input.GetKey(KeyCode.Alpha0) && index == 1) {
// index = 0;
// classpc = gameObject.AddComponent<PolygonCollider2D>();
// classpc.SetPath(0, new Vector2[] { });
//}
//if (Input.GetKey(KeyCode.Alpha1) && index == 0) {
// index = 1;
// classpc = gameObject.AddComponent<PolygonCollider2D>();
// classpc.SetPath(0, new Vector2[] { });
//}
Touch t;
if (Input.touches.Length > 0)
{
t = Input.GetTouch(0);
if (t.phase == TouchPhase.Ended)
{
Debug.Log("Finished touching!!");
classpc = gameObject.AddComponent<PolygonCollider2D>();
classpc.SetPath(0, new Vector2[] { });
}
}
var str = "";
var oldpath = classpc.GetPath(0);
for (int i = 0; i < oldpath.Length; i++)
{
str += i + ": x=" + oldpath[i].x + " y=" + oldpath[i].y + " | ";
}
//if (Input.touchCount > 0) {
// var sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere);
// sphere.transform.position = Camera.main.ScreenToWorldPoint(Input.GetTouch(0).position);
// sphere.transform.position = new Vector3(sphere.transform.position.x, sphere.transform.position.y, 0);
// Debug.Log(Camera.main.ScreenToWorldPoint(Input.GetTouch(0).position));
//}
var currInput = Input.touchCount > 0;
//if (currInput && !lastInput) {
// var pc = gameObject.AddComponent<PolygonCollider2D>();
// pc.SetPath(0, new Vec)
//}
if (currInput)
{
var point = Camera.main.ScreenToWorldPoint(Input.GetTouch(0).position);
var newPath = new Vector2[oldpath.Length + 2];
for (int i = 0; i < oldpath.Length / 2; i++)
{
newPath[i] = oldpath[i];
}
newPath[oldpath.Length / 2] = point;
newPath[oldpath.Length / 2 + 1] = new Vector2(point.x, point.y - 0.2f);
for (int i = oldpath.Length / 2; i < oldpath.Length; i++)
{
newPath[i + 2] = oldpath[i];
}
classpc.SetPath(0, newPath);
oldpath = newPath;
//
}
lastInput = currInput;
var lr = GetComponent<LineRenderer>();
lr.SetVertexCount(oldpath.Length / 2);
for (int i = 0; i < oldpath.Length / 2; i++)
{
lr.SetColors(new Color(123, 244, 80), new Color(244, 80, 123));
lr.SetWidth(0.1F, 0.1F);
lr.SetPosition(i, oldpath[i]);
}
// Debug.Log(str);
}
示例10: CompileTracedEdges
private static void CompileTracedEdges(PolygonCollider2D polygonCollider, int pathCount)
{
generatedPoints.Clear();
foreach (var point in tracedEdges)
{
generatedPoints.Add(point.Position);
}
if (polygonCollider.pathCount <= pathCount)
{
polygonCollider.pathCount += 1;
}
polygonCollider.SetPath(pathCount, generatedPoints.ToArray());
}
示例11: StopDraw
public void StopDraw()
{
StartDraw = false;
previousObj = null;
startPoint = null;
if(linePoints.Count<2){ linePoints.Clear(); return;}
#region getting circle shape
Hashtable table = new Hashtable();
foreach (Vector3 item in linePoints) {
float radius = (float) System.Math.Round( Vector2.Distance( item, compute2DPolygonCentroid(linePoints.ToArray(), linePoints.Count)), 2);
if(!table.ContainsKey( radius)) table.Add(radius, 0);
table[radius] = (int) table[radius] + 1;
}
GameObject parentObj = new GameObject("lineObject");
parentObj.transform.parent = transform;
foreach (DictionaryEntry item in table) {
if((int)item.Value >= 10 && table.Count > 6) {
CreateCircle(compute2DPolygonCentroid(linePoints.ToArray(), linePoints.Count), ""+item.Key, parentObj);
linePoints.Clear();
return;
}
}
#endregion
int ii = 0;
GameObject gm = null;
GameObject polyObj = new GameObject("polyObj");
polyObj.transform.parent = parentObj.transform;
PlaneFromPoly scr = polyObj.AddComponent<PlaneFromPoly>();
foreach (Vector3 item in linePoints) { //create points
gm = Instantiate(point, item, transform.rotation) as GameObject;
if(startPoint == null) startPoint = gm;
gm.transform.parent = polyObj.transform;
gm.GetComponent<LineObject>().firstObject = item;
gm.GetComponent<LineObject>().nextObject = gm;
if(previousObj != null){
gm.GetComponent<LineObject>().nextObject = previousObj;
}
previousObj = gm;
ii++;
}
scr.mat = mat;
scr.poly = linePoints.ToArray();
scr.keyPoints = linePoints;
int scoreMinus = -80;
if(Vector3.Distance( startPos, Input.mousePosition) < 10f){ // if shape is rounded
scoreMinus = -50;
scr.BuildMesh(linePoints);
gm.GetComponent<LineObject>().nextObject = startPoint;
polyCollider = polyObj.AddComponent<PolygonCollider2D>();
polyCollider.sharedMaterial = bounce;
polyCollider.CreatePrimitive(linePoints.Count);
polyCollider.SetPath(0, linePoints.ToArray() );
}
else{
edgeCollider = polyObj.AddComponent<EdgeCollider2D>();
edgeCollider.sharedMaterial = bounce;
// polyCollider = polyObj.AddComponent<PolygonCollider2D>();
// polyCollider.sharedMaterial = bounce;
// polyCollider.CreatePrimitive( linePoints.Count * 2 );
Vector2[] listV2 = new Vector2[linePoints.Count*2];
for (int i = 0; i < linePoints.Count; i++) {
listV2[i] = linePoints[i];
}
int j =0;
for (int i = linePoints.Count - 1; i >= 0; i--) {
listV2[j+linePoints.Count] = linePoints[i]+Vector2.up*0.05f;
j++;
}
edgeCollider.points = linePoints.ToArray(); //listV2;
// polyCollider.SetPath(0, listV2);
}
previousObj = null;
startPoint = null;
Rigidbody2D r = polyObj.AddComponent<Rigidbody2D>();
r.mass = 0.2f * linePoints.Count;
// r.collisionDetectionMode = CollisionDetectionMode2D.Continuous;
linePoints.Clear();
}
示例12: SetColliderPointsLocal
public static void SetColliderPointsLocal (PolygonCollider2D collider, Slot slot, BoundingBoxAttachment box) {
if (box == null) return;
if (box.IsWeighted()) Debug.LogWarning("UnityEngine.PolygonCollider2D does not support weighted or animated points. Collider points will not be animated and may have incorrect orientation. If you want to use it as a collider, please remove weights and animations from the bounding box in Spine editor.");
var verts = box.GetLocalVertices(slot, null);
collider.SetPath(0, verts);
}