Пример #1
0
    public void Clone(Mode mode)
    {
        var layers = _tileMapTarget.Layers;

        for (int l = 0; l < layers.Length; l++)
        {
            var layer = layers[l];

            for (int w = 0; w < _tileMapTarget.width; w++)
            {
                for (int h = 0; h < _tileMapTarget.height; h++)
                {
                    var tileId = _tileMapTarget.GetTile(w, h, l);

                    if (tileId != -1)
                    {
                        var tileInfo = _tileMapTarget.GetTileInfoForTileId(tileId);

                        if (tileInfo.stringVal == "n")
                        {
                            continue;
                        }

                        var nameIndex = _targetNameIndexes[tileId];

                        var tileToChange = 0;

                        if (tileInfo.stringVal == "c")
                        {
                            tileToChange = getSpriteId("tileset/" + tileInfo.intVal);
                        }

                        if (tileInfo.stringVal == "")
                        {
                            tileToChange = getSpriteId("tileset/" + (nameIndex + _offset));
                        }

                        switch (mode)
                        {
                        case Mode.Safe:
                            cloneSafe(tileId, tileToChange, w, h, l);
                            break;

                        case Mode.Override:
                            cloneOverride(tileToChange, w, h, l);
                            break;

                        case Mode.SafeOverride:
                            cloneSafeAdd(tileId, tileToChange, w, h, l);
                            break;
                        }
                    }
                }
            }
        }

        _tileMap.Build();
    }
Пример #2
0
    // Update is called once per frame
    void Update()
    {
        Debug.Log(tilemap.GetTile(1, 1, 3));

        tilemap.ClearTile(1, 1, 3);
        tilemap.Build();
    }
Пример #3
0
    private void cloneSafe(int otherTileId, int tileToChange, int x, int y, int layer)
    {
        var targetTileId = _tileMapTarget.GetTile(x, y, layer);
        var myTileId     = _tileMap.GetTile(x, y, layer);

        var targetNameIndex = _targetNameIndexes[targetTileId];
        var myNameIndex     = _myNameIndexes[targetTileId];

        var targetTileName = "tileset/" + targetTileId;
        var myTileName     = "tileset/" + myTileId;

        if (targetTileName == myTileName)
        {
            _tileMap.SetTile(x, y, layer, tileToChange);
        }
    }
        public bool IsWallAtCoords(Coordinates coords)
        {
            if (coords.x < 0 || coords.x >= map.width || coords.y < 0 || coords.y >= map.height)
            {
                //			print("Coords out of bounds : " + coords.ToString());
                return(false);
            }
            int wall = map.GetTile(coords.x, coords.y, wallLayer);

            if (wall == -1)
            {
                return(false);
            }
            return(true);
        }
Пример #5
0
 //保存当前tilemap的数据为一个字符串,格式与CVS相同
 public string SaveTileMap(tk2dTileMap tk2dTM, int layerID)
 {
     try
     {
         string result = "";
         width  = tk2dTM.width;
         height = tk2dTM.height;
         //根据tilemap的宽度和高度初始化tileID数组
         tileID = new int[width, height];
         //从第一行开始,依次读取每一行,即row
         for (int y = 0; y < height; y++)
         {
             //从第一列开始,一次读取每一列,即column
             for (int x = 0; x < width; x++)
             {
                 //因为tk2dTileMap与Tiled的坐标系不同,y正好是相反的,所以从tk2dTileMap中取tileID时,y的值为height-1-y
                 tileID[x, y] = tk2dTM.GetTile(x, height - 1 - y, layerID);
                 //如果没有达到tilemap的宽度,则添加 "," 区分每一个tile
                 if (x != width - 1)
                 {
                     result += tileID[x, y].ToString() + ",";
                 }
                 //否则,一行完成后,进行换行
                 else
                 {
                     result += tileID[x, y].ToString() + "\r\n";
                 }
             }
         }
         return(result);
     }
     catch
     {
         //throw;
         return("");
     }
 }
		/// <summary>
		/// Moves the chunk's gameobject's children to the prefab root
		/// </summary>
		public static void HideTileMapPrefabs(tk2dTileMap tileMap) {
			if (tileMap.renderData == null || tileMap.Layers == null) {
				// No Render Data to parent Prefab Root to
				return;
			}

			if (tileMap.PrefabsRoot == null) {
				var go = tileMap.PrefabsRoot = tk2dUtil.CreateGameObject("Prefabs");
				go.transform.parent = tileMap.renderData.transform;
				go.transform.localPosition = Vector3.zero;
				go.transform.localRotation = Quaternion.identity;
				go.transform.localScale = Vector3.one;
			}

			int instListCount = tileMap.GetTilePrefabsListCount();
			bool[] instExists = new bool[instListCount];

			for (int i = 0; i < tileMap.Layers.Length; ++i) {
				var layer = tileMap.Layers[i];
				for (int j = 0; j < layer.spriteChannel.chunks.Length; ++j) {
					var chunk = layer.spriteChannel.chunks[j];
					if (chunk.gameObject == null)
						continue;

					var t = chunk.gameObject.transform;
					int childCount = t.childCount;
					for (int k = 0; k < childCount; ++k) {
						GameObject go = t.GetChild(k).gameObject;
						for (int q = 0; q < instListCount; ++q) {
							int x, y, layerIdx;
							GameObject instance;
							tileMap.GetTilePrefabsListItem(q, out x, out y, out layerIdx, out instance);
							if (instance == go) {
								instExists[q] = true;
								break;
							}
						}
					}
				}
			}

			Object[] prefabs = tileMap.data.tilePrefabs;
			List<int> tileX = new List<int>();
			List<int> tileY = new List<int>();
			List<int> tileLayer = new List<int>();
			List<GameObject> tileInst = new List<GameObject>();
			for (int i = 0; i < instListCount; ++i) {
				int x, y, layerIdx;
				GameObject instance;
				tileMap.GetTilePrefabsListItem(i, out x, out y, out layerIdx, out instance);
				
				// Is it already IN the list for some reason?
				if (!instExists[i]) {
					int tileId = (x >= 0 && x < tileMap.width && y >= 0 && y < tileMap.height) ? tileMap.GetTile(x, y, layerIdx) : -1;
					if (tileId >= 0 && tileId < prefabs.Length && prefabs[tileId] != null) {
						instExists[i] = true;
					}
				}
				
				if (instExists[i]) {
					tileX.Add(x);
					tileY.Add(y);
					tileLayer.Add(layerIdx);
					tileInst.Add(instance);

					tk2dUtil.SetTransformParent(instance.transform, tileMap.PrefabsRoot.transform);
				}
			}
			
			tileMap.SetTilePrefabsList(tileX, tileY, tileLayer, tileInst);
		}
Пример #7
0
        /// <summary>
        /// Moves the chunk's gameobject's children to the prefab root
        /// </summary>
        public static void HideTileMapPrefabs(tk2dTileMap tileMap)
        {
            if (tileMap.renderData == null || tileMap.Layers == null)
            {
                // No Render Data to parent Prefab Root to
                return;
            }

            if (tileMap.PrefabsRoot == null)
            {
                var go = tileMap.PrefabsRoot = tk2dUtil.CreateGameObject("Prefabs");
                go.transform.parent        = tileMap.renderData.transform;
                go.transform.localPosition = Vector3.zero;
                go.transform.localRotation = Quaternion.identity;
                go.transform.localScale    = Vector3.one;
            }

            int instListCount = tileMap.GetTilePrefabsListCount();

            bool[] instExists = new bool[instListCount];

            for (int i = 0; i < tileMap.Layers.Length; ++i)
            {
                var layer = tileMap.Layers[i];
                for (int j = 0; j < layer.spriteChannel.chunks.Length; ++j)
                {
                    var chunk = layer.spriteChannel.chunks[j];
                    if (chunk.gameObject == null)
                    {
                        continue;
                    }

                    var t          = chunk.gameObject.transform;
                    int childCount = t.childCount;
                    for (int k = 0; k < childCount; ++k)
                    {
                        GameObject go = t.GetChild(k).gameObject;
                        for (int q = 0; q < instListCount; ++q)
                        {
                            int        x, y, layerIdx;
                            GameObject instance;
                            tileMap.GetTilePrefabsListItem(q, out x, out y, out layerIdx, out instance);
                            if (instance == go)
                            {
                                instExists[q] = true;
                                break;
                            }
                        }
                    }
                }
            }

            Object[]          prefabs   = tileMap.data.tilePrefabs;
            List <int>        tileX     = new List <int>();
            List <int>        tileY     = new List <int>();
            List <int>        tileLayer = new List <int>();
            List <GameObject> tileInst  = new List <GameObject>();

            for (int i = 0; i < instListCount; ++i)
            {
                int        x, y, layerIdx;
                GameObject instance;
                tileMap.GetTilePrefabsListItem(i, out x, out y, out layerIdx, out instance);

                // Is it already IN the list for some reason?
                if (!instExists[i])
                {
                    int tileId = (x >= 0 && x < tileMap.width && y >= 0 && y < tileMap.height) ? tileMap.GetTile(x, y, layerIdx) : -1;
                    if (tileId >= 0 && tileId < prefabs.Length && prefabs[tileId] != null)
                    {
                        instExists[i] = true;
                    }
                }

                if (instExists[i])
                {
                    tileX.Add(x);
                    tileY.Add(y);
                    tileLayer.Add(layerIdx);
                    tileInst.Add(instance);

                    tk2dUtil.SetTransformParent(instance.transform, tileMap.PrefabsRoot.transform);
                }
            }

            tileMap.SetTilePrefabsList(tileX, tileY, tileLayer, tileInst);
        }
 public static void HideTileMapPrefabs(tk2dTileMap tileMap)
 {
     if ((tileMap.renderData != null) && (tileMap.Layers != null))
     {
         if (tileMap.PrefabsRoot == null)
         {
             GameObject obj6 = tk2dUtil.CreateGameObject("Prefabs");
             tileMap.PrefabsRoot = obj6;
             GameObject obj2 = obj6;
             obj2.transform.parent = tileMap.renderData.transform;
             obj2.transform.localPosition = Vector3.zero;
             obj2.transform.localRotation = Quaternion.identity;
             obj2.transform.localScale = Vector3.one;
         }
         int tilePrefabsListCount = tileMap.GetTilePrefabsListCount();
         bool[] flagArray = new bool[tilePrefabsListCount];
         for (int i = 0; i < tileMap.Layers.Length; i++)
         {
             Layer layer = tileMap.Layers[i];
             for (int k = 0; k < layer.spriteChannel.chunks.Length; k++)
             {
                 SpriteChunk chunk = layer.spriteChannel.chunks[k];
                 if (chunk.gameObject != null)
                 {
                     Transform transform = chunk.gameObject.transform;
                     int childCount = transform.childCount;
                     for (int m = 0; m < childCount; m++)
                     {
                         GameObject gameObject = transform.GetChild(m).gameObject;
                         for (int n = 0; n < tilePrefabsListCount; n++)
                         {
                             int num7;
                             int num8;
                             int num9;
                             GameObject obj4;
                             tileMap.GetTilePrefabsListItem(n, out num7, out num8, out num9, out obj4);
                             if (obj4 == gameObject)
                             {
                                 flagArray[n] = true;
                                 break;
                             }
                         }
                     }
                 }
             }
         }
         UnityEngine.Object[] tilePrefabs = tileMap.data.tilePrefabs;
         List<int> xs = new List<int>();
         List<int> ys = new List<int>();
         List<int> layers = new List<int>();
         List<GameObject> instances = new List<GameObject>();
         for (int j = 0; j < tilePrefabsListCount; j++)
         {
             int num11;
             int num12;
             int num13;
             GameObject obj5;
             tileMap.GetTilePrefabsListItem(j, out num11, out num12, out num13, out obj5);
             if (!flagArray[j])
             {
                 int index = (((num11 < 0) || (num11 >= tileMap.width)) || ((num12 < 0) || (num12 >= tileMap.height))) ? -1 : tileMap.GetTile(num11, num12, num13);
                 if (((index >= 0) && (index < tilePrefabs.Length)) && (tilePrefabs[index] != null))
                 {
                     flagArray[j] = true;
                 }
             }
             if (flagArray[j])
             {
                 xs.Add(num11);
                 ys.Add(num12);
                 layers.Add(num13);
                 instances.Add(obj5);
                 tk2dUtil.SetTransformParent(obj5.transform, tileMap.PrefabsRoot.transform);
             }
         }
         tileMap.SetTilePrefabsList(xs, ys, layers, instances);
     }
 }
Пример #9
0
 /// <summary>
 /// 获取地砖信息
 /// </summary>
 /// <returns>The tile info.</returns>
 /// <param name="x">The x coordinate.</param>
 /// <param name="y">The y coordinate.</param>
 /// <param name="layer">Layer.</param>
 public tk2dRuntime.TileMap.TileInfo GetTileInfo(int x, int y, int layer)
 {
     return(Map.GetTileInfoForTileId(Map.GetTile(x, y, layer)));
 }
Пример #10
0
        //绘制窗口时调用
        void OnGUI()
        {
            if (Prefab == null)
            {
                return;
            }
            else
            {
                Selection.activeGameObject = Prefab;
            }
            data = null;

            GUILayout.BeginArea(new Rect(5, 5, 800, 20));
            GUI.Label(new Rect(0, 0, 50, 18), "搜索名称:");
            searchKeyword = GUI.TextField(new Rect(55, 0, 100, 18), searchKeyword);
            if (GUI.Button(new Rect(160, 0, 30, 18), "搜索"))
            {
                selGridInt = 0;
                fetchData(searchKeyword);
            }
            GUI.Label(new Rect(195, 0, 60, 18), "区域名:");
            areaName = GUI.TextField(new Rect(260, 0, 100, 18), areaName);
            if (GUI.Button(new Rect(365, 0, 40, 18), "改名"))
            {
                if (areaData[sceneName] != null)
                {
                    areaData[sceneName]["Name"] = areaName;
                    writeAreaDataToJson();
                    this.ShowNotification(new GUIContent("改名成功"));
                }
                else
                {
                    this.ShowNotification(new GUIContent("区域名称数据不存在!"));
                }
            }
            GUILayout.EndArea();

            float listStartX   = 5;
            float listStartY   = 25;
            float scrollHeight = Screen.currentResolution.height - 110;

            if (listNames != null && listNames.Count > 0)
            {
                float contextHeight = listNames.Count * 21;
                //开始滚动视图
                scrollPosition = GUI.BeginScrollView(new Rect(listStartX, listStartY, 200, scrollHeight), scrollPosition, new Rect(5, 5, 190, contextHeight), false, scrollHeight < contextHeight);

                selGridInt = GUILayout.SelectionGrid(selGridInt, listNames.ToArray(), 1, GUILayout.Width(190));
                selGridInt = selGridInt >= listNames.Count ? listNames.Count - 1 : selGridInt;
                data       = showListData[selGridInt];
                if (selGridInt != oldSelGridInt)
                {
                    oldSelGridInt   = selGridInt;
                    showId          = data.Id;
                    eventName       = data.Name;
                    sceneEventIndex = sceneEventIndexMapping[data.Type];
                    eventId         = data.EventId;
                    string[] fen = showId.Split(new char[] { '_' });
                    Prefab.transform.position           = map.GetTilePosition(int.Parse(fen[1]), int.Parse(fen[2]));
                    SceneView.lastActiveSceneView.pivot = Prefab.transform.position;
                    switch (data.Type)
                    {
                    case SceneEventType.EnterArea:
                        birthPointEventIdIndex = allBirthPointIdIndexs.ContainsKey(data.EventId) ? allBirthPointIdIndexs[data.EventId] : 0;
                        break;

                    case SceneEventType.EnterCity:
                        citySceneIdIndex = allCitySceneIdIndexs.ContainsKey(data.EventId) ? allCitySceneIdIndexs[data.EventId] : 0;
                        break;

                    case SceneEventType.Battle:
                        fightEventIdIndex = allFightIdIndexs.ContainsKey(data.EventId) ? allFightIdIndexs[data.EventId] : 0;
                        break;

                    default:
                        break;
                    }
                    eventOpenTypeIndex = sceneEventOpenIndexMapping.ContainsKey(data.OpenType) ? sceneEventOpenIndexMapping[data.OpenType] : 0;
                    switch (sceneEventOpenTypeEnums[eventOpenTypeIndex])
                    {
                    case SceneEventOpenType.FightWined:
                        if (allFightNames.Count <= openKeyIndex)
                        {
                            openKeyIndex = 0;
                        }
                        openKeyIndex = allFightIdIndexs.ContainsKey(data.OpenKey) ? allFightIdIndexs[data.OpenKey] : 0;
                        break;

                    case SceneEventOpenType.NeedItem:
                        if (Base.ItemDataNames.Count <= openKeyIndex)
                        {
                            openKeyIndex = 0;
                        }
                        openKeyIndex = Base.ItemDataIdIndexs.ContainsKey(data.OpenKey) ? Base.ItemDataIdIndexs[data.OpenKey] : 0;
                        break;

                    case SceneEventOpenType.NeedTasks:
                        stringValue = !string.IsNullOrEmpty(data.StringValue) ? data.StringValue : "";
                        break;

                    default:
                        openKey = "";
                        break;
                    }
                    eventNotice = data.Notice;
                    intValue    = data.IntValue;
                    if (meetEnemyRatesMapping.ContainsKey(sceneName))
                    {
                        currentMeetEnemyRates = meetEnemyRatesMapping[sceneName];
                    }
                    else
                    {
                        currentMeetEnemyRates = new List <RateData>();
                        meetEnemyRatesMapping.Add(sceneName, currentMeetEnemyRates);
                    }
                    for (int i = 0; i < currentMeetEnemyRates.Count; i++)
                    {
                        currentMeetEnemyRates[i].IdIndex = allFightIdIndexs.ContainsKey(currentMeetEnemyRates[i].Id) ? allFightIdIndexs[currentMeetEnemyRates[i].Id] : 0;
                    }
                }
                //结束滚动视图
                GUI.EndScrollView();

                if (data != null)
                {
                    GUILayout.BeginArea(new Rect(listStartX + 205, listStartY, 800, 300));
                    GUI.Label(new Rect(0, 0, 60, 18), "Id:");
                    EditorGUI.TextField(new Rect(65, 0, 150, 18), showId);
                    GUI.Label(new Rect(220, 0, 50, 18), "开启条件:");
                    eventOpenTypeIndex = EditorGUI.Popup(new Rect(275, 0, 80, 18), eventOpenTypeIndex, sceneEventOpenStrs.ToArray());
                    switch (sceneEventOpenTypeEnums[eventOpenTypeIndex])
                    {
                    case SceneEventOpenType.FightWined:
                        if (allFightNames.Count <= openKeyIndex)
                        {
                            openKeyIndex = 0;
                        }
                        openKeyIndex = EditorGUI.Popup(new Rect(360, 0, 150, 18), openKeyIndex, allFightNames.ToArray());
                        openKey      = allFights[openKeyIndex].Id;
                        eventNotice  = EditorGUI.TextArea(new Rect(515, 0, 100, 36), eventNotice);
                        break;

                    case SceneEventOpenType.NeedItem:
                        if (Base.ItemDataNames.Count <= openKeyIndex)
                        {
                            openKeyIndex = 0;
                        }
                        openKeyIndex = EditorGUI.Popup(new Rect(360, 0, 150, 18), openKeyIndex, Base.ItemDataNames.ToArray());
                        openKey      = Base.ItemDatas[openKeyIndex].Id;
                        eventNotice  = EditorGUI.TextArea(new Rect(515, 0, 100, 36), eventNotice);
                        break;

                    case SceneEventOpenType.NeedTasks:
                        stringValue = EditorGUI.TextField(new Rect(360, 0, 150, 18), stringValue);
                        eventNotice = EditorGUI.TextArea(new Rect(515, 0, 100, 36), eventNotice);
                        break;

                    default:
                        openKey = "";
                        break;
                    }
                    GUI.Label(new Rect(0, 20, 60, 18), "事件名称:");
                    eventName = EditorGUI.TextField(new Rect(65, 20, 150, 18), eventName);
                    GUI.Label(new Rect(0, 40, 60, 18), "事件类型:");
                    sceneEventIndex = EditorGUI.Popup(new Rect(65, 40, 150, 18), sceneEventIndex, sceneEventStrs.ToArray());

                    switch (sceneEventTypeEnums[sceneEventIndex])
                    {
                    case SceneEventType.EnterArea:
                        birthPointEventIdIndex = EditorGUI.Popup(new Rect(220, 40, 150, 18), birthPointEventIdIndex, allBirthPointNames.ToArray());
                        eventId = allBirthPointEvents[birthPointEventIdIndex].Id;
                        break;

                    case SceneEventType.EnterCity:
                        citySceneIdIndex = EditorGUI.Popup(new Rect(220, 40, 150, 18), citySceneIdIndex, allCitySceneNames.ToArray());
                        eventId          = allCityScenes[citySceneIdIndex].Id;
                        break;

                    case SceneEventType.Battle:
                        fightEventIdIndex = EditorGUI.Popup(new Rect(220, 40, 150, 18), fightEventIdIndex, allFightNames.ToArray());
                        eventId           = allFights[fightEventIdIndex].Id;
                        break;

                    case SceneEventType.EatFood:
                        GUI.Label(new Rect(220, 40, 65, 18), "开启干粮数:");
                        intValue = (int)EditorGUI.Slider(new Rect(285, 40, 180, 18), (float)intValue, 1, 99);
                        break;

                    default:
                        break;
                    }

                    GUI.Label(new Rect(0, 60, 100, 18), "事件Id:");
                    eventId = EditorGUI.TextField(new Rect(65, 60, 150, 18), eventId);

                    if (GUI.Button(new Rect(0, 80, 80, 18), "修改事件"))
                    {
                        if (eventName == "")
                        {
                            this.ShowNotification(new GUIContent("事件名不能为空!"));
                            return;
                        }
                        if (eventId == "")
                        {
                            this.ShowNotification(new GUIContent("事件Id不能为空!"));
                            return;
                        }
                        data.Name        = eventName;
                        data.Type        = sceneEventTypeEnums[sceneEventIndex];
                        data.EventId     = eventId;
                        data.OpenType    = sceneEventOpenTypeEnums[eventOpenTypeIndex];
                        data.OpenKey     = openKey;
                        data.Notice      = eventNotice;
                        data.IntValue    = intValue;
                        data.StringValue = stringValue;
                        writeDataToJson();
                        oldSelGridInt = -1;
                        getData();
                        fetchData(searchKeyword);
                        this.ShowNotification(new GUIContent("修改成功"));
                    }
                    string[] fen = showId.Split(new char[] { '_' });
                    if (fen.Length >= 3)
                    {
                        int i = int.Parse(fen[1]);
                        int j = int.Parse(fen[2]);
                        if (map.GetTileInfoForTileId(map.GetTile(i, j, 1)) == null)
                        {
                            if (GUI.Button(new Rect(85, 80, 300, 18), "该事件已从场景中被删除,点击清除此残余数据"))
                            {
                                if (!dataMapping.ContainsKey(data.Id))
                                {
                                    this.ShowNotification(new GUIContent("要删除的数据不存在!"));
                                    return;
                                }
                                dataMapping.Remove(data.Id);
                                writeDataToJson();
                                oldSelGridInt = -1;
                                getData();
                                fetchData(searchKeyword);
                                this.ShowNotification(new GUIContent("删除残余事件成功"));
                            }
                        }
                    }
                    GUILayout.EndArea();

                    GUILayout.BeginArea(new Rect(listStartX + 205, listStartY + 305, 800, 500));
                    GUI.Label(new Rect(0, 0, 60, 18), "随机遇敌:");
                    RateData rateData;
                    for (int i = 0; i < currentMeetEnemyRates.Count; i++)
                    {
                        if (currentMeetEnemyRates.Count <= i)
                        {
                            continue;
                        }
                        rateData = currentMeetEnemyRates[i];
                        GUI.Label(new Rect(0, 20 + i * 20, 60, 18), "遇敌战斗:");
                        rateData.IdIndex = EditorGUI.Popup(new Rect(65, 20 + i * 20, 150, 18), rateData.IdIndex, allFightNames.ToArray());
                        rateData.Id      = allFights[rateData.IdIndex].Id;
                        GUI.Label(new Rect(220, 20 + i * 20, 60, 18), "遇敌概率:");
                        rateData.Rate = EditorGUI.Slider(new Rect(285, 20 + i * 20, 180, 18), rateData.Rate, 0, 100);
                        if (GUI.Button(new Rect(470, 20 + i * 20, 40, 18), "删除"))
                        {
                            currentMeetEnemyRates.RemoveAt(i);
                        }
                    }
                    if (GUI.Button(new Rect(0, 180, 60, 18), "修改战斗"))
                    {
//						if (currentMeetEnemyRates.Count == 0) {
//							this.ShowNotification(new GUIContent("还没有添加任何随机战斗!"));
//							return;
//						}
                        Base.CreateFile(Application.dataPath + "/Resources/Data/Json", "AreaMeetEnemys.json", JsonManager.GetInstance().SerializeObject(meetEnemyRatesMapping));
                        this.ShowNotification(new GUIContent("修改随机遇敌数据成功"));
                    }
                    if (GUI.Button(new Rect(65, 180, 60, 18), "添加战斗"))
                    {
                        if (currentMeetEnemyRates.Count >= 8)
                        {
                            this.ShowNotification(new GUIContent("每个区域最多出现8种战斗!"));
                            return;
                        }
                        currentMeetEnemyRates.Add(new RateData(100, "0", 0));
                    }

                    GUILayout.EndArea();
                }
            }
        }
Пример #11
0
        static void InitParams()
        {
            //读取区域大地图宽高数据表
            areaSizeMapping = new Dictionary <string, SizeData>();
            JObject obj = JsonManager.GetInstance().GetJson("AreaSizeDatas", false);

            foreach (var item in obj)
            {
                if (item.Key != "0")
                {
                    areaSizeMapping.Add(item.Value["Id"].ToString(), JsonManager.GetInstance().DeserializeObject <SizeData>(item.Value.ToString()));
                }
            }
            int       index = 0;
            FieldInfo fieldInfo;

            object[]             attribArray;
            DescriptionAttribute attrib;

            //加载全部的SceneEventType枚举类型
            sceneEventTypeEnums    = new List <SceneEventType>();
            sceneEventStrs         = new List <string>();
            sceneEventIndexMapping = new Dictionary <SceneEventType, int>();
            index = 0;
            foreach (SceneEventType type in Enum.GetValues(typeof(SceneEventType)))
            {
                sceneEventTypeEnums.Add(type);
                fieldInfo   = type.GetType().GetField(type.ToString());
                attribArray = fieldInfo.GetCustomAttributes(false);
                attrib      = (DescriptionAttribute)attribArray[0];
                sceneEventStrs.Add(attrib.Description);
                sceneEventIndexMapping.Add(type, index);
                index++;
            }

            //加载全部的SceneEventOpeType枚举类型
            sceneEventOpenTypeEnums    = new List <SceneEventOpenType>();
            sceneEventOpenStrs         = new List <string>();
            sceneEventOpenIndexMapping = new Dictionary <SceneEventOpenType, int>();
            index = 0;
            foreach (SceneEventOpenType type in Enum.GetValues(typeof(SceneEventOpenType)))
            {
                sceneEventOpenTypeEnums.Add(type);
                fieldInfo   = type.GetType().GetField(type.ToString());
                attribArray = fieldInfo.GetCustomAttributes(false);
                attrib      = (DescriptionAttribute)attribArray[0];
                sceneEventOpenStrs.Add(attrib.Description);
                sceneEventOpenIndexMapping.Add(type, index);
                index++;
            }

            //初始化地图中的静态事件地砖对应的事件关联数据
            map = GameObject.Find("TileMap").GetComponent <tk2dTileMap>();
            string[] fen = EditorApplication.currentScene.Split(new char[] { '/' });
            sceneName = fen[fen.Length - 1].Replace(".unity", "");
            tk2dRuntime.TileMap.TileInfo tile;
            EventData        exsitEventData;
            EventData        newEventData;
            string           id;
            List <EventData> eventDatas = new List <EventData>();

            allBirthPointNames    = new List <string>();
            allBirthPointIdIndexs = new Dictionary <string, int>();
            allBirthPointEvents   = new List <EventData>();

            //处理区域大地图中文名
            areaData = JsonManager.GetInstance().GetJson("AreaNames", false);
            if (areaData[sceneName] == null)
            {
                areaData[sceneName]         = new JObject();
                areaData[sceneName]["Id"]   = sceneName;
                areaData[sceneName]["Name"] = sceneName;
                areaName = sceneName;
            }
            else
            {
                areaName = areaData[sceneName]["Name"].ToString();
            }
            writeAreaDataToJson();

            //获取旧数据
            dataMapping = new Dictionary <string, EventData>();
            obj         = JsonManager.GetInstance().GetJson("AreaEventDatas", false);
            EventData eventData;

            index = 0;
            foreach (var item in obj)
            {
                if (item.Key != "0")
                {
                    eventData = JsonManager.GetInstance().DeserializeObject <EventData>(item.Value.ToString());
                    if (eventData.SceneId == sceneName)
                    {
                        dataMapping.Add(eventData.Id, eventData);
                    }
                    //查找所有的出生点事件
                    if (eventData.Type == SceneEventType.BirthPoint)
                    {
                        allBirthPointNames.Add(eventData.Name);
                        allBirthPointIdIndexs.Add(eventData.Id, index);
                        allBirthPointEvents.Add(eventData);
                        index++;
                    }
                }
            }

            for (int i = 0; i < map.width; i++)
            {
                for (int j = 0; j < map.height; j++)
                {
                    tile = map.GetTileInfoForTileId(map.GetTile(i, j, 1));
                    if (tile != null)
                    {
                        id                   = sceneName + "_" + i + "_" + j;
                        newEventData         = new EventData();
                        newEventData.Id      = id;
                        newEventData.SceneId = sceneName;
                        if (dataMapping.ContainsKey(newEventData.Id))
                        {
                            exsitEventData       = dataMapping[newEventData.Id];
                            newEventData.Name    = exsitEventData.Name;
                            newEventData.EventId = exsitEventData.EventId;
                        }
                        else
                        {
                            newEventData.Name = "默认事件点 - " + i + "," + j;
                        }
                        eventDatas.Add(newEventData);
                    }
                }
            }
            //删除掉旧的数据
            dataMapping.Clear();
            JsonManager.GetInstance().Clear();
            getData();
            //添加新数据
            foreach (EventData item in eventDatas)
            {
                if (!dataMapping.ContainsKey(item.Id))
                {
                    dataMapping.Add(item.Id, item);
                }
            }
            //生成新数据
            writeDataToJson();
            getData();

            allCitySceneIdIndexs = new Dictionary <string, int>();
            allCitySceneNames    = new List <string>();
            allCityScenes        = new List <SceneData>();
            obj = JsonManager.GetInstance().GetJson("Scenes", false);
            SceneData sceneData;

            index = 0;
            foreach (var item in obj)
            {
                if (item.Key != "0")
                {
                    sceneData = JsonManager.GetInstance().DeserializeObject <SceneData>(item.Value.ToString());
                    if (sceneData.BelongToAreaName == sceneName)
                    {
                        allCitySceneNames.Add(sceneData.Name);
                        allCitySceneIdIndexs.Add(sceneData.Id, index);
                        allCityScenes.Add(sceneData);
                        index++;
                    }
                }
            }

            allFightIdIndexs = new Dictionary <string, int>();
            allFightNames    = new List <string>();
            allFights        = new List <FightData>();
            obj = JsonManager.GetInstance().GetJson("Fights", false);
            FightData fightData;

            index = 0;
            foreach (var item in obj)
            {
                if (item.Key != "0")
                {
                    fightData = JsonManager.GetInstance().DeserializeObject <FightData>(item.Value.ToString());
                    if (fightData.Type == FightType.Normal)
                    {
                        allFightNames.Add(fightData.Name);
                        allFightIdIndexs.Add(fightData.Id, index);
                        allFights.Add(fightData);
                        index++;
                    }
                }
            }
        }
Пример #12
0
    //false:不可通过
    //true:可通过
    public bool checkTile(int x, int y)
    {
        if (!(x < 11 && y < 11 && x > -1 && y > -1))
        {
            return(false);
        }
        tm = GameObject.Find("TileMap").GetComponent <tk2dTileMap>();
        AM = GetComponent <ActionManager>();
        int tileID = tm.GetTile(x, y, 1);

        if (tileID == -1)
        {
            return(true);
        }
        tk2dRuntime.TileMap.TileInfo tileinfo = tm.GetTileInfoForTileId(tileID);
        if (tileinfo != null)
        {
            if (tileinfo.stringVal == "Wall")
            {
                return(false);
            }
            //拥有Prefab
            Vector2      startPosition = new Vector2(x - 0.2f, y);
            Vector2      Direction     = new Vector2(x, y);
            RaycastHit2D hit           = Physics2D.Raycast(startPosition, Direction, 0.4f);
            //Debug.DrawLine(new Vector3(x - 0.2f, y, 0), new Vector3(x + 0.2f, y, 0), Color.red);
            if (hit.collider != null)
            {
                switch (hit.collider.tag)
                {
                case "Talk":
                    AM.talk(hit.collider.gameObject.GetComponent <Talk>());
                    return(false);

                case "Key":
                    if (AM.key(hit.collider.gameObject.GetComponent <Key>()))
                    {
                        tm.ClearTile(x, y, 1);
                    }
                    break;

                case "Door":
                    if (AM.door(hit.collider.gameObject.GetComponent <Door>()))
                    {
                        tm.ClearTile(x, y, 1);
                    }
                    return(false);

                case "DoorWall":
                    if (AM.doorwall(hit.collider.gameObject.GetComponent <DoorWall>()))
                    {
                        tm.ClearTile(x, y, 1);
                    }
                    return(false);

                case "Baoshi":
                    if (AM.baoshi(hit.collider.gameObject.GetComponent <Baoshi>()))
                    {
                        tm.ClearTile(x, y, 1);
                    }
                    break;

                case "Pingzi":
                    if (AM.pingzi(hit.collider.gameObject.GetComponent <Pingzi>()))
                    {
                        tm.ClearTile(x, y, 1);
                    }
                    break;

                case "Yaoshui":
                    if (AM.yaoshui(hit.collider.gameObject.GetComponent <Yaoshui>()))
                    {
                        tm.ClearTile(x, y, 1);
                    }
                    break;

                case "Zhuangbei":
                    if (AM.zhuangbei(hit.collider.gameObject.GetComponent <Zhuangbei>()))
                    {
                        tm.ClearTile(x, y, 1);
                    }
                    break;

                case "Enemy":
                    if (AM.enemy(hit.collider.gameObject.GetComponent <Enemy>()))
                    {
                        tm.ClearTile(x, y, 1);
                    }
                    return(false);

                case "StairUp":
                    AM.stair(hit.collider.gameObject.GetComponent <Stair>());
                    break;

                case "StairDown":
                    AM.stair(hit.collider.gameObject.GetComponent <Stair>());
                    break;

                case "Tool":
                    if (AM.mttool(hit.collider.gameObject.GetComponent <mtTool>()))
                    {
                        tm.ClearTile(x, y, 1);
                    }
                    break;
                }
                return(true);
            }
            else
            {
                return(true);
            }
        }
        else
        {
            return(false);
        }
    }