/// <summary>
 /// calcutates the size of the controls according to the screen size
 /// </summary>
 private void CalculateSize()
 {
     _contentWidth      = Screen.width * 0.98f;
     _contentHeight     = Screen.height * 0.98f;
     _buttonHeight      = GUI.skin.GetStyle("Button").CalcHeight(new GUIContent("some text"), _contentWidth); //get the height of a button with the text "some text"
     _topBarHeight      = _buttonHeight * 1.5f;
     _padding           = _buttonHeight * 0.15f;
     _topBarButtonWidth = _contentWidth / 8;
     _menuItemWidth     = _contentWidth / 5 - 20;                             //20% of the width for the MenuItems; 20 is subtracted for the scrollBar
     _menuSettingWidth  = _contentWidth - _menuItemWidth - _padding * 3 - 20; //80% minus the _padding for the Settings; 20 is subtracted for the scrollBar
     SettingTemplate.SetInputHeight(GUI.skin.GetStyle("TextField").CalcHeight(new GUIContent("some text"), _contentWidth));
     FileSelector.windowDimensions = new Rect(0, 0, _contentWidth * 0.5f, _contentHeight);
     _isSizeCalculated             = true;
 }
        /// <summary>
        /// Draws the Settings
        /// </summary>
        private void DrawSettings()
        {
            float posY = 0; //the position in Y-direction for the next control

            foreach (KeyValuePair <string, object> keyValuePair in _namesDictionary)
            {
                float height; //the height of the control
                bool  valueChanged = false;

                object newValue = null;
                if (keyValuePair.Value.GetType().IsArray) //Draw an array
                {
                    //the direct conversion (values = (object[]) oldValue) is not possible
                    object[] values = ((IEnumerable)keyValuePair.Value).Cast <object>().ToArray();
                    height = SettingTemplate.GetHeight(typeof(string)) +
                             values.Length * (SettingTemplate.GetHeight(values[0].GetType()) + _padding);
                    if (values.Length > 0)
                    {
                        newValue = SettingTemplate.DrawArray(values, keyValuePair.Key,
                                                             new Rect(0, posY, _menuSettingWidth, height));
                    }
                    if (newValue != null && !newValue.Equals(values))
                    {
                        valueChanged = true;
                    }
                }
                else //Draw a value other than arrays
                {
                    height   = SettingTemplate.GetHeight(keyValuePair.Value.GetType());
                    newValue = SettingTemplate.Draw(keyValuePair.Value, keyValuePair.Key,
                                                    new Rect(0, posY, _menuSettingWidth, height));

                    if (newValue != null && !newValue.Equals(keyValuePair.Value))
                    {
                        valueChanged = true;
                    }
                }

                if (valueChanged)                                                  //if the value was changed: store it temporary
                {
                    List <string> tempList = new List <string>(_namesList);        //this list is to add a Value temporary to _namesList
                    tempList.Add(keyValuePair.Key);
                    Settings.ChangeSettingTomporary(tempList.ToArray(), newValue); //add the changed value to the buffer of temporary changes
                }

                posY += height + _padding; //calculate the position in Y-direction
            }

            DrawSettingButtons(posY);
        }
        /// <summary>
        /// called by unity when an action to the userinterface happend
        /// </summary>
        private void OnGUI()
        {
            if (!_isSizeCalculated)
            {
                CalculateSize(); //Initialize
            }
            if (_actualSection == MenuSection.MainMenu)
            {
                DrawMainMenu();
            }
            else if (_actualSection == MenuSection.Settings)
            {
                //get the items and settings that are actually shown
                _menuItems       = Settings.GetMenuItems(_namesList.ToArray());
                _namesDictionary = Settings.GetMenuSettings(_namesList.ToArray());

                //calculate the height of the settings for the scrollView
                float settingContentHeight = 0;
                foreach (KeyValuePair <string, object> keyValuePair in _namesDictionary)
                {
                    if (keyValuePair.Value.GetType().IsArray)
                    {
                        //the direct conversion (values = (object[]) oldValue) is not possible
                        object[] values = ((IEnumerable)keyValuePair.Value).Cast <object>().ToArray();
                        settingContentHeight += SettingTemplate.GetHeight(typeof(string)) +
                                                values.Length * (SettingTemplate.GetHeight(values[0].GetType()) + _padding);
                    }
                    else
                    {
                        settingContentHeight += SettingTemplate.GetHeight(keyValuePair.Value.GetType());
                    }
                }
                settingContentHeight += _buttonHeight + _padding * 4 + 20; //height of the buttons on the bottom + the _padding between button and settings + height of the scrollBar

                //Begin drawing of the menu
                GUI.BeginGroup(new Rect(_padding, _padding, _contentWidth, _contentHeight)); //content; _padding to the edge

                //Bar on the top
                _topBarScrollPosition = GUI.BeginScrollView(new Rect(0, 0, _contentWidth, _topBarHeight),
                                                            _topBarScrollPosition, new Rect(0, 0, _contentWidth, _topBarHeight));
                DrawTopBar();
                GUI.EndScrollView();

                //MenuItems
                _itemScrollPosition =
                    GUI.BeginScrollView(new Rect(0, _topBarHeight, _menuItemWidth + 20, _contentHeight - _topBarHeight),
                                        _itemScrollPosition, new Rect(0, 0, _menuItemWidth, _menuItems.Count * (_buttonHeight + _padding)));
                DrawMenuItems();
                GUI.EndScrollView();//End MenuItems

                //Settings
                _settingScrollPosition =
                    GUI.BeginScrollView(new Rect(_menuItemWidth + 3 * _padding, _topBarHeight, _menuSettingWidth + 20,
                                                 _contentHeight - _topBarHeight), _settingScrollPosition, new Rect(0, 0, _menuSettingWidth, settingContentHeight));
                DrawSettings();
                GUI.EndScrollView(); //End Settings

                GUI.EndGroup();      //End Content
            }
            else if (_actualSection == MenuSection.Logging)
            {
                DrawTopBar();
                DrawLogging();
            }

            //Message
            if (DateTime.Now - _lastMessageTime < TimeSpan.FromSeconds(5))
            {
                GUI.Label(new Rect(25, _contentHeight - 25, _contentWidth, 25),
                          Message.Messages.Last().MessageText);
            }
        }