using System.Collections; using System.Collections.Generic; using UnityEngine; /// /// 查询贝塞尔点 /// public class FindBezier : ModuleFind { public readonly float FindRange = 0.02f; /// 板片资产 public ModuleAssets AssetsPlate => ModuleCore.AssetsPlate; protected override void Awake() => ModuleCore.FindBezier = this; public override bool Find(Vector3 position, out DataBezier bezier) { List plates = AssetsPlate.Datas; for (int i = 0; i < plates.Count; i++) { Vector3 localPosition = position - plates[i].dataDesign.position; bezier = Find(plates[i], localPosition); if (bezier != null) { return true; } } bezier = null; return false; } /// 查询匹配的边 private DataBezier Find(DataPlate plate, Vector3 localPosition) { for (int i = 0; i < plate.plateSides.Count; i++) { DataBezier bezier = Find(plate.plateSides[i], localPosition); if (bezier != null) { return bezier; } } return null; } /// 查询匹配的边 private DataBezier Find(DataPlateSide side, Vector3 localPosition) { if (side.bezier == Bezier.一阶) { return null; } float aDis = Vector3.Distance(side.aBezier, localPosition); if (aDis < FindRange) { return new DataBezier() { isA = true, side = side }; } float bDis = Vector3.Distance(side.bBezier, localPosition); if (bDis < FindRange) { return new DataBezier() { isA = false, side = side }; } return null; } }