//init
    public void Init()
    {
        // this.onChange = OnTest;
        this.ScrollItems.Clear();
        for (int i = 0; i < this.transform.childCount; i++)
        {
            GameObject go = this.transform.GetChild(i).gameObject;
            this.ScrollItems.Add(go);
            if (onChange != null)
            {
                onChange(go, i);
            }
            if (i >= this.Total)
            {
                go.SetActive(false);
            }
        }

        this.Grid = this.gameObject.GetComponent <UI_ListGrid>();
        this.Grid.Refresh();
        this.ItemCost = Grid.IntervalLine;
        this.ItemNum  = this.ScrollItems.Count / Grid.LineMaxCount;
        if (this.ScrollItems.Count % Grid.LineMaxCount > 0)
        {
            Debug.LogError("The Scroll item number must be the multiple of the grid line max count");
            ItemNum++;
        }
        this.MaxIndex = this.Total / Grid.LineMaxCount;
        if (this.Total % this.Grid.LineMaxCount > 0)
        {
            this.MaxIndex++;
        }
        this.MaxIndex -= this.ItemNum;
        for (int i = 0; i < this.ScrollItems.Count; i++)
        {
            GameObject go = this.ScrollItems[i];
            AddDragEvent(go);
        }
        if (this.mBackground != null)
        {
            AddDragEvent(this.mBackground);
        }
        this.MaxFixPos     = 0;
        this.MinFixPos     = (this.ItemNum - 1) * ItemCost * -1;
        this.RepositionMax = this.MaxFixPos + this.ItemCost;
        this.RepositionMin = this.MinFixPos - this.ItemCost;
        this.MaxPos        = this.MinFixPos + this.ItemCost * (this.ItemNum - 1);
        this.MinPos        = this.MaxFixPos - this.ItemCost * (this.ItemNum - 1);

        this.m_fMove_rate     = 1f;
        this.m_iNowIndex      = 0;
        this.m_fMove_speed    = 0f;
        this.m_iMoveDir       = 1;
        this.m_fMoveStartTime = 0;
        this.m_bDrag          = false;
        this.m_bFixPos        = false;
        this.m_cFixObj        = null;
        this.m_fFixSpeed      = 0;
    }
示例#2
0
    public override void OnInspectorGUI()
    {
        UI_ListGrid grid = target as UI_ListGrid;

        grid.LineMaxCount = EditorGUILayout.IntField("Line Max Count", grid.LineMaxCount);
        grid.IntervalItem = EditorGUILayout.IntField("Interval Item", grid.IntervalItem);
        grid.IntervalLine = EditorGUILayout.IntField("Interval Line", grid.IntervalLine);
        grid.Dir          = (UI_ListGrid.DIR)EditorGUILayout.EnumPopup("Direction", grid.Dir);

        if (GUILayout.Button("Refresh"))
        {
            grid.Refresh();
        }
    }