Ejemplo n.º 1
0
        protected override IEnumerator DoExport()
        {
            List <AreaSpawner> areaSpawnerList = m_Map.GetAreaSpawnerList();

            if (areaSpawnerList != null && areaSpawnerList.Count > 0)
            {
                for (int iArea = 0; iArea < areaSpawnerList.Count; iArea++)
                {
                    AreaSpawner areaSpawner = areaSpawnerList[iArea];
                    if (areaSpawner != null)
                    {
                        if (m_ExportAreaIds != null && m_ExportAreaIds.Contains(areaSpawner.GetAreaId()))
                        {
                            m_GamingMap.LoadGamingMapArea(areaSpawner, false);
                        }
                        yield return(null);
                    }
                }
            }
            yield return(null);

            m_GamingMap.InitGamingArea();
            yield return(null);

            m_GamingMap.BeginExport();
            yield return(null);

            IEnumerator updateAreaEnum = m_GamingMap.UpdataGamingAreas(true);

            if (updateAreaEnum != null)
            {
                while (updateAreaEnum.MoveNext())
                {
                    yield return(null);
                }
            }
            yield return(null);

            //刷新LeapOverview
            if (m_GamingMap.m_LeapOverview != null)
            {
                IEnumerator leapOverviewUpdate = m_GamingMap.m_LeapOverview.OnUpdate(m_GamingMap);
                if (leapOverviewUpdate != null)
                {
                    while (leapOverviewUpdate != null && leapOverviewUpdate.MoveNext())
                    {
                        yield return(null);
                    }
                }
            }
            yield return(null);

            EditorGamingMapData.SaveGamingMapToJson(m_GamingMap, m_ExportAreaIds);
            yield return(null);

            m_GamingMap.EndExport();
            yield return(null);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// 初始化
 /// </summary>
 /// <param name="areaId"></param>
 public void Init(AreaSpawner areaSpawner, GamingMap map)
 {
     m_GamingMap = map;
     m_AreaId    = areaSpawner.GetAreaId();
     //gameObject.name = string.Format("Area_{0}", m_AreaId);
     //gameObject.name = string.Format("Area_{0}", m_AreaName);
     gameObject.name = string.Format("{0}_{1}", m_AreaName, m_AreaId);
     AdjustTransform(areaSpawner);
     RefreshAreaInfo();
 }
Ejemplo n.º 3
0
        /// <summary>
        /// 创建GameArea
        /// </summary>
        /// <param name="areaSpawner"></param>
        private void CreateGamingArea(AreaSpawner areaSpawner)
        {
            string areaTemplete = "";
            GamingMapEditorSetting gamingSetting = GamingMapEditorUtility.GetGamingMapEditorSetting();

            if (gamingSetting != null)
            {
                areaTemplete = gamingSetting.m_GamingAreaTemplete;
            }
            GameObject areaTempleteAsset = AssetDatabase.LoadAssetAtPath <GameObject>(areaTemplete);
            GameObject obj = Instantiate(areaTempleteAsset);

            obj.name = string.Format("Area_{0}", areaSpawner.GetAreaId());
            obj.transform.SetParent(transform);
            GamingMapArea area = obj.GetComponent <GamingMapArea>();

            if (area == null)
            {
                area = obj.AddComponent <GamingMapArea>();
            }
            area.Init(areaSpawner, this);
            m_GamingAreaList.Add(area);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 刷新GamingMap ui
        /// </summary>
        /// <param name="map"></param>
        private void RefreshMapUI(GamingMap gamingMap)
        {
            if (gamingMap == null)
            {
                return;
            }

            m_ContentCache.Clear();
            m_ContentCache.Add(new GUIContent("导出数据到json"));
            m_ContentCache.Add(new GUIContent("保存"));
            Scene scene = gamingMap.GetMapScene();

            if (!scene.isLoaded)
            {
                gamingMap.OpenMapScene();
            }

            Map map = null;

            GameObject[] rootObjs = scene.GetRootGameObjects();
            if (rootObjs != null && rootObjs.Length > 0)
            {
                for (int iRoot = 0; iRoot < rootObjs.Length; iRoot++)
                {
                    GameObject obj = rootObjs[iRoot];
                    map = obj.GetComponent <Map>();
                    if (map != null)
                    {
                        break;
                    }
                }
            }
            if (map != null)
            {
                List <AreaSpawner> areaSpawnerList = map.GetAreaSpawnerList();
                if (areaSpawnerList != null && areaSpawnerList.Count > 0)
                {
                    for (int iArea = 0; iArea < areaSpawnerList.Count; iArea++)
                    {
                        AreaSpawner areaSpawner = areaSpawnerList[iArea];
                        GUIContent  content     = new GUIContent(string.Format("区域/GamingArea_{0}", areaSpawner.GetAreaId()));
                        m_ContentCache.Add(content);
                    }
                }
            }

            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:
                    //BeginExportGamingMap(gamingMap,map);
                    List <ulong> areaIds = new List <ulong>();
                    List <Leap> allLeaps = m_LeapOverview.m_LeapList;
                    if (allLeaps != null && allLeaps.Count > 0)
                    {
                        for (int iLeap = 0; iLeap < allLeaps.Count; iLeap++)
                        {
                            if (allLeaps[iLeap].m_IsExportToJson)
                            {
                                areaIds.Add(allLeaps[iLeap].m_LeapId);
                            }
                        }
                    }
                    new ExportGamingMapData().BeginExport(map, gamingMap, areaIds);
                    break;

                case 1:                                //保存
                    gamingMap.SaveScene();
                    break;

                default:
                    gamingMap.OnClickArea(select, map);
                    break;
                }
            }, userData);
            Event.current.Use();
        }
Ejemplo n.º 5
0
        public void LoadGamingMapArea(AreaSpawner areaSpawner, bool closeOtherArea = true)
        {
            if (areaSpawner == null)
            {
                return;
            }
            string m_AreaScenePath = string.Format("{0}/GamingMapArea_{1}_{2}.unity", GetOwnerAreaPath(), m_Uid, areaSpawner.GetAreaId());

            if (string.IsNullOrEmpty(m_AreaScenePath))
            {
                Debug.LogError("m_AreaScenePath == null");
                return;
            }

            GamingMapArea[] areaArray = UnityEngine.Object.FindObjectsOfType <GamingMapArea>();
            if (areaArray != null && areaArray.Length > 0)
            {
                for (int iArea = 0; iArea < areaArray.Length; iArea++)
                {
                    GamingMapArea area = areaArray[iArea];
                    if (area != null && area.m_AreaId == areaSpawner.GetAreaId())
                    {
                        //Debug.LogError(string.Format("{0}Area已导入", area.m_AreaId));
                        return;
                    }
                }
            }
            if (closeOtherArea)
            {
                SaveOtherGamingArea();
            }
            string areaScenePath = m_AreaScenePath.Replace("Assets", Application.dataPath);
            Scene  areaScene;

            if (!File.Exists(areaScenePath))
            {
                string gamingAreaPath = "";
                GamingMapEditorSetting gamingSetting = GamingMapEditorUtility.GetGamingMapEditorSetting();
                if (gamingSetting != null)
                {
                    gamingAreaPath = gamingSetting.m_GamingAreaTemplete;
                }
                areaScene = EditorSceneManager.NewScene(NewSceneSetup.EmptyScene, NewSceneMode.Additive);
                GameObject    areaTempleteAsset = AssetDatabase.LoadAssetAtPath <GameObject>(gamingAreaPath);
                GameObject    gamingArea        = GameObject.Instantiate(areaTempleteAsset);
                GamingMapArea mapArea           = gamingArea.GetComponent <GamingMapArea>();
                mapArea.Init(areaSpawner, this);
                EditorSceneManager.MoveGameObjectToScene(gamingArea, areaScene);
                EditorSceneManager.SaveScene(areaScene, m_AreaScenePath);
                EditorSceneManager.CloseScene(areaScene, true);
                AssetDatabase.Refresh();
            }

            areaScene = EditorSceneManager.OpenScene(m_AreaScenePath, OpenSceneMode.Additive);
            if (areaScene != null)
            {
                GamingMapArea mapArea  = null;
                GameObject[]  rootObjs = areaScene.GetRootGameObjects();
                if (rootObjs != null && rootObjs.Length > 0)
                {
                    for (int rIndex = 0; rIndex < rootObjs.Length; rIndex++)
                    {
                        mapArea = rootObjs[rIndex].GetComponent <GamingMapArea>();
                        if (mapArea != null)
                        {
                            break;
                        }
                    }
                }
                if (mapArea != null)
                {
                    EditorSceneManager.MoveGameObjectToScene(mapArea.gameObject, GetOwnerScene());
                    mapArea.transform.SetParent(transform);
                }
                EditorSceneManager.CloseScene(areaScene, true);
            }
        }
Ejemplo n.º 6
0
        public IEnumerator GenerateAreaDecorate(EditorCollider outData, List <EditorDecorate> editorDecorateList)
        {
            if (m_Map.m_AreaSpawnerCache != null && m_Map.m_AreaSpawnerCache.Count > 0)
            {
                EditorColliderArea[] areaList = new EditorColliderArea[m_Map.m_AreaSpawnerCache.Count];
                outData.areaList = areaList;
                List <GameObject> prefabList = new List <GameObject>();
                for (int iArea = 0; iArea < m_Map.m_AreaSpawnerCache.Count; iArea++)
                {
                    editorDecorateList.Clear();
                    EditorColliderArea editorArea = new EditorColliderArea();
                    areaList[iArea] = editorArea;
                    AreaSpawner areaSpawner = m_Map.m_AreaSpawnerCache[iArea];
                    Area        area        = areaSpawner.GetArea();

                    string areaName = areaSpawner.GetAreaScenePath();
                    while (!string.IsNullOrEmpty(areaName) && area == null)
                    {
                        area = areaSpawner.GetArea();
                        yield return(null);
                    }

                    editorArea.areaId = areaSpawner.GetAreaId();
                    if (area != null)
                    {
                        EditorGamingMapData.CorrectAreaColliderCenter(area);
                        yield return(null);

                        yield return(null);

                        prefabList.Clear();
                        MapEditorUtility.GetAllPrefab(area.transform, prefabList);
                        if (prefabList != null && prefabList.Count > 0)
                        {
                            for (int iUnit = 0; iUnit < prefabList.Count; iUnit++)
                            {
                                GameObject       unit          = prefabList[iUnit];
                                List <Transform> colliderRoots = MapEditorUtility.FindChilds <Transform>(unit.transform, "Collider");
                                if (colliderRoots == null || colliderRoots.Count <= 0)
                                {
                                    continue;
                                }
                                for (int iRoot = 0; iRoot < colliderRoots.Count; iRoot++)
                                {
                                    Transform colliderRoot = colliderRoots[iRoot];
                                    if (colliderRoot != null)
                                    {
                                        Collider[] colliders = colliderRoot.GetComponentsInChildren <Collider>();
                                        if (colliders != null && colliders.Length > 0)
                                        {
                                            for (int iCollider = 0; iCollider < colliders.Length; iCollider++)
                                            {
                                                EditorUtility.DisplayProgressBar("GenerateAreaDecorate", string.Format("{0} {1}", area.name, colliders[iCollider].gameObject.name), (iArea + 1) * 1.0f / m_Map.m_AreaSpawnerCache.Count);
                                                Quaternion rot = colliders[iCollider].transform.rotation;
                                                colliders[iCollider].transform.rotation = Quaternion.identity;
                                                yield return(null);

                                                EditorDecorate decorate = EditorGamingMapData.SaveColliderData(colliders[iCollider], rot, true);
                                                yield return(null);

                                                colliders[iCollider].transform.rotation = rot;
                                                if (decorate != null)
                                                {
                                                    decorate.id = m_AutoId++;
                                                    editorDecorateList.Add(decorate);
                                                }
                                                CheckColliderLayer(colliders[iCollider]);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        editorArea.decorateList = editorDecorateList.ToArray();
                    }
                    else
                    {
                        Debug.LogError(string.Format("Area {0} 未加载进来", areaSpawner.GetAreaId()));
                    }
                    yield return(null);

                    EditorUtility.ClearProgressBar();
                }
            }
        }