Hello everyone, im having some difficulties with NGUI (3.5.

We are working on applications and GUI where GUI elements should be dynamically moving here and there, new items appears, move in, move out and so on... It would be kind of hard to define all GUI in editor, as GUI have to change dynamically depending on situation. So I have to create NGUI elements from code, however i faced one problem with transform position - it is set to zero always, and im not sure how to fix it
here is my small example code:
public class GUIManager : MonoBehaviour {
private GameObject inputField;
public void LoginButtonClick()
{
Debug.Log("Login Button Clicked");
inputField
= CreateInputField
("Please Enter some text",
new Vector3
()); CreateButton
("Get Input Value",
new Vector3
(0
.0f,
-45f, 0
.0f
), PrintInputFieldValue
);
}
public GameObject CreateInputField(string baseText, Vector3 pos)
{
GameObject inputPrefab = Resources.Load<GameObject>("Prefabs/GUI/InputField");
GameObject input
= Instantiate
(inputPrefab,
new Vector3
(), transform
.rotation) as GameObject
; input.transform.position = pos;
SetTextToChiledLable(input, baseText);
return input;
}
public void CreateButton(string btnName, Vector3 pos, EventDelegate.Callback method)
{
GameObject buttonPrefab = Resources.Load<GameObject>("Prefabs/GUI/Button");
GameObject btn = Instantiate(buttonPrefab, pos, transform.rotation) as GameObject;
SetTextToChiledLable(btn, btnName);
btn
.GetComponent<UIButton
>().onClick.Add(new EventDelegate
(method
)); }
public void SetTextToChiledLable(GameObject parent, string text)
{
foreach(Transform child in parent.transform)
{
if (child.gameObject.name.Equals("Label"))
{
child.gameObject.GetComponent<UILabel>().text = text;
break;
}
}
}
public string GetTextFromChiledLable(GameObject parent)
{
foreach (Transform child in parent.transform)
{
if (child.gameObject.name.Equals("Label"))
{
return child.gameObject.GetComponent<UILabel>().text;
}
}
return "";
}
public void PrintInputFieldValue()
{
Debug.Log("Input field value was: " + inputField.GetComponent<UIInput>().value);
}
}
In 2 words:
I have static predefined button created in Editor with attached call back method: "LoginButtonClick", and predefined prefabs (button, input field).
By clicking that static button it would call: "LoginButtonClick"
which create one input field and one button where input field will be at zero coordinates and button should be a bit bellow (-45 on Y axes)
When i debug the process of creation of the button, prefab instantiated at the right position, however when item appear in the scene it already some how resets to zero, so it appears on top of input field and overlap it.
moreover setting "myButton.transform.position" to newly created button after it was placed in the scene doesn't have any effect.
So im wondering how to set position of GUI element in the script?
am also very surprised that there are so little information and tutorials on manipulations with NGUI trough script, I cant believe that most of the developers enough just in-editor gui definition.
I even have specious that im missing some concept of using NGUI and doing something wrong. or is there already some predefined helper code like "NGUI.CreateButton(btnName, callback)"
Here is logic my current test case:
Depending on application logic, i need to display NGUI elements for Login or Register actione where amount and position of elements could be different.
I know i can set all of that in editor with use of "tabs" where GUI for each tab (Login/Register) is predefined, however what if i don't want any tabs? If i need the same single screen where i would need 2 input fields(login/pass) and 2 buttons (login/Register) for Login screen and once user press "Register" add more (with nice animation: move in/move out) 3 input fields (email, name, etc..) without separate screens or tabs?
I believe that is achievable only trough script? am i right? Or im seriously missing some NGUI concept?