Home > other >  Read from the definition document shows how this is blank
Read from the definition document shows how this is blank

Time:09-22

Five UTF document - 16 were tried, and utf-8 or not
 using UnityEngine; 
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System;
Public class xh: MonoBehaviour {
//all jokes are stored in the linked list
ArrayList info=null;
//display information
Bool button=false;
//scroll view holds a
Public Vector2 scrollPositing;
//Use this for initialization
Void the Start () {
//read the file
Info=LoadFile (Application. DataPath, "FileName0");
//initialize the scrollbar
ScrollPositing=new Vector2 (0.0 0.0 f, f);
}
/*
* the path to read the file path
* name read file name
*/
ArrayList LoadFile (string path, string name)
{
StreamReader sr=null;//use the stream
Try
{
The sr=File. OpenText (path + "//" + name);
}
The catch (Exception e)
{
//if the path and name, did not find it returns null
E. oString ();
return null;
}
string line;
ArrayList arrlist=new ArrayList ();
while ((line=sr.ReadLine()) !=null)//read the file line by line information
{
//use & amp; Separate jokes
String [] STR=line. The Split (new char [] {' & amp; '});
The foreach (string STR) in I
{
Arrlist. Add (I);//all information will be added to the list
}
}
//off flow
The sr. The Close ();
//destroy flow
The sr. The Dispose ();
//return values
Return arrlist;
}
Void OnGUI ()
{
ScrollPositing=GUILayout. BeginScrollView (scrollPositing GUILayout), Width (Screen. Width), GUILayout. Height (Screen. Height));
GUILayout. BeginHorizontal (" box ");
If (GUILayout. Button (" the first set of joke "))
{
Info=LoadFile (Application. DataPath, "FileName0");//read the file
}
If (GUILayout. Button (" the second joke "))
{
Info=LoadFile (Application. DataPath, "FileName1");
}
If (GUILayout. Button (the third group "joke"))
{
Info=LoadFile (Application. DataPath, "FileName2");
}
If (GUILayout. Button (" the fourth group joke "))
{
Info=LoadFile (Application. DataPath, "FileName3");
}
If (GUILayout. Button (" five joke "))
{
Info=LoadFile (Application. DataPath, "FileName4");
}
GUILayout. EndHorizontal ();
If (GUILayout. Button (" display content/cancel "))
{
If (button)
The button=false;
The else
The button=true;
}
//to iterate through all jokes
Int size=info. Count;
for (int i=0; i {
//get every joke all content
String text=(string) info [I];
The string in the text. The Substring (0, 10) + "... ";
GUILayout. Box (title);//show the joke title
If (button)
{
GUILayout. Label (text);
}
}
//end view
GUILayout. EndScrollView ();
}
//Update is called once per frame
Void the Update () {

}
}

CodePudding user response:

ArrayList info=null; -- -- -- -- -- -- -- & gt; ArrayList info=new ArrayList ();
  • Related