FairyGUI.GComponent.AddChildAt C# (CSharp) Method

AddChildAt() public method

Adds a child to the component at a certain index.
public AddChildAt ( GObject child, int index ) : GObject
child GObject A child object
index int Index
return GObject
        public virtual GObject AddChildAt(GObject child, int index)
        {
            int numChildren = _children.Count;

            if (index >= 0 && index <= numChildren)
            {
                if (child.parent == this)
                {
                    SetChildIndex(child, index);
                }
                else
                {
                    child.RemoveFromParent();
                    child.InternalSetParent(this);

                    int cnt = _children.Count;
                    if (child.sortingOrder != 0)
                    {
                        _sortingChildCount++;
                        index = GetInsertPosForSortingChild(child);
                    }
                    else if (_sortingChildCount > 0)
                    {
                        if (index > (cnt - _sortingChildCount))
                            index = cnt - _sortingChildCount;
                    }

                    if (index == cnt)
                        _children.Add(child);
                    else
                        _children.Insert(index, child);

                    ChildStateChanged(child);
                    SetBoundsChangedFlag();
                }
                return child;
            }
            else
            {
                throw new Exception("Invalid child index: " + index + ">" + numChildren);
            }
        }

Usage Example

 static int AddChildAt(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);
         FairyGUI.GObject o = obj.AddChildAt(arg0, arg1);
         ToLua.PushObject(L, o);
         return(1);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
All Usage Examples Of FairyGUI.GComponent::AddChildAt