Пример #1
0
    public void Destroy()
    {
        foreach (object landObj in landTileds)
        {
            LandTiled tiled = landObj as LandTiled;
            tiled.OnDestroy();
        }
        landTileds.Clear();

        GameObject.Destroy(mainObj);
    }
Пример #2
0
    /// <summary>
    /// 初始化SceneTiled模块地图
    /// </summary>
    /// <param name="gObj">主GameObject</param>
    /// <param name="worldMapIndex">世界地图中的索引</param>
    public void Initlizate(GameObject gObj)
    {
        mainObj       = gObj;
        mainObj.name += "_" + WorldMapIndex;

#if UNITY_EDITOR
        if (MapDebug.DebugSceneTiled)
        {
            gObj.AddComponent <SceneTiledGizmo>();
        }
#endif
        gObj.transform.localScale = Vector3.one;
        gObj.transform.position   = WorldPosition;

        mapPoint = CoordinationConvert.SceneWorldToMapPoint(WorldPosition);

        //构造场景内的地块信息
        landTileds.Clear();
        int halfWidth  = LandTiled.halfTiledWidth;
        int halfHeight = LandTiled.halfTiledHeight;

        //        Vector3 orginPos = WorldPosition + new Vector3(halfSceneWidth - halfWidth,0);
        Vector3 orginPos = WorldPosition + new Vector3(halfSceneWidth, 0);

        for (int i = 0; i < SceneRow; i++)
        {
            int tiledRowIndex = i * SceneRow;
            for (int j = 0; j < SceneColumn; j++)
            {
                int tiledIndex = tiledRowIndex + j;
                //计算世界坐标中的位置
                float tiledX = halfWidth * j - halfWidth * i;
                float tiledY = -halfHeight * j - halfHeight * i;

                Vector3 position = new Vector3(tiledX, tiledY);
                position += orginPos;
                //构造记录映射
                TiledData td = new TiledData();
                //td.TiledId = ;
                td.SceneIndex = (byte)WorldMapIndex;
                td.Index      = tiledIndex;

                //实例土地
                LandTiled landTiled = new LandTiled(td);
                landTiled.WorldPosition = position;
                landTileds.Add(landTiled);

                MapCreater.Instance.LoadDel("Assets/Prefabs/LandSprite.prefab", obj =>
                {
                    landTiled.Initlizate(obj, this);
                });
            }
        }
    }
Пример #3
0
    private void debugViewMap(Vector2 mapLeftTop, Vector2 mapLeftBottom, Vector2 mapRightTop, Vector2 mapRightBottom)
    {
        foreach (LandTiled tiled in testLands)
        {
            if (tiled == null)
            {
                continue;
            }

            tiled.SetTiledState(ELandStatus.None);
        }
        testLands.Clear();

        int count = (int)(mapRightTop.x - mapLeftTop.x) + 2;

        for (int i = 0; i <= count; i++)
        {
            //上边缘
            Vector2   newMapPoint = mapLeftTop + new Vector2(i + 1, -i + 1);
            LandTiled tile        = MapData.Instance.FindLandTiledByMapPoint(newMapPoint);
            if (tile != null)
            {
                tile.SetTiledState(ELandStatus.Select);
                testLands.Add(tile);
            }

            //下边缘
            newMapPoint = mapLeftBottom + new Vector2(i - 1, -i);
            tile        = MapData.Instance.FindLandTiledByMapPoint(newMapPoint);
            if (tile != null)
            {
                tile.SetTiledState(ELandStatus.Self);
                testLands.Add(tile);
            }
        }

        //左边缘
        count = (int)(mapLeftTop.x - mapLeftBottom.x) + 1;
        for (int i = 0; i <= count; i++)
        {
            Vector2   newMapPoint = mapLeftTop - new Vector2(i, i - 2);
            LandTiled tile        = MapData.Instance.FindLandTiledByMapPoint(newMapPoint);
            if (tile != null)
            {
                tile.SetTiledState(ELandStatus.Friendly);
                testLands.Add(tile);
            }
        }

        //右边缘
        count = (int)(mapRightTop.x - mapRightBottom.x) + 2;
        for (int i = 0; i <= count; i++)
        {
            Vector2   newMapPoint = mapRightTop - new Vector2(i - 2, i);
            LandTiled tile        = MapData.Instance.FindLandTiledByMapPoint(newMapPoint);
            if (tile != null)
            {
                tile.SetTiledState(ELandStatus.Enemy);
                testLands.Add(tile);
            }
        }
    }
Пример #4
0
    public void Update()
    {
#if UNITY_ANDROID || UNITY_IOS
        if (Input.touchCount <= 0)
        {
            return;
        }

        Touch touch = Input.GetTouch(0);

        if (touch.phase == TouchPhase.Began || touch.phase == TouchPhase.Stationary)
        {
            beginTime = Time.time;
            beginPos  = mapCamera.ScreenToWorldPoint(touch.position);
        }
        else if (touch.phase == TouchPhase.Moved)
        {
            offset = (Vector2)mapCamera.ScreenToWorldPoint(touch.position) - beginPos;
        }
        else if (touch.phase == TouchPhase.Ended)
        {
            offset       = offsetZero;
            lastMousePos = touch.position;
            endTime      = Time.time;
            MapCamera.Instance.CallFinish();
        }
#else
        if (Input.GetMouseButtonDown(0))
        {
            beginPos  = mapCamera.ScreenToWorldPoint(Input.mousePosition + MapCamera.Instance.depath);
            beginTime = Time.time;
        }
        else if (Input.GetMouseButtonUp(0))
        {
            endTime      = Time.time;
            offset       = offsetZero;
            beginPos     = offsetZero;
            lastMousePos = Input.mousePosition;
            MapCamera.Instance.CallFinish();
        }
        else if (beginPos != offsetZero)
        {
            Vector3 curMouseSceenPos = Input.mousePosition;
            float   distance         = Vector3.Distance(lastMousePos, curMouseSceenPos);
            if (distance > 5f)
            {
                lastMousePos = curMouseSceenPos;
                Vector3 curMousePos = mapCamera.ScreenToWorldPoint(lastMousePos + MapCamera.Instance.depath);
                offset = (Vector2)curMousePos - beginPos;
            }
        }
#endif
        //移动移动
        if (offset != offsetZero)
        {
            //移动相反的方向
            MapCamera.Instance.Move(-offset);
            //	        cacheTrans.position += (Vector3)offset;
            offset = offsetZero;
        }

        //点击操作
        if (Math.Abs(endTime - beginTime) < touchTime)
        {
            endTime = 0;
            LandTiled landTiled = MapData.Instance.FindLandTiled(lastMousePos);
            if (landTiled != null)
            {
                landTiled.SetTiledState(landTiled.CurrentState == ELandStatus.Select ?
                                        ELandStatus.None : ELandStatus.Select);
            }
        }


        if (build)
        {
            Vector2 mapPoint = CoordinationConvert.ConvertTiledIndex(Input.mousePosition);
        }
    }