添加 SepCore.Runtime 和 SepCore.Base 程序集
- 暂时将 Entity 全部归进 Runtime 程序集里 - 调整部分 UI 的 UseCase/RawData/Context 之间的关系,让 RawData 更接近业务原始数据,Context 更接近 UI 直接可读的数据 - 调整其他程序集的引用关系
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
using Entity.EntityData;
|
||||
using UnityEngine;
|
||||
using UnityGameFramework.Runtime;
|
||||
|
||||
namespace Entity
|
||||
{
|
||||
public class CoinEntity : EntityBase
|
||||
{
|
||||
private CoinData _coinData;
|
||||
private bool _isCollected;
|
||||
|
||||
protected override void OnShow(object userData)
|
||||
{
|
||||
base.OnShow(userData);
|
||||
_isCollected = false;
|
||||
|
||||
if (userData is CoinData coinData)
|
||||
{
|
||||
_coinData = coinData;
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.Error("CoinEntity.OnShow() called with wrong type.");
|
||||
}
|
||||
|
||||
this.CachedTransform.localScale = new Vector3(0.3f, 0.3f, 0.3f);
|
||||
}
|
||||
|
||||
public bool TryCollect(Player player, float collectDistance = 0f)
|
||||
{
|
||||
if (_isCollected || player == null || !player.Available || _coinData == null) return false;
|
||||
|
||||
if (collectDistance > 0f)
|
||||
{
|
||||
float distance = Vector3.Distance(player.CachedTransform.position, CachedTransform.position);
|
||||
if (distance > collectDistance) return false;
|
||||
}
|
||||
|
||||
_isCollected = true;
|
||||
player.Coin += _coinData.Value;
|
||||
GameEntry.Entity.HideEntity(this);
|
||||
return true;
|
||||
}
|
||||
|
||||
private void OnTriggerEnter(Collider other)
|
||||
{
|
||||
TryCollect(other.GetComponent<Player>());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user