Hi
Generate a number of buttons based on XML file
The Code that generates the buttons.
The for loop doesn’t work for the buttons.
using UnityEngine;
using System.Collections;
public class Dialog : MonoBehaviour {
//textReader = GameObject.FindObjectOfType(typeof(textReader)) as textReader;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
void OnGUI (){
// Constrain all drawing to be within a 800x600 pixel area centered on the screen.
GUI.BeginGroup (new Rect (Screen.width / 2 - 400, Screen.height / 2 - 300, 800, 600));
GUI.Box (new Rect (0,0,800,600),"");
for(int x = 0;x < dtYourData.data.Rows.Count;x++)
GUI.Button(new Rect(0,x*20,20,10),textReader.option1);
GUI.EndGroup ();
//Either with a toolbar:
}
}
The code that reads the XML file, I didn’t make this one. I have done a little editing.
using UnityEngine;
using System.Collections;
using System;
using System.Data;
using System.Data.Odbc;
public class textReader : MonoBehaviour {
static public string option1;
static public string option2;
static public string option3;
static public int i = 0;
// Use this for initialization
void Start () {
readXLS(Application.dataPath + "/Book1.xls");
}
// Update is called once per frame
void Update () {
}
static public void readXLS( string filetoread)
{
// Must be saved as excel 2003 workbook, not 2007, mono issue really
string con = "Driver={Microsoft Excel Driver (*.xls)}; DriverId=790; Dbq="+filetoread+";";
//Debug.Log(con);
string yourQuery = "SELECT * FROM [Sheet1$]";
// our odbc connector
OdbcConnection oCon = new OdbcConnection(con);
// our command object
OdbcCommand oCmd = new OdbcCommand(yourQuery, oCon);
// table to hold the data
DataTable dtYourData = new DataTable("YourData");
// open the connection
oCon.Open();
// lets use a datareader to fill that table!
OdbcDataReader rData = oCmd.ExecuteReader();
// now lets blast that into the table by sheer man power!
dtYourData.Load(rData);
// close that reader!
rData.Close();
// close your connection to the spreadsheet!
oCon.Close();
// wow look at us go now! we are on a roll!!!!!
// lets now see if our table has the spreadsheet data in it, shall we?
// do something with the data here
// but how do I do this you ask??? good question!
// for giggles, lets see the column name then the data for that column!
option1 = (dtYourData.Rows[0][dtYourData.Columns*.ColumnName].ToString());*
_ option2 = (dtYourData.Rows[1][dtYourData.Columns*.ColumnName].ToString());_
_ option3 = (dtYourData.Rows[2][dtYourData.Columns.ColumnName].ToString());*_
* }*
}
So... Where is your question?
– SolvayThe for loop doesn't work for the buttons.
– Julian_Spring