//每行代码的执行 public void Run() { //--代码执行准备----------------------------------------------------- RunState r = rs, pr = rs; XmlElement c = (XmlElement)r.code[r.line]; //深入当前执行的最内层,取得当前执行的代码 while (r != null) { recode: //当前层代码执行完毕 if (r.line >= r.code.Count) { if (r.prev == null) { //如果是最上层代码执行完毕,说明该behaviour执行结束 //关闭当前开启的对话框 if (GameConfig.IsMsgProcess) { GameConfig.ActiveDialog.EndMsg(); } IsRunning = false; return; } //删除该层 r.prev.NextLine(); r.prev.next = null; r = r.prev; goto recode; } c = (XmlElement)r.code[r.line]; //如果该代码属于该层 if (c.ParentNode != r.root) { r.NextLine(); goto recode; } pr = r; r = r.next; } bool MsgProccessed = false; //是否有对话框执行的操作 bool ExitMark = false; //是否有立即退出behaviour的操作 bool BlockCode = false; //是否暂停运行下一行代码 //临时变量 RPGEvent rpg = this.gameObject.GetComponent <RPGEvent>(); GameObject go = this.gameObject; //--代码本体的关键操作----------------------------------------------- //套if层到当前层的next if (c.Name == "if") { //判断时候满足if条件 if ((bool)Storage.Condition(c.GetAttribute("condition"))) { Debug.Log("enter to a new if"); pr.Append(c.GetElementsByTagName("*"), c); Run(); return; } } //退出behaviour if (c.Name == "exit") { ExitMark = true; } //--音效操作-------------------------------------------------------- //播放音效 if (c.Name == "snd") { SoundPlayer.Play(c.InnerText); } //--变量操作-------------------------------------------------------- //游戏变量操作 if (c.Name == "var") { DataCenter.Put(c.GetAttribute("tar"), Storage.Condition(c.InnerText).ToString()); } //--对话框操作------------------------------------------------------ //设置当前对话角色 if (c.Name == "chara") { Character = c.InnerText; } //发起对话框的对话 if (c.Name == "s") { GameConfig.ActiveDialog.CreateMsg(Character, Storage.Deepin(c.InnerText)); //阻止代码继续运行直到对话框被用户关闭 BlockCode = true; MsgProccessed = true; } //调查文本 if (c.Name == "a") { GameConfig.ActiveSpy.CreateSpy(Storage.Deepin(c.InnerText)); BlockCode = true; } //--人物操作------------------------------------------------------- //设置行走任务 if (c.Name == "walk") { if (c.GetAttribute("tar") != "") { rpg = GameObject.Find(c.GetAttribute("tar")).GetComponent <RPGEvent>(); } if (c.GetAttribute("x") != "") { rpg.XTask = float.Parse(Storage.Condition(c.GetAttribute("x")).ToString()); } if (c.GetAttribute("y") != "") { rpg.YTask = float.Parse(Storage.Condition(c.GetAttribute("y")).ToString()); } rpg.UnlockFreeze(); } //开始根据设定的任务行走 if (c.Name == "walktask") { //等待走完 BlockCode = true; GameConfig.WalkingTask = true; } //面向人物 if (c.Name == "fixface") { int dir = GameObject.Find("Player").GetComponent <RPGEvent>().Direction; go.GetComponent <RPGEvent>().Direction = 3 - dir; go.GetComponent <RPGEvent>().UpdateFace(); Debug.Log("Fixed face:" + (3 - dir)); } if (c.Name == "face") { if (c.GetAttribute("tar") != null) { go = GameObject.Find(c.GetAttribute("tar")); } if (go == null) { go = this.gameObject; } go.GetComponent <RPGEvent>().Direction = int.Parse(Storage.Condition(c.InnerText).ToString()); go.GetComponent <RPGEvent>().UpdateFace(); } //和指定目标对齐坐标 if (c.Name == "fix") { Vector3 otrans = this.gameObject.transform.position; Transform ttrans = GameObject.Find(c.GetAttribute("src")).transform; if (c.GetAttribute("tar").IndexOf("x") >= 0) { ttrans.position = new Vector3(otrans.x, ttrans.position.y, ttrans.position.z); } if (c.GetAttribute("tar").IndexOf("y") >= 0) { ttrans.position = new Vector3(ttrans.position.x, otrans.y, ttrans.position.z); } } //显示或隐藏目标 if (c.Name == "visible") { if (c.GetAttribute("tar") != null) { go = GameObject.Find(c.GetAttribute("tar")); } if (go == null) { go = this.gameObject; } go.SetActive((bool)Storage.Condition(c.InnerText)); } //--地图操作------------------------------------------------------- //昼夜开关 if (c.Name == "time") { if (c.InnerText == "day") { GameConfig.DayNight = 0; } if (c.InnerText == "night") { GameConfig.DayNight = 1; } } //传送 if (c.Name == "tp") { GameConfig.TpSpot = c.GetAttribute("spot"); if (GameConfig.TpSpot == null) { GameConfig.TpSpot = ""; } GameConfig.TpDir = int.Parse(Storage.Condition(c.GetAttribute("face")).ToString()); Switcher.SwitchTo(c.InnerText); } //--交易操作------------------------------------------------------- //显示售货页面 if (c.Name == "shop") { PaySystem.CreateShop(c.InnerText, c.GetAttribute("cut"), c.GetAttribute("owner"), c.GetAttribute("post")); BlockCode = true; } //--等待操作------------------------------------------------------- if (c.Name == "wait") { GameObject fab = (GameObject)Resources.Load("Prefabs\\WaitObject"); GameObject box = Instantiate(fab, new Vector3(0, 0, 0), Quaternion.identity); box.SetActive(true); Destroy(box, float.Parse(c.InnerText)); GameConfig.MsgLock = true; } if (c.Name == "newfeature") { Switcher.SwitchTo("GardenFight"); } //--存档操作------------------------------------------------------- //存入存档 if (c.Name == "save") { GameObject fab = (GameObject)Resources.Load("Prefabs\\SaveCanvas"); GameObject obj = Instantiate(fab, new Vector3(0, 0, 90), Quaternion.identity); obj.SetActive(true); obj.transform.Find("SaveWord").GetComponent <Text>().text = c.InnerText; SoundPlayer.Play("Clock"); BlockCode = true; } //--代码执行收尾---------------------------------------------------- //若对话框没有被使用,则当作废弃关闭 if (!MsgProccessed) { if (GameConfig.IsMsgProcess) { GameConfig.ActiveDialog.EndMsg(); } } //需要立即退出behaviour if (ExitMark) { IsRunning = false; return; } //跳转到下一行 pr.NextLine(); //是否挂起 if (!BlockCode) { Run(); } else { HangUp(); } }
//每行代码的执行 public void Run() { //--代码执行准备----------------------------------------------------- RunState r = rs, pr = rs; XmlElement c = (XmlElement)r.code[r.line]; //深入当前执行的最内层,取得当前执行的代码 while (r != null) { recode: //当前层代码执行完毕 if (r.line >= r.code.Count) { if (r.prev == null) { //如果是最上层代码执行完毕,说明该behaviour执行结束 //关闭当前开启的对话框 if (GameConfig.IsMsgProcess) { GameConfig.ActiveDialog.EndMsg(); } IsRunning = false; return; } //删除该层 r.prev.NextLine(); r.prev.next = null; r = r.prev; goto recode; } c = (XmlElement)r.code[r.line]; //如果该代码属于该层 if (c.ParentNode != r.root) { r.NextLine(); goto recode; } pr = r; r = r.next; } bool MsgProccessed = false; //是否有对话框执行的操作 bool ExitMark = false; //是否有立即退出behaviour的操作 bool BlockCode = false; //是否暂停运行下一行代码 //临时变量 RPGEvent rpg = this.gameObject.GetComponent <RPGEvent>(); GameObject go = this.gameObject; //--代码本体的关键操作----------------------------------------------- //套if层到当前层的next if (c.Name == "if") { //判断时候满足if条件 if ((bool)Storage.Condition(c.GetAttribute("condition"))) { Debug.Log("enter to a new if"); pr.Append(c.GetElementsByTagName("*"), c); Run(); return; } } //退出behaviour if (c.Name == "exit") { ExitMark = true; } //--变量操作-------------------------------------------------------- //游戏变量操作 if (c.Name == "var") { Storage.Set(c.GetAttribute("tar"), Storage.Condition(c.InnerText).ToString()); } //--对话框操作------------------------------------------------------ //设置当前对话角色 if (c.Name == "chara") { Character = c.InnerText; } //发起对话框的对话 if (c.Name == "s") { GameConfig.ActiveDialog.CreateMsg(Character, Storage.Deepin(c.InnerText)); //阻止代码继续运行直到对话框被用户关闭 BlockCode = true; MsgProccessed = true; } //调查文本 if (c.Name == "a") { GameConfig.ActiveSpy.CreateSpy(Storage.Deepin(c.InnerText)); BlockCode = true; } //--人物操作------------------------------------------------------- //设置行走任务 if (c.Name == "walk") { if (c.GetAttribute("tar") != "") { rpg = GameObject.Find(c.GetAttribute("tar")).GetComponent <RPGEvent>(); } if (c.GetAttribute("x") != "") { rpg.XTask = float.Parse(Storage.Condition(c.GetAttribute("x")).ToString()); } if (c.GetAttribute("y") != "") { rpg.YTask = float.Parse(Storage.Condition(c.GetAttribute("y")).ToString()); } } //开始根据设定的任务行走 if (c.Name == "walktask") { //等待走完 BlockCode = true; GameConfig.WalkingTask = true; } //和指定目标对齐坐标 if (c.Name == "fix") { Vector3 otrans = this.gameObject.transform.position; Transform ttrans = GameObject.Find(c.GetAttribute("src")).transform; if (c.GetAttribute("tar").IndexOf("x") >= 0) { ttrans.position = new Vector3(otrans.x, ttrans.position.y, ttrans.position.z); } if (c.GetAttribute("tar").IndexOf("y") >= 0) { ttrans.position = new Vector3(ttrans.position.x, otrans.y, ttrans.position.z); } } //显示或隐藏目标 if (c.Name == "visible") { if (c.GetAttribute("tar") != null) { go = GameObject.Find(c.GetAttribute("tar")); } go.SetActive((bool)Storage.Condition(c.InnerText)); } //--地图操作------------------------------------------------------- //昼夜开关 if (c.Name == "time") { if (c.InnerText == "day") { GameConfig.DayNight = 0; } if (c.InnerText == "night") { GameConfig.DayNight = 1; } } //传送 if (c.Name == "tp") { GameConfig.TpSpot = c.GetAttribute("spot"); if (GameConfig.TpSpot == null) { GameConfig.TpSpot = ""; } GameConfig.TpDir = int.Parse(Storage.Condition(c.GetAttribute("face")).ToString()); Switcher.SwitchTo(c.InnerText); } //--代码执行收尾---------------------------------------------------- //若对话框没有被使用,则当作废弃关闭 if (!MsgProccessed) { if (GameConfig.IsMsgProcess) { GameConfig.ActiveDialog.EndMsg(); } } //需要立即退出behaviour if (ExitMark) { IsRunning = false; return; } //跳转到下一行 pr.NextLine(); //是否挂起 if (!BlockCode) { Run(); } else { HangUp(); } }