2025-04-28 16:56:34 +08:00
|
|
|
using System.Collections.Generic;
|
2025-08-11 15:52:55 +08:00
|
|
|
using PhxhSDK;
|
2025-04-28 16:56:34 +08:00
|
|
|
using PhxhSDK.AOT;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
using PhxhSDK.Phxh;
|
|
|
|
|
using Sirenix.OdinInspector;
|
|
|
|
|
|
|
|
|
|
#if UNITY_EDITOR
|
|
|
|
|
using UnityEditor;
|
|
|
|
|
using UnityEngine.SceneManagement;
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
[ExecuteAlways]
|
|
|
|
|
public class LegionLevelEditor : MonoBehaviour
|
|
|
|
|
{
|
|
|
|
|
public LegionLevelData LevelData { get; private set; }
|
|
|
|
|
|
|
|
|
|
public TextAsset LevelDataJson
|
|
|
|
|
{
|
|
|
|
|
get => _levelDataJson;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
var data = JsonToLevelData(value);
|
|
|
|
|
_levelDataJson = value;
|
|
|
|
|
LevelData = data;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[SerializeField] [LabelText("关卡数据")] [OnValueChanged("OnLevelDataJsonChanged")]
|
|
|
|
|
private TextAsset _levelDataJson;
|
|
|
|
|
|
|
|
|
|
private void OnLevelDataJsonChanged()
|
|
|
|
|
{
|
|
|
|
|
LevelDataJson = _levelDataJson;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private LegionLevelData JsonToLevelData(TextAsset jsonText)
|
|
|
|
|
{
|
|
|
|
|
#if UNITY_EDITOR
|
|
|
|
|
LegionLevelData levelData = null;
|
2025-09-13 17:18:26 +08:00
|
|
|
if (jsonText is not null)
|
2025-04-28 16:56:34 +08:00
|
|
|
{
|
|
|
|
|
var jsonStr = jsonText.text;
|
|
|
|
|
if (string.IsNullOrEmpty(jsonStr))
|
|
|
|
|
{
|
|
|
|
|
levelData = new();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
var path = AssetDatabase.GetAssetPath(jsonText);
|
|
|
|
|
levelData = JsonHelper.LoadJson<LegionLevelData>(path);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return levelData;
|
|
|
|
|
#else
|
|
|
|
|
return null;
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Awake()
|
|
|
|
|
{
|
2025-08-11 15:52:55 +08:00
|
|
|
if (BusyWrapper.isBusy)
|
|
|
|
|
return;
|
2025-04-28 16:56:34 +08:00
|
|
|
LevelData = JsonToLevelData(_levelDataJson);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnDestroy()
|
|
|
|
|
{
|
2025-08-11 15:52:55 +08:00
|
|
|
if (BusyWrapper.isBusy)
|
2025-04-28 16:56:34 +08:00
|
|
|
return;
|
|
|
|
|
SaveLevelData();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SaveLevelData()
|
|
|
|
|
{
|
|
|
|
|
#if UNITY_EDITOR
|
|
|
|
|
var currentScene = gameObject.scene;
|
2025-05-16 19:07:21 +08:00
|
|
|
if (currentScene.name.Contains("_PostProcess")) return;
|
|
|
|
|
|
2025-04-28 16:56:34 +08:00
|
|
|
if (_levelDataJson != null && !Application.isPlaying && currentScene == SceneManager.GetActiveScene())
|
|
|
|
|
{
|
|
|
|
|
var path = AssetDatabase.GetAssetPath(_levelDataJson);
|
|
|
|
|
JsonHelper.SaveJson(path, LevelData);
|
|
|
|
|
AssetDatabase.Refresh();
|
|
|
|
|
SaveDataForServer();
|
|
|
|
|
DebugUtil.Log("保存军团关卡数据成功!");
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#if UNITY_EDITOR
|
|
|
|
|
|
|
|
|
|
[SerializeField] [LabelText("服务器所用数据")]
|
|
|
|
|
private TextAsset _levelDataJsonForServer;
|
|
|
|
|
|
|
|
|
|
public LegionDataForServer LevelDataForServer;
|
|
|
|
|
|
|
|
|
|
public TextAsset LevelDataJsonForServer
|
|
|
|
|
{
|
|
|
|
|
get => _levelDataJsonForServer;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
var data = JsonToLevelDataServer(value);
|
|
|
|
|
_levelDataJsonForServer = value;
|
|
|
|
|
LevelDataForServer = data;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private LegionDataForServer JsonToLevelDataServer(TextAsset jsonText)
|
|
|
|
|
{
|
|
|
|
|
LegionDataForServer levelData = null;
|
2025-09-13 17:18:26 +08:00
|
|
|
if (jsonText is not null)
|
2025-04-28 16:56:34 +08:00
|
|
|
{
|
|
|
|
|
var jsonStr = jsonText.text;
|
|
|
|
|
if (string.IsNullOrEmpty(jsonStr))
|
|
|
|
|
{
|
|
|
|
|
levelData = new();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
var path = AssetDatabase.GetAssetPath(jsonText);
|
|
|
|
|
levelData = JsonHelper.LoadJson<LegionDataForServer>(path);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return levelData;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void SaveDataForServer()
|
|
|
|
|
{
|
|
|
|
|
var currentScene = gameObject.scene;
|
2025-05-16 19:07:21 +08:00
|
|
|
if (currentScene.name.Contains("_PostProcess")) return;
|
2025-04-28 16:56:34 +08:00
|
|
|
if (_levelDataJsonForServer != null && !Application.isPlaying && currentScene == SceneManager.GetActiveScene())
|
|
|
|
|
{
|
|
|
|
|
var path = AssetDatabase.GetAssetPath(_levelDataJsonForServer);
|
|
|
|
|
JsonHelper.SaveJson(path, LevelDataForServer);
|
|
|
|
|
AssetDatabase.Refresh();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 服务器所用数据
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class LegionDataForServer
|
|
|
|
|
{
|
|
|
|
|
public int _width;
|
|
|
|
|
public int _height;
|
|
|
|
|
public float radius;
|
|
|
|
|
public float length;
|
|
|
|
|
|
|
|
|
|
public List<BuildingsForServer> buildings;
|
|
|
|
|
public List<LinkBuilding> linkBuildings;
|
|
|
|
|
public List<PositionForServer> born_pos_a;
|
|
|
|
|
public List<PositionForServer> born_pos_b;
|
|
|
|
|
public List<PositionForServer> speed_hex;
|
|
|
|
|
|
|
|
|
|
public class BuildingsForServer
|
|
|
|
|
{
|
|
|
|
|
public int id;
|
|
|
|
|
public int x;
|
|
|
|
|
public int z;
|
|
|
|
|
public int building;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class PositionForServer
|
|
|
|
|
{
|
|
|
|
|
public int x;
|
|
|
|
|
public int z;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class LinkBuilding
|
|
|
|
|
{
|
|
|
|
|
public int build_a;
|
|
|
|
|
public int build_b;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endif
|
2025-02-11 15:03:22 +08:00
|
|
|
}
|