Пример #1
0
    public int DisplayOptionLine(string optionText, Action action)
    {
        int     optionNumber = _currentOptionLines.Count;
        KeyCode inputKey     = KeyCode.None;
        string  inputName    = "";

        if (optionNumber < SelectionKeys.Length)
        {
            if ((int)CharacterKey < SelectionKeys[optionNumber].Length)
            {
                inputKey = SelectionKeys[optionNumber][(int)CharacterKey];
                if (inputKey != KeyCode.None)
                {
                    inputName = "(" + inputKey.ToString() + ") ";
                }
            }
        }

        GameObject line = Instantiate(OptionPrefab);

        line.transform.SetParent(_lineParent.transform, false);
        line.transform.localPosition = _currLinePosition;
        Text text = line.GetComponent <Text>();

        text.text = inputName + optionText;

        ContentSizeFitter contentSizeFitter = line.GetComponent <ContentSizeFitter>();

        contentSizeFitter.SetLayoutVertical();

        _currLinePosition.y -= Mathf.Max(MinimumLineDistance, line.GetComponent <RectTransform>().rect.height + MinimumLineBuffer);

        RectTransform rectTransform = transform.GetComponent <RectTransform>();

        if (_currLinePosition.y < (_lineParent.transform.localPosition.y - rectTransform.rect.height))
        {
            Vector3 feedPosition = _lineParent.transform.localPosition;
            feedPosition.y = Mathf.Abs(_currLinePosition.y) - rectTransform.rect.height;
            _lineParent.transform.localPosition = feedPosition;
        }

        Button button = line.GetComponent <Button>();

        button.onClick.AddListener(() =>
        {
            action();
            GetComponent <AudioSource>().Play();
        });

        KeyboardSelection keyboardSelection = line.GetComponent <KeyboardSelection>();

        keyboardSelection.InputKey = inputKey;

        _currentOptionLines.Add(line);

        return(line.GetInstanceID());
    }
Пример #2
0
    public int DisplayOptionLine(string optionText, Action action)
    {
        optionText = optionText.Trim(new char[] { '\n', '\r' });

        int     optionNumber = _currentOptionLines.Count;
        KeyCode inputKey     = KeyCode.None;

        /*
         * string inputName = "";
         * if (optionNumber < SelectionKeys.Length)
         * {
         *  if ((int)CharacterKey < SelectionKeys[optionNumber].Length)
         *  {
         *      inputKey = SelectionKeys[optionNumber][(int)CharacterKey];
         *      if (inputKey != KeyCode.None)
         *      {
         *          inputName = "(" + inputKey.ToString() + ") ";
         *      }
         *  }
         * }
         */

        GameObject line = Instantiate(OptionPrefab, LineParent.transform, false);

        if (LineParent.transform.childCount > 1)
        {
            if (_currentOptionLines.Count == 0)
            {
                _currLineY -= MinimumLineBuffer * 2f;
            }
            else
            {
                _currLineY -= MinimumOptionBuffer;
            }
        }

        var position = line.GetComponent <RectTransform>().anchoredPosition;

        position.y = _currLineY;
        line.GetComponent <RectTransform>().anchoredPosition = position;

        Text text = line.GetComponent <Text>();

        text.text = /*inputName + */ optionText + "  ●";

        ContentSizeFitter contentSizeFitter = line.GetComponent <ContentSizeFitter>();

        contentSizeFitter.SetLayoutVertical();

        _currLineY -= Mathf.Max(MinimumLineDistance, line.GetComponent <RectTransform>().rect.height);

        var feedPosition = LineParent.GetComponent <RectTransform>().anchoredPosition;

        feedPosition.y = Mathf.Abs(_currLineY);
        LineParent.GetComponent <RectTransform>().anchoredPosition = feedPosition;

        Button button = line.GetComponent <Button>();

        button.onClick.AddListener(() =>
        {
            SelectOption(button.gameObject);
            action();
            //GetComponent<AudioSource>().Play();
        });

        KeyboardSelection keyboardSelection = line.GetComponent <KeyboardSelection>();

        keyboardSelection.InputKey = inputKey;

        _currentOptionLines.Add(line);

        return(line.GetInstanceID());
    }