You cannot select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
	
	
		
			85 lines
		
	
	
		
			2.7 KiB
		
	
	
	
		
			C#
		
	
			
		
		
	
	
			85 lines
		
	
	
		
			2.7 KiB
		
	
	
	
		
			C#
		
	
| using Entitas;
 | |
| using UnityEngine;
 | |
| using Game;
 | |
| public class BulletSystem : IExecuteSystem, IInitializeSystem
 | |
| {
 | |
|     private IGroup<GameEntity> _entities;
 | |
|     public void Initialize()
 | |
|     {
 | |
|         _entities = Util.GetGroup(GameMatcher.Bullet);
 | |
|     }
 | |
|     public void Execute()
 | |
|     {
 | |
|         foreach (var entity in _entities)
 | |
|         {
 | |
|             if (Util.IsPause(entity))
 | |
|             {
 | |
|                 continue;
 | |
|             }
 | |
|             UpdateBulletViewRot(entity);    // 更新子弹旋转
 | |
|             // UpdateBullet(entity);
 | |
|             UpdateBulletAlive(entity); //子弹销毁
 | |
|         }
 | |
|     }
 | |
|     public void UpdateBulletAlive(GameEntity entity)
 | |
|     {
 | |
|         if (!entity.timeline.IsRunning)
 | |
|         {
 | |
|             //时间轴跑完
 | |
|             Util.DestroyEntity(entity);
 | |
|         }
 | |
|         if (entity.move.IsAgainstWall)
 | |
|         {
 | |
|             //击中墙壁
 | |
|             Util.DestroyEntity(entity);
 | |
|         }
 | |
|         if (entity.skill.SkillHitInfo.Count > 0)
 | |
|         {
 | |
|             //命中
 | |
|             Util.DestroyEntity(entity);
 | |
|         }
 | |
|     }
 | |
|     // public void UpdateBullet(GameEntity entity)
 | |
|     // {
 | |
|     //     var id = entity.iD;
 | |
|     //     var bullet = entity.bullet;
 | |
|     //     var cfg = id.data;
 | |
|     //     var bp = cfg.blueprint;
 | |
|     //     var view = entity.view;
 | |
|     //     bullet.data.target = bullet.target;
 | |
|     //     switch (bullet.state)
 | |
|     //     {
 | |
|     //         case EBpState.Enter:
 | |
|     //             Util.RunBP(bp, GameConst.BP_ENTRANCE_Enter, bullet.data);
 | |
|     //             bullet.state = EBpState.Update;
 | |
|     //             break;
 | |
|     //         case EBpState.Update:
 | |
|     //             var timePast = Mathf.Min(Time.deltaTime, bullet.timeLeft);
 | |
|     //             bullet.timeLeft -= timePast;
 | |
|     //             if (bullet.timeLeft == 0)
 | |
|     //             {
 | |
|     //                 bullet.state = EBpState.Leave;
 | |
|     //             }
 | |
|     //             if (bullet.positionPre != Vector3.zero)
 | |
|     //             {
 | |
|     //                 Util.RunBP(bp, GameConst.BP_ENTRANCE_Update, bullet.data);
 | |
|     //             }
 | |
|     //             bullet.positionPre = entity.GetPos(); //刷新上一次位置
 | |
|     //             break;
 | |
|     //         case EBpState.Leave:
 | |
|     //             Util.RunBP(bp, GameConst.BP_ENTRANCE_Leave, bullet.data);
 | |
|     //             Util.DestroyEntity(entity);
 | |
|     //             break;
 | |
|     //     }
 | |
|     // }
 | |
|     public void UpdateBulletViewRot(GameEntity entity)
 | |
|     {
 | |
|         var view = entity.view;
 | |
|         var dir = entity.move.MoveDir;
 | |
|         if (dir.magnitude > 0)
 | |
|         {
 | |
|             var rot = Quaternion.FromToRotation(Vector3.right, dir);
 | |
|             view.TransformView.localRotation = rot;
 | |
|         }
 | |
|     }
 | |
| } |