public static void EndBpMode(bool ignoreBlueprint = false) { if (!bpMode) { return; } if (!ignoreBlueprint) { var ids = bpSelection.Keys.ToList(); BlueprintManager.Copy(ids, referenceId); if (BlueprintManager.hasData) { BlueprintManager.EnterBuildModeAfterBp(); } } bpMode = false; referenceId = 0; foreach (var selectionGizmo in bpSelection.Values) { selectionGizmo.Close(); } bpSelection.Clear(); if (areaSelectionGizmo != null) { areaSelectionGizmo.Close(); areaSelectionGizmo = null; } if (referenceGizmo != null) { referenceGizmo.Close(); referenceGizmo = null; } if (referenceSelectionGizmo != null) { referenceSelectionGizmo.Close(); referenceSelectionGizmo = null; } GC.Collect(); }
public static void AlterSelection(PlayerAction_Build __instance) { bool removeMode = VFInput.control; if (referenceSelectionGizmo != null) { referenceSelectionGizmo.Close(); referenceSelectionGizmo = null; } if (areaSelectionGizmo == null) { areaSelectionGizmo = CircleGizmo.Create(6, Vector3.zero, 10); areaSelectionGizmo.fadeOutScale = areaSelectionGizmo.fadeInScale = 1.8f; areaSelectionGizmo.fadeOutTime = areaSelectionGizmo.fadeInTime = 0.15f; areaSelectionGizmo.autoRefresh = true; areaSelectionGizmo.Open(); } areaSelectionGizmo.color = removeMode ? REMOVE_SELECTION_GIZMO_COLOR : ADD_SELECTION_GIZMO_COLOR; areaSelectionGizmo.radius = selectionRadius; if (__instance.groundTestPos != Vector3.zero) { areaSelectionGizmo.position = __instance.groundTestPos; } if (VFInput._buildConfirm.pressing) { areaSelectionGizmo.color = removeMode ? REMOVE_SELECTION_GIZMO_COLOR : ADD_SELECTION_GIZMO_COLOR; // target only buildings int mask = 131072; int found = Physics.OverlapBoxNonAlloc(__instance.groundTestPos, new Vector3(selectionRadius, 100f, selectionRadius), _tmp_cols, Maths.SphericalRotation(__instance.groundTestPos, 0f), mask, QueryTriggerInteraction.Collide); PlanetPhysics planetPhysics = __instance.player.planetData.physics; for (int i = 0; i < found; i++) { planetPhysics.GetColliderData(_tmp_cols[i], out ColliderData colliderData); if (colliderData.objId > 0) { var entityId = colliderData.objId; if (removeMode) { if (bpSelection.ContainsKey(entityId)) { bpSelection[entityId].Close(); bpSelection.Remove(entityId); } if (entityId == referenceId) { referenceId = 0; } } else if (!bpSelection.ContainsKey(entityId)) { var entityData = __instance.factory.entityPool[entityId]; ItemProto itemProto = LDB.items.Select((int)entityData.protoId); var gizmo = BoxGizmo.Create(entityData.pos, entityData.rot, itemProto.prefabDesc.selectCenter, itemProto.prefabDesc.selectSize); gizmo.multiplier = 1f; gizmo.alphaMultiplier = itemProto.prefabDesc.selectAlpha; gizmo.fadeInScale = gizmo.fadeOutScale = 1.3f; gizmo.fadeInTime = gizmo.fadeOutTime = 0.05f; gizmo.fadeInFalloff = gizmo.fadeOutFalloff = 0.5f; gizmo.color = Color.white; gizmo.Open(); bpSelection.Add(entityId, gizmo); } } } if (referenceId == 0) { var belts = new List <int>(); var buildings = new List <int>(); foreach (var entityId in bpSelection.Keys) { var entityData = __instance.factory.entityPool[entityId]; if (entityId != entityData.id) { continue; } ItemProto itemProto = LDB.items.Select((int)entityData.protoId); if (itemProto.prefabDesc.isBelt) { belts.Add(entityId); } else if (!itemProto.prefabDesc.isInserter) { buildings.Add(entityId); } } if (buildings.Count > 0) { referenceId = buildings.First(); } else if (belts.Count > 0) { referenceId = belts.First(); } } } if (referenceId != 0 && bpSelection.TryGetValue(referenceId, out BoxGizmo reference)) { if (referenceGizmo == null) { referenceGizmo = BoxGizmo.Create(Vector3.zero, Quaternion.identity, Vector3.zero, new Vector3(0.5f, 100f, 0.5f)); referenceGizmo.multiplier = 1f; referenceGizmo.alphaMultiplier = 0.5f; referenceGizmo.fadeInScale = referenceGizmo.fadeOutScale = 1.3f; referenceGizmo.fadeInTime = referenceGizmo.fadeOutTime = 0.05f; referenceGizmo.fadeInFalloff = referenceGizmo.fadeOutFalloff = 0.5f; referenceGizmo.color = Color.green; referenceGizmo.Open(); } referenceGizmo.transform.position = reference.transform.position; referenceGizmo.transform.rotation = reference.transform.rotation; referenceGizmo.center = reference.center; } }