Example #1
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);
            }
        }
Example #2
0
        // TODO: these creation methods are kind of dumb with repetitive code. Think
        // about refactoring them at a later stage might be a good idea.


        /// <summary>
        /// Creates a new landmark and adds it to the floor.
        /// </summary>
        /// <param name="rect">Dimensions of the landmark.</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>
        public Landmark CreateLandmark(Rect rect, bool preview, bool isUndoRedo = false)
        {
            if (preview)
            {
                // Destroys preview if it is of a different type
                if (previewObject != null && previewObject.GetComponent <Landmark>() == null)
                {
                    ClearPreview();
                }

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

                // Resize
                ((RectTransform)previewObject.transform).sizeDelta        = rect.size;
                ((RectTransform)previewObject.transform).anchoredPosition = rect.center;

                return(null);
            }
            else
            {
                // Clears the preview object.
                Landmark obj = Instantiate(landmarkPrefab, landmarkLayer);
                ((RectTransform)obj.transform).sizeDelta        = rect.size;
                ((RectTransform)obj.transform).anchoredPosition = rect.center;
                floor.landmarks.Add(obj);
                ClearPreview();

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

                return(obj);
            }
        }