Пример #1
0
    public void LinecastCut(Vector2 lineStart, Vector2 lineEnd, int layerMask = Physics2D.AllLayers)
    {
        Stick             stick            = FindObjectOfType <Stick>();
        List <GameObject> gameObjectsToCut = new List <GameObject>();

        RaycastHit2D[] hits = Physics2D.LinecastAll(lineStart, lineEnd, layerMask);
        foreach (RaycastHit2D hit in hits)
        {
            if (HitCounts(hit))
            {
                gameObjectsToCut.Add(hit.transform.gameObject);
            }
        }

        foreach (GameObject go in gameObjectsToCut)
        {
            SpriteCutterOutput output = SpriteCutter.Cut(new SpriteCutterInput()
            {
                lineStart              = lineStart,
                lineEnd                = lineEnd,
                gameObject             = go,
                gameObjectCreationMode = SpriteCutterInput.GameObjectCreationMode.CUT_OFF_ONE,
            });

            if (output != null && output.secondSideGameObject != null)
            {
                //Rigidbody2D newRigidbody = output.secondSideGameObject.AddComponent<Rigidbody2D>();
                //newRigidbody.velocity = output.firstSideGameObject.GetComponent<Rigidbody2D>().velocity;
                output.secondSideGameObject.transform.position = stick.transform.position;
                SlicedStick slicedStick = output.secondSideGameObject.AddComponent <SlicedStick>();;
            }
        }
    }
Пример #2
0
    void LinecastCut(Vector2 lineStart, Vector2 lineEnd)
    {
        List <GameObject> gameObjectsToCut = new List <GameObject>();

        RaycastHit2D[] hits = Physics2D.LinecastAll(lineStart, lineEnd, layerMask);
        foreach (RaycastHit2D hit in hits)
        {
            if (HitCounts(hit))
            {
                gameObjectsToCut.Add(hit.transform.gameObject);
            }
        }
        if (gameObjectsToCut.Count > 0)
        {
            Camera.main.GetComponent <CameraManager>().setShake(0.2f);
            Camera.main.GetComponent <FreezeFX>().FreezeScreen();
        }

        foreach (GameObject go in gameObjectsToCut)
        {
            SpriteCutterOutput output = SpriteCutter.Cut(new SpriteCutterInput()
            {
                lineStart              = lineStart,
                lineEnd                = lineEnd,
                gameObject             = go,
                gameObjectCreationMode = SpriteCutterInput.GameObjectCreationMode.CUT_OFF_COPY,
            });
            ModifyOutputObjects(output.firstSideGameObject);
            ModifyOutputObjects(output.secondSideGameObject);
        }
    }
    void LinecastCut(Vector2 lineStart, Vector2 lineEnd, int layerMask = Physics2D.AllLayers)
    {
        List <GameObject> gameObjectsToCut = new List <GameObject>();

        RaycastHit2D[] hits      = Physics2D.LinecastAll(lineStart, lineEnd, layerMask);
        int            NumOfhits = 0;

        foreach (RaycastHit2D hit in hits)
        {
            if (HitCounts(hit))
            {
                Debug.Log($"NumOfhits {NumOfhits.ToString()}");
                NumOfhits++;
                gameObjectsToCut.Add(hit.transform.gameObject);
            }
        }

        foreach (GameObject go in gameObjectsToCut)
        {
            SpriteCutterOutput output = SpriteCutter.Cut(new SpriteCutterInput()
            {
                lineStart              = lineStart,
                lineEnd                = lineEnd,
                gameObject             = go,
                gameObjectCreationMode = SpriteCutterInput.GameObjectCreationMode.CUT_OFF_ONE,
            });

            if (output != null && output.secondSideGameObject != null)
            {
                Rigidbody2D newRigidbody = output.secondSideGameObject.AddComponent <Rigidbody2D>();
                newRigidbody.velocity = output.firstSideGameObject.GetComponent <Rigidbody2D>().velocity;
            }
        }
    }
Пример #4
0
    private void Hakkem(GameObject enemyToBeHakkedDoorDeMidden, Vector2 slashStart, Vector2 slashEnd)
    {
        //remove potentials script the ugly way
        SpriteCutterOutput output = SpriteCutter.Cut(new SpriteCutterInput()
        {
            lineStart              = slashStart,
            lineEnd                = slashEnd,
            gameObject             = enemyToBeHakkedDoorDeMidden,
            gameObjectCreationMode = SpriteCutterInput.GameObjectCreationMode.CUT_OFF_NEW,
        });

        gameObject.GetComponent <DragCatapultMovement>().ResetJumpCount();
        StartCoroutine(DelayedForce(output, slashStart, slashEnd));
    }
Пример #5
0
    public void LinecastCut(Vector2 lineStart, Vector2 lineEnd, int layerMask = Physics2D.AllLayers)
    {
        List <GameObject> gameObjectsToCut = new List <GameObject>();

        RaycastHit2D[] hits = Physics2D.LinecastAll(lineStart, lineEnd, layerMask);
        foreach (RaycastHit2D hit in hits)
        {
            if (HitCounts(hit))
            {
                gameObjectsToCut.Add(hit.transform.gameObject);
            }
        }

        foreach (GameObject go in gameObjectsToCut)
        {
            SpriteCutterOutput output = SpriteCutter.Cut(new SpriteCutterInput()
            {
                lineStart              = lineStart,
                lineEnd                = lineEnd,
                gameObject             = go,
                gameObjectCreationMode = SpriteCutterInput.GameObjectCreationMode.CUT_OFF_COPY,
            });
        }
    }
Пример #6
0
    void LinecastCut(Vector2 lineStart, Vector2 lineEnd, int layerMask = Physics2D.AllLayers)
    {
        ready = false;
        List <GameObject> gameObjectsToCut = new List <GameObject>();

        RaycastHit2D[] hits = Physics2D.LinecastAll(lineStart, lineEnd, layerMask);

        foreach (RaycastHit2D hit in hits)
        {
            if (HitCounts(hit))
            {
                gameObjectsToCut.Add(hit.transform.gameObject);
            }
        }

        foreach (GameObject go in gameObjectsToCut)
        {
            segmentArea = 4;
            if (intersectionSegments.ContainsKey(go))
            {
                segmentArea = intersectionSegments[go];
            }
            mass = go.GetComponent <Rigidbody2D>().mass;



            SpriteCutterOutput output = SpriteCutter.Cut(new SpriteCutterInput()
            {
                lineStart              = lineStart,
                lineEnd                = lineEnd,
                gameObject             = go,
                gameObjectCreationMode = SpriteCutterInput.GameObjectCreationMode.CUT_OFF_ONE,
            });


            if (output != null && output.secondSideGameObject != null)
            {
                output.firstSideGameObject.tag  = "shadow";
                output.secondSideGameObject.tag = "shadow";

                Rigidbody2D newRigidbody = output.secondSideGameObject.AddComponent <Rigidbody2D>();
                newRigidbody.gravityScale = 1;

                output.firstSideGameObject.GetComponent <Rigidbody2D>().isKinematic  = true;
                output.secondSideGameObject.GetComponent <Rigidbody2D>().isKinematic = true;



                float mass1 = mass * segmentArea / 4;
                float mass2 = mass - (mass * segmentArea / 4);

                if (mass1 < 0.2f)
                {
                    mass1 = 0.2f;
                }
                if (mass2 < 0.2f)
                {
                    mass2 = 0.2f;
                }

                if (output.firstSideGameObject.GetComponent <Collider2D>().bounds.size.magnitude > output.secondSideGameObject.GetComponent <Collider2D>().bounds.size.magnitude)
                {
                    output.firstSideGameObject.GetComponent <Rigidbody2D>().mass  = mass1;
                    output.secondSideGameObject.GetComponent <Rigidbody2D>().mass = mass2;
                }
                else
                {
                    output.secondSideGameObject.GetComponent <Rigidbody2D>().mass = mass2;
                    output.firstSideGameObject.GetComponent <Rigidbody2D>().mass  = mass1;
                }



                toEnable.Add(output.firstSideGameObject);
                toEnable.Add(output.secondSideGameObject);
            }
        }

        ready = true;
    }