From d28ccaa7f92cf0613974676a35643256f7c838c2 Mon Sep 17 00:00:00 2001 From: SepComet <202308010230@stu.csust.edu.cn> Date: Sat, 6 Jun 2026 15:13:52 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BF=81=E7=A7=BB=20Coin/Exp/Projectile/Effect?= =?UTF-8?q?=20=E5=AE=9E=E4=BD=93=E7=9A=84=E7=94=9F=E6=88=90=E8=B7=AF?= =?UTF-8?q?=E5=BE=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SimulationWorld.HitPresentation.cs | 4 ++- .../Entity/EntityLogic/Enemy/EnemyBase.cs | 30 ++++++++++++++++- .../Entity/EntityLogic/Enemy/MeleeEnemy.cs | 32 ++++--------------- .../Entity/EntityLogic/Enemy/RemoteEnemy.cs | 22 +++++++------ .../Entity/EntityLogic/TargetableObject.cs | 10 +----- 5 files changed, 53 insertions(+), 45 deletions(-) diff --git a/Assets/GameMain/Scripts/Runtime/CustomComponent/Simulation/Presentation/SimulationWorld.HitPresentation.cs b/Assets/GameMain/Scripts/Runtime/CustomComponent/Simulation/Presentation/SimulationWorld.HitPresentation.cs index 90768a0..4845897 100644 --- a/Assets/GameMain/Scripts/Runtime/CustomComponent/Simulation/Presentation/SimulationWorld.HitPresentation.cs +++ b/Assets/GameMain/Scripts/Runtime/CustomComponent/Simulation/Presentation/SimulationWorld.HitPresentation.cs @@ -1,6 +1,8 @@ using SepCore.Event; using SepCore.Entity; +using SepCore.AsyncTask; using SepCore.Entity.Weapon; +using Cysharp.Threading.Tasks; using GameFramework.Event; using UnityEngine; @@ -127,7 +129,7 @@ namespace SepCore.Simulation { Position = args.HitPosition }; - entityComponent.ShowEffect(effectData); + entityComponent.ShowEffectAsync(effectData).Forget(); } } } diff --git a/Assets/GameMain/Scripts/Runtime/Entity/EntityLogic/Enemy/EnemyBase.cs b/Assets/GameMain/Scripts/Runtime/Entity/EntityLogic/Enemy/EnemyBase.cs index 2417f0a..437244e 100644 --- a/Assets/GameMain/Scripts/Runtime/Entity/EntityLogic/Enemy/EnemyBase.cs +++ b/Assets/GameMain/Scripts/Runtime/Entity/EntityLogic/Enemy/EnemyBase.cs @@ -1,4 +1,6 @@ -using SepCore.Definition; +using Cysharp.Threading.Tasks; +using SepCore.AsyncTask; +using SepCore.Definition; using SepCore.Entity; using UnityEngine; @@ -10,5 +12,31 @@ public abstract class EnemyBase : TargetableObject public virtual float AttackRange => 1f; public virtual void SetTarget(Transform target) => _target = target; + + protected EnemyData _enemyData; + + + protected override void OnDead(EntityBase attacker) + { + if (Random.value < _enemyData.DropPercent) + { + var data = new CoinData(_enemyData.DropCoin, GameEntry.Entity.NextId(), 10001) + { + Position = this.CachedTransform.position + }; + GameEntry.Entity.ShowCoinAsync(data).Forget(); + } + + if (Random.value < _enemyData.DropPercent) + { + var data = new ExpData(_enemyData.DropExp, GameEntry.Entity.NextId(), 10002) + { + Position = this.CachedTransform.position + }; + GameEntry.Entity.ShowExpAsync(data).Forget(); + } + + base.OnDead(attacker); + } } diff --git a/Assets/GameMain/Scripts/Runtime/Entity/EntityLogic/Enemy/MeleeEnemy.cs b/Assets/GameMain/Scripts/Runtime/Entity/EntityLogic/Enemy/MeleeEnemy.cs index 2d44bf3..cf20541 100644 --- a/Assets/GameMain/Scripts/Runtime/Entity/EntityLogic/Enemy/MeleeEnemy.cs +++ b/Assets/GameMain/Scripts/Runtime/Entity/EntityLogic/Enemy/MeleeEnemy.cs @@ -1,7 +1,6 @@ using SepCore.Components; using SepCore.CustomUtility; using SepCore.Definition; -using SepCore.Entity; using UnityEngine; using UnityGameFramework.Runtime; @@ -27,7 +26,13 @@ namespace SepCore.Entity private float _currAttackTimer; private AttackStateType _attackState = AttackStateType.Idle; - private EnemyData _meleeEnemyData; + + private EnemyData _meleeEnemyData + { + get => _enemyData; + set => _enemyData = value; + } + private TargetableObject _targetableTarget; protected override TargetableObjectData _targetableObjectData => _meleeEnemyData; @@ -83,29 +88,6 @@ namespace SepCore.Entity UpdateAttackState(elapseSeconds); } - protected override void OnDead(EntityBase attacker) - { - if (Random.value < _meleeEnemyData.DropPercent) - { - var data = new CoinData(_meleeEnemyData.DropCoin, GameEntry.Entity.NextId(), 10001) - { - Position = this.CachedTransform.position - }; - GameEntry.Entity.ShowCoin(data); - } - - if (Random.value < _meleeEnemyData.DropPercent) - { - var data = new ExpData(_meleeEnemyData.DropExp, GameEntry.Entity.NextId(), 10002) - { - Position = this.CachedTransform.position - }; - GameEntry.Entity.ShowExp(data); - } - - base.OnDead(attacker); - } - protected override void OnHide(bool isShutdown, object userData) { _movementComponent.OnReset(); diff --git a/Assets/GameMain/Scripts/Runtime/Entity/EntityLogic/Enemy/RemoteEnemy.cs b/Assets/GameMain/Scripts/Runtime/Entity/EntityLogic/Enemy/RemoteEnemy.cs index 8104de7..25c3af0 100644 --- a/Assets/GameMain/Scripts/Runtime/Entity/EntityLogic/Enemy/RemoteEnemy.cs +++ b/Assets/GameMain/Scripts/Runtime/Entity/EntityLogic/Enemy/RemoteEnemy.cs @@ -1,7 +1,8 @@ using SepCore.Components; +using SepCore.AsyncTask; using SepCore.CustomUtility; using SepCore.Definition; -using SepCore.Entity; +using Cysharp.Threading.Tasks; using UnityEngine; using UnityGameFramework.Runtime; @@ -34,7 +35,11 @@ namespace SepCore.Entity [SerializeField] private float _projectileSpawnHeightOffset = 0.6f; [SerializeField] private string _projectileAssetName = "BulletHandgun"; - private EnemyData _remoteEnemyData; + private EnemyData _remoteEnemyData + { + get => _enemyData; + set => _enemyData = value; + } protected override TargetableObjectData _targetableObjectData => _remoteEnemyData; public override float AttackRange => _attackRange; @@ -154,13 +159,12 @@ namespace SepCore.Entity Rotation = Quaternion.LookRotation(direction, Vector3.up) }; - GameEntry.Entity.ShowEntity( - entityId: projectileEntityId, - entityLogicType: typeof(EnemyProjectile), - entityAssetName: AssetUtility.GetEntityAsset(_projectileAssetName), - entityGroupName: EnemyProjectileGroupName, - priority: Constant.AssetPriority.BulletAsset, - userData: projectileData); + GameEntry.Entity.ShowEntityAsync( + projectileEntityId, + AssetUtility.GetEntityAsset(_projectileAssetName), + EnemyProjectileGroupName, + Constant.AssetPriority.BulletAsset, + projectileData).Forget(); _currAttackTimer = 0f; } diff --git a/Assets/GameMain/Scripts/Runtime/Entity/EntityLogic/TargetableObject.cs b/Assets/GameMain/Scripts/Runtime/Entity/EntityLogic/TargetableObject.cs index 847e14a..0e94ab5 100644 --- a/Assets/GameMain/Scripts/Runtime/Entity/EntityLogic/TargetableObject.cs +++ b/Assets/GameMain/Scripts/Runtime/Entity/EntityLogic/TargetableObject.cs @@ -1,13 +1,5 @@ -//------------------------------------------------------------ -// Game Framework -// Copyright © 2013-2021 Jiang Yin. All rights reserved. -// Homepage: https://gameframework.cn/ -// Feedback: mailto:ellan@gameframework.cn -//------------------------------------------------------------ - -using SepCore.Components; +using SepCore.Components; using SepCore.Definition; -using SepCore.Entity; using SepCore.CustomUtility; using UnityEngine;