資源簡介
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?????????{
????????????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?????????{
????????????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.me
????..A..H.???????191??2016-03-06?11:05??CarrotFantasy\Assets\Editor.me
????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.me
????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.me
????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.me
????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.me
????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.me
????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.me
????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.me
????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.me
????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.me
????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.me
????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.me
????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.me
????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.me
????I.A....??????8724??2016-08-21?20:31??CarrotFantasy\Assets\Game\Resources\Prefabs\TowerUpgrade.prefab
............此處省略2549個文件信息
評論
共有 條評論