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
↧