Exemplo n.º 1
0
    public void OnDrop(PointerEventData eventData)
    {
        DragDropItem item = eventData.pointerDrag.GetComponent <DragDropItem>();

        if (!item)
        {
            return;
        }

        if (acceptor.ApplyDrop(item.dragItem.GetItem()))
        {
            item.DropHandeled();
            item.transform.SetParent(retarget);

            RectTransform itemRect = item.GetComponent <RectTransform>();

            if (centered)
            {
                itemRect.anchoredPosition = new Vector2(rect.sizeDelta.x / 2f, -rect.sizeDelta.y / 2f + itemRect.sizeDelta.y / 2f);
            }
            else
            {
                PlaceInside(itemRect);
            }
        }
    }
Exemplo n.º 2
0
    public void Initialize(BuildListItemData buildingData)
    {
        data = buildingData;
        label = transform.Find("Label").GetComponent<UILabel>();
        dragBehavior = GetComponent<DragDropItem>();

        label.text = buildingData.buildingName;
        this.placementPrefab = buildingData.prefab;

        dragBehavior.prefab = placementPrefab;
    }
Exemplo n.º 3
0
 private void InitializeItems()
 {
     _items[0] = new DragDropItem(this, new Vector2(72, 91) + _itemPositinOffset, 60, 75, null);
     _items[1] = new DragDropItem(this, new Vector2(137, 91) + _itemPositinOffset, 60, 75, null);
     _items[2] = new DragDropItem(this, new Vector2(201, 91) + _itemPositinOffset, 60, 75, null);
     _items[3] = new DragDropItem(this, new Vector2(72, 170) + _itemPositinOffset, 60, 75, null);
     _items[4] = new DragDropItem(this, new Vector2(137, 170) + _itemPositinOffset, 60, 75, null);
     _items[5] = new DragDropItem(this, new Vector2(202, 170) + _itemPositinOffset, 60, 75, null);
     _items[6] = new DragDropItem(this, new Vector2(72, 250) + _itemPositinOffset, 60, 75, null);
     _items[7] = new DragDropItem(this, new Vector2(137, 250) + _itemPositinOffset, 60, 75, null);
     _items[8] = new DragDropItem(this, new Vector2(202, 250) + _itemPositinOffset, 60, 75, null);
 }
Exemplo n.º 4
0
        private void ListBox_Drop(object sender, DragEventArgs e)
        {
            try
            {
                if (_draggingItem == null)
                {
                    return;
                }

                // Figure out which listbox this was dropped in
                ListBox droppedListbox = GetDroppedListbox(e.Source as DependencyObject);
                if (droppedListbox == null)
                {
                    return;
                }

                // Cancel if they drop into the same listbox
                if (_draggingItem.IsFromShop)
                {
                    if (droppedListbox == lstShopInventory)
                    {
                        return;
                    }
                }
                else
                {
                    if (droppedListbox == lstBotInventory)
                    {
                        return;
                    }
                }

                // Transfer
                if (_draggingItem.IsFromShop)
                {
                    BuyItem(_draggingItem.Item);
                }
                else
                {
                    SellItem(_draggingItem.Item);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "ShopPanel", MessageBoxButton.OK, MessageBoxImage.Error);
            }
            finally
            {
                // No matter what happens, this needs to become null
                _draggingItem = null;
            }
        }
Exemplo n.º 5
0
        private void InitializeItems(bool useTopLeftText)
        {
            var c = _config;

            _items[0] = new DragDropItem(this, new Vector2(int.Parse(c["Item_Left_1"]), int.Parse(c["Item_Top_1"])), int.Parse(c["Item_Width_1"]), int.Parse(c["Item_Height_1"]), null, null, useTopLeftText);
            _items[1] = new DragDropItem(this, new Vector2(int.Parse(c["Item_Left_2"]), int.Parse(c["Item_Top_2"])), int.Parse(c["Item_Width_2"]), int.Parse(c["Item_Height_2"]), null, null, useTopLeftText);
            _items[2] = new DragDropItem(this, new Vector2(int.Parse(c["Item_Left_3"]), int.Parse(c["Item_Top_3"])), int.Parse(c["Item_Width_3"]), int.Parse(c["Item_Height_3"]), null, null, useTopLeftText);
            _items[3] = new DragDropItem(this, new Vector2(int.Parse(c["Item_Left_4"]), int.Parse(c["Item_Top_4"])), int.Parse(c["Item_Width_4"]), int.Parse(c["Item_Height_4"]), null, null, useTopLeftText);
            _items[4] = new DragDropItem(this, new Vector2(int.Parse(c["Item_Left_5"]), int.Parse(c["Item_Top_5"])), int.Parse(c["Item_Width_5"]), int.Parse(c["Item_Height_5"]), null, null, useTopLeftText);
            _items[5] = new DragDropItem(this, new Vector2(int.Parse(c["Item_Left_6"]), int.Parse(c["Item_Top_6"])), int.Parse(c["Item_Width_6"]), int.Parse(c["Item_Height_6"]), null, null, useTopLeftText);
            _items[6] = new DragDropItem(this, new Vector2(int.Parse(c["Item_Left_7"]), int.Parse(c["Item_Top_7"])), int.Parse(c["Item_Width_7"]), int.Parse(c["Item_Height_7"]), null, null, useTopLeftText);
            _items[7] = new DragDropItem(this, new Vector2(int.Parse(c["Item_Left_8"]), int.Parse(c["Item_Top_8"])), int.Parse(c["Item_Width_8"]), int.Parse(c["Item_Height_8"]), null, null, useTopLeftText);
            _items[8] = new DragDropItem(this, new Vector2(int.Parse(c["Item_Left_9"]), int.Parse(c["Item_Top_9"])), int.Parse(c["Item_Width_9"]), int.Parse(c["Item_Height_9"]), null, null, useTopLeftText);
        }
Exemplo n.º 6
0
    private void OnDrop(GameObject go)
    {
        DragDropItem component = go.GetComponent <DragDropItem>();

        if (component != null)
        {
            Transform transform = NGUITools.AddChild(base.gameObject, component.prefab).transform;
            transform.position = UICamera.lastHit.point;
            if (this.rotatePlacedObject)
            {
                transform.rotation = Quaternion.LookRotation(UICamera.lastHit.normal) * Quaternion.Euler(90f, 0f, 0f);
            }
            UnityEngine.Object.Destroy(go);
        }
    }
Exemplo n.º 7
0
    void OnDrop(GameObject go)
    {
        DragDropItem ddo = go.GetComponent <DragDropItem>();

        if (ddo != null)
        {
            GameObject child = NGUITools.AddChild(gameObject, ddo.prefab);

            Transform trans = child.transform;
            trans.position = UICamera.lastHit.point;
            if (rotatePlacedObject)
            {
                trans.rotation = Quaternion.LookRotation(UICamera.lastHit.normal) * Quaternion.Euler(90f, 0f, 0f);
            }
            Destroy(go);
        }
    }
Exemplo n.º 8
0
        private void ListBox_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            try
            {
                _draggingItem = null;

                var clickedItem = GetClickedItem(e.Source as DependencyObject);
                if (clickedItem == null)
                {
                    return;
                }

                _draggingItem = new DragDropItem(clickedItem.Item2 == lstShopInventory, clickedItem.Item1);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "ShopPanel", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Exemplo n.º 9
0
        private void ListBox_PreviewMouseMove(object sender, MouseEventArgs e)
        {
            try
            {
                if (_draggingItem == null)
                {
                    return;
                }
                else if (e.LeftButton != MouseButtonState.Pressed)
                {
                    _draggingItem = null;
                    return;
                }

                DataObject dragData = new DataObject(DATAFORMAT_DRAGGINGITEM, _draggingItem);
                DragDrop.DoDragDrop(_draggingItem.Item, dragData, DragDropEffects.Move);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "ShopPanel", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Exemplo n.º 10
0
 string CreateTooltip(DragDropItem item)
 {
     return("<color=#b8c7ff><b><size=14>" + item.itemLabel + "</size></b></color>\n\n<b>" + item.itemHint + "</b>");
 }
Exemplo n.º 11
0
	public void UI0000_BackGround_1_Pic_3Clicked(){
		transform.FindChild("UI1000").gameObject.SetActive(true);
		transform.FindChild("UI0000").gameObject.SetActive(false);
		dragdropitem = GameObject.FindGameObjectWithTag("DropUI").GetComponent<DragDropItem>();
		PageA = true;
		savebox = GameObject.Find("UI1000_Title_1_Icon_BackGround").GetComponent<SaveBox>();
		print(savebox.size);
		StartCoroutine(WaitSaveBoxGameObjectCreate());
	}
Exemplo n.º 12
0
	public  void pickup(){
		int index = Random.Range(0,names.Length);
		print(index);
		string name = names[index];
		bool isfind = false;
		for(int i = 0 ; i<SaveBoxGameObject.Length;i++)
		{
			if(SaveBoxGameObject[i].transform.childCount>0)//判斷目前格子有無物品
			{
				//有的話 判斷目前物品名字
				items = SaveBoxGameObject[i].GetComponentInChildren<DragDropItem>();
				print(items.name);
				if(items.transform.FindChild("UI1000_Pic_Icon").GetComponent<UISprite>().spriteName == name)
				{
					isfind = true;
					items.addcount(1);
					break;
				}
			}
		}
		if(isfind == false)
		{
			for(int i = 0 ; i<SaveBoxGameObject.Length; i++)
			{
				if(SaveBoxGameObject[i].transform.childCount == 0)
				{
					GameObject go = NGUITools.AddChild(SaveBoxGameObject[i],item);
					go.transform.FindChild("UI1000_Pic_Icon").GetComponent<UISprite>().spriteName = name;
					go.transform.rotation = Quaternion.Euler(0,0,-45);
					go.transform.localPosition = Vector3.zero;
					if(name == "UI_1000_Type_Summoner")
					{
						go.transform.FindChild("UI1000_Pic_Icon").GetComponent<UISprite>().color = new Color(255/255f,236/255f,92/255f,255/255f);						
					}
					else if(name == "UI_1000_Type_Hero")
					{
						go.transform.FindChild("UI1000_Pic_Icon").GetComponent<UISprite>().color = new Color(255/255f,236/255f,92/255f,255/255f);
					}
					else if(name == "UI_1000_Type_Worrior")
					{
						go.transform.FindChild("UI1000_Pic_Icon").GetComponent<UISprite>().color = new Color(83/255f,232/255f,255/255f,255/255f);
					}
					else if(name == "UI_1000_Type_Pastor")
					{
						go.transform.FindChild("UI1000_Pic_Icon").GetComponent<UISprite>().color = new Color(87/255f,240/255f,85/255f,255/255f);
					}
					else if(name == "UI_1000_Type_Knight")
					{
						go.transform.FindChild("UI1000_Pic_Icon").GetComponent<UISprite>().color = new Color(255/255f,239/255f,156/255f,255/255f);
					}
					else if(name == "UI_1000_Type_Assassin")
					{
						go.transform.FindChild("UI1000_Pic_Icon").GetComponent<UISprite>().color = new Color(255/255f,195/255f,53/255f,255/255f);
					}
					else if(name == "UI_1000_Type_Archer")
					{
						go.transform.FindChild("UI1000_Pic_Icon").GetComponent<UISprite>().color = new Color(255/255f,255/255f,10/255f,255/255f);
					}
					else if(name == "UI_1000_Type_Soldier")
					{
						go.transform.FindChild("UI1000_Pic_Icon").GetComponent<UISprite>().color = new Color(187/255f,255/255f,69/255f,255/255f);
					}
					break;
				}
			}
		}
	}
Exemplo n.º 13
0
 private void Initialize()
 {
     m_Entity       = new GameObject();
     m_DragDropItem = m_Entity.AddComponent <DragDropItem>() as DragDropItem;
     m_Entity.layer = WinterConst.UILAYER;
 }
Exemplo n.º 14
0
 // Use this for initialization
 void Awake()
 {
     label = transform.Find("Label").GetComponent<UILabel>();
     dragBehavior = GetComponent<DragDropItem>();
 }