Example #1
0
    public void SwapItems(DragWeapon item1, DragWeapon item2)
    {
        /*   if ((item1.name == "") || (item1.name == null))
         * {
         *     item1.name = item2.name;
         *     //it
         *     item1.ammoNum = item2.ammoNum;
         *     item1.SetWeapon(item1.name);
         *     item2.name = "";
         *     item2.ammoNum = 0;
         *     item2.maxNum = 0;
         *     SaveWeaponInfo(item1.slot, item1.weaponName, item1.ammoNum);
         *     item2.Init();
         * }
         */



        int    tNum;
        string tName;
        string tNom;

        tName = item2.weaponName;
        tNum  = item2.ammoNum;
        tNom  = item2.name;

        SaveWeaponInfo(item1.slot, tName, tNum);
        SaveWeaponInfo(item2.slot, item1.weaponName, item1.ammoNum);

        item2.weaponName = item1.weaponName;
        item2.SetWeapon(item1.weaponName);
        item2.ammoNum = item1.ammoNum;


        item1.weaponName = tName;
        item1.SetWeapon(tName);
        item1.ammoNum = tNum;
    }
Example #2
0
    public void OnPointerUp(PointerEventData data)
    {
        if (weapon)
        {
            weapon.transform.localPosition = new Vector3(0, 0, weapon.transform.localPosition.z);

            if (selling)
            {
                PointerEventData pe = new PointerEventData(EventSystem.current);
                pe.position = Input.mousePosition;
                List <RaycastResult> hits = new List <RaycastResult>();
                EventSystem.current.RaycastAll(pe, hits);

                foreach (RaycastResult h in hits)
                {
                    GameObject g       = h.gameObject;
                    DragWeapon wepSlot = g.GetComponent <DragWeapon>();
                    if (wepSlot != null)
                    {
                        if (!wepSlot.selling)
                        {
                            if (wepSlot.weapon != null)
                            {
                                if (MenuGlobal.instance.SellItem(slot, weaponPrice, weaponName))
                                {
                                    Destroy(weapon);
                                    weaponPrice       = 0;
                                    weaponName        = "";
                                    weaponTitle       = "";
                                    weaponDescription = "";
                                }
                            }
                            if (MenuGlobal.instance.BuyItem(wepSlot.slot, weaponPrice, weaponName, ammoNum))
                            {
                                wepSlot.SetWeapon(weaponName);
                            }
                        }
                    }
                }
            }
            else
            {
                PointerEventData pe = new PointerEventData(EventSystem.current);
                pe.position = Input.mousePosition;
                List <RaycastResult> hits = new List <RaycastResult>();
                EventSystem.current.RaycastAll(pe, hits);

                foreach (RaycastResult h in hits)
                {
                    GameObject g = h.gameObject;
                    if (g == MenuGlobal.instance.sellPanel)
                    {
                        if (MenuGlobal.instance.SellItem(slot, weaponPrice, weaponName))
                        {
                            Destroy(weapon);
                            weaponPrice       = 0;
                            weaponName        = "";
                            weaponTitle       = "";
                            weaponDescription = "";
                            MenuGlobal.instance.SetDescriptionText("");
                        }
                    }
                    else if (g.GetComponent <DragWeapon>() != null)
                    {
                        //Debug.Log("swap");
                        DragWeapon wep = g.GetComponent <DragWeapon>();
                        if (!wep.selling)
                        {
                            MenuGlobal.instance.SwapItems(this, wep);
                        }
                    }
                }
            }
        }
    }