Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Need More Tests] Use RuntimeInitializeOnLoadMethod to call Init() #26

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

UlyssesWu
Copy link
Contributor

This PR implements the method mentioned by @MorganMoon at here.

It no longer uses Awake() for init, the new way is to find and init all bindings before scene loaded:

        static void SceneManager_SceneLoaded(Scene scene, LoadSceneMode mode)
        {
            foreach (var parentT in scene.GetRootGameObjects())
            {
                //Call Init() on all bindings
                foreach (var binding in parentT.GetComponentsInChildren<AbstractMemberBinding>(true)) //including inactive GameObjects
                {
                    binding.Init();
                }
            }
        }

By this way, we can implement ToggleSelfBinding which can toggle active for the gameobject it attached on, even if the gameobject is inactive at startup.

I have tested on Unity-Weld-Examples and all demos should still work. However I don't know if this will bring down the performance by traversing all gameojbects in scene. Maybe a performance test is needed .

@UlyssesWu
Copy link
Contributor Author

UlyssesWu commented Sep 24, 2018

Demo

ViewModel:

    [Binding]
    public bool IsActive
    {
        get { return _isActive; }
        set
        {
            if (value == _isActive) return;
            _isActive = value;
            OnPropertyChanged("IsActive");
        }
    }

unityweld-1

TwoWayPropertyBinding (IsActive) on Toggle, ToggleSelfBinding (IsActive) on Text. Text is inactive.

unityweld-2

You can still activate Text by switching the Toggle, because the ToggleSelfBinding is initialized by SceneManager_SceneLoaded.

Copy link
Contributor

@RoryDungan RoryDungan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks pretty good! Will need some time to test it but so far I think it looks like a good change. I'm away from the office right now but will be back next week so we'll see if one of the other guys has time to test it, otherwise I'll take a more in-depth look at it then.

{
Init();
}
//protected void Awake()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should just delete this. We try to avoid leaving blocks of commented-out code because it can be confusing to someone else reading the code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants