纳金网

标题: MMO-简单Quest系统(原创). [打印本页]

作者: 她。    时间: 2012-8-7 10:23
标题: MMO-简单Quest系统(原创).
这部分code来自于前一段我们team的一个实验项目.希望对新手有所帮助.我写的很乱,欢迎提问.
QuestInfo.js
import System.Data;

import System.IO;
var theSourceFile: FileInfo = null;

var reader: StreamReader = null;
public var descriptionQuest: String;

public var descriptionHint: String;

public var state:int=0;

public var currentProcess:int=1;

public var currentKill:int=0;
public var dataSave:GameObject;
function Start() {

if(!dataSave.GetComponent(DataSave).isLoading){

NewLoadDescription();

}
}
function NewLoadDescription(){

state=0;

currentKill=0;

descriptionQuest=LoadDescription("Quest");

descriptionHint=LoadDescription("Hint");

}
private function LoadDescription(filetype: String): String{

var descripition: String="";
theSourceFile=null;

reader=null;
//theSourceFile = new FileInfo ("QuestDescription/"+filetype+currentProcess+".txt");

theSourceFile = new FileInfo (Application.dataPath+"/QuestDescription/"+filetype+currentProcess+".txt");

if ( theSourceFile != null && theSourceFile.Exists )

reader = theSourceFile.OpenText();
if ( reader == null )

{

Debug.Log("Quest.txt not found or not readable");

}

else

{

// Read each line from the file
descripition = reader.ReadToEnd();

//Debug.Log(descripition);

theSourceFile=null;

reader=null;

return(descripition);

}
}
function Update () {

}
GameManager.js
function OnGUI(){
//.......
if(switchWindowQuest){
windowRectQuest=GUI.Window(2,windowRectQuest,QuestWindow,"Quest");
}
if(questInfo.state>0){
if(questInfo.state==1)

{

mystyle.normal.textColor=Color.white;

}else if(questInfo.state==2)

{

mystyle.normal.textColor=Color.yellow;

}
GUI.Label(Rect(Screen.width-270,100,270,60),questInfo.descriptionHint,mystyle);

if(questInfo.currentProcess<5)

{

GUI.Label(Rect(Screen.width-100,140,100,30),"Killed "+questInfo.currentKill+" / 5 ",mystyle);

}else{

GUI.Label(Rect(Screen.width-100,140,100,30),"Killed "+questInfo.currentKill+" / 1 ",mystyle);

}

}
if(showMessage)

{

if(Time.time>=(beginTime+(messageRate/2)))

{

mystyle2.normal.textColor.a=1.0-((Time.time-(beginTime+(messageRate/2)))/(messageRate/2));

}
GUI.Label(Rect(Screen.width/2-(messageText.length/2*23),Screen.height/2-100,messageText.length*23,50),messageText,mystyle2);

}
}
function OpenQuestWindow(isopening:boolean){
if(questInfo.state==2){

Reward();

mystyle.normal.textColor=Color.white;
questInfo.currentProcess++;
questInfo.NewLoadDescription();

}
GameObject.FindGameObjectWithTag("MainCamera").GetComponent(CameraControl).CameraLock(isopening);

switchWindowQuest=isopening;
//Debug.Log("switch="+switchWindowQuest);

}
function Reward(){
playerInfo.Experience(50);

playerInfo.SkillPoint(playerInfo.SkillPoint()+1);

GetComponent(ItemInfo).Number(GetComponent(ItemInfo).Number()+10);

ShowMessage("You Got 50 experience, 10 mushRooms and 1 skillpoint.");

}
function QuestWindow(windowID: int){
GUI.Label(Rect(30,40,250,240),questInfo.descriptionQuest,mystyle);
if(questInfo.state==0){

if(GUI.Button(Rect(117,300,67,23),"Accept")){
questInfo.state=1;

OpenQuestWindow(false);

}
}else if(questInfo.state==1){

if(GUI.Button(Rect(117,300,67,23),"Abandon")){

questInfo.state=0;

questInfo.currentKill=0;

OpenQuestWindow(false);

}

}
if(GUI.Button(Rect(117,335,67,23),"Close")){
OpenQuestWindow(false);

}

GUI.DragWindow();

}
欢迎大家提问和纠正.如果觉得有所帮助,希望版主大人能给点加分和升级,我需要下载资源。U吧之前给予我很多,以后我也会继续努力发帖的.




欢迎光临 纳金网 (http://go.narkii.com/club/) Powered by Discuz! X2.5