Exemplo n.º 1
0
        public void SetWall(WallLogic wall, WallLogic prev, float start, float end)
        {
            Wall       = wall;
            StartPoint = start;
            EndPoint   = end;
            float3 prevCenter = (prev.GetEndPosition() + prev.GetStartPosition()) / 2;

            ClosestPoint = MathHelper.ClosestPoint(wall.GetStartPosition(), wall.GetEndPosition(), prevCenter);
            Position     = (startPosition + endPosition) / 2;

            float distance2 = MathHelper.SqrDistance(ClosestPoint.xyz, prevCenter);
            float offsetT   = data.BoundingSize.x / 2 / math.sqrt(distance2);
            // Debug.Log(offsetT);
            //Direction = GetPointSide(point);
            //cachedPoint = math.lerp(Position, point, offsetT);
            float3 movement = prevCenter - ClosestPoint.xyz;

            offset    = movement * offsetT;
            Position += offset;



            startPosition      = math.lerp(wall.GetStartPosition(), wall.GetEndPosition(), start) + offset - Position;
            endPosition        = math.lerp(wall.GetStartPosition(), wall.GetEndPosition(), end) + offset - Position;
            Position           = new float3(Position.x, data.ZoffsetinMeters, Position.z);
            transform.position = Position;
            vaild = true;
            UpdateVisuals();
        }
        public bool AddWall(WallLogic wall)
        {
            bool add = hashedWalls.Add(wall);

            if (add)
            {
                walls.Add(wall);
            }
            walls.Sort();
            //UpdateWalls();
            return(add);
        }
Exemplo n.º 3
0
        private void MergeAndDeselect()
        {
            List <CornerLogic> corners = Blueprint.Corners;

            int   close1 = -1, close2 = -1;
            float min1 = float.MaxValue;
            float min2 = float.MaxValue;

            for (int i = 0; i < corners.Count; i++)
            {
                if (i != selectedCorner1Index && i != selectedCorner2Index)
                {
                    float d1 = MathHelper.SqrDistance(corners[i].Position, selectedCorner1.Position);
                    if (d1 < Snap && d1 < min1)
                    {
                        min1   = d1;
                        close1 = i;
                    }
                    float d2 = MathHelper.SqrDistance(corners[i].Position, selectedCorner2.Position);
                    if (d2 < Snap && d2 < min2)
                    {
                        min2   = d2;
                        close2 = i;
                    }
                }
            }
            if (close1 == close2 && close1 != -1)
            {
                Blueprint.Instance.RemoveWall(SelectedWall);
                Blueprint.Instance.RemoveCorner(selectedCorner1);
                Blueprint.Instance.RemoveCorner(selectedCorner2);
            }
            else
            {
                if (close1 != -1 && close1 != selectedCorner1Index)
                {
                    var c = Blueprint.Corners[close1];
                    c.MergeOther(selectedCorner1);
                }
                if (close2 != -1 && close2 != selectedCorner2Index)
                {
                    var c = Blueprint.Corners[close2];
                    c.MergeOther(selectedCorner2);
                }
            }
            SelectedWall         = null;
            selectedCorner1      = null;
            selectedCorner2      = null;
            selectedCorner1Index = -1;
            selectedCorner2Index = -1;
            InputManger.Instance.DisableUI();
        }
        public bool RemoveWall(WallLogic wall)
        {
            bool add = hashedWalls.Remove(wall);

            walls.Remove(wall);
            if (walls.Count == 0)
            {
                Blueprint.Instance.RemoveCorner(this);
                GameObject.Destroy(gameObject);
            }
            walls.Sort();

            return(add);
        }
        public WallLogic GetPreviousWall(WallLogic wall)
        {
            if (walls.Count == 1)
            {
                return(null);
            }
            int i = walls.IndexOf(wall);

            if (i == 0)
            {
                return(walls[walls.Count - 1]);
            }
            else
            {
                return(walls[i - 1]);
            }
        }
        public WallLogic GetNextWall(WallLogic wall)
        {
            if (walls.Count == 1)
            {
                return(null);
            }
            int i = walls.IndexOf(wall);

            if (i == walls.Count - 1)
            {
                return(walls[0]);
            }
            else
            {
                return(walls[i + 1]);
            }
        }
Exemplo n.º 7
0
        public override void Delete()
        {
            Blueprint.Instance.RemoveWall(SelectedWall);
            if (selectedCorner1.GetWallsCount() == 0)
            {
                Blueprint.Instance.RemoveCorner(selectedCorner1);
            }
            if (selectedCorner2.GetWallsCount() == 0)
            {
                Blueprint.Instance.RemoveCorner(selectedCorner2);
            }

            SelectedWall         = null;
            selectedCorner1      = null;
            selectedCorner2      = null;
            selectedCorner1Index = -1;
            selectedCorner2Index = -1;
            InputManger.Instance.DisableUI();
        }
Exemplo n.º 8
0
 private void Hold(RaycastHit hit, float2 mousePosition, float3 point)
 {
     if (selectedCorner1 == null)
     {
         //UiDrag1.gameObject.SetActive(true);
         //UiDrag1.position = new float3(mousePosition.xy, 0);
         selectedCorner1 = CreateCorner(point, out selectedCorner1Index);
         Vector3 sPoint = Camera.main.WorldToScreenPoint(selectedCorner1.Position);
         //UiDrag1.position = sPoint;
         InputManger.Instance.MoveUIDrag1(sPoint);
     }
     else if (selectedCorner2 == null)
     {
         //UiDrag2.gameObject.SetActive(true);
         selectedCorner2 = CreateCorner(point, out selectedCorner2Index);
         Vector3 sPoint = Camera.main.WorldToScreenPoint(selectedCorner2.Position);
         InputManger.Instance.MoveUIDrag2(sPoint);
         //UiDrag2.position = sPoint;
         SelectedWall = CreateWall();
         //Options.gameObject.SetActive(true);
         if (Continuous)
         {
             lastCorner = selectedCorner2;
         }
     }
     else
     {
         float d1 = MathHelper.SqrDistance(point, selectedCorner1.Position);
         float d2 = MathHelper.SqrDistance(point, selectedCorner2.Position);
         if (d1 < d2)
         {
             InputManger.Instance.MoveUIDrag1(MoveCorner(point, selectedCorner1, selectedCorner1Index, selectedCorner2, selectedCorner2Index));
         }
         else
         {
             InputManger.Instance.MoveUIDrag2(MoveCorner(point, selectedCorner2, selectedCorner2Index, selectedCorner1, selectedCorner1Index));
         }
         InputManger.Instance.CenterUiOptions();
         //Options.position = (UiDrag1.position + UiDrag2.position) / 2;
     }
 }
Exemplo n.º 9
0
        public void UpdatePosition(float3 point)
        {
            if (Wall != null)
            {
                Wall.RemoveCutout(this);
                Wall.RemovePlaceable(this);
                Wall = null;
                if (Next != null)
                {
                    RemoveNext();
                }
                if (Prev != null)
                {
                    RemovePrev();
                }
            }
            selected = true;
            var    walls       = Blueprint.Walls;
            float  min         = float.MaxValue;
            float  t           = .5f;
            float3 cachedPoint = point;

            Position           = point;
            ClosestPoint       = new float4(cachedPoint, ClosestPoint.w);
            transform.position = Position;
            vaild = false;
            if (!data.FreeFloating)
            {
                for (int i = 0; i < walls.Count; i++)
                {
                    WallLogic wall       = walls[i];
                    float4    closest    = wall.GetClosestPoint(point, out t);
                    float     distance2  = MathHelper.SqrDistance(closest.xyz, point);
                    float     halfWidthT = data.BoundingSize.x / 2 / walls[i].Length;
                    float     startPoint = t - halfWidthT;
                    float     endPoint   = t + halfWidthT;
                    //Debug.Log((distance2 < Placeable.SnapDistance) + " : " + (distance2 < min) + " : " + (0 <= startPoint) + " : " + (endPoint <= 1));
                    if (distance2 < Placeable.SnapDistance && distance2 < min && 0 <= startPoint && endPoint <= 1)
                    {
                        CenterT      = t;
                        vaild        = true;
                        min          = distance2;
                        Wall         = wall;
                        ClosestPoint = closest;
                        float sign = math.sign(closest.w);

                        bool moved = false;
                        for (int j = 0; j < Wall.Cutouts.Count; j++)
                        {
                            var   other     = Wall.Cutouts[j];
                            float otherSign = math.sign(other.ClosestPoint.w);
                            bool  intersect = (!data.Offset || !other.data.Offset) || ((data.Offset && other.data.Offset) && sign == otherSign);
                            bool  overlap   = (other.data.BlockCutsBottom && data.BlockCutsBottom) || (other.data.BlocksCutsTop && data.BlocksCutsTop);
                            //Debug.Log(intersect + " : " + overlap);
                            if (intersect && overlap)
                            {
                                //Debug.Log(StartPoint + " : " + other.EndPoint+":"+(StartPoint <= other.EndPoint) );
                                //Debug.Log(EndPoint + " : " + other.EndPoint + ":" + (EndPoint >= other.EndPoint));
                                //Debug.Log(StartPoint + " : " + other.StartPoint + ":" + (EndPoint >= other.StartPoint));
                                //Debug.Log(EndPoint + " : " + other.StartPoint + ":" + (EndPoint >= other.StartPoint));
                                if (StartPoint <= other.EndPoint && EndPoint >= other.EndPoint)
                                {
                                    if (moved)
                                    {
                                        vaild = false;
                                    }
                                    var snap = other.EndPoint - StartPoint;

                                    t           += snap;
                                    CenterT      = t;
                                    cachedPoint  = math.lerp(Wall.GetStartPosition(), Wall.GetEndPosition(), t);
                                    ClosestPoint = new float4(cachedPoint, ClosestPoint.w);

                                    if (data.Cutout)
                                    {
                                        SetPrev(other);
                                    }
                                }
                                else if (StartPoint <= other.StartPoint && EndPoint >= other.StartPoint)
                                {
                                    if (moved)
                                    {
                                        vaild = false;
                                    }
                                    var snap = other.StartPoint - EndPoint;

                                    t           += snap;
                                    CenterT      = t;
                                    cachedPoint  = math.lerp(Wall.GetStartPosition(), Wall.GetEndPosition(), t);
                                    ClosestPoint = new float4(cachedPoint, ClosestPoint.w);
                                    if (data.Cutout)
                                    {
                                        SetNext(other);
                                    }
                                }
                            }
                        }
                        for (int j = 0; j < Wall.Placeables.Count; j++)
                        {
                            var   other     = Wall.Placeables[j];
                            float otherSign = math.sign(other.ClosestPoint.w);
                            bool  intersect = (!data.Offset || !other.data.Offset) || ((data.Offset && other.data.Offset) && sign == otherSign);
                            bool  overlap   = (other.data.BlockCutsBottom && data.BlockCutsBottom) || (other.data.BlocksCutsTop && data.BlocksCutsTop);
                            // Debug.Log(intersect + " : " + overlap);
                            if (intersect && overlap)
                            {
                                //Debug.Log(StartPoint + " : " + other.EndPoint + ":" + (StartPoint <= other.EndPoint));
                                //Debug.Log(EndPoint + " : " + other.EndPoint + ":" + (EndPoint >= other.EndPoint));
                                //Debug.Log(StartPoint + " : " + other.StartPoint + ":" + (EndPoint >= other.StartPoint));
                                //Debug.Log(EndPoint + " : " + other.StartPoint + ":" + (EndPoint >= other.StartPoint));
                                if (StartPoint <= other.EndPoint && EndPoint >= other.EndPoint)
                                {
                                    if (moved)
                                    {
                                        vaild = false;
                                    }
                                    var snap = other.EndPoint - StartPoint;

                                    t           += snap;
                                    cachedPoint  = math.lerp(Wall.GetStartPosition(), Wall.GetEndPosition(), t);
                                    ClosestPoint = new float4(cachedPoint, ClosestPoint.w);
                                }
                                else if (StartPoint <= other.StartPoint && EndPoint >= other.StartPoint)
                                {
                                    if (moved)
                                    {
                                        vaild = false;
                                    }
                                    var snap = other.StartPoint - EndPoint;

                                    t           += snap;
                                    cachedPoint  = math.lerp(Wall.GetStartPosition(), Wall.GetEndPosition(), t);
                                    ClosestPoint = new float4(cachedPoint, ClosestPoint.w);
                                }
                            }
                        }
                        if (StartPoint < 0 || EndPoint > 1)
                        {
                            vaild = false;
                        }



                        transform.eulerAngles = new Vector3(0, math.abs(closest.w), 0);

                        Position = ClosestPoint.xyz;
                        if (data.Offset)
                        {
                            float offsetT = data.BoundingSize.y / 2 / math.sqrt(distance2);
                            // Debug.Log(offsetT);
                            //Direction = GetPointSide(point);
                            //cachedPoint = math.lerp(Position, point, offsetT);
                            float3 movement = point - closest.xyz;
                            offset    = movement * offsetT;
                            Position += offset;
                        }
                        HalfWidthT         = data.BoundingSize.x / 2 / Wall.Length;
                        Position           = new float3(Position.x, data.ZoffsetinMeters, Position.z);
                        transform.position = Position;
                    }
                    else
                    {
                    }
                }
            }
            else
            {
                vaild = true;
                transform.position = Position;
            }


            UpdateVisuals();
        }
Exemplo n.º 10
0
        private void Tap(RaycastHit hit, float2 mousePosition, float3 point)
        {
            Debug.Log(hit.transform.name);
            if (hit.transform.name == "Wall")
            {
                SelectedWall         = hit.transform.GetComponent <WallLogic>();
                selectedCorner1      = SelectedWall.StartCorner;
                selectedCorner2      = SelectedWall.EndCorner;
                selectedCorner1Index = Blueprint.Corners.IndexOf(selectedCorner1);
                selectedCorner2Index = Blueprint.Corners.IndexOf(selectedCorner2);

                Vector3 sPoint = Camera.main.WorldToScreenPoint(selectedCorner1.Position);
                InputManger.Instance.MoveUIDrag1(sPoint);

                sPoint = Camera.main.WorldToScreenPoint(selectedCorner2.Position);
                InputManger.Instance.MoveUIDrag2(sPoint);
                InputManger.Instance.CenterUiOptions();
                if (Continuous)
                {
                    lastCorner = null;
                }
            }
            else if (SelectedWall != null)
            {
                MergeAndDeselect();
            }
            else if (Continuous && lastCorner != null)
            {
                selectedCorner1 = CreateCorner(lastCorner.Position, out selectedCorner1Index);
                Vector3 sPoint = Camera.main.WorldToScreenPoint(selectedCorner1.Position);
                InputManger.Instance.MoveUIDrag1(sPoint);
                selectedCorner2 = CreateCorner(point, out selectedCorner2Index);
                if (AxisAlign)
                {
                    selectedCorner2.AxisAlignWithOther(selectedCorner1);
                }
                sPoint = Camera.main.WorldToScreenPoint(selectedCorner2.Position);

                InputManger.Instance.MoveUIDrag2(sPoint);
                SelectedWall = CreateWall();
                InputManger.Instance.CenterUiOptions();

                if (Continuous)
                {
                    lastCorner = selectedCorner2;
                }
            }
            else
            {
                if (selectedCorner1 == null)
                {
                    selectedCorner1 = CreateCorner(point, out selectedCorner1Index);
                    Vector3 sPoint = Camera.main.WorldToScreenPoint(selectedCorner1.Position);
                    InputManger.Instance.MoveUIDrag1(sPoint);
                }
                else if (selectedCorner2 == null)
                {
                    selectedCorner2 = CreateCorner(point, out selectedCorner2Index);
                    if (AxisAlign)
                    {
                        selectedCorner2.AxisAlignWithOther(selectedCorner1);
                    }
                    Vector3 sPoint = Camera.main.WorldToScreenPoint(selectedCorner2.Position);

                    InputManger.Instance.MoveUIDrag2(sPoint);
                    SelectedWall = CreateWall();
                    InputManger.Instance.CenterUiOptions();

                    if (Continuous)
                    {
                        lastCorner = selectedCorner2;
                    }
                }
            }
        }