Beispiel #1
0
    // Update is called once per frame
    void Update()
    {
        //Check if the left Mouse button is clicked
        if (Input.GetKey(KeyCode.Mouse0))
        {
            //Set up the new Pointer Event
            m_PointerEventData = new PointerEventData(m_EventSystem);
            //Set the Pointer Event Position to that of the mouse position
            m_PointerEventData.position = Input.mousePosition;

            //Create a list of Raycast Results
            List <RaycastResult> results = new List <RaycastResult>();
            EventSystem.current.RaycastAll(m_PointerEventData, results);

            foreach (RaycastResult result in results)
            {
                shopItem trySelectItem = result.gameObject.GetComponent <shopItem>();

                if (trySelectItem)
                {
                    if (selectedItem)
                    {
                        selectedItem.GetComponent <Text>().color = Color.black;
                    }

                    selectedItem = trySelectItem;
                    selectedItem.GetComponent <Text>().color = Color.red;
                    itemTitle.text       = selectedItem.item.title;
                    itemDescription.text = selectedItem.item.description;
                    itemPrice.text       = selectedItem.item.price.ToString();
                }
            }
        }
    }
Beispiel #2
0
 void UpdateInventoryCanvas(Canvas inventoryCanvas)
 {
     selectedItem.transform.SetParent(inventoryCanvas.transform);
     selectedItem.GetComponent <Text>().color = Color.black;
     selectedItem         = null;
     itemTitle.text       = "";
     itemDescription.text = "";
     itemPrice.text       = "";
 }
Beispiel #3
0
    void SetShopItems(InventoryComponent inventory, Canvas inventoryCanvas)
    {
        foreach (Transform child in inventoryCanvas.transform)
        {
            Destroy(child.gameObject);
        }

        foreach (Item item in inventory.items)
        {
            Text     newItem     = new GameObject().AddComponent <Text>();
            shopItem newShopItem = newItem.gameObject.AddComponent <shopItem>();
            newShopItem.item      = item;
            newShopItem.inventory = inventory;

            newItem.transform.SetParent(inventoryCanvas.transform, false);
            newItem.text  = item.title;
            newItem.color = Color.black;
            newItem.font  = (Font)Resources.GetBuiltinResource(typeof(Font), "Arial.ttf");
        }
    }
Beispiel #4
0
        public PieceShop(String imgPath, int cost, Player owner, int menuWidth, int menuHeight, Pos menuPosition, uint menuColor) : base(imgPath, cost, owner, MOVEMODE.NONE)
        {
            this.menuColor    = menuColor;
            this.menuWidth    = menuWidth;
            this.menuHeight   = menuHeight;
            this.menuPosition = menuPosition;
            menuArea          = new Region(menuPosition.x, menuPosition.y,
                                           menuPosition.x + menuWidth,
                                           menuPosition.y + menuHeight);

            //init buttons
            for (int i = 0; i < shopItems.Length; i++)
            {
                shopItems[i]        = new shopItem();
                shopItems[i].button = new GameButton(0, 0, 0, 0);
            }

            shopItems[MB_SHOP].item   = new Piece("res/shop.png", 2, owner, MOVEMODE.NONE);
            shopItems[MB_PAWN].item   = new Piece("res/pawn.png", 1, owner, MOVEMODE.PAWN);
            shopItems[MB_KNIGHT].item = new Piece("res/knight.png", 3, owner, MOVEMODE.KNIGHT);
            shopItems[MB_KING].item   = new Piece("res/king.png", 4, owner, MOVEMODE.KING);
            shopItems[MB_BISHOP].item = new Piece("res/bishop.png", 10, owner, MOVEMODE.BISHOP);
            shopItems[MB_ROOK].item   = new Piece("res/rook.png", 10, owner, MOVEMODE.ROOK);
            shopItems[MB_QUEEN].item  = new Piece("res/queen.png", 15, owner, MOVEMODE.QUEEN);


            for (int i = 0; i < shopItems.Length; i++)
            {
                if (shopItems[i].item != null)
                {
                    shopItems[i].button.clickedAction = itemButtonClicked;
                    images[i] = fbgfx.LoadPNG(shopItems[i].item.imgPath);
                }
            }

            updateMenuImage();
            shopItems[MB_EXIT].button.clickedAction = exitFunction;
            shopItems[MB_BUY].button.clickedAction  = buyClicked;
        }
Beispiel #5
0
 IEnumerator initList()
 {
     if (isFirst)
     {
         foreach (var cloth in GameDataUtil.Clothdatas.Values)
         {
             GameObject go = Instantiate(shopPrefabs) as GameObject;
             go.transform.parent        = Parent;
             go.transform.localPosition = new Vector3(0, startY - distance * index, 0);
             go.transform.localScale    = Vector3.one;
             shopItem  _shopitem = go.GetComponent <shopItem>();
             ClothData datas = GameDataUtil.Clothdatas[cloth.type];
             string    picture = datas.picture.Substring(0, datas.picture.IndexOf('.'));
             string    name1, name2;
             int       price = (datas.ap + datas.hp + datas.magic + datas.defend) / 5 * Math.Max(1, datas.star / 2);//价格
             if (datas.magic > 0 || datas.defend > 0)
             {
                 name1 = "fang";
                 name2 = "fang";
                 _shopitem.InitShopList(picture, datas.name, 0, datas.magic, datas.defend, price, datas.type, name1, name2);
             }
             else
             {
                 name1 = "heart";
                 name2 = "swordicon";
                 _shopitem.InitShopList(picture, datas.name, 0, datas.hp, datas.ap, price, datas.type, name1, name2);
             }
             index++;
         }
         isFirst = false;
     }
     else
     {
     }
     yield return(null);
 }
Beispiel #6
0
 private void menuFunction(shopItem item)
 {
 }