本文整理汇总了C#中UnityEngine.PolygonCollider2D类的典型用法代码示例。如果您正苦于以下问题:C# PolygonCollider2D类的具体用法?C# PolygonCollider2D怎么用?C# PolygonCollider2D使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PolygonCollider2D类属于UnityEngine命名空间,在下文中一共展示了PolygonCollider2D类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Awake
// Use this for initialization
void Awake()
{
spriteRend = GetComponent<SpriteRenderer> ();
collider = GetComponent<PolygonCollider2D> ();
//DestroyPlanetChunk ();
}
示例2: Start
// Use this for initialization
void Start () {
area = this.gameObject.GetComponent<PolygonCollider2D> ();
/*Vector3[] passIn = new Vector3[points.Length];
for (int i = 0; i < points.Length; i++)
passIn [i] = points [i].transform.position;
SetCollider (passIn); */
}
示例3: Start
void Start()
{
base.Start();
anim = GetComponent<Animator>();
rigid = GetComponent<Rigidbody2D>();
collider = GetComponent<PolygonCollider2D>();
}
示例4: AssignValues
override public void AssignValues (List<ActionParameter> parameters)
{
SceneSettings sceneSettings = GameObject.FindWithTag (Tags.gameEngine).GetComponent <SceneSettings>();
if (sceneSetting == SceneSetting.DefaultNavMesh)
{
if (sceneSettings.navigationMethod == AC_NavigationMethod.PolygonCollider && changeNavMeshMethod == ChangeNavMeshMethod.ChangeNumberOfHoles)
{
hole = AssignFile <PolygonCollider2D> (parameters, parameterID, constantID, hole);
}
else
{
newNavMesh = AssignFile <NavigationMesh> (parameters, parameterID, constantID, newNavMesh);
}
}
else if (sceneSetting == SceneSetting.DefaultPlayerStart)
{
playerStart = AssignFile <PlayerStart> (parameters, parameterID, constantID, playerStart);
}
else if (sceneSetting == SceneSetting.SortingMap)
{
sortingMap = AssignFile <SortingMap> (parameters, parameterID, constantID, sortingMap);
}
else if (sceneSetting == SceneSetting.OnLoadCutscene || sceneSetting == SceneSetting.OnStartCutscene)
{
cutscene = AssignFile <Cutscene> (parameters, parameterID, constantID, cutscene);
}
}
示例5: AssignValues
public override void AssignValues(List<ActionParameter> parameters)
{
if (sceneSetting == SceneSetting.DefaultNavMesh)
{
if (KickStarter.sceneSettings.navigationMethod == AC_NavigationMethod.PolygonCollider && changeNavMeshMethod == ChangeNavMeshMethod.ChangeNumberOfHoles)
{
hole = AssignFile <PolygonCollider2D> (parameters, parameterID, constantID, hole);
replaceHole = AssignFile <PolygonCollider2D> (parameters, replaceParameterID, replaceConstantID, replaceHole);
}
else
{
newNavMesh = AssignFile <NavigationMesh> (parameters, parameterID, constantID, newNavMesh);
}
}
else if (sceneSetting == SceneSetting.DefaultPlayerStart)
{
playerStart = AssignFile <PlayerStart> (parameters, parameterID, constantID, playerStart);
}
else if (sceneSetting == SceneSetting.SortingMap)
{
sortingMap = AssignFile <SortingMap> (parameters, parameterID, constantID, sortingMap);
}
else if (sceneSetting == SceneSetting.SortingMap)
{
tintMap = AssignFile <TintMap> (parameters, parameterID, constantID, tintMap);
}
else if (sceneSetting == SceneSetting.OnLoadCutscene || sceneSetting == SceneSetting.OnStartCutscene)
{
cutscene = AssignFile <Cutscene> (parameters, parameterID, constantID, cutscene);
}
}
示例6: Awake
// Use this for initialization
void Awake () {
ignoreCollisionList = new List<Collider2D>();
rigid = GetComponent<Rigidbody2D>();
ball = this.gameObject.AddComponent<PolygonCollider2D>();
ball.sharedMaterial = ballPhysicsMat;
rend = GetComponent<LineRenderer>();
Vector2[] points = new Vector2[2 * (numSides + 1)];
rend.SetVertexCount(numSides + 1);
float visualRadius = (outerRadius + innerRadius) / 2;
rend.SetWidth(outerRadius - innerRadius, outerRadius - innerRadius);
// inner points
for (int i = 0; i <= numSides; i++)
{
float angle = TwoPI * i / numSides;
Vector2 direction = new Vector2(Mathf.Cos(angle), Mathf.Sin(angle));
points[i] = innerRadius * direction;
rend.SetPosition(i, visualRadius * direction);
}
// outer points
for (int i = numSides + 1; i < points.Length; i++)
{
float angle = TwoPI * i / numSides;
points[i] = new Vector2(outerRadius * Mathf.Cos(angle), outerRadius * Mathf.Sin(angle));
}
ball.points = points;
}
示例7: OnDrawGizmos
//---------------------------------------------------------------------------------------------
protected virtual void OnDrawGizmos()
{
Follow();
if (!m_pCollider)
m_pCollider = GetComponent<PolygonCollider2D>();
Vector2[] points = m_pCollider.points;
Vector2 p2D = transform.position;
if (points == null) return;
Vector3 pointCurrent, pointNext;
Vector3 angles = transform.rotation.eulerAngles;
for (var i = 0; i < points.Length - 1; i++)
{
pointCurrent = KDTools.Adjust(points[i], p2D, angles, transform.localScale);
pointNext = KDTools.Adjust(points[i + 1], p2D, angles, transform.localScale);
Gizmos.DrawLine(pointCurrent, pointNext);
}
pointCurrent = KDTools.Adjust
(
points[points.Length - 1],
p2D,
angles,
transform.localScale
);
pointNext = KDTools.Adjust(points[0], p2D, angles, transform.localScale);
Gizmos.DrawLine(pointCurrent, pointNext);
}
示例8: DrawAsteroid
public void DrawAsteroid()
{
var drawObject = GetComponent<LineRendererDrawer>();
polyCollider = GetComponent<PolygonCollider2D>();
var linePoints = circleSegments + 1;
var polyPoints = new Vector2[linePoints];
var drawPoints = new List<Vector2>();
float part = 360f / circleSegments;
int i = 0;
while (i < linePoints)
{
float duh = part * i * (2 * Mathf.PI / 360) * -1 + Mathf.PI / 2;
Vector3 pos = new Vector3((Mathf.Cos(duh) * radius), (Mathf.Sin(duh) * radius), 0);
if (i != 0 && i != (linePoints - 1))
{
pos = new Vector3(pos.x + Random.Range(-radius / 4, radius / 4), pos.y + Random.Range(-radius / 4, radius / 4), 0);
}
drawPoints.Add(pos);
polyPoints[i] = new Vector2(pos.x, pos.y);
i++;
}
drawObject.SetPoints(drawPoints);
polyCollider.points = polyPoints;
}
示例9: Awake
void Awake()
{
lightMesh = new Mesh();
lightMesh.name = string.Format("Light Mesh ({0})", name);
lightMesh.MarkDynamic();
meshFilter = GetComponent<MeshFilter>();
meshFilter.mesh = lightMesh;
meshRenderer = GetComponent<MeshRenderer>();
meshRenderer.sharedMaterial = lightMaterial;
var container = transform.Find("LightMesh");
if (!container)
{
container = new GameObject("LightMesh").transform;
container.SetParent(transform, true);
container.localPosition = Vector3.zero;
container.gameObject.layer = gameObject.layer;
}
lightMeshCollider = container.GetComponent<PolygonCollider2D>();
if (lightMeshCollider == null)
{
lightMeshCollider = container.gameObject.AddComponent<PolygonCollider2D>();
}
lightMeshCollider.isTrigger = true;
vertices = new List<Vertex>();
UpdateLightFX();
}
示例10: Start
void Start()
{
hitbox = gameObject.AddComponent<PolygonCollider2D>();
hitbox.isTrigger = true;
AudioSource.PlayClipAtPoint(Resources.Load<AudioClip>("Skills/Slash/slash_" + Random.Range(0,3).ToString()), gameObject.transform.position);
StartCoroutine("playAnimation", attackSpeed);
}
示例11: Awake
// ============= GENERATION ==============
private void Awake() {
allPoints = new List<Point>();
edgePoints = new List<Point>();
finishingPoints = new List<Point>();
polygonCollider = GetComponent<PolygonCollider2D>();
mesh = GetComponent<TriangulatedMesh>();
}
示例12: RebuildAllColliders
public override void RebuildAllColliders()
{
UpdateCollidable();
DestroyCollider();
var alphaTex = destructibleSprite.AlphaTex;
if (alphaTex != null)
{
var spriteRenderer = D2D_Helper.GetOrAddComponent<SpriteRenderer>(child);
var sprite = Sprite.Create(alphaTex, new Rect(0, 0, alphaTex.width, alphaTex.height), Vector2.zero, 1.0f, 0, SpriteMeshType.FullRect);
spriteRenderer.sprite = sprite;
collider = child.AddComponent<PolygonCollider2D>();
// Disable the collider if it couldn't form any triangles
collider.enabled = IsDefaultPolygonCollider2D(collider) == false;
D2D_Helper.Destroy(sprite);
D2D_Helper.Destroy(spriteRenderer);
UpdateColliderSettings();
}
}
示例13: Start
// Use this for initialization
void Start()
{
audio = gameObject.GetComponent<AudioSource>();
rb = GetComponent<Rigidbody2D>();
collision = GetComponent<PolygonCollider2D>();
}
示例14: MakeBounds
private void MakeBounds(PolygonCollider2D source)
{
if (source.renderer == null)
{
Vector2[] points = source.points;
float maxX = float.NegativeInfinity;
float maxY = float.NegativeInfinity;
foreach (Vector2 point in points)
{
if (point.x > maxX)
{
maxX = point.x;
}
if (point.y > maxY)
{
maxY = point.y;
}
}
Vector2 maxSize = new Vector2(maxX, maxY);
Vector2 pos = source.transform.position;
Vector2 polySize = maxSize - pos;
MakeBounds(source.gameObject, polySize, Vector2.zero);
}
else
{
MakeBounds(source.renderer);
}
}
示例15: Reset
void Reset()
{
gameObject.name = "@PolyNav2D";
masterCollider = GetComponent<PolygonCollider2D>();
masterCollider.isTrigger = true;
}