Ejemplo n.º 1
0
        public void GenerateFill(Transform transform, DayLightColliderShape shape, float height)
        {
            List <Polygon2> polys     = shape.GetPolygonsLocal();
            float           direction = Lighting2D.DayLightingSettings.direction * Mathf.Deg2Rad;

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

                Polygon2 worldPolygon = polygon.Copy();

                worldPolygon.ToScaleSelf(transform.localScale);
                worldPolygon.ToRotationSelf(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;

                    polygonShadowFill.points[i] = b;
                }

                polygonsPairs.Add(polygonPairs);

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

                MeshObject meshObject = MeshObject.Get(mesh);

                if (meshObject != null)
                {
                    meshes.Add(meshObject);
                }
            }
        }
Ejemplo n.º 2
0
        public void Generate(DayLightColliderShape shape)
        {
            float height = shape.height;

            if (shape.shadowType == DayLightCollider2D.ShadowType.SpriteOffset)
            {
                return;
            }

            if (shape.shadowType == DayLightCollider2D.ShadowType.SpriteProjection)
            {
                return;
            }

            Clear();

            List <Polygon2> polys = shape.GetPolygonsLocal();

            if (polys == null)
            {
                return;
            }

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

            float sunHeight = Lighting2D.DayLightingSettings.height;

            GenerateFill(shape.transform, shape, height * sunHeight);

            bool softness = Lighting2D.DayLightingSettings.softness.enable;

            if (softness)
            {
                GenerateSoftness();
            }
        }
Ejemplo n.º 3
0
    public void Initialize()
    {
        shapes.Clear();

        mainShape.shadowType = shadowType;
        mainShape.thickness  = shadowThickness;
        mainShape.maskType   = maskType;
        mainShape.height     = shadowDistance;

        mainShape.SetTransform(transform);
        mainShape.ResetLocal();

        mainShape.transform2D.Update();

        shapes.Add(mainShape);

        if (applyToChildren)
        {
            foreach (Transform childTransform in transform)
            {
                DayLightColliderShape shape = new DayLightColliderShape();
                shape.maskType   = mainShape.maskType;
                shape.shadowType = mainShape.shadowType;
                shape.height     = mainShape.height;

                shape.SetTransform(childTransform);
                shape.ResetLocal();

                shape.transform2D.Update();

                shapes.Add(shape);
            }
        }

        foreach (DayLightColliderShape shape in shapes)
        {
            shape.shadowMesh.Generate(shape);
        }
    }
Ejemplo n.º 4
0
 public void SetShape(DayLightColliderShape shape)
 {
     this.shape = shape;
 }