public void MakeAllDisconnectedPartsGhosty() { if (currCraft == null) { return; } //update structure currCraft.UpdatePhysParts(true); List <PhysPart> connectedParts = new List <PhysPart>(PartConnection.GetConnectedParts(currCraft.originPart)); foreach (PhysPart part in currCraft.Parts) { if (connectedParts.Contains(part)) { if (currPart == null || PartConnection.IsConnectedToPartIgnoringInvalidParts(part, currCraft.originPart, new PhysPart[1] { currPart })) //Check if part is connected to origin, IGNORING held part. { MakePartGhosty(part, false); } } else { MakePartGhosty(part, true); } } }
private void AddConnectionMenuItem_Click(object sender, EventArgs e) { string connectionTypeStr = (sender as ToolStripMenuItem).Tag as string; if (!string.IsNullOrEmpty(connectionTypeStr) && Enum.TryParse(connectionTypeStr, out LDD.Primitives.Connectors.ConnectorType connectorType)) { if (!ProjectManager.ShowConnections) { ProjectManager.ShowConnections = true; } var newConnection = PartConnection.Create(connectorType); var focusedBoneNode = GetFocusedParentElement <PartBone>(); if (focusedBoneNode != null) { (focusedBoneNode.Element as PartBone).Connections.Add(newConnection); } else { CurrentProject.Connections.Add(newConnection); } ProjectManager.SelectElement(newConnection); SelectElementNodeDelayed(newConnection); } }
void FixedUpdate() { //Debug stuff if (debug_disassembleConnectedParts) { debug_disassembleConnectedParts = false; PhysPart[] connectedParts = PartConnection.GetConnectedParts(originPart, true); List <PartConnection> connections = new List <PartConnection>(); foreach (PhysPart p in connectedParts) { foreach (PartConnection c in p.connections) { connections.Add(c); } } foreach (PartConnection c in connections) { c.fromPart.DisconnectPart(c.toPart); } } //Logic if (fixedCounter % 49 == 0) //once a second { //Auto-destroy if we are OOB if (Mathf.Abs(transform.position.x) > GameplayManager.instance.LevelBounds.x || Mathf.Abs(transform.position.y) > GameplayManager.instance.LevelBounds.y || Mathf.Abs(transform.position.z) > GameplayManager.instance.LevelBounds.z) { AutoDestruct(2.5f / Parts.Count); } } fixedCounter = (int)Mathf.Repeat(fixedCounter + 1, 50); }
public void ApplyStress(float stress) { if (enabled == false) { return; } if (stress > GetEffectiveStrength(internalStrength)) //destroy part if impact too strong { DestroyPart(GetStressToCarry(stress)); //destroy and carry stress } else //just break connections if impact not strong enough to destroy this part { List <PartConnection> brokenConnections = new List <PartConnection>(); foreach (PartConnection c in connections) { if (stress > c.GetTrueConnectionStrength()) { if (PartConnection.IsConnectedToPartIgnoringInvalidParts(c.toPart, GetBodyOrigin(), new PhysPart[1] { this }, true)) { brokenConnections.Add(c); } } } while (brokenConnections.Count > 0) { DisconnectPart(brokenConnections[0].toPart, GetStressToCarry(stress)); //disconenct and carry stress brokenConnections.RemoveAt(0); } } }
public void UpdateTransformStructureIfDisconnected() { MultipartPhysBody oldParent = GetBody(); if (!CheckConnectedToOrigin()) { PhysPart[] ConnectedParts = PartConnection.GetConnectedParts(this); Transform newDebrisCraft = new GameObject(oldParent.name + " debris").transform; newDebrisCraft.SetParent(GameplayManager.GameplayTransform); Transform newParent = new GameObject("Body").transform; newParent.SetParent(newDebrisCraft); newParent.transform.position = newDebrisCraft.transform.position = transform.position; newParent.transform.rotation = newDebrisCraft.transform.rotation = transform.rotation; foreach (PhysPart p in ConnectedParts) { p.transform.SetParent(newParent); } newDebrisCraft.gameObject.AddComponent <Rigidbody>().velocity = oldParent.rb.GetPointVelocity(transform.TransformPoint(CoMoffset)); newDebrisCraft.gameObject.AddComponent <MultipartPhysBody>(); oldParent.FullRecalcPhysics(); foreach (PhysPart p in ConnectedParts) { foreach (PartComponent c in p.components) { c.OnBodyChanged(); } } } }
void Start() { if (partName == null || partName == "") { partName = gameObject.name; } foreach (PartConnection c in connections) { c.fromPart = this; } RecalcConnections(); if (debug_showConnectToOrigin) { PartConnection.IsConnectedToPart(this, GetBodyOrigin(), true); } }
public ConnectorComboItem(PartConnection connection) { ID = connection.ID; Connection = connection; SubType = connection.SubType; }
private void FillConnectionDetails(PartConnection connection) { SetConnectionInfoVisibility(connection != null); connectorEditor1.UpdateBindings(connection?.Connector); }
private void SetCurrentObject(PartConnection connection, bool fromComboBox) { foreach (var ctrl in GetAllEditControl()) { ctrl.DataBindings.Clear(); } using (FlagManager.UseFlag(nameof(SetCurrentObject))) { if (SelectedElement != null) { SelectedElement.PropertyChanged -= SelectedElement_PropertyChanged; SelectedElement = null; } SelectedElement = connection; if (SelectedElement != null) { ElementNameTextBox.Enabled = true; ConnectionSubTypeCombo.Enabled = true; TransformEdit.Enabled = true; TypeValueLabel.Text = connection.ConnectorType.ToString(); ElementNameTextBox.DataBindings.Add(new Binding( "Text", connection, nameof(connection.Name), true, DataSourceUpdateMode.OnValidation)); EditControlHelpers.ForEach(x => x.UpdateVisibility(SelectedElement.ConnectorType)); TransformEdit.BindPhysicalElement(connection); switch (SelectedElement.ConnectorType) { case ConnectorType.Hinge: { OrientedCheckBox.DataBindings.Add(new Binding( "Checked", connection.Connector, nameof(HingeConnector.Oriented), true, DataSourceUpdateMode.OnPropertyChanged)); LimitMinBox.DataBindings.Add(new Binding( "Value", connection.Connector, nameof(HingeConnector.LimitMin), true, DataSourceUpdateMode.OnPropertyChanged)); LimitMaxBox.DataBindings.Add(new Binding( "Value", connection.Connector, nameof(HingeConnector.LimitMax), true, DataSourceUpdateMode.OnPropertyChanged)); FlipLimitMinBox.DataBindings.Add(new Binding( "Value", connection.Connector, nameof(HingeConnector.FlipLimitMin), true, DataSourceUpdateMode.OnPropertyChanged)); FlipLimitMaxBox.DataBindings.Add(new Binding( "Value", connection.Connector, nameof(HingeConnector.FlipLimitMax), true, DataSourceUpdateMode.OnPropertyChanged)); } break; case ConnectorType.Axel: { LengthBox.DataBindings.Add(new Binding( "Value", connection.Connector, nameof(AxelConnector.Length), true, DataSourceUpdateMode.OnPropertyChanged)); StartCappedCheckBox.DataBindings.Add(new Binding( "Checked", connection.Connector, nameof(AxelConnector.StartCapped), true, DataSourceUpdateMode.OnPropertyChanged)); EndCappedCheckBox.DataBindings.Add(new Binding( "Checked", connection.Connector, nameof(AxelConnector.EndCapped), true, DataSourceUpdateMode.OnPropertyChanged)); GrabbingCheckBox.DataBindings.Add(new Binding( "Checked", connection.Connector, nameof(AxelConnector.Grabbing), true, DataSourceUpdateMode.OnPropertyChanged)); GrabbingRequiredCheckBox.DataBindings.Add(new Binding( "Checked", connection.Connector, nameof(AxelConnector.IsGrabbingRequired), true, DataSourceUpdateMode.OnPropertyChanged)); } break; case ConnectorType.Gear: { ToothNumBox.DataBindings.Add(new Binding( "Value", connection.Connector, nameof(GearConnector.ToothCount), true, DataSourceUpdateMode.OnPropertyChanged)); RadiusNumBox.DataBindings.Add(new Binding( "Value", connection.Connector, nameof(GearConnector.Radius), true, DataSourceUpdateMode.OnPropertyChanged)); } break; case ConnectorType.Slider: { var sliderConn = connection.Connector as SliderConnector; LengthBox.DataBindings.Add(new Binding( "Value", connection.Connector, nameof(SliderConnector.Length), true, DataSourceUpdateMode.OnPropertyChanged)); CylindricalCheckBox.DataBindings.Add(new Binding( "Checked", connection.Connector, nameof(SliderConnector.Cylindrical), true, DataSourceUpdateMode.OnPropertyChanged)); StartCappedCheckBox.DataBindings.Add(new Binding( "Checked", connection.Connector, nameof(SliderConnector.StartCapped), true, DataSourceUpdateMode.OnPropertyChanged)); EndCappedCheckBox.DataBindings.Add(new Binding( "Checked", connection.Connector, nameof(SliderConnector.EndCapped), true, DataSourceUpdateMode.OnPropertyChanged)); UpdateSliderSpringValue(); } break; case ConnectorType.Rail: { LengthBox.DataBindings.Add(new Binding( "Value", connection.Connector, nameof(RailConnector.Length), true, DataSourceUpdateMode.OnPropertyChanged)); } break; case ConnectorType.Fixed: { AxesNumberBox.DataBindings.Add(new Binding( "Value", connection.Connector, nameof(FixedConnector.Axes), true, DataSourceUpdateMode.OnPropertyChanged)); } break; case ConnectorType.Ball: { UpdateFlexEditorVisibility(); FillFlexValues(); } break; } FillSubTypeComboBox(SelectedElement.ConnectorType); SetSubTypeComboValue(SelectedElement.SubType); SelectedElement.PropertyChanged += SelectedElement_PropertyChanged; if (SyncSelectionCheckBox.Checked && fromComboBox && !FlagManager.IsSet(nameof(SyncToCurrentSelection))) { ProjectManager.SelectElement(connection); } } else { TypeValueLabel.Text = string.Empty; //FlexTextBox.Text = string.Empty; EditControlHelpers.ForEach(x => x.SetVisibility(false)); ElementNameTextBox.Enabled = false; ConnectionSubTypeCombo.Enabled = false; TransformEdit.Enabled = false; TransformEdit.BindPhysicalElement(null); //HingeLayoutPanel.Visible = false; } if (!fromComboBox && ElementsComboBox.SelectedItem != SelectedElement) { ElementsComboBox.SelectedItem = SelectedElement; } } }
public bool CheckConnectedToOrigin() { return(PartConnection.IsConnectedToPart(this, GetBodyOrigin())); }