Пример #1
0
        internal DisplayObject AddChildAt(DisplayObject child, int index)
        {
            int count = this._children.Count;

            index = Mathf.Clamp(index, 0, count);

            if (child.parent == this)
            {
                this.SetChildIndex(child, index);
            }
            else
            {
                child.RemoveFromParent();
                child.SetParent(this);
                child.siblingIndex = index;

                this._children.Add(child);
                this._children.Sort(CompareSiblingIndex);

                if (this.stage != null)                  //可能父对象还没有添加到舞台哦
                {
                    child.HandleAddToStage();
                }
            }
            return(child);
        }
Пример #2
0
        internal DisplayObject RemoveChildAt(int index, bool dispose = false)
        {
            if (index < 0 || index >= this._children.Count)
            {
                return(null);
            }
            DisplayObject child = this._children[index];

            if (this.stage != null)
            {
                child.HandleRemoveFromStage();
            }

            this._children.Remove(child);

            if (!dispose)
            {
                child.SetParent(null);
            }
            else
            {
                child.Dispose();
            }

            return(child);
        }