[Unity] Best approach to switch/navigate between views
Hello.
I'm looking for the 'right' way to display various xaml when they're needed. For instance a completely different xaml-view (like credits), maybe options or just a panel like a character panel. I could probably use a kind of user/custom control. But maybe it's even possible to navigate between different xamls?
Am I correct, that multiple user controls with code behind are only possible in the native version of Noesis? Would assigning various user controls to the content of a content control be a solution for changing the views?
Is there a road map when code behind may be expected in the Unity version?
I'm looking for the 'right' way to display various xaml when they're needed. For instance a completely different xaml-view (like credits), maybe options or just a panel like a character panel. I could probably use a kind of user/custom control. But maybe it's even possible to navigate between different xamls?
Am I correct, that multiple user controls with code behind are only possible in the native version of Noesis? Would assigning various user controls to the content of a content control be a solution for changing the views?
Is there a road map when code behind may be expected in the Unity version?
-
-
sfernandez
Site Admin
- Posts: 3203
- Joined:
Re: [Unity] Best approach to switch/navigate between views
It all depends on the complexity and structure of your app/game. But I would suggest the following:I'm looking for the 'right' way to display various xaml when they're needed. For instance a completely different xaml-view (like credits), maybe options or just a panel like a character panel. I could probably use a kind of user/custom control. But maybe it's even possible to navigate between different xamls?
- When you are within something like a game menu and navigating through different panels, I would say it is better to keep everything under the same Unity scene and same NoesisGUIPanel component. You just load/create the corresponding custom UserControl and add it to the main UI tree (placing it inside a known Panel or ContentControl). This approach permits you to launch animations to make cool transitions between panels.
- When you are going to load a completely new scene with new 3D models, like when you click Play on the game main menu, I would switch to a different Unity scene with its own NoesisGUIPanel components. That way you clean any possible unused resource from memory.
No, you can have any number of UserControls with their own code-behind in Unity too. As I said before, it is a good idea to load/create user controls and assign them to the current UI to change views.Am I correct, that multiple user controls with code behind are only possible in the native version of Noesis? Would assigning various user controls to the content of a content control be a solution for changing the views?
UserControls can already have code-behind specified by a Unity script class. Or by code-behind in Unity do you mean the possibility to specify event handlers programmed in Unity scripts directly in the xaml? This is something that doesn't have an exact time yet.Is there a road map when code behind may be expected in the Unity version?
Re: [Unity] Best approach to switch/navigate between views
Thank you for your quick reply.
Unfortunately I didn't have the time to get more work done regarding navigating between views using NoesisGUI. Once I've done that I'll probably get back here. 
I have a few more questions regarding UserControls but I'll open up a new topic to keep it separated.


I have a few more questions regarding UserControls but I'll open up a new topic to keep it separated.
Re: [Unity] Best approach to switch/navigate between views
Hi, I write in this thread because I am trying to implement a way to navigate back by the different views hierarchy and I think the title of this one suits perfect.
As I didn't find any Navigate Back (as we can find in Xamarin, for instance, but it is normal considering the wpf approach) I have desgined a draft like you can see in t he code below.
It seems to work ok except in a case that you go to a view and navigate back several times in a fast way, in this case it crashes. I've tried to debug it through noesis methods until this point:
Class: Collection.
Method: Add
ret = NoesisGUI_PINVOKE.Collection_Add__SWIG_0(swigCPtr, BaseComponent.getCPtr(item));
It seems that the delegates that is calling native intructions makes the app to crash, in a way I cannot even catch through an exception (debuging with adb in android says something like app pid="xxx" died!)
After I put the uc.Dispose() in the LoadView method in my MainView it seems to work a little better, but anyway if go too fast (going to a view, navigate back, go again, etc..) it crashes.
Also, when I use an internal button that calls the ViewActions.NavigateBack (acting slowly, with pauses of seconds) it seems to work in android (in editor mode it always work). But when I use the Android back button (as you can see in the MainView.Update) it automatically crash (no way of making it work).
If I use Esc in Unity Editor, after two or three times of going to the view and navigating back it makes the Unity3d editor to crash (which is something not very unusual as the Editor crashes constantly with any thing, even when blinking in pair seconds : p)
I will probably report it as a bug, but first I want to find a work around way.
and in the MainView.cs
As I didn't find any Navigate Back (as we can find in Xamarin, for instance, but it is normal considering the wpf approach) I have desgined a draft like you can see in t he code below.
It seems to work ok except in a case that you go to a view and navigate back several times in a fast way, in this case it crashes. I've tried to debug it through noesis methods until this point:
Class: Collection.
Method: Add
ret = NoesisGUI_PINVOKE.Collection_Add__SWIG_0(swigCPtr, BaseComponent.getCPtr(item));
It seems that the delegates that is calling native intructions makes the app to crash, in a way I cannot even catch through an exception (debuging with adb in android says something like app pid="xxx" died!)
After I put the uc.Dispose() in the LoadView method in my MainView it seems to work a little better, but anyway if go too fast (going to a view, navigate back, go again, etc..) it crashes.
Also, when I use an internal button that calls the ViewActions.NavigateBack (acting slowly, with pauses of seconds) it seems to work in android (in editor mode it always work). But when I use the Android back button (as you can see in the MainView.Update) it automatically crash (no way of making it work).
If I use Esc in Unity Editor, after two or three times of going to the view and navigating back it makes the Unity3d editor to crash (which is something not very unusual as the Editor crashes constantly with any thing, even when blinking in pair seconds : p)
I will probably report it as a bug, but first I want to find a work around way.
Code: Select all
public static class ViewActions
{
private static Stack<ViewModelBaseUnity> _navigationPath;
public static Stack<ViewModelBaseUnity> NavigationPath
{
get { return _navigationPath ?? (_navigationPath= new Stack<ViewModelBaseUnity>()); }
}
public static Action<ViewModelBaseUnity> LoadView { get; set; }
public static void Navigate(ViewModelBaseUnity viewModel)
{
NavigationPath.Push(viewModel);
LoadView(viewModel);
}
public static void NavigateBack()
{
if (NavigationPath.Count > 1)
{
// remove current
var current = NavigationPath.Pop();
// retrieves and remove parent
var prev = NavigationPath.Pop();
// navigate to parent
Navigate(prev);
}
}
}
Code: Select all
public class MainView : MonoBehaviour, IXamlLocalizable
{
public string Xaml { get { return "MainView.xaml"; }}
private NoesisGUIPanel GuiPanel;
private Grid DivContent;
public void Update()
{
if (Input.GetKeyDown(KeyCode.Escape))
{
try
{
ViewActions.NavigateBack();
}
catch (Exception e1)
{
ClientDebugger.SendToDebug("NavigateBack error: "+e1.Message);
}
}
}
private void LoadView(ViewModelBaseUnity viewModel)
{
var viewType = ViewDictionary.RegisteredTypes[viewModel.GetType()];
Debug.Log("loading view:" + viewType.Name+"---------------------------------");
try
{
var viewCodeBehind = gameObject.AddComponent(viewType);
var xaml = ((IXamlLocalizable)viewCodeBehind).Xaml;
var uc = DivContent.GetChildren();
uc.Dispose();
DivContent.GetChildren().Clear();
var newView = NoesisGUISystem.LoadXaml<UserControl>(xaml);
DivContent.GetChildren().Add(newView);
newView.SetDataContext(viewModel);
}
catch (Exception e1)
{
Debug.Log(e1.Message);
}
}
}
-
-
sfernandez
Site Admin
- Posts: 3203
- Joined:
Re: [Unity] Best approach to switch/navigate between views
Hi,
Looking at your code I don't find anything wrong (apart from the uc.Dispose() that shouldn't be necessary, and it could probably cause other crashes).
One thing that I will check is that you don't try to load the Views outside the main thread, and you also ensure that no object access NoesisGUI API from a Dispose() because it would be called from a GC thread.
I will try to reproduce your crash, and if I have no success I'll ask you to create a ticket in our bugtracker with your project attached.
Thanks for reporting.
Looking at your code I don't find anything wrong (apart from the uc.Dispose() that shouldn't be necessary, and it could probably cause other crashes).
One thing that I will check is that you don't try to load the Views outside the main thread, and you also ensure that no object access NoesisGUI API from a Dispose() because it would be called from a GC thread.
I will try to reproduce your crash, and if I have no success I'll ask you to create a ticket in our bugtracker with your project attached.
Thanks for reporting.
-
-
sfernandez
Site Admin
- Posts: 3203
- Joined:
Re: [Unity] Best approach to switch/navigate between views
I set up a sample based on your code and I was unable to make it crash. I'm afraid I will need your project (or part of it) where I can reproduce the problem.
Could you please create a ticket in our bugtracker and attach the project? Thanks.
Could you please create a ticket in our bugtracker and attach the project? Thanks.
Re: [Unity] Best approach to switch/navigate between views
Besides, Genom, what version of noesisGUI are you using? I assume you are using v1.1.13 because v1.1.14 is yet not published in the store, could you please validate your account and try with v1.1.14?
Thanks!
Thanks!
Re: [Unity] Best approach to switch/navigate between views
Hi guys, I'm using the 1.1.14, I could downloaded it from the Unity Asset Store (in the Unity Editor app) which was showing that an update was available there for Noesis.
I have reported the bug and uploaded a mini-version of my project. However, I had to remove most of plugins, components and references in order to make it small (before 90Mb). If you want the whole one, please provide a place to upload it (or I can share it in drive)
Regarding the size (and probably something to be moved to another thread) I find increadible heavy apks after compiling the project. I realied that, when compiling for android, within the apk (open as rar) there were the Noesis librarias for Desktop, OpenGL and iOS, so after removed them my apk came from 220 MB to just 40 MB which anyway is incredible big for 10 views and couple of images..
cheers!
I have reported the bug and uploaded a mini-version of my project. However, I had to remove most of plugins, components and references in order to make it small (before 90Mb). If you want the whole one, please provide a place to upload it (or I can share it in drive)
Regarding the size (and probably something to be moved to another thread) I find increadible heavy apks after compiling the project. I realied that, when compiling for android, within the apk (open as rar) there were the Noesis librarias for Desktop, OpenGL and iOS, so after removed them my apk came from 220 MB to just 40 MB which anyway is incredible big for 10 views and couple of images..
cheers!
Re: [Unity] Best approach to switch/navigate between views
Hi Genom,
Most size optimization recommendations for iOS are valid for Android as well: http://docs.unity3d.com/Manual/iphone-p ... ation.html
For example the size of our production APK of the app created with Unity + NoesisGUI (+ Facebook Unity SDK + Flurry Android SDK + some other Unity plugins) is about 15Mb.
Regards,
Albert
Most size optimization recommendations for iOS are valid for Android as well: http://docs.unity3d.com/Manual/iphone-p ... ation.html
For example the size of our production APK of the app created with Unity + NoesisGUI (+ Facebook Unity SDK + Flurry Android SDK + some other Unity plugins) is about 15Mb.
Regards,
Albert
Re: [Unity] Best approach to switch/navigate between views
Merci Albert ; )
we are quite new to Unity (not even two months) and we are trying to learn fast to go to production after changing our whole development migrating from Xamarin (we decided it just after discovering your product at early december, what a pitty not have discovered it before -.-)
so thanks for you suggestion!
we are quite new to Unity (not even two months) and we are trying to learn fast to go to production after changing our whole development migrating from Xamarin (we decided it just after discovering your product at early december, what a pitty not have discovered it before -.-)
so thanks for you suggestion!
Who is online
Users browsing this forum: Google [Bot], Semrush [Bot] and 10 guests