Ejemplo n.º 1
0
    /// <summary>
    /// 向特定快捷栏中添加一个快捷技能
    /// </summary>
    /// <param name="id">技能id</param>
    /// <param name="surface">快捷栏对象</param>
    public void SetOneGridShotSkillByIdAndName(int id, GameObject surface)
    {
        ShotCutGrid findGrid = null;

        if (surface.tag == "ShotCutGrid")
        {
            findGrid = surface.GetComponent <ShotCutGrid>();
        }
        else
        {
            findGrid = surface.GetComponentInParent <ShotCutGrid>();
        }
        Debug.Log(findGrid.name);
        //如果该快捷栏中已经有技能了(先移除技能)
        if (findGrid.id != 0)
        {
            findGrid.UnloadThisGridShotCut();
            Debug.Log("除");
        }
        Debug.Log("添");
        GameObject createNewSkill = NGUITools.AddChild(findGrid.gameObject, newSkill);

        createNewSkill.GetComponent <UISprite>().depth = 1;
        findGrid.SetThisGridShotCutById(id);
    }
Ejemplo n.º 2
0
    /// <summary>
    /// 拖拽结束后的处理
    /// </summary>
    /// <param name="oldTransform">被拖拽物品原所在的格子</param>
    /// <param name="enterTransform">被拖拽物品现所在的格子</param>
    private void BagItemGrid_OnLeftEndDrag(Transform oldTransform, Transform enterTransform)
    {
        if (isDrag == true)
        {
            isDrag = false;

            dragItem.Hide();
            if (enterTransform == null)  //将物品扔出背包
            {
                Destroy(oldTransform.GetChild(1).gameObject);
                BagItemGrid bagItemGrid = oldTransform.gameObject.GetComponent <BagItemGrid>();
                bagItemGrid.Clear();
            }
            else if (enterTransform.tag == Tags.grid)
            {
                BagItemGrid bagItemGrid = oldTransform.gameObject.GetComponent <BagItemGrid>();
                BagItemGrid enterGrid   = enterTransform.gameObject.GetComponent <BagItemGrid>();
                if (enterTransform.childCount == 1) //将物品拖到一个新的地方
                {
                    GameObject itemGo = Instantiate(bagItem, enterTransform);
                    itemGo.transform.localPosition = Vector3.zero;
                    enterGrid.SetByID(bagItemGrid.id, bagItemGrid.count);
                    Destroy(oldTransform.GetChild(1).gameObject);
                    bagItemGrid.Clear();
                }
                else //物品位置交换
                {
                    int oldID    = bagItemGrid.id;
                    int oldCount = bagItemGrid.count;
                    oldTransform.GetChild(1).gameObject.GetComponent <Image>().enabled = true;
                    bagItemGrid.SetByID(enterGrid.id, enterGrid.count);

                    enterGrid.SetByID(oldID, oldCount);
                }
            }
            else if (enterTransform.tag == Tags.shotCutGrid)
            {
                ShotCutGrid shotCutGrid = enterTransform.GetComponent <ShotCutGrid>();
                BagItemGrid bagItemGrid = oldTransform.GetComponent <BagItemGrid>();
                if (bagItemGrid.info.type == objectType.Drug)
                {
                    shotCutGrid.id = bagItemGrid.id;
                    oldTransform.GetChild(1).gameObject.GetComponent <Image>().enabled = true;
                    Image      image = shotCutGrid.transform.FindChild("Image").GetComponent <Image>();
                    ObjectInfo info  = ObjectsInfo._instance.GetObjectInfoById(shotCutGrid.id);
                    image.gameObject.SetActive(true);
                    string path = "Icon/" + info.name_Icon;
                    image.sprite = Resources.Load(path, typeof(Sprite)) as Sprite;
                }
            }
            else //拖到了背包的其他地方,位置复原
            {
                oldTransform.GetChild(1).gameObject.GetComponent <Image>().enabled = true;
            }
        }
    }