Ejemplo n.º 1
0
    private void MakeMesh()
    {
        timer += Time.deltaTime;
        if (timer < maxTime)
        {
            return;
        }
        if (beams.Count <= 0)
        {
            return;
        }

        lightup.Light();
        foreach (BeamPair pair in beams)
        {
            Vector3 left = pair.Beam1.Point;
            Vector3 leftEnd;
            Vector3 right = pair.Beam2.Point;
            Vector3 rightEnd;

            RaycastHit2D leftHit  = new RaycastHit2D();
            RaycastHit2D rightHit = new RaycastHit2D();

            bool reflectL = false;
            bool reflectR = false;

            ReflectionHandler l = null;
            ReflectionHandler r = null;

            BeamFOV.Beam point1 = new BeamFOV.Beam();
            BeamFOV.Beam point2 = new BeamFOV.Beam();

            col.enabled = false;

            leftHit  = Physics2D.Raycast(left, pair.Beam1.Dir, pair.Beam1.Distance, ObstacleMask + CharacterMask + InteractableMask);
            rightHit = Physics2D.Raycast(right, pair.Beam2.Dir, pair.Beam2.Distance, ObstacleMask + CharacterMask + InteractableMask);
            //myHandler.handler.AddHit(leftHit);
            //myHandler.handler.AddHit(rightHit);


            if (myHandler.handler.bulb.power == Bulb.Power.XRAY)
            {
                rightHit = Physics2D.Raycast(right, pair.Beam2.Dir, pair.Beam2.Distance, CharacterMask + InteractableMask);
            }
            if (myHandler.handler.bulb.power == Bulb.Power.XRAY)
            {
                leftHit = Physics2D.Raycast(left, pair.Beam1.Dir, pair.Beam1.Distance, CharacterMask + InteractableMask);
            }
            if (leftHit.collider == null)
            {
                leftEnd = left + pair.Beam1.Dir * pair.Beam1.Distance;
            }
            else if (InteractableMask == (InteractableMask | (1 << leftHit.collider.gameObject.layer)))
            {
                myHandler.handler.AddInteractable(leftHit.collider.gameObject.transform);
                if (myHandler.handler.bulb.power == Bulb.Power.XRAY)
                {
                    leftHit = Physics2D.Raycast(left, pair.Beam1.Dir, pair.Beam1.Distance, CharacterMask);
                }
                else
                {
                    leftHit = Physics2D.Raycast(left, pair.Beam1.Dir, pair.Beam1.Distance, ObstacleMask + CharacterMask);
                }
            }
            else
            {
                myHandler.handler.AddHit(leftHit);
            }
            if (rightHit.collider == null)
            {
                rightEnd = right + pair.Beam2.Dir * pair.Beam2.Distance;
            }

            else if (InteractableMask == (InteractableMask | (1 << rightHit.collider.gameObject.layer)))
            {
                myHandler.handler.AddInteractable(rightHit.collider.gameObject.transform);
                if (myHandler.handler.bulb.power == Bulb.Power.XRAY)
                {
                    rightHit = Physics2D.Raycast(right, pair.Beam2.Dir, pair.Beam2.Distance, CharacterMask);
                }
                else
                {
                    rightHit = Physics2D.Raycast(right, pair.Beam2.Dir, pair.Beam2.Distance, ObstacleMask + CharacterMask);
                }
            }
            else
            {
                myHandler.handler.AddHit(rightHit);
            }


            col.enabled = true;


            if (leftHit.collider == null)
            {
                leftEnd = left + pair.Beam1.Dir * pair.Beam1.Distance;
            }
            else
            {
                leftEnd = leftHit.point;

                reflectL = true;
                l        = leftHit.collider.GetComponent <ReflectionHandler>();
                float deltaD = pair.Beam1.Distance - (leftEnd - left).magnitude;
                point1 = new BeamFOV.Beam(leftEnd, deltaD, Vector3.Reflect(pair.Beam1.Dir, leftHit.normal));
            }
            if (rightHit.collider == null)
            {
                rightEnd = right + pair.Beam2.Dir * pair.Beam2.Distance;
            }
            else
            {
                rightEnd = rightHit.point;

                reflectR = true;
                r        = rightHit.collider.GetComponent <ReflectionHandler>();
                float deltaD = pair.Beam2.Distance - (rightEnd - right).magnitude;
                point2 = new BeamFOV.Beam(rightEnd, deltaD, Vector3.Reflect(pair.Beam2.Dir, rightHit.normal));
            }

            if (reflectL && reflectR && l != null)
            {
                if (l == r)
                {
                    l.AddBeam(point1, point2);
                }
            }

            int topLeft  = AddPoint(leftEnd);
            int topRight = AddPoint(rightEnd);
            int botLeft  = AddPoint(left);
            int botRight = AddPoint(right);

            AddRect(topLeft, topRight, botLeft, botRight);
        }
    }
Ejemplo n.º 2
0
 public void AddBeam(BeamFOV.Beam ray1, BeamFOV.Beam ray2)
 {
     beams.Add(new BeamPair(ray2, ray1));
 }
Ejemplo n.º 3
0
 public BeamPair(BeamFOV.Beam beam1, BeamFOV.Beam beam2)
 {
     Beam1 = beam1;
     Beam2 = beam2;
 }
Ejemplo n.º 4
0
 public void AddBeam(BeamFOV.Beam ray1, BeamFOV.Beam ray2)
 {
     beams.AddBeam(ray1, ray2);
 }