Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

OpenGUI: Open source GUI framework for Unity

Discussion in 'Works In Progress - Archive' started by mrzapp, May 26, 2013.

  1. Akira_san

    Akira_san

    Joined:
    Jul 1, 2013
    Posts:
    69
    Some scene examples would be nice too.
     
  2. mrzapp

    mrzapp

    Joined:
    May 26, 2013
    Posts:
    137
    @frankieboy: It appears you've got the old OnGUI version there, or you might have included the C# code by accident and then Unity compiled it first and left off UnityScripts with identical class names. I've updated the first post to make it a bit more clear which version to download, and also removed the C# code from the repo.

    @akira: There is, I've updated the first post with a link.
     
    Last edited: Feb 9, 2014
  3. Lokkij

    Lokkij

    Joined:
    Aug 18, 2013
    Posts:
    22
    First of all, this project looks awesome!
    However, I am experiencing a poblem with it right now. After importing the assets, I get the following error: "BCE0018: The name 'iTween.EaseType' does not denote a valid type ('not found')". The problem occurs on line 13 in OGTween.js.
    Do you know what the problem could be? It sounds like I'm missing some kind of class. I think I imported everything correctly though.
    Thanks in advance :)
     
  4. mrzapp

    mrzapp

    Joined:
    May 26, 2013
    Posts:
    137
    Thanks a lot, I'm glad you like it.
    The problem is that the OGTween class requires iTween by Bob Berkebile. You can either remove or comment OGTween.js or download iTween from here. It's also to be found in the example project from the GitHub repo. I'd generally recommend that you download that to get a proper demonstration of how OpenGUI works.

    I'll make sure to make a point of this in the first post, thanks for the heads up.

    EDIT: I made a new release for the example project, link in the first post.
     
    Last edited: Feb 9, 2014
  5. frankyboy450

    frankyboy450

    Joined:
    Jan 21, 2011
    Posts:
    106
    Alright. Downloaded the latest version which contained the OpenGUI folder which I imported into my project.
    I made a MenuRoot with the OGRoot script attached to. Then I made a Page gameObject with the OGPage script to in and last I made a Button gameobject with the OGButton script attached to it. but for some reason the button isn't visible in-game.
    I set the Stretch width and height to screen width and height but still no button :/
     
  6. mrzapp

    mrzapp

    Joined:
    May 26, 2013
    Posts:
    137
    That might be because there's no Camera component on your OGRoot object. Refer to the example project for a complete setup ready-made, it's a lot easier to just copy from that :)
     
    Last edited: Feb 9, 2014
  7. frankyboy450

    frankyboy450

    Joined:
    Jan 21, 2011
    Posts:
    106
    oh wow... totally forgot about the camera.. Thanks ;D Now the only problem left before I can start
    converting the UnityGUI to OpenGUI is that in C# when I want to set up a reference to the button.
    when I write
    public OGButton btnContinue;

    is get this error:
    Assets/OpenGUI/Test.cs(6,16): error CS0246: The type or namespace name `OGButton' could not be found. Are you missing a using directive or an assembly reference?

    I remember earlier today I was able to write that without any problems and I could later use that reference to set up the anchor etc...
     
  8. Lokkij

    Lokkij

    Joined:
    Aug 18, 2013
    Posts:
    22
    Thanks for the quick reply! That fixed it.
    So far, I'm really liking this. Nothing really fancy, just a basic but solid GUI solution. In other words, exactly what we need :)

    One extremely helpful addition would be some "default" prefabs to start off with, so just a basic button, scrollview, etc. Sure, you can copy them from the example scene, but it would be a lot easier if they were just included in the package.
     
  9. chrisall76

    chrisall76

    Joined:
    May 19, 2012
    Posts:
    667
    It's nice, but a C# version would help as communicating between my C# scripts and the plugin is impossible (things like syncing up a healthbar, inventory, etc.). I may try to conver all the scripts to C# now so I can use them though, pretty nice plugin.
     
  10. Lokkij

    Lokkij

    Joined:
    Aug 18, 2013
    Posts:
    22
    I just found that out as well. That sadly makes it a lot less useful to us, but if you are going to port it to C#, that would be awesome :D
    I could also give it a try, but I'm not exactly an expert on C#, and definitely not on Javascript/Unityscript.
     
  11. Muber Gaming

    Muber Gaming

    Joined:
    Jan 24, 2014
    Posts:
    48
    Hi mrzapp,

    I am experiencing something odd with openGUI skin prefab,

    I am not sure if it is my setup or an actual bug,
    every time i add a new style from the OGDefault OGSkin prefab it does not persists for some reason after i restart unity editor, it only works in the current session, if i close the unity editor and restart it, then my new style i did before it does not get saved in OGDefault skin prefab, weird.

    it only persists if you drag out the OGDefault sking prefab to the scene hierarchy do the additions of new styles and configure it then save it back and overwrite existing OGDefault skin in the project folder, then it gets saved correctly and persists thru other sessions/unity editors restarts.


    maybe you can help me corroborate , just to make sure it is not my current setup.

    thanks again.
     
  12. Muber Gaming

    Muber Gaming

    Joined:
    Jan 24, 2014
    Posts:
    48
    Also having issues building game:
    Assets/Extensions/OpenGUI/Scripts/OGRoot.js(415,33): BCE0005: Unknown identifier: 'Handles'.
    Assets/Extensions/OpenGUI/Scripts/OGRoot.js(420,33): BCE0005: Unknown identifier: 'Handles'.
    Error building Player because scripts had compiler errors


    altho i can click on play in the unity editor without no compiling errors , just when i try to build player.
     
  13. chrisall76

    chrisall76

    Joined:
    May 19, 2012
    Posts:
    667
    I tried converting for a few hours, too many errors kept coming to handle.
    Main two where

    1.Handle doesn't exist anywhere, had to comment that out to stop error
    2.Function does not exist when I looked, that's another error that showed up

    I'll just wait and see if you add C# support.
     
  14. frankyboy450

    frankyboy450

    Joined:
    Jan 21, 2011
    Posts:
    106
    So... You can't use C# with this? That might be why I haven't gotten it to work so far...
     
  15. mrzapp

    mrzapp

    Joined:
    May 26, 2013
    Posts:
    137
    TL;DR:
    • You definitely can use UnityScript plugins with your C# project, it's in the Unity documentation. Porting OpenGUI to C# is not needed.
    • Compile errors might happen, if the OpenGUI folder is not in the root of your project, or if you by mistake imported the old C# simultaneously
    • New beta here fixes build errors
    • OpenGUI is still in beta, this is why your feedback matters. If you're looking for a completely polished, trouble-free package, this is not it. Yet.
    • Unity itself is not bug-free, as any plugin developer might tell you, and it does take a few workarounds.

    Answers:

    This could be either because you didn't place the OpenGUI folder in the root of your project, or that you imported the old C# version as well (which I have now removed from the repo)

    That's exactly what creating a new GameObject, adding a widget component (e.g. OGButton), and clicking "Get default styles" is for. There are a bunch of defaults set up for the OGDefault skin, but you can just duplicate that and modify it to your liking. Check out the inspector for the skin, and it should become apparent what you can do with it.

    It's not impossible, the official Unity documentation outlines how communication between UnityScript and C# works. Having a C# version as well would of course be a very welcome addition, but not really vital, as the UnityScript version works fine when used correctly.

    "Handles" is a native Unity class, and if it doesn't compile because of that, it's a Unity bug. I fixed it in the latest beta, linked in the first post.


    C# "support" is already there, it doesn't have to be the same language to be used with your project. It's the compile order that matters, as described above.

    I've experienced this issue at random as well, it's another Unity bug, this time related to serialisation. I think I might have to rewrite the inspector code using the SerialisedObject type. I'll add it to the tracker.

    I hope that puts a lid on some of the misunderstandings, I've made a few changes to the first post to account for them. I realise that a lot of this confusion could have been avoided with better documentation, so I'll try to improve on that some more. I'll also do some tutorials with both UnityScript and C# examples.
     
    Last edited: Feb 10, 2014
  16. Lokkij

    Lokkij

    Joined:
    Aug 18, 2013
    Posts:
    22
    Okay, I might just be really stupid, but I can't get the US-C# compatability to work. Basically, it does not seem to recognise the US code: "CS0246: The type of namespace 'OGPopUp' could not be found. Are you missing a using directive or assembly reference?".
    I am sure the OpenGUI folder is in the right place - I even get the error in the example project (of course only when I add my own code). What exactly do I need to do to make it work?

    Also, a potential (very minor) bug: it seems the default 'hover' style for a button is background instead of button or buttonactive.

    You've been really helpful so far, thanks for that :eek:
     
    Last edited: Feb 10, 2014
  17. mrzapp

    mrzapp

    Joined:
    May 26, 2013
    Posts:
    137
    Oh crap, you're right! The reason I wasn't seeing this is because I've been temporarily suspending OGTween. So, here's the solution: Instead of the root directory, place OpenGUI in a folder called "Plugins" and remove or comment out OGTween.js. Then take the "Editor" folder, rename it "OpenGUI" and place it in /Assets/Editor.

    I'm sorry, that was an oversight on my behalf. I'll find a way to fix this, just go without OGTween for now. You can use iTween directly instead, the documentation is pretty straightforward.

    EDIT: I've updated the example project and the latest release to account for this.
     
    Last edited: Feb 11, 2014
  18. MuNgLo

    MuNgLo

    Joined:
    Jan 27, 2014
    Posts:
    31
    If I understand the features correctly there isn't anyway to have a "global" page. I mean like a hud element that exists always. think of how some games have friendslist for example.
    Have I understood it correctly? (if so please add it :) )

    Trying to get it up and running and Ii think I got stuck on what you mention in your last post so I will have to give it another go I guess.
     
  19. mrzapp

    mrzapp

    Joined:
    May 26, 2013
    Posts:
    137
    It doesn't exist yet, but it's on the issue tracker linked in the first post
     
  20. MuNgLo

    MuNgLo

    Joined:
    Jan 27, 2014
    Posts:
    31
    So I got it all "working". I started out with the github master branch and used the above mentioned layout. Fixed the OGDefault prefab,material and texture settings.
    I say "working" as the default styles are gone. is there any way to get them back?

    Adding styles work though but I'd rather not remap everything just to have a markupskin. :/

    So I see the buttons in the editor and all like the example but no styles and also I get this..
    IndexOutOfRangeException: Array index is out of range.
    OGWidgetInspector.OnInspectorGUI () (at Assets/Editor/OpenGUI/OGWidgetInspector.js:67)
    UnityEditor.InspectorWindow.DrawEditors (Boolean isRepaintEvent, UnityEditor.Editor[] editors, Boolean eyeDropperDirty) (at C:/BuildAgent/work/d3d49558e4d408f4/Editor/Mono/Inspector/InspectorWindow.cs:850)
    UnityEditor.DockArea:OnGUI()


    This on a empty projekt with a scene with minimal objects. One OGRoot, one OGPage with one background and a button.
     
    Last edited: Feb 11, 2014
  21. mrzapp

    mrzapp

    Joined:
    May 26, 2013
    Posts:
    137
    I don't know what you mean by "fixed the OGDefault prefab", but it shouldn't be necessary to fix anything. If your defaults setup is gone, you can click "Auto detect" in the top right of the "Manage defaults" mode of the OGSkin inspector, but if you mean that all styles are gone, then that's a corrupted prefab, and I'd need to know more about what you did prior to this.

    Generally, I'd recommend you download the releases linked in the first post rather than checkout the repo. Whatever is not "released" is considered development code.
     
  22. MuNgLo

    MuNgLo

    Joined:
    Jan 27, 2014
    Posts:
    31
    the OGDefault material texture and Skin prefab all had wrong values. Texture wasn't transparent on import. The material didn't have the texture picked and the prefab for the skin had a nonworking script attached wich I had to replace with a new OGSkin.
    I did try the beta-2 pre release earlier and if I remember correctly, also had problems with styles and OGDefault prefab and that release have listed under known bugs..
    "Prefab changes to OGSkin objects might not persist. Dragging it into scene and applying fixes this temporarily."
    So I figured it was related.

    Could ofcource been a bad download.

    The beta2 prerelease had the same thing while the "Open GUI Example Project" does retain proper settings on the skin bits. It only retains the styles.
     
    Last edited: Feb 11, 2014
  23. mrzapp

    mrzapp

    Joined:
    May 26, 2013
    Posts:
    137
    It sounds like a bad download. If you are having no problems with the example project, then I suggest you just use that. It should be the exact same prefabs and code, and I haven't heard about your situation before or experienced it myself. I updated the beta-2 with a fix for C#, perhaps downloading that again would help.

    EDIT: About the import settings:
    the texture of an atlas should be type: GUI and filter mode: Point.
    the material should have the shader "Unlit/Vertex Colored"
    the font shader on the OGSkin should be "GUI/3D Text Shader"

    Just to clear that up as well
     
    Last edited: Feb 11, 2014
  24. MuNgLo

    MuNgLo

    Joined:
    Jan 27, 2014
    Posts:
    31
    Shouldn't really matter since I've run it in new empty projects. I haven't run any of my own scripts at all. It's just a bit strange.
     
  25. mrzapp

    mrzapp

    Joined:
    May 26, 2013
    Posts:
    137
    It is very strange. Might be .meta related then, I really don't know :p
     
  26. MuNgLo

    MuNgLo

    Joined:
    Jan 27, 2014
    Posts:
    31
    This might be a stupid beginner question but I'm having trouble getting the OGUI drawn to my main camera. Depending on depth I get either the OGRoot camera or the playercamera but how do I get the GUI from OGRoot to my maincamera?
     
  27. mrzapp

    mrzapp

    Joined:
    May 26, 2013
    Posts:
    137
    The camera on the OGRoot needs to be set to Depth Only, and the depth has to be lower than the main camera. Try to play around with the depth setting on the two cameras, I bet you'll get it that way :)
     
  28. MuNgLo

    MuNgLo

    Joined:
    Jan 27, 2014
    Posts:
    31
    Thx a lot. That Depth only was what was needed I guess :D

    Also I would suggest adding alignment to the OGPage to manipulate the transform. Right now I have made a 200 wide GUI element with tabs and so on. It's all on one page but as I need it in upper right corner regardless of resolution I added a simple script to manipulate the transform on the OGPage object.
    As far as I get it should be safe to do, right?
    But a align to center,topmiddle,leftbottom... and so on with an offset would probably be appreciated by others.

    I also have a graphical issue on the corners of some OGbuttons on top of a background (OFSliced Sprite). On the corners of the button it seems the background isn't drawn so you end up with transparency.
    Oh and the kicker is that it changes button so it has to be something with the order it gets resolved I guess.

    Edit--
    Styles are messed up in this version to. Just not as bad. I have 2 buttons that work as intended but all buttons placed under empty gameobjects used for tabcontent have their style messed up.
    While those that work have Button on all style and ButtonActive on active, the ones that don't work have background on hover, thumb and disabled.
    Getting default styles or trying to set default styles in the skin doesn't. It just changes back.
     
    Last edited: Feb 11, 2014
  29. mrzapp

    mrzapp

    Joined:
    May 26, 2013
    Posts:
    137
    There is alignment, it's the "anchor" and "pivot" variables of OGWidget and all subclasses. If you want a group of objects to be aligned, just add OGWidget to the parent object. As for the styles being off, you need to press "get default styles" when you create widgets manually. Other than that, the default styles might not all be set up perfectly, but you can always change them in the OGSkin. Read the first post for a disclaimer on that.

    You are right about the corner rendering issue, I'll add that to the tracker.
     
    Last edited: Feb 11, 2014
  30. MuNgLo

    MuNgLo

    Joined:
    Jan 27, 2014
    Posts:
    31
    Thanks for taking the time to explaining stuff. Much appreciated.
    However the styles do have problems. If I make a button then press get default styles I end up with the wrong styles (background on hover,thumb and disabled). So I then edit the stylesetup under the skin and sure enough it has background on the buttons so I change them. Then back to the button and get default. YEY!
    All gone after I restart Unity though. :/

    The first 2 buttons I made worked fine. they remembered the style settings they have. But the OGDefault prefab didn't.

    After some messing around, rebuilding the OGDefault prefab, it seems to work as intended now. Is this connected to the "Serialisation issues with OGSkin prefabs" issue on the tracker or is it just Unity being weird?
     
  31. frankyboy450

    frankyboy450

    Joined:
    Jan 21, 2011
    Posts:
    106
    Hmm.. I tried out the latest example where I made some buttons and made a C# script to make a reference to them with
    public OGButton btn;
    but that didn't work... Do I need to place the script somewhere specific to find the type OGButton?

    This is my script:
    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4.  
    5. public class TestButton : MonoBehaviour {
    6.  
    7.     public OGButton btnContinue;
    8.  
    9.     // Use this for initialization
    10.     void Start () {
    11.         btnContinue.text = "HELLO!";
    12.     }
    13.    
    14.     // Update is called once per frame
    15.     void Update () {
    16.    
    17.     }
    18. }
    19.  
    I noticed that the MyPage.cs didn't have any problem with it though.
    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4.  
    5. public class MyPage : OGPage {
    6.  
    7.     public OGButton btn;
    8.  
    9.     // This is called when the page is switched to
    10.     override public void StartPage () {
    11.    
    12.     }
    13.    
    14.     // This is called once per frame
    15.     override public void UpdatePage () {
    16.    
    17.     }
    18.  
    19.     // This is called when the page is switched away from
    20.     override public void ExitPage () {
    21.  
    22.     }
    23.  
    24.     // You must use a custom function to switch pages
    25.     public void SwitchPage () {
    26.         OGRoot.GetInstance().GoToPage ( "MyOtherPage" );
    27.     }
    28. }
    29.  
    even though the auto-fill doesn't work it didn't give me any error messages on the MyPage.cs but it did on TestButton.cs
     
    Last edited: Feb 12, 2014
  32. mrzapp

    mrzapp

    Joined:
    May 26, 2013
    Posts:
    137
    No problem, I appreciate the feedback. I am doing an FAQ right now based on this thread. I'll link it in the first post when it's ready on the project site

    Yes and yes :) Long story short, Unity has some issues with reading the prefab data into the inspector and writing them back into the prefab, and it might be solved by using a class called SerializedObject. If not, i'm going to do a big green "Save" button that briefly instantiates the prefab, applies it and removes it again.
     
  33. mrzapp

    mrzapp

    Joined:
    May 26, 2013
    Posts:
    137
    It's again related to the compile order. Just put your C# script in a subfolder somewhere like /Assets/Scripts and it should compile correctly. I'll change the first post to include this.
     
  34. frankyboy450

    frankyboy450

    Joined:
    Jan 21, 2011
    Posts:
    106
    Alright, that fixed the compile error and now I'm able to define the button with
    public OGButton btn;

    and change the text with btn.text = "HELLO"; in the start()
    The autofill doesn't work and neither does btn.Anchor.XOffset = Screen.width / 4;
    or btn.func = function () { Debug.Log ( "Clicked!" ); };
     
  35. mrzapp

    mrzapp

    Joined:
    May 26, 2013
    Posts:
    137
    I've updated the wiki with some explanations on anchor, pivot and stretch. Check out the OGWidget documentation and click the properties you want examples for.

    The AutoFill I have no clue on, I've been using Vim for a long time now because of issues like that. My impression is that the Unity bundled version of MonoDevelop doesn't really "get" UnityScript as well as C#. I'd guess that MonoDevelop uses its own serialisation system, which just doesn't parse .js files as well as it should.

    The OGButton.func definitely works for me, at least in a UnityScript. If you're on C#, it should be as easy as:
    Code (csharp):
    1.  
    2. void SomeFunction () {
    3.    // Do something
    4. }
    5.  
    6. void Start () {
    7.    btn.func = SomeFunction;
    8. }
    9.  
    ..but I'd have to verify that.
     
  36. frankyboy450

    frankyboy450

    Joined:
    Jan 21, 2011
    Posts:
    106
    Thanks for the help with the OGWidget documentation. I get an error when I Attempt using that code:

    Code (csharp):
    1. error CS0428: Cannot convert method group `SomeFunction' to non-delegate type `Boo.Lang.ICallable'. Consider using parentheses to invoke the method
    And by adding () To the end so it looks like this instead:
    btnContinue.func = SomeFunction();

    I Get the same Error.
     
    Last edited: Feb 13, 2014
  37. Lokkij

    Lokkij

    Joined:
    Aug 18, 2013
    Posts:
    22
    I have to say, I'm really impressed with this package! It basically has everything we need, so I'm going to start integrating it into our own project.
    Thanks a lot for making this, and for releasing it for free :)

    EDIT: by the way, when importing the files from the release package, the OGSkin script on OGDefault doesn't seem to load properly. Copying the files from the example project works fine though.
     
    Last edited: Feb 13, 2014
  38. mrzapp

    mrzapp

    Joined:
    May 26, 2013
    Posts:
    137
    No problem. It appears that there is no cross-language function pointer compatibility with C# and UnityScript, as the former uses delegates and the latter just uses a variable. I've updated the documentation to reflect this. You can use the "target", "message" and "argument" features instead.
     
  39. mrzapp

    mrzapp

    Joined:
    May 26, 2013
    Posts:
    137
    You're very welcome. I love getting this kind of response, for the longest time I didn't think anyone was interested :)

    What is the problem you're having with the release package, can you describe it in detail? I might have to package it as a .unitypackage instead to make sure things stay where they are.
     
  40. Lokkij

    Lokkij

    Joined:
    Aug 18, 2013
    Posts:
    22
    Everything works just fine, except the OGSkin script on the OGDefault prefab says something like "could not load monobehaviour". Adding an OGSkin script manually doesn't work either: it doesn't throw any errors, but the usual UI for the script is gone (like when a component is collapsed). It's like it doesn't see the script in the files (while it's clearly there).
     
  41. mrzapp

    mrzapp

    Joined:
    May 26, 2013
    Posts:
    137
    You are right. I fixed it by exporting it to a .unitypackage. Releases are henceforth distributed as such. Thanks for your help ironing out all these bugs, much appreciated :)
     
  42. Lokkij

    Lokkij

    Joined:
    Aug 18, 2013
    Posts:
    22
    Is it possible to "clip" a UI element to a GameObject? The actual "clip to" field is limited to just ScrollViews, but is there any way to get the same effect for a GameObject?
     
  43. mrzapp

    mrzapp

    Joined:
    May 26, 2013
    Posts:
    137
    The "clipTo" variable needs to get a drawing rectangle, which is calculated by OGWidget. I could allow for you to just link that type of object instead of restricting it to OGScrollView. I'll add it to the tracker.
     
  44. MuNgLo

    MuNgLo

    Joined:
    Jan 27, 2014
    Posts:
    31
    Is it possible to make a widget object and have it track a 3d object in the scene? think healthbar above a unit in a rts or similar. I figure that would be a good featurerequest otherwise.
     
  45. mrzapp

    mrzapp

    Joined:
    May 26, 2013
    Posts:
    137
    Yeah, just position it with Camera::WorldToScreenPoint. It's in the Unity docs
     
  46. MuNgLo

    MuNgLo

    Joined:
    Jan 27, 2014
    Posts:
    31
    I was more thinking of if there where already something in OpenGUI for it. Like a premade dropin script to override the widgets position with a target objects position, maybe even scaled over distance.
     
  47. mrzapp

    mrzapp

    Joined:
    May 26, 2013
    Posts:
    137
    I agree, that would be cool :) Not so hard to do either. I'll add it to the tracker.
     
  48. Lokkij

    Lokkij

    Joined:
    Aug 18, 2013
    Posts:
    22
    Hmm, for some reason I cannot move the Root backwards (Z axis). When I change it, it immediately snaps back to z = 0. Is there a particular reason for this?
     
  49. Seth-McCumber

    Seth-McCumber

    Joined:
    May 26, 2013
    Posts:
    141
  50. mrzapp

    mrzapp

    Joined:
    May 26, 2013
    Posts:
    137
    It's a limitation of the pixel matrix set by OpenGL, it can't be below world position 0. Just move surrounding widgets back instead :)