Exemple #1
0
        /// <summary>
        ///     adjust 2d and 3d objects transform according to data
        /// </summary>
        /// <param name="pos3D"></param>
        /// <param name="go"></param>
        /// <param name="startingPos"></param>
        private void AdjustCurrentFurnitureWallPos3D(Vector3 pos3D, GameObject go, Vector3 startingPos)
        {
            if (IsOnWall)
            {
                //GetComponent<Rigidbody>().MovePosition
                associated3DObject.transform.position = new Vector3(
                    pos3D.x,
                    Mathf.Clamp(pos3D.y, 0.1f, 3),
                    pos3D.z
                    );
                associated2DObject.transform.position = VectorFunctions.GetExactPositionFrom3DObject(associated2DObject,
                                                                                                     associated3DObject, associated3DObject.transform.position);
                //VectorFunctions.Switch3D2D(associated3DObject.transform.position);

                var w = WallsCreator.Instance.GetWallFromGameObject(go);

                var perp = w.GetPerpendicularFromPos(pos3D);

                associated3DObject.transform.rotation = Quaternion.FromToRotation(Vector3.forward, perp);

                associated3DObject.transform.localEulerAngles = new Vector3(
                    0,
                    associated3DObject.transform.localEulerAngles.y,
                    EulerAngles.z
                    );

                associated2DObject.transform.localEulerAngles = VectorFunctions.Switch2D3D(new Vector3(
                                                                                               0,
                                                                                               -associated3DObject.transform.localEulerAngles.y,
                                                                                               associated3DObject.transform.localEulerAngles.z
                                                                                               ));

                EulerAngles       = associated3DObject.transform.localEulerAngles;
                AssociatedElement = w;
            }
            else
            {
                if (pos3D.magnitude != float.PositiveInfinity)
                {
                    associated3DObject.transform.position =
                        pos3D; //.GetComponent<Rigidbody>().MovePosition(associated3DObject.transform.position + (pos3D - startingPos));
                }
                associated2DObject.transform.position = this is HelperElement
                    ? VectorFunctions.Switch3D2D(associated3DObject.transform.position)
                    : VectorFunctions.GetExactPositionFrom3DObject(associated2DObject, associated3DObject,
                                                                   associated3DObject.transform.position);
            }
        }
Exemple #2
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();
            }
        }