102 lines
3.5 KiB
C#
102 lines
3.5 KiB
C#
using System.Linq;
|
|
using cfg.VihecleCultivateCfg;
|
|
using Cysharp.Threading.Tasks;
|
|
using Gameplay.Character;
|
|
using Gameplay.Net;
|
|
using Gameplay.Performance;
|
|
using Gameplay.Unit;
|
|
using Gameplay.Unit.Data;
|
|
using Gameplay.Utils;
|
|
using Gameplay.Vehicle.Data;
|
|
using PhxhSDK;
|
|
using UnityEngine;
|
|
namespace Gameplay.Vehicle
|
|
{
|
|
public class BaseVehicle : GameUnit
|
|
{
|
|
|
|
public readonly VehicleConfigData configData;
|
|
public readonly VehicleRuntimeData runtimeData;
|
|
|
|
public VehicleAnim vAnim;
|
|
|
|
public BaseBattery battery;
|
|
|
|
public BaseVehicle(uint id, VehicleConfigData configData,
|
|
int troopId) : base(id, troopId, EGameUnitType.Vehicle)
|
|
{
|
|
debugShowInfo = configData.debugShowInfo;
|
|
this.configData = configData;
|
|
runtimeData = new VehicleRuntimeData();
|
|
runtimeData.owner = this;
|
|
runtimeData.configData = configData;
|
|
|
|
commonData.canControl = troopId == ETroopsId.Self;
|
|
}
|
|
|
|
public async UniTask CreateAsync()
|
|
{
|
|
GameUnitManager.instance.RecordLoadPath(configData.prefabPath);
|
|
var sampleObj = await AssetManager.Instance.LoadAssetAsync<GameObject>(configData.prefabPath);
|
|
if (sampleObj == null)
|
|
{
|
|
DebugUtil.LogError("加载vehicle失败: {0}", configData.prefabPath);
|
|
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();
|
|
|
|
//设置涂装
|
|
var id = configData.configId;
|
|
var paintCfg = Actor.Instance.Character.GetVehicleDevelopment(id)?.paint_set;
|
|
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("载具涂装配置为空!");
|
|
|
|
// 绑定动画数据
|
|
vAnim = new VehicleAnim(this);
|
|
|
|
// 设置后处理
|
|
var obj = Node.GameObject;
|
|
var isEnemy = commonData.troopId != ETroopsId.Self;
|
|
OutlineManager.instance.AutoAddFromObj(obj, isEnemy);
|
|
|
|
PerformanceManager.instance.HandleCreateUnit(obj);
|
|
}
|
|
|
|
}
|
|
}
|