예제 #1
0
        /// <summary>
        /// Render all options with non-empty text.
        /// </summary>
        private void RenderOptionButtons()
        {
            Option selected = Option.SelectedNone;

            // Render options with non-empty text.
            var options = GetOptionList();

            // Space the button similar to Unity dialog. Ex.
            // | [ Option 1 (Cancel) ]                         [ Option 2 (Alt) ] [ Option 0 (Ok) ] |
            // |                                            [ Option 1 (Cancel) ] [ Option 0 (Ok) ] |
            // |                                                                  [ Option 0 (Ok) ] |
            List <int> spacesBeforeButtons = new List <int>(options.Count == 3 ?
                                                            new int[3] {
                0, 2, 0
            } :
                                                            new int[3] {
                2, 0, 0
            });

            for (int i = 0; i < options.Count; ++i)
            {
                // Place spaces before the button.
                if (i < spacesBeforeButtons.Count)
                {
                    for (int j = 0; j < spacesBeforeButtons[i]; ++j)
                    {
                        EditorGUILayout.Space();
                    }
                }

                var pair = options [i];
                if (GUILayout.Button(pair.Key))
                {
                    selected = pair.Value;
                }
            }

            if (selected != Option.SelectedNone)
            {
                selectedOption = selected;
                if (dialogContext.CompleteAction != null)
                {
                    dialogContext.CompleteAction(selectedOption);
                }
                Close();
            }
        }