예제 #1
0
        /// <summary>
        /// Raises the generate button press event.
        /// </summary>
        public void OnGenerateButtonPress()
        {
            if (editingObject == null)
            {
                return;
            }

            // Create a bunch of stacks in this area, I guess.
            int desired = int.Parse(rowsInputField.text);
            int current = editingObject.aisles.Count;

            // If desired is more than current, add as many as we should, rearranging
            // the gap between two as needed.
            for (int i = 0; desired > current + i; i++)
            {
                Aisle obj = Instantiate(aislePrefab, editingObject.container);
                editingObject.aisles.Add(obj);
                obj.GetComponent <Rectangle>().disableEditing = true;
            }

            // Otherwise we remove them.
            for (int i = 0; current - i > desired; i++)
            {
                Aisle obj = editingObject.aisles[desired];
                editingObject.aisles.RemoveAt(desired);
                Destroy(obj.gameObject);
            }

            if (desired != current)
            {
                ActionManager.shared.Push();
            }
        }
예제 #2
0
        /// <summary>
        /// Creates a new aisle and adds it to the floor.
        /// </summary>
        /// <param name="rect">Dimensions of the aisle.</param>
        /// <param name = "preview">Whether this is only a preview of the real object.</param>
        /// <param name = "isUndoRedo">Is this creation a result of undo/redo?</param>
        /// <param name = "insideAisleArea">Inside an aisle area?</param>
        public Aisle CreateAisle(Rect rect, bool preview, bool isUndoRedo = false, bool insideAisleArea = false)
        {
            Aisle obj = null;

            if (preview)
            {
                // Destroys preview if it is of a different type
                if (previewObject != null && previewObject.GetComponent <Aisle>() == null)
                {
                    ClearPreview();
                }

                // Create a preview object if it is not there already.
                if (previewObject == null)
                {
                    previewObject       = Instantiate(aislePrefab, previewLayer).GetComponent <CanvasGroup>();
                    previewObject.alpha = 0.5f;
                }

                Rectangle t            = previewObject.GetComponent <Rectangle>();
                bool      shouldRotate = rect.width > rect.height;
                t.SetRotation(shouldRotate ? 90 : 0);
                t.SetSize(shouldRotate ? new Vector2(rect.height, rect.width) : rect.size);
                t.SetCenter(rect.center);
            }
            else
            {
                // Clears the preview object.
                obj = Instantiate(aislePrefab, aisleLayer);
                Rectangle t = obj.GetComponent <Rectangle>();

                if (!insideAisleArea)
                {
                    floor.aisles.Add(obj);
                }

                ClearPreview();

                bool shouldRotate = rect.width > rect.height;
                t.SetRotation(shouldRotate ? 90 : 0);
                t.SetSize(shouldRotate ? new Vector2(rect.height, rect.width) : rect.size);
                t.SetCenter(rect.center);

                if (!isUndoRedo)
                {
                    ActionManager.shared.Push();
                }
            }

            // Resize - we do something more here. We want to rotate the aisle
            // depending on whichever side is longer.
            return(obj);
        }
예제 #3
0
        /// <summary>
        /// Sets up the script according to the given object. If we can edit it,
        /// then we update our values. Otherwise hide this panel.
        /// </summary>
        /// <param name="obj">Object.</param>
        public void SetEditingObject(GameObject obj)
        {
            if (obj == null)
            {
                editingObject = null;
            }
            else
            {
                editingObject = obj.GetComponent <Aisle>();
            }

            PopulateObject();
        }
예제 #4
0
        public void FromJSON(FloorController api, JSONNode root)
        {
            Rectangle r = GetComponent <Rectangle>();

            r.SetCenter(new Vector2(root["center_x"].AsFloat, root["center_y"].AsFloat));
            r.SetSize(new Vector2(root["width"].AsFloat, root["height"].AsFloat));
            r.SetRotation(root["rotation"].AsFloat);

            foreach (JSONNode node in root["aisles"].AsArray)
            {
                Aisle aisle = api.CreateAisle(Rect.zero, false, true, true);
                aisle.transform.SetParent(container, false);
                aisle.FromJSON(api, node);
            }
        }
예제 #5
0
        /// <summary>
        /// Overwrites this floor's content with JSON object root.
        /// </summary>
        /// <param name = "api">The FloorController.</param>
        /// <param name="root">Root.</param>
        public void FromJSON(FloorController api, JSONNode root)
        {
            if (root == null)
            {
                return;
            }

            floorId    = root["floor_id"];
            floorName  = root["floor_name"];
            floorOrder = root["floor_order"];
            libraryId  = root["library"];

            if (api == null)
            {
                // Not ready to expand yet!
                floorJSONCache = root.ToString();
                return;
            }

            aisles.Clear();
            aisleAreas.Clear();
            walls.Clear();
            landmarks.Clear();

            foreach (JSONObject obj in root["aisles"].AsArray)
            {
                Aisle aisle = api.CreateAisle(Rect.zero, false, true);
                aisle.FromJSON(api, obj);
            }

            foreach (JSONObject obj in root["aisle_areas"].AsArray)
            {
                AisleArea aisleArea = api.CreateAisleArea(Rect.zero, false, true);
                aisleArea.FromJSON(api, obj);
            }

            foreach (JSONObject obj in root["walls"].AsArray)
            {
                Wall wall = api.CreateWall(Vector2.zero, Vector2.zero, false, true);
                wall.FromJSON(api, obj);
            }

            foreach (JSONObject obj in root["landmarks"].AsArray)
            {
                Landmark landmark = api.CreateLandmark(Rect.zero, false, true);
                landmark.FromJSON(api, obj);
            }
        }