示例#1
0
// ~~ private
    private void RefreshAttributes(IAttributeData data, ColumnGridFlexibleRect root)
    {
        VerticalFlexibleRect child = VerticalFlexibleRect.GetRect(ViewData);

        child.transform.SetParent(root.transform, false);

        foreach (KeyValuePair <string, float[]> pair in data.AttributeDictionary)
        {
            HorizontalFlexibleRect grandchild = HorizontalFlexibleRect.GetRect(ViewData);
            grandchild.transform.SetParent(child.transform, false);

            GameObject keyLeafObj = new GameObject(pair.Key.ToString());
            Text       keyText    = keyLeafObj.AddComponent <Text>();
            keyText.font     = UnityBuiltin.Font("Arial");
            keyText.text     = pair.Key;
            keyText.color    = Color.black;
            keyText.fontSize = (int)TextConstants.BODY_TEXT_SIZE;

            keyLeafObj.transform.SetParent(grandchild.transform, false);

            GameObject valueLeafObj = new GameObject(pair.Value.ToString());
            Text       valueText    = valueLeafObj.AddComponent <Text>();
            valueText.font     = UnityBuiltin.Font("Arial");
            valueText.text     = pair.Value[0].ToString();
            valueText.color    = Color.black;
            valueText.fontSize = (int)TextConstants.BODY_TEXT_SIZE;

            valueLeafObj.transform.SetParent(grandchild.transform, false);
        }
    }
示例#2
0
    public void Refresh(
        List <Action> selfAbilities = null,
        Dictionary <Action, Action <Vector3> > locationAbilities    = null,
        Dictionary <Action, Action <GameObject[]> > objectAbilities = null
        )
    {
        Clear();

        _rootFlexRectMono =
            HorizontalFlexibleRect.GetRect(ViewData);

        _rootFlexRectMono.transform.SetParent(ContentRect.transform, false);

        _rootFlexRectMono.SizeDelta = new Vector2(ContentRect.SizeDelta.x, ContentRect.SizeDelta.y);

        if (selfAbilities != null && selfAbilities.Count > 0)
        {
            CreateSelfAbilityBar(
                selfAbilities,
                ViewData.SelfActionBGColor
                ).transform.SetParent(_rootFlexRectMono.transform, false);
        }

        if (locationAbilities != null && locationAbilities.Count > 0)
        {
            CreateLocationAbilityBar(
                locationAbilities,
                ViewData.LocationActionBGColor
                ).transform.SetParent(_rootFlexRectMono.transform, false);
        }

        if (objectAbilities != null && objectAbilities.Count > 0)
        {
            CreateObjectAbilityBar(
                objectAbilities,
                ViewData.ObjectActionBGColor
                ).transform.SetParent(_rootFlexRectMono.transform, false);
        }

        _rootFlexRectMono.Refresh();
    }
示例#3
0
    private HorizontalFlexibleRect CreateObjectAbilityBar(
        Dictionary <Action, Action <GameObject[]> > abilities,
        Color buttonColor
        )
    {
        HorizontalFlexibleRect child = HorizontalFlexibleRect.GetRect(ViewData);

        foreach (KeyValuePair <Action, Action <GameObject[]> > pair in abilities)
        {
            GameObject leafObj = new GameObject(pair.Value.Method.Name + " Button");

            leafObj.SetActive(false);
            Image  image  = leafObj.AddComponent <Image>();
            Button button = leafObj.AddComponent <Button>();
            button.onClick.AddListener(() => button.Deselect());
            AddWaitClickObjectButtonListener(button, pair.Key, pair.Value);
            ColorBlock cBlock = button.colors;
            cBlock.normalColor      = buttonColor;
            cBlock.pressedColor     = buttonColor;
            cBlock.selectedColor    = buttonColor;
            cBlock.highlightedColor = cBlock.normalColor.GetHighlightedColor(.75f);
            button.colors           = cBlock;
            leafObj.SetActive(true);

            GameObject textObj = new GameObject(pair.Value.Method.Name + " Text");
            textObj.transform.SetParent(leafObj.transform, false);
            TextMeshProUGUI buttonText = textObj.AddComponent <TextMeshProUGUI>();
            buttonText.enableAutoSizing = true;
            buttonText.margin           = new Vector4(10f, 10f, 10f, 10f);
            buttonText.text             = pair.Value.Method.Name;
            buttonText.alignment        = TextAlignmentOptions.Center;
            buttonText.color            = buttonColor.GetInvertedColor();

            leafObj.transform.SetParent(child.transform, false);
        }

        return(child);
    }