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;
            }
        }
Example #2
0
        // Update is called once per frame
        private void Update()
        {
            if (Input.GetKeyDown(KeyCode.F1) && InputFunctions.IsMouseOutsideUI())
            {
                SwitchViewMode();
            }

            grid.SetActive(SettingsManager.Instance.SoftwareParameters.ShowGrid);

            var go             = InputFunctions.GetHoveredObject2D(cam2DTop.GetComponent <Camera>());
            var isElementArrow = false;

            if (go && go.tag.Contains("Arrow"))
            {
                isElementArrow = true;
            }

            // CURSOR
            UpdateCursor(isElementArrow);

            // Camera render texture

            if (m_mode == ViewMode.Top)
            {
                //if (!cam3D.GetComponent<Camera>().orthographic)
                //{
                //    cam3D.GetComponent<Camera3DMove>().SetTopView();
                //}

                ///<summary>
                ///suivre la cam 2D
                /// </summary>

                //cam3D.transform.localEulerAngles = Vector3.right * 90f;
                //cam3D.GetComponent<Camera3DMove>().SetPosition(VectorFunctions.Switch2D3D(
                //cam2DTop.transform.position + Vector3.right * 2.5f, cam2DTop.transform.position.z * -1f));
            }
            else if (m_mode == ViewMode.ThreeD)
            {
                if (cam3D.GetComponent <Camera>().orthographic)
                {
                    cam3D.GetComponent <Camera3DMove>().SetNormalView();
                }
                // cam2DTop.GetComponent<Camera2DMove>().SetPosition(cam3D.transform.position + Vector3.right * 2.5f);
            }

            // UI Bindings
            //UI.faceButton.interactable = som.currentWallsData.Count == 1;
        }
Example #3
0
        /// <summary>
        ///     Move function. The starting pos is where the users starts clicking,
        ///     so its a kind of offset so the element does not "teleport" its position into mouse but moves smoothly
        /// </summary>
        /// <param name="startingPos">where the users starts clicking</param>
        public virtual void Move(Vector3 startingPos)
        {
            InitVar();

            List <string> tags = new List <string> {
                ""
            };

            if (IsOnWall)
            {
                tags.Add("Wall");
            }
            else
            {
                tags.Add("Ground");
            }
            if (CanBePutOnFurniture)
            {
                tags.Add("Furniture");
            }
            tags.Add("WorkPlane");

            switch (cam.gameObject.layer)
            {
            case (int)ErgoLayers.Top:
                Vector3 pos2D       = InputFunctions.GetWorldPoint(cam);
                Vector3 closestProj = pos2D;

                // If on wall then stick to wall
                if (IsOnWall)
                {
                    //Debug.Log("Sticking...");
                    Wall closestWall = null;
                    // Seek closest projection for a wall
                    foreach (Wall wd in WallsCreator.Instance.GetWalls())
                    {
                        if (closestWall == null)
                        {
                            closestWall = wd;
                            closestProj = Math3d.ProjectPointOnLineSegment(wd.P1, wd.P2, pos2D);
                        }
                        else
                        {
                            Vector3 proj = Math3d.ProjectPointOnLineSegment(wd.P1, wd.P2, pos2D);
                            if (Vector2.Distance(pos2D, proj) < Vector2.Distance(pos2D, closestProj))
                            {
                                closestWall = wd;
                                closestProj = proj;
                            }
                        }
                    }

                    AssociatedElement = closestWall;
                    Vector3 pos33D = VectorFunctions.Switch2D3D(closestProj - closestWall.Thickness * (closestProj - pos2D).normalized) + Position.y * Vector3.up;
                    // Repeat the 3D algo and readapt 2D
                    AdjustCurrentFurnitureWallPos3D(pos33D, closestWall.associated3DObject, startingPos);
                }
                else
                {
                    associated2DObject.transform.position += pos2D - startingPos;

                    if (associated3DObject)
                    {
                        float y = 0;
                        if (CanBePutOnFurniture)
                        {
                            GameObject potentialFurniture = InputFunctions.GetHoveredObject2D
                                                            (
                                cam2d,
                                associated2DObject.name,
                                true
                                                            );

                            if (potentialFurniture)
                            {
                                Furniture f = FurnitureCreator.Instance.GetFurnitureFromGameObject(potentialFurniture);
                                if (f != null)
                                {
                                    y = f.Position.y + f.Size.y;
                                }
                            }
                        }

                        associated2DObject.transform.position = new Vector3
                                                                (
                            associated2DObject.transform.position.x,
                            associated2DObject.transform.position.y, -y / 5f
                                                                );

                        associated3DObject.transform.position = VectorFunctions.Switch2D3D(associated2DObject.transform.position, y);
                    }
                }

                if (text2D)
                {
                    text2D.transform.position = associated2DObject.transform.position;
                }
                break;

            case (int)ErgoLayers.ThreeD:
                Vector3    pos3D         = InputFunctions.GetWorldPoint(cam);
                Vector3    closestProj3D = pos3D;
                GameObject go;

                if (IsOnWall)
                {
                    Vector3 pos33D = InputFunctions.GetWorldPoint(out go, cam, associated3DObject, tags.ToArray());
                    AdjustCurrentFurnitureWallPos3D(pos33D, go, startingPos);
                }
                else
                {
                    if (associated3DObject == null)
                    {
                        return;
                    }

                    //Fix a l'etage l'objet
                    float tmpY = associated3DObject.transform.position.y;
                    associated3DObject.transform.position += pos3D - startingPos;

                    if (associated3DObject)
                    {
                        float y = 0;
                        if (CanBePutOnFurniture)
                        {
                            var potentialFurniture = InputFunctions.GetHoveredObject2D(
                                GlobalManager.Instance.cam2DTop.GetComponent <Camera>(), associated2DObject.name,
                                true);
                            if (potentialFurniture)
                            {
                                var f = FurnitureCreator.Instance.GetFurnitureFromGameObject(potentialFurniture);
                                y = f.Position.y + f.Size.y;
                            }
                        }

                        associated3DObject.transform.position = associated3DObject.transform.position;

                        associated3DObject.transform.position = new Vector3(associated3DObject.transform.position.x, tmpY, associated3DObject.transform.position.z);

                        associated2DObject.transform.position = new Vector3(associated3DObject.transform.position.x, associated3DObject.transform.position.z, associated2DObject.transform.position.z);
                    }
                }
                break;
            }

            if (associated3DObject)
            {
                Position = associated3DObject.transform.position;
            }
            else
            {
                Position = VectorFunctions.Switch2D3D(associated2DObject.transform.position);
            }
        }
Example #4
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;
            }
        }
Example #5
0
        // Update is called once per frame
        private void Update()
        {
            /////////////////


            cotationTM.color = Color.black;

            if (myElement == null && !isUp && !isDown && !isLeft && !isRight && !isMeasure)
            {
                Destroy(gameObject);
            }

            if (!cotationField)
            {
                foreach (var inf in FindObjectsOfType <InputField>())
                {
                    // ceinture bretelles
                    if (inf.name == "CotationField" || inf.tag == "Cotation")
                    {
                        cotationField = inf;
                    }
                }
            }

            if (!is3D)
            {
                start.z = -0.05f;
                end.z   = -0.05f;
            }

            var show = Length > 0.005 && Length != float.PositiveInfinity && !IsExterior;

            /*start != Vector3.positiveInfinity && end != Vector3.positiveInfinity && */

            arrow1.gameObject.SetActive(show);
            arrow2.gameObject.SetActive(show);
            middle1.gameObject.SetActive(show);
            middle2.gameObject.SetActive(show);
            cotationTM.gameObject.SetActive(show);
            if (!show)
            {
                return;
            }


            var approxDist = Mathf.Floor(Vector3.Distance(start, end) * 100f);
            var offset     = approxDist > 999 ? 0.4f : 0.3f;

            var dir = (end - start).normalized;

            transform.position = (start + end) / 2f;

            transform.rotation = Quaternion.FromToRotation(Vector3.up, dir);

            arrow1.position = start;
            arrow2.position = end;

            var mid     = (arrow1.position + arrow2.position) / 2f;
            var dist    = Vector3.Distance(arrow1.position, arrow2.position);
            var midSize = new Vector2(0.025f, dist / 2f - offset);

            middle1.transform.position = (arrow1.position + mid) / 2f - dir * offset / 4f;
            middle1.size = midSize;

            middle2.transform.position = (arrow2.position + mid) / 2f + dir * offset / 4f;
            middle2.size = midSize;

            cotationTM.transform.position = mid + textOffset + Perp * decalTextOffset;

            if (!is3D)
            {
                cotationTM.transform.localEulerAngles = -transform.localEulerAngles;
            }

            //cotationTM.characterSize = 0.4f;
            cotationTM.text = approxDist + "";

            if (!isMeasure)
            {
                if (is3D)
                {
                    cotationTM.GetComponent <BoxCollider>().size =
                        new Vector3(Mathf.Clamp(Mathf.Log10(approxDist) * 0.13f, 0f, 2f), 0.18f, 0.1f);
                }
                //cotationTM.transform.Translate(cotationTM.)
                else
                {
                    cotationTM.GetComponent <BoxCollider2D>().size =
                        new Vector2(Mathf.Clamp(Mathf.Log10(approxDist) * 0.1f, 0f, 2f), 0.18f);
                }
            }

            // Scale in function of cam Z in 2D
            if (!is3D)
            {
                cotationTM.transform.localScale =
                    Vector3.one * Mathf.Abs(GlobalManager.Instance.cam2DTop.transform.position.z / 10f);
            }

            // Show cotations ? (from room params)
            if (myElement is Wall)
            {
                var r = WallFunctions.GetRoomsFromWall(myElement as Wall, WallsCreator.Instance.GetRooms());
                if (r.Count > 0)
                {
                    for (var i = 0; i < transform.childCount; i++)
                    {
                        transform.GetChild(i).gameObject
                        .SetActive(transform.GetChild(i).gameObject.activeInHierarchy&& r[0].ShowCotations);
                    }
                }
            }

            // Live Update
            if (Input.GetMouseButtonDown(0))
            {
                GameObject go;
                if (is3D)
                {
                    go = InputFunctions.GetHoveredObject(GlobalManager.Instance.cam3D.GetComponent <Camera>());
                }
                else
                {
                    go = InputFunctions.GetHoveredObject2D(GlobalManager.Instance.cam2DTop.GetComponent <Camera>());
                }
                if (go)
                {
                    if (go == cotationTM.gameObject)
                    {
                        SelectedObjectManager.Instance.SetCurrentCotation(this);
                    }
                }
            }

            // Rotation measure
            if (isMeasure)
            {
                Transform camTrans = GlobalManager.Instance.GetActiveCamera().transform;

                List <Transform> transformList = new List <Transform> {
                    middle1.transform, middle2.transform
                };
                foreach (var _transform in transformList)
                {
                    _transform.LookAt(camTrans);
                    _transform.localEulerAngles = new Vector3(0, _transform.localEulerAngles.y, 180);
                }
            }
        }
Example #6
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;
            }
        }