Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Ncyphe · Jan 29, 2015 at 01:46 PM · c#errorguilayoutguistyle

ArgumentException: Getting control 1's position...

"ArgumentException: Getting control 1's position in a group with only 1 controls when doing Repaint"

I've searched this error and found many responses; however, the solutions some people have given have just gone over my head on how I can adapt it to my code.

A littler premise, I've been trying to create draggable window panes to create a visual Icon Represented Map Editor in Unity, and ultimately extend it to create a simple script editor for creating interactions with NPCs and entities in a game. My issue arose when I tried to stylize some buttons.

I'm gonna post some of my code.

[A WindowPane Controller] public class TAGWindowController : ScriptableObject {

     bool f_Scrollable = false; //when no window is selected ina  drag, will a drag move every window?
 
     Vector2 m_MouseOffset; //the offset the mouse was from the origin of the window
     Vector2 m_LastMousePos; //last known position of the mouse.  Used for scrolling
 
     List<TAGWindow> m_Panels = new List<TAGWindow>();
     TAGWindow m_DraggedPanel = null;    //Which window is currently being dragged
     TAGWindow m_MouseOverPanel = null;        //Which window is the mouse hovering over
     TAGWindow m_FocusedPanel = null;    //Which window is selected and focused
 
     int m_NextWindowID = 0;
 
     public void OnEnable()
     {
     }
 
 
 
     public void OnGUI()
     {
         Event e = Event.current;
         
         
         if(e.type == EventType.Repaint)
         {
         }
 
         //Reset what the mouse is over, in case it has changed
         if(m_MouseOverPanel != null)
         {
             m_MouseOverPanel.Hover = false;
 
             m_MouseOverPanel = null;
         }
 
         //Find the top most window the mouse is over
         for(int i=0; i< m_Panels.Count; i++)
         {
             //if(m_Panels[i].Contains(e.mousePosition))
             //    m_Panels[i].Hover = true;
             if(m_Panels[i].Contains(e.mousePosition))
             {
                 m_MouseOverPanel = m_Panels[i];
             }
         }
 
         //If the mouse is found over a panel, set the panel's Hover mode to true;
         if(m_MouseOverPanel!= null)
             m_MouseOverPanel.Hover = true;
         
         if(e.isMouse)
         {
             if(e.button == 0) //Left Mouse Button Selects Pane
             {
                 if(e.type == EventType.MouseDown)
                 {
                     if(m_MouseOverPanel != null)
                     {
                         m_FocusedPanel = m_MouseOverPanel;
                         m_DraggedPanel = m_MouseOverPanel;
                         m_MouseOffset = m_DraggedPanel.Position - e.mousePosition;
 
                         m_FocusedPanel.Selected = true;
                         MovePaneToTop(m_FocusedPanel);
                     }
                 }else if(e.type == EventType.MouseUp)
                 {
                     m_DraggedPanel = null;
                     //m_scrolling = false;
                     
                 }else if(e.type == EventType.MouseDrag)
                 {
                     if(m_DraggedPanel != null)
                     {
                         m_DraggedPanel.Position = e.mousePosition + m_MouseOffset;
                     }
                 }
             }else if(e.button == 1) //Right Mouse Button scrolls pane
             {
                 if(e.type == EventType.MouseDown)
                 {
                     m_LastMousePos = e.mousePosition;
                 }else if(e.type == EventType.MouseUp)
                 {
                 }else if(e.type == EventType.MouseDrag)
                 {
                     Vector2 drag = e.mousePosition - m_LastMousePos;
                     m_LastMousePos = e.mousePosition;
                     for(int i=0;i<m_Panels.Count;i++)
                     {
                         m_Panels[i].Translate(drag);
                     }
                 }
             }
 
         }
         
         for(int i=0; i< m_Panels.Count; i++)
         {
             m_Panels[i].OnGUI();
         }
 
     }
 
     public void AddWindow(TAGWindow newWindow)
     {
         newWindow.ID = m_NextWindowID++;
         m_Panels.Add(newWindow);
     }
 
     public bool Scrollable
     {
         get{
             return f_Scrollable;
         }
         set{
             f_Scrollable = value;
         }
     }
 
     public void MovePaneToTop(TAGWindow pane)
     {
         m_Panels.Remove(pane);
         m_Panels.Add(pane);
     }
 }

TAGWindow is the base class my window panes extend from public class TAGWindow : ScriptableObject {

     //public enum MouseStatusTypes{None = 0, Hover, Selected};
 
     Rect m_WindowRect = new Rect(0,0,0,0);
     Rect m_DragRect; //a position on the window that allows the window to be dragged
 
     int m_ID = -1;
 
     bool m_MouseOver = false;  //is the mouse hovering over the window
 
     //bool m_enabled = true; // is the WIndow enabled;
     bool m_Dragging = false; // is the window currently being dragged
     bool m_Focused = false;
     bool m_Selected = false;
 
     //MouseStatusTypes f_MouseStatus;

     //Getters and setters shortened for the posting
     public Vector2 Position
     public Vector2 Size
     public Rect WindowRect
     public Rect DragRect
     public bool Dragging
     public bool Focused
     public bool Hover
     public int ID
     public bool Selected

     public bool Contains(Vector2 point)
     {
         return m_WindowRect.Contains(point);
     }
 
     public bool PointInDragRect(Vector2 point)
     {
         return m_DragRect.Contains(point);
     }
 
     public void Translate(Vector2 shift) //shift the window by Vector2
     {
         m_WindowRect.position += shift;
     }
 
     public virtual void OnGUI()
     {
         Debug.Log ("A Window's OnGUI was not overriden");
     }
 
     public virtual void OnUpdate()
     {
         Debug.Log ("A Window's OnUpdate was not overriden");
     }
 }

And Finally, the main class that pieces it all together, with a custom window extending TAGWindow public class TAGMapEditor : EditorWindow {

     bool doRepaint = false;
 
     Dictionary<int,TAGWindow> Rooms = new Dictionary<int,TAGWindow>();
 
     TAGWindowController panes = CreateInstance<TAGWindowController>();
 
 
     [MenuItem("UTAG/Map Editor")]
     public static void Init()
     {
         GetWindow (typeof(TAGMapEditor)).Show ();
     }
 
     public void OnEnable()
     {
 
         RoomIcon t = CreateInstance<RoomIcon>();
         t.WindowRect = new Rect(20,20,100,100);
         t.parent = this;
         panes.AddWindow(t);
 
         t = CreateInstance<RoomIcon>();
         t.WindowRect = new Rect(20,200,200,200);
         t.parent = this;
         panes.AddWindow(t);
 
         t = CreateInstance<RoomIcon>();
         t.WindowRect = new Rect(300,300,200,100);
         t.parent = this;
         panes.AddWindow(t);
 
         panes.AddWindow(CreateInstance<Black>());
     }
 
     public void Update()
     {
         //panes.OnUpdate();
         if(doRepaint)
             Repaint();
     }
 
     public void OnGUI()
     {
         panes.OnGUI ();
         doRepaint = true;
     }
 }
 
 
 public class RoomIcon : TAGWindow
 {
     public TAGMapEditor parent = null;
 
     public override void OnGUI()
     {
         GUILayout.BeginArea(WindowRect);
         {
             if(Hover)
                 GUI.color = Color.cyan;
             else
                 GUI.color = Color.gray;
             GUI.Box(new Rect(0,0,base.Size.x,base.Size.y),"");
 
             GUILayout.BeginHorizontal("",EditorStyles.toolbarButton);
             {
                 if(GUI.Button(new Rect(0,0,30,20),base.ID.ToString(),EditorStyles.toolbarButton))
                 {
                     EditorWindow.GetWindow<TAGMapEditor>().NewPathStart(base.ID);
                 }
             }
             GUILayout.EndHorizontal();
 
         }
         GUILayout.EndArea();
     }
 }

The issues lay in the extended Window class RoomIcon. When I try to stylize the buttons, I get the error. I've tried separating different parts of code based on EvenType.Repaint and .Layout, but I still run into issues. Any help here would be very much appreciated, as I just don't know, anymore.

Edit: I've tried several different things, and the more I tried, the more I fear I'm gonna need to start over from scratch . . . again. Any assistance in this insanity would be helpful.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

2 People are following this question.

avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

[SOLVED]GUIStyle Word Wrap Check 1 Answer

Can you use GUIStyle with GUILayout? 0 Answers

Distribute terrain in zones 3 Answers

How to set GUIStyle.font 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges