User avatar
Scherub
Topic Author
Posts: 141
Joined: 06 May 2014, 20:53
Contact:

[Unity] Best approach to switch/navigate between views

08 May 2014, 00:37

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?
 
User avatar
sfernandez
Site Admin
Posts: 3203
Joined: 22 Dec 2011, 19:20

Re: [Unity] Best approach to switch/navigate between views

08 May 2014, 13:31

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?
It all depends on the complexity and structure of your app/game. But I would suggest the following:

- 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.
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?
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.
Is there a road map when code behind may be expected in the Unity version?
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.
 
User avatar
Scherub
Topic Author
Posts: 141
Joined: 06 May 2014, 20:53
Contact:

Re: [Unity] Best approach to switch/navigate between views

11 May 2014, 18:34

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.
 
Genom
Posts: 47
Joined: 04 Dec 2014, 14:47

Re: [Unity] Best approach to switch/navigate between views

17 Jan 2015, 14:20

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.
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);
            }
        }
    }
and in the MainView.cs
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);
            }
                
       }
              
  }

 
User avatar
sfernandez
Site Admin
Posts: 3203
Joined: 22 Dec 2011, 19:20

Re: [Unity] Best approach to switch/navigate between views

19 Jan 2015, 17:40

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.
 
User avatar
sfernandez
Site Admin
Posts: 3203
Joined: 22 Dec 2011, 19:20

Re: [Unity] Best approach to switch/navigate between views

19 Jan 2015, 18:54

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.
 
User avatar
jsantos
Site Admin
Posts: 4219
Joined: 20 Jan 2012, 17:18
Contact:

Re: [Unity] Best approach to switch/navigate between views

19 Jan 2015, 22:35

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!
 
Genom
Posts: 47
Joined: 04 Dec 2014, 14:47

Re: [Unity] Best approach to switch/navigate between views

21 Jan 2015, 17:47

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!
 
timashev
Posts: 28
Joined: 22 Jan 2014, 00:47

Re: [Unity] Best approach to switch/navigate between views

21 Jan 2015, 19:22

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
 
Genom
Posts: 47
Joined: 04 Dec 2014, 14:47

Re: [Unity] Best approach to switch/navigate between views

21 Jan 2015, 21:29

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!

Who is online

Users browsing this forum: Google [Bot], Semrush [Bot] and 10 guests