Ejemplo n.º 1
0
        public static void PlaceWalls()
        {
            BoundsInt Bounds = DungeonUtility.GetTilemap().cellBounds;

            TileBase[]        allTiles         = DungeonUtility.GetTilemap().GetTilesBlock(Bounds);
            List <CustomTile> tilesWithinRange = new List <CustomTile>();
            TileHolder        tileHolder       = TileManager.GetTileHolder(TileType.Wall);

            for (int x = 0; x < Bounds.size.x; x++)
            {
                for (int y = 0; y < Bounds.size.y; y++)
                {
                    float randomFreq = Random.Range(1, tileHolder.Tiles.OrderByDescending(t => t.PickChance).First().PickChance);
                    tilesWithinRange = tileHolder.Tiles.Where(t => t.PickChance >= randomFreq).ToList();
                    TileBase tile = allTiles[x + y * Bounds.size.x];
                    int      tempTileIndex;
                    tempTileIndex = Random.Range(0, tilesWithinRange.Count);
                    Vector3Int pos = new Vector3Int(x, y, 0);
                    if (tile == null)
                    {
                        TileManager.PlaceTile(pos, tempTileIndex, null, m_walls, tilesWithinRange[tempTileIndex], DictionaryType.Walls);
                        Tile tileT = m_walls.GetTile <Tile>(pos);
                        if (tilesWithinRange[tempTileIndex].SpriteVariations.Length > 0)
                        {
                            Sprite sT = tilesWithinRange[tempTileIndex].SpriteVariations[Random.Range(0, tilesWithinRange[tempTileIndex].SpriteVariations.Length)];
                            if (sT != null)
                            {
                                tileT.sprite = sT;
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
    void SetupTileHolders()
    {
        tileHolders = new TileHolder[numTiles];

        for (int i = numTiles - 1; i >= 0; i--)
        {
            TileHolder th = ((GameObject)Instantiate(tileHolderPrefab)).GetComponent <TileHolder>();
            th.name        = "Tile Holder " + i.ToString();
            th.index       = i;
            tileHolders[i] = th;
        }

        float puzzleWidthInPoints  = puzzleWidth * tileMargin;
        float puzzleHeightInPoints = puzzleHeight * tileMargin;

        Vector2 origin = new Vector2(-puzzleWidthInPoints / 2f, puzzleHeightInPoints / 2f);

        for (int y = 0; y < puzzleHeight; y++)
        {
            for (int x = 0; x < puzzleWidth; x++)
            {
                tileHolders[x + y * puzzleWidth].transform.position = new Vector3(origin.x + (x + 0.5f) * tileMargin, origin.y - (y + 0.5f) * tileMargin, 0);
            }
        }
    }
Ejemplo n.º 3
0
    // moves the commander to a certain position. fires events as usual
    public void MoveCommander(TileData tile)
    {
        if (_hasBeenLifted || _liftingPiece)
        {
            return;
        }
        TileHolder tileHolder = tile.TileObject.GetComponentInChildren <TileHolder>();

        if (tileHolder != null)
        {
            _forceMove = true;

            //try get the commander position marker
            GameObject posMarker = getCommanderMarker(tileHolder);
            if (posMarker != null)
            {
                _destination         = posMarker.transform.position;
                _destinationRotation = posMarker.transform.rotation;
            }
            else
            {
                _destination = tileHolder.transform.position;
            }

            _targetY         = tileHolder._Tile.Height;
            _destinationTile = tileHolder;

            LiftPiece();
        }
    }
Ejemplo n.º 4
0
    void OnMouseUp()
    {
        _dragging = false;

        //if the tile hovered is not in the reachable set then back to original tile
        if (_destinationTile == null || !_reachableTiles.Contains(_destinationTile._Tile))
        {
            //commander not moved
            _destinationTile = null;
            GameObject posMarker = getCommanderMarker(_Player.CommanderPosition.TileObject.GetComponentInChildren <TileHolder>());
            _toGoTo  = (posMarker != null) ? posMarker.transform.position: _Player.CommanderPosition.TileObject.transform.position;
            _targetY = _Player.CommanderPosition.Height;
        }
        else
        {
            //commander moved
            _toGoTo = _destination;
            OnCommanderDrop(new Vector3(_destination.x, _targetY, _destination.z));
            // _destinationTile = null;
        }

        //drop the commander
        _toGoTo.y = _targetY;
        if (_destinationRotation != null)
        {
            // rotate to the new marker rotation
            _lerpRotation.LerpTo(_destinationRotation);
        }
        OnDropCommander(_Player.CommanderPosition);


        //raycast
        this.gameObject.layer = _defaultLayer;
    }
        public void AddTile(TileHolder tile)
        {
            int id = 0;

            switch (TileSelection)
            {
            case TileSelectionType.None:
                return;

            case TileSelectionType.TowerBuy:
            {
                id = tile.Tile.Grid.BuildZone.Contains(tile.Tile) ? goodTargetId : badTargetId;
                break;
            }

            case TileSelectionType.TowerAction:
            {
                var action = SelectedTower.ActiveActions[SelectedTowerActionId] as TargetAction;
                if (action == null)
                {
                    return;
                }
                id = action.CorrectTarget(tile.Tile) ? goodTargetId : badTargetId;
                break;
            }
            }

            outlineLayers[id].Add(tile.gameObject);
        }
Ejemplo n.º 6
0
    GameObject getCommanderMarker(TileHolder tHolder)
    {
        if (tHolder == null)
        {
            return(null);
        }

        switch (_Player.Type)
        {
        case PlayerType.None:
            Debug.LogError("Cannot get marker for player type None");
            break;

        case PlayerType.Battlebeard:
            return(tHolder._MarkerCommanderBB);

        case PlayerType.Stormshaper:
            return(tHolder._MarkerCommanderSS);

        default:
            Debug.LogError("Unhandled player type getting position marker");
            break;
        }

        return(null);
    }
Ejemplo n.º 7
0
 private void ReverseX(List <TileHolder.TileConfig> l, Area a, TileHolder g)
 {
     foreach (TileHolder.TileConfig t in l)
     {
         t.X(g.Max().x - t.pos.x);
     }
 }
Ejemplo n.º 8
0
        public static void PlaceFloorTile(Vector2Int _buildPoint)
        {
            Vector3Int t = new Vector3Int(_buildPoint.x, _buildPoint.y, 0);

            if (!TileManager.GetTileDictionaryFloor().ContainsKey(t))
            {
                TileHolder        tileHolder       = TileManager.GetTileHolder(TileType.Floor);
                float             randomFreq       = Random.Range(1, tileHolder.Tiles.OrderByDescending(t => t.PickChance).First().PickChance);
                List <CustomTile> tilesWithinRange = new List <CustomTile>();
                tilesWithinRange = tileHolder.Tiles.Where(t => t.PickChance >= randomFreq).ToList();
                int tempTileIndex;
                tempTileIndex = Random.Range(0, tilesWithinRange.Count);
                TileManager.PlaceTile(t, tempTileIndex, null, DungeonUtility.GetTilemap(), tilesWithinRange[tempTileIndex], DictionaryType.Floor);

                m_floorPositions.Add(t);
                Tile tileT = DungeonUtility.GetTilemap().GetTile <Tile>(t);
                if (tilesWithinRange[tempTileIndex].SpriteVariations.Length > 0)
                {
                    Sprite sT = tilesWithinRange[tempTileIndex].SpriteVariations[Random.Range(0, tilesWithinRange[tempTileIndex].SpriteVariations.Length)];
                    if (sT != null)
                    {
                        tileT.sprite = sT;
                    }
                }
            }
        }
Ejemplo n.º 9
0
 private void UpdateSelectedTileHolder(TileHolder currentClickedTileHolder)
 {
     _currentSelectedTileHolderSetRepository.Set(
         currentClickedTileHolder
         );
     _previousClickedTileHolder = currentClickedTileHolder;
 }
Ejemplo n.º 10
0
 private void ReverseY(List <TileHolder.TileConfig> l, Area a, TileHolder g)
 {
     foreach (TileHolder.TileConfig t in l)
     {
         t.Y(g.Max().y - t.pos.y);
     }
 }
Ejemplo n.º 11
0
 private void OnSelectedTileUpdated([CanBeNull] TileHolder tileHolder)
 {
     if (_viewModel.CurrentlyHoveredTileHolderLiveData.Value == tileHolder)
     {
         _hoveredTileIndicatorController.SetDisabled();
     }
 }
Ejemplo n.º 12
0
    void Awake()
    {
        instance = this;

        address.Clear();
        while (address.Count < 1024)
        {
            address.Add("");
        }


        try
        {
            sprites = Resources.LoadAll <Sprite>(tiles.name);
            TextAsset ta   = Resources.Load <TextAsset>(tiles.name + "_data");
            string    vals = ta.text.Replace("\r", "");         // System.IO.File.ReadAllText("Assets/Resources/" +tiles.name+"_data.txt").Replace("\r","");
            string[]  data = vals.Split("\n"[0]);
            address.Clear();
            address.AddRange(data);

            while (address.Count > 1024)
            {
                address.RemoveAt(1023);
            }
        }
        catch
        {
        }
        while (address.Count < 1024)
        {
            address.Add("");
        }
    }
Ejemplo n.º 13
0
    fieldSprite DrawSprite(bool pEvenOdd, OAM pOAM)
    {
        // сначала пытаемся найти тот же спрайт
        fieldSprite spr = sprites.Find(s => /*s.spriteNum == pOAM.spriteNum &&*/ s.EvenOdd != pEvenOdd && s.active);

        // пытаемся найти неактивный спрайт
        if (spr == null)
        {
            spr = sprites.Find(s => !s.active);
        }

        // клонируем
        if (spr == null)
        {
            spr = Instantiate(defaultSprite) as fieldSprite;
            spr.transform.SetParent(transform);
            spr.transform.localScale = Vector3.one * 10;
            sprites.Add(spr);
        }

        spr.transform.localPosition = new Vector3(0f + scale * pOAM.xTop, 0f - scale * pOAM.yTop, 0);
        spr.spriteNum     = pOAM.spriteNum;
        spr.EvenOdd       = pEvenOdd;
        spr.active        = true;
        pOAM.isBackGround = false;
        spr.DrawSprite(TileHolder.GetSprite(pOAM));
        return(spr);
    }
Ejemplo n.º 14
0
    void FillEmptySpaces()
    {
        for (int x = 0; x < grid.GetLength(0); x++)
        {
            for (int y = 0; y < grid.GetLength(1); y++)
            {
                if (grid[x, y].tileType == TileType.Normal)
                {
                    TileHolder tile = Instantiate(tilePrefab, transform).GetComponent <TileHolder>();
                    tile.x      = x;
                    tile.y      = y;
                    tiles[x, y] = tile;

                    grid[x, y].X = x;
                    grid[x, y].Y = y;

                    tile.transform.position = new Vector3(x, y);
                }
                if (x == grid.GetLength(0) - 1)
                {
                    if (grid[x, y].tileType != TileType.Impassable)
                    {
                        grid[x, y].tileType = TileType.Victory;
                    }
                }
            }
        }

        if (onTilesReady != null)
        {
            onTilesReady();
        }
    }
Ejemplo n.º 15
0
    public void SetTile(TileHolder tile)
    {
        if (IsInsideGrid(tile.x, tile.y) && tile.tileType != TileType.Normal)
        {
            grid[tile.x, tile.y]  = new GridTile(tile.x, tile.y, tile.tileType);
            tiles[tile.x, tile.y] = tile;
            if (tile.y == grid.GetLength(1) - 1)
            {
                tile.SetSprite(TopSide);
                if (Random.Range(0, 101) < stickSpawnChance)
                {
                    Transform stick = SpawnStick(true);
                    stick.SetParent(tile.transform);
                    stick.localPosition = new Vector3(-0.25f, 0.9f);
                }
            }
            else if (tile.y == 0)
            {
                tile.SetSprite(BottomSide);
                if (Random.Range(0, 101) < stickSpawnChance)
                {
                    Transform stick = SpawnStick(false);
                    stick.SetParent(tile.transform);
                    stick.localPosition = new Vector3(-0.25f, -0.9f);
                }
            }
            if (fillWaitCoroutine != null)
            {
                StopCoroutine(fillWaitCoroutine);
            }

            fillWaitCoroutine = StartCoroutine(WaitForTiles());
        }
    }
Ejemplo n.º 16
0
    /*------------------------------------------------------------------------------------------------------------------*/
    /********************************************************************************************************************/
    /************************************************ Unity Behaviours **************************************************/
    /********************************************************************************************************************/
    /*------------------------------------------------------------------------------------------------------------------*/

    #region Unity Behaviours

    /// <summary>
    /// The Awake method.
    /// </summary>
    private void Awake()
    {
        if (Instance != this)
        {
            Instance = this;
        }
        CheckTiles();
    }
Ejemplo n.º 17
0
    public void SetTileHolder(TileHolder th)
    {
        Vector3 origPos = transform.position;

        transform.parent   = th.transform;
        transform.position = origPos;
        th.tile            = this;
        tileHolder         = th;
    }
Ejemplo n.º 18
0
    void OnMouseDrag()
    {
        //only if movement is allowed
        if (_allowMovement)
        {
            if (!_dragging)
            {
                OnStartDrag();
                _dragging = true;
            }

            //if hovered a tile that is reachable then move have the player move there
            Collider   tileParent;
            TileHolder tileHolder = null;
            if (BoardUI.GetTileHovered_Position(out tileParent))
            {
                tileHolder = tileParent.GetComponentInChildren <TileHolder> ();
            }

            if (tileHolder != null)
            {
                //try get the commander position marker
                GameObject posMarker = getCommanderMarker(tileHolder);
                if (posMarker != null)
                {
                    _toGoTo              = posMarker.transform.position;
                    _destination         = _toGoTo;
                    _destinationRotation = posMarker.transform.rotation;
                }
                else
                {
                    _toGoTo      = tileHolder.transform.position;
                    _destination = _toGoTo;
                }

                _toGoTo.y = _LiftedHeight;

                _targetY = tileHolder._Tile.Height;

                _destinationTile = tileHolder;

                //dragging
                OnDraggingCommander();
            }
            else
            {
                _destinationTile = null;
            }

            if (!_hasBeenLifted && !_liftingPiece)              // && _destinationTile == null )//|| _prevHovered != hoveredCollider))
            {
                LiftPiece();
            }
            //block raycast
            this.gameObject.layer = LayerMask.NameToLayer("Ignore Raycast");
        }
    }
Ejemplo n.º 19
0
        public IEnumerator CreateSpawner(EnemyPreset preset, TileHolder tile, YieldInstruction wait = null)
        {
            var spawner = new EnemySpawner(preset, tile.Tile);
            var obj     = Instantiate(spawnerPrefab);

            obj.SetVisual(preset.SpawnerVisualPrefab);
            obj.Init(spawner, tile);
            _currentSpawners.Add(obj);
            yield return(wait);
        }
Ejemplo n.º 20
0
        private IEnumerator CreateEnemy(EnemyPreset preset, TileHolder tile, WaitForSeconds wait)
        {
            var enemy = new Enemy(preset, tile.Tile);
            var obj   = Instantiate(enemyPrefab);

            obj.SetVisual(preset.VisualPrefab);
            obj.Init(enemy, tile);
            _currentEnemies.Add(obj);
            yield return(wait);
        }
 public static TileHolder GetTileHolder(TileType _type)
 {
     foreach (TileHolder t in m_tileHolders)
     {
         if (t.name.Contains(_type.ToString()))
         {
             m_tileHolderToReturn = t;
         }
     }
     return(m_tileHolderToReturn);
 }
Ejemplo n.º 22
0
        public IEnumerator CreateTower(TowerPreset preset, TileHolder tile, YieldInstruction wait = null)
        {
            var tower = new Tower(preset, tile.Tile);
            var obj   = Instantiate(TowerPrefab);

            obj.SetVisual(preset.VisualPrefab);
            obj.Init(tower, tile);
            _currentTowers.Add(obj);

            yield return(wait);
        }
Ejemplo n.º 23
0
        static void BuildPathTile(Vector3Int _pos)
        {
            TileHolder        tileHolder       = TileManager.GetTileHolder(TileType.Path);
            float             randomFreq       = Random.Range(1, tileHolder.Tiles.OrderByDescending(t => t.PickChance).First().PickChance);
            List <CustomTile> tilesWithinRange = new List <CustomTile>();

            tilesWithinRange = tileHolder.Tiles.Where(t => t.PickChance >= randomFreq).ToList();
            int tempTileIndex;

            tempTileIndex = Random.Range(0, tilesWithinRange.Count);
            TileManager.PlaceTile(_pos, tempTileIndex, WallGen.GetTilemap(), DungeonUtility.GetTilemap(), tilesWithinRange[tempTileIndex], DictionaryType.Floor);
        }
Ejemplo n.º 24
0
    void _lerpPosition_OnLerpFinished()
    {
        //if lifting piece then not doin it anymore
        if (_liftingPiece)
        {
            _liftingPiece  = false;
            _hasBeenLifted = true;

            if (_forceMove)
            {
                // move over the destination tile
                _lerpPosition._LerpTime = _MoveTime;
                _toGoTo   = _destination;
                _toGoTo.y = _LiftedHeight;
                _lerpPosition.LerpTo(_toGoTo);
            }
        }
        // if commander has been dropped
        else if (this.transform.position.y != _LiftedHeight)
        {
            OnCommanderGrounded(_Player.CommanderPosition);

            if (_destinationTile != null)
            {
                if (_forceMove && _forceMoveEvents)
                {
                    OnCommanderForceMoved(_destinationTile._Tile);
                }
                else
                {
                    OnCommanderMoved(_destinationTile._Tile);
                }
            }
            _destinationTile = null;
            _hasBeenLifted   = false;

            if (_forceMove)
            {
                // force move has ended
                _forceMove       = false;
                _forceMoveEvents = false;
            }
        }
        // if commander has been force moved over a tile
        else if (_forceMove && _hasBeenLifted)
        {
            _toGoTo.y = _targetY;
            if (_destinationRotation != null)
            {
                _lerpRotation.LerpTo(_destinationRotation);
            }
        }
    }
Ejemplo n.º 25
0
 void Awake()
 {
     if (Instance == null)
     {
         Instance = this;
         DontDestroyOnLoad(this);
     }
     else if (Instance != this)
     {
         Destroy(gameObject);
     }
 }
Ejemplo n.º 26
0
    void loadGrid(float x, float y)
    {
        gridX = (int)x;
        gridY = (int)y;
        clearGrid();
//		foreach (GameObject g in linesArray) {
//			Destroy (g);
//		}
        gridsArray = new Tile[gridX, gridY];
        linesArray = new ArrayList();
        float minX = -x / 2.0f + 0.5f;
        float minY = y / 2.0f - 0.5f;
        float maxX = x / 2.0f - 0.5f;
        float maxY = -y / 2.0f + 0.5f;
        //Debug.Log("x: " + x + ", minX: " + minX);
        int xcur = 0;

        for (float n = minX; n <= maxX; n++)
        {
            int ycur = 0;
            for (float m = minY; m >= maxY; m--)
            {
                GameObject go = (GameObject)Instantiate(gridPrefab);
                Tile       t  = new Tile(go, xcur, ycur, 255.0f, 255.0f, 255.0f, 0.4f);
                TileHolder th = go.AddComponent <TileHolder>();
                th.tile = t;
                gridsArray[xcur, ycur] = t;
                go.transform.position  = new Vector3(n, m, 0);
                go.transform.parent    = grids.transform;
                //		SpriteRenderer sr = go.GetComponent<SpriteRenderer>();
                //	sr.sprite.border = new Vector4(1.0f,1.0f,1.0f,1.0f);
                //		sr.color = new Color(t.red,t.green,t.blue,t.alpha);
                ycur++;
            }
            xcur++;
        }

        /*
         * int x1 = 1;
         * for (float n=minX;n<=minX;n++) {
         *      GameObject go = new GameObject("LineX" + x1);
         *      LineRenderer lr = go.AddComponent<LineRenderer>();
         *      go.transform.parent = lines.transform;
         *      lr.SetVertexCount(2);
         *      lr.SetPosition(0,new Vector3(n,minY,0));
         *      lr.SetPosition(1,new Vector3(n,maxY,0));
         *      lr.material = new Material(Shader.Find("Unlit/Texture"));
         *      lr.SetColors(Color.black,Color.black);
         *      lr.SetWidth(71.0f/70.0f,71.0f/70.0f);
         * }
         * xx++;*/
    }
Ejemplo n.º 27
0
    private void FlipXY(List <TileHolder.TileConfig> l, Area a, TileHolder g)
    {
        int        tmp     = g.Max().x;
        Vector2Int flipmax = new Vector2Int(g.Max().y, g.Max().y);

        g.Max(flipmax);

        foreach (TileHolder.TileConfig t in l)
        {
            tmp = t.pos.x;
            t.X(t.pos.y);
            t.Y(tmp);
        }
    }
Ejemplo n.º 28
0
        public void ShowIndicator([CanBeNull] TileHolder tileHolder)
        {
            if (tileHolder == null)
            {
                SetDisabled();
                return;
            }

            var indicatorPosition = tileHolder.transform.position;

            indicatorPosition.y += config.IndicatorOffsetFromMap;

            indicatorGameObject.transform.position = indicatorPosition;
            indicatorGameObject.SetActive(true);
        }
Ejemplo n.º 29
0
    private void Start()
    {
        TileList.Init();
        TileHolder.Init();

        Rect          camR     = Utils.CameraRect();
        Rect          listR    = TileList.CalculateWorldRect();
        BoxCollider2D colldier = GetComponent <BoxCollider2D>();

        float width  = TileHolder.Width;
        float height = camR.height - TileHolder.Height;

        transform.position = new Vector3(listR.xMax + width / 2, listR.yMax - height / 2);
        colldier.size      = new Vector2(width, height);
    }
Ejemplo n.º 30
0
 void clearGrid()
 {
     if (gridsArray != null)
     {
         foreach (Tile t in gridsArray)
         {
             //	foreach (Tile t in tA) {
             TileHolder th = t.tileGameObject.GetComponent <TileHolder>();
             th.tile = null;
             Destroy(t.tileGameObject);
             //	}
         }
     }
     gridsArray = null;
 }
Ejemplo n.º 31
0
    GameObject getCommanderMarker(TileHolder tHolder)
    {
		if (tHolder == null) {
			return null;
		}

        switch (_Player.Type)
        {
            case PlayerType.None:
                Debug.LogError("Cannot get marker for player type None");
                break;
            case PlayerType.Battlebeard:
                return tHolder._MarkerCommanderBB;
            case PlayerType.Stormshaper:
                return tHolder._MarkerCommanderSS;
            default:
                Debug.LogError("Unhandled player type getting position marker");
                break;
        }

        return null;
    }
Ejemplo n.º 32
0
    void _lerpPosition_OnLerpFinished()
    {
        //if lifting piece then not doin it anymore
        if (_liftingPiece)
        {
            _liftingPiece = false;
            _hasBeenLifted = true;

			if (_forceMove) {
				// move over the destination tile
				_lerpPosition._LerpTime = _MoveTime;
				_toGoTo = _destination;
				_toGoTo.y = _LiftedHeight;
				_lerpPosition.LerpTo(_toGoTo);
			}
        }
		// if commander has been dropped
        else if (this.transform.position.y != _LiftedHeight)
        {
			OnCommanderGrounded(_Player.CommanderPosition);
		
			if (_destinationTile != null){
				if (_forceMove && _forceMoveEvents) {
					OnCommanderForceMoved(_destinationTile._Tile);
				}
				else {
					OnCommanderMoved(_destinationTile._Tile);
				}
			}
			_destinationTile = null;
            _hasBeenLifted = false;

			if (_forceMove) {
				// force move has ended
				_forceMove = false;
				_forceMoveEvents = false;
			}
		}
		// if commander has been force moved over a tile
		else if (_forceMove && _hasBeenLifted) {
			_toGoTo.y = _targetY;
			if (_destinationRotation != null) {
				_lerpRotation.LerpTo(_destinationRotation);
			}
		}
    }
Ejemplo n.º 33
0
    void OnMouseDrag()
    {
		//only if movement is allowed
		if (_allowMovement) {

			if (!_dragging) {
				OnStartDrag ();
				_dragging = true;
			}

			//if hovered a tile that is reachable then move have the player move there
			Collider tileParent;
			TileHolder tileHolder = null;
			if (BoardUI.GetTileHovered_Position (out tileParent)){
				tileHolder = tileParent.GetComponentInChildren<TileHolder> ();
			}

            if (tileHolder != null)
            {

                //try get the commander position marker
                GameObject posMarker = getCommanderMarker(tileHolder);
                if (posMarker != null)
                {
                    _toGoTo = posMarker.transform.position;
                    _destination = _toGoTo;
					_destinationRotation = posMarker.transform.rotation;
                }
                else
                {
                    _toGoTo = tileHolder.transform.position;
                    _destination = _toGoTo;
                }

                _toGoTo.y = _LiftedHeight;

				_targetY = tileHolder._Tile.Height;

                _destinationTile = tileHolder;

                //dragging
                OnDraggingCommander();
            }
            else
            {
                _destinationTile = null;
            }

			if (!_hasBeenLifted && !_liftingPiece) {// && _destinationTile == null )//|| _prevHovered != hoveredCollider))
				LiftPiece ();
			}
            //block raycast 
            this.gameObject.layer = LayerMask.NameToLayer("Ignore Raycast");
		}
    }
Ejemplo n.º 34
0
    void OnMouseUp()
    {
        _dragging = false;

		//if the tile hovered is not in the reachable set then back to original tile
        if (_destinationTile == null || !_reachableTiles.Contains(_destinationTile._Tile))
        {
			//commander not moved
			_destinationTile = null;
            GameObject posMarker = getCommanderMarker(_Player.CommanderPosition.TileObject.GetComponentInChildren<TileHolder>());
            _toGoTo = (posMarker!=null) ? posMarker.transform.position: _Player.CommanderPosition.TileObject.transform.position;
			_targetY = _Player.CommanderPosition.Height;
        }
        else
        {
            //commander moved
            _toGoTo = _destination;
			OnCommanderDrop(new Vector3(_destination.x, _targetY, _destination.z));
           // _destinationTile = null;
        }

        //drop the commander
        _toGoTo.y = _targetY;
		if (_destinationRotation != null) {
			// rotate to the new marker rotation
			_lerpRotation.LerpTo(_destinationRotation);
		}
        OnDropCommander(_Player.CommanderPosition);


        //raycast 
        this.gameObject.layer = _defaultLayer;
    }
Ejemplo n.º 35
0
	// moves the commander to a certain position. fires events as usual
	public void MoveCommander(TileData tile){
		if (_hasBeenLifted || _liftingPiece) {
			return;
		}
		TileHolder tileHolder = tile.TileObject.GetComponentInChildren<TileHolder>();
		if (tileHolder != null) {

			_forceMove = true;
			
			//try get the commander position marker
			GameObject posMarker = getCommanderMarker(tileHolder);
			if (posMarker != null) {
				_destination = posMarker.transform.position;
				_destinationRotation = posMarker.transform.rotation;
			}
			else {
				_destination = tileHolder.transform.position;
			}

			_targetY = tileHolder._Tile.Height;
			_destinationTile = tileHolder;

			LiftPiece();
		}
	}