Unity实现RPG角色对话框
来源:互联网 发布:淘宝网电影票 编辑:程序博客网 时间:2024/03/29 21:32
因为打算制作一款RPG类的游戏demo,所以在制作的时候,会考虑到加入角色对话与剧情系统,本来是打算使用插件来做,但是又不想了。
主要的思路相信很多人在各类博客上也都有看到过,从xml文件中解析文本,然后添加到对话框中,并且显示出来,接下来我们就来实现
第一步 UI的实现
这里我做的比较简单,仅仅使用了一个panel与text,来制作了一个简单的对话框效果,然后将其重命名后制作成预置
第二步 UI的管理代码
有关UI的管理,我们要做的就是实现UI的显示,文本内容的控制,UI的消失,以及对对话框是否存在的判断,这里我命名为Dialogmanger.cs
using System.Collections;using System.Collections.Generic;using UnityEngine;using UnityEngine.UI;public class Dialogmanger : MonoBehaviour { private static Dialogmanger instance; public GameObject DialogBox; //用于保存对话框的预置体 public GameObject Dialog; //用于获取场景组件中的对话框 public Transform DialogText; //文本 /// <summary> /// 单例 /// </summary> /// <value>The instance.</value> public static Dialogmanger Instance{ get { if(instance == null) { instance = new Dialogmanger(); } return instance; } } /// <summary> /// Shows the dialog. /// </summary> public void showDialog( ){ DialogBox = Resources.Load<GameObject> ("prefebs/Dialogbox"); Instantiate (DialogBox); } /// <summary> /// Sets the dialog text. /// </summary> /// <param name="sentence">Sentence.</param> public void setDialogText(string sentence){ if (GameObject.Find ("Dialogbox(Clone)")) { Dialog = GameObject.Find ("Dialogbox(Clone)"); DialogText = Dialog.transform.Find ("dialogText"); Text dialogtext = DialogText.GetComponent<Text> (); dialogtext.text = sentence; } } /// <summary> /// Destories the dialog. /// </summary> public void DestoryDiaLog(){ if (GameObject.Find ("Dialogbox(Clone)")) { Dialog = GameObject.Find ("Dialogbox(Clone)"); Destroy (Dialog); } } /// <summary> /// Determines whether this instance is empty dialog. /// </summary> /// <returns><c>true</c> if this instance is empty dialog; otherwise, <c>false</c>.</returns> public bool IsEmptyDialog(){ if (GameObject.Find ("Dialogbox(Clone)")) { return false; }else{ return true; } }}
地址:git@code.csdn.net:snippets/2593111.git
第三步 对XML文件的解析
using System.Collections;using System.Collections.Generic;using UnityEngine;using System.Xml;public class XmlReader : MonoBehaviour { private static XmlDocument XMLDout; private static XmlReader instance; private int Index; private string TAG; public static XmlReader Instance{ get { if(instance == null) { instance = new XmlReader(); } return instance; } } public void readXML(string path){ XMLDout = new XmlDocument (); string url=Application.dataPath+"/"+path; XMLDout.Load (url); } public int getCout(string tag,int index){ Index = index; TAG = tag; int inCout = XMLDout.GetElementsByTagName (tag) [index].ChildNodes.Count; return inCout; } public string getXML(string tag,int cout){ string xml= XMLDout.GetElementsByTagName (tag) [Index].ChildNodes [cout].InnerText; return xml; }}
地址:git@code.csdn.net:snippets/2593113.git
最后就是主要的逻辑实现
XML的文件如此
<?xml version="1.0" encoding="utf-8"?> <Xml> <JD> <Name>云天河:还记得吗?我们第一次来树屋时,我说以后要到山上隐居,不问江湖世事,那些……都还想是昨天的情景,可仔细想想,原来已经过了那么久啊,发生了好多好多的事……</Name> <X>韩菱纱:我只想找个地方,静静了结自己的生命……日子久了,你和紫英会慢慢把我忘记的,忘记了,就不会伤心了……</X> <Y>云天河:可是,人一旦要死了,发而会多很多牵挂,想起以前的事……</Y> </JD> </Xml>
主要逻辑在下方连接
git@code.csdn.net:snippets/2593106.git
对话框的功能基本就实现了
后面还会实现更多的功能,现在列一个列表
1.UI对话框
2.剧情系统
3.背包系统
4.打怪以及被怪物追着打
5.与node服务器结合
目前就想到那么多..
阅读全文
0 0
- Unity实现RPG角色对话框
- [Unity&RPG]实现简单的鼠标点击移动 角色
- Unity RPG游戏角色残影效果如何实现
- 【unity学习笔记】手机RPG游戏中角色移动方式实现
- RPG角色
- Unity实现第三人称角色控制
- RPG角色生成器
- RPG角色生成器
- RPG角色生成器
- rpg角色生成器
- RPG角色生成器
- RPG角色生成器
- (MFC)RPG角色生成器
- RPG简单角色加载
- 利用NGUI与XML实现RPG游戏对话框
- Unity NGUI实现角色名追随角色移动
- unity 角色死亡界面变灰实现
- Unity Player角色移动控制脚本实现
- 网络判断
- noip2017提高组初赛答案
- CSDN-markdown编辑器手册
- Git-------(1)如何用Git拷贝项目
- Linux中对文件以及目录的基础操作
- Unity实现RPG角色对话框
- 【Ubuntu】Ubuntu设置和查看环境变量
- D6逻辑运算符
- Linux Unit4--用户管理
- OS简史
- python高效编程技巧2(如何为元组的每个元素命名,提高程序的可读性)
- python 列表的使用总结
- CSRF攻击和XSS攻击
- IntelliJ IDEA @Test不提示导包的问题