Jump to content

Recommended Posts

        private void Refresh()
        {
            if (Heater != null && PButtons.Count > 0)
            {
                int Dir = 1;// Heater.GetDirection();

                for (int i = 0; i < 8; i++)
                {
                    UnityEngine.UI.Image component = buttonObjects[i].transform.Find("Image").GetComponent<UnityEngine.UI.Image>();
                    component.color = Color.white;
                    if (i == Dir)
                    {
                        component.enabled = true;
                        component.sprite = arrowSprite_act[i];
                        Debug.Log("act:" + buttonObjects[i].name + ", sprite :" + component.sprite.ToString());
                    }
                    else
                    {
                        component.enabled = false;
                        component.sprite = arrowSprite_inact[i];
                        Debug.Log("in_act:" + buttonObjects[i].name + ", sprite :" + component.sprite.ToString());
                    }
                }
            }
        }
//...........
                arrowSprite_act.Add( Sprite.Create(tex, new Rect(0, 0, tex.width, tex.height), new Vector2(0.5f, 0.5f)));

                byte[] imageBytes_inact = File.ReadAllBytes(imagePath + @"\assets\" + directions[i] + "_INACT.png");
                Texture2D tex_inact = new Texture2D(2, 2);
                tex_inact.LoadImage(imageBytes_inact);
                arrowSprite_inact.Add(Sprite.Create(tex_inact, new Rect(0, 0, tex_inact.width, tex_inact.height), new Vector2(0.5f, 0.5f)));

                PButtons.Add(new PButton("DirectionButton" + i.ToString())
                    {
                        ToolTip = "Select direction " + directions[i],
                        Margin = new RectOffset(5, 15, 5, 15),
                        Color = mColor,
                        Sprite = arrowSprite_inact[i],  
                    }
                );

 
               PButtons[i].OnClick = OnButtonClick;
 
                panel.AddChild(PButtons[i], new GridComponentSpec(rows[i], columns[i]));
                buttonObjects.Add(PButtons[i].Build());  
//..........
              private void OnButtonClick(GameObject target)
        {
            if (Heater != null)
            {
                Heater.SetDirection(0);
                Refresh();
            }
        }

When I click the button, the button image does not change as expected.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
  • Create New...