void BuildBindingsMenu(int listIndex, int selectedIndex = -1) { TutorialManagerModel model = TutorialManagerModelMiddleware.GetInstance().TMData; bindingsMenu = new GenericMenu(); int index = 0; model.steps.ForEach(step => { string stepId = step.id; bindingsMenu.AddItem( new GUIContent(stepId.Replace('-', '/')), index == selectedIndex, SetSelectedBinding, new SelectedBindingInfo(stepId, index, listIndex) ); index++; }); }
protected void RenderContentElements() { if (addButtonStyle == null) { DefineStyles(); } TutorialManagerModel model = TutorialManagerModelMiddleware.GetInstance().TMData; if (model.steps.Count() == 0) { // Display warning EditorGUILayout.HelpBox(k_TMSettingsRequiredMessage, MessageType.Warning, true); } else { RenderBindings(); RenderOptOutCheckbox(); } }
public override void OnInspectorGUI() { serializedObject.Update(); RenderContentElements(); AdaptiveText myTarget = (AdaptiveText)target; TutorialManagerModelMiddleware model = TutorialManagerModelMiddleware.GetInstance(); RenderOverrideOnlyWhenNotEmptyCheckbox(); if (lastKnownTextValue != myTarget.GetCurrentText() || bindingsHaveChanged) { CreateOrUpdateTextEntities(myTarget, model); } bool hasText = false; if (myTarget.GetComponent <Text>() != null || myTarget.GetComponent <TextMesh>() != null) { hasText = true; } #if TEXTMESHPRO_PRESENT if (!hasText && myTarget.GetComponent <TMP_Text>() != null) { hasText = true; } #endif if (hasText == false) { // Display warning EditorGUILayout.HelpBox(k_TextRequiredMessage, MessageType.Warning, true); } serializedObject.ApplyModifiedProperties(); lastKnownTextValue = myTarget.GetCurrentText(); bindingsHaveChanged = false; }
protected void RenderBindings() { SerializedProperty arraySizeProperty = bindingIdsProperty.FindPropertyRelative("Array.size"); TutorialManagerModel model = TutorialManagerModelMiddleware.GetInstance().TMData; int count = Mathf.Max(1, arraySizeProperty.intValue); for (int a = 0; a < count; a++) { bool isFirst = (a == 0); bool isLast = (a == count - 1); int bindingIndex = 0; if (isLast && a >= arraySizeProperty.intValue) { bindingIndex = 0; } else { SerializedProperty elementProperty = bindingIdsProperty.GetArrayElementAtIndex(a); bindingIndex = GetCurrentIndex(model, elementProperty.stringValue); } using (new GUILayout.HorizontalScope()) { var labelRect = EditorGUILayout.GetControlRect(); labelRect.width = EditorGUIUtility.labelWidth; var buttonRect = new Rect( labelRect.x + labelRect.width, labelRect.y, EditorGUIUtility.currentViewWidth - (labelRect.width + (labelRect.x * 2f)), EditorGUIUtility.singleLineHeight ); if (isLast) { buttonRect.width -= 40f; } var labelContent = isFirst ? bindingLabel : emptyLabel; EditorGUI.LabelField(labelRect, labelContent); string id = "Binding lost"; if (bindingIndex >= 0 && bindingIndex < model.steps.Count) { id = model.steps[bindingIndex].id; } string bindingDisplayName = Regex.Replace(id, "-", ", "); if (GUI.Button(buttonRect, new GUIContent(bindingIndex < 0 ? blankBinding : new GUIContent(bindingDisplayName)), EditorStyles.popup)) { BuildBindingsMenu(a, bindingIndex); bindingsMenu.DropDown(buttonRect); } if (isLast) { if (GUILayout.Button(addBindingButtonGUIContent, addButtonStyle, GUILayout.MaxWidth(20f))) { arraySizeProperty.intValue++; bindingsHaveChanged = true; } EditorGUI.BeginDisabledGroup(isFirst); if (GUILayout.Button(deleteBindingButtonGUIContent, addButtonStyle, GUILayout.MaxWidth(20f))) { arraySizeProperty.intValue = Mathf.Max(1, arraySizeProperty.intValue - 1); bindingsHaveChanged = true; } EditorGUI.EndDisabledGroup(); } } } }