Beispiel #1
0
        public override void OnInspectorGUI()
        {
            base.OnInspectorGUI();

            EditorGUILayout.Space();
            MapBlock curr = mapBlockVisualizer.GetMapBlock();

            if (curr != null)
            {
                EditorGUILayout.LabelField(string.Format("当前网格 {0}", curr.name));
                EditorGUILayout.LabelField(string.Format("当前网格宽度 {0}", curr.Width));
                EditorGUILayout.LabelField(string.Format("当前网格高度 {0}", curr.Height));
            }

            EditorGUILayout.Space();
            GUILayout.BeginVertical("Box");

            width_  = EditorGUILayout.IntField("网格宽度", width_);
            height_ = EditorGUILayout.IntField("网格高度", height_);

            if (GUILayout.Button("创建网格"))
            {
                if (width_ < 16)
                {
                    width_ = 16;
                }
                if (height_ < 16)
                {
                    height_ = 16;
                }
                MapBlock mb = new MapBlock();
                mb.Init(width_, height_);
                mapBlockVisualizer.Reload(mb);
            }

            EditorGUILayout.Space();
            if (GUILayout.Button("加载数据"))
            {
                string initdir = PlayerPrefs.GetString("mbpath", Application.dataPath);
                string path    = EditorUtility.OpenFilePanel("加载数据", initdir, "bytes");
                if (path != string.Empty)
                {
                    if (File.Exists(path))
                    {
                        FileStream   fs     = File.OpenRead(path);
                        BinaryReader reader = new BinaryReader(fs);
                        MapBlock     mb     = new MapBlock();
                        if (mb.Load(reader))
                        {
                            mb.name = path;
                            mapBlockVisualizer.Reload(mb);
                        }
                        reader.Close();
                        fs.Close();
                    }
                }
            }

            EditorGUILayout.Space();
            if (GUILayout.Button("保存文件"))
            {
                MapBlock mb = mapBlockVisualizer.GetMapBlock();
                if (mb != null)
                {
                    string path = mb.name;
                    if (path == string.Empty)
                    {
                        string initdir = PlayerPrefs.GetString("mbpath", Application.dataPath);
                        path = EditorUtility.SaveFilePanel("保存文件", initdir, "a.bytes", "bytes");
                    }
                    if (path != string.Empty)
                    {
                        var fs = File.OpenWrite(path);
                        var bw = new BinaryWriter(fs);
                        mb.Save(bw);
                        bw.Close();
                        fs.Close();
                        mb.name = path;
                        Debug.LogWarningFormat("保存成功 {0}", path);
                    }
                }
            }

            GUILayout.EndVertical();
        }