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("log"); } protected override void Run(Flow flow) { Util.Print(flow.GetValue(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("p1"); pos2 = ValueInput("p2"); target = ValueOutput>("target"); } protected override void Run(Flow flow) { var entity = Util.GetEntity(data.Entity); var p1 = flow.GetValue(pos1); var p2 = flow.GetValue(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(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("p1"); pos2 = ValueInput("p2"); width = ValueInput("width"); height = ValueInput("height"); target = ValueOutput>("target"); } protected override void Run(Flow flow) { var entity = Util.GetEntity(data.Entity); var p1 = flow.GetValue(pos1); var p2 = flow.GetValue(pos2); var w = flow.GetValue(width); var h = flow.GetValue(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(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("entity"); // damageRate = ValueInput("damageRate"); // hitDir = ValueInput("hitDir"); // isFlow = ValueInput("isFlow"); // hitId = ValueInput("hitId"); // isSkill = ValueInput("isSkill"); // performance = ValueInput("performance"); // } // protected override void Run(Flow flow) // { // var t = flow.GetValue(target); // var d = flow.GetValue(damageRate); // var hd = flow.GetValue(hitDir); // var ifw = flow.GetValue(isFlow); // var hid = flow.GetValue(hitId); // var s = flow.GetValue(isSkill); // var p = flow.GetValue(performance); // var hitKey = new Tuple(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); // } // } }