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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by javydreamercsw · Sep 15, 2014 at 03:33 PM · guicustomcollapse

How to relocate components dynamically?

I have a series of TextAreas folded with EditorGUI.Foldout. This works fine but I would like to push the following foldouts when I open one above them. So I use an array of Rect when I create them so I could hopefully modify those making components move but it doesn't seem to work.

I'm a unity3d and C# newbie so bare with me with the code:

     using UnityEngine;
     using UnityEditor;
     using System.Collections;
     
     public class PageViewer : MonoBehaviour {
         public float x;
         public float y;
         //Store the field values for CRUD operations.
         private string[] variables = new string[]{
             "",
             "",
             "",
             "",
             ""
             };
         //This handles the collapsable status for each field.
         private bool[] status = new bool[]{
             false,
             false,
             false,
             false,
             false
         };
         //Position of fields for dynamic display.
         private Rect[] positions = new Rect[]{
             new Rect(),
             new Rect(),
             new Rect(),
             new Rect(),
             new Rect()
         };
         public int gap;
         public float height;
         public float width;
         public Page original, mod;
         private Vector2 scrollPosition;
     
         // Use this for initialization
         void Start () {
         }
     
         private void OnGUI(){
             float newy = y + gap;
             int index = 0;
             
             createEditableTextArea(x, newy, gap, width, 30, "X", index++);
             
             newy += gap * 2 + 30;
             createEditableTextArea (x, newy, gap, width, height + 120, "Y", index++);
             
             newy += gap * 2 + height + 120;
             createEditableTextArea (x, newy, gap, width, height, "Z", index++);
             
             newy += gap * 2 + height;
             createEditableTextArea (x, newy, gap, width, height, "A", index++);
             
             newy += gap * 2 + height;
             createEditableTextArea (x, newy, gap, width, height, "B", index++);
             }
     
         public void createEditableTextArea(float x, float y, int gap, float width, 
                                            float height, string description,int index){
             positions [index] = new Rect (x, y, width, height);
             status [index] = EditorGUI.Foldout (new Rect (x - gap, index * 30, width
                             + (gap * 2), 30), status [index], description);
             if (status [index]) {
                 GUI.Box (new Rect (x - gap, y - gap, width + (gap * 2), 
                                    height + (gap * 2)), description);
                 variables [index] = GUI.TextArea (positions [index], 
                                       variables [index]);
                 Debug.Log("Opened: "+description);
                 //Move the following fileds down
                 for(int i=index+1;i<positions.Length;i++){
                     float ny=y+height+gap;
                     Debug.Log("Updating position index: "+i+" from: "+positions[i].y+" to: "+ny);
                     positions[i].x=0;
                 }
             } 
         }
 }

I was expecting the components to move to x=0 but nothing happened. Any idea?

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

GUI Skin Custom textures in C# 2 Answers

Custom Material Editor 1 Answer

How do you get the default inspector to draw for Prefabs ? 2 Answers

GameObjects with custom properties into a GUI textbox. 0 Answers

Using different custom inspectorscripts 1 Answer


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