Beispiel #1
0
    private void Awake()
    {
        InterfaceController controller = InterfaceController.GetInstance();

        if (controller)
        {
            cursorSlot = controller.GetCursorSlot();
        }

        RectTransform rect = (transform as RectTransform);

        rect.localScale = new Vector3(1, 1, 1);

        rect.anchorMin = new Vector2(0, 0);
        rect.anchorMax = rect.anchorMin;

        rect.sizeDelta = new Vector2(SLOT_SIZE, SLOT_SIZE);

        GameObject lbl = new GameObject("label");

        lbl.AddComponent <RectTransform>().SetParent(rect, false);

        labelText               = lbl.AddComponent <Text>();
        labelText.fontSize      = 14;
        labelText.alignment     = TextAnchor.MiddleCenter;
        labelText.raycastTarget = false;
        labelText.font          = Resources.GetBuiltinResource <Font>("Arial.ttf");

        RectTransform fg = new GameObject("item").AddComponent <RectTransform>();

        fg.SetParent(transform, false);

        fg.localScale = new Vector3(1, 1, 1);

        fg.anchorMin = new Vector2(0, 0);
        fg.anchorMax = new Vector2(1, 1);

        fg.anchoredPosition = new Vector2(0, 0);
        fg.sizeDelta        = new Vector2(0, 0);

        foreground = fg.gameObject.AddComponent <Image>();
        foreground.raycastTarget = false;

        GameObject numberBackground = new GameObject("numberBackground");

        numberBackground.AddComponent <RectTransform>().SetParent(fg, false);

        Image numberBg = numberBackground.AddComponent <Image>();

        numberBg.color         = new Color(0F, 0F, 0F, .75F);
        numberBg.raycastTarget = false;

        RectTransform bgRect = numberBackground.GetComponent <RectTransform>();

        bgRect.anchorMin = new Vector2(0F, 0F);
        bgRect.anchorMax = bgRect.anchorMin;
        bgRect.pivot     = new Vector2(0F, 0F);
        bgRect.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, 24F);
        bgRect.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, SLOT_SIZE);

        GameObject num = new GameObject("number");

        count           = num.AddComponent <Text>();
        count.font      = Resources.GetBuiltinResource <Font>("Arial.ttf");
        count.fontSize  = 24;
        count.alignment = TextAnchor.MiddleCenter;
        count.transform.SetParent(numberBackground.transform, false);
        count.raycastTarget = false;

        RefreshSlot();

        if (isDummy)
        {
            return;
        }

        rect.anchoredPosition = new Vector2(x, y);

        background       = gameObject.AddComponent <Image>();
        background.color = color;
    }