Search Unity

Feature Request Can we get an 'object sender' parameter in IVisualElementScheduler.Execute ?

Discussion in 'UIElements' started by aybe, Dec 20, 2018.

  1. aybe

    aybe

    Joined:
    May 24, 2015
    Posts:
    104
    It would be nice if somehow we could get the sender object as a parameter in the action, that would allow us to instead of writing the following code:

    Code (CSharp):
    1.             scheduler
    2.                 .Execute(s =>
    3.                 {
    4.                     const string tr = "tint-red";
    5.                     const string tg = "tint-green";
    6.                     _buildButton.RemoveFromClassList(tr);
    7.                     _buildButton.RemoveFromClassList(tg);
    8.                     _buildButton.AddToClassList(HasFile ? tg : tr);
    9.                     _buildButton.SetEnabled(HasFile);
    10.                 })
    11.                 .Forever(); // extension method
    To write the following code:

    Code (CSharp):
    1.             scheduler
    2.                 .Execute((s, t) =>
    3.                 {
    4.                     var button = t as Button;
    5.                     if (button == null)
    6.                         throw new ArgumentNullException(nameof(button));
    7.                    
    8.                     const string tr = "tint-red";
    9.                     const string tg = "tint-green";
    10.                     button.RemoveFromClassList(tr);
    11.                     button.RemoveFromClassList(tg);
    12.                     button.AddToClassList(HasFile ? tg : tr);
    13.                     button.SetEnabled(HasFile);
    14.                 })
    15.                 .Forever();
    I guess you get the point of how useful of this 'sender' would be.

    Thanks !
     
  2. uDamian

    uDamian

    Unity Technologies

    Joined:
    Dec 11, 2017
    Posts:
    299
    Yep! I can see this being useful. I've added the request to our tracking for prioritization. Thanks!
     
  3. aybe

    aybe

    Joined:
    May 24, 2015
    Posts:
    104