protected void UpdateJointEditors(IEnumerable<RigidBody> values) { RigidBody[] valArray = values.ToArray(); int visibleElementCount = valArray.NotNull().Min(o => o.Joints == null ? 0 : o.Joints.Count()); // Add missing editors for (int i = 0; i < visibleElementCount; i++) { JointInfo joint = valArray.NotNull().First().Joints.ElementAtOrDefault(i); Type jointType = joint.GetType(); bool matchesAll = valArray.NotNull().All(r => jointType.IsInstanceOfType(r.Joints.ElementAtOrDefault(i))); if (matchesAll) { RigidBodyJointPropertyEditor elementEditor; if (i < this.jointEditors.Count) { elementEditor = this.jointEditors[i]; if (elementEditor.EditedType != jointType) { elementEditor.EditedType = jointType; this.ParentGrid.ConfigureEditor(elementEditor); } } else { elementEditor = new RigidBodyJointPropertyEditor(); elementEditor.EditedType = jointType; this.ParentGrid.ConfigureEditor(elementEditor); this.jointEditors.Add(elementEditor); } elementEditor.PropertyName = string.Format("Joints[{0}]", i); elementEditor.Getter = this.CreateJointValueGetter(i); elementEditor.Setter = this.CreateJointValueSetter(i); elementEditor.ParentGetter = this.GetValue; if (!this.HasPropertyEditor(this.jointEditors[i])) this.AddPropertyEditor(this.jointEditors[i], i); } else if (this.jointEditors.Count > i) { this.RemovePropertyEditor(this.jointEditors[i]); } } // Remove overflowing editors for (int i = this.jointEditors.Count - 1; i >= visibleElementCount; i--) { this.RemovePropertyEditor(this.jointEditors[i]); this.jointEditors.RemoveAt(i); } // Add "Add joint" editor if (this.addJointEditor == null) { this.addJointEditor = new RigidBodyJointAddNewPropertyEditor(); this.addJointEditor.Getter = this.CreateAddNewJointValueGetter(); this.addJointEditor.Setter = v => {}; this.ParentGrid.ConfigureEditor(this.addJointEditor); this.AddPropertyEditor(this.addJointEditor); } }
protected void UpdateJointEditors(IEnumerable <RigidBody> values) { RigidBody[] valArray = values.ToArray(); int visibleElementCount = valArray.NotNull().Min(o => o.Joints == null ? 0 : o.Joints.Count()); // Add missing editors for (int i = 0; i < visibleElementCount; i++) { JointInfo joint = valArray.NotNull().First().Joints.ElementAtOrDefault(i); Type jointType = joint.GetType(); bool matchesAll = valArray.NotNull().All(r => jointType.IsInstanceOfType(r.Joints.ElementAtOrDefault(i))); if (matchesAll) { RigidBodyJointPropertyEditor elementEditor; if (i < this.jointEditors.Count) { elementEditor = this.jointEditors[i]; if (elementEditor.EditedType != jointType) { elementEditor.EditedType = jointType; this.ParentGrid.ConfigureEditor(elementEditor); } } else { elementEditor = new RigidBodyJointPropertyEditor(); elementEditor.EditedType = jointType; this.ParentGrid.ConfigureEditor(elementEditor); this.jointEditors.Add(elementEditor); } elementEditor.PropertyName = string.Format("Joints[{0}]", i); elementEditor.Getter = this.CreateJointValueGetter(i); elementEditor.Setter = this.CreateJointValueSetter(i); elementEditor.ParentGetter = this.GetValue; if (!this.HasPropertyEditor(this.jointEditors[i])) { this.AddPropertyEditor(this.jointEditors[i], i); } } else if (this.jointEditors.Count > i) { this.RemovePropertyEditor(this.jointEditors[i]); } } // Remove overflowing editors for (int i = this.jointEditors.Count - 1; i >= visibleElementCount; i--) { this.RemovePropertyEditor(this.jointEditors[i]); this.jointEditors.RemoveAt(i); } // Add "Add joint" editor if (this.addJointEditor == null) { this.addJointEditor = new RigidBodyJointAddNewPropertyEditor(); this.addJointEditor.Getter = this.CreateAddNewJointValueGetter(); this.addJointEditor.Setter = v => {}; this.ParentGrid.ConfigureEditor(this.addJointEditor); this.AddPropertyEditor(this.addJointEditor); } }