public void SetDialog(Dialog dialog, UiPolicy uiPolicy)
    {
        if (!initialized)
        {
            Init();
        }
        bool isScrolledAllTheWayDown = !scrollRect.verticalScrollbar.gameObject.activeInHierarchy ||
                                       scrollRect.verticalNormalizedPosition < 1f / 1024; // keep scrolling down if really close to bottom

        switch (uiPolicy)
        {
        case UiPolicy.StartOver: RemoveDialogElements(); break;

        case UiPolicy.DisablePrev: DeactivateDialogChoices(); break;

        case UiPolicy.Continue: break;
        }
        if (dialog == null)
        {
            tokenizer.AddError("missing dialog");  return;
        }
        if (dialog.options != null)
        {
            for (int i = 0; i < dialog.options.Length; ++i)
            {
                Dialog.DialogOption opt = dialog.options[i];
                if (opt.Available(tokenizer, GetScriptScope()))
                {
                    AddDialogOption(opt, isScrolledAllTheWayDown);
                }
            }
        }
    }
示例#2
0
    private void DrawOption(Rect rect, int index, bool active, bool focused)
    {
        Dialog.DialogOption opt = (Dialog.DialogOption)optionsReorderableList.list[index];

        EditorGUI.LabelField(moveRect(labelRect, rect), "Text: ");
        opt.text = EditorGUI.TextField(moveRect(optionRect, rect), opt.text);

        if (myNode.Childs[index] != null)
        {
            myNode.Childs[index].Name = "Option " + (index + 1);
        }
    }
    public ListItemUi AddDialogOption(Dialog.DialogOption option, bool scrollAllTheWayDown)
    {
        if (!initialized)
        {
            Init();
        }
        ListItemUi li = null;

        do
        {
            Dialog.Text t = option as Dialog.Text;
            if (t != null)
            {
                li = listUi.AddItem(option, scriptedVariableScope.Format(t.text), null, prefab_textUi);
                break;
            }
            Dialog.Choice c = option as Dialog.Choice;
            if (c != null)
            {
                li = listUi.AddItem(option, scriptedVariableScope.Format(c.text), () => ParseCommand(c.command), prefab_buttonUi);
                currentChoices.Add(li);
                break;
            }
            Dialog.Command cmd = option as Dialog.Command;
            if (cmd != null)
            {
                ParseCommand(cmd.command);
                break;
            }
        }while (false);
        if (li != null)
        {
            li.text.alignment = option.anchorText;
        }
        if (scrollAllTheWayDown && !goingToScrollAllTheWayDown)
        {
            goingToScrollAllTheWayDown = true;
            // we want scroll all the way down, and can't control when the UI updates enough to realize it can scroll
            NonStandard.Clock.setTimeout(() => {
                goingToScrollAllTheWayDown = false; scrollRect.verticalNormalizedPosition = 0;
            }, 100);
            // 100ms (1/10th of a second) is not bad for UI lag, and should be enough time for the UI to update itself
        }
        return(li);
    }