|  |  |  | 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.LocalPositionOrder; | 
					
						
							|  |  |  |         view.PosView.Value = transView.position; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } |