Esempio n. 1
0
        /// <summary>
        /// Builds a PLib UI object and adds it to an existing UI object.
        /// </summary>
        /// <param name="component">The UI object to add.</param>
        /// <param name="parent">The parent of the new object.</param>
        /// <param name="index">The sibling index to insert the element at, if provided.</param>
        /// <returns>The built version of the UI object.</returns>
        public static GameObject AddTo(this IUIComponent component, GameObject parent,
                                       int index = -2)
        {
            if (component == null)
            {
                throw new ArgumentNullException(nameof(component));
            }
            if (parent == null)
            {
                throw new ArgumentNullException(nameof(parent));
            }
            var child = component.Build();

            child.SetParent(parent);
            if (index == -1)
            {
                child.transform.SetAsLastSibling();
            }
            else if (index >= 0)
            {
                child.transform.SetSiblingIndex(index);
            }
            return(child);
        }