private void updateVehiclePosition(UILabel vehicleLabel) { try { DraggableVehicleInfo dvi = vehicleLabel.GetComponentInChildren <DraggableVehicleInfo>(); if (dvi.isDragging) { return; } ushort vehicleId = dvi.vehicleId; ushort stopId = Singleton <VehicleManager> .instance.m_vehicles.m_buffer[vehicleId].m_targetBuilding; var labelStation = residentCounters[Singleton <VehicleManager> .instance.m_vehicles.m_buffer[vehicleId].m_targetBuilding]; float destX = stationOffsetX[stopId] - labelStation.width; if (Singleton <TransportManager> .instance.m_lines.m_buffer[Singleton <VehicleManager> .instance.m_vehicles.m_buffer[vehicleId].m_transportLine].GetStop(0) == stopId && (Singleton <VehicleManager> .instance.m_vehicles.m_buffer[vehicleId].m_flags & Vehicle.Flags.Stopped) != 0) { destX = stationOffsetX[TransportLine.GetPrevStop(stopId)]; } float yOffset = vehicleYbaseOffset; int busesOnStation = vehiclesOnStation.ContainsKey(stopId) ? vehiclesOnStation[stopId] : 0; if ((Singleton <VehicleManager> .instance.m_vehicles.m_buffer[vehicleId].m_flags & Vehicle.Flags.Stopped) != 0) { ushort prevStop = TransportLine.GetPrevStop(stopId); destX -= labelStation.width / 2; busesOnStation = Math.Max(busesOnStation, vehiclesOnStation.ContainsKey(prevStop) ? vehiclesOnStation[prevStop] : 0); vehiclesOnStation[prevStop] = busesOnStation + 1; } else if ((Singleton <VehicleManager> .instance.m_vehicles.m_buffer[vehicleId].m_flags & Vehicle.Flags.Arriving) != 0) { destX += labelStation.width / 4; ushort nextStop = TransportLine.GetNextStop(stopId); busesOnStation = Math.Max(busesOnStation, vehiclesOnStation.ContainsKey(nextStop) ? vehiclesOnStation[nextStop] : 0); vehiclesOnStation[nextStop] = busesOnStation + 1; } else if ((Singleton <VehicleManager> .instance.m_vehicles.m_buffer[vehicleId].m_flags & Vehicle.Flags.Leaving) != 0) { destX -= labelStation.width / 4; ushort prevStop = TransportLine.GetPrevStop(stopId); busesOnStation = Math.Max(busesOnStation, vehiclesOnStation.ContainsKey(prevStop) ? vehiclesOnStation[prevStop] : 0); vehiclesOnStation[prevStop] = busesOnStation + 1; } else { ushort prevStop = TransportLine.GetPrevStop(stopId); busesOnStation = Math.Max(busesOnStation, vehiclesOnStation.ContainsKey(prevStop) ? vehiclesOnStation[prevStop] : 0); } yOffset = vehicleYbaseOffset + busesOnStation * vehicleYoffsetIncrement; vehiclesOnStation[stopId] = busesOnStation + 1; vehicleLabel.position = new Vector3(destX, yOffset); } catch (Exception e) { TLMUtils.doLog("ERROR UPDATING VEHICLE!!!"); TLMUtils.doErrorLog(e.ToString()); //redrawLine(); } }
private void vehicleHover(UIComponent component, UIMouseEventParameter eventParam) { bool oldVal = component.GetComponentInChildren <DraggableVehicleInfo>().isDragging; bool newVal = (eventParam.buttons & UIMouseButton.Left) != UIMouseButton.None; component.GetComponentInChildren <DraggableVehicleInfo>().isDragging = newVal; if (oldVal != newVal && newVal == false) { TLMUtils.doLog("onVehicleDrop! {0}", component.name); DraggableVehicleInfo dvi = eventParam.source.parent.GetComponentInChildren <DraggableVehicleInfo>(); UIView view = GameObject.FindObjectOfType <UIView>(); UIHitInfo[] hits = view.RaycastAll(eventParam.ray); DroppableStationInfo dsi = null; UIComponent res = null; int idxRes = -1; for (int i = hits.Length - 1; i >= 0; i--) { UIHitInfo hit = hits[i]; DroppableStationInfo[] dsiList = hit.component.GetComponentsInChildren <DroppableStationInfo>(); if (dsiList.Length == 0) { dsiList = hit.component.parent.GetComponentsInChildren <DroppableStationInfo>(); } if (dsiList.Length == 1) { dsi = dsiList[0]; res = hit.component; idxRes = i; break; } } if (dvi == null || dsi == null) { TLMUtils.doLog("Drag Drop falhou! {0}", eventParam.source.name); return; } else { TLMUtils.doLog("Drag Funcionou! {0}/{1} ({2}-{3})", eventParam.source.name, dsi.gameObject.name, res.gameObject.name, idxRes); VehicleAI ai = (VehicleAI)Singleton <VehicleManager> .instance.m_vehicles.m_buffer[dvi.vehicleId].Info.GetAI(); ai.SetTarget(dvi.vehicleId, ref Singleton <VehicleManager> .instance.m_vehicles.m_buffer[dvi.vehicleId], dsi.nodeId); } } }