Search Unity

SimpleGUI (WiP)

Discussion in 'Works In Progress - Archive' started by IzzySoft, Feb 22, 2014.

  1. IzzySoft

    IzzySoft

    Joined:
    Feb 11, 2013
    Posts:
    376
    What does it do?
    I planned to use a single texture atlas that contained multiple button backgrounds, and allow the user to visually setup the 9 Slices (as well as other settings later). This is still in the planning / prototyping stages.

    Why did I make it?
    It was my 1st attempt at working with Unity3D and i'm trying to learn how the Unity Editor worked. Not to mention, my own frustration with Unity3D in not being able to visually see how the GUIStyle Borders are actually affecting the button slicing. It was all guessing game until i got what i was looking for. :/ But thats for 2D GUI, this is for 3D GUI though, but most of the same concepts still apply for 9 Sliced control texture backgrounds.

    What sets it apart from the rest?
    I made it for myself. ;) And since i'm a visual kinda guy, I want to visually see and edit things about the Style... in this case, its the Border Style of the controls background. And I wanted to use a single texture atlas to define a larger number of backgrounds, including the different states like the default idle (or Normal) state, Pressed down state, Hover Over state, currently Focused control state, and something that i wish was part of the GUIStyle... ability to set the background/style for a Disabled state.

    How far have I gotten?
    I'm working on the tough stuff now, and just finished the Pan and Zoom portion of the editor which allows the users to define the 9 Slices Visually using a number of grab handles.


    Currently this is what the Editor looks like (could change later):


    How do I add Undo/Redo support?
    After struggling with the in-built Undo and trying to tell the difference between my Undo's apart from Undo's performed in the Scene view (or other views), i gave up on trying to use Undo.RegisterUndo... and started working on a custom undo for my Editor Window.

    In this screencast, i try and show my 1st attempt / progress with adding custom Undo/Redo features.


    Tell me what your impressions are. ;)

    Thanks. ;D
     
    Last edited: Mar 4, 2014
  2. IzzySoft

    IzzySoft

    Joined:
    Feb 11, 2013
    Posts:
    376
    Progress Update for the Undo / Redo features:

     
    Last edited: Jun 5, 2014
  3. IzzySoft

    IzzySoft

    Joined:
    Feb 11, 2013
    Posts:
    376
    Lenghty Progress update

    Shows work done for the Scene View and showing texture in the Game View as pixel perfect.



    Feedback / questions are welcome. ;)

    Thanks.
     
    Last edited: Jun 5, 2014
  4. IzzySoft

    IzzySoft

    Joined:
    Feb 11, 2013
    Posts:
    376
    Still working on the Scene View group handles...



    So..
    bottom left: looks like a square, but has 1/4 eaten away, and Moves the while Group area.
    top left: looks like a circle, but has 1/4 eaten away, and might be used to Rotate a GUI Control... not sure if a GUI Group needs to be rotated?!?
    four sides: arrows used to resize the GUI Group or GUI Control (when able to, if auto Resize To not set to say the GameView)

    Also...



    trying out some different grid designs. just wanted to see how it would look. ;)

    Suggestions, Comments are appreciated allot.
    Thanks. :)
     
  5. IzzySoft

    IzzySoft

    Joined:
    Feb 11, 2013
    Posts:
    376
    Super Short update: (added a Layout Component)

     
    Last edited: Jun 5, 2014
  6. IzzySoft

    IzzySoft

    Joined:
    Feb 11, 2013
    Posts:
    376
     
    Last edited: Jun 5, 2014
  7. IzzySoft

    IzzySoft

    Joined:
    Feb 11, 2013
    Posts:
    376
  8. IzzySoft

    IzzySoft

    Joined:
    Feb 11, 2013
    Posts:
    376
  9. IzzySoft

    IzzySoft

    Joined:
    Feb 11, 2013
    Posts:
    376
    Ahhh.. I think i have a good workaround to the EditorGUILayout.IntField().

    Problem?
    - I couldnt set the Width of the Label thats drawn by EditorGUILayout.IntField()

    - Solution:
    Code (CSharp):
    1.  
    2. static void OnInspGUI_DrawIntLabel( GUIContent contLabel, ref int Value, int nLabelWidth, int nIntFieldWidth )
    3.     {
    4.         Rect rectLabel = GUILayoutUtility.GetRect( contLabel, (GUIStyle)"label", GUILayout.Width( nLabelWidth ) );
    5.         rectLabel.width += 3;
    6.         GUI.Label( rectLabel, contLabel );
    7.         Value = EditorGUILayout.IntField( Value, GUILayout.Width( nIntFieldWidth ) );
    8.  
    9.         int nDiff = 0;
    10.  
    11.         Event evt = Event.current;
    12.         bool isMouseOver = rectLabel.Contains( evt.mousePosition );
    13.         int control_ID = GUIUtility.GetControlID( contLabel, FocusType.Native );
    14.         EventType eType = evt.GetTypeForControl( control_ID );
    15.  
    16.         switch( eType ) {
    17.         case EventType.MouseDown:
    18.             if( isMouseOver )
    19.             {
    20.                 current_IntLabel_ID = control_ID;
    21.                 v2_IntLabel_mouseDown.x = evt.mousePosition.x;
    22.                 v2_IntLabel_mouseDown.y = evt.mousePosition.y;
    23.                 evt.Use();
    24.             }
    25.             break;
    26.      
    27.         case EventType.MouseUp:
    28.             if( current_IntLabel_ID != -10000 )
    29.             {
    30.                 v2_IntLabel_mouseDown.x = -10000;
    31.                 v2_IntLabel_mouseDown.y = -10000;
    32.                 current_IntLabel_ID = -10000;
    33.                 evt.Use();
    34.             }
    35.             break;
    36.      
    37.         case EventType.MouseDrag:
    38.             if( current_IntLabel_ID == control_ID )
    39.             {
    40.                 nDiff = (int)(evt.mousePosition.x - v2_IntLabel_mouseDown.x);
    41.                 v2_IntLabel_mouseDown.x = evt.mousePosition.x;
    42.                 v2_IntLabel_mouseDown.y = evt.mousePosition.y;
    43.  
    44.                 if (nDiff != 0) { Value += nDiff; GUI.changed = true; }
    45.                 evt.Use();
    46.             }
    47.             break;
    48.  
    49.         case EventType.Repaint:
    50.             //if( isMouseOver )
    51.             //{
    52.                 EditorGUIUtility.AddCursorRect( rectLabel,  MouseCursor.SlideArrow, control_ID );
    53.                 //evt.Use();
    54.             //}
    55.             break;
    56.         }
    57.     }
    58.  
    And when I call it on WIDTH, Height still using .IntField()
    this is what i get now. You can left click drag the mouse while over the label to change the Int Value.



    End Result:



    Rate, Comment, Like, Subscribe, Tweet, Friend. ;D
     
    Last edited: Oct 31, 2014
  10. IzzySoft

    IzzySoft

    Joined:
    Feb 11, 2013
    Posts:
    376
    Also,

    Instead of having a Gazillion Icons that do different things in the Hierarchy for a Game Object... just have one icon that shows a context menu? :)

    ex: Left Click on the Cog (with the down arrow) and it shows a context menu?

     
  11. IzzySoft

    IzzySoft

    Joined:
    Feb 11, 2013
    Posts:
    376
    Bitmap Fonts example...