Пример #1
0
 private void OnEnable()
 {
     m_MapSetting              = MapEditorUtility.GetMapEditorSetting();
     m_MapTempletePath         = m_MapSetting.m_MapTempletePath;
     m_MapSavePath             = m_MapSetting.m_MapSavePath;
     m_AreaSpawnerTempletePath = m_MapSetting.m_AreaSpawnerTempletePath;
 }
Пример #2
0
        /// <summary>
        /// 获取所有的Map路径
        /// </summary>
        /// <returns></returns>
        public static List <string> GetMapScenePath()
        {
            List <string>    mapPaths     = new List <string>();
            string           mapScenePath = "";
            MapEditorSetting mapSetting   = MapEditorUtility.GetMapEditorSetting();

            if (mapSetting != null)
            {
                mapScenePath = mapSetting.m_MapSavePath;
            }
            string[] mapPathArray = AssetDatabase.FindAssets("t:Scene", new string[] { mapScenePath });
            if (mapPathArray != null && mapPathArray.Length > 0)
            {
                for (int iMap = 0; iMap < mapPathArray.Length; iMap++)
                {
                    string   assetPath = AssetDatabase.GUIDToAssetPath(mapPathArray[iMap]);
                    string[] pathSplit = assetPath.Split('/');
                    if (pathSplit != null && pathSplit.Length > 0)
                    {
                        if (pathSplit[pathSplit.Length - 1].Contains("Map_"))
                        {
                            mapPaths.Add(assetPath);
                        }
                    }
                }
            }
            return(mapPaths);
        }
Пример #3
0
        private void OnEndExport()
        {
            GameObject.DestroyImmediate(gameObject);
            GamingMapEditorSetting gamingSetting = GamingMapEditorUtility.GetGamingMapEditorSetting();

            MapEditorUtility.OpenFolder(MapEditorUtility.GetFullPath(gamingSetting.m_ConfigPath));
        }
Пример #4
0
        public static ExportParameter CreateExportParameter()
        {
            ExportParameter exportParameter = new ExportParameter();

            exportParameter.ExportedUnitAddressableKeys = new HashSet <string>();
            MapEditorSetting mapEditorSetting = MapEditorUtility.GetOrCreateMapEditorSetting();

            string exportAssetPath = string.Format("{0}/Units"
                                                   , mapEditorSetting.AssetExportDirectory);

            string[] resAssets = AssetDatabase.FindAssets("t:Prefab", new string[] { exportAssetPath });
            if (resAssets != null && resAssets.Length > 0)
            {
                for (int iRes = 0; iRes < resAssets.Length; iRes++)
                {
                    string   resPath  = AssetDatabase.GUIDToAssetPath(resAssets[iRes]);
                    string[] resSplit = resPath.Split('/');
                    if (resSplit != null && resSplit.Length > 0)
                    {
                        string   lastName      = resSplit[resSplit.Length - 1];
                        string[] lastNameSplit = lastName.Split('_');
                        if (lastNameSplit != null && lastNameSplit.Length == 2)
                        {
                            lastName = lastName.Replace(".prefab", "");
                            exportParameter.ExportedUnitAddressableKeys.Add(lastName);
                        }
                    }
                }
            }
            return(exportParameter);
        }
Пример #5
0
        private IEnumerator Export_Co()
        {
            yield return(null);

            ExportParameter exportParameter = MapEditorUtility.CreateExportParameter();

            exportParameter.ThrowExceptionAtAbort       = true;
            exportParameter.ExportedUnitAddressableKeys = new HashSet <string>();

            string[] sceneGuids = AssetDatabase.FindAssets("t:Scene");
            for (int iScene = 0; iScene < sceneGuids.Length; iScene++)
            {
                Scene        iterScene       = EditorSceneManager.OpenScene(AssetDatabase.GUIDToAssetPath(sceneGuids[iScene]), OpenSceneMode.Single);
                GameObject[] rootGameObjects = iterScene.GetRootGameObjects();
                for (int iRootGameObject = 0; iRootGameObject < rootGameObjects.Length; iRootGameObject++)
                {
                    GameObject iterGameObject = rootGameObjects[iRootGameObject];
                    Map        iterMap        = iterGameObject.GetComponent <Map>();
                    if (iterMap)
                    {
                        //ExporterHandle handle = new Exporter().BeginExport(iterMap, MapEditorUtility.GetOrCreateMapEditorSetting().ExportAllMapSetting, exportParameter);

                        ExporterHandle handle = new Exporter().BeginExport(iterMap, MapEditorUtility.GetOrCreateMapEditorSetting().ExportAllMapSetting, exportParameter, iterMap.GetAreaSpawnerList(), true);
                        while (!handle.IsDone)
                        {
                            yield return(null);
                        }
                    }
                }
            }
        }
Пример #6
0
        protected override IEnumerator DoExport()
        {
            if (m_IsCleanAll)
            {
                //TODO:导出前先清除所有的unit
                MapEditorSetting mapEditorSetting = MapEditorUtility.GetMapEditorSetting();
                string           exportAssetPath  = string.Format("{0}/{1}"
                                                                  , mapEditorSetting.AssetExportDirectory
                                                                  , Constants.UNIT_PREFAB_EXPORT_DIRECTORY);
                exportAssetPath = MapEditorUtility.GetFullPath(exportAssetPath);

                string[] unitFiles = Directory.GetFiles(exportAssetPath, "*.prefab", SearchOption.AllDirectories);

                if (unitFiles != null && unitFiles.Length > 0)
                {
                    UTF8Encoding utf8 = new UTF8Encoding(false);
                    for (int iFile = 0; iFile < unitFiles.Length; iFile++)
                    {
                        EditorUtility.DisplayProgressBar("删除所有unit", unitFiles[iFile], iFile * 1.0f / unitFiles.Length);
                        File.Delete(unitFiles[iFile]);
                        yield return(null);
                    }
                }
                EditorUtility.ClearProgressBar();
                AssetDatabase.Refresh();
            }
            yield return(null);

            if (m_MapPaths != null && m_MapPaths.Count > 0)
            {
                for (int iMap = 0; iMap < m_MapPaths.Count; iMap++)
                {
                    string       mapPath         = m_MapPaths[iMap];
                    Scene        iterScene       = EditorSceneManager.OpenScene(mapPath, OpenSceneMode.Single);
                    GameObject[] rootGameObjects = iterScene.GetRootGameObjects();
                    for (int iRootGameObject = 0; iRootGameObject < rootGameObjects.Length; iRootGameObject++)
                    {
                        GameObject iterGameObject = rootGameObjects[iRootGameObject];
                        Map        iterMap        = iterGameObject.GetComponent <Map>();
                        if (iterMap)
                        {
                            ExporterHandle handle = iterMap.ExportMap();
                            while (!handle.IsDone)
                            {
                                yield return(null);
                            }
                        }
                    }
                }
            }
            yield return(null);

            ///导出所有结束后 把公用unit放到单独目录下
            IEnumerator findCommonUnitsEnumerator = new Exporter().FindCommonUnits();

            while (findCommonUnitsEnumerator.MoveNext())
            {
                yield return(null);
            }
        }
Пример #7
0
        /// <summary>
        /// 加载MapScene
        /// </summary>
        public void LoadMapScene()
        {
            UnLoadMapScene();
            string           sceneName        = Constants.EXPORT_MAP_FOLDER_NAME_STARTWITHS + GetMapUid();
            MapEditorSetting mapEditorSetting = MapEditorUtility.GetOrCreateMapEditorSetting();
            string           scenePath        = string.Format("{0}/{1}/{2}{3}.unity"
                                                              , mapEditorSetting.AssetExportDirectory
                                                              , sceneName
                                                              , Constants.SCENE_EXPORT_FILENAMESTARTWITHS
                                                              , GetMapUid());

            if (!File.Exists(scenePath))
            {
                EditorUtility.DisplayDialog("提示", "未导出对应的MapScene", "确定");
                return;
            }
            if (Application.isPlaying)
            {
                Scene scene = SceneManager.GetSceneByPath(scenePath);
                if (!scene.isLoaded)
                {
                    m_MapScene = scene;
                    SceneManager.LoadScene(scenePath, LoadSceneMode.Additive);
                }
            }
            else
            {
                m_MapScene = EditorSceneManager.OpenScene(scenePath, OpenSceneMode.Additive);
            }
        }
        private void OnEnable()
        {
            m_SelectTypeIndex = 0;
            if (m_RelationSceneList == null)
            {
                m_RelationSceneList = new List <string>();
            }
            m_RelationSceneList.Clear();
            string           mapScenePath = "";
            MapEditorSetting mapSetting   = MapEditorUtility.GetMapEditorSetting();

            if (mapSetting != null)
            {
                mapScenePath = mapSetting.m_MapSavePath;
            }
            string[] mapPathArray = AssetDatabase.FindAssets("t:Scene", new string[] { mapScenePath });
            if (mapPathArray != null && mapPathArray.Length > 0)
            {
                for (int iMap = 0; iMap < mapPathArray.Length; iMap++)
                {
                    string   assetPath = AssetDatabase.GUIDToAssetPath(mapPathArray[iMap]);
                    string[] pathSplit = assetPath.Split('/');
                    if (pathSplit != null && pathSplit.Length > 0)
                    {
                        if (pathSplit[pathSplit.Length - 1].Contains("Map_"))
                        {
                            m_RelationSceneList.Add(assetPath);
                        }
                    }
                }
            }
        }
Пример #9
0
        public IEnumerator DoUpdate_Co(Map map, int indexInMap, bool isExporting, AreaSpawner areaSpawner = null)
        {
            m_Leap         = GetComponentInChildren <MapLeap>();
            m_TreasureRoot = GetComponentInChildren <TreasureRootMark>();
            if (m_TreasureRoot != null)
            {
                IEnumerator treasureEnumerator = m_TreasureRoot.DoUpdate();
                if (treasureEnumerator != null)
                {
                    while (treasureEnumerator.MoveNext())
                    {
                        yield return(null);
                    }
                }
            }
            yield return(null);

            map.LoadExtenInfo(this);
            m_MineralRoot = GetComponentInChildren <MineralRootMark>();
            if (m_MineralRoot != null)
            {
                IEnumerator mineralEnumerator = m_MineralRoot.DoUpdate();
                if (mineralEnumerator != null)
                {
                    while (mineralEnumerator.MoveNext())
                    {
                        yield return(null);
                    }
                }
            }
            yield return(null);

            if (m_Leap != null)
            {
                m_Leap.DoUpdate(areaSpawner.m_AreaUid);
            }
            m_OwnerMap           = map;
            m_OwnerAreaSpawner   = areaSpawner;
            transform.localScale = Vector3.one;            // 美术说Area不会有缩放
            if (m_OwnerAreaSpawner != null)
            {
                gameObject.name = m_OwnerAreaSpawner.GetAreaSpawnObjName();
            }
            Bounds areaAABB = new Bounds();

            MapEditorUtility.CaculateAABB(transform, ref areaAABB, isExporting);
            m_AABB     = areaAABB;
            m_Diameter = MathUtility.CaculateDiagonal(m_AABB);
            if (VoxelGrid != null)
            {
                VoxelGrid.DoUpdate(m_AABB);
            }

            _Debug.DoUpdate(this);
        }
Пример #10
0
            public void InitMapUids()
            {
                _MapUids = new List <uint>();

                MapEditorSetting mapEditorSetting = MapEditorUtility.GetMapEditorSetting();

                string[] mapPathArray = AssetDatabase.FindAssets("t:Scene", new string[] { mapEditorSetting != null ? mapEditorSetting.m_MapSavePath : "" });
                if (mapPathArray == null)
                {
                    return;
                }

                for (int iMap = 0; iMap < mapPathArray.Length; iMap++)
                {
                    string   assetPath      = AssetDatabase.GUIDToAssetPath(mapPathArray[iMap]);
                    string[] pathSplitArray = assetPath.Split('/');
                    if (pathSplitArray.Length == 0)
                    {
                        continue;
                    }

                    string pathSplit = pathSplitArray[pathSplitArray.Length - 1];
                    if (!pathSplit.Contains("Map_"))
                    {
                        continue;
                    }
                    pathSplit = pathSplit.Replace(".unity", "");

                    string[] splitPath = pathSplit.Split('/');
                    if (splitPath.Length == 0)
                    {
                        continue;
                    }

                    string showPath = splitPath[splitPath.Length - 1];
                    if (string.IsNullOrEmpty(showPath))
                    {
                        continue;
                    }

                    string[] showPathArray = showPath.Split('_');
                    if (showPathArray.Length != 2)
                    {
                        continue;
                    }

                    if (uint.TryParse(showPathArray[1], out uint result) &&
                        result > 0)
                    {
                        _MapUids.Add(result);
                    }
                }
            }
Пример #11
0
        private void InstantiateUnit(SceneUnitInfo unitInfo, Transform parent)
        {
            if (m_Owner.UseAsset)
            {
                AssetUtil.InstanceAssetAsync(m_AreaDetailInfo.AssetInfos[unitInfo.AssetIndex].AddressableKey, (pathOrAddress, uObj, userData) =>
                {
                    if (uObj != null)
                    {
                        GameObject resultObj = uObj as GameObject;
                        if (resultObj != null)
                        {
                            m_WaitInstantiateCount--;
                            Transform t = resultObj.transform;
                            t.SetParent(m_UnitsRoot);
                            t.localPosition = unitInfo.LocalPosition;
                            t.localRotation = unitInfo.LocalRotation;
                            t.localScale    = unitInfo.LocalScale;
                        }
                    }
                });
            }
            else
            {
                m_WaitInstantiateCount--;
                string path = string.Format("{0}/{1}Map_{2}/{3}.prefab"
                                            , MapEditorUtility.GetOrCreateMapEditorSetting().AssetExportDirectory
                                            , Constants.UNIT_PREFAB_EXPORT_DIRECTORY
                                            , m_Owner.MapInfo.Uid
                                            , m_AreaDetailInfo.AssetInfos[unitInfo.AssetIndex].AddressableKey);

                GameObject asset = AssetDatabase.LoadAssetAtPath <GameObject>(path);
                if (asset == null)
                {
                    string[] paths = AssetDatabase.FindAssets(m_AreaDetailInfo.AssetInfos[unitInfo.AssetIndex].AddressableKey);
                    if (paths != null && paths.Length > 0)
                    {
                        path  = AssetDatabase.GUIDToAssetPath(paths[0]);
                        asset = AssetDatabase.LoadAssetAtPath <GameObject>(path);
                    }
                }

                if (asset != null)
                {
                    Transform t = Instantiate(asset).transform;
                    t.SetParent(parent);
                    t.localPosition = unitInfo.LocalPosition;
                    t.localRotation = unitInfo.LocalRotation;
                    t.localScale    = unitInfo.LocalScale;
                }
            }
        }
Пример #12
0
        public void ExportArea()
        {
            ExportData exportData = new ExportData();

            exportData.m_Map             = m_Map;
            exportData.m_ExportParameter = MapEditorUtility.CreateExportParameter();
            exportData.m_AreaSpawners    = new List <AreaSpawner>()
            {
                this
            };
            SplitAreaWindow.OpenWindow(exportData);
            //老版导出设置
            //new Exporter().BeginExport(m_Map, m_Map.ExportSetting, new ExportParameter(),new List<AreaSpawner>() { this});
        }
Пример #13
0
        private IEnumerator GenerateResidentDecorate(List <EditorDecorate> editorDecorateList)
        {
            DontDestroyAtExport residentRoot = UnityEngine.Object.FindObjectOfType <DontDestroyAtExport>();

            if (residentRoot != null)
            {
                List <Transform> colliderRoots = MapEditorUtility.FindChilds <Transform>(residentRoot.transform, "Collider");
                if (colliderRoots == null || colliderRoots.Count <= 0)
                {
                    yield break;
                }

                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++)
                            {
                                EditorGamingMapData.CorrectCollider(colliders[iCollider]);
                                yield return(null);

                                yield return(null);

                                Quaternion rot = colliders[iCollider].transform.rotation;
                                colliders[iCollider].transform.rotation = Quaternion.identity;
                                yield return(null);

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

                                colliders[iCollider].transform.rotation = rot;
                                if (decorate != null)
                                {
                                    decorate.id = m_AutoId++;
                                    editorDecorateList.Add(decorate);
                                }
                                CheckColliderLayer(colliders[iCollider]);
                            }
                        }
                    }
                }
            }
            yield return(null);
        }
Пример #14
0
        private string GetMapScenePath()
        {
            string           sceneName  = "";
            MapEditorSetting mapSetting = MapEditorUtility.GetMapEditorSetting();

            if (mapSetting != null)
            {
                sceneName = mapSetting.m_MapSavePath;
            }
            string scenePath = string.Format("{0}\\Map_{1}.unity"
                                             , sceneName
                                             , this.m_MapId);

            scenePath = scenePath.Replace("\\", "/");
            return(scenePath);
        }
Пример #15
0
        private bool TryLoadAreaDetailInfo()
        {
            if (m_AreaDetailInfo == null)
            {
                string areaDetailInfoPath = string.Format("{0}/{1}{2}/{3}.asset"
                                                          , MapEditorUtility.GetOrCreateMapEditorSetting().AssetExportDirectory
                                                          , Constants.EXPORT_MAP_FOLDER_NAME_STARTWITHS
                                                          , m_Owner.GetMapUid()
                                                          , AreaInfo.DetailInfoAddressableKey);
                m_AreaDetailInfo = AssetDatabase.LoadAssetAtPath <AreaDetailInfo>(areaDetailInfoPath);
                if (areaDetailInfoPath == null)
                {
                    Debug.LogError(string.Format("cant find file ({0})", areaDetailInfoPath));
                }
            }

            return(m_AreaDetailInfo != null);
        }
Пример #16
0
		/// <summary>
		/// 初始化
		/// </summary>
		public void Init()
		{
            m_GamingSetting = GamingMapEditorUtility.GetGamingMapEditorSetting();
            m_MapSetting = MapEditorUtility.GetMapEditorSetting();
            m_SelectIndex = -1;
			m_GuiStyle = new GUIStyle();
			m_GuiStyle.fontSize = 20;
			m_GuiStyle.fontStyle = FontStyle.BoldAndItalic;
			m_GuiContentArray = new GUIContent[] { new GUIContent("创建地图配置"), new GUIContent("打开地图配置列表"),new GUIContent("创建地图") };

			m_GamingMapPath = m_GamingSetting.m_GamingMapPath;
			m_GamingMapTemplete = m_GamingSetting.m_GamingMapTemplete;
			m_GamingAreaTemplete = m_GamingSetting.m_GamingAreaTemplete;
			m_ConfigPath = m_GamingSetting.m_ConfigPath;
			m_JsonPath = m_GamingSetting.m_JsonPath;
			m_CreatureTempletePath = m_GamingSetting.m_CreatureTempletePath;
			m_LocationTempletePath = m_GamingSetting.m_LocationTempletePath;
            m_LeapTempletePath = m_GamingSetting.m_LeapTempletePath;
            m_TriggerTempletePath = m_GamingSetting.m_TriggerTempletePath;
            m_MaxShipPath = m_GamingSetting.m_MaxShipPath;
            m_StarMapPath = m_GamingSetting.m_StarMapPath;
            m_SpacecraftPropertyPath = m_GamingSetting.m_SpacecraftPropertyPath;

            m_MapTempletePath = m_MapSetting.m_MapTempletePath;
            m_TreasurePrefabSavePath = m_MapSetting.m_TreasurePrefabSavePath;
            m_MapSavePath = m_MapSetting.m_MapSavePath;
			m_AreaSpawnerTempletePath = m_MapSetting.m_AreaSpawnerTempletePath;
            m_ColliderSavePath = m_MapSetting.m_ColliderSavePath;
            m_ColliderSavePathCopy = m_MapSetting.m_ColliderSavePathCopy;
            m_MineralPrefabSavePath = m_MapSetting.m_MineralPrefabSavePath;
            /*m_GamingMapPath = PlayerPrefsUtility.GetString(Constants.GAMINGMAP_SAVE_PATH);
			m_GamingMapTemplete = PlayerPrefsUtility.GetString(Constants.GAMINGMAP_TEMPLETE_PATH);
			m_GamingAreaTemplete = PlayerPrefsUtility.GetString(Constants.GAMINGAREA_TEMPLETE_PATH);
			m_ConfigPath = PlayerPrefsUtility.GetString(Constants.CONFIG_PATH);
			m_JsonPath = PlayerPrefsUtility.GetString(Constants.SAVEJSON_PATH);

			m_CreatureTempletePath = PlayerPrefsUtility.GetString(Constants.CREATURE_TEMPLETE_PATH);
			m_LocationTempletePath = PlayerPrefsUtility.GetString(Constants.LOCATION_TEMPLETE_PATH);

			m_MapTempletePath = PlayerPrefsUtility.GetString(Constants.MAP_TEMPLETE_PATH);
			m_MapSavePath = PlayerPrefsUtility.GetString(Constants.MAP_SAVE_PATH);
			m_AreaSpawnerTempletePath = PlayerPrefsUtility.GetString(Constants.AREASPAWNER_TEMPLETE_PATH);*/
        }
Пример #17
0
        private void OnGUI()
        {
            GUILayout.BeginVertical("box");
            GUILayout.BeginHorizontal();
            m_MapId = EditorGUILayout.TextField("地图ID:", m_MapId);
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("地图模板路径:", m_MapTempletePath);
            if (GUILayout.Button("选择"))
            {
                m_MapTempletePath = MapEditorUtility.OpenFilePanel("", "unity");
                m_MapTempletePath = MapEditorUtility.GetRelativePath(m_MapTempletePath);
                m_MapSetting.m_MapTempletePath = m_MapTempletePath;
            }
            GUILayout.EndHorizontal();
            GUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("地图保存路径:", m_MapSavePath);
            if (GUILayout.Button("选择"))
            {
                m_MapSavePath = MapEditorUtility.OpenFloderPanel();
                m_MapSavePath = MapEditorUtility.GetRelativePath(m_MapSavePath);
                m_MapSetting.m_MapSavePath = m_MapSavePath;
            }
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("AreaSpawner模板路径:", m_AreaSpawnerTempletePath);
            if (GUILayout.Button("选择"))
            {
                m_AreaSpawnerTempletePath = MapEditorUtility.OpenFilePanel("", "prefab");
                m_AreaSpawnerTempletePath = MapEditorUtility.GetRelativePath(m_MapSavePath);
                m_MapSetting.m_AreaSpawnerTempletePath = m_AreaSpawnerTempletePath;
            }
            GUILayout.EndHorizontal();

            if (GUILayout.Button("创建"))
            {
                CreateMap();
            }

            GUILayout.EndVertical();
        }
Пример #18
0
        private void CalcuateAllPrefab(GameObject obj, Dictionary <int, UnitInfo> unitInfos)
        {
            if (obj == null)
            {
                return;
            }

            if (!obj.activeSelf || obj.hideFlags == HideFlags.DontSave)
            {
                return;
            }
            if (obj.GetComponent <SemaphoreMark>() || obj.GetComponent <IRootMark>() ||
                obj.GetComponent <TreasureInfoMark>())
            {
                return;
            }
            MapEditorUtility.SelectChildParticleSystem(obj);
            GameObject sourcePrefab = UnityEditor.PrefabUtility.GetCorrespondingObjectFromSource(obj);;

            if (sourcePrefab == null)
            {
                //TODO:继续往子节点进行遍历
                int childCount = obj.transform.childCount;
                if (childCount > 0)
                {
                    for (int iChild = 0; iChild < childCount; iChild++)
                    {
                        CalcuateAllPrefab(obj.transform.GetChild(iChild).gameObject, unitInfos);
                    }
                }
            }
            else
            {
                UnitInfo unitInfo = new UnitInfo();
                unitInfo.InstanceId = obj.GetInstanceID();
                unitInfo.Unit       = obj;
                MapEditorUtility.CaculateAABB(obj.transform, ref unitInfo.AABB);
                unitInfos.Add(unitInfo.InstanceId, unitInfo);
            }
        }
Пример #19
0
        /// <summary>
        /// 创建NPC
        /// </summary>
        public void CreateCreature()
        {
            GameObject creatureObj = new GameObject();

            creatureObj.transform.SetParent(transform);
            Creature creature = creatureObj.AddComponent <Creature>();

            if (creature != null)
            {
                m_CreatureCache = gameObject.GetComponentsInChildren <Creature>();
                CalcuateMaxCreatureId();
                int    nextCreatureId = (int)(m_MaxCreatureId + 1);
                string creatureUidStr = string.Format("{0}{1}{2}", m_GamingMapArea.GetGamingMapId(), m_GamingMapArea.m_AreaId, MapEditorUtility.CalcuateNumber(nextCreatureId, 3));
                ulong  creatureUid    = ulong.Parse(creatureUidStr);
                creature.Init(creatureUid, nextCreatureId, this);
            }
            Selection.activeGameObject = creatureObj;
        }
Пример #20
0
        private void OnGUI()
        {
            GUILayout.BeginHorizontal("box");
            EditorGUILayout.LabelField("关联地图Scene:", m_RelationScene);
            if (m_HasSelect)
            {
                if (GUILayout.Button("收起", GUILayout.Width(100)))
                {
                    m_HasSelect = false;
                }
                GUILayout.EndHorizontal();
                m_VerticalPos = GUILayout.BeginScrollView(m_VerticalPos);
                GUILayout.BeginVertical("box");
                if (m_RelationSceneList != null && m_RelationSceneList.Count > 0)
                {
                    for (int iRelation = 0; iRelation < m_RelationSceneList.Count; iRelation++)
                    {
                        string[] splitPath = m_RelationSceneList[iRelation].Split('/');
                        if (splitPath != null && splitPath.Length > 0)
                        {
                            string showPath = splitPath[splitPath.Length - 1];
                            if (!string.IsNullOrEmpty(showPath))
                            {
                                showPath = showPath.Replace(".unity", "");
                                if (GUILayout.Button(showPath))
                                {
                                    m_RelationScene = m_RelationSceneList[iRelation];
                                    m_HasSelect     = false;
                                }
                            }
                        }
                    }
                }
                else
                {
                    GUILayout.Label("未找到关联的Scene");
                }
                GUILayout.EndVertical();
                GUILayout.EndScrollView();
            }
            else
            {
                if (GUILayout.Button("选择", GUILayout.Width(100)))
                {
                    m_HasSelect = true;
                }
                GUILayout.EndHorizontal();
            }
            GUILayout.BeginVertical("box");
            m_GamingMapId   = EditorGUILayout.TextField("GamingMap Id:", m_GamingMapId);
            m_GamingMapName = EditorGUILayout.TextField("名称:", m_GamingMapName);
            //m_GamingMapType = (GamingMapType)EditorGUILayout.EnumPopup("类型:", m_GamingMapType);
            m_SelectTypeIndex = EditorGUILayout.Popup(new GUIContent("类型:"), m_SelectTypeIndex, EditorGamingMapData.GAMINGMAPTYPE_NAME);
            m_GamingMapType   = (GamingMapType)m_SelectTypeIndex;
            if (GUILayout.Button("创建"))
            {
                if (m_RelationScene == null)
                {
                    EditorUtility.DisplayDialog("提示", "请选择关联地图Scene", "确定");
                    return;
                }

                uint mapId;
                if (!uint.TryParse(m_GamingMapId, out mapId))
                {
                    EditorUtility.DisplayDialog("提示", "GamingMap id格式错误", "确定");
                    return;
                }
                if (string.IsNullOrEmpty(m_GamingMapName))
                {
                    EditorUtility.DisplayDialog("提示", "名称不能为空", "确定");
                    return;
                }
                string mapPath = "";
                GamingMapEditorSetting gamingSetting = GamingMapEditorUtility.GetGamingMapEditorSetting();
                if (gamingSetting != null)
                {
                    mapPath = string.Format("{0}/GamingMap_{1}.unity", MapEditorUtility.GetFullPath(gamingSetting.m_GamingMapPath), mapId);
                }
                if (File.Exists(mapPath))
                {
                    EditorUtility.DisplayDialog("提示", "该GamingMap已存在", "确定");
                    return;
                }
                List <Scene> openScenes = new List <Scene>();
                for (int iScene = 0; iScene < EditorSceneManager.sceneCount; iScene++)
                {
                    Scene sceneTmp = EditorSceneManager.GetSceneAt(iScene);
                    openScenes.Add(sceneTmp);
                }

                SaveOpenScene();
                //打开对应的map 找到mapid 创建Gamingmap 初始化GamingMap和Area
                Scene        scene = EditorSceneManager.OpenScene(m_RelationScene, OpenSceneMode.Additive);
                Map          map   = null;
                GameObject[] objs  = scene.GetRootGameObjects();
                if (objs != null && objs.Length > 0)
                {
                    for (int iObj = 0; iObj < objs.Length; iObj++)
                    {
                        map = objs[iObj].GetComponent <Map>();
                        if (map != null)
                        {
                            break;
                        }
                    }
                }

                //string gamingPath = PlayerPrefsUtility.GetString(Constants.GAMINGMAP_TEMPLETE_PATH);
                string gamingPath = "";
                if (gamingSetting != null)
                {
                    gamingPath  = MapEditorUtility.GetFullPath(gamingSetting.m_GamingMapTemplete);
                    gamingPath += "/";
                }
                FileUtil.CopyFileOrDirectory(gamingPath, mapPath);
                AssetDatabase.ImportAsset(mapPath);
                Scene        exportScene = EditorSceneManager.OpenScene(mapPath, OpenSceneMode.Additive);
                GameObject[] exportObjs  = exportScene.GetRootGameObjects();
                if (exportObjs != null && exportObjs.Length > 0)
                {
                    for (int iExport = 0; iExport < exportObjs.Length; iExport++)
                    {
                        GamingMap gamingMap = exportObjs[iExport].GetComponent <GamingMap>();
                        if (gamingMap != null)
                        {
                            gamingMap.Init(mapId, map.Uid, m_GamingMapName, m_GamingMapType, map.GetAreaSpawnerList());
                            break;
                        }
                    }
                }
                SceneManager.SetActiveScene(exportScene);
                EditorSceneManager.SaveScene(exportScene);
                EditorSceneManager.CloseScene(scene, true);

                if (openScenes != null && openScenes.Count > 0)
                {
                    for (int iOpen = 0; iOpen < openScenes.Count; iOpen++)
                    {
                        Scene openScene = openScenes[iOpen];
                        EditorSceneManager.SaveScene(openScene);
                        EditorSceneManager.CloseScene(openScene, true);
                    }
                }
            }
            GUILayout.EndVertical();
        }
Пример #21
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();
                }
            }
        }
Пример #22
0
        /// <summary>
        /// 创建Location
        /// </summary>
        public void CreateLocation()
        {
            GameObject locationObj = new GameObject();

            locationObj.transform.SetParent(transform);
            Location location = locationObj.AddComponent <Location>();

            if (location != null)
            {
                m_LocationCache = gameObject.GetComponentsInChildren <Location>();
                CalcuateMaxLocationId();
                int    nextLocationId = m_MaxLocationId + 1;
                string strLocationUid = string.Format("{0}{1}{2}", m_GamingMapArea.GetGamingMapId(), m_GamingMapArea.m_AreaId, MapEditorUtility.CalcuateNumber(nextLocationId, 2));
                ulong  locationUid    = ulong.Parse(strLocationUid);
                location.Init(locationUid, nextLocationId, this);
            }
            Selection.activeGameObject = locationObj;
        }
Пример #23
0
		private void OnGUI()
		{
            m_GamingSetting = GamingMapEditorUtility.GetGamingMapEditorSetting();
            m_MapSetting = MapEditorUtility.GetMapEditorSetting();
            GUILayout.BeginVertical();
			m_SelectIndex = GUILayout.SelectionGrid(m_SelectIndex, m_GuiContentArray,2,GUILayout.Height(100));
			OnClickGrid(m_SelectIndex);
			GUILayout.BeginVertical("box");
			EditorGUILayout.LabelField("GamingMap设置:", m_GuiStyle);
			GUILayout.Space(5);
			GUILayout.BeginHorizontal("box");
			
			EditorGUILayout.LabelField("GamingMap保存路径:", m_GamingMapPath);
			//GUILayout.FlexibleSpace();
			if (GUILayout.Button("选择"))
			{
				m_GamingMapPath = MapEditorUtility.OpenFloderPanel();
				m_GamingMapPath = MapEditorUtility.GetRelativePath(m_GamingMapPath);
				m_GamingSetting.m_GamingMapPath = m_GamingMapPath;
				//PlayerPrefsUtility.SetString(Constants.GAMINGMAP_SAVE_PATH, m_GamingMapPath);
			}
			GUILayout.EndHorizontal();
			GUILayout.BeginHorizontal("box");
			EditorGUILayout.LabelField("GamingMap模板:", m_GamingMapTemplete);
			if (GUILayout.Button("选择"))
			{
				m_GamingMapTemplete = MapEditorUtility.OpenFilePanel("", "unity");
				m_GamingMapTemplete = MapEditorUtility.GetRelativePath(m_GamingMapTemplete);
				m_GamingSetting.m_GamingMapTemplete = m_GamingMapTemplete;
				//PlayerPrefsUtility.SetString(Constants.GAMINGMAP_TEMPLETE_PATH, m_GamingMapTemplete);
			}
			GUILayout.EndHorizontal();
			GUILayout.BeginHorizontal("box");
			EditorGUILayout.LabelField("GamingMapArea模板",m_GamingAreaTemplete);
			if(GUILayout.Button("选择"))
			{
				m_GamingAreaTemplete = MapEditorUtility.OpenFilePanel("", "prefab");
				m_GamingAreaTemplete = MapEditorUtility.GetRelativePath(m_GamingAreaTemplete);
				m_GamingSetting.m_GamingAreaTemplete = m_GamingAreaTemplete;
				//PlayerPrefsUtility.SetString(Constants.GAMINGAREA_TEMPLETE_PATH, m_GamingAreaTemplete);
			}
			GUILayout.EndHorizontal();

			GUILayout.BeginHorizontal("box");
			EditorGUILayout.LabelField("配置表路径", m_ConfigPath);
			if (GUILayout.Button("选择"))
			{
				m_ConfigPath = MapEditorUtility.OpenFloderPanel("");
				m_ConfigPath = MapEditorUtility.GetRelativePath(m_ConfigPath);
				m_GamingSetting.m_ConfigPath = m_ConfigPath;
				//PlayerPrefsUtility.SetString(Constants.CONFIG_PATH, m_ConfigPath);
			}
			GUILayout.EndHorizontal();

			GUILayout.BeginHorizontal("box");
			EditorGUILayout.LabelField("Json保存路径", m_JsonPath);
			if (GUILayout.Button("选择"))
			{
				m_JsonPath = MapEditorUtility.OpenFloderPanel("");
				m_JsonPath = MapEditorUtility.GetRelativePath(m_JsonPath);
				m_GamingSetting.m_JsonPath = m_JsonPath;
				//PlayerPrefsUtility.SetString(Constants.SAVEJSON_PATH, m_JsonPath);
			}
			GUILayout.EndHorizontal();

			GUILayout.BeginHorizontal("box");
			EditorGUILayout.LabelField("Creature模板", m_CreatureTempletePath);
			if (GUILayout.Button("选择"))
			{
				m_CreatureTempletePath = MapEditorUtility.OpenFilePanel("","prefab");
				m_CreatureTempletePath = MapEditorUtility.GetRelativePath(m_CreatureTempletePath);
				m_GamingSetting.m_CreatureTempletePath = m_CreatureTempletePath;
				//PlayerPrefsUtility.SetString(Constants.CREATURE_TEMPLETE_PATH, m_CreatureTempletePath);
			}
			GUILayout.EndHorizontal();


			GUILayout.BeginHorizontal("box");
			EditorGUILayout.LabelField("Location模板", m_LocationTempletePath);
			if (GUILayout.Button("选择"))
			{
				m_LocationTempletePath = MapEditorUtility.OpenFilePanel("", "prefab");
				m_LocationTempletePath = MapEditorUtility.GetRelativePath(m_LocationTempletePath);
				m_GamingSetting.m_LocationTempletePath = m_LocationTempletePath;
			}
			GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal("box");
            EditorGUILayout.LabelField("Leap模板", m_LeapTempletePath);
            if (GUILayout.Button("选择"))
            {
                m_LeapTempletePath = MapEditorUtility.OpenFilePanel("", "prefab");
                m_LeapTempletePath = MapEditorUtility.GetRelativePath(m_LeapTempletePath);
                m_GamingSetting.m_LeapTempletePath = m_LeapTempletePath;
            }
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal("box");
            EditorGUILayout.LabelField("Trigger模板", m_TriggerTempletePath);
            if (GUILayout.Button("选择"))
            {
                m_TriggerTempletePath = MapEditorUtility.OpenFilePanel("", "prefab");
                m_TriggerTempletePath = MapEditorUtility.GetRelativePath(m_TriggerTempletePath);
                m_GamingSetting.m_TriggerTempletePath = m_TriggerTempletePath;
            }
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal("box");
            EditorGUILayout.LabelField("最大战舰", m_MaxShipPath);
            if (GUILayout.Button("选择"))
            {
                m_MaxShipPath = MapEditorUtility.OpenFilePanel("", "prefab");
                m_MaxShipPath = MapEditorUtility.GetRelativePath(m_MaxShipPath);
                m_GamingSetting.m_MaxShipPath = m_MaxShipPath;
            }
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal("box");
            EditorGUILayout.LabelField("星图保存路径", m_StarMapPath);
            if (GUILayout.Button("选择"))
            {
                m_StarMapPath = MapEditorUtility.OpenFloderPanel("");
                m_StarMapPath = MapEditorUtility.GetRelativePath(m_StarMapPath);
                m_GamingSetting.m_StarMapPath = m_StarMapPath;
            }
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal("box");
            EditorGUILayout.LabelField("战舰属性保存路径", m_SpacecraftPropertyPath);
            if (GUILayout.Button("选择"))
            {
                m_SpacecraftPropertyPath = MapEditorUtility.OpenFloderPanel("");
                m_SpacecraftPropertyPath = MapEditorUtility.GetRelativePath(m_SpacecraftPropertyPath);
                m_GamingSetting.m_SpacecraftPropertyPath = m_SpacecraftPropertyPath;
            }
            GUILayout.EndHorizontal();

            GUILayout.EndVertical();
			GUILayout.Space(20);
			//Map的相关配置
			GUILayout.BeginVertical("box");
			EditorGUILayout.LabelField("Map设置:", m_GuiStyle);
			GUILayout.Space(5);
			GUILayout.BeginHorizontal("box");
			EditorGUILayout.LabelField("地图模板路径", m_MapTempletePath);
			if (GUILayout.Button("选择"))
			{
				m_MapTempletePath = MapEditorUtility.OpenFilePanel("", "unity");
				m_MapTempletePath = MapEditorUtility.GetRelativePath(m_MapTempletePath);
				m_MapSetting.m_MapTempletePath = m_MapTempletePath;
				//PlayerPrefsUtility.SetString(Constants.MAP_TEMPLETE_PATH, m_MapTempletePath);
			}
			GUILayout.EndHorizontal();

			GUILayout.BeginHorizontal("box");
			EditorGUILayout.LabelField("地图保存路径:", m_MapSavePath);
			if (GUILayout.Button("选择"))
			{
				m_MapSavePath = MapEditorUtility.OpenFloderPanel();
				m_MapSavePath = MapEditorUtility.GetRelativePath(m_MapSavePath);
				m_MapSetting.m_MapSavePath = m_MapSavePath;
				//PlayerPrefsUtility.SetString(Constants.MAP_SAVE_PATH, m_MapSavePath);
			}
			GUILayout.EndHorizontal();

			GUILayout.BeginHorizontal("box");
			EditorGUILayout.LabelField("AreaSpawner模板路径:", m_AreaSpawnerTempletePath);
			if (GUILayout.Button("选择"))
			{
				m_AreaSpawnerTempletePath = MapEditorUtility.OpenFilePanel("", "prefab");
				m_AreaSpawnerTempletePath = MapEditorUtility.GetRelativePath(m_AreaSpawnerTempletePath);
				m_MapSetting.m_AreaSpawnerTempletePath = m_AreaSpawnerTempletePath;
			}
			GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal("box");
            EditorGUILayout.LabelField("碰撞体保存路径:", m_ColliderSavePath);
            if (GUILayout.Button("选择"))
            {
                m_ColliderSavePath = MapEditorUtility.OpenFloderPanel("");
                m_ColliderSavePath = MapEditorUtility.GetRelativePath(m_ColliderSavePath);
                m_MapSetting.m_ColliderSavePath = m_ColliderSavePath;
            }
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal("box");
            EditorGUILayout.LabelField("碰撞体备份保存路径:", m_ColliderSavePathCopy);
            if (GUILayout.Button("选择"))
            {
                m_ColliderSavePathCopy = MapEditorUtility.OpenFloderPanel("");
                m_ColliderSavePathCopy = MapEditorUtility.GetRelativePath(m_ColliderSavePathCopy);
                m_MapSetting.m_ColliderSavePathCopy = m_ColliderSavePathCopy;
            }
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal("box");
            EditorGUILayout.LabelField("寻宝预设保存路径:", m_TreasurePrefabSavePath);
            if (GUILayout.Button("选择"))
            {
                m_TreasurePrefabSavePath = MapEditorUtility.OpenFloderPanel("");
                m_TreasurePrefabSavePath = MapEditorUtility.GetRelativePath(m_TreasurePrefabSavePath);
                m_MapSetting.m_TreasurePrefabSavePath = m_TreasurePrefabSavePath;
            }
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal("box");
            EditorGUILayout.LabelField("挖矿预设保存路径:", m_MineralPrefabSavePath);
            if (GUILayout.Button("选择"))
            {
                m_MineralPrefabSavePath = MapEditorUtility.OpenFloderPanel("");
                m_MineralPrefabSavePath = MapEditorUtility.GetRelativePath(m_MineralPrefabSavePath);
                m_MapSetting.m_MineralPrefabSavePath = m_MineralPrefabSavePath;
            }
            GUILayout.EndHorizontal();

            GUILayout.EndVertical();
			GUILayout.EndVertical();
            EditorUtility.SetDirty(m_MapSetting);
            EditorUtility.SetDirty(m_GamingSetting);
        }