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.
		
		
		
		
		
			
		
			
	
	
		
			184 lines
		
	
	
		
			6.7 KiB
		
	
	
	
		
			C#
		
	
		
		
			
		
	
	
			184 lines
		
	
	
		
			6.7 KiB
		
	
	
	
		
			C#
		
	
| 
											2 years ago
										 | using System.Collections.Generic; | ||
|  | using UnityEngine; | ||
|  | using Bolt; | ||
|  | 
 | ||
|  | namespace Game | ||
|  | { | ||
|  | 
 | ||
|  |     [UnitTitle("测试打印")] | ||
|  |     [UnitSubtitle("NodeDebugLog")] | ||
|  |     [UnitCategory("Game-Common")] | ||
|  |     public class NodeDebugLog : NodeDefault | ||
|  |     { | ||
|  |         public ValueInput log { get; private set; } | ||
|  |         protected override void Def() | ||
|  |         { | ||
|  |             log = ValueInput<object>("log"); | ||
|  |         } | ||
|  |         protected override void Run(Flow flow) | ||
|  |         { | ||
|  |             Util.Print(flow.GetValue<object>(log)); | ||
|  |         } | ||
|  |     } | ||
|  |     [UnitTitle("射线检测(1->2)")] | ||
|  |     [UnitSubtitle("NodeRayCast")] | ||
|  |     [UnitCategory("Game-Common")] | ||
|  |     public class NodeRayCast : NodeDefault | ||
|  |     { | ||
|  |         public ValueInput pos1; | ||
|  |         public ValueInput pos2; | ||
|  |         public ValueOutput target; | ||
|  |         protected override void Def() | ||
|  |         { | ||
|  |             pos1 = ValueInput<Vector3>("p1"); | ||
|  |             pos2 = ValueInput<Vector3>("p2"); | ||
|  |             target = ValueOutput<List<int>>("target"); | ||
|  |         } | ||
|  |         protected override void Run(Flow flow) | ||
|  |         { | ||
|  |             var entity = Util.GetEntity(data.Entity); | ||
|  |             var p1 = flow.GetValue<Vector3>(pos1); | ||
|  |             var p2 = flow.GetValue<Vector3>(pos2); | ||
|  |             var dir = p2 - p1; | ||
|  |             tempListInt.Clear(); | ||
|  |             if (dir.magnitude != 0) | ||
|  |             { | ||
|  |                 var hitInfos = Physics.RaycastAll(p1, dir, dir.magnitude, layerMask: UtilPhysics.LayerMaskHit); | ||
|  |                 foreach (var hitInfo in hitInfos) | ||
|  |                 { | ||
|  |                     var hitGo = hitInfo.transform.gameObject; | ||
|  |                     var hitEntityId = 0; | ||
|  |                     EntityInfo info; | ||
|  |                     if (hitGo.TryGetComponent<EntityInfo>(out info)) | ||
|  |                     { | ||
|  |                         hitEntityId = info.entityId; | ||
|  |                         if (Util.GetEntity(hitEntityId).Team() == entity.Team()) | ||
|  |                         { | ||
|  |                             continue; | ||
|  |                         } | ||
|  |                         tempListInt.Add(hitEntityId); | ||
|  |                     } | ||
|  |                 } | ||
|  |             } | ||
|  |             flow.SetValue(target, tempListInt); | ||
|  |         } | ||
|  |     } | ||
|  |     [UnitTitle("Box检测(1->2)")] | ||
|  |     [UnitSubtitle("NodeBoxCast")] | ||
|  |     [UnitCategory("Game-Common")] | ||
|  |     public class NodeBoxCast : NodeDefault | ||
|  |     { | ||
|  |         public ValueInput pos1; | ||
|  |         public ValueInput pos2; | ||
|  |         public ValueInput width; | ||
|  |         public ValueInput height; | ||
|  |         public ValueOutput target; | ||
|  |         protected override void Def() | ||
|  |         { | ||
|  |             pos1 = ValueInput<Vector3>("p1"); | ||
|  |             pos2 = ValueInput<Vector3>("p2"); | ||
|  |             width = ValueInput<float>("width"); | ||
|  |             height = ValueInput<float>("height"); | ||
|  |             target = ValueOutput<List<int>>("target"); | ||
|  |         } | ||
|  |         protected override void Run(Flow flow) | ||
|  |         { | ||
|  |             var entity = Util.GetEntity(data.Entity); | ||
|  |             var p1 = flow.GetValue<Vector3>(pos1); | ||
|  |             var p2 = flow.GetValue<Vector3>(pos2); | ||
|  |             var w = flow.GetValue<float>(width); | ||
|  |             var h = flow.GetValue<float>(height); | ||
|  |             var dir = p2 - p1; | ||
|  |             tempListInt.Clear(); | ||
|  |             if (dir.magnitude != 0) | ||
|  |             { | ||
|  |                 var center = (p2 + p1) / 2; | ||
|  |                 var halfExtents = new Vector3(w / 2, h / 2, dir.magnitude); | ||
|  |                 var rot = Quaternion.FromToRotation(Vector3.right, dir); | ||
|  |                 var hitInfos = Physics.BoxCastAll(center, halfExtents, dir, rot, 0, layerMask: UtilPhysics.LayerMaskHit); | ||
|  |                 Util.DrawBox(center, halfExtents, dir, Color.green); | ||
|  |                 foreach (var hitInfo in hitInfos) | ||
|  |                 { | ||
|  |                     var hitGo = hitInfo.transform.gameObject; | ||
|  |                     var hitEntityId = 0; | ||
|  |                     EntityInfo info; | ||
|  |                     if (hitGo.TryGetComponent<EntityInfo>(out info)) | ||
|  |                     { | ||
|  |                         hitEntityId = info.entityId; | ||
|  |                         if (Util.GetEntity(hitEntityId).Team() == entity.Team()) | ||
|  |                         { | ||
|  |                             continue; | ||
|  |                         } | ||
|  |                         tempListInt.Add(hitEntityId); | ||
|  |                     } | ||
|  |                 } | ||
|  |             } | ||
|  |             flow.SetValue(target, tempListInt); | ||
|  |         } | ||
|  |     } | ||
|  |     // [UnitTitle("造成伤害")] | ||
|  |     // [UnitSubtitle("NodeDamage")] | ||
|  |     // [UnitCategory("Game-Common")] | ||
|  |     // public class NodeDamage : NodeDefault | ||
|  |     // { | ||
|  |     //     public ValueInput target; | ||
|  |     //     public ValueInput damageRate; | ||
|  |     //     public ValueInput hitDir; | ||
|  |     //     public ValueInput isFlow; | ||
|  |     //     public ValueInput hitId; | ||
|  |     //     public ValueInput isSkill; | ||
|  |     //     public ValueInput performance; | ||
|  |     //     protected override void Def() | ||
|  |     //     { | ||
|  |     //         target = ValueInput<int>("entity"); | ||
|  |     //         damageRate = ValueInput<float>("damageRate"); | ||
|  |     //         hitDir = ValueInput<Vector3>("hitDir"); | ||
|  |     //         isFlow = ValueInput<bool>("isFlow"); | ||
|  |     //         hitId = ValueInput<int>("hitId"); | ||
|  |     //         isSkill = ValueInput<bool>("isSkill"); | ||
|  |     //         performance = ValueInput<ESKillPerformance>("performance"); | ||
|  |     //     } | ||
|  |     //     protected override void Run(Flow flow) | ||
|  |     //     { | ||
|  |     //         var t = flow.GetValue<int>(target); | ||
|  |     //         var d = flow.GetValue<float>(damageRate); | ||
|  |     //         var hd = flow.GetValue<Vector3>(hitDir); | ||
|  |     //         var ifw = flow.GetValue<bool>(isFlow); | ||
|  |     //         var hid = flow.GetValue<int>(hitId); | ||
|  |     //         var s = flow.GetValue<bool>(isSkill); | ||
|  |     //         var p = flow.GetValue<ESKillPerformance>(performance); | ||
|  |     //         var hitKey = new Tuple<int, int>(t, hid); | ||
|  |     //         var owner = Util.GetEntity(data.owner); | ||
|  |     //         var targetEntity = Util.GetEntity(t); | ||
|  |     //         var hitInfo = new SkillHitInfo() | ||
|  |     //         { | ||
|  |     //             skillParam = new AttackBehaviour() | ||
|  |     //             { | ||
|  |     //                 isFlow = ifw, | ||
|  |     //                 damageRate = d, | ||
|  |     //                 hitId = hid, | ||
|  |     //             }, | ||
|  |     //             ownerEntity = owner.ID(), | ||
|  |     //             hitEntity = t, | ||
|  |     //             hitPos = targetEntity.Pos(), | ||
|  |     //             hitDir = hd, | ||
|  |     //             isRight = true, | ||
|  |     //             isDealed = false, | ||
|  |     //             isSkill = s, | ||
|  |     //             performance = (uint)p, | ||
|  |     //         }; | ||
|  |     //         if (s) | ||
|  |     //         { | ||
|  |     //             if (!owner.skill.skillHitInfo.ContainsKey(hitKey)) | ||
|  |     //             { | ||
|  |     //                 owner.skill.skillHitInfo[hitKey] = hitInfo; | ||
|  |     //             } | ||
|  |     //         } | ||
|  |     //         else | ||
|  |     //         { | ||
|  |     //             owner.skill.hitInfo.Add(hitInfo); | ||
|  |     //         } | ||
|  | 
 | ||
|  |     //     } | ||
|  | } |