private void Start() { _ActionsMenu = ActionsMenu; slider.onClick.AddListener(() => { //gestire la mostra del Button UpDown if (SelectFurniture.currentFurniture) { if (SelectFurniture.currentFurniture is HouseRoom || SelectFurniture.currentFurniture is Construction) { _UpDown.SetActive(false); _Rotate.SetActive(false); } else { _UpDown.SetActive((PlanGraphics.currentMode == PlanGraphics.Modes._2D) ? false : true); } } }); destroy.onClick.AddListener(() => { HideFurniture(); Destroy(SelectFurniture.currentFurniture.gameObject); SelectFurniture.currentFurniture = null; }); color.onClick.AddListener(() => { //se l'oggetto selezionato è di tipo HouseRoom o Construcion if (SelectFurniture.currentFurniture is HouseRoom || SelectFurniture.currentFurniture is Construction) { //l'update dei colori viene eseguito nella init PatternsManager.Init(); PatternsManager._menu.SetActive(true); PatternsManager.currentPanel.SetActive(true); ActionsMenu.SetActive(false); } }); scale.onClick.AddListener(() => { }); //attivo il FurnitureMenu se un muro è selezionato change.onClick.AddListener(() => { if (SelectFurniture.currentFurniture is Construction) { FurnitureMenu._FurnitureMenu.SetActive(true); FurnitureMenu._Constructions_panel.SetActive(true); FurnitureMenu._Interiors_panel.SetActive(false); FurnitureMenu._Rooms_panel.SetActive(false); } }); exit.onClick.AddListener(() => { SelectFurniture._DeselectFurniture(); HideFurniture(); }); }
void GenerateUI() { foreach (Furniture item in items) { Transform t = null; Furniture newItem = null; //decido il container in cui andrà l'item da istanziare in base al tipo di oggetto if (item is Construction) { newItem = item.GetComponent <Construction>(); t = Constructions_container.transform; } else if (item is HouseRoom) { newItem = item.GetComponent <HouseRoom>(); t = Rooms_container.transform; } else { newItem = item.GetComponent <Furniture>(); t = Interios_container.transform; } GameObject go = Instantiate(itemPrefab, t, false); go.transform.FindChild("Text").GetComponent <Text>().text = newItem.name; go.transform.FindChild("Image").GetComponent <Image>().sprite = newItem.icon; go.GetComponent <Button>().onClick.AddListener(() => { //se l'item corrente è di tipo construction if (item is Construction) { //se c'è un 'oggetto selezionato di tipo construction cambia quel muro con questo se no evito d'istanziarlo if (SelectFurniture.currentFurniture is Construction) { GameObject _go = Instantiate(item.gameObject, SelectFurniture.currentFurniture.transform.parent, false); _go.transform.localRotation = SelectFurniture.currentFurniture.transform.localRotation; _go.transform.localPosition = SelectFurniture.currentFurniture.transform.localPosition; //prendo solo la parte prima dei (clone) e la assegno come nome _go.name = _go.name.Split('(')[0]; //salvo in in una variabile l'oggetto che poi distruggerò GameObject _lastWall = SelectFurniture.currentFurniture.gameObject; //deseleziono l'oggetto corrente SelectFurniture._DeselectFurniture(); //seleziono il nuovo oggetto SelectFurniture._SelectFurniture(_go.GetComponent <Construction>()); /////////////////////////////// //_go.transform.GetComponent<Construction>().name = _lastWall.transform.GetComponent<Construction>().name; //la stanza corrente HouseRoom hr = _go.transform.parent.GetComponent <HouseRoom>(); for (int i = 0; i < hr.walls.Length; i++) { //trovo nell'array la posizione del vecchio muro per metterci al suo posto il nuovo muro if (hr.walls[i].gameObject.Equals(_lastWall)) { hr.walls[i] = _go.transform.GetComponent <Construction>(); if (hr.walls[i].Direction == Construction.Directions.Left) { hr.left = _go.transform.GetComponent <Construction>(); //imposto la direction del muro che sto cambiando con la direction del muro vecchio _go.transform.GetComponent <Construction>().Direction = Construction.Directions.Left; } else if (hr.walls[i].Direction == Construction.Directions.Right) { hr.right = _go.transform.GetComponent <Construction>(); //imposto la direction del muro che sto cambiando con la direction del muro vecchio _go.transform.GetComponent <Construction>().Direction = Construction.Directions.Right; } else if (hr.walls[i].Direction == Construction.Directions.Front) { hr.front = _go.transform.GetComponent <Construction>(); //imposto la direction del muro che sto cambiando con la direction del muro vecchio _go.transform.GetComponent <Construction>().Direction = Construction.Directions.Front; } else if (hr.walls[i].Direction == Construction.Directions.Back) { hr.back = _go.transform.GetComponent <Construction>(); //imposto la direction del muro che sto cambiando con la direction del muro vecchio _go.transform.GetComponent <Construction>().Direction = Construction.Directions.Back; } } } //distruggo l'oggetto precedente Destroy(_lastWall); return; } else { return; } } GameObject obj = Instantiate(item.gameObject, house.transform); Furniture f = null; Vector3 pos = Vector3.zero; if (newItem is HouseRoom) { pos = roomPrefab.transform.position; f = obj.GetComponent <HouseRoom>(); } else if (newItem is Construction) { f = obj.GetComponent <Construction>(); } else { pos = new Vector3(roomPrefab.transform.position.x, roomPrefab.transform.position.y + 0.5f, roomPrefab.transform.position.z); f = obj.GetComponent <Furniture>(); } obj.transform.position = pos; obj.transform.rotation = obj.transform.rotation; //seleziono l'oggetto corrente SelectFurniture._SelectFurniture(f); }); } }