public ConfigElementLabelPresent(AddToConfigWindow window, string targetLabel) { var uxmlPath = k_UxmlDir + "ConfigElementLabelPresent.uxml"; AssetDatabase.LoadAssetAtPath <VisualTreeAsset>(uxmlPath).CloneTree(this); labelElement = this.Q <Label>("config-name"); var removeButton = this.Q <Button>("remove-from-config-button"); removeButton.text = "Remove Label"; var openButton = this.Q <Button>("open-config-button"); openButton.clicked += () => { Selection.SetActiveObjectWithContext(labelConfig, null); }; removeButton.clicked += () => { var editor = Editor.CreateEditor(labelConfig); if (editor is SemanticSegmentationLabelConfigEditor semanticEditor) { semanticEditor.RemoveLabel(targetLabel); } else if (editor is IdLabelConfigEditor idEditor) { idEditor.RemoveLabel(targetLabel); } window.RefreshLists(); Object.DestroyImmediate(editor); }; }
public ConfigElementLabelNotPresent(AddToConfigWindow window, List <string> targetLabels) { var uxmlPath = k_UxmlDir + "ConfigElementLabelPresent.uxml"; AssetDatabase.LoadAssetAtPath <VisualTreeAsset>(uxmlPath).CloneTree(this); labelElement = this.Q <Label>("config-name"); var addButton = this.Q <Button>("remove-from-config-button"); addButton.text = targetLabels.Count == 1 ? "Add Label" : "Add All Labels"; var openButton = this.Q <Button>("open-config-button"); openButton.clicked += () => { Selection.SetActiveObjectWithContext(labelConfig, null); }; addButton.clicked += () => { var editor = Editor.CreateEditor(labelConfig); if (editor is SemanticSegmentationLabelConfigEditor semanticEditor) { foreach (var label in targetLabels) { semanticEditor.AddLabel(label); } } else if (editor is IdLabelConfigEditor idEditor) { foreach (var label in targetLabels) { idEditor.AddLabel(label); } } if (targetLabels.Count > 1) { window.SetStatus("All Labels Added to " + labelConfig.name); } window.RefreshLists(); Object.DestroyImmediate(editor); }; }