コード例 #1
0
    public static void CreatePropertyCard(Transform parent, Property property, Vector2 localPosition, Vector2 sizeDelta)
    {
        Street street = property.GetComponent <Street>();

        GameObject cardObj = new GameObject("InventoryCard");
        Image      card    = cardObj.AddComponent <Image>();

        card.tag = "InventoryCard";
        card.transform.SetParent(parent);
        card.rectTransform.sizeDelta     = sizeDelta;
        card.rectTransform.localPosition = localPosition;

        cardObj.AddComponent <InventoryPropertyMouseInputUI>().property = property;

        Text title = new GameObject().AddComponent <Text>();

        title.text      = property.Title;
        title.fontSize  = 6;
        title.color     = Color.black;
        title.font      = Resources.GetBuiltinResource <Font>("Arial.ttf");
        title.alignment = TextAnchor.UpperCenter;
        title.transform.SetParent(card.transform);
        title.rectTransform.sizeDelta     = new Vector2(card.rectTransform.sizeDelta.x * 4 / 5, card.rectTransform.sizeDelta.y / 6);
        title.rectTransform.localPosition = new Vector2(0f, 35f);

        if (!property.Mortgaged)
        {
            Text price = new GameObject().AddComponent <Text>();
            price.text      = "$" + property.Price;
            price.fontSize  = 6;
            price.color     = Color.black;
            price.font      = Resources.GetBuiltinResource <Font>("Arial.ttf");
            price.alignment = TextAnchor.UpperCenter;
            price.transform.SetParent(card.transform);
            price.rectTransform.sizeDelta     = new Vector2(card.rectTransform.sizeDelta.x * 4 / 5, card.rectTransform.sizeDelta.y / 6);
            price.rectTransform.localPosition = new Vector2(0f, -40f);

            if (street != null)
            {
                Image streetColour = new GameObject("StreetColour").AddComponent <Image>();
                streetColour.transform.SetParent(card.transform);
                streetColour.rectTransform.sizeDelta     = new Vector2(card.rectTransform.sizeDelta.x, card.rectTransform.sizeDelta.y / 6);
                streetColour.rectTransform.localPosition = new Vector2(0f, card.rectTransform.sizeDelta.y / 2 - streetColour.rectTransform.sizeDelta.y / 2);
                streetColour.color = new Color(street.Colour.r, street.Colour.g, street.Colour.b, 1);

                title.rectTransform.localPosition = new Vector2(0f, 20f);

                //grays out street if not able to build house in house mode
                if (BuildHouseMode && !street.CanBuildHouse())
                {
                    DisableCard(cardObj);
                }
            }
            else if (property.GetComponent <Utility>() != null || property.GetComponent <RailwayStation>() != null)
            {
                Image icon = new GameObject("Icon").AddComponent <Image>();
                icon.sprite = property.GetComponent <Tile>().Icon;
                icon.rectTransform.SetParent(card.transform);
                icon.rectTransform.localPosition = Vector2.zero;
                icon.rectTransform.sizeDelta     = new Vector2(card.rectTransform.sizeDelta.x * 0.7f, card.rectTransform.sizeDelta.x * 0.7f);
            }
        }
        else
        {
            title.text = "MORTGAGED";
            title.rectTransform.localPosition = Vector3.zero;
        }

        //grays out non-street properties if in house mode or if cant sell house, or if in payment menu and property mortgaged, or can't pay unmortgage cost
        if ((!TradingMode &&
             ((BuildHouseMode && (street == null || street.Mortgaged)) ||
              (!BuildHouseMode && street != null && !street.CanMortagage() && !street.Mortgaged && !street.CanSellHouse()) ||
              (PaymentOptions.enabled == true && property.Mortgaged) ||
              (property.Mortgaged && property.Owner.GetBalance() < property.UnMortgageCost))) ||
            (TradingMode && street != null && street.Houses > 0))
        {
            DisableCard(cardObj);
        }
    }