Files
Main/Assets/Code/Logic/_Required/Entity/Object/GroundBuff.cs
2025-01-25 04:38:09 +08:00

88 lines
2.6 KiB
C#

using Thousandto.Core.Asset;
using Thousandto.Cfg.Data;
using Thousandto.Code.Center;
using UnityEngine;
namespace Thousandto.Code.Logic
{
//地面buff对象
public class GroundBuff : Entity
{
#region//私有变量
private DeclareGroundBuff _buffCfg = null;
private FGameObjectVFX _vfx = null;
private float _sqrLogicSize = 0f;
private float _frontSendTime = 0f;
private int _actType = 0;
#endregion
#region//初始化,加载Skin,卸载处理
protected override FSkinBase OnSetupSkin()
{
FSkinModel skin = GameCenter.LuaSystem.Adaptor.CreateFSkinModel(FSkinTypeCode.Custom);
skin.SetLayer(LayerUtils.SceneVFX);
return skin;
}
protected override bool OnInitializeAfter(EntityInitInfo baseInfo)
{
base.OnInitializeAfter(baseInfo);
var info = baseInfo as GroundBuffInitInfo;
SyncInfo(info);
return true;
}
protected override void OnUninitializeBefore()
{
if (_vfx != null)
{
_vfx.Destroy();
}
base.OnUninitializeBefore();
}
public void SyncInfo(GroundBuffInitInfo info)
{
_buffCfg = info.Cfg;
_sqrLogicSize = (_buffCfg.LogicBodySize / 100f) * (_buffCfg.LogicBodySize / 100f);
if (_vfx != null)
{
_vfx.Destroy();
}
_frontSendTime = 0f;
_actType = info.ActType;
_vfx = new FGameObjectVFX(ModelTypeCode.OtherVFX, _buffCfg.Res);
_vfx.SetParent(this.ModelTransform);
_vfx.SetPosition(Position);
_vfx.SetLayer(this.Layer);
_vfx.Play();
}
protected override void OnUpdate(float dt)
{
//生命池不发消息
if (_actType == 2)
return;
if(_buffCfg != null)
{
var lp = GameCenter.GameSceneSystem.GetLocalPlayer();
if(lp != null)
{
if(GetSqrDistance2d(lp.Position2d) <= _sqrLogicSize && (Time.realtimeSinceStartup - _frontSendTime) >= 1f)
{
//发送碰撞消息
_frontSendTime = Time.realtimeSinceStartup;
MSG_Map.ReqGroundBuffStar msg = new MSG_Map.ReqGroundBuffStar();
msg.gbid = this.ID;
msg.Send();
}
}
}
base.OnUpdate(dt);
}
#endregion
}
}