NLDClient-yudde/ProjectNLD/Assets/Code/Scripts/Gameplay/Vehicle/BaseVehicle.cs

102 lines
3.5 KiB
C#
Raw Normal View History

using System.Linq;
2024-12-26 13:24:22 +08:00
using cfg.VihecleCultivateCfg;
using Cysharp.Threading.Tasks;
2023-08-22 19:08:45 +08:00
using Gameplay.Character;
2024-12-26 13:24:22 +08:00
using Gameplay.Net;
2023-10-19 15:00:19 +08:00
using Gameplay.Performance;
2023-12-13 16:20:41 +08:00
using Gameplay.Unit;
using Gameplay.Unit.Data;
2024-12-26 13:24:22 +08:00
using Gameplay.Utils;
2023-08-22 19:08:45 +08:00
using Gameplay.Vehicle.Data;
2023-10-19 15:00:19 +08:00
using PhxhSDK;
2023-08-22 19:08:45 +08:00
using UnityEngine;
namespace Gameplay.Vehicle
{
public class BaseVehicle : GameUnit
{
2023-10-19 15:00:19 +08:00
public readonly VehicleConfigData configData;
public readonly VehicleRuntimeData runtimeData;
2023-08-22 19:08:45 +08:00
public VehicleAnim vAnim;
public BaseBattery battery;
2023-08-22 19:08:45 +08:00
public BaseVehicle(uint id, VehicleConfigData configData,
int troopId) : base(id, troopId, EGameUnitType.Vehicle)
{
debugShowInfo = configData.debugShowInfo;
2023-08-22 19:08:45 +08:00
this.configData = configData;
runtimeData = new VehicleRuntimeData();
runtimeData.owner = this;
runtimeData.configData = configData;
commonData.canControl = troopId == ETroopsId.Self;
}
2024-02-20 13:45:32 +08:00
public async UniTask CreateAsync()
2023-08-22 19:08:45 +08:00
{
2024-02-20 13:45:32 +08:00
GameUnitManager.instance.RecordLoadPath(configData.prefabPath);
2024-01-11 13:33:30 +08:00
var sampleObj = await AssetManager.Instance.LoadAssetAsync<GameObject>(configData.prefabPath);
2023-08-22 19:08:45 +08:00
if (sampleObj == null)
{
2024-01-11 13:33:30 +08:00
DebugUtil.LogError("加载vehicle失败: {0}", configData.prefabPath);
2023-08-22 19:08:45 +08:00
return;
}
// 父节点已销毁
if (Node == null) return;
// 创建对象
var parent = Node.GameObject.transform;
var go = Object.Instantiate(sampleObj, parent, true);
go.transform.ResetLocals();
Node.GameObject.SetLayerEx(Node.GameObject.layer);
// 找到炮台挂点
var allTrans = go.GetComponentsInChildren<Transform>();
var pointName = "Battery_point01";
var fireTrans = allTrans.First(t => t.name == pointName);
battery = new BaseBattery(this, fireTrans);
await battery.CreateView();
2024-12-26 13:24:22 +08:00
//设置涂装
var id = configData.configId;
2025-01-03 19:30:27 +08:00
var paintCfg = Actor.Instance.Character.GetVehicleDevelopment(id)?.paint_set;
2024-12-26 13:24:22 +08:00
if (paintCfg != null)
{
for (int i = 1; i < (int)PaintType.Max; i++)
{
var paintID = paintCfg[i];
if (paintID == 0)
continue;
var paintPath = PathEx.GetVehiclePaintPath((int)id, (int)paintID);
//加载涂装材质球
var material = await CommonUtils.GetVehiclePaintMaterial(paintPath);//临时方法
var root = VehicleDataHelper.FindVehiclePartRoot(go, (int)id, (PaintType)i);
if (material != null && root != null)
{
var renderers = root.GetComponent<SkinnedMeshRenderer>();
renderers.materials = new Material[] { material };
}
}
}
else
DebugUtil.LogError("载具涂装配置为空!");
2023-08-22 19:08:45 +08:00
// 绑定动画数据
vAnim = new VehicleAnim(this);
// 设置后处理
var obj = Node.GameObject;
var isEnemy = commonData.troopId != ETroopsId.Self;
OutlineManager.instance.AutoAddFromObj(obj, isEnemy);
2023-10-19 15:00:19 +08:00
PerformanceManager.instance.HandleCreateUnit(obj);
2023-08-22 19:08:45 +08:00
}
}
}