Exemple #1
0
        private IEnumerator DoAnalyzeArea(Map map, AreaSpawner areaSpawner, bool showDialog = true)
        {
            string areaName   = areaSpawner.GetAreaScenePath();
            Area   exportArea = null;
            Scene  areaScene  = EditorSceneManager.OpenScene(areaName, OpenSceneMode.Additive);

            if (areaScene != null)
            {
                SceneManager.SetActiveScene(areaScene);
                GameObject[] rootObjArray = areaScene.GetRootGameObjects();
                if (rootObjArray != null && rootObjArray.Length > 0)
                {
                    for (int index = 0; index < rootObjArray.Length; index++)
                    {
                        SceneManager.MoveGameObjectToScene(rootObjArray[index], map.GetOwnerScene());
                        Area area = rootObjArray[index].GetComponent <Area>();
                        if (area != null)
                        {
                            exportArea = area;
                        }
                    }
                }
                EditorSceneManager.CloseScene(areaScene, true);
            }
            yield return(null);

            if (exportArea != null)
            {
                areaSpawner.SetArea(exportArea);
                IEnumerator areaSpawnerEnumerator = areaSpawner.DoUpdate(map, true);
                while (areaSpawnerEnumerator.MoveNext())
                {
                    yield return(null);
                }
                //TODO: 1、计算area的直径  2、计算所有unit的直径 3、算出推荐格子大小 对应层AABB范围
                //如果大于等于Area直径的90%以上的unit数量大于0 算一个层
                Bounds areaAABB        = exportArea.GetAABB();
                float  areaDiameter    = Mathf.Max(areaAABB.size.x, areaAABB.size.y, areaAABB.size.z);
                float  consultDiameter = areaDiameter * 0.9f;
                CalcuateLayer(map, exportArea, areaDiameter);
                EditorUtility.SetDirty(m_EditorSplitAreaSetting);
                GameObject.DestroyImmediate(exportArea.gameObject);
            }
            EditorUtility.ClearProgressBar();
            if (showDialog)
            {
                EditorUtility.DisplayDialog("Analyze", "分析成功", "OK");
            }
            AssetDatabase.Refresh();
        }
        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();
                }
            }
        }