- 创建文件流的方法
private static byte[] getImageByte(string imagePath)
{
//读取到文件
FileStream files = new FileStream(imagePath, FileMode.Open);
//新建比特流对象
byte[] imgByte = new byte[files.Length];
//将文件写入对应比特流对象
files.Read(imgByte, 0, imgByte.Length);
//关闭文件
files.Close();
//返回比特流的值
return imgByte;
}
- 读XML
using System.Xml;
private void AnalysisXml()
{
XmlDocument document = new XmlDocument(); //实例化一个xml文档
document.Load(Application.dataPath + "/Data/Dialog.xml"); //加载 XML 内容
XmlElement rootEle = document.LastChild as XmlElement; //根节点
foreach (XmlElement ele in rootEle.ChildNodes) //遍历根节点的所有子节点}
- enum 类型
public enum CommandType
{
Say, //说话
Bgm, //背景音
Bg //背景
}
- 加载场景
public void ReloadScene()
{
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex); //重载当前场景
}
- ray
Ray mRay=Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit mHi;
//判断是否击中了NPC
if(Physics.Raycast(mRay,out mHi))
RaycastHit mHit;
Ray mRay=mManager.Manager_Camera.ScreenPointToRay(Input.mousePosition);
bool isHit=Physics.Raycast(mRay,out mHit);
if(isHit && mHit.collider.gameObject.tag=="NPC")
- Rect
Rect mRect=new Rect((Screen.width-mTalkIcon.width)/2,
Screen.height-mTalkIcon.height,
mTalkIcon.width,mTalkIcon.height);
- 鼠标形状
mManager.Mangager_Cursor.SetCursor(Cursor.CursorType.Talk);
Cursor.visible=false;
mManager.Mangager_Cursor.SetCursor(Cursor.CursorType.Default);
- 距离
Transform NPC=mHit.collider.gameObject.transform;
Vector3 v1=NPC.position;
Vector3 v2=mManager.Player.position;
if(Vector3.Distance(v1,v2)<=2.0F && Input.GetMouseButtonDown(0))
- npc 朝向
//使v1,v2共面
v1=new Vector3(v1.x,0,v1.z);
v2=new Vector3(v2.x,0,v2.z);
//计算v1,v2连线的向量
Vector3 mDir=(v1-v2).normalized;
//计算NPC的旋转角度
float NpcAngle=getAngle(new Vector3(0,0,1),mDir);
float PlayerAngle=getAngle(new Vector3(0,0,1),mDir);
//将NPC旋转到面向主角
NPC.forward=mDir;
- GameManager
//获取游戏管理器
mManager=GameObject.Find("GameManager").GetComponent<GameManager>();
//设置游戏状态
mManager.SetGameState(GameState.InEvent);
- 集合 命名空间
using System.Collections.Generic; //引用集合
using UnityEngine.SceneManagement; //引用命名空间
using UnityEngine.UI; //引用UI
网友评论