Ejemplo n.º 1
0
    // Remove Position
    static public List <Slice2D> PolygonSliceAll(Vector2D position, Polygon2D slicePolygon, bool destroy, Slice2DLayer layer = null)
    {
        List <Slice2D> result = new List <Slice2D> ();

        if (layer == null)
        {
            layer = Slice2DLayer.Create();
        }

        Polygon2D slicePolygonDestroy = null;

        if (destroy)
        {
            slicePolygonDestroy = slicePolygon.ToScale(new Vector2(1.1f, 1.1f));
            slicePolygonDestroy = slicePolygonDestroy.ToOffset(position);
        }

        slicePolygon = slicePolygon.ToOffset(position);

        foreach (Slicer2D id in GetListLayer(layer))
        {
            result.Add(id.PolygonSlice(slicePolygon, slicePolygonDestroy));
        }

        return(result);
    }
Ejemplo n.º 2
0
    static public List <Slice2D> LinearSliceAll(Pair2D slice, Slice2DLayer layer = null, bool perform = true)
    {
        List <Slice2D> result = new List <Slice2D> ();

        if (layer == null)
        {
            layer = Slice2DLayer.Create();
        }

        foreach (Slicer2D id in GetListLayer(layer))
        {
            Slice2D sliceResult = id.LinearSlice(slice, perform);

            if (perform)
            {
                if (sliceResult.gameObjects.Count > 0)
                {
                    result.Add(sliceResult);
                }
            }
            else
            {
                if (sliceResult.polygons.Count > 0)
                {
                    result.Add(sliceResult);
                }
            }
        }

        return(result);
    }
Ejemplo n.º 3
0
 public void SetController(Slicer2DInputController inputController, Slicer2DVisuals visualsSettings, Slice2DLayer layerObject, Slicer2DControllerEventHandling eventHandling)
 {
     input        = inputController;
     visuals      = visualsSettings;
     sliceLayer   = layerObject;
     eventHandler = eventHandling;
 }
Ejemplo n.º 4
0
    static public List <Slicer2D> GetListLayer(Slice2DLayer layer)
    {
        List <Slicer2D> result = new List <Slicer2D> ();

        foreach (Slicer2D id in slicer2DList)
        {
            if (id.MatchLayers(layer))
            {
                result.Add(id);
            }
        }

        return(result);
    }
Ejemplo n.º 5
0
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Space))
        {
            float     timer = Time.realtimeSinceStartup;
            Polygon2D poly  = Polygon2D.CreateFromCollider(gameObject).ToWorldSpace(transform);

            Slicer2D.ComplexSliceAll(poly.pointsList, Slice2DLayer.Create());

            Destroy(gameObject);

            Slicer2D.Debug.Log(name + " in " + (Time.realtimeSinceStartup - timer) * 1000 + "ms");
        }
    }
Ejemplo n.º 6
0
    static public List <Slicer2D> GetListLayer(Slice2DLayer layer)
    {
        getLayerList.Clear();

        foreach (Slicer2D id in slicer2DList)
        {
            if (id.MatchLayers(layer))
            {
                getLayerList.Add(id);
            }
        }

        return(getLayerList);
    }
Ejemplo n.º 7
0
    static public List <Slice2D> ExplodeAll(Slice2DLayer layer)
    {
        List <Slice2D> result = new List <Slice2D> ();

        foreach (Slicer2D id in GetListLayer(layer))
        {
            Slice2D sliceResult = id.Explode();
            if (sliceResult.gameObjects.Count > 0)
            {
                result.Add(sliceResult);
            }
        }

        return(result);
    }
Ejemplo n.º 8
0
    static public List <Slice2D> PointSliceAll(Vector2D slice, float rotation, Slice2DLayer layer)
    {
        List <Slice2D> result = new List <Slice2D> ();

        foreach (Slicer2D id in GetListLayer(layer))
        {
            Slice2D sliceResult = id.PointSlice(slice, rotation);
            if (sliceResult.gameObjects.Count > 0)
            {
                result.Add(sliceResult);
            }
        }

        return(result);
    }
Ejemplo n.º 9
0
    static public List <Slice2D> ComplexCutSliceAll(ComplexCut complexCut, Slice2DLayer layer)
    {
        List <Slice2D> result = new List <Slice2D> ();

        foreach (Slicer2D id in GetListLayer(layer))
        {
            Slice2D sliceResult = id.ComplexCutSlice(complexCut);
            if (sliceResult.gameObjects.Count > 0)
            {
                result.Add(sliceResult);
            }
        }

        return(result);
    }
Ejemplo n.º 10
0
    static public List <Slice2D> LinearSliceAll(Pair2D slice, Slice2DLayer layer)
    {
        List <Slice2D> result = new List <Slice2D> ();

        foreach (Slicer2D id in GetListLayer(layer))
        {
            Slice2D sliceResult = id.LinearSlice(slice);

            if (sliceResult.gameObjects.Count > 0)
            {
                result.Add(sliceResult);
            }
        }

        return(result);
    }
Ejemplo n.º 11
0
    // Update is called once per frame
    void Update()
    {
        //Simple Test before implementing event
        if (Input.GetKey(KeyCode.K))
        {
            GameObject.Find("MainTimeline").GetComponent <FallingTimeManager>().ResumeTimeline();
        }

        if (Input.GetKey(KeyCode.S) && !_sendKeyPressed)
        {
            SendCut();
            _keyPressed = true;
            Debug.Log("Send Cut Event");
        }

        if (Input.GetKey(KeyCode.V) && !_keyPressed)
        {
            _keyPressed = true;
            foreach (var cutPair in _userCutPoints)
            {
                List <Slice2D> sliceResult = Slicer2D.LinearSliceAll(cutPair, Slice2DLayer.Create());
                foreach (var slice in sliceResult)
                {
                    List <GameObject> slicedGameObjects = slice.GetGameObjects();
                    foreach (var sg in slicedGameObjects)
                    {
                        sg.GetComponent <Rigidbody2D>().AddForce(UnityEngine.Random.insideUnitCircle, ForceMode2D.Impulse);
                    }
                }
            }
            GameObject[] cutLines = GameObject.FindGameObjectsWithTag("cut_line");
            foreach (var cutLine in cutLines)
            {
                Destroy(cutLine);
            }
        }

//        if (_userCutPoints.Count == cutTarget && !_alreadyCut){
//            Debug.Log("wtf why it sends all the time");
//            SendCutFall();
//            Cut();
//            GameObject.Find("MainTimeline").GetComponent<FallingTimeManager>().ResumeTimeline();
//            _alreadyCut = true;
//        }
    }
Ejemplo n.º 12
0
    void Cut()
    {
//        DoSlowMotion();
//        _startSlowMotion = true;
        foreach (var cutPair in _cutPoints)
        {
            List <Slice2D> sliceResult = Slicer2D.LinearSliceAll(cutPair, Slice2DLayer.Create());
            foreach (var slice in sliceResult)
            {
                List <GameObject> slicedGameObjects = slice.GetGameObjects();
                foreach (var sg in slicedGameObjects)
                {
                    sg.GetComponent <Rigidbody2D>().AddForce(Random.insideUnitCircle * 20, ForceMode2D.Impulse);
                    sg.AddComponent <SliceMoveOut>();
                }
            }
        }
    }
Ejemplo n.º 13
0
    static public List <Slice2D> ExplodingSliceAll(Vector2f point, Slice2DLayer layer)
    {
        List <Slice2D> result = new List <Slice2D> ();

        foreach (Slicer2D id in GetList())
        {
            if (id.MatchLayers(layer))
            {
                Slice2D sliceResult = id.ExplodingSlice(point);
                if (sliceResult.gameObjects.Count > 0)
                {
                    result.Add(sliceResult);
                }
            }
        }

        return(result);
    }
Ejemplo n.º 14
0
    static public List <Slice2D> ComplexSliceAll(List <Vector2f> slice, Slice2DLayer layer)
    {
        List <Slice2D> result = new List <Slice2D> ();

        foreach (Slicer2D id in GetList())
        {
            if (id.MatchLayers(layer))
            {
                Slice2D sliceResult = id.ComplexSlice(slice);
                if (sliceResult.gameObjects.Count > 0)
                {
                    result.Add(sliceResult);
                }
            }
        }

        return(result);
    }
Ejemplo n.º 15
0
    static public List <Slice2D> ComplexSliceAll(List <Vector2D> slice, Slice2DLayer layer = null)
    {
        List <Slice2D> result = new List <Slice2D> ();

        if (layer == null)
        {
            layer = Slice2DLayer.Create();
        }

        foreach (Slicer2D id in GetListLayer(layer))
        {
            Slice2D sliceResult = id.ComplexSlice(slice);
            if (sliceResult.gameObjects.Count > 0)
            {
                result.Add(sliceResult);
            }
        }

        return(result);
    }
Ejemplo n.º 16
0
    static public List <Slice2D> LinearCutSliceAll(LinearCut linearCut, Slice2DLayer layer = null)
    {
        List <Slice2D> result = new List <Slice2D> ();

        if (layer == null)
        {
            layer = Slice2DLayer.Create();
        }

        foreach (Slicer2D id in GetListLayer(layer))
        {
            Slice2D sliceResult = id.LinearCutSlice(linearCut);
            if (sliceResult.gameObjects.Count > 0)
            {
                result.Add(sliceResult);
            }
        }

        return(result);
    }
Ejemplo n.º 17
0
    static public List <Slice2D> ExplodeAll(Slice2DLayer layer = null, int explosionSlices = 0)
    {
        List <Slice2D> result = new List <Slice2D> ();

        if (layer == null)
        {
            layer = Slice2DLayer.Create();
        }

        foreach (Slicer2D id in GetListLayer(layer))
        {
            Slice2D sliceResult = id.Explode(explosionSlices);
            if (sliceResult.GetGameObjects().Count > 0)
            {
                result.Add(sliceResult);
            }
        }

        return(result);
    }
Ejemplo n.º 18
0
    static public List <Slice2D> ExplodeInPointAll(Vector2D point, Slice2DLayer layer = null)
    {
        List <Slice2D> result = new List <Slice2D> ();

        if (layer == null)
        {
            layer = Slice2DLayer.Create();
        }

        foreach (Slicer2D id in GetListLayer(layer))
        {
            Slice2D sliceResult = id.ExplodeInPoint(point);
            if (sliceResult.gameObjects.Count > 0)
            {
                result.Add(sliceResult);
            }
        }

        return(result);
    }
Ejemplo n.º 19
0
    static public List <Slice2D> ComplexCutSliceAll(ComplexCut complexCut, Slice2DLayer layer = null)
    {
        List <Slice2D> result = new List <Slice2D> ();

        if (layer == null)
        {
            layer = Slice2DLayer.Create();
        }

        foreach (Slicer2D id in GetListLayer(layer))
        {
            Slice2D sliceResult = id.ComplexCutSlice(complexCut);
            if (sliceResult.GetGameObjects().Count > 0)
            {
                result.Add(sliceResult);
            }
        }

        return(result);
    }
Ejemplo n.º 20
0
 public void Cut()
 {
     foreach (var cutPair in _userCutPoints)
     {
         List <Slice2D> sliceResult = Slicer2D.LinearSliceAll(cutPair, Slice2DLayer.Create());
         foreach (var slice in sliceResult)
         {
             List <GameObject> slicedGameObjects = slice.GetGameObjects();
             foreach (var sg in slicedGameObjects)
             {
                 sg.GetComponent <Rigidbody2D>().AddForce(UnityEngine.Random.insideUnitCircle * 20, ForceMode2D.Impulse);
                 sg.AddComponent <SliceMoveOut>();
             }
         }
     }
     GameObject[] cutLines = GameObject.FindGameObjectsWithTag("cut_line");
     foreach (var cutLine in cutLines)
     {
         Destroy(cutLine);
     }
 }
Ejemplo n.º 21
0
    // Shouldn't Have Position
    static public List <Slice2D> PolygonSliceAll(Vector2f position, Polygon slicePolygon, Polygon slicePolygonDestroy, Slice2DLayer layer)
    {
        Polygon sliceDestroy = null;
        Polygon slice        = slicePolygon.ToOffset(position);

        if (slicePolygonDestroy != null)
        {
            sliceDestroy = slicePolygonDestroy.ToOffset(position);
        }

        List <Slice2D> result = new List <Slice2D> ();

        foreach (Slicer2D id in GetList())
        {
            if (id.MatchLayers(layer))
            {
                result.Add(id.PolygonSlice(slice, slicePolygon, sliceDestroy));
            }
        }

        return(result);
    }
Ejemplo n.º 22
0
    public List <Slice2D> Update(Vector2D position, float timer, Slice2DLayer layer)
    {
        List <Slice2D> result = new List <Slice2D>();

        foreach (Slicer2D slicer in Slicer2D.GetListCopy())
        {
            if (slicer.MatchLayers(layer) == false)
            {
                continue;
            }

            SlicerTrailObject trail = null;
            trailList.TryGetValue(slicer, out trail);

            if (trail == null)
            {
                trail = new SlicerTrailObject();
                trailList.Add(slicer, trail);
            }

            if (trail.lastPosition != null)
            {
                if (Vector2D.Distance(trail.lastPosition, position) > 0.05f)
                {
                    trail.pointsList.Add(new TrailPoint(position, timer));
                }
            }
            else
            {
                trail.pointsList.Add(new TrailPoint(position, timer));
            }

            if (trail.pointsList.Count > 1)
            {
                foreach (TrailPoint trailPoint in new List <TrailPoint>(trail.pointsList))
                {
                    if (trailPoint.Update() == false)
                    {
                        trail.pointsList.Remove(trailPoint);
                    }
                }

                List <Vector2D> points = new List <Vector2D>();
                foreach (TrailPoint trailPoint in trail.pointsList)
                {
                    points.Add(trailPoint.position);
                }

                Slicer2D.complexSliceType = Slicer2D.SliceType.Regular;
                Slice2D slice = slicer.ComplexSlice(points);
                if (slice.GetGameObjects().Count > 0)
                {
                    trailList.Remove(slicer);

                    result.Add(slice);
                }
                ;
            }

            trail.lastPosition = position;
        }

        return(result);
    }
Ejemplo n.º 23
0
    public List <Slice2D> Update(Vector2D position, float timer, Slice2DLayer layer)
    {
        List <Slice2D> result = new List <Slice2D>();

        foreach (Slicer2D slicer in Slicer2D.GetListCopy())
        {
            if (slicer.MatchLayers(layer) == false)
            {
                continue;
            }

            SlicerTrailObject trail = null;
            trailList.TryGetValue(slicer, out trail);

            if (trail == null)
            {
                trail = new SlicerTrailObject();
                trailList.Add(slicer, trail);
            }

            if (trail.lastPosition != null)
            {
                if (Vector2D.Distance(trail.lastPosition, position) > 0.05f)
                {
                    trail.pointsList.Insert(0, new TrailPoint(position, timer));
                }
            }
            else
            {
                trail.pointsList.Insert(0, new TrailPoint(position, timer));
            }

            foreach (TrailPoint trailPoint in new List <TrailPoint>(trail.pointsList))
            {
                if (trailPoint.Update() == false)
                {
                    trail.pointsList.Remove(trailPoint);
                }
            }

            if (trail.pointsList.Count > 1)
            {
                Vector2D firstPoint  = null;
                Vector2D lastPoint   = null;
                bool     insideState = false;

                foreach (TrailPoint trailPoint in trail.pointsList)
                {
                    bool inside = false;
                    if (slicer.shape.GetLocal().PointInPoly(trailPoint.position.InverseTransformPoint(slicer.transform)))
                    {
                        inside = true;
                    }

                    switch (insideState)
                    {
                    case true:
                        // Slice!
                        if (inside == false)
                        {
                            lastPoint = trailPoint.position;

                            insideState = false;
                            break;
                        }
                        break;

                    case false:
                        if (inside == false)
                        {
                            // Searching For Start of Slice
                            firstPoint  = trailPoint.position;
                            insideState = true;
                        }
                        break;
                    }

                    if (lastPoint != null)
                    {
                        break;
                    }
                }

                if (firstPoint != null && lastPoint != null)
                {
                    Slicer2D.complexSliceType = Slicer2D.SliceType.Regular;
                    Slice2D slice = slicer.LinearSlice(new Pair2D(firstPoint, lastPoint));
                    if (slice.GetGameObjects().Count > 0)
                    {
                        trailList.Remove(slicer);

                        result.Add(slice);
                    }
                    ;
                }
            }

            trail.lastPosition = position;
        }
        return(result);
    }
Ejemplo n.º 24
0
 public bool MatchLayers(Slice2DLayer sliceLayer)
 {
     return((sliceLayer == null || sliceLayer.GetLayerType() == Slice2DLayerType.All) || sliceLayer.GetLayerState(GetLayerID()));
 }