示例#1
0
        private void AddCheckboxZone(int idx, UIHelperExtension uiHelperExt, ItemClass.Zone zone)
        {
            UITextureAtlas thumbAtlas   = FindObjectOfType <ZoningPanel>().GetComponentInChildren <UIScrollablePanel>().atlas;
            UICheckBox     checkLR      = uiHelperExt.AddCheckboxNoLabel($"ConfigZ{idx}{zone}");
            var            checkedObj   = (UISprite)checkLR.checkedBoxObject;
            UISprite       uncheckedObj = checkLR.Find <UISprite>("Unchecked");

            checkedObj.spriteName         = $"Zoning{zone}";
            uncheckedObj.spriteName       = $"Zoning{zone}Disabled";
            checkedObj.atlas              = thumbAtlas;
            uncheckedObj.atlas            = thumbAtlas;
            checkLR.size                  = new Vector2(47, 32);
            checkedObj.size               = new Vector2(47, 32);
            uncheckedObj.size             = new Vector2(47, 32);
            checkedObj.relativePosition   = default;
            uncheckedObj.relativePosition = default;

            checkLR.tooltip = Locale.Get("ZONEDBUILDING_TITLE", zone.ToString());

            checkLR.isChecked          = CustomZoneData.Instance[idx].HasZone(zone);
            checkLR.eventCheckChanged += (x, y) =>
            {
                if (!m_loading)
                {
                    if (y)
                    {
                        CustomZoneData.Instance[idx].AddToZone(zone);
                    }
                    else
                    {
                        CustomZoneData.Instance[idx].RemoveFromZone(zone);
                    }
                }
            };

            CustomZoneData.EventOneChanged += (x) =>
            {
                if (x == idx)
                {
                    try
                    {
                        m_loading         = true;
                        checkLR.isChecked = CustomZoneData.Instance[idx].HasZone(zone);
                    }
                    finally
                    {
                        m_loading = false;
                    }
                }
            };

            CustomZoneData.EventAllChanged += () =>
            {
                try
                {
                    m_loading         = true;
                    checkLR.isChecked = CustomZoneData.Instance[idx].HasZone(zone);
                }
                finally
                {
                    m_loading = false;
                }
            };
        }