导入敌人模型素材,统一经验和金币掉落物
This commit is contained in:
@@ -201,26 +201,14 @@ namespace SepCore.AsyncTask
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步显示金币掉落实体。
|
||||
/// 异步显示掉落实体。
|
||||
/// </summary>
|
||||
public static UniTask<CoinEntity> ShowCoinAsync(this EntityComponent entityComponent,
|
||||
CoinData data,
|
||||
public static UniTask<DropEntity> ShowDropAsync(this EntityComponent entityComponent,
|
||||
DropData data,
|
||||
float timeout = 30f,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
return ShowEntityByDataAsync<CoinEntity>(entityComponent, typeof(CoinEntity), GameEntry.Luban.Global.DropGroupName,
|
||||
Constant.AssetPriority.EffectAsset, data, timeout, cancellationToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步显示经验掉落实体。
|
||||
/// </summary>
|
||||
public static UniTask<ExpEntity> ShowExpAsync(this EntityComponent entityComponent,
|
||||
ExpData data,
|
||||
float timeout = 30f,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
return ShowEntityByDataAsync<ExpEntity>(entityComponent, typeof(ExpEntity), GameEntry.Luban.Global.DropGroupName,
|
||||
return ShowEntityByDataAsync<DropEntity>(entityComponent, typeof(DropEntity), GameEntry.Luban.Global.DropGroupName,
|
||||
Constant.AssetPriority.EffectAsset, data, timeout, cancellationToken);
|
||||
}
|
||||
|
||||
|
||||
@@ -63,20 +63,13 @@ namespace SepCore.Components
|
||||
{
|
||||
Transform transformToUnregister = _cachedTransform;
|
||||
|
||||
float defaultRadius = GameEntry.Luban != null && GameEntry.Luban.IsReady
|
||||
? GameEntry.Luban.Global.EnemyBodyRadius / 1000f
|
||||
: 0.5f;
|
||||
int defaultIterations = GameEntry.Luban != null && GameEntry.Luban.IsReady
|
||||
? GameEntry.Luban.Global.EnemySeparationIterations
|
||||
: 4;
|
||||
|
||||
_enemyBodyRadius = GameEntry.Luban.Global.EnemyBodyRadius;
|
||||
_separationIterations = GameEntry.Luban.Global.EnemySeparationIterations;
|
||||
_speedBase = 0;
|
||||
_cachedTransform = null;
|
||||
_direction = Vector3.zero;
|
||||
_isMoving = false;
|
||||
_avoidEnemyOverlap = false;
|
||||
_enemyBodyRadius = defaultRadius;
|
||||
_separationIterations = defaultIterations;
|
||||
_player = null;
|
||||
_enemy = null;
|
||||
|
||||
|
||||
@@ -39,11 +39,10 @@ namespace SepCore.Components
|
||||
public void SetMove(bool canMove)
|
||||
{
|
||||
_canMove = canMove;
|
||||
if (!canMove)
|
||||
{
|
||||
_direction = Vector3.zero;
|
||||
SetWalking(false);
|
||||
}
|
||||
if (canMove) return;
|
||||
|
||||
_direction = Vector3.zero;
|
||||
SetWalking(false);
|
||||
}
|
||||
|
||||
public void SetDirection(Vector3 direction)
|
||||
|
||||
@@ -6,6 +6,8 @@ namespace SepCore.Simulation
|
||||
{
|
||||
SimulationStats Stats { get; }
|
||||
|
||||
int PickupCount { get; }
|
||||
|
||||
void Tick(in SimulationTickContext context);
|
||||
|
||||
void ClearSimulationState();
|
||||
|
||||
+3
-18
@@ -224,33 +224,18 @@ namespace SepCore.Simulation
|
||||
continue;
|
||||
}
|
||||
|
||||
if (entity is CoinEntity coin)
|
||||
if (entity is DropEntity drop)
|
||||
{
|
||||
if (player != null)
|
||||
{
|
||||
coin.TryCollect(player);
|
||||
drop.TryCollect(player);
|
||||
}
|
||||
else
|
||||
{
|
||||
var entityComponent = GameEntry.Entity;
|
||||
if (entityComponent != null)
|
||||
{
|
||||
entityComponent.HideEntity(coin);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (entity is ExpEntity exp)
|
||||
{
|
||||
if (player != null)
|
||||
{
|
||||
exp.TryCollect(player);
|
||||
}
|
||||
else
|
||||
{
|
||||
var entityComponent = GameEntry.Entity;
|
||||
if (entityComponent != null)
|
||||
{
|
||||
entityComponent.HideEntity(exp);
|
||||
entityComponent.HideEntity(drop);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0878ab0829c34f44a83d5e5a1eb586ea
|
||||
timeCreated: 1770292173
|
||||
+18
-11
@@ -4,40 +4,47 @@ using UnityGameFramework.Runtime;
|
||||
|
||||
namespace SepCore.Entity
|
||||
{
|
||||
public class CoinEntity : EntityBase
|
||||
public class DropEntity : EntityBase
|
||||
{
|
||||
private CoinData _coinData;
|
||||
private DropData _dropData;
|
||||
private bool _isCollected;
|
||||
|
||||
|
||||
protected override void OnShow(object userData)
|
||||
{
|
||||
base.OnShow(userData);
|
||||
_isCollected = false;
|
||||
|
||||
if (userData is CoinData coinData)
|
||||
if (userData is DropData dropData)
|
||||
{
|
||||
_coinData = coinData;
|
||||
_dropData = dropData;
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.Error("CoinEntity.OnShow() called with wrong type.");
|
||||
Log.Error("DropEntity.OnShow() called with wrong type: {0}.", userData?.GetType().Name);
|
||||
}
|
||||
|
||||
this.CachedTransform.localScale = new Vector3(0.3f, 0.3f, 0.3f);
|
||||
|
||||
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 (_isCollected || player == null || !player.Available || _dropData == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (collectDistance > 0f)
|
||||
{
|
||||
float distance = Vector3.Distance(player.CachedTransform.position, CachedTransform.position);
|
||||
if (distance > collectDistance) return false;
|
||||
if (distance > collectDistance)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
_isCollected = true;
|
||||
player.Coin += _coinData.Value;
|
||||
player.Coin += _dropData.CoinCount;
|
||||
player.Exp += _dropData.ExpCount;
|
||||
GameEntry.Entity.HideEntity(this);
|
||||
return true;
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 46bb2720dba28ea4eb80892da753e866
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -75,20 +75,13 @@ namespace SepCore.Entity
|
||||
{
|
||||
if (Random.value < EnemyData.DropPercent)
|
||||
{
|
||||
var data = new CoinData(EnemyData.DropCoin, GameEntry.Entity.NextId())
|
||||
int coinCount = GameEntry.Luban.Global.DropEntityCoinCount;
|
||||
int expCount = GameEntry.Luban.Global.DropEntityExpCount;
|
||||
var data = new DropData(coinCount, expCount, GameEntry.Entity.NextId())
|
||||
{
|
||||
Position = CachedTransform.position
|
||||
};
|
||||
GameEntry.Entity.ShowCoinAsync(data).Forget();
|
||||
}
|
||||
|
||||
if (Random.value < EnemyData.DropPercent)
|
||||
{
|
||||
var data = new ExpData(EnemyData.DropExp, GameEntry.Entity.NextId())
|
||||
{
|
||||
Position = CachedTransform.position
|
||||
};
|
||||
GameEntry.Entity.ShowExpAsync(data).Forget();
|
||||
GameEntry.Entity.ShowDropAsync(data).Forget();
|
||||
}
|
||||
|
||||
base.OnDead(attacker);
|
||||
|
||||
@@ -1,49 +0,0 @@
|
||||
using SepCore.Entity;
|
||||
using UnityEngine;
|
||||
using UnityGameFramework.Runtime;
|
||||
|
||||
namespace SepCore.Entity
|
||||
{
|
||||
public class ExpEntity:EntityBase
|
||||
{
|
||||
private ExpData _expData;
|
||||
private bool _isCollected;
|
||||
|
||||
protected override void OnShow(object userData)
|
||||
{
|
||||
base.OnShow(userData);
|
||||
_isCollected = false;
|
||||
|
||||
if (userData is ExpData expData)
|
||||
{
|
||||
_expData = expData;
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.Error("expEntity.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 || _expData == null) return false;
|
||||
|
||||
if (collectDistance > 0f)
|
||||
{
|
||||
float distance = Vector3.Distance(player.CachedTransform.position, CachedTransform.position);
|
||||
if (distance > collectDistance) return false;
|
||||
}
|
||||
|
||||
_isCollected = true;
|
||||
player.Exp += _expData.Value;
|
||||
GameEntry.Entity.HideEntity(this);
|
||||
return true;
|
||||
}
|
||||
|
||||
private void OnTriggerEnter(Collider other)
|
||||
{
|
||||
TryCollect(other.GetComponent<Player>());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ec4ae4b0a327442a88463eafd59c5b6e
|
||||
timeCreated: 1770293001
|
||||
@@ -105,7 +105,7 @@ namespace SepCore.Entity
|
||||
return null;
|
||||
}
|
||||
|
||||
float actualTimeout = timeout ?? (GameEntry.Luban.Global.EntityAsyncTimeout / 1000f);
|
||||
float actualTimeout = GameEntry.Luban.Global.EntityAsyncTimeout;
|
||||
WeaponBase weapon = await GameEntry.Entity.ShowWeaponAsync(weaponData, actualTimeout);
|
||||
if (weapon == null)
|
||||
{
|
||||
@@ -160,7 +160,7 @@ namespace SepCore.Entity
|
||||
int id = GameEntry.Entity.NextId();
|
||||
var weaponData = EntityDataFactory.Create(id, nextTierConfig, Id, CampType.Player);
|
||||
|
||||
float actualTimeout = timeout ?? (GameEntry.Luban.Global.EntityAsyncTimeout / 1000f);
|
||||
float actualTimeout = GameEntry.Luban.Global.EntityAsyncTimeout;
|
||||
WeaponBase newWeapon = await GameEntry.Entity.ShowWeaponAsync(weaponData, actualTimeout);
|
||||
if (newWeapon == null)
|
||||
{
|
||||
|
||||
@@ -30,7 +30,8 @@ namespace SepCore.Entity
|
||||
float fromHPRatio = _healthComponent.HealthRatio;
|
||||
_healthComponent.TakeDamage(damageResult.Damage, damageResult.IsCrit, false, hitPosition);
|
||||
float toHPRatio = _healthComponent.HealthRatio;
|
||||
if (fromHPRatio > toHPRatio)
|
||||
bool isDead = _healthComponent.CurrentHealth <= 0;
|
||||
if (fromHPRatio > toHPRatio && !isDead)
|
||||
{
|
||||
GameEntry.HPBar.ShowHPBar(this, fromHPRatio, toHPRatio);
|
||||
}
|
||||
@@ -49,7 +50,7 @@ namespace SepCore.Entity
|
||||
}
|
||||
}
|
||||
|
||||
if (_healthComponent.CurrentHealth <= 0)
|
||||
if (isDead)
|
||||
{
|
||||
OnDead(attacker);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user