Exemple #1
0
        public void GenerateFill(DayLightingTile tile, float height)
        {
            List <Polygon2> polys     = tile.polygons;
            float           direction = Lighting2D.DayLightingSettings.direction * Mathf.Deg2Rad;

            foreach (Polygon2 polygon in polys)
            {
                if (polygon.points.Length < 2)
                {
                    continue;
                }

                Polygon2 worldPolygon = polygon.Copy();

                // worldPolygon.ToScaleItself(transform.localScale);
                //worldPolygon.ToRotationItself(transform.rotation.eulerAngles.z * Mathf.Deg2Rad);

                Polygon2           polygonShadow = GenerateShadow(worldPolygon, direction, height);
                List <DoublePair2> polygonPairs  = DoublePair2.GetList(polygonShadow.points);

                Polygon2 polygonShadowFill = polygonShadow.Copy();

                int pointsCount = polygonShadowFill.points.Length;

                for (int i = 0; i < pointsCount; i++)
                {
                    Vector2 a = polygonShadowFill.points[(i - 1 + pointsCount) % pointsCount];
                    Vector2 b = polygonShadowFill.points[i];
                    Vector2 c = polygonShadowFill.points[(i + 1) % pointsCount];

                    float angle_a = (float)System.Math.Atan2(a.y - b.y, a.x - b.x) + pi2;
                    float angle_c = (float)System.Math.Atan2(b.y - c.y, b.x - c.x) + pi2;

                    b.x += Mathf.Cos(angle_a) * 0.001f;
                    b.y += Mathf.Sin(angle_a) * 0.001f;

                    b.x += Mathf.Cos(angle_c) * 0.001f;
                    b.y += Mathf.Sin(angle_c) * 0.001f;
                }

                polygonsPairs.Add(polygonPairs);

                Mesh mesh = PolygonTriangulator2.TriangulateSimple(polygonShadowFill, Vector2.zero, Vector2.zero);

                MeshObject meshObject = MeshObject.Get(mesh);

                if (meshObject != null)
                {
                    meshes.Add(meshObject);
                }
            }
        }
Exemple #2
0
        public void Generate(DayLightingTile tile)
        {
            float height = tile.height;

            Clear();

            if (meshBrush == null)
            {
                meshBrush = new MeshBrush();
            }

            float sunHeight = Lighting2D.DayLightingSettings.height;

            GenerateFill(tile, height * sunHeight);


            bool softness = Lighting2D.DayLightingSettings.softness.enable;

            if (softness)
            {
                GenerateSoftness();
            }
        }
Exemple #3
0
    public void Initialize()
    {
        TilemapEvents.Initialize();

        GetCurrentTilemap().Initialize();

        dayTiles.Clear();

        switch (tilemapType)
        {
        case MapType.SuperTilemapEditor:

            switch (superTilemapEditor.shadowTypeSTE)
            {
            case SuperTilemapEditorSupport.TilemapCollider.ShadowType.Grid:
            case SuperTilemapEditorSupport.TilemapCollider.ShadowType.TileCollider:
                foreach (LightTile tile in GetTileList())
                {
                    DayLightingTile dayTile = new DayLightingTile();
                    dayTile.shadowMesh = new DayLighting.TilemapShadowMesh();
                    dayTile.height     = height;

                    dayTile.polygons = tile.GetWorldPolygons(GetCurrentTilemap());

                    dayTiles.Add(dayTile);

                    dayTile.shadowMesh.Generate(dayTile);
                }
                break;

                                                #if (SUPER_TILEMAP_EDITOR)
            case SuperTilemapEditorSupport.TilemapCollider.ShadowType.Collider:

                foreach (Polygon2 polygon in superTilemapEditor.GetWorldColliders())
                {
                    DayLightingTile dayTile = new DayLightingTile();
                    dayTile.shadowMesh = new DayLighting.TilemapShadowMesh();
                    dayTile.height     = height;

                    dayTile.polygons = new List <Polygon2>();

                    Polygon2 poly = polygon.Copy();
                    poly.ToOffsetSelf(transform.position);

                    dayTile.polygons.Add(poly);

                    dayTiles.Add(dayTile);

                    dayTile.shadowMesh.Generate(dayTile);
                }


                break;
                                        #endif
            }


            break;

        case MapType.UnityRectangle:

            switch (rectangle.shadowType)
            {
            case LightTilemapCollider.ShadowType.Grid:
            case LightTilemapCollider.ShadowType.SpritePhysicsShape:
                foreach (LightTile tile in GetTileList())
                {
                    DayLightingTile dayTile = new DayLightingTile();
                    dayTile.shadowMesh = new DayLighting.TilemapShadowMesh();
                    dayTile.height     = height;

                    dayTile.polygons = tile.GetWorldPolygons(GetCurrentTilemap());

                    dayTiles.Add(dayTile);

                    dayTile.shadowMesh.Generate(dayTile);
                }

                break;

            case LightTilemapCollider.ShadowType.CompositeCollider:
                foreach (Polygon2 polygon in rectangle.compositeColliders)
                {
                    DayLightingTile dayTile = new DayLightingTile();
                    dayTile.shadowMesh = new DayLighting.TilemapShadowMesh();
                    dayTile.height     = height;

                    dayTile.polygons = new List <Polygon2>();

                    Polygon2 poly = polygon.Copy();
                    poly.ToOffsetSelf(transform.position);

                    dayTile.polygons.Add(poly);

                    dayTiles.Add(dayTile);

                    dayTile.shadowMesh.Generate(dayTile);
                }
                break;
            }

            break;
        }
    }