Ejemplo n.º 1
0
    public void loadItems()
    {
        // start setting the beginning position of the objects and the width of them
        xWeapon  = 0.85f;                                                                   // position X that the weapon will instantiate
        xClothes = 0.85f;                                                                   // position X that the clothe will instantiate
        wWeapon  = (prefabWeaponItem.GetMaxBounds() - prefabWeaponItem.GetMinBounds()).x;   // width of the weapon object
        wClothes = (prefabClothesItem.GetMaxBounds() - prefabClothesItem.GetMinBounds()).x; // width of the clothe object

        // add default items
        foreach (Item defaultItem in StaticItemsList.getDefault())
        {
            addItem(defaultItem);
        }

        // check if has objects saved
        if (SaveSystem.hasObject("CloakRoom_List"))
        {
            // if yes, then gets them
            ArrayList _itemsList = (ArrayList)SaveSystem.load("CloakRoom_List", typeof(ArrayList));

            // pass through list and add which item
            foreach (Item item in _itemsList)
            {
                addItem(item);
            }
        }

        // add the empty object in the final
        this.addLastWeapon();
        this.addLastClothes();

        // the ContentLength receive the length of list
        scrollableWeaponArea.ContentLength  = xWeapon;
        scrollableClothesArea.ContentLength = xClothes;
    }
Ejemplo n.º 2
0
    public void loadStoreItems()
    {
        // get items list to buy
        ArrayList _staticItemsList = StaticItemsList.get();

        // used to load the items list bought
        ArrayList _cloakRoomList = new ArrayList();

        // check if there are objects
        if (SaveSystem.hasObject("CloakRoom_List"))
        {
            // if there are, load them
            _cloakRoomList = (ArrayList)SaveSystem.load("CloakRoom_List", typeof(ArrayList));
        }

        float _y = 0.0f;                                                      // position Y that the item will instantiate
        float _h = (prefabItem.GetMaxBounds() - prefabItem.GetMinBounds()).y; // height of the item object

        // pass every item of list
        foreach (Item item in _staticItemsList)
        {
            // it compares if this item was already bought
            if (!compareList(_cloakRoomList, item))
            {
                // instantiates the prefabItem
                tk2dUILayout _layout = Instantiate(prefabItem) as tk2dUILayout;

                // changes the parent
                _layout.transform.parent = scrollableArea.contentContainer.transform;

                // and changes the position
                _layout.transform.localPosition = new Vector3(0, _y, 0);

                // fills the store item informations
                _layout.gameObject.AddComponent <StoreItem>().init(item);

                // add and get the tk2dUIItem Component to set some informations
                tk2dUIItem _uiItem = _layout.transform.FindChild("BlackSquare").FindChild("BuyButton").gameObject.AddComponent <tk2dUIItem>();

                // set message target
                _uiItem.sendMessageTarget = _layout.gameObject;

                // set the method that will call
                _uiItem.SendMessageOnClickMethodName = "buyItem";

                // set this informations
                _uiItem.InternalSetIsChildOfAnotherUIItem(true);
                _uiItem.isHoverEnabled = true;

                // sum the position with the heigth to other item
                _y -= _h;
            }
        }

        // the ContentLength receive the heigth of list
        scrollableArea.ContentLength = Mathf.Abs(_y);
    }