public BuildingSlot GetClosestSlot(Vector3 position, BuildingSlotType slotType, bool forPlacement, out float closestDistance) { closestDistance = float.MaxValue; BuildingSlot closestSlot = null; foreach (var slot in _slots) { if (slot.type != slotType && slotType != BuildingSlotType.All) { continue; } if (forPlacement && slot.ignoreForPlacement) { continue; } var dist = (slot.transform.position - position).sqrMagnitude; if (dist < closestDistance) { closestDistance = dist; closestSlot = slot; } } return(closestSlot); }
public BuildingSlot[] GetSlotsAtPosition(Vector3 position, BuildingSlotType slotType, int ignorePartIdx = -1) { const float threshold = 0.05f; var slots = new List <BuildingSlot>(); foreach (var slot in _slots) { if (slot.type != slotType && slotType != BuildingSlotType.All) { continue; } if (ignorePartIdx != -1) { if (slot.partIdx == ignorePartIdx) { continue; } } var dist = (slot.transform.position - position).sqrMagnitude; if (dist < threshold) { slots.Add(slot); } } return(slots.ToArray()); }
void RpcBuild(Replica buildingReplica, BuildingPartType partType, BuildingSlotType buildingSlotType, Vector3 slotPosition) { var building = buildingReplica.GetComponent <Building>(); float distance = 0; var slot = building.GetClosestSlot(slotPosition, buildingSlotType, true, out distance); //#TODO check distance Assert.IsNotNull(slot); building.AddPart(partType, slot); building.Rebuild(); }
BuildingSocket[] GetSocketsAtPosition(Vector3 position, BuildingSlotType slotType) { const float threshold = 0.05f; var sockets = new List <BuildingSocket>(); foreach (var socket in _sockets) { if (socket.slotType != slotType && slotType != BuildingSlotType.All) { continue; } var dist = (socket.transform.position - position).sqrMagnitude; if (dist < threshold) { sockets.Add(socket); } } return(sockets.ToArray()); }