Esempio n. 1
0
        public void Initialise(ShopState shopState)
        {
            this.shopState = shopState;

            allShopDecorations = new List <ShopDecorationObject>(GetComponentsInChildren <ShopDecorationObject>());
            foreach (var shopDecoration in allShopDecorations)
            {
                shopDecoration.gameObject.SetActive(false);
            }
            //Debug.Log("Decorations: " + allShopDecorations.Count);

            allShopDecorationSlots = new List <ShopDecorationSlot>(GetComponentsInChildren <ShopDecorationSlot>());
            foreach (var slot in allShopDecorationSlots)
            {
                slot.Initialise(slotFeedbackPrefabGo);
            }
            //Debug.Log("Slots: " + allShopDecorationSlots.Count);

            // Load state
            if (shopState.occupiedSlots != null)
            {
                for (int i = 0; i < shopState.occupiedSlots.Length; i++)
                {
                    var slotState = shopState.occupiedSlots[i];
                    if (slotState.decorationID == "")
                    {
                        continue;
                    }
                    var decorationPrefab = allShopDecorations.Find(x => x.id == slotState.decorationID);
                    var slot             = allShopDecorationSlots.FirstOrDefault(x => x.slotType == decorationPrefab.slotType && x.slotIndex == slotState.slotIndex);
                    if (slot != null && decorationPrefab != null)
                    {
                        //Debug.Log("LOADING ASSIGNED " + slot + " AND " + decorationPrefab);
                        var newDeco = SpawnNewDecoration(decorationPrefab);
                        slot.Assign(newDeco);
                    }
                }
            }

            //Debug.Log(shopState.ToString());

            // Initialise context
            SetContextClosed();

            // TEST
            if (testDecorationFilling)
            {
                var allPrefabDecorations = FindObjectsOfType <ShopAction_UnlockDecoration>().ToList().ConvertAll(x => x.UnlockableDecorationObject).ToList();
                foreach (var slot in allShopDecorationSlots)
                {
                    var prefab = allPrefabDecorations.FirstOrDefault(x => x.slotType == slot.slotType);
                    if (prefab != null)
                    {
                        slot.Assign(Instantiate(prefab));
                    }
                }
            }
        }
Esempio n. 2
0
        public static ShopState CreateFromJson(string jsonData)
        {
            var shopState = JsonUtility.FromJson <ShopState>(jsonData);

            if (shopState == null)
            {
                shopState = new ShopState();
            }
            return(shopState);
        }