public AroundPart FindPart(Vector3 p, int unitCount = 8) { float minDistance = 9999; float nofullDistance = 9999; int minCount = 99999; AroundPart minDistanceItem = null; AroundPart nofullItem = null; AroundPart minCountItem = null; bool allFull = true; float score = 0; float minScore = 9999; AroundPart minScoreItem = null; float oDistance = Vector3.Distance(p, o); foreach (AroundPart aroundPart in pars) { if (aroundPart.Distance(p) <= minDistance) { minDistance = aroundPart.mDistance; minDistanceItem = aroundPart; } if (aroundPart.mDistance < nofullDistance && !aroundPart.GetIsFull(unitCount)) { nofullDistance = aroundPart.mDistance; nofullItem = aroundPart; } if (aroundPart.count < aroundPart.initNum) { allFull = false; } if (aroundPart.count < minCount) { minCount = aroundPart.count; minCountItem = aroundPart; } score = aroundPart.mDistance / oDistance * 0.65f + aroundPart.count / aroundPart.initNum * 0.35f; if (score <= minScore) { minScore = score; minScoreItem = aroundPart; } } if (nofullItem == null) { nofullItem = minScoreItem; } return(nofullItem); }
void SetAroundPoints() { SphereCollider sphereCollider = GetComponent <SphereCollider>(); if (sphereCollider == null) { Transform sphereColliderGO = transform.FindChild("ObstacleBox-Ray"); if (sphereColliderGO != null) { sphereCollider = sphereColliderGO.GetComponent <SphereCollider>(); } } if (sphereCollider != null) { radius = sphereCollider.radius * transform.lossyScale.x; } partAngle = 360f / partNum; r = radius + externalRadius; o = transform.position; for (int i = 0; i < partNum; i++) { AroundPart aroundPart = new AroundPart(); aroundPart.index = i; aroundPart.initNum = partPointNum; aroundPart.o = o; aroundPart.r = r; aroundPart.angleBegin = angleOffset + partAngle * i; aroundPart.angleEnd = angleOffset + partAngle * (i + 1); aroundPart.Init(); pars.Add(aroundPart); } }
public List <Vector3> FindPoints(Vector3 p, int unitCount, out AroundPart aroundPart) { aroundPart = FindPart(p, unitCount); return(aroundPart.GetPoints(unitCount)); }