|  |  |  | using System; | 
					
						
							|  |  |  | using UnityEngine; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace Game | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     public class SkillHitInfo | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         public AttackBehaviour SkillParam; | 
					
						
							|  |  |  |         public float AttackRate; | 
					
						
							|  |  |  |         public float StunkRate; | 
					
						
							|  |  |  |         public float ExecutekRate; | 
					
						
							|  |  |  |         public int OwnerEntity; | 
					
						
							|  |  |  |         public int HitEntity; //0为非实体对象 | 
					
						
							|  |  |  |         public Vector3 HitPos; | 
					
						
							|  |  |  |         public Vector3 HitDir; | 
					
						
							|  |  |  |         public bool IsRight; | 
					
						
							|  |  |  |         public bool IsDealed; //已经结算 | 
					
						
							|  |  |  |         public string SkillId; //是否技能造成的伤害 | 
					
						
							|  |  |  |         public uint Performance; //性能tag的mask | 
					
						
							|  |  |  |         public int StaggerLevel; | 
					
						
							|  |  |  |         public bool IsBreak; | 
					
						
							|  |  |  |         public EHitType HitType; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public class ClipAttack : TimelineClipBase | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         private AttackClip _mRealAsset; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         public override void OnEnter() | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             _mRealAsset = Asset as AttackClip; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         public override void OnStay() | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             var skill = Owner.skill; | 
					
						
							|  |  |  |             var castDir = Owner.skill.CastDir; | 
					
						
							|  |  |  |             castDir = new Vector3(castDir.x, 0, castDir.z); //忽略y | 
					
						
							|  |  |  |             var param = _mRealAsset.template; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             void DealFunc(GameObject hitGo, Vector3 hitPos) | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 var hitEntityId = 0; | 
					
						
							|  |  |  |                 EntityInfo info; | 
					
						
							|  |  |  |                 if (hitGo.TryGetComponent<EntityInfo>(out info)) | 
					
						
							|  |  |  |                 { | 
					
						
							|  |  |  |                     hitEntityId = info.entityId; | 
					
						
							|  |  |  |                     if (Util.GetEntity(hitEntityId).Team() == Owner.Team()) | 
					
						
							|  |  |  |                     { | 
					
						
							|  |  |  |                         return; | 
					
						
							|  |  |  |                     } | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 var hitKey = new Tuple<int, int>(hitEntityId, param.hitId); | 
					
						
							|  |  |  |                 if (!Owner.skill.SkillHitInfo.ContainsKey(hitKey)) | 
					
						
							|  |  |  |                 { | 
					
						
							|  |  |  |                     var skillHitInfo = new SkillHitInfo() | 
					
						
							|  |  |  |                     { | 
					
						
							|  |  |  |                         SkillParam = param, | 
					
						
							|  |  |  |                         AttackRate = 1, | 
					
						
							|  |  |  |                         StunkRate = 1, | 
					
						
							|  |  |  |                         ExecutekRate = 1, | 
					
						
							|  |  |  |                         OwnerEntity = Owner.ID(), | 
					
						
							|  |  |  |                         HitEntity = hitEntityId, | 
					
						
							|  |  |  |                         HitPos = hitPos, | 
					
						
							|  |  |  |                         HitDir = castDir, | 
					
						
							|  |  |  |                         IsRight = Owner.move.IsRight, | 
					
						
							|  |  |  |                         IsDealed = false, | 
					
						
							|  |  |  |                         SkillId = skill.SkillId.Value, | 
					
						
							|  |  |  |                         Performance = 0, | 
					
						
							|  |  |  |                         StaggerLevel = param.staggerLevel, | 
					
						
							|  |  |  |                         IsBreak = true, | 
					
						
							|  |  |  |                         HitType = param.hitType, | 
					
						
							|  |  |  |                     }; | 
					
						
							|  |  |  |                     if (!string.IsNullOrEmpty(skillHitInfo.SkillId)) | 
					
						
							|  |  |  |                     { | 
					
						
							|  |  |  |                         var skillCfg = Util.GetSkillMasterConfigData(skillHitInfo.SkillId); | 
					
						
							|  |  |  |                         if (skillCfg != null) | 
					
						
							|  |  |  |                         { | 
					
						
							|  |  |  |                             var featureSkill = skillCfg.GetFeatureSkill(); | 
					
						
							|  |  |  |                             skillHitInfo.AttackRate = featureSkill.AttackRate; | 
					
						
							|  |  |  |                             skillHitInfo.StunkRate = featureSkill.StunRate; | 
					
						
							|  |  |  |                             skillHitInfo.ExecutekRate = featureSkill.ExecuteRate; | 
					
						
							|  |  |  |                         } | 
					
						
							|  |  |  |                     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                     Owner.skill.SkillHitInfo[hitKey] = skillHitInfo; | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             if (param.isRaycast) | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 var posPre = Owner.PosPre(); | 
					
						
							|  |  |  |                 var pos = Owner.Pos(); | 
					
						
							|  |  |  |                 var distance = Vector3.Distance(pos, posPre); | 
					
						
							|  |  |  |                 var dir = pos - posPre; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 var hitInfos = Physics.RaycastAll(posPre, dir, distance, UtilPhysics.LayerMaskHit); | 
					
						
							|  |  |  |                 Util.Draw(posPre, pos, Color.green); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 foreach (var hitInfo in hitInfos) | 
					
						
							|  |  |  |                 { | 
					
						
							|  |  |  |                     var hitGo = hitInfo.transform.gameObject; | 
					
						
							|  |  |  |                     DealFunc(hitGo, hitInfo.point); | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             else | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 var rot = Quaternion.FromToRotation(Vector3.right, castDir); | 
					
						
							|  |  |  |                 var toGridSize = 16f / 64f; | 
					
						
							|  |  |  |                 var center = rot * param.center * toGridSize + Owner.Pos(); | 
					
						
							|  |  |  |                 var halfExtents = param.halfExtents * toGridSize; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 var hitInfos = Physics.BoxCastAll(center, halfExtents, castDir, rot, 0, | 
					
						
							|  |  |  |                     layerMask: UtilPhysics.LayerMaskHit); | 
					
						
							|  |  |  |                 Util.DrawBox(center, halfExtents, castDir, Color.green); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 foreach (var hitInfo in hitInfos) | 
					
						
							|  |  |  |                 { | 
					
						
							|  |  |  |                     var hitGo = hitInfo.transform.gameObject; | 
					
						
							|  |  |  |                     DealFunc(hitGo, hitInfo.point); | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         public override void OnLeave() | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } |