void Update()
    {
        if (_destroyed)
        {
            return;
        }
        if (_nrOfItems == 0)
        {
            RKLog.LogError("INFINITESCROLLER2 HEEFT GEEN DATA", "infinitescroller");
        }
        if (lastCount == 0 && _nrOfItems > 0)
        {
            Rebuild();
        }

        if (started)
        {
            fill();
        }

        if (_nrOfItems != 0)
        {
            lastCount = _nrOfItems;
        }
    }
Beispiel #2
0
    private void ParseReturn <T>(HTTPRequest originalRequest, HTTPResponse response, SendTypes type, Action <ReturnTypes, T, int> action)
    {
        if (response == null)
        {
            RKLog.LogError("Parsereturn, response null ", "apicontroller");
            action(ReturnTypes.ERROR, (T)(object)null, 1);
            return;
        }

        GenericData       returnResponse = new GenericData();
        SendValueResponse res;
        int returnerror;

        //Debug.Log("parsereturn 2!");
        //        Debug.LogError("dit is iets ervoor");
        //        Debug.LogError(response.DataAsText);



        ReturnTypes returntype;

        switch (type)
        {
        default:
            RKLog.Log("response: " + response.DataAsText);

            res = JsonUtility.FromJson <SendValueResponse>(response.DataAsText);
            foreach (ResponseStringList val in res.strings)
            {
                Debug.Log("set3: " + val.key + " to " + val.value);
                returnResponse.Set(val.key, val.value);
            }

            foreach (ResponseIntList val in res.ints)
            {
                returnResponse.Set(val.key, val.value);
            }

            returntype  = ReturnTypes.ERROR;
            returnerror = -1;

            if (res.success)
            {
                returntype = ReturnTypes.SUCCESS;
            }

            RKLog.Log("returntype: " + returntype + " returnresponse: " + returnResponse + " res error: " + res.error);
            action(returntype, (T)(object)returnResponse, res.error);


            break;
        }
    }
 public void SetKey(int key)
 {
     RKLog.LogError("Set Key " + key, "infinitescroller");
     Rebuild(key);
 }
    private void build(string dir, float current, float offset, float totalvalue)
    {
        //Debug.LogError("hallo! "+ _width + "x"+_height);

        //RKLog.LogError("build" + dir, " current " + current);

        bool broken = false;

        int nextkey = this._maxkey + 1;

        if (dir == "up")
        {
            nextkey = this._minkey - 1;
        }

        if (nextkey < 0 && _nrOfItems != -1 || ((nextkey > (_nrOfItems - 1)) && _nrOfItems != -1))
        {
            // RKLog.LogError("INFINITESCROLLER BREAK0 " + this.gameObject.name, "infinitescroller");
            return;
        }

        //Debug.LogError("build "+dir);

        int counter = 0;

        while (CheckCanRenderNext(dir, current, offset, totalvalue, broken))
        {
            if ((nextkey < 0 && _nrOfItems != -1) || ((nextkey > (_nrOfItems - 1)) && _nrOfItems != -1))
            {
                RKLog.LogError("INFINITESCROLLER BREAK1 " + this.gameObject.name, "infinitescroller");
                break;
            }



            //       RKLog.LogError("ja, render next " + current + "dir: " + dir + " nrofitems: "+ this._nrOfItems+ " : "+ this.gameObject.name + " nextkey: "+ nextkey + " >= "+ ( _nrOfItems - 1 ), "infinitescroller");


            if (_nrOfItems == 0)
            {
                RKLog.LogError("INFINITESCROLLER2 HEEFT GEEN DATA " + this.gameObject.name, "infinitescroller");
                break;
            }



            GameObject ob = _objectPool.getObject();
            if (!ob)
            {
                RKLog.LogError("INFINITESCROLLER BREAK2 " + this.gameObject.name, "infinitescroller");
                broken = true;
                break;
            }

            if (dir == "up")
            {
                //Debug.LogError("got ob ");
            }


            //IInfiniteScrollPrefab obinterface = ob.GetInterface<IInfiniteScrollPrefab>();

            //obinterface.setData<IInfiniteScrollPrefab>(_data);
            //obinterface.setKey(nextkey);
            // obinterface.SetKey(nextkey);
            ob.name = nextkey.ToString();
            //RKLog.LogError("Get nextkey " + nextkey + " length "+_nrOfItems, "infinitescroller");
            if (nextkey <= _nrOfItems || _nrOfItems == -1)
            {
                _callback(nextkey, ob);
            }

            float size = ob.GetComponent <RectTransform>().sizeDelta.y;

            if (direction == directions.Horizontal)
            {
                size = ob.GetComponent <RectTransform>().sizeDelta.x;
                float add = 0;
                if (dir == "up")
                {
                    add = size;
                }
                ob.absolutePosition(new Vector2(current - add, 0));
            }
            else
            {
                float add = 0;
                if (dir == "up")
                {
                    add = size;
                }
//                Debug.LogError("add pixels " + size + " dir = "+dir+ " nextkey = " + nextkey + "current:  " + current +" add: "+ add + " height: "+_height);


                ob.absolutePosition(new Vector2(0, current + add));

                //Debug.LogError("place on " + ob.x() + " - " + ob.y());
                //Debug.LogError("place on "+(current + add));
            }

            //Debug.Log("check outeritem "+nextkey + " = "+ outerItem(nextkey));

            if (outerItem(nextkey))
            {
                if (nextkey == 0)
                {
                    if (direction == directions.Horizontal)
                    {
                        _scroller.maxX = 0;
                        if (_nrOfItems == 1)
                        {
                            _scroller.minX = 0;
                        }
                    }
                    else
                    {
                        _scroller.minY = 0 - ob.y() + _startpos;
                        if (_nrOfItems == 1)
                        {
                            if (buildDirection == builddirections.Backwards)
                            {
                                _scroller.maxY = (0 - ob.y() - _height) + size + _spacing;
                                _scroller.minY = _scroller.maxY;
                            }
                            else
                            {
                                _scroller.maxY = _scroller.minY;
                            }
                        }
                    }
                }
                else
                {
                    if (direction == directions.Horizontal)
                    {
                        //Debug.LogError(ob.x());
                        _scroller.minX = (0 - ob.x() + _width) - size - _spacing;
                    }
                    else
                    {
                        //_scroller.maxY = (0-ob.y()-_height)+size+_spacing;
                        //float newheight = _height;

                        float scrollDistance = ((0 - ob.y()) + size + _spacing);
                        float dis            = scrollDistance - _height;
                        RKLog.Log("maxy = " + scrollDistance + " height " + _height + " dis " + dis);
                        if (dis < 0)
                        {
                            dis = 0;
                        }



                        _scroller.maxY = dis;



                        RKLog.LogError("setting maxy, item " + nextkey + " maxy:" + _scroller.maxY + " oby: " + ob.y() + ", obj height " + size + " height: " + _height + " size: " + size + " spacing: " + _spacing + "");
                        //RKLog.LogError("maxy "+_scroller.GetComponent<RectTransform>().rect.height + " size: "+size + " spacing: "+ _spacing);
                    }
                }

                if (_scroller.minX > _scroller.maxX)
                {
                    _scroller.minX = _scroller.maxX;
                }
            }

            if (_scroller.minY > _scroller.maxY)
            {
                if (buildDirection == builddirections.Backwards)
                {
                    _scroller.minY = _scroller.maxY;
                }
                else
                {
                    _scroller.maxY = _scroller.minY;
                }
            }



//            Debug.LogError("SET SCROLLER "+ _scroller.minY +"x" +_scroller.maxY);


            counter++;



            if ((direction == directions.Horizontal && dir == "down") || direction == directions.Vertical && dir == "up")
            {
                current = current + size + _spacing;
            }
            if ((direction == directions.Horizontal && dir == "up") || direction == directions.Vertical && dir == "down")
            {
                current = current - size - _spacing;
            }

            if (dir == "down")
            {
//                RKLog.LogError("nextkey down" + nextkey, "infinitescroller");
                nextkey++;
            }
            else if (dir == "up")
            {
//                RKLog.LogError("nextkey up" +nextkey, "infinitescroller");
                nextkey--;
            }


            ///}
        }


        var currentpos = 0;
    }