• 大小: 28.72MB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2023-08-02
  • 语言: 其他
  • 标签: 保卫萝卜  

资源简介

unity保卫萝卜工程文件,包含资源代码 !

资源截图

代码片段和文件信息

using UnityEngine;
using UnityEditor;
using System.IO;
using System.Collections;
using System.Collections.Generic;

[CustomEditor(typeof(Map))]
public class MapEditor : Editor
{
    [HideInInspector]
    public Map Map = null;

    //关卡列表
    List m_files = new List();

    //当前编辑的关卡索引号
    int m_selectIndex = -1;
    
    public override void OnInspectorGUI()
    {
        base.OnInspectorGUI();

        if(Application.isPlaying)
        {
            //关联的Mono脚本组件
            Map = target as Map;

            EditorGUILayout.BeginHorizontal();
            int currentIndex = EditorGUILayout.Popup(m_selectIndex GetNames(m_files));
            if (currentIndex != m_selectIndex)
            {
                m_selectIndex = currentIndex;

                //加载关卡
                LoadLevel();
            }
            if (GUILayout.Button(“读取列表“))
            {
                //读取关卡列表
                LoadLevelFiles();
            }
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            if (GUILayout.Button(“清除塔点“))
            {
                Map.ClearHolder();
            }
            if (GUILayout.Button(“清除路径“))
            {
                Map.ClearRoad();
            }
            EditorGUILayout.EndHorizontal();

            if (GUILayout.Button(“保存数据“))
            {
                //保存关卡
                SaveLevel();
            }
        }

        if (GUI.changed)
            EditorUtility.SetDirty(target);
    }

    void LoadLevelFiles()
    {
        //清除状态
        Clear();

        //加载列表
        m_files = Tools.GetLevelFiles();

        //默认加载第一个关卡
        if (m_files.Count > 0)
        {
            m_selectIndex = 0;
            LoadLevel();
        }
    }

    void LoadLevel()
    {
        FileInfo file = m_files[m_selectIndex];

        Level level = new Level();
        Tools.FillLevel(file.FullName ref level);

        Map.LoadLevel(level);
    }

    void SaveLevel()
    {
        //获取当前加载的关卡
        Level level = Map.Level;

        //临时索引点
        List list = null;

        //收集放塔点
        list = new List();
        for (int i = 0; i < Map.Grid.Count; i++)
        {
            Tile t = Map.Grid[i];
            if (t.CanHold)
            {
                Point p = new Point(t.X t.Y);
                list.Add(p);
            }
        }
        level.Holder = list;

        //收集寻路点
        list = new List();
        for (int i = 0; i < Map.Road.Count; i++)
        {
            Tile t = Map.Road[i];
            Point p = new Point(t.X t.Y);
            list.Add(p);
        }
        level.Path = list;

        //路径
        string fileName = m_files[m_selectIndex].FullName;

        //保存关卡
        Tools.SaveLevel(fileName level);

        //弹框提示
        EditorUtility.DisplayDialog(“保存关卡数据“ “保存成功“ “确定

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件       3578  2016-10-26 21:19  CarrotFantasy\Assets\Editor\MapEditor.cs

    ..A..H.       262  2016-04-17 21:34  CarrotFantasy\Assets\Editor\MapEditor.cs.meta

    ..A..H.       191  2016-03-06 11:05  CarrotFantasy\Assets\Editor.meta

    I.A....      7532  2016-10-23 11:58  CarrotFantasy\Assets\Game\Resources\Prefabs\BallBullet.prefab

    ..A..H.       179  2016-10-22 21:10  CarrotFantasy\Assets\Game\Resources\Prefabs\BallBullet.prefab.meta

    I.A....      7844  2016-10-23 10:40  CarrotFantasy\Assets\Game\Resources\Prefabs\Bottle.prefab

    ..A..H.       179  2016-08-06 18:02  CarrotFantasy\Assets\Game\Resources\Prefabs\Bottle.prefab.meta

    I.A....      7492  2016-10-23 11:38  CarrotFantasy\Assets\Game\Resources\Prefabs\Fan.prefab

    ..A..H.       179  2016-10-23 11:00  CarrotFantasy\Assets\Game\Resources\Prefabs\Fan.prefab.meta

    I.A....      7572  2016-10-23 11:56  CarrotFantasy\Assets\Game\Resources\Prefabs\FanBullet.prefab

    ..A..H.       179  2016-10-23 11:00  CarrotFantasy\Assets\Game\Resources\Prefabs\FanBullet.prefab.meta

    I.A....      7500  2016-07-31 21:21  CarrotFantasy\Assets\Game\Resources\Prefabs\Luobo.prefab

    ..A..H.       179  2016-07-31 18:25  CarrotFantasy\Assets\Game\Resources\Prefabs\Luobo.prefab.meta

    I.A....      8196  2016-08-07 17:03  CarrotFantasy\Assets\Game\Resources\Prefabs\Map.prefab

    ..A..H.       179  2016-05-08 20:05  CarrotFantasy\Assets\Game\Resources\Prefabs\Map.prefab.meta

    I.A....      7604  2016-08-07 17:28  CarrotFantasy\Assets\Game\Resources\Prefabs\Monster0.prefab

    ..A..H.       179  2016-06-11 16:10  CarrotFantasy\Assets\Game\Resources\Prefabs\Monster0.prefab.meta

    I.A....      7604  2016-08-07 17:28  CarrotFantasy\Assets\Game\Resources\Prefabs\Monster1.prefab

    ..A..H.       179  2016-06-11 16:11  CarrotFantasy\Assets\Game\Resources\Prefabs\Monster1.prefab.meta

    I.A....      7604  2016-08-07 17:28  CarrotFantasy\Assets\Game\Resources\Prefabs\Monster2.prefab

    ..A..H.       179  2016-06-11 16:13  CarrotFantasy\Assets\Game\Resources\Prefabs\Monster2.prefab.meta

    I.A....      7604  2016-08-07 17:28  CarrotFantasy\Assets\Game\Resources\Prefabs\Monster3.prefab

    ..A..H.       179  2016-06-11 16:14  CarrotFantasy\Assets\Game\Resources\Prefabs\Monster3.prefab.meta

    I.A....      7604  2016-08-07 17:28  CarrotFantasy\Assets\Game\Resources\Prefabs\Monster4.prefab

    ..A..H.       179  2016-06-11 16:15  CarrotFantasy\Assets\Game\Resources\Prefabs\Monster4.prefab.meta

    I.A....      7604  2016-08-07 17:28  CarrotFantasy\Assets\Game\Resources\Prefabs\Monster5.prefab

    ..A..H.       179  2016-06-11 16:16  CarrotFantasy\Assets\Game\Resources\Prefabs\Monster5.prefab.meta

    I.A....      8700  2016-08-21 20:31  CarrotFantasy\Assets\Game\Resources\Prefabs\TowerCreator.prefab

    ..A..H.       179  2016-08-06 19:43  CarrotFantasy\Assets\Game\Resources\Prefabs\TowerCreator.prefab.meta

    I.A....      8724  2016-08-21 20:31  CarrotFantasy\Assets\Game\Resources\Prefabs\TowerUpgrade.prefab

............此处省略2549个文件信息

评论

共有 条评论