纳金网
标题:
行为类的交互脚本
[打印本页]
作者:
狂风大尉
时间:
2014-6-25 01:13
标题:
行为类的交互脚本
using UnityEngine;
using System.Collections;
using System.IO;
using System.Xml;
public class Book : MonoBehaviour {
// Use this for initialization
string _FileLocation;
string _FileName = “MConfig.xml”;
string _xmlData;
XmlDocument configData;
private ArrayList pages;
public GameObject page;
private int index = 0;
private int pageLen = 0;
void Start () {
_FileLocation = Application.dataPath;
pages = new ArrayList();
LoadXML();
initBook();
}
// Update is called once per frame
void Update () {
}
void LoadXML() {
StreamReader r = File.OpenText(_FileLocation + “\\” + _FileName);
string info = r.ReadToEnd();
r.Close();
_xmlData = info;
configData = new XmlDocument();
configData.LoadXml(_xmlData);
}
void initBook() {
foreach (XmlNode item in configData.SelectNodes(“/mConfig/page”))
{
//print(item.Attributes[“murl”].Value);材质路径
GameObject obj = (GameObject)Instantiate(page);
obj.renderer.material.mainTexture = (Texture)Resources.Load(item.Attributes[“murl”].Value);
pages.Add(obj);
pageLen++;
}
}
public void PageUp(){
print(“page Up”);
}
public void PageDown() {
print(“page Down”);
}
}
复制代码
这里我们用了加载XML的方式来生成指定的书的页,那么我们如何才能控制PageUp()以及PageDown()方法呢?具体的方式是通过如下代码:
using UnityEngine;
using System.Collections;
public class NButton : MonoBehaviour {
// Use this for initialization
private Book book;
void Start () {
} Unity3D教程手册
// Update is called once per frame
void Update () {
}
void OnMouseDown() {
book = (Book)GameObject.Find(“Book”).GetComponent(typeof(Book));
book.PageDown();
}
}
复制代码
原文来自:
Unity3D教程手册:http://www.unitymanual.com/6220.html
作者:
hyui
时间:
2014-6-25 02:35
Thanks for sharing this!
作者:
wucnj
时间:
2014-6-25 09:06
感谢分享!!!
作者:
hariboot
时间:
2014-6-25 09:12
MARK THIS CONTENT
欢迎光临 纳金网 (http://rs.narkii.com/club/)
Powered by Discuz! X2.5