// Remove Dwellings and Sub Dwelling windows public void RomveDwellings(CSDwellings dwellings) { int index = m_SubDwellingsList.FindIndex(item0 => item0.m_Dwellings == dwellings); if (index != -1) { CSUI_SubDwellings sdWnd = m_SubDwellingsList[index]; m_SubDwellingsList.RemoveAt(index); GameObject.DestroyImmediate(sdWnd.gameObject); // Rename for (int i = index; i < m_SubDwellingsList.Count; i++) { m_SubDwellingsList[i].gameObject.name = i.ToString(); } // Get new Max page int totalPage = m_SubDwellingsList.Count / m_Page.m_PageCount; m_Page.m_MaxPageCount = (m_SubDwellingsList.Count % m_Page.m_PageCount) == 0 ? totalPage : totalPage + 1; PageTurning(m_Page.m_Index); } else { Debug.LogWarning("The Dwellings that you want to remove is not exsist!"); } }
// Add new Sub Dwellings windows public void AddDwellings(CSDwellings dwellings) { if (!m_SubDwellingsList.Exists(item0 => item0.m_Dwellings == dwellings)) { // Create a Sub Dwellings Window CSUI_SubDwellings sd = Instantiate(m_SubDwellings.m_Prefab) as CSUI_SubDwellings; sd.transform.parent = m_SubDwellings.m_Root.transform; sd.transform.localPosition = Vector3.zero; sd.transform.localRotation = Quaternion.identity; sd.transform.localScale = Vector3.one; sd.m_IconRadioRoot = m_SubDwellings.m_IconRadio; sd.m_QueryMatRoot = m_QuaryMatWndRoot; sd.m_Entity = dwellings; sd.m_Dwellings = dwellings; sd.gameObject.name = m_SubDwellingsList.Count.ToString(); sd.m_DwelingsUI = this; sd.gameObject.SetActive(true); m_SubDwellingsList.Add(sd); int totalPage = m_SubDwellingsList.Count / m_Page.m_PageCount; m_Page.m_MaxPageCount = (m_SubDwellingsList.Count % m_Page.m_PageCount) == 0 ? totalPage : totalPage + 1; if (m_Page.m_Index + m_Page.m_PageCount < m_SubDwellingsList.Count) { sd.gameObject.SetActive(false); } else { m_SubDwellings.m_Root.repositionNow = true; } } else { Debug.LogWarning("The Dwellings that you want to add into UI is areadly exsts!"); } }