// Used by Prop Painter public void Add(Instance instance) { if (!selection.Contains(instance)) { m_newSelection.AddObject(instance); } }
public static void ClearPOFromSelection() { if (!MoveItTool.PO.Enabled) { return; } HashSet <Instance> toRemove = new HashSet <Instance>(); foreach (Instance i in selection) { if (i is MoveableProc) { toRemove.AddObject(i); } } foreach (Instance i in toRemove) { selection.RemoveObject(i); } MoveItTool.m_debugPanel.UpdatePanel(); }
private HashSet <Instance> GetMarqueeList(Ray mouseRay) { HashSet <Instance> list = new HashSet <Instance>(); Building[] buildingBuffer = Singleton <BuildingManager> .instance.m_buildings.m_buffer; PropInstance[] propBuffer = Singleton <PropManager> .instance.m_props.m_buffer; NetNode[] nodeBuffer = Singleton <NetManager> .instance.m_nodes.m_buffer; NetSegment[] segmentBuffer = Singleton <NetManager> .instance.m_segments.m_buffer; TreeInstance[] treeBuffer = Singleton <TreeManager> .instance.m_trees.m_buffer; m_selection.a = m_clickPositionAbs; m_selection.c = RaycastMouseLocation(mouseRay); if (m_selection.a.x == m_selection.c.x && m_selection.a.z == m_selection.c.z) { m_selection = default; } else { float angle = Camera.main.transform.localEulerAngles.y * Mathf.Deg2Rad; Vector3 down = new Vector3(Mathf.Cos(angle), 0, -Mathf.Sin(angle)); Vector3 right = new Vector3(-down.z, 0, down.x); Vector3 a = m_selection.c - m_selection.a; float dotDown = Vector3.Dot(a, down); float dotRight = Vector3.Dot(a, right); if ((dotDown > 0 && dotRight > 0) || (dotDown <= 0 && dotRight <= 0)) { m_selection.b = m_selection.a + dotDown * down; m_selection.d = m_selection.a + dotRight * right; } else { m_selection.b = m_selection.a + dotRight * right; m_selection.d = m_selection.a + dotDown * down; } Vector3 min = m_selection.Min(); Vector3 max = m_selection.Max(); int gridMinX = Mathf.Max((int)((min.x - 16f) / 64f + 135f), 0); int gridMinZ = Mathf.Max((int)((min.z - 16f) / 64f + 135f), 0); int gridMaxX = Mathf.Min((int)((max.x + 16f) / 64f + 135f), 269); int gridMaxZ = Mathf.Min((int)((max.z + 16f) / 64f + 135f), 269); InstanceID id = new InstanceID(); ItemClass.Layer itemLayers = GetItemLayers(); if (PO.Active && filterProcs) { foreach (PO_Object obj in PO.Objects) { if (!obj.isHidden() && PointInRectangle(m_selection, obj.Position)) { id.NetLane = obj.Id; list.AddObject(id); } } } for (int i = gridMinZ; i <= gridMaxZ; i++) { for (int j = gridMinX; j <= gridMaxX; j++) { if (filterBuildings || filterSurfaces || (filterPicker && Filters.Picker.IsBuilding)) { ushort building = BuildingManager.instance.m_buildingGrid[i * 270 + j]; int count = 0; while (building != 0u) { if (IsBuildingValid(ref buildingBuffer[building], itemLayers) && PointInRectangle(m_selection, buildingBuffer[building].m_position)) { if (Filters.Filter(buildingBuffer[building].Info, ref buildingBuffer[building])) { id.Building = Building.FindParentBuilding(building); if (id.Building == 0) { id.Building = building; } list.Add(id); } } building = buildingBuffer[building].m_nextGridBuilding; if (++count > 49152) { CODebugBase <LogChannel> .Error(LogChannel.Core, "Buildings: Invalid list detected!\n" + Environment.StackTrace); break; } } } if (filterProps || filterDecals || filterSurfaces || (filterPicker && Filters.Picker.IsProp)) { ushort prop = PropManager.instance.m_propGrid[i * 270 + j]; int count = 0; while (prop != 0u) { if (Filters.Filter(propBuffer[prop].Info)) { if (PointInRectangle(m_selection, propBuffer[prop].Position)) { id.Prop = prop; list.Add(id); } } prop = propBuffer[prop].m_nextGridProp; if (++count > 65536) { CODebugBase <LogChannel> .Error(LogChannel.Core, "Prop: Invalid list detected!\n" + Environment.StackTrace); } } } if (filterNodes || filterBuildings || (filterPicker && Filters.Picker.IsNode)) { ushort node = NetManager.instance.m_nodeGrid[i * 270 + j]; int count = 0; while (node != 0u) { if (IsNodeValid(ref nodeBuffer[node], itemLayers) && PointInRectangle(m_selection, nodeBuffer[node].m_position)) { ushort building = NetNode.FindOwnerBuilding(node, 363f); if (building != 0) { if (filterBuildings) { id.Building = Building.FindParentBuilding(building); if (id.Building == 0) { id.Building = building; } list.Add(id); } } else if (filterNodes || (filterPicker && Filters.Picker.IsNode)) { if (Filters.Filter(nodeBuffer[node])) { id.NetNode = node; list.Add(id); } } } node = nodeBuffer[node].m_nextGridNode; if (++count > 32768) { CODebugBase <LogChannel> .Error(LogChannel.Core, "Nodes: Invalid list detected!\n" + Environment.StackTrace); } } } if (filterSegments || filterBuildings || (filterPicker && Filters.Picker.IsSegment)) { ushort segment = NetManager.instance.m_segmentGrid[i * 270 + j]; int count = 0; while (segment != 0u) { if (IsSegmentValid(ref segmentBuffer[segment], itemLayers) && PointInRectangle(m_selection, segmentBuffer[segment].m_bounds.center)) { ushort building = FindOwnerBuilding(segment, 363f); if (building != 0) { if (filterBuildings) { id.Building = Building.FindParentBuilding(building); if (id.Building == 0) { id.Building = building; } list.Add(id); } } else if (filterSegments || (filterPicker && Filters.Picker.IsSegment)) { if (Filters.Filter(segmentBuffer[segment])) { id.NetSegment = segment; list.Add(id); } } } segment = segmentBuffer[segment].m_nextGridSegment; if (++count > 36864) { CODebugBase <LogChannel> .Error(LogChannel.Core, "Segments: Invalid list detected!\n" + Environment.StackTrace); } } } } } if (filterTrees || (filterPicker && Filters.Picker.IsTree)) { gridMinX = Mathf.Max((int)((min.x - 8f) / 32f + 270f), 0); gridMinZ = Mathf.Max((int)((min.z - 8f) / 32f + 270f), 0); gridMaxX = Mathf.Min((int)((max.x + 8f) / 32f + 270f), 539); gridMaxZ = Mathf.Min((int)((max.z + 8f) / 32f + 270f), 539); for (int i = gridMinZ; i <= gridMaxZ; i++) { for (int j = gridMinX; j <= gridMaxX; j++) { uint tree = TreeManager.instance.m_treeGrid[i * 540 + j]; int count = 0; while (tree != 0) { if (PointInRectangle(m_selection, treeBuffer[tree].Position)) { if (Filters.Filter(treeBuffer[tree].Info)) { id.Tree = tree; list.Add(id); } } tree = treeBuffer[tree].m_nextGridTree; if (++count > 262144) { CODebugBase <LogChannel> .Error(LogChannel.Core, "Trees: Invalid list detected!\n" + Environment.StackTrace); } } } } } } return(list); }