Ejemplo n.º 1
0
        /// <summary>
        /// Creates a Container widget to be used with the other widget factory methods.
        /// </summary>
        /// <param name="config"></param>
        /// <param name="slots"></param>
        /// <param name="parent">Optional, if specified, the new widget will become a child</param>
        /// <param name="siblingIndex">Optional, if parent is specified, the new widget will become a child with this index</param>
        /// <param name="parentSlots">Optional, if parent is specified, the new widget will become a child, acting like the parent has this many slots</param>
        /// <returns></returns>
        public GameObject GetContainerWidget(
            ContainerConfig config,
            int slots                    = 1,
            GameObject parent            = null,
            int siblingIndex             = -1,
            int parentSlots              = -1,
            ContainerConfig parentConfig = ContainerConfig.Submissive)
        {
            GameObject containerWidget = GameObject.Instantiate(optionWidgetPrefab);

            if (parent == null)
            {
                //We want to apply ContainerConfig (and thus height) if there is no parent
                ApplyContainerConfig(containerWidget, config);
            }
            else if (parent.GetComponent <LayoutGroup>() != null)
            {
                //We want to apply ContainerConfig (and thus height) if there is no there is a layout group in parent
                containerWidget.transform.SetParent(parent.transform, false);
                ApplyContainerConfig(containerWidget, config);
            }
            else
            {
                //We want to apply anchors and the like if there is a parent and it doesn't have a layout
                CoupleToParent(
                    widget: containerWidget,
                    parent: parent,
                    index: siblingIndex,
                    slots: parentSlots,
                    config: parentConfig);
            }

            WidgetFactoryContainerOrganizer container = containerWidget.GetComponent <WidgetFactoryContainerOrganizer>();

            //Store its values
            container.config = config;
            container.slots  = slots;

            return(containerWidget);
        }
Ejemplo n.º 2
0
        private static void CoupleToParent(
            GameObject widget,
            GameObject parent,
            int index,
            int slots,
            ContainerConfig config,
            ContainerConfig configSupplement = ContainerConfig.None)
        {
            if (parent != null)
            {
                widget.transform.SetParent(parent.transform, false);

                WidgetFactoryContainerOrganizer container = parent.GetComponent <WidgetFactoryContainerOrganizer>();
                if (container != null)
                {
                    //Pull down container's configuration
                    if (config == ContainerConfig.Submissive)
                    {
                        config = container.config;
                    }

                    //Pull down container's slots
                    if (slots == -1)
                    {
                        slots = container.slots;
                    }

                    if (index == -1)
                    {
                        index = container.childCount;
                    }

                    //Let it know we used one more of its slots
                    container.childCount++;
                }
            }

            //Set these values up to meaningful numbers if our parent doesn't have a WidgetFactoryContainerOrganizer
            if (slots == -1)
            {
                slots = 1;
            }

            if (index == -1)
            {
                index = 0;
            }

            if (configSupplement != ContainerConfig.None)
            {
                //Apply container config supplement
                //First by adding the masked values
                uint supplementMaskedValues  = (uint)(configSupplement & ContainerConfig.All_Addable_Masks);
                uint configMaskedValues      = (uint)(config & ContainerConfig.All_Addable_Masks);
                uint incrementedMaskedValues = (configMaskedValues + supplementMaskedValues) & (uint)ContainerConfig.All_Addable_Masks;
                config = (ContainerConfig)((uint)(config & ~ContainerConfig.All_Addable_Masks) | incrementedMaskedValues);

                //Now turn on flags that were set on in the supplement:
                config |= (configSupplement & ~ContainerConfig.All_Addable_Masks);
            }

            ApplyContainerConfigToWidget(widget, config, index, slots);
        }