Exemple #1
0
    // Update is called once per frame
    void Update()
    {
        cursorMove();
        switch (stateIndex)
        {
        case 0:
            lvl = lvlManager.getLevelObjectFromTilePos(lvlManager.getTilePosFromWorldPos(ingameCursor.position));
            if (lvl != null)
            {
                //Reset the previous tile back to normal
                if (previousSelectedTile != null)
                {
                    previousSelectedTile.GetComponent <Renderer>().material = previousSelectedTileMaterial;
                    previousSelectedTileMaterial = lvl.levelTile.hexObject.gameObject.GetComponent <Renderer>().material;
                }

                //Set material of selected tile
                lvl.levelTile.hexObject.gameObject.GetComponent <Renderer>().material = selectedTileMaterial;

                //Add update list of selected tiles
                selectedTiles.Clear();
                selectedTiles.Add(lvl.levelTile);

                //update debug text of current selected tile
                selectedLevelText.text = "lvl :" + lvl.levelTile.tileIndex_X + "  " + lvl.levelTile.tileIndex_Y;

                previousSelectedTile = lvl.levelTile.hexObject.gameObject;
            }
            break;

        default:
            VRAR_Tile selTile = lvl.getTileFromIndexPos(lvlManager.getTilePosFromWorldPos(ingameCursor.position).x, lvlManager.getTilePosFromWorldPos(ingameCursor.position).y);
            if (selTile != null)
            {
                //Reset the previous tile back to normal
                if (previousSelectedTile != null)
                {
                    previousSelectedTile.GetComponent <Renderer>().material = previousSelectedTileMaterial;
                    previousSelectedTileMaterial = selTile.hexObject.gameObject.GetComponent <Renderer>().material;
                }

                //Set material of selected tile
                selTile.hexObject.gameObject.GetComponent <Renderer>().material = selectedTileMaterial;

                //Add update list of selected tiles
                selectedTiles.Clear();
                selectedTiles.Add(selTile);

                //update debug text of current selected tile
                selectedLevelText.text = "lvl :" + selTile.tileIndex_X + "  " + selTile.tileIndex_Y;

                previousSelectedTile = selTile.hexObject.gameObject;

                lvl.tileUpdate(0, 0);
            }
            break;
        }
    }
Exemple #2
0
    void FixedUpdate()
    {
        //Debug.Log(brushTicking);


        if (brushTicking && (GameStateManager.instance.getGlobalStateIndex() == GameStateManager.STATE_LEVEL_EDITOR || GameStateManager.instance.getGlobalStateIndex() != GameStateManager.STATE_PLAYING) && !Valve.VR.InteractionSystem.VRInputHandler.isInTileObjectEditMenu)
        {
            //EditTile(brushActionDropdown.value);
            EditTile(currentBrush);
        }
        else if (brushTicking && GameStateManager.instance.getGlobalStateIndex() == GameStateManager.STATE_PLAYING)
        {
            EditTile(currentBrush);
        }
        else if (TileToolEditTick && GameStateManager.instance.getGlobalStateIndex() == GameStateManager.STATE_LEVEL_EDITOR)
        {
            TileToolEditTick = false;

            /*
             * VRAR_Level lvl = GameStateManager.instance.getCurrentLevel();//TileRenderer.getCurrLVL();
             *
             *
             * VRAR_Tile tile = lvl.getTileFromIndexPos(lvlManager.getTilePosFromWorldPos(ingameCursor.position).x, lvlManager.getTilePosFromWorldPos(ingameCursor.position).y);
             * if (tile != null)
             * {
             *  //currentlySelected = tile;
             *
             *  if (!menuOpen)
             *  {
             *      menuOpen = true;
             *      OpenTileProperties(tile);
             *  }
             * }*/
        }
        else if (GameStateManager.instance.getGlobalStateIndex() == GameStateManager.STATE_PLAYING || GameStateManager.instance.getGlobalStateIndex() == GameStateManager.STATE_LEVEL_EDITOR)
        {
            VRAR_Level lvl  = GameStateManager.instance.getCurrentLevel();
            VRAR_Tile  tile = lvl.getTileFromIndexPos(lvlManager.getTilePosFromWorldPos(ingameCursor.position).x, lvlManager.getTilePosFromWorldPos(ingameCursor.position).y);

            if (tile != null)
            {
                if (tile != lastSelectedTile)
                {
                    OpenTileProperties(tile);
                }
                lastSelectedTile = tile;
            }
        }
    }
Exemple #3
0
    // Update is called once per frame
    void Update()
    {
        //cursorMove();
        switch (GameStateManager.instance.getGlobalStateIndex())
        {
        case GameStateManager.STATE_CAMPAIGN_EDITOR:
            cursorMarker.position = Vector3.Scale(leftHandCursor.position, (truncY)) + offY;
            lvl = lvlManager.getLevelObjectFromTilePos(lvlManager.getTilePosFromWorldPos(leftHandCursor.position));
            if (lvl != null)
            {
                GameStateManager.instance.setCurrentLevel(lvl);

                //Reset the previous tile back to normal
                if (previousSelectedTile != null)
                {
                    //    previousSelectedTile.GetComponent<Renderer>().material = previousSelectedTileMaterial;
                    //    previousSelectedTileMaterial = lvl.levelTile.hexObject.gameObject.GetComponent<Renderer>().material;
                    previousSelectedTile.hexObject.gameObject.GetComponent <Renderer>().material = TileObjectManger.getMaterial(previousSelectedTile.GetTerrain());
                }

                //Set material of selected tile
                lvl.levelTile.hexObject.gameObject.GetComponent <Renderer>().material = selectedTileMaterial;

                //Add update list of selected tiles
                selectedTiles.Clear();
                selectedTiles.Add(lvl.levelTile);

                //update debug text of current selected tile
                selectedLevelText.text = "lvl :" + lvl.levelTile.tileIndex_X + "  " + lvl.levelTile.tileIndex_Y;

                //previousSelectedTile = lvl.levelTile.hexObject.gameObject;
                previousSelectedTile = lvl.levelTile;
            }
            break;

        case GameStateManager.STATE_LEVEL_EDITOR:
            lvl = GameStateManager.instance.getCurrentLevel();
            //Debug.Log("level state :"+lvl.levelTile.ToString());
            cursorMarker.position = Vector3.Scale(rightHandCursor.position, (truncY)) + offY;
            //cursorMarker.position *= 5f;
            //VRAR_Tile selTile=  lvl.getTileFromIndexPos(lvlManager.getTilePosFromWorldPos(rightHandCursor.position).x, lvlManager.getTilePosFromWorldPos(rightHandCursor.position).y);
            VRAR_Tile selTile = lvl.getTileFromIndexPos(lvlManager.getTilePosFromWorldPos(cursorMarker.position).x, lvlManager.getTilePosFromWorldPos(cursorMarker.position).y);
            if (selTile != null)
            {
                //Reset the previous tile back to normal
                if (previousSelectedTile != null)
                {
                    //previousSelectedTile.GetComponent<Renderer>().material = previousSelectedTileMaterial;
                    //previousSelectedTileMaterial = selTile.hexObject.gameObject.GetComponent<Renderer>().material;
                    previousSelectedTile.hexObject.gameObject.GetComponent <Renderer>().material = TileObjectManger.getMaterial(previousSelectedTile.GetTerrain());
                }

                //Set material of selected tile
                selTile.hexObject.gameObject.GetComponent <Renderer>().material = selectedTileMaterial;

                //Add update list of selected tiles
                selectedTiles.Clear();
                selectedTiles.Add(selTile);

                //update debug text of current selected tile
                selectedLevelText.text = "lvl :" + selTile.tileIndex_X + "  " + selTile.tileIndex_Y;

                //previousSelectedTile = selTile.hexObject.gameObject;
                previousSelectedTile = selTile;

                lvl.tileUpdate(0, 0);
            }
            break;

        case GameStateManager.STATE_PLAYING:
            break;
        }
    }
Exemple #4
0
    public void EditTile(int num)
    {
        VRAR_Level lvl  = GameStateManager.instance.getCurrentLevel();
        VRAR_Tile  tile = lvl.getTileFromIndexPos(lvlManager.getTilePosFromWorldPos(ingameCursor.position).x, lvlManager.getTilePosFromWorldPos(ingameCursor.position).y);

        currentBrush = num;
        if (brushTickDivider-- == 0) // || true)
        {
            brushTickDivider = 4;
            //VRAR_Level lvl = GameStateManager.instance.getCurrentLevel();//TileRenderer.getCurrLVL();

            //VRAR_Tile tile = lvl.getTileFromIndexPos(lvlManager.getTilePosFromWorldPos(ingameCursor.position).x, lvlManager.getTilePosFromWorldPos(ingameCursor.position).y);
            if (tile != null)
            {
                //currentlySelected = tile;
                List <VRAR_Tile> effectedTiles = lvl.selectRadius(tile.tileIndex_X, tile.tileIndex_Y, brushSize);

                //resetPrevous.Clear();
                // resetPrevous.Add(lvl.getTileFromIndexPos(lvlManager.getTilePosFromWorldPos(leftHandCursor.position).x, lvlManager.getTilePosFromWorldPos(leftHandCursor.position).y));
                foreach (VRAR_Tile surroundTile in effectedTiles)
                {
                    if (surroundTile.hexObject != null)//phantom tiles shouldn't be changed
                    {
                        switch (num)
                        {
                        case 0:
                            if (surroundTile.height_ < maxTileHeight)
                            {
                                surroundTile.setHeight(surroundTile.height_ + 0.1f);
                                TileRenderer.instance.updateTile(surroundTile);    //todo only do this after the user stopped changing the height (for optimization)
                            }
                            //else { surroundTile.setHeight(minTileHeight); }
                            break;

                        case 1:
                            if (surroundTile.height_ > minTileHeight)
                            {
                                surroundTile.setHeight(surroundTile.height_ - 0.1f);
                                TileRenderer.instance.updateTile(surroundTile);    //todo only do this after the user stopped changing the height (for optimization)
                            }
                            //else { surroundTile.setHeight(maxTileHeight); }
                            break;

                        case 3:
                        {
                            //remove tile
                            VRAR_Tile remTile = lvl.removeTile(surroundTile.tileIndex_X, surroundTile.tileIndex_Y);

                            var tileMessage = new TileMessage(remTile, true);
                            NetworkServer.SendToAll(CustomNetMsg.Tile, tileMessage);

                            TileRenderer.instance.updateTile(surroundTile);
                        }
                        break;

                        case 4:
                            if (surroundTile.hexObject != null)
                            {
                                //surroundTile.hexObject.gameObject.GetComponent<Renderer>().material = tileRenderer.defaultTileMaterial;
                                surroundTile.SetTerrain("Mountain");
                                TileRenderer.instance.updateTile(surroundTile);
                            }
                            break;

                        case 5:
                            if (surroundTile.hexObject != null)
                            {
                                //surroundTile.hexObject.gameObject.GetComponent<Renderer>().material = tileRenderer.waterTileMaterial;
                                surroundTile.SetTerrain("Water");
                                TileRenderer.instance.updateTile(surroundTile);
                            }
                            break;

                        case 6:
                            if (surroundTile.hexObject != null)
                            {
                                //surroundTile.hexObject.gameObject.GetComponent<Renderer>().material = tileRenderer.selectedTileMaterial;
                                surroundTile.SetTerrain("Grass");
                                TileRenderer.instance.updateTile(surroundTile);
                            }
                            break;
                        }
                    }
                    else
                    {//functions that run on both existing and phantom tiles but when the cursor is still on a existing tile!
                        switch (num)
                        {
                        case 2:
                            //if tile is phantom tile, create actual
                            if (surroundTile.isPhantom)
                            {
                                TileRenderer.instance.updateTile(lvl.addNewTile(surroundTile.tileIndex_X, surroundTile.tileIndex_Y));
                            }
                            break;
                        }
                    }
                }
                //lastSelectedTile = tile;
            }
            else
            {//cursor is not actually on a tile
                switch (num)
                {
                case 2:
                    //spawn middle tile first (and the rest gets spawned in the next tick), and select amount around it
                    TileRenderer.instance.updateTile(lvl.addNewTile(lvlManager.getTilePosFromWorldPos(ingameCursor.position).x, lvlManager.getTilePosFromWorldPos(ingameCursor.position).y));
                    break;

                case 3:
                {
                    VRAR_Tile        middleTempTile = (lvl.addNewTile(lvlManager.getTilePosFromWorldPos(ingameCursor.position).x, lvlManager.getTilePosFromWorldPos(ingameCursor.position).y));
                    List <VRAR_Tile> deletingTiles  = lvl.selectRadius(middleTempTile.tileIndex_X, middleTempTile.tileIndex_Y, brushSize);

                    foreach (VRAR_Tile surroundTile in deletingTiles)
                    {
                        TileRenderer.instance.updateTile(lvl.removeTile(surroundTile.tileIndex_X, surroundTile.tileIndex_Y));
                    }
                }
                break;
                }
            }
        }
    }
Exemple #5
0
    // Update is called once per frame
    void Update()
    {
        //cursorMove();
        switch (GameStateManager.instance.getGlobalStateIndex())
        {
        case GameStateManager.STATE_CAMPAIGN_EDITOR:
            cursorMarker.position = Vector3.Scale(leftHandCursor.position, (truncY)) + offY;
            lvl = lvlManager.getLevelObjectFromTilePos(lvlManager.getTilePosFromWorldPos(leftHandCursor.position));
            if (lvl != null)
            {
                GameStateManager.instance.setCurrentLevel(lvl);

                //Reset the previous tile back to normal
                if (previousSelectedTile != null)
                {
                    previousSelectedTile.hexObject.gameObject.GetComponent <Renderer>().material = TileObjectManger.getMaterial(previousSelectedTile.GetTerrain());
                }

                //Set material of selected tile
                lvl.levelTile.hexObject.gameObject.GetComponent <Renderer>().material = TileObjectManger.getMaterial("Selection");

                //Add update list of selected tiles
                selectedTiles.Clear();
                selectedTiles.Add(lvl.levelTile);

                //update debug text of current selected tile
                selectedLevelText.text = "lvl :" + lvl.levelTile.tileIndex_X + "  " + lvl.levelTile.tileIndex_Y;

                previousSelectedTile = lvl.levelTile;
            }
            break;

        case GameStateManager.STATE_LEVEL_EDITOR:
            lvl = GameStateManager.instance.getCurrentLevel();
            cursorMarker.position = Vector3.Scale(rightHandCursor.position, (truncY)) + offY;
            selTile = lvl.getTileFromIndexPos(lvlManager.getTilePosFromWorldPos(cursorMarker.position).x, lvlManager.getTilePosFromWorldPos(cursorMarker.position).y);
            if (selTile != null && selTile.hexObject != null && !Valve.VR.InteractionSystem.VRInputHandler.isInTileObjectEditMenu)
            {
                //if selectedHexPrefab is a prefab (so not in any scene)
                if (selectedHexPrefab.gameObject.scene.name == null)
                {
                    selectedHexPrefabItem = selectedHexPrefab;
                    //spawn prefab is scene
                    selectedHexPrefab = Instantiate(selectedHexPrefab);
                }


                //Reset the previous tile back to normal
                if (previousSelectedTile != null)
                {
                    //previousSelectedTile.hexObject.gameObject.GetComponent<Renderer>().material = TileObjectManger.getMaterial(previousSelectedTile.GetTerrain());
                }

                //Set material of selected tile

                //selTile.hexObject.gameObject.GetComponent<Renderer>().material = TileObjectManger.getMaterial("Selection");
                selectedHexPrefab.gameObject.transform.position = selTile.hexObject.position + (new Vector3(0, (float)(selTile.height_ + 0.1), 0));

                //Add update list of selected tiles
                selectedTiles.Clear();
                selectedTiles.Add(selTile);

                //update debug text of current selected tile
                selectedLevelText.text = "lvl :" + selTile.tileIndex_X + "  " + selTile.tileIndex_Y;

                previousSelectedTile = selTile;

                lvl.tileUpdate(0, 0);
            }
            break;

        case GameStateManager.STATE_PLAYING:
            lvl = GameStateManager.instance.getCurrentLevel();
            cursorMarker.position = Vector3.Scale(rightHandCursor.position, (truncY)) + offY;
            selTile = lvl.getTileFromIndexPos(lvlManager.getTilePosFromWorldPos(cursorMarker.position).x, lvlManager.getTilePosFromWorldPos(cursorMarker.position).y);
            if (selTile != null && selTile.hexObject != null && !Valve.VR.InteractionSystem.VRInputHandler.isInTileObjectEditMenu)
            {
                if (prevSelTile != selTile)
                {
                    //var tileMessage = new TileMessage(selTile);
                    if (prevSelTile != null && prevSelTile.hexObject != null)
                    {
                        foreach (VRAR_Tile tile in GameStateManager.instance.getCurrentLevel().dirtyTiles)
                        {
                            var tileMessage = new TileMessage(tile, false);
                            NetworkServer.SendToAll(CustomNetMsg.Tile, tileMessage);
                        }
                        GameStateManager.instance.getCurrentLevel().dirtyTiles.Clear();
                    }
                }

                //if selectedHexPrefab is a prefab (so not in any scene)
                if (selectedHexPrefab.gameObject.scene.name == null)
                {
                    selectedHexPrefabItem = selectedHexPrefab;
                    //spawn prefab is scene
                    selectedHexPrefab = Instantiate(selectedHexPrefab);
                }

                //Set material of selected tile
                selectedHexPrefab.gameObject.transform.position = selTile.hexObject.position + (new Vector3(0, selTile.height_ - 1, 0));

                prevSelTile = selTile;
            }
            break;
        }
    }
Exemple #6
0
    void Update()
    {
        if (brushTicking)
        {
            if (brushTickDivider-- == 0)
            {
                brushTickDivider = 4;
                //VRAR_Level lvl = lvlManager.getLevelObjectFromTilePos(lvlManager.getTilePosFromWorldPos(ingameCursor.position));
                VRAR_Level lvl = TileRenderer.getCurrLVL();

                VRAR_Tile tile = lvl.getTileFromIndexPos(lvlManager.getTilePosFromWorldPos(ingameCursor.position).x, lvlManager.getTilePosFromWorldPos(ingameCursor.position).y);
                if (tile != null)
                {
                    List <VRAR_Tile> effectedTiles = lvl.selectRadius(tile.tileIndex_X, tile.tileIndex_Y, brushSize);

                    //resetPrevous.Clear();
                    // resetPrevous.Add(lvl.getTileFromIndexPos(lvlManager.getTilePosFromWorldPos(ingameCursor.position).x, lvlManager.getTilePosFromWorldPos(ingameCursor.position).y));
                    foreach (VRAR_Tile surroundTile in effectedTiles)
                    {
                        if (surroundTile != null)
                        {
                            switch (brushActionDropdown.value)
                            {
                            case 0:
                                if (surroundTile.height_ < maxTileHeight)
                                {
                                    surroundTile.setHeight(surroundTile.height_ + 0.05f);
                                    //Debug.Log(surroundTile);
                                }
                                //else { surroundTile.setHeight(minTileHeight); }
                                break;

                            case 1:
                                if (surroundTile.height_ > minTileHeight)
                                {
                                    surroundTile.setHeight(surroundTile.height_ - 0.05f);
                                }
                                //else { surroundTile.setHeight(maxTileHeight); }
                                break;

                            case 2:
                                if (surroundTile.hexObject != null)
                                {
                                    surroundTile.hexObject.gameObject.GetComponent <Renderer>().material = tileRenderer.defaultTileMaterial;
                                }
                                break;

                            case 3:
                                if (surroundTile.hexObject != null)
                                {
                                    surroundTile.hexObject.gameObject.GetComponent <Renderer>().material = tileRenderer.waterTileMaterial;
                                }
                                break;

                            case 4:
                                if (surroundTile.hexObject != null)
                                {
                                    surroundTile.hexObject.gameObject.GetComponent <Renderer>().material = tileRenderer.selectedTileMaterial;
                                }
                                break;
                            }
                        }
                        else
                        {
                            Debug.Log("sur was null");
                        }
                    }
                }
            }
        }
    }
Exemple #7
0
    void Update()
    {
        //Debug.Log(brushTicking);
        if (brushTicking && GameStateManager.instance.getGlobalStateIndex() == GameStateManager.STATE_LEVEL_EDITOR)
        {
            if (brushTickDivider-- == 0)
            {
                brushTickDivider = 4;
                //VRAR_Level lvl = lvlManager.getLevelObjectFromTilePos(lvlManager.getTilePosFromWorldPos(leftHandCursor.position));
                VRAR_Level lvl = TileRenderer.getCurrLVL();

                VRAR_Tile tile = lvl.getTileFromIndexPos(lvlManager.getTilePosFromWorldPos(ingameCursor.position).x, lvlManager.getTilePosFromWorldPos(ingameCursor.position).y);
                if (tile != null)
                {
                    currentlySelected = tile;
                    List <VRAR_Tile> effectedTiles = lvl.selectRadius(tile.tileIndex_X, tile.tileIndex_Y, brushSize);
                    if (!menuOpen)
                    {
                        OpenTileProperties(tile);
                        menuOpen = true;
                    }
                    //resetPrevous.Clear();
                    // resetPrevous.Add(lvl.getTileFromIndexPos(lvlManager.getTilePosFromWorldPos(leftHandCursor.position).x, lvlManager.getTilePosFromWorldPos(leftHandCursor.position).y));
                    foreach (VRAR_Tile surroundTile in effectedTiles)
                    {
                        if (surroundTile != null)
                        {
                            switch (brushActionDropdown.value)
                            {
                            case 0:
                                if (surroundTile.height_ < maxTileHeight)
                                {
                                    surroundTile.setHeight(surroundTile.height_ + 0.05f);
                                    //Debug.Log(surroundTile);
                                }
                                //else { surroundTile.setHeight(minTileHeight); }
                                break;

                            case 1:
                                if (surroundTile.height_ > minTileHeight)
                                {
                                    surroundTile.setHeight(surroundTile.height_ - 0.05f);
                                }
                                //else { surroundTile.setHeight(maxTileHeight); }
                                break;

                            case 2:
                                if (surroundTile.hexObject != null)
                                {
                                    //surroundTile.hexObject.gameObject.GetComponent<Renderer>().material = tileRenderer.defaultTileMaterial;
                                    surroundTile.SetTerrain("Mountain");
                                    TileRenderer.instance.updateTile(surroundTile);
                                }
                                break;

                            case 3:
                                if (surroundTile.hexObject != null)
                                {
                                    //surroundTile.hexObject.gameObject.GetComponent<Renderer>().material = tileRenderer.waterTileMaterial;
                                    surroundTile.SetTerrain("Water");
                                    TileRenderer.instance.updateTile(surroundTile);
                                }
                                break;

                            case 4:
                                if (surroundTile.hexObject != null)
                                {
                                    //surroundTile.hexObject.gameObject.GetComponent<Renderer>().material = tileRenderer.selectedTileMaterial;
                                    surroundTile.SetTerrain("Grass");
                                    TileRenderer.instance.updateTile(surroundTile);
                                }
                                break;
                            }
                        }
                        else
                        {
                            Debug.Log("sur was null");
                        }
                    }
                }
            }
        }
    }