Ejemplo n.º 1
0
        //根据数据,生成storeItem,加入对应的grid
        private void SetGrid <T>(Transform gridTr, Dictionary <int, T> list) where T : BaseObject
        {
            if (typeof(T) != typeof(Elixir))
            {
                for (int i = 0; i < gridTr.childCount; i++)
                {
                    GameObject go = gridTr.GetChild(i).gameObject;
                    if (go != null)
                    {
                        GameObject.Destroy(go);
                    }
                }
            }

            foreach (T t in list.Values)
            {
                GameObject go   = GameObject.Instantiate(ItemPrefab.UnityObj) as GameObject;
                storeItem  item = go.AddComponent <storeItem>();
                item.SetData(t);

                go.transform.SetParent(gridTr);
                go.transform.localScale = new Vector3(1, 1, 1);
            }
        }
Ejemplo n.º 2
0
        //精油初级高级分类
        private void SetOilGrid(Transform OilGrid_Primary, Transform OilGrid_Semi, Transform OilGrid_Senior, Dictionary <int, Oil> list, Dictionary <int, Formula> fs)
        {
            //清空格子
            for (int i = 0; i < OilGrid_Primary.childCount; i++)
            {
                GameObject go = OilGrid_Primary.GetChild(i).gameObject;
                if (go != null)
                {
                    GameObject.Destroy(go);
                }
            }

            for (int i = 0; i < OilGrid_Semi.childCount; i++)
            {
                GameObject go = OilGrid_Semi.GetChild(i).gameObject;
                if (go != null)
                {
                    GameObject.Destroy(go);
                }
            }

            for (int i = 0; i < OilGrid_Senior.childCount; i++)
            {
                GameObject go = OilGrid_Senior.GetChild(i).gameObject;
                if (go != null)
                {
                    GameObject.Destroy(go);
                }
            }

            //分类放入格子
            foreach (Oil t in list.Values)
            {
                GameObject go   = GameObject.Instantiate(ItemPrefab.UnityObj) as GameObject;
                storeItem  item = go.AddComponent <storeItem>();

                item.SetData(t);
                if (t.OilType == 1)
                {
                    go.transform.SetParent(OilGrid_Primary);
                }
                else if (t.OilType == 2)
                {
                    go.transform.SetParent(OilGrid_Semi);
                }
                else if (t.OilType == 3)
                {
                    go.transform.SetParent(OilGrid_Senior);
                }
                go.transform.localScale = new Vector3(1, 1, 1);
            }

            //将神秘配方放入背包高级精油格子
            foreach (Formula f in fs.Values)
            {
                GameObject go   = GameObject.Instantiate(ItemPrefab.UnityObj) as GameObject;
                storeItem  item = go.AddComponent <storeItem>();
                item.SetData(f);
                go.transform.SetParent(OilGrid_Senior);
                go.transform.localScale = new Vector3(1, 1, 1);
            }
        }