156 lines
4.5 KiB
C#
156 lines
4.5 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using Cysharp.Threading.Tasks;
|
|
using Gameplay.Effect;
|
|
using Gameplay.Skill;
|
|
using Gameplay.Unit;
|
|
using Gameplay.Unit.Data;
|
|
using PhxhSDK;
|
|
|
|
namespace Gameplay.Summon
|
|
{
|
|
using cfg.SummonCfg;
|
|
using Level;
|
|
using LTGame;
|
|
using UnityEngine;
|
|
|
|
public class BaseSummon : GameUnit
|
|
{
|
|
|
|
public readonly DataSummon configData;
|
|
public readonly SummonRuntimeData runtimeData;
|
|
|
|
protected NStateMachine<BaseSummonState> _fsm;
|
|
|
|
public readonly GameUnit creator;
|
|
|
|
public BaseSummon(DataSummon configData, uint id, GameUnit creator) : base(id, creator.commonData.troopId, EGameUnitType.Summon)
|
|
{
|
|
// TODO: 暂时不知道从哪里读
|
|
commonData.level = 1;
|
|
this.creator = creator;
|
|
this.configData = configData;
|
|
runtimeData = new SummonRuntimeData();
|
|
runtimeData.remainExistTime = configData.ExistTime;
|
|
|
|
commonData.canControl = false;
|
|
statusData.canBeAttack = configData.CanBeAttack;
|
|
|
|
commonData.standLevel = configData.StandCrossLevel;
|
|
commonData.crossLevel = configData.MoveCrossLevel;
|
|
}
|
|
|
|
private void _InitFsm()
|
|
{
|
|
_OnInitFsm();
|
|
}
|
|
|
|
protected virtual void _OnInitFsm()
|
|
{
|
|
_fsm = new NStateMachine<BaseSummonState>();
|
|
_fsm.Add(new SummonStateWaitRemove(this));
|
|
}
|
|
|
|
public async void Create()
|
|
{
|
|
var modelPath = configData.ModelPath;
|
|
var loadObj = await AssetManager.Instance.LoadAssetAsync<GameObject>(modelPath);
|
|
if (loadObj == null)
|
|
{
|
|
return;
|
|
}
|
|
var instObj = Object.Instantiate(loadObj, Node.GameObject.transform);
|
|
instObj.transform.localPosition = Vector3.zero;
|
|
instObj.transform.localRotation = Quaternion.identity;
|
|
instObj.transform.localScale = Vector3.one;
|
|
|
|
Node.GameObject.SetLayerEx(Node.GameObject.layer);
|
|
}
|
|
|
|
public void Init(int createCellIndex, float yaw)
|
|
{
|
|
_InitNode(createCellIndex, yaw);
|
|
_OnInited();
|
|
_InitFsm();
|
|
}
|
|
|
|
private void _InitNode(int createCellIndex, float yaw)
|
|
{
|
|
var map = LevelManager.Instance.CurrentLevel.Map;
|
|
var worldPos = map.TGSCellIndex2WorldPosition(createCellIndex);
|
|
transData.pos = worldPos;
|
|
transData.yaw = yaw;
|
|
|
|
Node.GameObject.transform.SetPositionAndRotation(transData.pos, transData.rot);
|
|
}
|
|
|
|
protected virtual void _OnInited() {
|
|
|
|
}
|
|
|
|
protected override void _OnLogicUpdate(float dt)
|
|
{
|
|
base._OnLogicUpdate(dt);
|
|
|
|
_UpdateExitTime(dt);
|
|
|
|
_fsm.LogicUpdate(dt);
|
|
|
|
_UpdateTrans(dt);
|
|
}
|
|
|
|
private void _UpdateExitTime(float dt)
|
|
{
|
|
runtimeData.remainExistTime -= dt;
|
|
}
|
|
|
|
private void _UpdateTrans(float dt)
|
|
{
|
|
if (IsDispose()) return;
|
|
if (transData.isTransChanged)
|
|
{
|
|
Node.GameObject.transform.SetPositionAndRotation(transData.pos, transData.rot);
|
|
}
|
|
transData.Reset();
|
|
}
|
|
|
|
protected float _ReatFloatParam(int index)
|
|
{
|
|
if (configData.FloatParams.Count <= index)
|
|
{
|
|
DebugUtil.LogError("技能参数不足: " + configData.RoleID + " " + index);
|
|
return 0;
|
|
}
|
|
return configData.FloatParams[index];
|
|
}
|
|
|
|
protected int _ReadIntParam(int index)
|
|
{
|
|
var floatVal = _ReatFloatParam(index);
|
|
return Mathf.RoundToInt(floatVal);
|
|
}
|
|
|
|
protected override void OnDispose()
|
|
{
|
|
// 播放销毁特效
|
|
if (configData.DestroyEffectId > 0)
|
|
{
|
|
EffectManager.instance.PlayEffectById(configData.DestroyEffectId,
|
|
Node.GameObject.transform.position,
|
|
Node.GameObject.transform.rotation);
|
|
}
|
|
|
|
// 播放销毁音效
|
|
if (configData.DestroyAudioId > 0)
|
|
{
|
|
_ = AudioManager.Instance.PlayAudio(configData.DestroyAudioId, Node.GameObject.transform.position);
|
|
}
|
|
base.OnDispose();
|
|
}
|
|
|
|
}
|
|
}
|