public void UpdateElements(EditorArea[] areas) { if (areas == null || areas.Length <= 0) { if (m_PlanetAreas != null && m_PlanetAreas.Count > 0) { for (int iPlanet = m_PlanetAreas.Count - 1; iPlanet >= 0; iPlanet--) { PlanetAreaElement areaElement = m_PlanetAreas[iPlanet]; if (areaElement != null) { if (areaElement.m_AreaData != null) { Debug.LogError("PlanetAreaContainer " + m_GamingMapId + " 删除了 " + areaElement.m_AreaData.areaId); } m_PlanetAreas.Remove(areaElement); GameObject.DestroyImmediate(areaElement.gameObject); } } } return; } for (int iArea = 0; iArea < areas.Length; iArea++) { EditorArea editorArea = areas[iArea]; PlanetAreaElement element = GetElement(editorArea.areaId); if (element == null) { CreateElement(editorArea, null); Debug.LogError("PlanetAreaContainer " + m_GamingMapId + " 新增了 " + editorArea.areaId); } else { element.Init(editorArea, null); } } if (m_PlanetAreas != null && m_PlanetAreas.Count > 0) { for (int iPlanet = m_PlanetAreas.Count - 1; iPlanet >= 0; iPlanet--) { PlanetAreaElement areaElement = m_PlanetAreas[iPlanet]; EditorArea editorArea = GetArea(areaElement.m_AreaData.areaId, areas); if (editorArea == null) { if (areaElement.m_AreaData != null) { Debug.LogError("PlanetAreaContainer " + m_GamingMapId + " 删除了 " + areaElement.m_AreaData.areaId); } m_PlanetAreas.Remove(areaElement); GameObject.DestroyImmediate(areaElement.gameObject); } } } }
private void CreateElement(EditorArea editorArea, EditorPlanet planet) { GameObject planetArea = GameObject.Instantiate(m_Panel.m_PlanetAreaElementPrefab); planetArea.SetActive(true); planetArea.transform.SetParent(transform); planetArea.transform.localPosition = Vector3.zero; PlanetAreaElement planetElement = planetArea.GetComponent <PlanetAreaElement>(); if (planetElement != null) { EditorStarMapArea starMapArea = m_Panel.m_Root.GetPreviewArea(planet, editorArea.areaId); planetElement.Init(editorArea, starMapArea); m_PlanetAreas.Add(planetElement); } }