40 lines
1.5 KiB
C#
40 lines
1.5 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using UnityEditor;
|
|
using UnityEditor.SceneManagement;
|
|
using UnityEngine;
|
|
|
|
public static class LevelEditorHelper
|
|
{
|
|
private const string LEVEL_TEMPLATE_PATH = "Assets/Scenes/Maps/Template/MapDefault/MapDefault.unity";
|
|
|
|
private const string MAP_FOLDER = "Assets/Scenes/Maps";
|
|
|
|
[MenuItem("Assets/创建地图场景")]
|
|
private static void CreateLevel()
|
|
{
|
|
var currDir = EditorUtil.GetCurrentAssetDirectory().Replace("\\", "/");
|
|
var dirName = Path.GetFileName(currDir);
|
|
var count = AssetDatabase.FindAssets("t:SceneAsset", new[] { currDir }).Length + 1;
|
|
var savePath = EditorUtil.GetAssetUniquePath($"{currDir}/{dirName}_{count}.unity", out var assetName);
|
|
AssetDatabase.CopyAsset(LEVEL_TEMPLATE_PATH, savePath);
|
|
var newScene = AssetDatabase.LoadAssetAtPath<SceneAsset>(savePath);
|
|
EditorGUIUtility.PingObject(newScene);
|
|
}
|
|
|
|
[MenuItem("Tools/地图场景/后处理所有场景")]
|
|
private static void PostProcessAllMap()
|
|
{
|
|
var guids = AssetDatabase.FindAssets("t:SceneAsset", new[] { MAP_FOLDER });
|
|
foreach (var guid in guids)
|
|
{
|
|
var scenePath = AssetDatabase.GUIDToAssetPath(guid);
|
|
if (scenePath.Contains("Template"))
|
|
continue;
|
|
var scene = EditorSceneManager.OpenScene(scenePath, OpenSceneMode.Additive);
|
|
ScenePostProcessor.Instance.PostProcess(scene,true);
|
|
EditorSceneManager.CloseScene(scene, true);
|
|
}
|
|
}
|
|
} |