Ejemplo n.º 1
0
        private void CreateElement(EditorGamingMap editorData)
        {
            GameObject planetObj = Instantiate(m_FixedStarPanel.m_PlanetElementPrefab);

            planetObj.SetActive(true);
            planetObj.transform.SetParent(transform);

            PlanetElement planetElement = planetObj.GetComponent <PlanetElement>();

            if (planetElement != null)
            {
                EditorPlanet planet = m_FixedStarPanel.m_Root.GetPreviewPlanet(editorData.gamingmapId);
                if (planet != null)
                {
                    planetElement.Init(editorData, planet);
                    //planetObj.transform.localPosition = Vector3.zero;
                }
                else
                {
                    planetElement.Init(editorData, null);
                    //planetObj.transform.localPosition = Vector3.zero;
                    Debug.LogError("PlanetContainer " + m_StarMapId + "新增了:" + editorData.gamingmapId);
                }
                m_PlanetElements.Add(planetElement);
            }
        }
Ejemplo n.º 2
0
        public void UpdateElements(List <EditorGamingMap> gamingMaps)
        {
            if (gamingMaps == null || gamingMaps.Count <= 0)
            {
                for (int iElement = m_PlanetElements.Count - 1; iElement >= 0; iElement--)
                {
                    PlanetElement planetElement = m_PlanetElements[iElement];
                    if (planetElement != null)
                    {
                        GameObject.DestroyImmediate(planetElement.gameObject);
                        EditorGamingMap gamingMap = planetElement.m_StarData;
                        if (gamingMap != null)
                        {
                            Debug.LogError("PlanetContainer " + m_StarMapId + " 删除了" + gamingMap.gamingmapId);
                        }
                    }
                }
                return;
            }

            for (int iGaming = 0; iGaming < gamingMaps.Count; iGaming++)
            {
                EditorGamingMap editorData = gamingMaps[iGaming];
                if (editorData == null)
                {
                    continue;
                }
                PlanetElement element = GetElement(editorData.gamingmapId);
                if (element == null)
                {
                    CreateElement(editorData);
                    if (editorData != null)
                    {
                        Debug.LogError("PlanetContainer " + m_StarMapId + "新增了" + editorData.gamingmapId);
                    }
                }
                else
                {
                    element.Init(editorData, null);
                }
            }

            if (m_PlanetElements != null && m_PlanetElements.Count > 0)
            {
                for (int iElement = m_PlanetElements.Count - 1; iElement >= 0; iElement--)
                {
                    PlanetElement planetElement = m_PlanetElements[iElement];
                    if (planetElement == null)
                    {
                        continue;
                    }
                    EditorGamingMap editorGamingMap = planetElement.m_StarData;
                    if (editorGamingMap != null)
                    {
                        bool exist = ExistsGamingMap(gamingMaps, editorGamingMap.gamingmapId);
                        if (!exist)
                        {
                            m_PlanetElements.Remove(planetElement);
                            GameObject.DestroyImmediate(planetElement.gameObject);
                            EditorGamingMap gamingMap = planetElement.m_StarData;
                            if (gamingMap != null)
                            {
                                Debug.LogError("PlanetContainer " + m_StarMapId + "删除了" + gamingMap.gamingmapId);
                            }
                        }
                    }
                }
            }
        }