MrHayato
Topic Author
Posts: 36
Joined: 19 Sep 2014, 21:29

[Unity] Starting a storyboard after dynamic load

19 Sep 2014, 22:04

Hi there,

I found this weird bug while trying to start a storyboard when loading my view dynamically. The way my code is set up, I have a NoesisGUIPanel on my Main Camera, with a Root.xaml view on it. The root xaml is barebones and only contains:
    <ContentControl x:Name="RootContainer" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch">
    </ContentControl>
I also have a Root.cs that does the following to load xaml dynamically:
        public T LoadView<T>(string xamlFilePath) where T : BaseComponent, IXamlView
        {
            var loaded = NoesisGUISystem.LoadXaml<T>(xamlFilePath);
            _contentContainer.SetContent(loaded);
            _contentContainer.SetVisibility(Visibility.Visible);
            return loaded;
        }
This works great so far, and loads things as I want.

Now, I have a xaml file that has a storyboard in it. All it does, is animate a grid up using a transform. The animation is invoked using the following code in a .cs file:
        public void StartOpenTransition()
        {
            _openAnim = FindResource<Storyboard>("OpenDetailCard");
            _openAnim.Completed += SbOnOpenCompleted;
            _openAnim.Begin(_contentContainer);
        }
This works great on its own when I manually call StartOpenTransition(). However, if I call it from Root after loading it dynamically, it doesn't work:
var view = _root.LoadView<DetailCard>("detailcard.xaml");
view.StartOpenTransition();
What happens, is the grid is in the state where the transition has already been completed, so it's like it finished animating without doing the animation.

The next step I took, was created a MonoBehaviour and put it on the Camera (where the NoesisGUIPanel is) and put in a Coroutine to start the animation:
        private Root _root;

        public void Start()
        {
            _root = GetComponent<NoesisGUIPanel>().GetRoot<Root>();
        }

        public void Update()
        {
            if (Input.GetKeyDown(KeyCode.Alpha1))
            {
                var view = _root.LoadView<DetailCard>();
                StartCoroutine(OpenDetailCard(view));
            }
        }

        private IEnumerator OpenDetailCard(DetailCard view)
        {
            yield return null;
            view.StartOpenTransition();
        }
Now, when I run the project, if I hit "1" on my keyboard, the view is loaded dynamically like normal, and the storyboard is played fully as intended. If I switch the order of the StartOpenTransition() call and the yield return null, then it doesn't work again.

Not sure what the problem is, but it kinda sucks that I'd have to create a Coroutine for every animation I want to run on load. Is this a bug? Or is this intended because of threading or something?
 
User avatar
sfernandez
Site Admin
Posts: 1915
Joined: 22 Dec 2011, 19:20

Re: [Unity] Starting a storyboard after dynamic load

23 Sep 2014, 11:21

Could you please try to delay the beginning of your Storyboard like this:
<Storyboard x:Key="OpenDetailCard" BeginTime="0:0:1">
    ...
</Storyboard>
And let me know if the animation is played entirely.
I think I know what is happening, but I want to make sure.
 
MrHayato
Topic Author
Posts: 36
Joined: 19 Sep 2014, 21:29

Re: [Unity] Starting a storyboard after dynamic load

23 Sep 2014, 18:20

I have done that, but instead of delaying before playing the animation, it delays for the specified time, and then instantly goes to the state where the animation is completed.
 
User avatar
sfernandez
Site Admin
Posts: 1915
Joined: 22 Dec 2011, 19:20

Re: [Unity] Starting a storyboard after dynamic load

25 Sep 2014, 20:47

Ok, it is not what I expected but please try another thing.
Now modify the animation duration time to make it last longer, maybe by changing speed ratio:
<Storyboard x:Key="OpenDetailCard" SpeedRatio="0.25">
    ...
</Storyboard>
EDIT: Code corrected ;)
 
MrHayato
Topic Author
Posts: 36
Joined: 19 Sep 2014, 21:29

Re: [Unity] Starting a storyboard after dynamic load

28 Sep 2014, 01:28

I assume you meant to put code where SpeedRatio="0.25" or something along those lines? I gave that a try and the exact same thing happened.
 
User avatar
sfernandez
Site Admin
Posts: 1915
Joined: 22 Dec 2011, 19:20

Re: [Unity] Starting a storyboard after dynamic load

29 Sep 2014, 11:12

I will need the xaml+cs you are using to debug what is happening. You can create a ticket in our bugtracker if you don't want to share these files with others.
 
MrHayato
Topic Author
Posts: 36
Joined: 19 Sep 2014, 21:29

Re: [Unity] Starting a storyboard after dynamic load

01 Oct 2014, 01:01

I created a sample here at this gist: https://gist.github.com/MrHayato/4d1bef7b2af8c6aad1cb

While creating a sample, I noticed something that might be the cause of the problem. In the storyboard, the Y value is a binding to the height of the control. However, if I remove the binding, and use an integer, everything works as it should. Hopefully that helps.
 
User avatar
sfernandez
Site Admin
Posts: 1915
Joined: 22 Dec 2011, 19:20

Re: [Unity] Starting a storyboard after dynamic load

07 Oct 2014, 19:05

While creating a sample, I noticed something that might be the cause of the problem. In the storyboard, the Y value is a binding to the height of the control.
Now everything makes sense.

When SimpleView is loaded and added to the SimpleRoot container, it is marked to update its layout in the next GUI Update. Until it is measured and arranged, the ActualHeight property keeps its default value (0.0f).

If the storyboard is fired just after view is loaded, the Binding will still have a value of 0.0f, so animation doesn't change anything.

You can force a layout update before launching the animation to obtain the result you are looking for.
 
User avatar
jsantos
Site Admin
Posts: 2905
Joined: 20 Jan 2012, 17:18
Contact:

Re: [Unity] Starting a storyboard after dynamic load

07 Oct 2014, 19:23

Note that UpdateLayout() will be made public in v1.1.12.
 
MrHayato
Topic Author
Posts: 36
Joined: 19 Sep 2014, 21:29

Re: [Unity] Starting a storyboard after dynamic load

09 Oct 2014, 17:55

This didn't seem to work. I've tried it both in the monobehaviour that creates the view, and the view itself in OnPostInit. Is there a specific time to run the UpdateLayout call?

Who is online

Users browsing this forum: No registered users and 1 guest