NLDClient-yudde/ProjectNLD/Assets/Editor/LevelEditor/LevelEditorHelper.cs

22 lines
877 B
C#

using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEditor;
using UnityEngine;
public static class LevelEditorHelper
{
private const string LEVEL_TEMPLATE_PATH = "Assets/Scenes/Maps/Template/MapDefault/MapDefault.unity";
[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);
}
}