public void CopyAttributeValuesTo(HEU_AttributesStore destAttrStore) { foreach(HEU_AttributeData attrData in _attributeDatas) { HEU_AttributeData destAttrData = destAttrStore.GetAttributeData(attrData._name); if(destAttrStore != null) { attrData.CopyValuesTo(destAttrData); SetAttributeDataDirty(destAttrData); } } }
private void DrawAttributeSelection() { // Try to re-use the last selected node string lastSelectedNodeName = null; SerializedProperty lastSelectedNodeNameProperty = HEU_EditorUtility.GetSerializedProperty(_toolsInfoSerializedObject, "_lastAttributeNodeName"); if (lastSelectedNodeNameProperty != null) { lastSelectedNodeName = lastSelectedNodeNameProperty.stringValue; } HEU_AttributesStore foundAttributeStore = null; // Get the names of the all editable nodes having an attribute store for this asset // While doing that, we'll find the last selected attribute store int lastSelectedIndex = 0; List<string> nodeNames = new List<string>(); foreach (HEU_AttributesStore attributeStore in _attributesStores) { string geoName = attributeStore.GeoName; if (!nodeNames.Contains(geoName)) { nodeNames.Add(geoName); // Either re-select last selected node, or select the first one found if (string.IsNullOrEmpty(lastSelectedNodeName) || lastSelectedNodeName.Equals(geoName)) { lastSelectedNodeName = geoName; lastSelectedIndex = nodeNames.Count - 1; foundAttributeStore = attributeStore; } } } // Try to re-use the last selected attribute string lastSelectedAttributeName = null; SerializedProperty lastSelectedAttributeProperty = HEU_EditorUtility.GetSerializedProperty(_toolsInfoSerializedObject, "_lastAttributeName"); if (lastSelectedAttributeProperty != null) { lastSelectedAttributeName = lastSelectedAttributeProperty.stringValue; } // Display a dropdown list of editable nodes with attribute stores int currentSelectedIndex = EditorGUILayout.Popup(_editableNodeLabel, lastSelectedIndex, nodeNames.ToArray()); if (currentSelectedIndex != lastSelectedIndex) { // User changed node selection, so update it lastSelectedNodeName = nodeNames[currentSelectedIndex]; foundAttributeStore = null; foreach (HEU_AttributesStore attributeStore in _attributesStores) { string geoName = attributeStore.GeoName; if (geoName.Equals(lastSelectedNodeName)) { foundAttributeStore = attributeStore; break; } } SetSelectedAttributeStore(foundAttributeStore); // Reset selected attribute to first attribute SetSelectedAttributeData(_selectedAttributesStore.GetAttributeData(0)); lastSelectedAttributeName = _selectedAttributeData._name; lastSelectedAttributeProperty.stringValue = lastSelectedAttributeName; lastSelectedNodeNameProperty.stringValue = lastSelectedNodeName; _GUIChanged = true; } else { // Since selected node hasn't changed, re-use the last selected attribute SetSelectedAttributeStore(foundAttributeStore); SetSelectedAttributeData(_selectedAttributesStore.GetAttributeData(lastSelectedAttributeName)); } // Get attribute names for selected node List<string> attributeNames = _selectedAttributesStore.GetAttributeNames(); // Find the last selected attribute index int lastAttributeIndex = -1; if (!string.IsNullOrEmpty(lastSelectedAttributeName)) { for(int i = 0; i < attributeNames.Count; ++i) { if (lastSelectedAttributeName.Equals(attributeNames[i])) { lastAttributeIndex = i; break; } } } // Use first attribute as default if none selected last time if(lastAttributeIndex == -1) { lastAttributeIndex = 0; HEU_AttributeData data = _selectedAttributesStore.GetAttributeData(0); if (data != null) { lastSelectedAttributeProperty.stringValue = data._name; } } // Display attributes as dropdown if (attributeNames.Count > 0) { int currentAttributeIndex = EditorGUILayout.Popup(_attributeLabel, lastAttributeIndex, attributeNames.ToArray()); if (currentAttributeIndex != lastAttributeIndex) { // User changed attribute selection, so update it SetSelectedAttributeData(_selectedAttributesStore.GetAttributeData(attributeNames[currentAttributeIndex])); lastSelectedAttributeProperty.stringValue = _selectedAttributeData._name; } } }