181 lines
7.1 KiB
C#
181 lines
7.1 KiB
C#
using System.Collections.Generic;
|
|
using System.IO;
|
|
using UnityEditor;
|
|
using UnityEditor.SceneManagement;
|
|
using UnityEngine;
|
|
using UnityEngine.SceneManagement;
|
|
using Vanguard.App;
|
|
using Vanguard.Battle;
|
|
using Vanguard.Board3D;
|
|
|
|
namespace Vanguard.Editor
|
|
{
|
|
/// <summary>
|
|
/// Создаёт сцены-экраны и прописывает их в Build Settings.
|
|
/// Запуск: меню Vanguard → Rebuild Client Scenes или
|
|
/// Unity -batchmode -quit -executeMethod Vanguard.Editor.SceneBuilder.BuildAll.
|
|
/// </summary>
|
|
public static class SceneBuilder
|
|
{
|
|
private const string SceneDir = "Assets/Vanguard/Scenes";
|
|
private const string BootPath = "Assets/Scenes/Boot.unity";
|
|
private const string PlaymatConfigPath =
|
|
"Assets/Vanguard/Runtime/Board3D/Config/PlaymatLayoutConfig.asset";
|
|
private const string AnimationConfigPath =
|
|
"Assets/Vanguard/Resources/AnimationConfig.asset";
|
|
private const string PlaymatScenePath = SceneDir + "/GameBoard3D.unity";
|
|
|
|
[MenuItem("Vanguard/Rebuild Client Scenes")]
|
|
public static void BuildAll()
|
|
{
|
|
if (!Directory.Exists(SceneDir))
|
|
{
|
|
Directory.CreateDirectory(SceneDir);
|
|
AssetDatabase.Refresh();
|
|
}
|
|
|
|
Create<LoginSceneController>("Login");
|
|
Create<LobbySceneController>("Lobby");
|
|
Create<DeckBuilderSceneController>("DeckBuilder");
|
|
Create<BattleSceneController>("Battle");
|
|
EnsurePlaymatConfig();
|
|
EnsureAnimationConfig();
|
|
OverlayPrefabBuilder.BuildOverlayPrefabs();
|
|
|
|
var scenes = new List<EditorBuildSettingsScene>();
|
|
Add(scenes, BootPath);
|
|
Add(scenes, SceneDir + "/Login.unity");
|
|
Add(scenes, SceneDir + "/Lobby.unity");
|
|
Add(scenes, SceneDir + "/DeckBuilder.unity");
|
|
Add(scenes, SceneDir + "/Battle.unity");
|
|
|
|
EditorBuildSettings.scenes = scenes.ToArray();
|
|
AssetDatabase.SaveAssets();
|
|
AssetDatabase.Refresh();
|
|
|
|
Debug.Log("Vanguard scenes rebuilt: " + scenes.Count);
|
|
}
|
|
|
|
[MenuItem("Vanguard/Rebuild Playmat Sandbox")]
|
|
public static void BuildPlaymatSandbox()
|
|
{
|
|
if (!Directory.Exists(SceneDir))
|
|
{
|
|
Directory.CreateDirectory(SceneDir);
|
|
AssetDatabase.Refresh();
|
|
}
|
|
|
|
var config = EnsurePlaymatConfig();
|
|
var scene = EditorSceneManager.NewScene(NewSceneSetup.EmptyScene, NewSceneMode.Single);
|
|
|
|
var cameraGo = new GameObject("Main Camera");
|
|
cameraGo.tag = "MainCamera";
|
|
var camera = cameraGo.AddComponent<Camera>();
|
|
camera.clearFlags = CameraClearFlags.SolidColor;
|
|
camera.backgroundColor = new Color(0.02f, 0.025f, 0.045f);
|
|
camera.fieldOfView = config.cameraFov;
|
|
camera.transform.position = config.cameraPosition;
|
|
var direction = config.cameraTarget - config.cameraPosition;
|
|
if (direction.sqrMagnitude > 0.001f)
|
|
camera.transform.rotation = Quaternion.LookRotation(direction, Vector3.up);
|
|
|
|
var lightGo = new GameObject("Directional Light");
|
|
var light = lightGo.AddComponent<Light>();
|
|
light.type = LightType.Directional;
|
|
light.color = new Color(1f, 0.88f, 0.68f);
|
|
light.intensity = 1.15f;
|
|
light.shadows = LightShadows.Soft;
|
|
light.transform.rotation = Quaternion.Euler(48f, -32f, 0f);
|
|
|
|
var root = new GameObject("Playmat Sandbox");
|
|
var sandbox = root.AddComponent<PlaymatSandbox>();
|
|
sandbox.config = config;
|
|
|
|
EditorSceneManager.SaveScene(scene, PlaymatScenePath);
|
|
AssetDatabase.SaveAssets();
|
|
AssetDatabase.Refresh();
|
|
Debug.Log("Vanguard playmat sandbox rebuilt: " + PlaymatScenePath);
|
|
}
|
|
|
|
[MenuItem("Vanguard/Rebuild Animation Config")]
|
|
public static void BuildAnimationConfig()
|
|
{
|
|
EnsureAnimationConfig();
|
|
AssetDatabase.SaveAssets();
|
|
AssetDatabase.Refresh();
|
|
Debug.Log("Vanguard animation config ready: " + AnimationConfigPath);
|
|
}
|
|
|
|
private static AnimationConfig EnsureAnimationConfig()
|
|
{
|
|
var config = AssetDatabase.LoadAssetAtPath<AnimationConfig>(AnimationConfigPath);
|
|
if (config != null)
|
|
return config;
|
|
|
|
var directory = Path.GetDirectoryName(AnimationConfigPath);
|
|
if (!string.IsNullOrEmpty(directory) && !Directory.Exists(directory))
|
|
{
|
|
Directory.CreateDirectory(directory);
|
|
AssetDatabase.Refresh();
|
|
}
|
|
|
|
config = ScriptableObject.CreateInstance<AnimationConfig>();
|
|
config.name = "AnimationConfig";
|
|
AssetDatabase.CreateAsset(config, AnimationConfigPath);
|
|
AssetDatabase.SaveAssets();
|
|
return config;
|
|
}
|
|
|
|
private static PlaymatLayoutConfig EnsurePlaymatConfig()
|
|
{
|
|
var config = AssetDatabase.LoadAssetAtPath<PlaymatLayoutConfig>(PlaymatConfigPath);
|
|
if (config != null)
|
|
return config;
|
|
|
|
var directory = Path.GetDirectoryName(PlaymatConfigPath);
|
|
if (!string.IsNullOrEmpty(directory) && !Directory.Exists(directory))
|
|
{
|
|
Directory.CreateDirectory(directory);
|
|
AssetDatabase.Refresh();
|
|
}
|
|
|
|
config = PlaymatLayoutConfig.CreateDefault();
|
|
AssetDatabase.CreateAsset(config, PlaymatConfigPath);
|
|
AssetDatabase.SaveAssets();
|
|
return config;
|
|
}
|
|
|
|
private static void Create<T>(string sceneName) where T : MonoBehaviour
|
|
{
|
|
var scene = EditorSceneManager.NewScene(NewSceneSetup.EmptyScene, NewSceneMode.Single);
|
|
|
|
var root = new GameObject(sceneName + " Scene");
|
|
root.AddComponent<T>();
|
|
|
|
var cameraGo = new GameObject("Main Camera");
|
|
cameraGo.tag = "MainCamera";
|
|
var camera = cameraGo.AddComponent<Camera>();
|
|
camera.clearFlags = CameraClearFlags.SolidColor;
|
|
camera.backgroundColor = new Color(0.02f, 0.03f, 0.055f);
|
|
camera.transform.position = new Vector3(0f, 3.2f, -10f);
|
|
camera.transform.rotation = Quaternion.Euler(12f, 0f, 0f);
|
|
|
|
var lightGo = new GameObject("Directional Light");
|
|
var light = lightGo.AddComponent<Light>();
|
|
light.type = LightType.Directional;
|
|
light.color = new Color(0.82f, 0.88f, 1f);
|
|
light.intensity = 0.9f;
|
|
light.shadows = LightShadows.Soft;
|
|
light.transform.rotation = Quaternion.Euler(48f, -32f, 0f);
|
|
|
|
EditorSceneManager.SaveScene(scene, SceneDir + "/" + sceneName + ".unity");
|
|
}
|
|
|
|
private static void Add(ICollection<EditorBuildSettingsScene> scenes, string path)
|
|
{
|
|
if (File.Exists(path))
|
|
scenes.Add(new EditorBuildSettingsScene(path, true));
|
|
}
|
|
}
|
|
}
|