/// Update the inventory and add a new button in terms of the template used. /// @param prf PrefabJSON object which contains the description of the object. /// @note Each button own a prefab JSON parameter with the description of the object to which it is assigned. public void UpdateInventory(PrefabJSON prf) { if (buttonTemplate) { Debug.Log("Test 1"); } GameObject newButton = Instantiate(buttonTemplate) as GameObject; newButton.SetActive(true); switch (this.prefab.name) { case "chair_1": Debug.Log("CHAIR 1"); newButton.GetComponent <InventoryButton>().SetIcon(Resources.Load <Sprite>("Sprites/Items/chair_1_prefab")); break; case "bed_1": Debug.Log("BED 1"); newButton.GetComponent <InventoryButton>().SetIcon(Resources.Load <Sprite>("Sprites/Items/bed_1_prefab")); break; case "torchere_1": Debug.Log("TORCHERE 1"); newButton.GetComponent <InventoryButton>().SetIcon(Resources.Load <Sprite>("Sprites/Items/torchere_1_prefab")); break; } newButton.GetComponent <InventoryButton>().SetName(this.title); newButton.GetComponent <InventoryButton>().SetPrefabJSON(prf); newButton.transform.SetParent(buttonTemplate.transform.parent, false); }
/// Get prefab of the object to place. /// @param prefab PrefabJSON object to place. public void PreAddItem(PrefabJSON prefab) { ARItemsHandling.ConfigItem found = itemsHandling.GetConfigItems().Find((config) => config.name == prefab.typeName); if (found != null) { this.ItemToPlace = found.loadedPrefab; itemsHandling.SetPrefabJSON(prefab); Debug.Log("SetItemToPlaceName : " + this.ItemToPlace); this.EnableInterface(); Update(); } }
/// Initiate the PrefabJSON object for the button. /// Each type of features have color and texture set with default values in terms of prefab name. /// @see PrefabJSON() public void InitPrefabJSON() { prefabDescription = new PrefabJSON(); prefabDescription.typeName = name.text; prefabDescription.title = name.text; if (name.text == "chair_1") { prefabDescription.appearances = new Appearance[3]; prefabDescription.appearances[0] = new Appearance { name = "metal", color = "#FFFFFF", texture = "base_material" }; prefabDescription.appearances[1] = new Appearance { name = "plastic", color = "#FFFFFF", texture = "base_material" }; prefabDescription.appearances[2] = new Appearance { name = "seat", color = "#FFFFFF", texture = "base_material" }; } if (name.text == "bed_1") { prefabDescription.appearances = new Appearance[5]; prefabDescription.appearances[0] = new Appearance { name = "base", color = "#FFFFFF", texture = "base_material" }; prefabDescription.appearances[1] = new Appearance { name = "blanket", color = "#FFFFFF", texture = "base_material" }; prefabDescription.appearances[2] = new Appearance { name = "mattress", color = "#FFFFFF", texture = "base_material" }; prefabDescription.appearances[3] = new Appearance { name = "pillow", color = "#FFFFFF", texture = "base_material" }; prefabDescription.appearances[4] = new Appearance { name = "pillow 1", color = "#FFFFFF", texture = "base_material" }; } if (name.text == "torchere_1") { prefabDescription.appearances = new Appearance[2]; prefabDescription.appearances[0] = new Appearance { name = "base", color = "#FFFFFF", texture = "base_material" }; prefabDescription.appearances[1] = new Appearance { name = "plafond", color = "#FFFFFF", texture = "base_material" }; } }
/// Save the object description in Database if the user is connected. /// The inventory is updated. public void SaveObject() { int i = 0; PrefabJSON prf = new PrefabJSON(); prf.appearances = new Appearance[this.features.Count]; prf.typeName = this.prefab.name; if (this.title == "") { prf.title = "Default Object"; } else { prf.title = this.title; } foreach (var pair in this.features) { Appearance apr = new Appearance(); if (pair.Value.color == "default") { apr.color = "#FFFFFF"; } else { apr.color = pair.Value.color; } apr.texture = pair.Value.texture; apr.name = pair.Value.name; prf.appearances[i] = apr; i += 1; } if (GlobalStatus.token != "") { var JSONresult = JsonConvert.SerializeObject(prf); this.SaveToBack(JSONresult); } this.UpdateInventory(prf); }
/// Set the prefab JSON description. /// @param prefab PrefabJSON object containing object description. /// @see PrefabJSON() public void SetPrefabJSON(PrefabJSON prefab) { this.prefabDescription = prefab; }
/// Set the description of an item from a PrefabJSON object. /// @param prefab A PrefabJSON object containing the description of an item created. /// @see PrefabJSON public void SetPrefabJSON(PrefabJSON prefab) { this.prefabDescription = prefab; Debug.Log(prefab.title + " -> " + prefab.appearances[0].color); }