Exemplo n.º 1
0
    protected override void OnLoad()
    {
        base.OnLoad();
        //load data from setting data
        BaseData_ItemTable.Instance.LoadDataFromSettingTable();

        //create some item data(from network server)
        CreateSomeItemData();


        foreach (int item in Enum.GetValues(typeof(ItemModule.EnumMainType)))
        {
            if (item == 0)
            {
                continue;
            }
            string typeName = Enum.GetName(typeof(ItemModule.EnumMainType), item);
            ItemModule.EnumMainType temp = (ItemModule.EnumMainType)Enum.Parse(typeof(ItemModule.EnumMainType), typeName);
            int num = UnityEngine.Random.Range(3, 5);
            //Debug.Log(num);
            for (int i = 0; i < num; i++)
            {
                ItemModule.ItemData itemModile = _itemData[UnityEngine.Random.Range(0, _itemData.Count)]._ItemData;
                //tableDic[temp][i] = itemModile;
                //tableDic[temp][i]._ItemData = MethodExtension.DeepClone(itemModile);
                tableDic[temp][i] = new ItemModule()
                {
                    _ItemData = MethodExtension.DeepClone(itemModile)
                };

                //Debug.Log(_listItem.Count);
            }
            //for (int i = num; i < tableDic[temp].Length - num; i++)
            //{
            //    tableDic[temp][i] = new ItemModule() { _ItemData = new ItemModule.ItemData() };
            //    Debug.Log(tableDic[temp][i]._ItemData == null);
            //}
        }
    }
Exemplo n.º 2
0
    public void AddImageNum(ItemModule.ItemData itemData, ItemModule.EnumMainType mainType, uint count = 1)
    {
        //Debug.Log(itemData);

        if (itemData.Num < 20)
        {
            itemData.Num += count;
        }
        else
        {
            for (int i = 0; i < tableDic[mainType].Length; i++)
            {
                //Debug.Log("==");
                if (tableDic[mainType][i] == null)
                {
                    continue;
                }
                else if (tableDic[mainType][i]._ItemData.Id == itemData.Id && tableDic[mainType][i]._ItemData.Num < 20)
                {
                    AddImageNum(tableDic[mainType][i]._ItemData, mainType);
                    return;
                }
            }
            for (int i = 0; i < tableDic[mainType].Length; i++)
            {
                //Debug.Log("addNull");
                if (tableDic[mainType][i] == null || tableDic[mainType][i]._ItemData.Num == 0)
                {
                    tableDic[mainType][i] = new ItemModule()
                    {
                        _ItemData = MethodExtension.DeepClone <ItemModule.ItemData>(itemData)
                    };
                    tableDic[mainType][i]._ItemData.Num = count;
                    return;
                }
            }
        }
    }