Files
JJBB/Assets/Editor/Scripts/Path/AllServerObstacle.cs
2024-08-23 15:49:34 +08:00

109 lines
3.3 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System;
using System.Collections.Generic;
using System.Linq;
using Games.GlobeDefine;
using GCGame.Table;
using UnityEditor;
using UnityEditor.SceneManagement;
using UnityEngine;
public class AllServerObstacle : EditorWindow
{
[MenuItem("ProTool/ServerObstacle/Create For All")]
public static void ShowWindow()
{
GetWindow<AllServerObstacle>();
}
private void OnGUI()
{
GUILayout.Label("即将为所有SceneClass索引的场景创建服务器碰撞");
if (GUILayout.Button("确定"))
{
Close();
var sceneHash = new HashSet<string>();
var sceneList = EditorTableManager.GetTable<Tab_SceneClass>();
foreach (var scene in sceneList)
{
var sceneName = scene.ResName.Trim();
if (!string.IsNullOrEmpty(sceneName) &&
sceneName != GlobeVar.sceneRole &&
sceneName != GlobeVar.sceneLoading &&
sceneName != GlobeVar.sceneLogin)
sceneHash.Add(sceneName);
}
var action = new AllServerObstacleAction(sceneHash.ToArray());
action.Start();
}
if (GUILayout.Button("取消"))
Close();
}
private class AllServerObstacleAction : EditorPerFrameActionBase
{
private string[] _scenePaths;
private int _currentIndex;
// 打开场景后,跳过一帧
private bool _skip;
public AllServerObstacleAction(string[] scenePaths)
{
_scenePaths = scenePaths;
}
protected override int GetCurrentIndex()
{
return _currentIndex;
}
protected override int GetTotalCount()
{
return _scenePaths.Length;
}
protected override void PerFrameAction()
{
if (_skip)
{
_skip = false;
_currentIndex++;
ServerObstacle.CreateObstacle();
}
else
{
var sceneName = _scenePaths[_currentIndex];
var scenePath = SceneDisassembly.sceneRoot.Open(sceneName + SceneDisassembly.sceneExtension);
var error = false;
try
{
var scene = EditorSceneManager.OpenScene(scenePath, OpenSceneMode.Single);
Debug.Log("加载场景 " + scene.name);
if (scene.name == sceneName)
{
}
else
{
Debug.LogError(string.Format("无法加载场景{0}于项目路径{1}", sceneName, scenePath));
error = true;
}
}
catch (Exception e)
{
Debug.LogError(e);
error = true;
}
if (error)
{
_skip = false;
_currentIndex++;
Debug.LogWarning(string.Format("场景{0}保存为空白文件!", sceneName));
ServerObstacle.CreateEmptyObstacle(sceneName);
}
else
_skip = true;
}
}
}
}