本文整理汇总了C#中UnityEngine.PolygonCollider2D.CreatePrimitive方法的典型用法代码示例。如果您正苦于以下问题:C# PolygonCollider2D.CreatePrimitive方法的具体用法?C# PolygonCollider2D.CreatePrimitive怎么用?C# PolygonCollider2D.CreatePrimitive使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UnityEngine.PolygonCollider2D
的用法示例。
在下文中一共展示了PolygonCollider2D.CreatePrimitive方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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();
}