Beispiel #1
0
        public void Init(StarMapEditorRoot root, bool needReset = false)
        {
            m_Root = root;
            if (!needReset)
            {
                Check();
                return;
            }
            int childCount = transform.childCount;

            if (childCount > 0)
            {
                for (int iChild = childCount - 1; iChild >= 0; iChild--)
                {
                    GameObject.DestroyImmediate(transform.GetChild(iChild).gameObject);
                }
            }

            m_PlanetAreaContainers.Clear();

            List <EditorGamingMap> allGamingMaps = m_Root.m_AllGamingMaps;

            if (allGamingMaps != null && allGamingMaps.Count > 0)
            {
                for (int iAllGaming = 0; iAllGaming < allGamingMaps.Count; iAllGaming++)
                {
                    EditorGamingMap editorData = allGamingMaps[iAllGaming];
                    if (editorData == null)
                    {
                        continue;
                    }
                    CreatePlanetArea(editorData);
                }
            }
        }
Beispiel #2
0
        public void Init(PlanetPanel panel, EditorArea[] areas, uint mapId)
        {
            m_Panel       = panel;
            m_GamingMapId = mapId;
            m_PlanetAreas.Clear();
            if (areas != null && areas.Length > 0)
            {
                EditorPlanet planet = m_Panel.m_Root.GetPreviewPlanet(mapId);
                if (planet != null)
                {
                    m_MiniMapSize    = planet.minimapSize;
                    m_FixedStarRes   = planet.bgmapRes;
                    m_FixedStarScale = planet.bgmapScale.ToVector2();
                    if (m_FixedStarContainer != null)
                    {
                        m_FixedStarContainer.rectTransform.sizeDelta = m_FixedStarScale;
                    }

                    m_FixedStarPos = planet.bgmapPos.ToVector2();
                    m_FixedStarObj = StarMapEditorRoot.FindResAsset(m_FixedStarRes);
                }
                for (int iArea = 0; iArea < areas.Length; iArea++)
                {
                    EditorArea editorArea = areas[iArea];
                    if (editorArea == null)
                    {
                        continue;
                    }
                    CreateElement(editorArea, planet);
                }
            }
            RefreshMap();
        }
        /// <summary>
        /// 右键响应
        /// </summary>
        /// <param name="instanceID"></param>
        /// <param name="selectionRect"></param>
        private void OnHierarchyGUI(int instanceID, Rect selectionRect)
        {
            if (Event.current != null && selectionRect.Contains(Event.current.mousePosition) &&
                Event.current.button == 1 && Event.current.type <= EventType.MouseUp)
            {
                GameObject selectedGameObject = EditorUtility.InstanceIDToObject(instanceID) as GameObject;
                if (selectedGameObject)
                {
                    StarMapEditorRoot starMapRoot = selectedGameObject.GetComponent <StarMapEditorRoot>();
                    if (starMapRoot != null)
                    {
                        RefreshStarMapRootUI(starMapRoot);
                    }

                    FixedStarElement starElement = selectedGameObject.GetComponent <FixedStarElement>();
                    if (starElement != null)
                    {
                        RefreshFixedStarElementUI(starElement);
                    }

                    StarMapMainPanel starMapMainPanel = selectedGameObject.GetComponent <StarMapMainPanel>();
                    if (starMapMainPanel != null)
                    {
                        RefreshStarMapMainPanel(starMapMainPanel);
                    }

                    PlanetElement planetElement = selectedGameObject.GetComponent <PlanetElement>();
                    if (planetElement != null)
                    {
                        RefreshPalnetElement(planetElement);
                    }

                    FixedStarPanel fixedStarPanel = selectedGameObject.GetComponent <FixedStarPanel>();
                    if (fixedStarPanel != null)
                    {
                        RefreshFixedStarPanel(fixedStarPanel);
                    }

                    PlanetPanel planetPanel = selectedGameObject.GetComponent <PlanetPanel>();
                    if (planetPanel != null)
                    {
                        RefreshPlanetPanel(planetPanel);
                    }

                    PlanetContainer planetContainer = selectedGameObject.GetComponent <PlanetContainer>();
                    if (planetContainer != null)
                    {
                        RefreshPlanetContainer(planetContainer);
                    }

                    PlanetAreaContainer planetAreaContainer = selectedGameObject.GetComponent <PlanetAreaContainer>();
                    if (planetAreaContainer != null)
                    {
                        RefreshPlanetAreaContainer(planetAreaContainer);
                    }
                }
            }
        }
        public void Init(EditorArea area, EditorStarMapArea starMapArea)
        {
            if (area == null)
            {
                return;
            }
            if (rectTrans == null)
            {
                rectTrans = GetComponent <RectTransform>();
            }

            if (starMapArea != null)
            {
                m_Res = starMapArea.area_res;
                rectTrans.anchoredPosition = starMapArea.position.ToVector2();
                m_Resobj = StarMapEditorRoot.FindResAsset(m_Res);
            }
            m_AreaData      = area;
            gameObject.name = area.areaName;
            if (m_Tip == null)
            {
                Transform tipTrans = transform.Find("tip");
                if (tipTrans != null)
                {
                    m_Tip = tipTrans.gameObject.GetComponent <Text>();
                }
            }

            if (m_Tip != null)
            {
                m_Tip.text = "";
                EditorLeap[] leaps = area.leapList;
                if (leaps != null && leaps.Length > 0)
                {
                    EditorLeap leap = leaps[0];
                    if (leap.leapType == (int)LeapType.Main)
                    {
                        m_Tip.text = "主";
                    }
                    else if (leap.leapType == (int)LeapType.Child)
                    {
                        m_Tip.text = "副";
                    }
                }
            }
        }
        /// <summary>
        /// 刷新npc列表显示ui
        /// </summary>
        /// <param name="contentList"></param>
        /// <param name="areaSpawner"></param>
        private void RefreshStarMapRootUI(StarMapEditorRoot starMapRoot)
        {
            if (starMapRoot == null)
            {
                return;
            }
            m_ContentCache.Clear();
            m_ContentCache.Add(new GUIContent("打开星图面板"));
            m_ContentCache.Add(new GUIContent("保存"));
            m_ContentCache.Add(new GUIContent("导出json"));
            m_ContentCache.Add(new GUIContent("导入json"));
            m_ContentCache.Add(new GUIContent("重置"));
            Vector2    mousePosition = Event.current.mousePosition;
            GameObject userData      = Selection.activeGameObject;
            int        selected      = -1;

            EditorUtility.DisplayCustomMenu(new Rect(mousePosition.x, mousePosition.y, 0, 0), m_ContentCache.ToArray(), selected,
                                            delegate(object data, string[] opt, int select)
            {
                switch (select)
                {
                case 0:
                    starMapRoot.OpenStarMap();
                    break;

                case 1:
                    EditorSceneManager.SaveOpenScenes();
                    break;

                case 2:        //导出json
                    starMapRoot.ExportStarMap();
                    break;

                case 3:        //导入json
                    starMapRoot.LoadStarMap();
                    break;

                case 4:        //初始化
                    m_PreviewStarMap = null;
                    InitPanels(true);
                    break;
                }
            }, userData);
            Event.current.Use();
        }
Beispiel #6
0
        public void InitFixedStar(StarMapEditorRoot root, bool needReset = false)
        {
            m_Root          = root;
            m_StarMapVoList = ConfigVO <StarMapVO> .Instance.GetList();

            if (!needReset)
            {
                Check();
                return;
            }
            Clear();
            if (m_StarMapVoList != null && m_StarMapVoList.Count > 0)
            {
                for (int iStar = 0; iStar < m_StarMapVoList.Count; iStar++)
                {
                    StarMapVO starVo = m_StarMapVoList[iStar];
                    CreateFixedStarElement(starVo);
                }
            }
        }
Beispiel #7
0
        public IEnumerator DoEditorUpdate(StarMapEditorRoot root)
        {
            m_Root = root;
            if (m_RectTrans == null)
            {
                m_RectTrans = GetComponent <RectTransform>();
            }
            if (m_RectTrans != null)
            {
                m_RectTrans.anchoredPosition = Vector2.zero;
            }
            yield return(null);

            m_PlanetContains.Clear();
            PlanetContainer[] containers = GetComponentsInChildren <PlanetContainer>(true);
            if (containers != null && containers.Length > 0)
            {
                for (int iContainer = 0; iContainer < containers.Length; iContainer++)
                {
                    m_PlanetContains.Add(containers[iContainer]);
                }
            }
            yield return(null);

            if (m_PlanetContains != null && m_PlanetContains.Count > 0)
            {
                for (int iPlanet = 0; iPlanet < m_PlanetContains.Count; iPlanet++)
                {
                    PlanetContainer container = m_PlanetContains[iPlanet];
                    if (container == null || container.gameObject == null)
                    {
                        continue;
                    }
                    IEnumerator containerEnumer = container.DoEditorUpdate(this);
                    while (container != null && container.gameObject != null && containerEnumer.MoveNext())
                    {
                        yield return(null);
                    }
                }
            }
        }
Beispiel #8
0
 public void Init(EditorGamingMap gamingData, EditorPlanet planet)
 {
     if (gamingData == null)
     {
         return;
     }
     m_StarData      = gamingData;
     gameObject.name = gamingData.gamingmapName;
     if (m_RectTrans == null)
     {
         m_RectTrans = GetComponent <RectTransform>();
     }
     if (planet != null)
     {
         m_Res = planet.gamingmapRes;
         m_RectTrans.anchoredPosition = planet.position.ToVector2();
         m_ResScale            = planet.scale.ToVector2();
         m_RectTrans.sizeDelta = m_ResScale;
         m_ResObj = StarMapEditorRoot.FindResAsset(m_Res);
     }
 }
        private void HierarchyItemCB(int instanceid, Rect selectionrect)
        {
            GameObject obj = EditorUtility.InstanceIDToObject(instanceid) as GameObject;

            if (obj == null)
            {
                return;
            }
            bool              isActive = obj.activeSelf;
            Transform         trans    = obj.transform;
            StarMapEditorRoot root     = obj.GetComponent <StarMapEditorRoot>();

            if (root != null)
            {
                DrawUI(trans, selectionrect, "编辑", Color.red);
            }

            StarMapMainPanel starMapMainPanel = obj.GetComponent <StarMapMainPanel>();

            if (starMapMainPanel != null)
            {
                DrawUI(trans, selectionrect, "编辑星图", isActive ? Color.yellow : Color.red);
            }

            FixedStarPanel fixedStarPanel = obj.GetComponent <FixedStarPanel>();

            if (fixedStarPanel != null)
            {
                DrawUI(trans, selectionrect, "编辑恒星", isActive ? Color.yellow : Color.red);
            }

            PlanetPanel planetPanel = obj.GetComponent <PlanetPanel>();

            if (planetPanel != null)
            {
                DrawUI(trans, selectionrect, "编辑行星", isActive ? Color.yellow : Color.red);
            }

            FixedStarElement fixedStarElement = obj.GetComponent <FixedStarElement>();

            if (fixedStarElement != null)
            {
                DrawUI(trans, selectionrect, "恒星", Color.red);
            }

            PlanetContainer planetContainer = obj.GetComponent <PlanetContainer>();

            if (planetContainer != null)
            {
                DrawUI(trans, selectionrect, "行星组", isActive ? Color.yellow : Color.red);
            }

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

            if (planetElement != null)
            {
                DrawUI(trans, selectionrect, "行星", Color.red);
            }

            PlanetAreaContainer planetAreaContainer = obj.GetComponent <PlanetAreaContainer>();

            if (planetAreaContainer != null)
            {
                DrawUI(trans, selectionrect, "区域组", isActive ? Color.yellow : Color.red);
            }

            PlanetAreaElement planetAreaElement = obj.GetComponent <PlanetAreaElement>();

            if (planetAreaElement != null)
            {
                DrawUI(trans, selectionrect, "区域", Color.blue);
            }
        }
        public IEnumerator DoEditorUpdate(StarMapEditorRoot root)
        {
            m_Root = root;
            if (m_RectTrans != null)
            {
                m_RectTrans = GetComponent <RectTransform>();
            }
            if (m_RectTrans != null)
            {
                m_RectTrans.anchoredPosition = Vector2.zero;
            }
            yield return(null);

            m_FixedStarElements.Clear();
            FixedStarElement[] elements = GetComponentsInChildren <FixedStarElement>(true);
            if (elements != null && elements.Length > 0)
            {
                for (int iElement = 0; iElement < elements.Length; iElement++)
                {
                    m_FixedStarElements.Add(elements[iElement]);
                }
            }
            yield return(null);

            if (m_FixedStarElements != null && m_FixedStarElements.Count > 0)
            {
                for (int iStarElement = 0; iStarElement < m_FixedStarElements.Count; iStarElement++)
                {
                    FixedStarElement element = m_FixedStarElements[iStarElement];
                    if (element != null)
                    {
                        IEnumerator elementEnumer = element.DoEditorUpdate(this);
                        while (elementEnumer.MoveNext())
                        {
                            yield return(null);
                        }
                    }
                }
            }
            yield return(null);


            m_Trails.Clear();
            TrailRenderer[] trails = GetComponentsInChildren <TrailRenderer>();
            if (trails != null && trails.Length > 0)
            {
                for (int iTrail = 0; iTrail < trails.Length; iTrail++)
                {
                    m_Trails.Add(trails[iTrail]);
                    //trails[iTrail].Clear();
                }
            }
            yield return(null);

            if (m_StarMapVoList != null && m_StarMapVoList.Count > 0)
            {
                int           trailIndex  = 0;
                TrailRenderer trailRender = null;
                for (int iStar = 0; iStar < m_StarMapVoList.Count; iStar++)
                {
                    StarMapVO starMapVo = m_StarMapVoList[iStar];
                    if (starMapVo == null)
                    {
                        continue;
                    }
                    FixedStarElement beginElement = GetElement(starMapVo.FixedStarid);
                    if (beginElement == null)
                    {
                        continue;
                    }
                    int[] relationIds = starMapVo.Relation_Id;
                    if (relationIds != null && relationIds.Length > 0)
                    {
                        for (int iRelation = 0; iRelation < relationIds.Length; iRelation++)
                        {
                            FixedStarElement endElement = GetElement(relationIds[iRelation]);
                            if (endElement == null)
                            {
                                continue;
                            }
                            if (m_Trails.Count > trailIndex)
                            {
                                trailRender = m_Trails[trailIndex];
                            }
                            else
                            {
                                GameObject trailObj = new GameObject("Trail_" + trailIndex);
                                trailRender = trailObj.AddComponent <TrailRenderer>();
                            }
                            trailRender.transform.SetParent(beginElement.transform);
                            trailIndex++;
                            trailRender.Clear();
                            trailRender.startWidth = 0.3f;
                            trailRender.AddPosition(beginElement.transform.position);
                            trailRender.AddPosition(endElement.transform.position);
                            trailRender.transform.position = endElement.transform.position;
                        }
                    }
                }
            }
        }