public void CreateSampleData() { for (var i = 0; i < 20; i++) { Clamps.Add(GetRandomClamp()); } }
private static void SpawnModel(int type, int vehicle) { var coords = GetEntityCoords(PlayerPedId(), false); SetNetworkIdExistsOnAllMachines(VehToNet(vehicle), true); if (type == 0) { RequestModel((uint)GetHashKey("p_car_keys_01")); Object = CreateObject(GetHashKey("p_car_keys_01"), coords.X, coords.Y, coords.Z, true, true, true); var boneIndex = GetEntityBoneIndexByName(vehicle, "wheel_lf"); SetEntityHeading(Object, 0f); SetEntityRotation(Object, 60f, 20f, 10f, 1, true); AttachEntityToEntity(Object, vehicle, boneIndex, -0.10f, 0.15f, -0.30f, 180f, 200f, 90f, true, true, false, false, 2, true); SetEntityRotation(Object, 60f, 20f, 10f, 1, true); SetEntityAsMissionEntity(Object, true, true); FreezeEntityPosition(Object, true); TriggerServerEvent("Server:ChangeCarState", VehToNet(vehicle), true); Clamps.Add(Object, vehicle); } else if (type == 1) { RequestModel((uint)GetHashKey("prop_cs_protest_sign_03")); Object = CreateObject(GetHashKey("prop_cs_protest_sign_03"), coords.X, coords.Y, coords.Z, true, true, true); var boneIndex = GetEntityBoneIndexByName(vehicle, "interiorlight"); var model = GetEntityModel(vehicle); var vector1 = new Vector3(0f, 0f, 0f); var vector2 = new Vector3(0f, 0f, 0f); GetModelDimensions((uint)model, ref vector1, ref vector2); FreezeEntityPosition(Object, true); SetEntityAsMissionEntity(Object, true, true); //AttachEntityToEntity(Object, vehicle, boneIndex, 0f, ((vector2.Y - vector1.Y) / 2), ((vector2.Z - vector1.Z) / 2) - ((vector2.Z - vector1.Z) / 5f), 0f, 0f, 0f, true, true, false, false, 1, true); AttachEntityToEntity(Object, vehicle, boneIndex, 0f, -((vector2.Y - vector1.Y) / 2) + 5f, -0.12f, 0f, 0f, 0f, true, true, false, false, 1, true); Stickers.Add(Object, vehicle); } }
/// <summary> /// Call this regularly to fill the ShirtListBox with shirts. Will automatically already existing shirts (in case of cyclic buffer). /// </summary> public void ClampChanged(Clamp clamp, ChangeType changeType) { var existsAlready = Clamps.Any(c => c.ID == clamp.ID); if (changeType == ChangeType.ClampDetected) { // remove ALL if (existsAlready) { var clamps = Clamps.Where(c => c.ID == clamp.ID); foreach (var clampToRemove in clamps) { ExecuteDeleteSpecificClamp(clampToRemove); } } Clamps.Add(new Clamp { ID = clamp.ID, TimeStamp = clamp.CurrentShirt != null ? clamp.CurrentShirt.LastRfidRead : DateTime.Now, CurrentShirt = clamp.CurrentShirt }); } else if (changeType == ChangeType.ClampRemoved) { // remove ALL if (existsAlready) { var clamps = Clamps.Where(c => c.ID == clamp.ID); foreach (var clampToRemove in clamps) { ExecuteDeleteSpecificClamp(clampToRemove); } } } else if (changeType == ChangeType.ShirtChanged) { if (existsAlready) { var existingClamp = Clamps.First(c => c.ID == clamp.ID); existingClamp.CurrentShirt.RfidReadCounter = clamp.CurrentShirt.RfidReadCounter; existingClamp.CurrentShirt.LastRfidRead = clamp.CurrentShirt.LastRfidRead; existingClamp.CurrentShirt.FlaggedComment = clamp.CurrentShirt.FlaggedComment; existingClamp.CurrentShirt.Route = clamp.CurrentShirt.Route; existingClamp.CurrentShirt.SelectedRouteIndex = clamp.CurrentShirt.SelectedRouteIndex; } } }
private void DestroyAll() { if (Clamps.Count > 0) { Simulation.clampMutex.WaitOne(); foreach (NeuronClamp clamp in Clamps) { if (clamp != null && clamp.focusVert != -1) { Destroy(clamp.transform.parent.gameObject); } } Clamps.Clear(); Simulation.clampMutex.ReleaseMutex(); } }
private void ExecuteDeleteSpecificClamp(Clamp existingClamp) { _logger.Debug(string.Format("Execute delete of specific clamp (clamp='{0}'", existingClamp)); const double deletionDelay = 700; // Must be greater than the animation duration in the DataTemplate !!! var deletionTimer = new DispatcherTimer { Interval = TimeSpan.FromMilliseconds(deletionDelay) }; deletionTimer.Tick += (o, args) => { _logger.Debug(string.Format("Remove clamp (clamp='{0}'", existingClamp)); Clamps.Remove(existingClamp); deletionTimer.Stop(); EventHelper.RemoveAllEventHandler(deletionTimer, "Tick"); }; deletionTimer.Start(); existingClamp.IsRemoving = true; }
public void PreviewClamp(RaycastHit hit) { // If we haven't already created a preview clamp, create one if (previewClamp == null) { Simulation.clampMutex.WaitOne(); previewClamp = BuildClamp(hit); // If we couldn't build a preview clamp, don't try to preview the position hit if (previewClamp == null) { Simulation.clampMutex.ReleaseMutex(); return; } Clamps.Remove(previewClamp); Simulation.clampMutex.ReleaseMutex(); foreach (Collider col in previewClamp.GetComponentsInChildren <Collider>()) { col.enabled = false; } previewClamp.SwitchMaterial(previewClamp.previewMaterial); previewClamp.name = "PreviewClamp"; foreach (GameObject defaultCapHolder in previewClamp.defaultCapHolders) { Destroy(defaultCapHolder); } foreach (GameObject destroyCapHolder in previewClamp.destroyCapHolders) { Destroy(destroyCapHolder); } } // Ensure the clamp is enabled previewClamp.transform.parent.gameObject.SetActive(true); // Set the size and orientation of the preview clamp previewClamp.PlaceClamp(Simulation.GetNearestPoint(hit)); }
/// <summary> /// Start the interpolation and set it's needed values /// </summary> private void StartupInterpolation() { try { if (Body == null) { Body = FlightGlobals.Bodies.Find(b => b.bodyName == BodyName); } if (Vessel == null) { Vessel = FlightGlobals.Vessels.FindLast(v => v.id == VesselId); } InterpolationStarted = true; if (Body != null && Vessel != null) { PlanetariumDifference = Planetarium.GetUniversalTime() - PlanetTime; Vessel.ActionGroups.SetGroup(KSPActionGroup.Gear, Target.ActionGrpControls[0]); Vessel.ActionGroups.SetGroup(KSPActionGroup.Light, Target.ActionGrpControls[1]); Vessel.ActionGroups.SetGroup(KSPActionGroup.Brakes, Target.ActionGrpControls[2]); Vessel.ActionGroups.SetGroup(KSPActionGroup.SAS, Target.ActionGrpControls[3]); Vessel.ActionGroups.SetGroup(KSPActionGroup.RCS, Target.ActionGrpControls[4]); var stage = Vessel.currentStage; if (stage != Stage) { Vessel.ActionGroups.ToggleGroup(KSPActionGroup.Stage); Vessel.currentStage = Stage; } else { var engines = Vessel.FindPartModulesImplementing <ModuleEngines>(); var enginesToActivate = engines.Where(e => !e.EngineIgnited && ActiveEngines.Contains(e.part.craftID)); var enginesToStop = engines.Where(e => e.EngineIgnited && StoppedEngines.Contains(e.part.craftID)); var decouplersToLaunch = Vessel.FindPartModulesImplementing <ModuleDecouple>() .Where(d => !d.isDecoupled && !Decouplers.Contains(d.part.craftID)); var anchoredDecouplersToLaunch = Vessel.FindPartModulesImplementing <ModuleAnchoredDecoupler>() .Where(d => !d.isDecoupled && !Decouplers.Contains(d.part.craftID)); var clamps = Vessel.FindPartModulesImplementing <LaunchClamp>() .Where(c => !Clamps.Contains(c.part.craftID)); var docks = Vessel.FindPartModulesImplementing <ModuleDockingNode>() .Where(d => !d.IsDisabled && !Docks.Contains(d.part.craftID)); foreach (var engine in enginesToActivate) { engine.Activate(); } foreach (var engine in enginesToStop) { engine.Shutdown(); } foreach (var decoupler in decouplersToLaunch) { decoupler.Decouple(); } foreach (var anchoredDecoupler in anchoredDecouplersToLaunch) { anchoredDecoupler.Decouple(); } foreach (var clamp in clamps) { clamp.Release(); } foreach (var dock in docks) { dock.Decouple(); } } //Here we use the interpolation facor to make the interpolation duration //shorter or longer depending on the amount of updates we have in queue. //We never exceed the MaxSInterpolationTime _interpolationDuration = Target.SentTime - SentTime - VesselUpdateInterpolationSystem.GetInterpolationFactor(VesselId); _interpolationDuration = Mathf.Clamp(_interpolationDuration, 0, VesselUpdateInterpolationSystem.MaxSInterpolationTime); } } catch (Exception e) { Debug.LogError($"[LMP]: Coroutine error in StartupInterpolation {e}"); } }