示例#1
0
    public void Start()
    {
        eventController.OnEnvChangeShapeEvent.AddListener(ResetAndCleanUp);

        Instance              = this;
        tilemapCollider       = GetComponent <CompositeCollider2D>();
        shadowCasterContainer = shadow_caster_go;
        //shadowCasterContainer = GetComponent<ShadowCaster2D>().gameObject;
        for (int i = 0; i < tilemapCollider.pathCount; i++)
        {
            Vector2[] pathVertices = new Vector2[tilemapCollider.GetPathPointCount(i)];
            tilemapCollider.GetPath(i, pathVertices);

            GameObject shadowCaster = new GameObject("shadow_caster_^" + i);
            shadowCasters.Add(shadowCaster);
            PolygonCollider2D shadowPolygon = (PolygonCollider2D)shadowCaster.AddComponent(typeof(PolygonCollider2D));
            shadowPolygons.Add(shadowPolygon);
            shadowCaster.transform.parent = shadowCasterContainer.transform;
            shadowPolygon.points          = pathVertices;
            shadowPolygon.enabled         = true;
            shadowPolygon.isTrigger       = true;
            //if (shadowCaster.GetComponent<ShadowCaster2D>() != null) // remove existing caster?
            //    Destroy(shadowCaster.GetComponent<ShadowCaster2D>());
            ShadowCaster2D shadowCasterComponent = shadowCaster.AddComponent <ShadowCaster2D>();
            shadowCasterComponents.Add(shadowCasterComponent);
            shadowCasterComponent.selfShadows = true;
        }
    }
 public void Start()
 {
     Instance              = this;
     tilemapCollider       = GetComponent <CompositeCollider2D>();
     shadowCasterContainer = GameObject.Find("shadow_casters");
     for (int i = 0; i < tilemapCollider.pathCount; i++)
     {
         Vector2[] pathVertices = new Vector2[tilemapCollider.GetPathPointCount(i)];
         tilemapCollider.GetPath(i, pathVertices);
         GameObject shadowCaster = new GameObject("shadow_caster_" + i);
         shadowCasters.Add(shadowCaster);
         PolygonCollider2D shadowPolygon = (PolygonCollider2D)shadowCaster.AddComponent(typeof(PolygonCollider2D));
         shadowPolygons.Add(shadowPolygon);
         shadowCaster.transform.parent = shadowCasterContainer.transform;
         shadowPolygon.points          = pathVertices;
         shadowPolygon.enabled         = false;
         //if (shadowCaster.GetComponent<ShadowCaster2D>() != null) // remove existing caster?
         //    Destroy(shadowCaster.GetComponent<ShadowCaster2D>());
         ShadowCaster2D shadowCasterComponent = shadowCaster.AddComponent <ShadowCaster2D>();
         shadowCasterComponents.Add(shadowCasterComponent);
         shadowCasterComponent.selfShadows = true;
     }
 }