Ejemplo n.º 1
0
    void LoadSceneAsset()
    {
        filePath = EditorUtility.OpenFilePanel("打开", filePath, "asset");
        if (string.IsNullOrEmpty(filePath) || !filePath.Contains(".asset"))
        {
            return;
        }
        MapWorldAsset mapWorldAsset = (MapWorldAsset)AssetDatabase.LoadAssetAtPath("Assets" + filePath.Replace(Application.dataPath, ""), typeof(MapWorldAsset));

        if (mapWorldAsset != null)
        {
            for (int i = 0; i < mapWorldAsset.mapScenes.Count; i++)
            {
                currMapScene           = new GameObject("Map" + (i + 1)).AddComponent <MapScene>();
                currMapScene.offsetX   = mapWorldAsset.mapScenes[i].offsetX;
                currMapScene.offsetY   = mapWorldAsset.mapScenes[i].offsetY;
                currMapScene.mapSizeX  = mapWorldAsset.mapScenes[i].mapSizeX;
                currMapScene.mapSizeY  = mapWorldAsset.mapScenes[i].mapSizeY;
                currMapScene.worldType = mapWorldAsset.mapScenes[i].worldType;
                currMapScene.layers    = new List <MapEditorSortLayer>(mapWorldAsset.mapScenes[i].layers);
                for (int n = 0; n < mapWorldAsset.mapScenes[i].layerItems.Count; n++)
                {
                    currMapScene.layerItems.Add(new MapLayerItem());
                    currMapScene.layerItems[n].posList = new List <int>(mapWorldAsset.mapScenes[i].layerItems[n].posList);
                    currMapScene.layerItems[n].items   = new List <MapResourceItem>(mapWorldAsset.mapScenes[i].layerItems[n].items);
                }
                mapSceneList.Add(currMapScene);
                currMapScene.FreshMapGrid();
                currMapScene.UpdateMap();
            }
        }
        FreshResource();
    }
Ejemplo n.º 2
0
    void SaveSceneAsset()
    {
        if (currMapScene != null)
        {
            filePath = EditorUtility.SaveFilePanel("保存", filePath, "", "asset");
            if (string.IsNullOrEmpty(filePath) || !filePath.Contains(".asset"))
            {
                return;
            }
            MapWorldAsset newData = ScriptableObject.CreateInstance <MapWorldAsset>();
            for (int i = 0; i < mapSceneList.Count; i++)
            {
                MapSceneAsset mapSceneAsset = new MapSceneAsset();
                mapSceneAsset.offsetX   = mapSceneList[i].offsetX;
                mapSceneAsset.offsetY   = mapSceneList[i].offsetY;
                mapSceneAsset.mapSizeX  = mapSceneList[i].mapSizeX;
                mapSceneAsset.mapSizeY  = mapSceneList[i].mapSizeY;
                mapSceneAsset.worldType = mapSceneList[i].worldType;
                mapSceneAsset.layers    = new List <MapEditorSortLayer>(mapSceneList[i].layers);

                for (int n = 0; n < mapSceneList[i].layerItems.Count; n++)
                {
                    mapSceneAsset.layerItems.Add(new MapLayerItem());
                    mapSceneAsset.layerItems[n].posList = new List <int>(mapSceneList[i].layerItems[n].posList);
                    mapSceneAsset.layerItems[n].items   = new List <MapResourceItem>(mapSceneList[i].layerItems[n].items);
                }
                newData.mapScenes.Add(mapSceneAsset);
            }
            AssetDatabase.CreateAsset(newData, "Assets" + filePath.Replace(Application.dataPath, ""));
            AssetDatabase.SaveAssets();
            AssetDatabase.Refresh();
        }
    }