[Unity] Starting a storyboard after dynamic load
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:
I also have a Root.cs that does the following to load xaml dynamically:
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:
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:
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:
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?
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:
Code: Select all
<ContentControl x:Name="RootContainer" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch">
</ContentControl>
Code: Select all
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;
}
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:
Code: Select all
public void StartOpenTransition()
{
_openAnim = FindResource<Storyboard>("OpenDetailCard");
_openAnim.Completed += SbOnOpenCompleted;
_openAnim.Begin(_contentContainer);
}
Code: Select all
var view = _root.LoadView<DetailCard>("detailcard.xaml");
view.StartOpenTransition();
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:
Code: Select all
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();
}
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?
-
sfernandez
Site Admin
- Posts: 3152
- Joined:
Re: [Unity] Starting a storyboard after dynamic load
Could you please try to delay the beginning of your Storyboard like this:
And let me know if the animation is played entirely.
I think I know what is happening, but I want to make sure.
Code: Select all
<Storyboard x:Key="OpenDetailCard" BeginTime="0:0:1">
...
</Storyboard>
I think I know what is happening, but I want to make sure.
Re: [Unity] Starting a storyboard after dynamic load
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.
-
sfernandez
Site Admin
- Posts: 3152
- Joined:
Re: [Unity] Starting a storyboard after dynamic load
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:
EDIT: Code corrected
Now modify the animation duration time to make it last longer, maybe by changing speed ratio:
Code: Select all
<Storyboard x:Key="OpenDetailCard" SpeedRatio="0.25">
...
</Storyboard>
Re: [Unity] Starting a storyboard after dynamic load
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.
-
sfernandez
Site Admin
- Posts: 3152
- Joined:
Re: [Unity] Starting a storyboard after dynamic load
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.
Re: [Unity] Starting a storyboard after dynamic load
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.
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.
-
sfernandez
Site Admin
- Posts: 3152
- Joined:
Re: [Unity] Starting a storyboard after dynamic load
Now everything makes sense.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.
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.
Re: [Unity] Starting a storyboard after dynamic load
Note that UpdateLayout() will be made public in v1.1.12.
Re: [Unity] Starting a storyboard after dynamic load
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