示例#1
0
 /// <summary>
 ///     Start 3d measure
 /// </summary>
 public void PutFirstPoint3D()
 {
     if (m_goPutFirstPoint3D)
     {
         if (InputFunctions.IsClickingOutsideUI())
         {
             measure3D.gameObject.SetActive(true);
             measure3D.start      = InputFunctions.GetWorldPoint(GlobalManager.Instance.cam3D.GetComponent <Camera>());
             m_goPutSecondPoint3D = true;
         }
     }
 }
示例#2
0
 /// <summary>
 ///     End 3d measure
 /// </summary>
 public void PutSecondPoint3D()
 {
     if (m_goPutSecondPoint3D)
     {
         measure3D.end = InputFunctions.GetWorldPoint(GlobalManager.Instance.cam3D.GetComponent <Camera>());
         if (InputFunctions.IsClickingOutsideUI())
         {
             IsMesuring          = false;
             m_goPutFirstPoint2D = m_goPutFirstPoint3D = m_goPutSecondPoint2D = m_goPutSecondPoint3D = false;
         }
     }
 }
示例#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);
            }
        }
示例#4
0
        // Update is called once per frame
        private void Update()
        {
            // RIGIDBODIES
            foreach (var f in m_furnituresData)
            {
                if (f != m_currentFurniture)
                {
                    //if (f.associated3DObject == null) { return; }
                    var rb = f.associated3DObject.GetComponent <Rigidbody>();

                    // Freeze all except if its current selected furniture
                    if (SelectedObjectManager.Instance.currentFurnitureData.Count == 1 &&
                        SelectedObjectManager.Instance.currentFurnitureData[0] == f)
                    {
                        if (f.IsOnWall)
                        {
                            rb.constraints = RigidbodyConstraints.FreezeRotation;
                            rb.useGravity  = false;
                        }
                        else
                        {
                            if (f.CanBePutOnFurniture)
                            {
                                rb.constraints = RigidbodyConstraints.FreezeRotation;
                            }
                            else
                            {
                                rb.constraints = RigidbodyConstraints.FreezeRotation |
                                                 RigidbodyConstraints.FreezePositionY;
                            }
                        }
                    }
                    else
                    {
                        rb.constraints = RigidbodyConstraints.FreezeAll;
                    }

                    // update 2D position if moving
                    if (f.associated3DObject?.GetComponent <Rigidbody>().velocity.magnitude > 0 && f.associated3DObject.activeSelf) //activeSelf Evite de deplacer l'objet 2D quand la 3d est masquer
                    {
                        f.Position = f.associated3DObject.transform.position;
                        f.associated2DObject.transform.position =
                            VectorFunctions.GetExactPositionFrom3DObject(f.associated2DObject, f.associated3DObject,
                                                                         f.Position);
                        //VectorFunctions.Switch3D2D(f.Position);
                        rb.velocity *= 0.5f;
                    }

                    f.text2D.transform.position = f.associated2DObject.transform.position;
                }
            }

            // In creation -> check view then position it
            if (m_currentFurniture != null)
            {
                m_currentFurniture.Move(InputFunctions.GetWorldPoint(GlobalManager.Instance.GetActiveCamera()));
            }
            // Validate
            if (Input.GetMouseButtonDown(0) && m_currentFurniture != null)
            {
                m_currentFurniture.Position = m_currentFurniture3D.transform.position;
                m_currentFurniture          = null;

                if (m_currentFurniScript)
                {
                    Destroy(m_currentFurniScript.gameObject);
                    m_currentFurniScript = null;
                }

                //m_currentFurniture3D.GetComponent<MeshCollider>().enabled = true;
            }

            // in creation -> rotation
            //if (Input.GetMouseButtonDown(1)) { //m_currentFurniture.Rotation = Vector3.Angle(m_currentFurniture.Position,Input.mousePosition); };

            if (Input.GetButtonDown("Cancel"))
            {
                CancelFurniture();
            }
        }