void UpdateMarkerLibraryData(MarsMarkerLibrary markerLibrary, string markerGuidValue) { const string markersProp = "m_Markers"; if (m_CurrentMarkerIndex != ImageMarkerEditorUtils.UnselectedMarkerIndex && m_CurrentMarkerIndex < markerLibrary.Count && markerLibrary[m_CurrentMarkerIndex].MarkerId.ToString() == markerGuidValue && m_MarkerLibrary == markerLibrary) { return; } m_CurrentMarkerIndex = ImageMarkerEditorUtils.CurrentSelectedImageMarkerIndex(markerLibrary, markerGuidValue); if (m_MarkerLibrary != markerLibrary) { m_MarkerLibrarySerializedObject = new SerializedObject(markerLibrary); m_MarkerProperty = m_MarkerLibrarySerializedObject.FindProperty(markersProp); m_MarkerLibrary = markerLibrary; } if (m_CurrentMarkerIndex != ImageMarkerEditorUtils.UnselectedMarkerIndex) { m_SizeOptionIndex = MarkerConstants.GetSelectedMarsMarkerSizeOption(markerLibrary[m_CurrentMarkerIndex].Size); m_MarkerDefinitionProperty = m_MarkerProperty.GetArrayElementAtIndex(m_CurrentMarkerIndex); } }
/// <summary> /// Draw info contents (texture thumbnail, marker tag and size) for an image marker inside a library /// </summary> /// <param name="markerDefinitionProperty">The marker definition serialized property</param> /// <param name="markerSizeOptionIndex">Selected option for pre-set physical sizes</param> /// <returns>The current marker sized option index</returns> public static int DrawImageMarkerInfoContentsAtIndex(SerializedProperty markerDefinitionProperty, int markerSizeOptionIndex) { const string texturePropName = "m_Texture"; const string labelPropName = "m_Label"; const string sizePropName = "m_Size"; var markerTextureProperty = markerDefinitionProperty.FindPropertyRelative(texturePropName); var labelProperty = markerDefinitionProperty.FindPropertyRelative(labelPropName); var sizeProperty = markerDefinitionProperty.FindPropertyRelative(sizePropName); using (new EditorGUILayout.VerticalScope()) { using (var check = new EditorGUI.ChangeCheckScope()) { EditorGUILayout.PropertyField(markerTextureProperty); EditorGUILayout.PropertyField(labelProperty); var newSizeIndex = EditorGUILayout.Popup(styles.MarkerSize, markerSizeOptionIndex, MarkerConstants.MarkerSizeOptions); if (newSizeIndex != 0 && newSizeIndex != markerSizeOptionIndex) { markerSizeOptionIndex = newSizeIndex; sizeProperty.vector2Value = MarkerConstants.MarkerSizeOptionsValuesInMeters[markerSizeOptionIndex]; } EditorGUI.indentLevel++; EditorGUILayout.PropertyField(sizeProperty, new GUIContent(string.Empty, sizeProperty.tooltip)); EditorGUI.indentLevel--; if (check.changed) { var sizeValue = sizeProperty.vector2Value; sizeValue = new Vector2( Mathf.Max(MarkerConstants.MinimumPhysicalMarkerSizeWidthInMeters, sizeValue.x), Mathf.Max(MarkerConstants.MinimumPhysicalMarkerSizeHeightInMeters, sizeValue.y)); sizeProperty.vector2Value = sizeValue; markerSizeOptionIndex = MarkerConstants.GetSelectedMarsMarkerSizeOption(sizeValue); ImageMarkerSizeUpdate?.Invoke(BuildMarkerId(markerDefinitionProperty), sizeValue); } } } return(markerSizeOptionIndex); }