void InitCables() { int toConnectCabs = chosenSetup.ConnectedCables.Count; int toDetachCabs = chosenSetup.DetachedCables.Count; int noCab = Components.Cables.Count - 2 /*Per i cavi virtuali dei posti 1 e 5*/ - toConnectCabs - toDetachCabs; List <int> alreadySetCabs = new List <int>() { 1, 5 }; while (toConnectCabs + toDetachCabs + noCab > 0) { //choose an avaiable cable int cabIndex = Random.Range(0, Components.Cables.Count); GameObject cab = Components.Cables[cabIndex]; if (alreadySetCabs.Contains(cabIndex)) { if (alreadySetCabs.Count >= Components.Cables.Count) { Debug.LogError("Impossible Setup"); return; } continue; } else { alreadySetCabs.Add(cabIndex); } if (toConnectCabs > 0) { cab.SetActive(true); toConnectCabs--; CableType cabColor = chosenSetup.ConnectedCables[toConnectCabs]; MeshRenderer cabRenderer = cab.GetComponentInChildren <MeshRenderer>(); cabRenderer.material = GetMaterialByType(cabColor); SelectableSwitch cabSwitch = cab.GetComponentInChildren <SelectableSwitch>(); cabSwitch.Init(this, new CabSwitchData() { CabType = cabColor, CabID = cabIndex }); cabSwitch.selectStatus = true; switches.Add(cabSwitch); } else if (toDetachCabs > 0) { cab.SetActive(true); toDetachCabs--; CableType cabColor = chosenSetup.DetachedCables[toDetachCabs]; MeshRenderer cabRenderer = cab.GetComponentInChildren <MeshRenderer>(); cabRenderer.material = GetMaterialByType(cabColor); SelectableSwitch cabSwitch = cab.GetComponentInChildren <SelectableSwitch>(); cabSwitch.Init(this, new CabSwitchData() { CabType = cabColor, CabID = cabIndex }); cabSwitch.selectStatus = false; switches.Add(cabSwitch); } else { noCab--; cab.SetActive(false); } } }