I am trying to make a NGUI add-on for CInput 2 and when its done it will be on the asset store. It will be a free asset so if anyone could contribute code to make this possible it would be nice.
This is my start it will create a label and 2 buttons for every action set
The prefab is a panel with out the panel component then a label and 2 buttons as children.
using UnityEngine;
using System.Collections;
//Version # 0.01
//Made by Dustin Loring this is the start of adding NGUI support to CInput2
//December 23 2014
public class uilistviewscript : MonoBehaviour {
//The grid prefab
public GameObject myGrid;
//The prefab that contains the label, and 2 buttons
public GameObject myCellPrefab;
// Use this for initialization
void Start () {
//Makes all buttons so it can be set but will first clear the grid
PopulateUIGrid();
//Refreshes the grid
myGrid.GetComponent<UIGrid>().Reposition();
}
public void ClearUIGrid () {
//destories all childeren in the myGrid prefab then loop though until its done
while (myGrid.transform.childCount > 0)
NGUITools.Destroy(myGrid.transform.GetChild(0).gameObject);
}
//Used to Creat the list of key names and buttons
public void PopulateUIGrid () {
//call ClearUIGrid so that the grid is empty and we wont have doubles
ClearUIGrid ();
//Loop for all the key set up in cinput
for (int n = 0; n < cInput.length; n++) {
//The name of the input. ie.Attack, Run, Fire....
string key_name = cInput.GetText (n, 0);
//The name of the primary key. ie.w,a,s,d....
string key_one = cInput.GetText (n, 1);
//The name of the primary key. ie.Leftarrow, rightarrow....
string key_two = cInput.GetText (n, 2);
//Adds the prefab to the grid
GameObject item = NGUITools.AddChild (myGrid, myCellPrefab);
//Names the prefab you just added
item.name = key_name;
//Names the label inside the prefab you just added
item.GetComponentInChildren<UILabel>().text = key_name;
//Names the first button inside the prefab you just added
item.transform.FindChild ("Key1_Button").GetComponentInChildren<UILabel>().text = key_one;
//Names the second button inside the prefab you just added
item.transform.FindChild ("Key2_Button").GetComponentInChildren<UILabel>().text = key_two;
}
}
}
