Inheritance: MonoBehaviour
コード例 #1
0
    private void OnGUI()
    {
        toolbarOption = GUILayout.Toolbar(toolbarOption, toolbarTexts, GUILayout.Width(Screen.width));
        switch (toolbarOption)
        {
        case 0:
            ShowAllMapInfoGUI();
            if (currentLoadMap != null && GUILayout.Button("保存"))
            {
                MapInfomation mapInfo = MapManager.MapInfosDic[currentLoadMap.id];
                if (mapInfo.isCreateLightMap)
                {
                    mapInfo.mapLightMap = MapUseConstValues.LightMapFileNamePrefix + mapInfo.mapFileName;
                    MapEditorWindowFunction.BakeLightMap(() =>
                    {
                        GetCurrentEditMapRoot();
                        SaveLightMapInfo();
                    });
                }
                SaveMapInfoData();
                SaveMapData();

                AssetDatabase.Refresh();
            }
            break;

        case 1:
            NewMapFileGUI();
            break;
        }
    }
コード例 #2
0
    bool NewMapFileGUI()
    {
        GUILayout.BeginHorizontal("box");
        newFileName = EditorDrawGUIUtil.DrawBaseValue("新建地图文件", newFileName).ToString();
        if (GUILayout.Button("确定", GUILayout.Width(50)))
        {
            if (ResourcePathManager.ContainsFileName(newFileName))
            {
                EditorUtility.DisplayDialog("错误", "文件名与其他文件重复", "OK");
                return(true);
            }
            MapInfomation info = new MapInfomation();
            info.id = GetMaxID() + 1;
            //info.sceneName = "Scene_" + newFileName;
            info.mapFileName = MapUseConstValues.MapFileNamePrefix + newFileName;
            MapManager.MapInfosDic.Add(info.id, info);

            GlobalEvent.AddEvent(EditorGlobalEventEnum.OnResourcesAssetsChange, (t) =>
            {
                Initialize();
            }, true);
            SaveMapInfoData();

            FileUtils.CreateTextFile(MapUseConstValues.MapDataDirectory + info.mapFileName + "/" + info.mapFileName + ".txt", "");
            AssetDatabase.Refresh();

            return(false);
        }
        GUILayout.EndHorizontal();
        return(true);
    }
コード例 #3
0
ファイル: InBound.cs プロジェクト: jkloop45/Solution
        public static void MapInfomation(MapInfomation P)
        {
            if (P.Details == null)
            {
                return;
            }

            MapLayer.LoadMap(P.Details);
        }
コード例 #4
0
    void SaveMapData()
    {
        string data = GetSceneInfo();

        MapInfomation info = MapManager.MapInfosDic[currentLoadMap.id];
        string        path = MapUseConstValues.MapDataDirectory + info.mapFileName + "/";

        if (!Directory.Exists(path))
        {
            Directory.CreateDirectory(path);
            AssetDatabase.Refresh();
        }
        PrefabUtility.CreatePrefab(path + mapLightRoot.name + ".prefab", mapLightRoot.gameObject, ReplacePrefabOptions.ConnectToPrefab);
        PrefabUtility.CreatePrefab(path + mapColliderRoot.name + ".prefab", mapColliderRoot.gameObject, ReplacePrefabOptions.ConnectToPrefab);
        FileUtils.CreateTextFile(path + info.mapFileName + ".txt", data);
    }
コード例 #5
0
ファイル: ExportZone.cs プロジェクト: jiowchern/TurnBasedRPG
    private void _Export(MapInfomation root, string path)
    {
        var mapInfo = root;
        if(mapInfo != null)
        {
            var entityBuilders = root.GetComponentsInChildren<EntityBuilder>();
            System.Collections.Generic.List<Regulus.Project.TurnBasedRPG.Data.Entity> entitys = new System.Collections.Generic.List<Regulus.Project.TurnBasedRPG.Data.Entity>();
            foreach (var entityBuilder in entityBuilders)
            {

                entitys.Add( _Build( entityBuilder.EntityKind, entityBuilder.gameObject ) );
            }

            Regulus.Project.TurnBasedRPG.Data.Map mapData = new Regulus.Project.TurnBasedRPG.Data.Map();
            mapData.Name = mapInfo.Name;
            mapData.Entitys = entitys.ToArray();

            Regulus.Utility.IO.Serialization.Write<Regulus.Project.TurnBasedRPG.Data.Map>(mapData , path);
        }
        else
        {

        }
    }
コード例 #6
0
    private void SaveLightMapInfo()
    {
        MapInfomation info = MapManager.MapInfosDic[currentLoadMap.id];
        string        path = MapUseConstValues.MapDataDirectory + info.mapFileName + "/LightMap/";

        if (Directory.Exists(path))
        {
            Directory.Delete(path, true);
        }
        Directory.CreateDirectory(path);
        AssetDatabase.Refresh();

        string mapLightDir = "";

        for (int i = 0; i < LightmapSettings.lightmaps.Length; i++)
        {
            LightmapData data = LightmapSettings.lightmaps[i];
            if (data.lightmapDir != null)
            {
                Texture2D tempTex = data.lightmapDir;

                string texPath = AssetDatabase.GetAssetPath(tempTex);
                if (string.IsNullOrEmpty(mapLightDir))
                {
                    mapLightDir = Path.GetDirectoryName(texPath);
                    //Debug.Log("mapLightDir :" + mapLightDir);
                }
                string temp = path + MapUseConstValues.LightmapDirNamePrefix + MapManager.MapInfosDic[currentLoadMap.id].mapFileName + "_" + i + ".png";
                AssetDatabase.MoveAsset(texPath, temp);
            }

            if (data.lightmapColor != null)
            {
                Texture2D tempTex = data.lightmapColor;

                string texPath = AssetDatabase.GetAssetPath(tempTex);
                //TextureImporter import = AssetImporter.GetAtPath(texPath) as TextureImporter;
                //Debug.Log("Name :" + tempTex.name);
                //Debug.Log("textureType :" + import.textureType);
                //Debug.Log("textureShape :" + import.textureShape);
                //import.isReadable = true;
                //import.textureCompression = TextureImporterCompression.Uncompressed;
                //import.SaveAndReimport();
                string temp = path + MapUseConstValues.LightmapColorPrefix + MapManager.MapInfosDic[currentLoadMap.id].mapFileName + "_" + i + ".exr";
                AssetDatabase.MoveAsset(texPath, temp);
            }
        }
        AssetDatabase.Refresh();

        string[] exrPaths = PathUtils.GetDirectoryFilePath(mapLightDir, new string[] { ".png", ".exr" });
        for (int i = 0; i < exrPaths.Length; i++)
        {
            string temp      = exrPaths[i];
            string name      = Path.GetFileNameWithoutExtension(temp);
            string extension = Path.GetExtension(temp);
            name = name + "_" + MapManager.MapInfosDic[currentLoadMap.id].mapFileName + "_" + i + extension;
            string newPath = path + name;
            AssetDatabase.MoveAsset(temp, newPath);
        }
        AssetDatabase.Refresh();

        string lightmapData = GetLightMapInfo();

        FileUtils.CreateTextFile(path + MapUseConstValues.LightMapFileNamePrefix + info.mapFileName + ".txt", lightmapData);
    }
コード例 #7
0
    void ShowAllMapInfoGUI()
    {
        List <MapInfomation> mapInfos = new List <MapInfomation>(MapManager.MapInfosDic.Values);

        pos = GUILayout.BeginScrollView(pos, true, true);
        foreach (MapInfomation info in mapInfos)
        {
            bool isOpen = (currentLoadMap == info);

            if (isOpen)
            {
                GUI.color = Color.red;
            }



            GUILayout.BeginHorizontal();
            GUILayout.BeginVertical("box");
            GUILayout.Label("ID: " + info.id);
            //GUILayout.Label("Scene: " + info.sceneName);
            GUILayout.Label("MapFile: " + info.mapFileName);
            GUILayout.Space(4);
            GUILayout.Box("Light Map :");
            info.isCreateLightMap = (bool)EditorDrawGUIUtil.DrawBaseValue("是否生成光照贴图", info.isCreateLightMap);
            if (info.isCreateLightMap)
            {
                info.lightMapSize = EditorGUILayout.IntPopup("光照贴图单张最大尺寸:", info.lightMapSize, lightMapSizeNames, lightMapSizeValue);
                LightmapEditorSettings.maxAtlasHeight = info.lightMapSize;
                LightmapEditorSettings.maxAtlasWidth  = info.lightMapSize;
                GUILayout.Label("光照贴图文件: " + info.mapLightMap);
            }

            GUILayout.Space(4);

            GUILayout.Label("Collider File :" + info.mapColliderInfoFileName);

            GUILayout.EndVertical();
            GUILayout.BeginVertical("box");
            if (GUILayout.Button(isOpen?"卸载地图": "加载地图", GUILayout.Width(120)))
            {
                if (!isOpen)
                {
                    if (currentLoadMap != null)
                    {
                        if (EditorUtility.DisplayDialog("警告", "是否切换地图,请记得先保存!", "OK", "Cancel"))
                        {
                            MapManager.DestoryMapGameObjectInScene(currentLoadMap.id);
                            currentLoadMap = null;
                        }
                        else
                        {
                            return;
                        }
                    }
                    currentLoadMap = info;
                    MapManager.CreateMapGameObjectInScene(info.id);
                    GetCurrentEditMapRoot();
                }
                else
                {
                    if (EditorUtility.DisplayDialog("警告", "是否卸载地图,请记得先保存!", "OK", "Cancel"))
                    {
                        MapManager.DestoryMapGameObjectInScene(info.id);
                        currentLoadMap = null;
                    }
                }
            }

            GUILayout.EndVertical();
            GUILayout.EndHorizontal();
            GUILayout.Space(5);
            if (currentLoadMap == null && GUILayout.Button("删除"))
            {
                if (EditorUtility.DisplayDialog("警告", "是否删除地图:" + info.mapFileName, "OK", "Cancel"))
                {
                    MapManager.MapInfosDic.Remove(info.id);
                    GlobalEvent.AddEvent(EditorGlobalEventEnum.OnResourcesAssetsChange, (t) =>
                    {
                        Initialize();
                    }, true);
                    SaveMapInfoData();

                    FileUtils.DeleteFile(MapUseConstValues.MapDataDirectory + info.mapFileName + "/" + info.mapFileName + ".txt");
                    AssetDatabase.Refresh();
                    return;
                }
            }

            GUI.color = oldColor;
        }
        GUILayout.EndScrollView();
    }