当前位置: 首页>>代码示例>>C#>>正文


C# UIButton.AddUIComponent方法代码示例

本文整理汇总了C#中UIButton.AddUIComponent方法的典型用法代码示例。如果您正苦于以下问题:C# UIButton.AddUIComponent方法的具体用法?C# UIButton.AddUIComponent怎么用?C# UIButton.AddUIComponent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在UIButton的用法示例。


在下文中一共展示了UIButton.AddUIComponent方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SetupControls

        private void SetupControls()
        {
            if (m_policyButton != null) return;

            isVisible = true;
            canFocus = true;
            isInteractive = true;
            backgroundSprite = "GenericPanel";
            size = new Vector2(364f, 44f);
            objectUserData = ToolsModifierControl.policiesPanel;

            m_policyButton = AddUIComponent<UIButton>();
            m_policyButton.name = "PolicyButton";
            m_policyButton.text = "Theme Name";
            m_policyButton.size = new Vector2(324f, 40f);
            m_policyButton.focusedBgSprite = "PolicyBarBackActive";
            m_policyButton.normalBgSprite = "PolicyBarBack";
            m_policyButton.relativePosition = new Vector3(2f, 2f, 0f);
            m_policyButton.textPadding.left = 50;
            m_policyButton.textColor = new Color32(0, 0, 0, 255);
            m_policyButton.disabledTextColor = new Color32(0, 0, 0, 255);
            m_policyButton.hoveredTextColor = new Color32(0, 0, 0, 255);
            m_policyButton.pressedTextColor = new Color32(0, 0, 0, 255);
            m_policyButton.focusedTextColor = new Color32(0, 0, 0, 255);
            m_policyButton.disabledColor = new Color32(124, 124, 124, 255);
            m_policyButton.dropShadowColor = new Color32(103, 103, 103, 255);
            m_policyButton.dropShadowOffset = new Vector2(1f, 1f);
            m_policyButton.textHorizontalAlignment = UIHorizontalAlignment.Left;
            m_policyButton.useDropShadow = false;
            m_policyButton.textScale = 0.875f;

            // This helper component updates the checkbox state every game tick
            m_policyButton.gameObject.AddComponent<ThemePolicyContainer>();

            m_policyCheckBox = m_policyButton.AddUIComponent<UICheckBox>();
            m_policyCheckBox.name = "Checkbox";
            m_policyCheckBox.size = new Vector2(363f, 44f);
            m_policyCheckBox.relativePosition = new Vector3(0f, -2f, 0f);
            m_policyCheckBox.clipChildren = true;

            // Connect the checkbox with our theme manager
            m_policyCheckBox.eventCheckChanged += delegate(UIComponent component, bool isChecked)
            {
                lock (component)
                {
                    var districtId = ToolsModifierControl.policiesPanel.targetDistrict;
                    var districtThemes = BuildingThemesManager.instance.GetDistrictThemes(districtId, true);

                    if (isChecked == districtThemes.Contains(m_theme)) return;

                    if (isChecked)
                    {
                        BuildingThemesManager.instance.EnableTheme(districtId, m_theme);
                    }
                    else
                    {
                        BuildingThemesManager.instance.DisableTheme(districtId, m_theme);
                    }
                }

            };

            // Checkbox-related UI components
            m_sprite = m_policyCheckBox.AddUIComponent<UISprite>();
            m_sprite.name = "Unchecked";
            m_sprite.spriteName = "ToggleBase";
            m_sprite.size = new Vector2(16f, 16f);
            m_sprite.relativePosition = new Vector3(336.6984f, 14, 0f);

            m_policyCheckBox.checkedBoxObject = m_sprite.AddUIComponent<UISprite>();
            m_policyCheckBox.checkedBoxObject.name = "Checked";
            ((UISprite)m_policyCheckBox.checkedBoxObject).spriteName = "ToggleBaseFocused";
            m_policyCheckBox.checkedBoxObject.size = new Vector2(16f, 16f);
            m_policyCheckBox.checkedBoxObject.relativePosition = Vector3.zero;
        }
开发者ID:aoighost,项目名称:BuildingThemes,代码行数:75,代码来源:UIThemePolicyItem.cs


注:本文中的UIButton.AddUIComponent方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。