Exemple #1
0
        public Vector3 GetCenter()
        {
            if (Walls.Count == 0)
            {
                return(VectorFunctions.Switch3D2D(Position));
            }
            var positions = new List <Vector3>();

            foreach (var w in Walls)
            {
                if (!positions.Contains(w.P1))
                {
                    positions.Add(w.P1);
                }
                if (!positions.Contains(w.P2))
                {
                    positions.Add(w.P2);
                }
            }

            var center = Vector3.zero;

            foreach (var p in positions)
            {
                center = center + p;
            }
            return(new Vector3(center.x / positions.Count, center.y / positions.Count, center.z / positions.Count));
        }
Exemple #2
0
        private void Update()
        {
            // RIGIDBODIES
            foreach (var s in m_stairs)
            {
                var rb = s.associated3DObject.GetComponent <Rigidbody>();
                // Freeze all except if its current selected furniture
                if (SelectedObjectManager.Instance.currentStairs.Contains(s))
                {
                    if (s.IsOnWall)
                    {
                        rb.constraints = RigidbodyConstraints.FreezeRotation;
                        rb.useGravity  = false;
                    }
                    else
                    {
                        rb.constraints = RigidbodyConstraints.FreezeRotation | RigidbodyConstraints.FreezePositionY;
                    }
                }
                else
                {
                    rb.constraints = RigidbodyConstraints.FreezeAll;
                }

                // update 2D position if moving
                if (s.associated3DObject?.GetComponent <Rigidbody>().velocity.magnitude > 0)
                {
                    s.Position = s.associated3DObject.transform.position;
                    s.associated2DObject.transform.position =
                        VectorFunctions
                        .Switch3D2D(s.Position);     // + s.Depth / 2f * s.associated3DObject.transform.forward);
                    rb.velocity *= 0.5f;
                }
            }
        }
Exemple #3
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;
            }
        }
Exemple #4
0
        /// <summary>
        ///     Rebuild 2D and 3D objects from data
        /// </summary>
        public override void RebuildSceneData()
        {
            CharactersCreator.Instance.DestroyGameObject(associated2DObject);
            CharactersCreator.Instance.DestroyGameObject(associated3DObject);
            associated2DObject = CharactersCreator.Instance.CreateCharacter2D(Type, SpreadArms);
            associated3DObject = CharactersCreator.Instance.CreateCharacter3D(Type, SpreadArms);
            associated2DObject.transform.position         = VectorFunctions.Switch3D2D(Position);
            associated3DObject.transform.position         = Position;
            associated2DObject.transform.localEulerAngles = Vector3.forward * Rotation * -1f;
            associated3DObject.transform.localEulerAngles = Vector3.up * Rotation;

            //if(Type == CharacterType.WheelChairEmpty)
            //{
            //    associated3DObject.transform.localEulerAngles -= Vector3.right * 90;
            //}

            associated2DObject.tag = "Character";
            associated3DObject.tag = "Character";
            associated2DObject.gameObject.SetLayerRecursively((int)ErgoLayers.Top);
            associated3DObject.gameObject.SetLayerRecursively((int)ErgoLayers.ThreeD);

            var s  = Size;
            var ms = MeshSize;

            associated2DObject.transform.localScale = VectorFunctions.Switch3D2D(
                new Vector3(s.x / ms.x, s.y / ms.y, s.z / ms.z));
            associated3DObject.transform.localScale =
                new Vector3(s.x / ms.x, s.y / ms.y, s.z / ms.z);
        }
Exemple #5
0
 /// <summary>
 ///     Update position from wanted one
 /// </summary>
 /// <param name="newPosition"></param>
 public virtual void SetPosition(Vector3 newPosition)
 {
     Position = newPosition;
     associated2DObject.transform.position = VectorFunctions.Switch3D2D(newPosition);
     if (associated3DObject)
     {
         associated3DObject.transform.position = newPosition;
     }
 }
Exemple #6
0
        /// <summary>
        ///     Set element size, updates 2d and 3d objects
        /// </summary>
        /// <param name="newSize">Wanted size</param>
        public virtual void SetSize(Vector3 newSize)
        {
            Size = newSize;
            var s     = Size;
            var ms    = MeshSize;
            var sOnMs = new Vector3(s.x / ms.x, s.y / ms.y, s.z / ms.z);

            associated3DObject.transform.localScale = sOnMs;
            associated2DObject.transform.localScale = VectorFunctions.Switch3D2D(sOnMs);
        }
Exemple #7
0
        /// <summary>
        ///     Adapt sprite scaling according to mesh size and user's wanted size
        /// </summary>
        private void SetFurni2DSize()
        {
            var s     = m_currentFurniture.Size;
            var ms    = m_currentFurniture.MeshSize;
            var sOnMs = new Vector3(s.x / ms.x, s.y / ms.y, s.z / ms.z);

            m_currentFurniture.associated2DObject.transform.localScale =
                VectorFunctions.Switch3D2D(sOnMs);
            m_currentFurniture.AdjustSpriteSize();
        }
Exemple #8
0
 /// <summary>
 ///     Set element size, updates 2d and 3d objects
 /// </summary>
 /// <param name="newSize">Wanted size</param>
 public override void SetSize(Vector3 newSize)
 {
     Size = new Vector3
     {
         x = Mathf.Abs(Size.x),
         y = Mathf.Abs(Size.y),
         z = Mathf.Abs(Size.z)
     };
     Size = newSize;
     associated2DObject.GetComponent <TextZoneScript>().bg.size = VectorFunctions.Switch3D2D(Size);
     associated3DObject.GetComponent <TextZoneScript>().bg.size = VectorFunctions.Switch3D2D(Size);
 }
Exemple #9
0
        /// <summary>
        ///     Get perpendicular to adjust furniture on the wall
        /// </summary>
        public Vector3 GetPerpendicularFromPos(Vector3 pos)
        {
            var pos2D = VectorFunctions.Switch3D2D(pos);

            if (Vector3.Dot(Center - pos2D, Perpendicular) < 0)
            {
                //Debug.Log("Perpendicular");
                return(VectorFunctions.Switch2D3D(Perpendicular));
            }

            //Debug.Log("Pas Perpendicular");
            return(VectorFunctions.Switch2D3D(-Perpendicular));
        }
Exemple #10
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 #11
0
        /// <summary>
        ///     Check if a position is between our selection rectangle bounds
        /// </summary>
        /// <param name="position"></param>
        /// <returns></returns>
        public bool IsWithinSelectionBounds(Vector3 position)
        {
            if (!IsSelecting)
            {
                return(false);
            }

            var camera = GlobalManager.Instance.GetActiveCamera();

            if (camera == GlobalManager.Instance.cam2DTop.GetComponent <Camera>())
            {
                position = VectorFunctions.Switch3D2D(position);
            }

            var viewportBounds =
                GetViewportBounds(camera, firstPosition, Input.mousePosition);

            return(viewportBounds.Contains(
                       camera.WorldToViewportPoint(position)));
        }
Exemple #12
0
        /// <summary>
        ///     Build text zone from data
        /// </summary>
        /// <param name="tz">TextZoneElement</param>
        public void RebuildTextZone(TextZoneElement tz)
        {
            Destroy(tz.associated2DObject);
            Destroy(tz.associated3DObject);
            tz.associated2DObject = Instantiate(textZonePrefab);
            tz.associated2DObject.SetLayerRecursively((int)ErgoLayers.Top);
            tz.associated2DObject.transform.position = VectorFunctions.Switch3D2D(tz.Position);
            tz.associated2DObject.GetComponent <TextZoneScript>().SetSize(VectorFunctions.Switch3D2D(tz.Size));
            tz.associated2DObject.GetComponent <TextZoneScript>().bg.color = tz.BackgroundColor;
            tz.associated2DObject.GetComponent <TextZoneScript>().tm.color = tz.TextColor;
            tz.associated2DObject.GetComponent <TextZoneScript>().tm.text  = tz.Text;
            tz.associated2DObject.GetComponent <TextZoneScript>().textSize = tz.TextSize;

            tz.associated3DObject = Instantiate(textZonePrefab);
            tz.associated3DObject.SetLayerRecursively((int)ErgoLayers.ThreeD);
            tz.associated3DObject.transform.position = tz.Position;
            tz.associated3DObject.GetComponent <TextZoneScript>().SetSize(VectorFunctions.Switch3D2D(tz.Size));
            tz.associated3DObject.GetComponent <TextZoneScript>().bg.color = tz.BackgroundColor;
            tz.associated3DObject.GetComponent <TextZoneScript>().tm.color = tz.TextColor;
            tz.associated3DObject.GetComponent <TextZoneScript>().tm.text  = tz.Text;
            tz.associated3DObject.GetComponent <TextZoneScript>().textSize = tz.TextSize;
        }
Exemple #13
0
        // Unity scene data
        /// <summary>
        ///     Rebuild 2D and 3D objects from data
        /// </summary>
        public override void RebuildSceneData()
        {
            EulerAngles = new Vector3(0, Rotation, 0);
            StairsCreator.Instance.DestroyPreviousStairs(associated3DObject);
            StairsCreator.Instance.DestroyPreviousStairs(associated2DObject);
            if (Curvature > 0)
            {
                associated3DObject = StairsCreator.Instance.GenerateCurvedStairs(
                    InnerRadius, Curvature, NbSteps, Width, Height, BuildSides, ToTheLeft
                    );
            }
            else
            {
                associated3DObject = StairsCreator.Instance.GenerateStairs(NbSteps, Width, Height, Depth, BuildSides);
            }

            associated3DObject.transform.position         = Position;
            associated3DObject.transform.localEulerAngles = EulerAngles;
            associated3DObject.tag   = "Stairs";
            associated3DObject.layer = (int)ErgoLayers.ThreeD;
            associated3DObject.AddComponent <MeshCollider>().convex = true;

            var rb = associated3DObject.AddComponent <Rigidbody>();

            rb.constraints = RigidbodyConstraints.FreezePositionY | RigidbodyConstraints.FreezeRotationX |
                             RigidbodyConstraints.FreezeRotationY | RigidbodyConstraints.FreezeRotationZ;
            rb.useGravity = true;


            associated2DObject = StairsCreator.Instance.Generate2DStairs(this);


            associated2DObject.transform.position =
                VectorFunctions.Switch3D2D(Position + Depth / 2f * associated2DObject.transform.forward);
            associated2DObject.transform.localEulerAngles = new Vector3(0, 0, -Rotation);
            associated2DObject.name = "Stairs2D";
            associated2DObject.tag  = "Stairs";
            associated2DObject.SetLayerRecursively((int)ErgoLayers.Top);
        }
Exemple #14
0
        /// <summary>
        ///     Force a furniture to rebuild gameobjects (scene data) and adjust the transforms
        /// </summary>
        /// <param name="f">Furniture data</param>
        private void RebuildFurniture(Furniture f)
        {
            f.RebuildSceneData();

            if (f.IsCustom)
            {
                f.associated3DObject = ImportManager.Instance.GetGameObjectFromCustomObject(new CustomFurniture
                {
                    Path = f.CustomPath,
                    Name = f.Name
                });
                f.associated3DObject.transform.parent = parent3D;
                AddCollider(f.associated3DObject);
                f.associated2DObject = Instantiate(backUpFurniture2DTop, parent2DTop);
            }
            else
            {
                // 3D
                f.associated3DObject = Instantiate(f.associated3DObject, parent3D);
                // 2D
                if (f.associated2DObject)
                {
                    f.associated2DObject = Instantiate(f.associated2DObject, parent2DTop);
                }
                else
                {
                    f.associated2DObject = Instantiate(backUpFurniture2DTop, parent2DTop);
                }
            }

            var s  = f.Size;
            var ms = f.MeshSize;

            f.associated3DObject.transform.position         = f.Position;
            f.associated3DObject.transform.localEulerAngles =
                f.EulerAngles;
            f.associated3DObject.transform.localScale =
                new Vector3(s.x / ms.x, s.y / ms.y, s.z / ms.z);
            f.associated3DObject.SetLayerRecursively((int)ErgoLayers.ThreeD);
            //f.associated3DObject.GetComponent<Rigidbody>().constraints = RigidbodyConstraints.FreezeAll;


            f.associated2DObject.transform.position =
                VectorFunctions
                .Switch3D2D(f
                            .Position); // VectorFunctions.GetExactPositionFrom3DObject(f.associated2DObject, f.associated3DObject, f.Position);
            f.associated2DObject.transform.localEulerAngles =
                f.EulerAngles.y * Vector3.forward * -1f;
            f.associated2DObject.transform.localScale = VectorFunctions.Switch3D2D(new Vector3(
                                                                                       f.Size.x / f.MeshSize.x,
                                                                                       f.Size.y / f.MeshSize.y,
                                                                                       f.Size.z / f.MeshSize.z
                                                                                       ));

            f.associated2DObject.SetLayerRecursively((int)ErgoLayers.Top);

            f.associated3DObject.tag = "Furniture";
            f.associated2DObject.tag = "Furniture";

            InitFurnitureText(f);
            f.AdjustSpriteSize();
        }
Exemple #15
0
        // Update is called once per frame
        private void Update()
        {
            if (GlobalManager.Instance.GetActiveCamera().tag != "Cam2D")
            {
                foreach (var g in m_allArrows)
                {
                    g.SetActive(false);
                }
                return;
            }

            var show = SelectedObjectManager.Instance.currentSelectedElements.Where(e => e is MovableElement).Count() ==
                       1;

            // Ajout exceptions : murs et ouvertures de murs
            show = show && SelectedObjectManager.Instance.currentWallsData.Count == 0 &&
                   SelectedObjectManager.Instance.currentWallOpenings.Count == 0 &&
                   SelectedObjectManager.Instance.currentStairs.Count == 0;

            foreach (var g in m_allArrows)
            {
                g.SetActive(show);
            }

            if (show)
            {
                var me = SelectedObjectManager.Instance.currentSelectedElements.First() as MovableElement;
                if (SelectedObjectManager.Instance.currentSelectedElements.Count() == 0 || me == null)
                {
                    return;
                }

                try
                {
                    var pos  = me.associated2DObject.transform.position; //VectorFunctions.Switch3D2D(me.Position);
                    var size = VectorFunctions.Switch3D2D(me.Size / 2f);

                    SetOrigins(me, pos, size);
                }
                catch { }

                if (up != currentArrow)
                {
                    up.transform.position = oUp;
                }
                if (down != currentArrow)
                {
                    down.transform.position = oDown;
                }
                if (left != currentArrow)
                {
                    left.transform.position = oLeft;
                }
                if (right != currentArrow)
                {
                    right.transform.position = oRight;
                }
                if (upLeft != currentArrow)
                {
                    upLeft.transform.position = oUpLeft;
                }
                if (upRight != currentArrow)
                {
                    upRight.transform.position = oUpRight;
                }
                if (downLeft != currentArrow)
                {
                    downLeft.transform.position = oDownLeft;
                }
                if (downRight != currentArrow)
                {
                    downRight.transform.position = oDownRight;
                }
            }

            if (show)
            {
                foreach (var go in m_allArrows)
                {
                    go.transform.localScale =
                        Vector3.one * Mathf.Abs(GlobalManager.Instance.cam2DTop.transform.position.z / 10f);
                }
                ClickArrow();
            }
            else
            {
                isMoving = false;
            }
        }