Exemplo n.º 1
0
    void Start()
    {
        KeepData saveData = SaveData._Sav.GetSaveData();
        Itemsave s        = GameObject.FindObjectOfType <Itemsave> ();

        Debug.Log(saveData._Slidery);
        for (int q = 0; q < saveData._HaveItemOn.Count; q++)
        {
            GameObject dj = GameObject.Instantiate(btn);
            dj.transform.SetParent(_DJL);
            dj.GetComponent <Button> ().image.sprite = s._item [saveData._HaveItemOn[q]];
            dj.transform.GetComponent <RectTransform> ().anchoredPosition = new Vector2(45 + 85 * q, 44);
            _dj.Add(dj);
        }


        for (int t = 0; t < saveData._IsUclockItem.Count; t++)
        {
            if (saveData._IsUclockItem[t] == true)
            {
                _dj [t].GetComponent <Button> ().image.sprite = null;
                _dj [t].GetComponent <Button> ().image.color  = new Color(0, 0, 0, 0);
                //saveData._HaveItemOn [t] = 10;
                _dj[t].transform.SetParent(_DJ);
            }
        }

        for (int q = 0; q < saveData._HaveItemOn.Count; q++)
        {
            if (saveData._HaveItemOn [q] < 10)
            {
                _dj [q].GetComponent <Button> ().image.sprite = s._item [saveData._HaveItemOn [q]];
                _dj [q].GetComponent <Button> ().image.color  = new Color(1, 1, 1, 1);
            }
        }

        _itemPic = new List <Pic> (saveData._HaveItemId.Count);
        for (int i = 0; i < saveData._HaveItemId.Count; i++)
        {
            Pic item = GameObject.Instantiate(_itemPrefab);
            item._Id = saveData._HaveItemId [i];

            //更新技能点
            Gx(item);
            item.GetComponentInChildren <Text> ().text = saveData._HaveItemName [saveData._HaveItemId [i]];
            item.Shuoming.text = "" + item._shuoming [saveData._HaveItemId [i]];
            item.pic.sprite    = item._pic [saveData._HaveItemId[i]];
            item.transform.SetParent(_canvas);
            x = -196 * (Mathf.Pow(-1, (i % colunm_count)));
            saveData._Slidery = 118 - 195 * (i / colunm_count);
            SaveData._Sav.SaveGameData();
            item.transform.GetComponent <RectTransform> ().anchoredPosition = new Vector2(x, saveData._Slidery);
            //已解锁道具个数大于可装备道具个数
            item._Use.onClick.AddListener(delegate() {
                //道具装备个数小于道具解锁个数
                if (saveData._Djnum < saveData._IsUclockItemNum)
                {
                    if (item._Id < 10)
                    {
                        Click(item._Id, item);

                        saveData._Djnum++;
                        SaveData._Sav.SaveGameData();
                    }
                }
            });

            // 把道具图片加入列表
            _itemPic.Add(item);


            for (int t = 0; t < item._Skill.Count; t++)
            {
                SkillJs(t, item, item._Id);
            }
        }
        for (int k = 0; k < _dj.Count; k++)
        {
            int index = k;
            if (saveData._IsUclockItem [k] == true)
            {
                _dj [k].GetComponent <Button> ().onClick.AddListener(delegate() {
                    if (saveData._Djnum > 0)
                    {
                        DropItem(index);
                    }
                });
            }
        }
        for (int k = 0; k < saveData._HaveItemOn.Count; k++)
        {
            int index = k;
            if (saveData._IsUclockItem [k] == true)
            {
                _dj[k].GetComponent <Button>().onClick.AddListener(delegate() {
                    if (saveData._Djnum > 0)
                    {
                        DropItem(index);
                    }
                });
            }

            // 装备栏为空处理
            if (saveData._HaveItemOn [k] == -1 && saveData._IsUclockItem[k] == true)
            {
                _dj[k].GetComponent <Button>().image.sprite = null;
            }
            // 有装备处理
            for (int j = 0; j < 10; j++)
            {
                if (saveData._HaveItemOn [k] == j)
                {
                    _dj[k].GetComponent <Button>().image.sprite = s._item [j];
                }
            }
        }
    }
Exemplo n.º 2
0
    /// <summary>
    /// 卸下该栏装备
    /// </summary>
    /// <param name="i">The index.</param>
    void DropItem(int i)
    {
        // 卸下空道具,退出
        if (_dj [i].GetComponent <Button>().image.sprite == null)
        {
            return;
        }

        KeepData saveData = SaveData._Sav.GetSaveData();

        // 卸下道具,图片为空
        //if (saveData._HaveItemOn [i] != 10 && saveData._IsUclockItem [i] == true) {
        saveData._HaveItemId.Add(saveData._HaveItemOn [i]);
        saveData._ItemId.Remove(saveData._HaveItemOn [i]);
        saveData._HaveItemOn.Remove(i);
        SaveData._Sav.SaveGameData();

        _dj [i].GetComponent <Button> ().image.sprite = null;
        _dj [i].SetActive(false);
        //Destroy (_dj [i]);
        saveData._Djnum--;
        SaveData._Sav.SaveGameData();
        //}
        // 更新道具栏
        int z    = saveData._HaveItemId.Count - 1;
        Pic item = GameObject.Instantiate(_itemPrefab);

        item._Id = saveData._HaveItemId [z];
        //更新技能点
        Gx(item);
        item.GetComponentInChildren <Text> ().text = saveData._HaveItemName [saveData._HaveItemId [z]];
        item.Shuoming.text = "" + item._shuoming [saveData._HaveItemId [i]];
        item.pic.sprite    = item._pic [saveData._HaveItemId[i]];
        item.transform.SetParent(_canvas);
        x = -196 * (Mathf.Pow(-1, (z % colunm_count)));
        saveData._Slidery = 118 - 195 * (z / colunm_count);
        SaveData._Sav.SaveGameData();
        item.transform.GetComponent <RectTransform> ().anchoredPosition = new Vector2(x, saveData._Slidery);
        item._Use.onClick.AddListener(delegate() {
            //道具装备个数小于道具解锁个数
            if (saveData._Djnum < saveData._IsUclockItemNum)
            {
                if (item._Id < 10)
                {
                    Click2(item._Id, item);

                    saveData._Djnum++;
                    SaveData._Sav.SaveGameData();
                }
            }
        });
        // 把道具图片加入列表
        _itemPic.Add(item);


        for (int t = 0; t < item._Skill.Count; t++)
        {
            SkillJs(t, item, item._Id);
        }

        GameObject dj = GameObject.Instantiate(btn);

        dj.transform.SetParent(_DJ);
        dj.GetComponent <Button> ().image.sprite = null;
        dj.GetComponent <Button> ().image.color  = new Color(0, 0, 0, 0);
        dj.transform.GetComponent <RectTransform> ().anchoredPosition = new Vector2(75 + 150 * saveData._Djnum, -50);
        _dj.Add(dj);
        _dj.Reverse();
    }