示例#1
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);
                    }
                }
            }
        }
        private void OpenPlanetAreaContainer(PlanetAreaContainer planetAreaContainer)
        {
            if (planetAreaContainer == null)
            {
                return;
            }
            CloseAllPanel();
            PlanetPanel planetPanel = planetAreaContainer.m_Panel;

            if (planetPanel != null)
            {
                planetPanel.gameObject.SetActive(true);
                planetPanel.Open(planetAreaContainer);
            }
        }
        private void RefreshPlanetPanel(PlanetPanel planetPanel)
        {
            if (planetPanel == null)
            {
                return;
            }
            m_ContentCache.Clear();
            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:
                    OpenPlanet(null);
                    break;
                }
            }, userData);
            Event.current.Use();
        }
示例#5
0
        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);
            }
        }
示例#6
0
        public IEnumerator DoEditorUpdate(PlanetPanel panel)
        {
            m_Panel = panel;
            transform.localPosition = Vector3.zero;
            yield return(null);

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

            if (m_PlanetAreas != null && m_PlanetAreas.Count > 0)
            {
                for (int iPlanet = 0; iPlanet < m_PlanetAreas.Count; iPlanet++)
                {
                    PlanetAreaElement element        = m_PlanetAreas[iPlanet];
                    IEnumerator       elementEnumera = element.DoEditorUpdate(this);
                    while (element != null && element.gameObject != null && elementEnumera.MoveNext())
                    {
                        yield return(null);
                    }
                }
            }
            yield return(null);

            if (m_MiniMap != null)
            {
                m_MiniMap.localScale = Vector3.one;
            }
            yield return(null);

            Transform containerTrans = transform.Find("FixedStarContainer");

            if (containerTrans == null)
            {
                GameObject fixedContainer = new GameObject("FixedStarContainer");
                fixedContainer.transform.SetParent(transform);
                Image image = fixedContainer.AddComponent <Image>();
                m_FixedStarContainer = image;
            }
            else
            {
                m_FixedStarContainer = containerTrans.GetOrAddComponent <Image>(true);
            }
            m_FixedStarContainer.rectTransform.anchoredPosition3D = m_FixedStarPos;
            m_FixedStarContainer.rectTransform.sizeDelta          = m_FixedStarScale;
            m_FixedStarContainer.transform.localScale             = Vector3.one;
            if (m_FixedStarContainer != null)
            {
                if (m_MiniMap != null)
                {
                    int miniIndex = m_MiniMap.GetSiblingIndex();
                    m_FixedStarContainer.transform.SetSiblingIndex(miniIndex + 1);
                }
                else
                {
                    m_FixedStarContainer.transform.SetSiblingIndex(0);
                }
            }
            yield return(null);

            if (m_FixedStarObj != null)
            {
                m_FixedStarRes = m_FixedStarObj.name;
            }
            else
            {
                m_FixedStarRes = "";
            }

            //if(m_FixedStarContainer != null)
            //{
            //    int childCount = m_FixedStarContainer.transform.childCount;
            //    if(m_FixedStarObj != null)
            //    {
            //        GameObject fixedStarObj = null;
            //        if (childCount > 0)
            //        {
            //            fixedStarObj = m_FixedStarContainer.GetChild(0).gameObject;
            //            if(fixedStarObj.name != m_FixedStarObj.name)
            //            {
            //                GameObject.DestroyImmediate(fixedStarObj);
            //                childCount = m_FixedStarContainer.transform.childCount;
            //            }
            //        }
            //        if(childCount <=0)
            //        {
            //            fixedStarObj = GameObject.Instantiate(m_FixedStarObj, m_FixedStarContainer);
            //            fixedStarObj.name = m_FixedStarObj.name;
            //        }
            //        fixedStarObj.transform.localPosition = Vector3.zero; ;
            //        fixedStarObj.transform.localScale = Vector3.one;
            //    }
            //    else
            //    {
            //        for (int iChild = childCount - 1; iChild >= 0; iChild--)
            //        {
            //            GameObject.DestroyImmediate(m_FixedStarContainer.GetChild(iChild).gameObject);
            //        }
            //    }

            //}
        }