有了前面三章的学习,我们试着做一个小游戏来强化学习的技术,比如做一个 推箱子Sokoban 游戏;
一.由于每关地图不一样,首先得想到的是做一个地图关卡编辑器
(很多类容都要用到前一章知识:
https://blog.youkuaiyun.com/mww584161068/article/details/79986005)
(由于没有美工给图,随便将就用点图,以实现功能为主)
1,把图都做成预制体。
2.然后编辑需要加载这些预制体的脚本
(借助前一章的一些脚本,就不贴了
https://blog.youkuaiyun.com/mww584161068/article/details/79986005)
public class MapEditor :ViewEditor {
static int selectMum;
static int widthMum=1;
static int heightMum=1;
GameObject wallH;
GameObject wallV;
GameObject leftUp;
GameObject rightUp;
GameObject rightDown;
GameObject leftDown;
GameObject light;
GameObject dark;
protected override void OnGUI()
{
if (MwwWindow.instance != null)
{
selectMum = MwwWindow.instance.DrawViewSelect<MapEditor>(selectMum);
EditorGUILayout.Space();
widthMum = EditorGUILayout.IntField("宽度:", widthMum);
heightMum = EditorGUILayout.IntField("高度:", heightMum);
EditorGUILayout.Space();
EditorGUILayout.Space();
if (GUILayout.Button("生成边框"))
{
Create();
}
}
}
void Init()
{
wallH= (GameObject)Resources.Load("Prefab/H", typeof(GameObject));
wallV = (GameObject)Resources.Load("Prefab/V", typeof(GameObject));
leftUp= (GameObject)Resources.Load("Prefab/left_up", typeof(GameObject));
rightUp= (GameObject)Resources.Load("Prefab/right_up", typeof(GameObject));
rightDown = (GameObject)Resources.Load("Prefab/right_down", typeof(GameObject));
leftDown= (GameObject)Resources.Load("Prefab/left_down", typeof(GameObject));
light = (GameObject)Resources.Load("Prefab/light", typeof(GameObject));
dark = (GameObject)Resources.Load("Prefab/dark", typeof(GameObject));
}
const float leftUp_wallH_V = 0.03f;
const float leftUp_wallH=0.59f;
const float