Search Unity

[RELEASED] XmlLayout: Xml-driven UI Framework

Discussion in 'Assets and Asset Store' started by DaceZA, May 3, 2016.

  1. Dan_lala

    Dan_lala

    Joined:
    May 14, 2015
    Posts:
    42
    after import I get lots of errors:

    import error.png

    Can someone please tell me why?
     
  2. halley

    halley

    Joined:
    Aug 26, 2013
    Posts:
    737
    It's not clear from the example if the XML Layouts can refer to any arbitrary class or prefab for XML elements, or just the elements you see in the included demos. For example, I may have acquired other Unity GUI assets like progress bars or styled buttons, which I want to use as-is (not just import their graphics and recreate).
     
  3. DaceZA

    DaceZA

    Joined:
    Dec 19, 2014
    Posts:
    152
    @Dan_lala

    Hi there, sorry about those error messages. It turns out that in more recent versions of Unity, Unity has changed the default 'API Compatibility Level' from .NET 3.5 to 2.0, and 2.0 doesn't contain the 'Remoting' namespace. However, you can switch from .NET 2.0 to .NET 4.0 by opening your 'Project Settings' (Edit -> Project Settings), and then under 'Player Settings' switching the 'API Compatibility Level' setting from .NET 2.0 to .NET 4.0.




    Additionally, 'Remoting' is only required for MVVM functionality, so if you don't want to use that, then you can disable it and then switch back to .NET 2.0 if you'd prefer by using the XmlLayout Configuration object (Assets -> XmlLayout -> Configuration)



    Sorry about the complication, I built the MVVM side of things when .NET 3.5 was the default setting in Unity, so at the time it seemed harmless enough to have it enabled by default. I intend to have it disabled by default for future versions of XmlLayout (so as to avoid these error messages), but I just need to find a way of disabling it for users who aren't using it, without disabling it for those who are (preferably without requiring them to do anything).
     
  4. DaceZA

    DaceZA

    Joined:
    Dec 19, 2014
    Posts:
    152
    @halley

    Hi there,

    XmlLayout can use non-standard elements, although in almost all cases it will be necessary to write a little bit of code to let XmlLayout know, for example, where to locate the prefab (if one is needed), how to handle instantiation (if any special handling is required), how to apply attributes (if they require any handling beyond simply passing the value to a field or property on the component). Additionally, the tag handler defines values for auto-complete, e.g. the name of the tag, and any attributes it should have available (and what data types to use for them).

    In general, writing tag handler code is fairly straight-forward, although naturally it is something that gets easier with experience. For example, here is a tag I recently added to support vector images:

    Code (CSharp):
    1. [ElementTagHandler("SVGImage")]
    2.     public class SVGImageTagHandler : ElementTagHandler
    3.     {
    4.         // this is a custom element, add it to the auto complete file
    5.         public override bool isCustomElement { get { return true; } }
    6.      
    7.         // No prefab required
    8.         public override string prefabPath { get { return null; } }
    9.  
    10.         // Specifies which component is the main component of this tag
    11.         public override MonoBehaviour primaryComponent
    12.         {
    13.             get
    14.             {
    15.                 return currentInstanceTransform.GetComponent<XmlLayoutSVGImage>();
    16.             }
    17.         }
    18.  
    19.         // attributes for auto complete
    20.         public override Dictionary<string, string> attributes
    21.         {
    22.             get
    23.             {
    24.                 return new Dictionary<string, string>()
    25.                 {
    26.                     { "image", "xs:string" },
    27.                     { "preserveAspect", "xs:boolean" },
    28.                 };
    29.             }
    30.         }
    31.  
    32.         // create and return an instance of this tag
    33.         // (used by XmlLayout to get an instance when you use the tag)
    34.         public override XmlElement GetInstance(RectTransform parent, XmlLayout xmlLayout, string overridePrefabPath = null)
    35.         {
    36.             var instance = base.GetInstance(parent, xmlLayout, overridePrefabPath);
    37.  
    38.             instance.gameObject.name = "SVGImage";
    39.             instance.gameObject.AddComponent<XmlLayoutSVGImage>();
    40.             instance.gameObject.AddComponent<LayoutElement>();
    41.  
    42.             MatchParentDimensions();
    43.  
    44.             return instance;
    45.         }
    The tag handler for this is fairly simple, it specifies a) that no prefab is used, b) the primary component is of type 'XmlLayoutSVGImage', c) there are two attributes (beyond the default attributes), and d) how to create a new instance (normally only required if no prefab is used). In this case, no special attribute handling is required, so XmlLayout's default 'ApplyAttributes()' behaviour defined in the parent 'ElementTagHandler' class is left as-is (it uses reflection to locate attributes by name, and then attempts to apply values to them without requiring you to define handling for each attribute).

    There's documentation on this available here: http://www.digital-legacy.co.za/XmlLayout/Documentation#CustomTags

    I hope this helps answer your question :)
     
    halley likes this.
  5. halley

    halley

    Joined:
    Aug 26, 2013
    Posts:
    737
    Great! I briefly skimmed that page but didn't quite connect that I would need a custom tag for each custom UI element type I wanted to use from XML. Very informative reply, thanks!
     
  6. DaceZA

    DaceZA

    Joined:
    Dec 19, 2014
    Posts:
    152
  7. DaceZA

    DaceZA

    Joined:
    Dec 19, 2014
    Posts:
    152
    @Dan_lala

    After seeing your post, I have decided that it is really important to get XmlLayout working by default in Unity 2019 without requiring any changes to be made, especially seeing as MVVM is an optional feature that isn't required for many users. As a result, I've made it so that, as of XmlLayout v1.86, MVVM is disabled by default, and these error messages will not be shown. Users can still enable MVVM if they wish (after switching to .NET 4x), but by default MVVM functionality will not be available and the error messages will not be shown when importing XmlLayout into a new project in Unity 2019.

    The unfortunate downside is that users who have been using MVVM previously will have to manually enable MVVM in their projects after importing the updated version, but for everyone else, no changes will need to be made and everything should work out of the box.

    v1.86 has been submitted to the asset store a few minutes ago, and should be available in a day or so. In the meantime, you can still continue as-is by following the steps I outlined in my earlier post - I just wanted to let you know that the problem will has been resolved and won't occur again in future :)
     
  8. Dan_lala

    Dan_lala

    Joined:
    May 14, 2015
    Posts:
    42
    Great! You might also want to change it to a more promiment spot... i had looked at the asset descrition and the online documentation for those errors and must have missed Installing XmlLayout -> Additional Note #2 (found it now on hindsight), ie. it might not be the best way to get this message across (plus it is a bit hidden and not mentioning any errors).

    Thank you very much for you help and this extension!
     
  9. DaceZA

    DaceZA

    Joined:
    Dec 19, 2014
    Posts:
    152
    You're welcome! :)
     
  10. EmeralLotus

    EmeralLotus

    Joined:
    Aug 10, 2012
    Posts:
    1,324
    I have net 4 enabled on 2019.2.16f1
    ran the MVVC example and getting this error. Do you know what this could be.
    Cheers
     

    Attached Files:

  11. DaceZA

    DaceZA

    Joined:
    Dec 19, 2014
    Posts:
    152
    Hi there,

    Have you enabled MVVM? In more recent versions of XmlLayout, MVVM is disabled by default. You can enable it by using the XmlLayout Configuration object, which is accessed via the Assets -> XmlLayout -> Configuration menu. On the configuration editor, there is a button at the bottom which you can click to enable or disable MVVM.

    If MVVM is not enabled, then the tags (such as 'List') will not be compiled, which is usually why you why you would see error messages like this one.

    If that doesn't help, it may be necessary to re-import XmlLayout (I noticed that, for some reason, switching between .NET 2.0 and .NET 4.0 can introduce compilation issues which seem to require a re-import. In Unity 2019.3, this seems to have been fixed - switching back and forth between .NET implementations didn't cause the problem anymore).

    I hope this helps!
     
    EmeralLotus likes this.
  12. EmeralLotus

    EmeralLotus

    Joined:
    Aug 10, 2012
    Posts:
    1,324
    Thank you, this was my problem. Fixed
     
  13. EmeralLotus

    EmeralLotus

    Joined:
    Aug 10, 2012
    Posts:
    1,324
    I would like to make a scheduling interface like that of Teamweek and wondering if you have tips how it can be done with XMLlayout. Here is a link to a video of the interface

    There are many use cases for this kind of interface. for example, a video or audio editing interface.

     
  14. DaceZA

    DaceZA

    Joined:
    Dec 19, 2014
    Posts:
    152
    Hi there,

    You could put together the basic UI using tables (remember that you can nest tables within other table cells if need be) - but setting up the 'tasks' will likely require a bit of code to set up their size/position/etc. depending on the task date/duration/etc. You will probably need to position the task position manually outside of (and above) the the tables.
    Overall I'd say it's definitely doable, but there will be quite a bit of work involved in putting it all together.
     
  15. drpelz

    drpelz

    Joined:
    Dec 7, 2017
    Posts:
    31
    Using v1.93 and it seems to be pretty good. However the buttons do not really work well in my case because I want to create a button that has a smaller touchable area than the images I'm using for it. Transition is 'SpriteSwap' but I'm missing the attribute 'targetGraphic' so I can set the path of the image to it!:( BTW it's a button where its images are changed when I hover over it but I can't figure out how to use it properly with xmllayout.:mad:

    Also I do miss support for DoTween (Pro). Otherwise nice work, dude!:D
     
  16. DaceZA

    DaceZA

    Joined:
    Dec 19, 2014
    Posts:
    152
    Hi there,

    I've added a targetGraphic attribute for you - you can get it here: https://pastebin.com/FsxbDMvt

    I'll include it in the next version of XmlLayout (v1.94).

    The targetGraphic expects either an internalId (if the target element is a child of the button) or a regular id (if it is not), for example:

    Code (CSharp):
    1.   <Button width="100" height="32" transition="SpriteSwap" color="clear" pressedSprite="Sprites/Icons/Cancel" disabledSprite="Sprites/Icons/Arrow_Right" highlightedSprite="Sprites/Icons/Arrow_Left" targetGraphic="target">
    2.   </Button>
    3.  
    4.   <Image id="target" image="Sprites/Icons/Move" width="128" height="64" raycastTarget="false" />



    PS: Unity recently added a 'selected' state in addition to the original states for selectable elements, I've just added attributes for that as well which will be included in v1.94. If you need them immediately, you can replace your copy of UI/XmlLayout/Custom Attributes/Transition.cs with this: https://pastebin.com/DAfpahus

    As for DoTween, there's nothing stopping you from using it. XmlLayout has its own internal animation system which you can use to create custom animations (See Examples/Animation) if you wish, but with a little bit of code you can easily use DoTween or any other animation framework (after all, elements created by XmlLayout are more-or-less standard Unity UI elements and as such can be interacted with in the same way).

    PS #2 - I'll be sending you an updated XmlLayout package with all of the above, that way you won't need to add anything manually or make any changes when v1.94 comes out.
     
    Last edited: Jan 25, 2020
  17. drpelz

    drpelz

    Joined:
    Dec 7, 2017
    Posts:
    31
    Awesome!:) Thank you so much for implementing the targetGraphic-attribute in xmllayout. I will try this ASAP! Now this is some great support!:)
     
  18. DaceZA

    DaceZA

    Joined:
    Dec 19, 2014
    Posts:
    152
    You're welcome :)
     
  19. drpelz

    drpelz

    Joined:
    Dec 7, 2017
    Posts:
    31
    Is it just me or does xmllayout not work in 2019.3.0f6?:( It disappeared in this Unity version...switching back to v2019.2.12f1.
     
  20. DaceZA

    DaceZA

    Joined:
    Dec 19, 2014
    Posts:
    152
    Hi there,

    I've just tested in 2019.3.0f6 and there appears to be an exception being thrown in the example scene, preventing it from being rendered - it looks like Unity may have changed the order of event execution as the Start() method used by one of the examples used to be called after XmlLayout's initialization in earlier versions of Unity, but is now being called before it. Fortunately, it's easy enough to fix, I've just added a delay to that code so that it executes once initialization is complete which fixes the problem - once the exception is removed, the example scene seems to work correctly.

    Outside of the main example scene, everything seemed to work correctly - are other scenes affected for you?

    Here is the fix for the example scene, specifically, UI/XmlLayout/Examples/XmlLayout_Example_ColorSchemeManager.cs (replace your copy of this file with this one and it should sort the example scene out for you): https://pastebin.com/ibZXSaEy
     
  21. drpelz

    drpelz

    Joined:
    Dec 7, 2017
    Posts:
    31
    I will test it in my project but I have the feeling that xmllayout won't work. As I said before it disappeared in my case. When I right-click xmllayout has gone. I try to test xmllayout with 2019.3 and create an empty game project.

    BTW: While importing my project into 2019.3 from 2019.2 Unity changed the asset database from version 1 (deprecated) to version 2. Maybe that's the cause of the issue?

    Update: Finally it works! The problem was that the asset "2D Homing Missiles" from Sean Duffy was not working properly (i.e. there were two GUI-bugs in 2019.3). I removed this asset and now it's working! Thanks for your great support! Much appreciated!:D
     
    Last edited: Feb 5, 2020
  22. DaceZA

    DaceZA

    Joined:
    Dec 19, 2014
    Posts:
    152
    You're welcome! I'm glad you managed to get it working :)

    Unfortunately, as you've seen, if the project can't compile due to code in one plugin, that can prevent compilation of the rest of it as well - it's not always the case (for example, plugins in different assemblies usually won't affect one another). If you like, XmlLayout does allow you to have it create its own separate assembly (via the Assets -> XmlLayout -> Configuration menu -> 'Generate Assembly Definition Files'), although naturally (and unfortunately) this menu is only available if XmlLayout was able to compile in the first place :)
     
    Last edited: Feb 6, 2020
unityunity