Пример #1
0
        /// <summary>
        ///     Move the opening along the wall, according to mouse.
        /// </summary>
        /// <param name="offset">The starting position when the users clicks</param>
        public override void Move(Vector3 offset)
        {
            Camera cam = GlobalManager.Instance.GetActiveCamera();

            switch (cam.gameObject.layer)
            {
            case (int)ErgoLayers.Top:

                Vector3       pos2D   = InputFunctions.GetWorldPoint2D(cam);
                Room          r       = SelectedObjectManager.Instance.currentRoomData;
                System.Single roomMod = r == null ? 1f : r.LockAngles ? 1f / 4f : 1f / 2f;
                SetPosition(VectorFunctions.Switch3D2D(Position) + (pos2D - offset) * roomMod);

                break;

            case (int)ErgoLayers.ThreeD:

                Vector3 pos3D = InputFunctions.GetWorldPoint3D(cam, false);
                Room    room  = SelectedObjectManager.Instance.currentRoomData;
                //System.Single roomModif = room == null ? 1f : room.LockAngles ? 1f / 4f : 1f / 2f;
                SetPosition(VectorFunctions.Switch3D2D(offset));

                //Debug.Log(pos3D+"   "+ VectorFunctions.Switch3D2D(offset) +"     Result = "+ (pos3D - offset) * 1 + "    final = " + VectorFunctions.Switch2D3D(Position) + (pos3D - offset) * 1);

                break;
            }
        }
Пример #2
0
        /// <summary>
        ///     Create a new text zone. Its a comment zone shown in both views.
        /// </summary>
        private void CreateTextZone()
        {
            if (m_isCreating)
            {
                if (!m_isDragging)
                {
                    if (InputFunctions.IsClickingOutsideUI())
                    {
                        m_startPoint   = InputFunctions.GetWorldPoint2D(GlobalManager.Instance.GetActiveCamera());
                        m_endPoint     = InputFunctions.GetWorldPoint2D(GlobalManager.Instance.GetActiveCamera());
                        m_isDragging   = true;
                        currentElement = new TextZoneElement
                        {
                            Text            = "Commentaire",
                            BackgroundColor = Color.gray,
                            TextColor       = Color.black,
                            TextSize        = 1
                        };
                        currentElement.associated2DObject = Instantiate(textZonePrefab);
                        currentElement.associated3DObject = Instantiate(textZonePrefab);

                        currentElement.associated2DObject.GetComponentInChildren <TextMesh>().fontStyle = FontStyle.Bold;
                        currentElement.associated3DObject.GetComponentInChildren <TextMesh>().fontStyle = FontStyle.Bold;

                        currentElement.associated2DObject.SetLayerRecursively((int)ErgoLayers.Top);
                        currentElement.associated3DObject.SetLayerRecursively((int)ErgoLayers.ThreeD);
                    }
                }
                else
                {
                    m_endPoint = InputFunctions.GetWorldPoint2D(GlobalManager.Instance.GetActiveCamera());

                    if (InputFunctions.IsClickingOutsideUI())
                    {
                        m_isCreating = false;
                        m_isDragging = false;
                        m_helpers.Add(currentElement);
                        OperationsBufferScript.Instance.AddAutoSave("Creation zone de texte");
                    }

                    currentElement.associated2DObject.transform.position = (m_startPoint + m_endPoint) / 2f;
                    currentElement.Position = VectorFunctions.Switch2D3D((m_startPoint + m_endPoint) / 2f);
                    currentElement.associated3DObject.transform.position = currentElement.Position;

                    (currentElement as TextZoneElement).Size = VectorFunctions.Switch2D3D(currentElement
                                                                                          .associated2DObject.GetComponent <TextZoneScript>().SetSize(m_startPoint, m_endPoint));
                    currentElement.associated3DObject.GetComponent <TextZoneScript>().SetSize(m_startPoint, m_endPoint);

                    // CANCEL
                    if (Input.GetMouseButtonDown(1))
                    {
                        m_isCreating = false;
                        m_isDragging = false;
                        Destroy(currentElement.associated2DObject);
                        currentElement = null;
                    }
                }
            }
        }
Пример #3
0
        private void ClickArrow()
        {
            // Press on arrow = select arrow
            if (Input.GetMouseButtonDown(0))
            {
                var go = InputFunctions.GetHoveredObject2D(GlobalManager.Instance.GetActiveCamera());
                if (!go || go.tag != "WallArrow")
                {
                    isMoving = false;
                    return;
                }

                currentArrow = go;
            }

            // Release = no arrow
            if (Input.GetMouseButtonUp(0))
            {
                currentArrow = null;
            }

            // if arrow
            if (currentArrow)
            {
                var proj     = Vector3.zero;
                var mousePos = InputFunctions.GetWorldPoint2D(GlobalManager.Instance.GetActiveCamera());
                var d        = 0f;
                switch (currentArrow.name)
                {
                case "P1o":
                    proj    = Vector3.Project(mousePos - wo.Position, wo.Wall.Direction) + wo.Position;
                    d       = Vector3.Distance(proj, wo.Position);
                    wo.Size = new Vector3(d, wo.Size.y, wo.Size.z);
                    wo.SetPosition(wo.Position - d * wo.Wall.Direction);
                    WallsCreator.Instance.AdjustAllWalls();
                    WallOpeningPropScript.Instance.UpdateWallOpeningProperties();

                    break;

                case "P2o":
                    proj    = Vector3.Project(mousePos - wo.Position, -wo.Wall.Direction) + wo.Position;
                    d       = Vector3.Distance(proj, wo.Position);
                    wo.Size = new Vector3(d, wo.Size.y, wo.Size.z);
                    wo.SetPosition(wo.Position + d * wo.Wall.Direction);
                    WallsCreator.Instance.AdjustAllWalls();
                    WallOpeningPropScript.Instance.UpdateWallOpeningProperties();

                    break;
                }

                currentArrow.transform.position = proj + m_decal;
                isMoving = true;
            }
            else
            {
                isMoving = false;
            }
        }
Пример #4
0
 /// <summary>
 ///     End 2D measure
 /// </summary>
 public void PutSecondPoint2D()
 {
     if (m_goPutSecondPoint2D)
     {
         measure2D.end = InputFunctions.GetWorldPoint2D(GlobalManager.Instance.cam2DTop.GetComponent <Camera>());
         if (InputFunctions.IsClickingOutsideUI())
         {
             IsMesuring          = false;
             m_goPutFirstPoint2D = m_goPutFirstPoint3D = m_goPutSecondPoint2D = m_goPutSecondPoint3D = false;
         }
     }
 }
Пример #5
0
 /// <summary>
 ///     Start 2D measure
 /// </summary>
 public void PutFirstPoint2D()
 {
     if (m_goPutFirstPoint2D)
     {
         if (InputFunctions.IsClickingOutsideUI())
         {
             measure2D.gameObject.SetActive(true);
             measure2D.start =
                 InputFunctions.GetWorldPoint2D(GlobalManager.Instance.cam2DTop.GetComponent <Camera>());
             m_goPutSecondPoint2D = true;
         }
     }
 }
Пример #6
0
        private void ClickArrow()
        {
            // Press on arrow = select arrow
            if (Input.GetMouseButtonDown(0))
            {
                var go = InputFunctions.GetHoveredObject2D(GlobalManager.Instance.GetActiveCamera());
                if (!go || go.tag != "WallArrow")
                {
                    isMoving = false;
                    return;
                }

                currentArrow = go;
            }

            // Release = no arrow
            if (Input.GetMouseButtonUp(0) && currentArrow != null)
            {
                OperationsBufferScript.Instance.AddAutoSave("Mise à jour mur");
                currentArrow = null;
            }

            // if arrow
            if (currentArrow)
            {
                var proj     = Vector3.zero;
                var mousePos = InputFunctions.GetWorldPoint2D(GlobalManager.Instance.GetActiveCamera());
                if (m_prevPos == mousePos)
                {
                    return;
                }
                switch (currentArrow.name)
                {
                case "P1":
                    if (Input.GetAxis("LibrePoint") > 0)
                    {
                        WallsCreator.Instance.UpdateWallPoint(w, mousePos + w.Direction * m_arrowOffset, true);
                    }
                    else
                    {
                        proj = (Vector3.Project(mousePos - w.P1, w.Direction) + w.P1);
                        WallsCreator.Instance.UpdateWallPoint(w, proj + w.Direction * m_arrowOffset, true);
                    }
                    break;

                case "P2":
                    if (Input.GetAxis("LibrePoint") > 0)
                    {
                        WallsCreator.Instance.UpdateWallPoint(w, mousePos - w.Direction * m_arrowOffset, false);
                    }
                    else
                    {
                        proj = Vector3.Project(mousePos - w.P2, -w.Direction) + w.P2;
                        WallsCreator.Instance.UpdateWallPoint(w, proj - w.Direction * m_arrowOffset, false);
                    }
                    break;

                case "UpPerp":
                    proj        = Vector3.Project(mousePos - w.Center, -w.Perpendicular) + w.Center;
                    w.Thickness = Vector3.Distance(proj, w.Center) * 2f;
                    WallsCreator.Instance.AdjustAllWalls();
                    WallPropPanelScript.Instance.UpdateWallProperties();
                    break;

                case "DownPerp":
                    proj        = Vector3.Project(mousePos - w.Center, w.Perpendicular) + w.Center;
                    w.Thickness = Vector3.Distance(proj, w.Center) * 2f;
                    WallsCreator.Instance.AdjustAllWalls();
                    WallPropPanelScript.Instance.UpdateWallProperties();
                    break;
                }

                currentArrow.transform.position = proj + m_decal;
                isMoving  = true;
                m_prevPos = mousePos;
            }
            else
            {
                isMoving = false;
            }
        }
Пример #7
0
        /// <summary>
        ///     Main method, called when the users stars dragging one of the buttons
        /// </summary>
        private void ClickArrow()
        {
            var me = SelectedObjectManager.Instance.currentSelectedElements.First() as MovableElement;

            // Press on arrow = select arrow
            if (InputFunctions.IsClickingOutsideUI())
            {
                var go = InputFunctions.GetHoveredObject2D(GlobalManager.Instance.GetActiveCamera());
                // Debug.Log("CLICK ARROW " + go);
                if (!go || go.tag != "ElementArrow")
                {
                    isMoving = false;
                    return;
                }

                currentArrow = go;
            }

            // Release = no arrow
            if (Input.GetMouseButtonUp(0) && currentArrow != null)
            {
                currentArrow = null;
                OperationsBufferScript.Instance.AddAutoSave("Etirement");
            }

            // if arrow
            if (currentArrow)
            {
                var   proj      = Vector3.zero;
                var   dif       = Vector3.zero;
                var   sizeCompo = Vector3.zero;
                float dist      = 0;
                var   direction = Vector3.zero;
                var   mousePos  = InputFunctions.GetWorldPoint2D(GlobalManager.Instance.GetActiveCamera());
                if (m_prevPos == mousePos)
                {
                    return;
                }
                //Debug.Log("FLECHE " + currentArrow.name);
                switch (currentArrow.name)
                {
                case "Up":
                    direction = me.associated2DObject.transform.up;
                    proj      = Vector3.Project(mousePos - oUp, direction) + oUp;
                    dif       = proj - oUp;
                    dist      = Vector3.Distance(proj, oUp);
                    sizeCompo = Vector3.up;
                    break;

                case "Down":
                    direction = -me.associated2DObject.transform.up;
                    proj      = Vector3.Project(mousePos - oDown, direction) + oDown;
                    dif       = proj - oDown;
                    dist      = Vector3.Distance(proj, oDown);
                    sizeCompo = Vector3.up;
                    break;

                case "Left":
                    direction = -me.associated2DObject.transform.right;
                    proj      = Vector3.Project(mousePos - oLeft, direction) + oLeft;
                    dif       = proj - oLeft;
                    dist      = Vector3.Distance(proj, oLeft);
                    sizeCompo = Vector3.right;
                    break;

                case "Right":
                    direction = me.associated2DObject.transform.right;
                    proj      = Vector3.Project(mousePos - oRight, direction) + oRight;
                    dif       = proj - oRight;
                    dist      = Vector3.Distance(proj, oRight);
                    sizeCompo = Vector3.right;
                    break;

                case "UpLeft":
                    direction = -me.associated2DObject.transform.right + me.associated2DObject.transform.up;
                    proj      = Vector3.Project(mousePos - oUpLeft, direction) + oUpLeft;
                    dif       = proj - oUpLeft;
                    dist      = Vector3.Distance(proj, oUpLeft);
                    sizeCompo = Vector3.up + Vector3.right;
                    break;

                case "UpRight":
                    direction = me.associated2DObject.transform.right + me.associated2DObject.transform.up;
                    proj      = Vector3.Project(mousePos - oUpRight, direction) + oUpRight;
                    dif       = proj - oUpRight;
                    dist      = Vector3.Distance(proj, oUpRight);
                    sizeCompo = Vector3.up + Vector3.right;
                    break;

                case "DownLeft":
                    direction = -me.associated2DObject.transform.right - me.associated2DObject.transform.up;
                    proj      = Vector3.Project(mousePos - oDownLeft, direction) + oDownLeft;
                    dif       = proj - oDownLeft;
                    dist      = Vector3.Distance(proj, oDownLeft);
                    sizeCompo = Vector3.up + Vector3.right;
                    break;

                case "DownRight":
                    direction = me.associated2DObject.transform.right - me.associated2DObject.transform.up;
                    proj      = Vector3.Project(mousePos - oDownRight, direction) + oDownRight;
                    dif       = proj - oDownRight;
                    dist      = Vector3.Distance(proj, oDownRight);
                    sizeCompo = Vector3.up + Vector3.right;
                    break;
                }

                SetSizeCompoAndDirection(dif, direction, sizeCompo, out direction, out sizeCompo);
                me.SetPosition(me.Position + VectorFunctions.Switch2D3D(dist * direction / 4f));
                me.SetSize(me.Size + VectorFunctions.Switch2D3D(dist * sizeCompo / 2f));
                if (me is Furniture)
                {
                    (me as Furniture).AdjustSpriteSize();
                }
                currentArrow.transform.position =
                    new Vector3(proj.x, proj.y, me.associated2DObject.transform.position.z);
                isMoving  = true;
                m_prevPos = proj;
                FurniturePropScript.Instance.UpdateFurnitureProperties();
            }
            else
            {
                isMoving = false;
            }
        }