當前位置: 首頁>>代碼示例>>C#>>正文


C# UnityEngine.PolygonCollider2D類代碼示例

本文整理匯總了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 ();
        }
開發者ID:dialcforchris,項目名稱:InterstellarmadillosGame,代碼行數:8,代碼來源:GravityBody.cs

示例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); */
	}
開發者ID:RIT-SMCS,項目名稱:Gerrymander,代碼行數:8,代碼來源:DistrictCollider.cs

示例3: Start

 void Start()
 {
     base.Start();
     anim = GetComponent<Animator>();
     rigid = GetComponent<Rigidbody2D>();
     collider = GetComponent<PolygonCollider2D>();
 }
開發者ID:stronklabs,項目名稱:fastfast,代碼行數:7,代碼來源:Player.cs

示例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);
			}
		}
開發者ID:amutnick,項目名稱:CrackTheCode_Repo,代碼行數:28,代碼來源:ActionNavMesh.cs

示例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);
     }
 }
開發者ID:mcbodge,項目名稱:eidolon,代碼行數:31,代碼來源:ActionNavMesh.cs

示例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;
	}
開發者ID:AlbearKamoo,項目名稱:Witches-vs-Aliens-2015-2016,代碼行數:36,代碼來源:HampsterBall.cs

示例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);
    }
開發者ID:aaronroles,項目名稱:LITZombies,代碼行數:36,代碼來源:KD2DArea.cs

示例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;
    }
開發者ID:torston,項目名稱:Asteroids,代碼行數:26,代碼來源:Asteroid.cs

示例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();
    }
開發者ID:igm-capstone,項目名稱:proto-03-lights,代碼行數:33,代碼來源:Light2D.cs

示例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);
 }
開發者ID:rwbysafire,項目名稱:DemonHeart,代碼行數:7,代碼來源:SlashLogic.cs

示例11: Awake

	// ============= GENERATION ==============
	private void Awake() {
		allPoints = new List<Point>();
		edgePoints = new List<Point>();
		finishingPoints = new List<Point>();
		polygonCollider = GetComponent<PolygonCollider2D>();
		mesh = GetComponent<TriangulatedMesh>();
	}
開發者ID:wtrebella,項目名稱:Grappler,代碼行數:8,代碼來源:MountainChunk.cs

示例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();
        }
    }
開發者ID:rickbatka,項目名稱:birds,代碼行數:26,代碼來源:D2D_AutoSpriteCollider.cs

示例13: Start

    // Use this for initialization
    void Start()
    {

        audio = gameObject.GetComponent<AudioSource>();
        rb = GetComponent<Rigidbody2D>();
        collision = GetComponent<PolygonCollider2D>();
    }
開發者ID:dustmant27,項目名稱:UnitySpaceShooter,代碼行數:8,代碼來源:EnemyMoveDown.cs

示例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);
     }
 }
開發者ID:Jay2645,項目名稱:UnityHelperFunctions,代碼行數:28,代碼來源:Bounds2D.cs

示例15: Reset

    void Reset()
    {

        gameObject.name = "@PolyNav2D";
        masterCollider = GetComponent<PolygonCollider2D>();
        masterCollider.isTrigger = true;
    }
開發者ID:SamuelKnox,項目名稱:Project-Heist,代碼行數:7,代碼來源:PolyNav2D.cs


注:本文中的UnityEngine.PolygonCollider2D類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。