GetTilePosition() public méthode

Returns the tile position in world space
public GetTilePosition ( int x, int y ) : Vector3
x int
y int
Résultat Vector3
Exemple #1
0
    /// <summary>
    /// 根据地砖编号转换成坐标
    /// </summary>
    /// <param name="x">The x coordinate.</param>
    /// <param name="y">The y coordinate.</param>
    /// <param name="doEvent">If set to <c>true</c> do event.</param>
    /// <param name="duringMove">If set to <c>true</c> during move.</param>
    public void SetPosition(int x, int y, bool doEvent = true, bool duringMove = false)
    {
        tk2dRuntime.TileMap.TileInfo groundTile = GetTileInfo(x, y, 0);
        //判断禁止通过的碰撞区域
        if (groundTile == null || groundTile.stringVal == "obstacle")
        {
            return;
        }
        if (doEvent)
        {
            //记录当前坐标
            Messenger.Broadcast <string, Vector2, System.Action <UserData> >(NotifyTypes.UpdateUserDataAreaPos, UserModel.CurrentUserData.CurrentAreaSceneName, new Vector2(x, y), null);
            Invoke("doEventDelay", duringMove ? 0.24f : 0);
        }
        _x = x;
        _y = y;
        Vector3 position = Map.GetTilePosition(_x, _y);
        float   rx       = Map.partitionSizeX * 0.005f;

        if (duringMove)
        {
            transform.DOMove(new Vector3(position.x + rx, position.y, position.z), 0.3f);
        }
        else
        {
            transform.position = new Vector3(position.x + rx, position.y, position.z);
        }
//		Map.ColorChannel.SetColor(_x, _y, new Color(1, 1, 1, 0));
//		Map.Build(tk2dTileMap.BuildFlags.Default);
    }
Exemple #2
0
    void LateUpdate()
    {
        // TODO: Better camera code
        if (!isFairyPause && player.isAlive && isGameReady && !isGoal)
        {
            cameraTransform.Translate(player.moveAmount);

            // Move camera vertically ON SLOPE
            if (tileInfo != null)
            {
                if (tileInfo.intVal == 1)
                {
                    hasSloped = true;

                    Vector3 tilePosition = tilemap.GetTilePosition(tileX, tileY);
                    float   moveBy       = lastGroundPositionY;

                    // Going down?
                    if (lastGroundPositionY < tempGroundPosition)
                    {
                        moveBy -= 10f;
                    }
                    else
                    {
                        moveBy += 10f;
                    }

                    cameraTransform.position = Vector3.Slerp(cameraTransform.position, new Vector3(playerTransform.position.x + playerXCameraOffset - 1f, moveBy, cameraTransform.position.z), Time.deltaTime / 4);
                }
                else
                {
                    if (isCameraLerping)
                    {
                        // TODO: Deal with down slopes
                        cameraTransform.position = Vector3.Slerp(cameraTransform.position, new Vector3(playerTransform.position.x + playerXCameraOffset - 1f, lastGroundPositionY + 2.45f, cameraTransform.position.z), Time.deltaTime);

                        if (Mathf.Abs(cameraTransform.position.y - (lastGroundPositionY + 2.45f)) <= acceptableCameraRange)
                        {
                            isCameraLerping = false;
                            hasSloped       = false;
                        }
                    }

                    if (hasSloped)
                    {
                        if (!isCameraLerping && (Mathf.Abs(cameraTransform.position.y - (lastGroundPositionY + 2.45f)) > acceptableCameraRange))
                        {
                            isCameraLerping = true;
                        }
                    }
                }
            }
        }
    }
        public TileInfo GetTileAtPosition(Vector2 pos, TileLayer l)
        {
            int           x, y, tileId = -1;
            TileDirection dir = TileDirection.Up;

            if (map.GetTileAtPosition(pos, out x, out y))
            {
                tileId = map.GetTile(x, y, (int)l);
            }
            tk2dTileFlags flags = map.GetTileFlags(x, y, (int)l);

            dir = (TileFlagsToTileDirection(flags));

            TileInfo tile = new TileInfo();

            tile.worldPos = map.GetTilePosition(x, y);
            switch (tileId)
            {
            case 0:
            case 1:
            case 2:
            case 3:
            case 4:
            case 32:
            case 33:
            case 34:
            case 35:
            case 36:
            case 64:
            case 65:
            case 66:
                tile.type = TileType.Wall;
                break;

            case 8:
                tile.type = TileType.Lava;
                break;

            default:
                tile.type = TileType.Empty;
                break;
            }
            if (tileId == spikeTile)
            {
                tile.type = TileType.Spike;
            }
            print(tile.type);
            tile.direction = dir;
            return(tile);
        }
Exemple #4
0
    static void StartGame()
    {
        //Set the gamestate
        gameState = GameState.Paused;

        //set the TileMapController
        tmc = GameObject.Find("TileMapController").GetComponent <TileMapController> ();
        tmc.StartGame();

        //Find a random square of Beach
        List <Tile> beaches = new List <Tile> ();

        for (int i = 0; i < fullMap.Width; i++)
        {
            for (int j = 0; j < fullMap.Height; j++)
            {
                if (fullMap.GetTile(i, j, 25).Biome == "Beach" && !fullMap.GetTile(i, j, 25).IsBlocked)
                {
                    beaches.Add(fullMap.GetTile(i, j, 25));
                }
            }
        }
        Tile startTile = beaches[Random.Range(0, beaches.Count)];

        startTile.Biome = "Start Location";
        Vector3 tilePos = tileMap.GetTilePosition(startTile.PointX, startTile.PointY);

        tilePos.z = Camera.main.transform.position.z;
        Camera.main.transform.position = tilePos;

        //Initialize the character list
        characters = new List <WorldObject> ();
        WorldObject dwarf = new WorldObject("Dwarf", startTile.PointX, startTile.PointY, 25);

        characters.Add(dwarf);
        //tmc.DrawWorldObj ();
    }
Exemple #5
0
    private Vector3 GetPosition(Point p)
    {
        Vector3 result = Tilemap.GetTilePosition(p.X, p.Y);

        return(result);
    }
Exemple #6
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();
                }
            }
        }