Files
Main/Assets/Editor/External/MonsterRadious/MonsterRadiousEditor.cs

75 lines
3.0 KiB
C#
Raw Normal View History

2025-01-25 04:38:09 +08:00
using Thousandto.Cfg.Data;
using Thousandto.Code.Logic;
using Thousandto.Core.Asset;
using Thousandto.Core.Base;
using Thousandto.Editor.Excel;
using System.Collections.Generic;
using System.IO;
using System.Text;
using UnityEditor;
using UnityEngine;
class MonsterRadiousEditor
{
[MenuItem("Ares/怪物半径生成")]
static void CreateRadius()
{
EditorUtility.DisplayProgressBar("导出中", "", 0f);
var modelExcelInfo = ExcelReader.Read("../../Gamedata/Config/client/ModelConfig.xlsx");
var monsterExcelInfo = ExcelReader.Read("../../Gamedata/Config/monster.xlsx");
if (monsterExcelInfo == null || modelExcelInfo == null)
{
UnityEngine.Debug.LogError("生成失败,读取表数据错误");
return;
}
StringBuilder pathStr = new StringBuilder(100);
var iter = monsterExcelInfo.IdValuesTable.GetEnumerator();
var counter = 0;
var maxCount = monsterExcelInfo.IdValuesTable.Count;
try
{
while(iter.MoveNext())
{
EditorUtility.DisplayProgressBar("导出中", "", (float)counter / maxCount);
var sizeScale = monsterExcelInfo.GetIntValue(iter.Current.Key, "size_scale");
var usePlayerModel = monsterExcelInfo.GetIntValue(iter.Current.Key, "PlayerModel");
if(usePlayerModel != 0)
{
var radius = (int)((sizeScale / 100f) * 100);
monsterExcelInfo.SetValue(iter.Current.Key, "strike_distance", radius);
}
else
{
var modelID = monsterExcelInfo.GetIntValue(iter.Current.Key, "res");
var type = modelExcelInfo.GetIntValue(modelID.ToString(), "type");
if (type == (int)RoleSkinModelType.MonsterBody)
{
var modelResID = modelExcelInfo.GetIntValue(modelID.ToString(), "model");
pathStr.Length = 0;
pathStr.AppendFormat("Assets/GameAssets/Resources/Prefab/Monster/m_{0:D3}.prefab", modelResID);
var monsterGo = AssetDatabase.LoadAssetAtPath<GameObject>(pathStr.ToString());
if (monsterGo != null)
{
var controller = monsterGo.GetComponent<CapsuleCollider>();
if (controller != null)
{
var radius = (int)((sizeScale / 100f) * (controller.radius * 2f) * 100);
monsterExcelInfo.SetValue(iter.Current.Key, "strike_distance", radius);
}
}
}
}
++counter;
}
}
finally
{
ExcelWriter.Write("../../Gamedata/Config/monster.xlsx", monsterExcelInfo);
iter.Dispose();
}
EditorUtility.ClearProgressBar();
}
}