예제 #1
0
    void StartSpriteRenderer()
    {
        spriteRenderer = GetComponent <SpriteRenderer>();

        if (spriteRenderer == null)
        {
            Debug.LogError("Destruction2D: Game object is missing SpriteRenderer Component");
        }

        if (chunks.enabled)
        {
            StartChunks();
        }
        else
        {
            Sprite sprite = spriteRenderer.sprite;
            pixelsPerUnit = sprite.pixelsPerUnit;
            Debug.Log("sprite.pixelsPerUnit");

            if (originalSprite == null)
            {
                originalSprite = sprite;
            }

            if (replaceSprite == false)
            {
                originalSpriteMaterial             = new Material(Shader.Find("Sprites/Default"));
                originalSpriteMaterial.mainTexture = originalSprite.texture;
            }

            Texture2D texture = originalSprite.texture;

            renderTexture = new RenderTexture((int)sprite.rect.width, (int)sprite.rect.height, 32);
            outputTexture = new Texture2D((int)sprite.rect.width, (int)sprite.rect.height);

            switch (textureType)
            {
            case TextureType.Mesh:
                outputMaterial             = new Material(Shader.Find("Sprites/Default"));
                outputMaterial.mainTexture = texture;

                Destroy(spriteRenderer);

                break;

            case TextureType.Sprite:
                break;
            }

            Destruction2DManager.RequestBufferEvent(this);
        }
    }
예제 #2
0
    public void AddModifier(Texture2D texture, Vector2 position, Vector2 size, float rotation)
    {
        Polygon2D poly = Polygon2D.CreateFromRect(size);

        poly.ToRotationItself(rotation * Mathf.Deg2Rad);
        poly.ToOffsetItself(new Vector2D(position));

        List <Polygon2D> polys = shape.GetWorld();

        if (polys.Count > 0)
        {
            bool touch = false;

            foreach (Polygon2D p in polys)
            {
                if (Math2D.PolyCollidePoly(poly, p) == true)
                {
                    touch = true;
                }
            }

            if (touch == false)
            {
                return;
            }
        }
        else
        {
            Polygon2D p     = GetBoundPolygon();
            bool      touch = false;

            p = p.ToWorldSpace(transform);

            if (Math2D.PolyCollidePoly(p, poly) == true)
            {
                touch = true;
            }

            if (touch == false)
            {
                return;
            }
        }

        Vector2 pos = transform.InverseTransformPoint(position);

        float ratioX = 1;

        if (transform.localScale.x != transform.localScale.y)
        {
            ratioX = transform.localScale.x / transform.localScale.y;
            size.y = size.y * ratioX;
        }

        size.x /= transform.localScale.x;
        size.y /= transform.localScale.y;
        size.y /= ratioX;

        DestructionModifier modifier = new DestructionModifier(texture, pos, size, rotation);

        modifiers.Add(modifier);

        modifiersAdded = true;         // add only if colides

        if (textureType == TextureType.SpriteShape)
        {
            buffer.renderCamera.enabled = true;
        }
        else
        {
            Destruction2DManager.RequestBufferEvent(this);             // Check if it is already requested
        }
    }
예제 #3
0
    public bool DestroyByPolygon(EraseBrush EraseBrush)
    {
        //CrumbsEffect.isSlicing = false;

        if (EraseBrush.GetWorldShape().pointsList.Count < 3)
        {
            return(false);
        }

        List <Polygon2D> polys = shape.GetWorld();

        if (polys.Count > 0)
        {
            bool touch   = false;
            bool outside = false;

            foreach (Polygon2D p in polys)
            {
                if (Math2D.PolyCollidePoly(EraseBrush.GetWorldShape(), p) == true)
                {
                    touch = true;
                }

                if (EraseBrush.GetWorldShape().PolyInPoly(p) == false)
                {
                    outside = true;
                }
            }



            if (touch == false)
            {
                return(false);
            }
            // CrumbsEffect.isSlicing = true;
            if (outside == false)
            {
                Destroy(gameObject);
                return(true);
            }
        }
        else
        {
            Polygon2D bound = GetBoundPolygon();
            bool      touch = false;

            bound.ToWorldSpaceItself(transform);

            if (Math2D.PolyCollidePoly(EraseBrush.GetWorldShape(), bound) == true)
            {
                touch = true;
            }

            if (touch == false)
            {
                return(false);
            }
        }

        eraseEvents.Add(new DestructionEvent(EraseBrush));

        if (textureType == TextureType.SpriteShape)
        {
            buffer.renderCamera.enabled = true;
        }
        else
        {
            Destruction2DManager.RequestBufferEvent(this);
        }
        return(true);
    }