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.
		
		
		
		
		
			
		
			
	
	
		
			69 lines
		
	
	
		
			1.8 KiB
		
	
	
	
		
			C#
		
	
		
		
			
		
	
	
			69 lines
		
	
	
		
			1.8 KiB
		
	
	
	
		
			C#
		
	
| 
											2 years ago
										 | using Entitas; | ||
|  | using UnityEngine; | ||
|  | using Game; | ||
|  | using Vector3 = UnityEngine.Vector3; | ||
|  | 
 | ||
|  | // view的3d转2d的表现在此处理 | ||
|  | public class ViewSystem : IExecuteSystem, IInitializeSystem | ||
|  | { | ||
|  |     private IGroup<GameEntity> _entities; | ||
|  | 
 | ||
|  |     public void Initialize() | ||
|  |     { | ||
|  |         _entities = Util.GetGroup(GameMatcher.View); | ||
|  |     } | ||
|  | 
 | ||
|  |     public void Execute() | ||
|  |     { | ||
|  |         foreach (var entity in _entities) | ||
|  |         { | ||
|  |             UpdateShake(entity); //更新抖动 | ||
|  |             UpdateViewPos(entity); //更新位置 | ||
|  |             if (Util.IsPause(entity)) | ||
|  |             { | ||
|  |                 continue; | ||
|  |             } | ||
|  | 
 | ||
|  |             UpdateActive(entity); //更新显示 | ||
|  |         } | ||
|  |     } | ||
|  | 
 | ||
|  |     private static void UpdateActive(GameEntity entity) | ||
|  |     { | ||
|  |         var view = entity.view; | ||
|  |         var entityItem = view.EntityPoolItem; | ||
|  |         if (entityItem.IsAlive && !entityItem.GameObject.activeSelf) | ||
|  |         { | ||
|  |             entityItem.GameObject.SetActive(true); | ||
|  |         } | ||
|  |     } | ||
|  | 
 | ||
|  |     private static void UpdateShake(GameEntity entity) | ||
|  |     { | ||
|  |         var view = entity.view; | ||
|  |         if (view.ShakeTimeLeft == 0) | ||
|  |         { | ||
|  |             return; | ||
|  |         } | ||
|  | 
 | ||
|  |         view.ShakeTimeLeft -= Time.unscaledDeltaTime; | ||
|  |         if (view.ShakeTimeLeft < 0) | ||
|  |         { | ||
|  |             view.ShakeTimeLeft = 0; | ||
|  |             view.LocalPositionShake = Vector3.zero; | ||
|  |             return; | ||
|  |         } | ||
|  | 
 | ||
|  |         var shakeDist = Mathf.Sin(view.ShakeTimeLeft * GameConst.ShakeRate) * GameConst.ShakeDistance; | ||
|  |         view.LocalPositionShake = new Vector3(shakeDist, 0, 0); | ||
|  |     } | ||
|  | 
 | ||
|  |     private static void UpdateViewPos(GameEntity entity) | ||
|  |     { | ||
|  |         var view = entity.view; | ||
|  |         view.PositionPre = entity.Pos(); | ||
|  |         var transView = view.TransformViewMain; | ||
|  |         transView.localPosition = view.LocalPositionShake; | ||
|  |         view.PosView.Value = transView.position; | ||
|  |     } | ||
|  | } |