FairyGUI.GComponent.SetChildIndexBefore C# (CSharp) Method

SetChildIndexBefore() public method

Moves a child to a certain position which is in front of the child previously at given index. 与SetChildIndex不同的是,如果child原来在index的前面,那么child插入的位置是index-1,即保证排在原来占据index的对象的前面。
public SetChildIndexBefore ( GObject child, int index ) : int
child GObject
index int
return int
        public int SetChildIndexBefore(GObject child, int index)
        {
            int oldIndex = _children.IndexOf(child);
            if (oldIndex == -1)
                throw new ArgumentException("Not a child of this container");

            if (child.sortingOrder != 0) //no effect
                return oldIndex;

            int cnt = _children.Count;
            if (_sortingChildCount > 0)
            {
                if (index > (cnt - _sortingChildCount - 1))
                    index = cnt - _sortingChildCount - 1;
            }

            if (oldIndex < index)
                return _SetChildIndex(child, oldIndex, index - 1);
            else
                return _SetChildIndex(child, oldIndex, index);
        }

Usage Example

 static int SetChildIndexBefore(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 3);
         FairyGUI.GComponent obj  = (FairyGUI.GComponent)ToLua.CheckObject(L, 1, typeof(FairyGUI.GComponent));
         FairyGUI.GObject    arg0 = (FairyGUI.GObject)ToLua.CheckObject(L, 2, typeof(FairyGUI.GObject));
         int arg1 = (int)LuaDLL.luaL_checknumber(L, 3);
         int o    = obj.SetChildIndexBefore(arg0, arg1);
         LuaDLL.lua_pushinteger(L, o);
         return(1);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }