private int GetCurrentIndex(TutorialManagerModel model, string bindingId)
 {
     return(model.steps.Select((value, index) => new { value, index })
            .Where(pair => pair.value.id == bindingId)
            .Select(pair => pair.index + 1)
            .FirstOrDefault() - 1);
 }
        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++;
            });
        }
        private bool CachedStepsAreStillValid(TutorialManagerModel model)
        {
            bool isValid = model.stepTable.Count == stepIds.Count;

            if (isValid)
            {
                int aa = 0;
                foreach (KeyValuePair <string, StepEntity> t in model.stepTable)
                {
                    if (t.Value.id != stepIds[aa])
                    {
                        isValid = false;
                        break;
                    }
                    aa++;
                }
            }
            return(isValid);
        }
        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();
            }
        }
        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();
                    }
                }
            }
        }