Example #1
0
    public void HidePath(LinkElementPlaceholder elementClicked)
    {
        GameObject activator = elementClicked.type == LinkElementPlaceholder.LinkElementType.Activator ? elementClicked.gameObject : elementClicked.elementLinked.gameObject;

        ClearPath(TileMapPathfinding.FindPathCoordinates(V3Helper.V3ToV3Int(currentActivatorShowed.transform.position), V3Helper.V3ToV3Int(currentActivatorShowed.GetComponent <LinkElementPlaceholder>().elementLinked.transform.position)));
        currentActivatorShowed = null;
    }
Example #2
0
    protected override void OnMouseDown()
    {
        if (PuzzleEditorController.instance.GetCurrentTool() == PuzzleEditorController.Tools.Arrow)
        {
            if (state == States.InLevel)
            {
                canvas.gameObject.SetActive(true);

                if (elementLinked)
                {
                    if (buttonText.text != "Unlink")
                    {
                        buttonText.text = "Unlink";
                    }

                    if (elementLinked.GetComponent <LinkElementPlaceholder>().buttonText.text != "Unlink")
                    {
                        elementLinked.GetComponent <LinkElementPlaceholder>().buttonText.text = "Unlink";
                    }

                    LinkElementPlaceholder LEP = elementLinked.GetComponent <LinkElementPlaceholder>();
                    LEP.canvas.gameObject.SetActive(true);

                    PuzzleEditorController.instance.ShowPath(this);
                }
            }
            else
            {
                canvas.gameObject.SetActive(false);
            }
        }
    }
    public static Level BuildLevel(int levelSize, List <GameObject> gameObjects, Tilemap ground, Tilemap collidable)
    {
        Level levelTS = new Level();

        levelTS.size = levelSize;

        for (int i = 0; i < gameObjects.Count; ++i)
        {
            if (gameObjects[i].GetComponent <LinkElementPlaceholder>())
            {
                LinkElementPlaceholder LEP = gameObjects[i].GetComponent <LinkElementPlaceholder>();

                int refPos = -1;

                if (LEP.elementLinked)
                {
                    for (int j = 0; j < gameObjects.Count; ++j)
                    {
                        if (gameObjects[j] == LEP.elementLinked)
                        {
                            refPos = j;
                            break;
                        }
                    }
                }

                levelTS.levelElements.Add(new ElementData(gameObjects[i].transform.position.x, gameObjects[i].transform.position.y, gameObjects[i].transform.position.z, (int)LEP.PEType, refPos));
            }
            else
            {
                PuzzleElementPlaceHolder PEP = gameObjects[i].GetComponent <PuzzleElementPlaceHolder>();

                levelTS.levelElements.Add(new ElementData(gameObjects[i].transform.position.x, gameObjects[i].transform.position.y, gameObjects[i].transform.position.z, (int)PEP.PEType, -1));
            }
        }

        foreach (var pos in ground.cellBounds.allPositionsWithin)
        {
            Vector3Int iPos = new Vector3Int(pos.x, pos.y, pos.z);

            if (ground.HasTile(iPos))
            {
                levelTS.groundTiles.Add(new TileData(iPos.x, iPos.y, iPos.z, CheckTile(ground.GetTile(iPos))));
            }
        }

        foreach (var pos in collidable.cellBounds.allPositionsWithin)
        {
            Vector3Int iPos = new Vector3Int(pos.x, pos.y, pos.z);

            if (collidable.HasTile(iPos))
            {
                levelTS.collidableTiles.Add(new TileData(iPos.x, iPos.y, iPos.z, CheckTile(collidable.GetTile(iPos))));
            }
        }

        return(levelTS);
    }
Example #4
0
    public override void DeleteObject()
    {
        PuzzleEditorController.instance.DeleteLinkingObject(this);

        if (elementLinked)
        {
            LinkElementPlaceholder LEP = elementLinked.GetComponent <LinkElementPlaceholder>();
            LEP.elementLinked   = null;
            LEP.buttonText.text = "Link";
        }

        base.DeleteObject();
    }
Example #5
0
    public void HideAllInspectors()
    {
        foreach (KeyValuePair <GameObject, LinkElementPlaceholder.LinkElementType> pair in linkingObjects)
        {
            LinkElementPlaceholder LEP = pair.Key.GetComponent <LinkElementPlaceholder>();
            if (LEP.canvas.gameObject.activeSelf)
            {
                LEP.canvas.gameObject.SetActive(false);
            }
        }

        ClearCurrentPath();
    }
Example #6
0
    public void DeleteLinkingObject(LinkElementPlaceholder LGO)
    {
        GameObject activator = LGO.type == LinkElementPlaceholder.LinkElementType.Activator ? LGO.gameObject : LGO.elementLinked.gameObject;

        if (LGO.elementLinked && currentActivatorShowed)
        {
            ClearPath(TileMapPathfinding.FindPathCoordinates(V3Helper.V3ToV3Int(activator.transform.position), V3Helper.V3ToV3Int(activator.GetComponent <LinkElementPlaceholder>().elementLinked.transform.position)));

            currentActivatorShowed = null;
        }

        if (linkingObjects.ContainsKey(LGO.gameObject))
        {
            linkingObjects.Remove(LGO.gameObject);
        }
    }
Example #7
0
    public void MovedLinkingObject(LinkElementPlaceholder LEP, Vector3 oldPos)
    {
        GameObject activator = LEP.type == LinkElementPlaceholder.LinkElementType.Activator ? LEP.gameObject : LEP.elementLinked.gameObject;

        if (currentActivatorShowed)
        {
            if (activator != LEP.gameObject)
            {
                ClearPath(TileMapPathfinding.FindPathCoordinates(V3Helper.V3ToV3Int(activator.transform.position), V3Helper.V3ToV3Int(oldPos)));
            }
            else
            {
                ClearPath(TileMapPathfinding.FindPathCoordinates(V3Helper.V3ToV3Int(oldPos), V3Helper.V3ToV3Int(LEP.elementLinked.transform.position)));
            }
        }

        DrawLine(TileMapPathfinding.FindPathCoordinates(V3Helper.V3ToV3Int(activator.transform.position), V3Helper.V3ToV3Int(activator.GetComponent <LinkElementPlaceholder>().elementLinked.transform.position)));
        currentActivatorShowed = activator;
        LEP.canvas.gameObject.SetActive(true);
        LEP.elementLinked.GetComponent <LinkElementPlaceholder>().canvas.gameObject.SetActive(true);
    }
Example #8
0
    public void ShowPath(LinkElementPlaceholder elementClicked)
    {
        if (currentActivatorShowed)
        {
            ClearPath(TileMapPathfinding.FindPathCoordinates(V3Helper.V3ToV3Int(currentActivatorShowed.transform.position), V3Helper.V3ToV3Int(currentActivatorShowed.GetComponent <LinkElementPlaceholder>().elementLinked.transform.position)));
        }

        foreach (KeyValuePair <GameObject, LinkElementPlaceholder.LinkElementType> pair in linkingObjects)
        {
            if (pair.Key != elementClicked.gameObject && pair.Key != elementClicked.elementLinked.gameObject)
            {
                LinkElementPlaceholder LEP = pair.Key.GetComponent <LinkElementPlaceholder>();
                if (LEP.canvas.gameObject.activeSelf)
                {
                    LEP.canvas.gameObject.SetActive(false);
                }
            }
        }

        GameObject activator = elementClicked.type == LinkElementPlaceholder.LinkElementType.Activator ? elementClicked.gameObject : elementClicked.elementLinked.gameObject;

        currentActivatorShowed = activator;
        DrawLine(TileMapPathfinding.FindPathCoordinates(V3Helper.V3ToV3Int(activator.transform.position), V3Helper.V3ToV3Int(activator.GetComponent <LinkElementPlaceholder>().elementLinked.transform.position)));
    }
Example #9
0
    void ApplyLevel(Level level)
    {
        // Elements
        Dictionary <GameObject, int> elementsToLink = new Dictionary <GameObject, int>();

        for (int i = 0; i < level.levelElements.Count; ++i)
        {
            ElementData ED  = level.levelElements[i];
            Vector3     pos = new Vector3(ED.posX, ED.posY, ED.posZ);
            GameObject  go  = null;

            switch (ED.type)
            {
            case (int)PuzzleElementPlaceHolder.PuzzleElementType.Puzzle:
                go = Instantiate(puzzlePH, pos, puzzlePH.transform.rotation, mainElementsEditor);
                break;

            case (int)PuzzleElementPlaceHolder.PuzzleElementType.Player:
                go = Instantiate(playerPH, pos, playerPH.transform.rotation, mainElementsEditor);
                break;

            case (int)PuzzleElementPlaceHolder.PuzzleElementType.PlatformBox:
                go = Instantiate(platformBoxPH, pos, platformBoxPH.transform.rotation, mainElementsEditor);
                break;

            case (int)PuzzleElementPlaceHolder.PuzzleElementType.PlatformCircle:
                go = Instantiate(platformCirclePH, pos, platformCirclePH.transform.rotation, mainElementsEditor);
                break;

            case (int)PuzzleElementPlaceHolder.PuzzleElementType.Doors:
                go = Instantiate(doorsPH, pos, doorsPH.transform.rotation, mainElementsEditor);
                break;

            case (int)PuzzleElementPlaceHolder.PuzzleElementType.MovingBox:
                go = Instantiate(movingBoxPH, pos, movingBoxPH.transform.rotation, mainElementsEditor);
                break;

            case (int)PuzzleElementPlaceHolder.PuzzleElementType.VerticalLeftDoors:
                go = Instantiate(VLDoorsPH, pos, VLDoorsPH.transform.rotation, mainElementsEditor);
                break;

            case (int)PuzzleElementPlaceHolder.PuzzleElementType.VerticalRightDoors:
                go = Instantiate(VRDoorsPH, pos, VRDoorsPH.transform.rotation, mainElementsEditor);
                break;
            }

            if (go)
            {
                go.GetComponent <PuzzleElementPlaceHolder>().ChangeState(PuzzleElementPlaceHolder.States.InLevel);
            }

            LinkElementPlaceholder LEP = go.GetComponent <LinkElementPlaceholder>();
            if (LEP)
            {
                var linkingObjects = PuzzleEditorController.instance.linkingObjects;
                if (!linkingObjects.ContainsKey(go))
                {
                    linkingObjects.Add(go, LEP.type);
                }

                if (ED.elementLinkedPos != -1)
                {
                    foreach (KeyValuePair <GameObject, int> previousElement in elementsToLink)
                    {
                        if (i == previousElement.Value)
                        {
                            previousElement.Key.GetComponent <LinkElementPlaceholder>().elementLinked = go;
                            LEP.elementLinked = previousElement.Key;

                            elementsToLink.Remove(previousElement.Key);
                            break;
                        }
                    }

                    if (!LEP.elementLinked)
                    {
                        elementsToLink.Add(go, ED.elementLinkedPos);
                    }
                }
            }
        }

        // Tiles
        AllTiles allTiles = PuzzleEditorController.instance.allTiles;

        PuzzleEditorController.instance.SetSize(level.size);
        SetCameraSize(level.size);

        for (int i = 0; i < level.groundTiles.Count; ++i)
        {
            TileData   TD  = level.groundTiles[i];
            Vector3Int pos = new Vector3Int(TD.posX, TD.posY, TD.posZ);
            PuzzleEditorController.instance.baseTM.SetTile(pos, GetTileFromInt(TD.id, allTiles));
        }

        for (int i = 0; i < level.collidableTiles.Count; ++i)
        {
            TileData   TD  = level.collidableTiles[i];
            Vector3Int pos = new Vector3Int(TD.posX, TD.posY, TD.posZ);
            PuzzleEditorController.instance.collidable.SetTile(pos, GetTileFromInt(TD.id, allTiles));
        }

        levelName.text        = level.name;
        levelDescription.text = level.description;
        ApplyLevelInfo(level.name, level.creatorName, level.description);
    }
Example #10
0
    // Update is called once per frame
    void Update()
    {
        if (mouseBlockedByUI || LevelManager.instance.mode != LevelManager.LevelMode.Editor)
        {
            return;
        }

        Vector3Int mousePos = HLTilemap.WorldToCell(cam.ScreenToWorldPoint(Input.mousePosition));

        // Change Tools Keyboard Controls -------------------------------------------
        if (!LevelManager.instance.levelName.isFocused && !LevelManager.instance.levelDescription.isFocused)
        {
            if (Input.GetKeyDown(KeyCode.R))
            {
                ChangeTool((int)Tools.Dropper);
            }

            if (Input.GetKeyDown(KeyCode.E))
            {
                ChangeTool((int)Tools.Eraser);
            }

            if (Input.GetKeyDown(KeyCode.W))
            {
                ChangeTool((int)Tools.Brush);
            }

            if (Input.GetKeyDown(KeyCode.Q))
            {
                ChangeTool((int)Tools.Arrow);
            }
        }
        // --------------------------------------------------------------------------


        // Change Tool to EyeDropper
        if (Input.GetKeyDown(KeyCode.LeftAlt) && !LevelManager.instance.levelName.isFocused && !LevelManager.instance.levelDescription.isFocused)
        {
            ChangeTool((int)Tools.Dropper);
        }

        switch (currentTool)
        {
        case Tools.Arrow:

            if (mousePos != previousCoordinate)
            {
                HLTilemap.SetTile(previousCoordinate, null);
                if (sizeLimit.HasTile(mousePos))
                {
                    HLTilemap.SetTile(mousePos, allTiles.blankArrowToolTile);
                    previousCoordinate = mousePos;
                }
                else
                {
                    previousCoordinate = new Vector3Int(-999, -999, -999);
                }
            }

            if (Input.GetMouseButton(0) && currentPuzzleElementSelected && sizeLimit.HasTile(mousePos))
            {
                currentPuzzleElementSelected.GetComponent <PuzzleElementPlaceHolder>().ChangeState(PuzzleElementPlaceHolder.States.InLevel);

                LinkElementPlaceholder LEP = currentPuzzleElementSelected.GetComponent <LinkElementPlaceholder>();
                if (LEP)
                {
                    if (!linkingObjects.ContainsKey(currentPuzzleElementSelected))
                    {
                        linkingObjects.Add(currentPuzzleElementSelected, LEP.type);
                    }
                }

                currentPuzzleElementSelected = null;
            }

            if (Input.GetMouseButton(1) && currentPuzzleElementSelected)
            {
                Destroy(currentPuzzleElementSelected);
                currentPuzzleElementSelected = null;
            }

            break;

        case Tools.Brush:

            if (mousePos != previousCoordinate)
            {
                HLTilemap.SetTile(previousCoordinate, null);
                if (sizeLimit.HasTile(mousePos))
                {
                    HLTilemap.SetTile(mousePos, currentSelectedTile);
                    previousCoordinate = mousePos;
                }
                else
                {
                    previousCoordinate = new Vector3Int(-999, -999, -999);
                }
            }

            // Paint Tiles
            if (Input.GetMouseButton(0) && currentSelectedTile != allTiles.blankCursorTile && sizeLimit.HasTile(mousePos))
            {
                desiredTM.SetTile(mousePos, currentSelectedTile);

                if (desiredTM != baseTM)
                {
                    baseTM.SetTile(mousePos, null);
                }

                if (desiredTM != collidable)
                {
                    collidable.SetTile(mousePos, null);
                }
            }

            // Erase Tiles
            if (Input.GetMouseButton(1))
            {
                if (collidable.GetTile(mousePos))
                {
                    collidable.SetTile(mousePos, null);
                }

                if (baseTM.GetTile(mousePos))
                {
                    baseTM.SetTile(mousePos, null);
                }
            }

            // Reset Brush
            if (Input.GetMouseButtonDown(2))
            {
                selectedTile        = TileButton.Tiles.None;
                currentSelectedTile = allTiles.blankCursorTile;
                previousCoordinate  = new Vector3Int(-999, -999, -999);
            }

            break;

        case Tools.Eraser:

            if (mousePos != previousCoordinate)
            {
                HLTilemap.SetTile(previousCoordinate, null);
                HLTilemap.SetTile(previousCoordinate, null);
                if (sizeLimit.HasTile(mousePos))
                {
                    HLTilemap.SetTile(mousePos, allTiles.blankArrowToolTile);
                    previousCoordinate = mousePos;
                }
                else
                {
                    previousCoordinate = new Vector3Int(-999, -999, -999);
                }
            }

            if (Input.GetMouseButton(0))
            {
                if (collidable.GetTile(mousePos))
                {
                    collidable.SetTile(mousePos, null);
                }

                if (baseTM.GetTile(mousePos))
                {
                    baseTM.SetTile(mousePos, null);
                }
            }

            break;

        case Tools.Dropper:

            if (Input.GetKeyUp(KeyCode.LeftAlt) && previousTool != -1 && previousTool != (int)Tools.Dropper)
            {
                ChangeTool(previousTool);
            }

            if (mousePos != previousCoordinate)
            {
                HLTilemap.SetTile(previousCoordinate, null);
                if (sizeLimit.HasTile(mousePos))
                {
                    HLTilemap.SetTile(mousePos, allTiles.blankArrowToolTile);
                    previousCoordinate = mousePos;
                }
                else
                {
                    previousCoordinate = new Vector3Int(-999, -999, -999);
                }
            }

            if (Input.GetMouseButtonUp(0))
            {
                Ray          ray = cam.ScreenPointToRay(Input.mousePosition);
                RaycastHit2D hit = Physics2D.Raycast(ray.origin, ray.direction);

                if (hit.collider && hit.collider.CompareTag("Placeholder"))
                {
                    currentPuzzleElementSelected = Instantiate(hit.collider.gameObject);
                    currentPuzzleElementSelected.GetComponent <PuzzleElementPlaceHolder>().ChangeState(PuzzleElementPlaceHolder.States.Selected);
                    ChangeTool((int)Tools.Arrow);

                    return;
                }

                TileBase tileSelected = null;

                if (collidable.GetTile(mousePos))
                {
                    tileSelected = collidable.GetTile(mousePos);
                    desiredTM    = collidable;
                }

                if (baseTM.GetTile(mousePos))
                {
                    tileSelected = baseTM.GetTile(mousePos);
                    desiredTM    = baseTM;
                }

                if (tileSelected)
                {
                    currentSelectedTile = tileSelected;
                    ChangeTool((int)Tools.Brush);
                }
            }

            break;
        }
    }
Example #11
0
    public void LinkElement(LinkElementPlaceholder GOToLink)
    {
        // Unlink
        if (GOToLink.elementLinked)
        {
            LinkElementPlaceholder anotherLep = GOToLink.elementLinked.GetComponent <LinkElementPlaceholder>();

            currentActivatorShowed = null;
            GameObject activator = GOToLink.type == LinkElementPlaceholder.LinkElementType.Activator ? GOToLink.gameObject : anotherLep.gameObject;
            ClearPath(TileMapPathfinding.FindPathCoordinates(V3Helper.V3ToV3Int(activator.transform.position), V3Helper.V3ToV3Int(activator.GetComponent <LinkElementPlaceholder>().elementLinked.transform.position)));

            anotherLep.elementLinked   = null;
            anotherLep.buttonText.text = "Link";

            GOToLink.elementLinked   = null;
            GOToLink.buttonText.text = "Link";
            return;
        }

        // Element pending to be linked
        if (currentLinkingObject)
        {
            // Different Link types, link
            if (currentLinkingObject.type != GOToLink.type)
            {
                if (!GOToLink.elementLinked)
                {
                    GOToLink.elementLinked = currentLinkingObject.gameObject;
                    currentLinkingObject.buttonText.text = "Unlink";
                    currentLinkingObject.elementLinked   = GOToLink.gameObject;
                    GOToLink.buttonText.text             = "Unlink";
                    currentLinkingObject.ShowCanvas(true);
                    currentLinkingObject = null;

                    foreach (KeyValuePair <GameObject, LinkElementPlaceholder.LinkElementType> linkingGO in linkingObjects)
                    {
                        LinkElementPlaceholder LEP = linkingGO.Key.GetComponent <LinkElementPlaceholder>();
                        if (LEP != GOToLink && LEP != GOToLink.elementLinked.GetComponent <LinkElementPlaceholder>())
                        {
                            LEP.ShowCanvas(false);
                        }
                    }

                    GameObject activator = GOToLink.type == LinkElementPlaceholder.LinkElementType.Activator ? GOToLink.gameObject : GOToLink.elementLinked.gameObject;
                    currentActivatorShowed = activator;
                    DrawLine(TileMapPathfinding.FindPathCoordinates(V3Helper.V3ToV3Int(activator.transform.position), V3Helper.V3ToV3Int(activator.GetComponent <LinkElementPlaceholder>().elementLinked.transform.position)));
                    return;
                }
            }
            else
            {
                // Same Link types different objects, substitute
                if (currentLinkingObject != GOToLink)
                {
                    currentLinkingObject.buttonText.text = "Link";
                    GOToLink.buttonText.text             = "Cancel";
                    currentLinkingObject = GOToLink;
                }
                // Same object, cancel linking process
                else
                {
                    currentLinkingObject.buttonText.text = "Link";
                    currentLinkingObject = null;

                    HideAllInspectors();
                }
            }
        }

        // Start Linking
        currentLinkingObject = GOToLink;
        currentLinkingObject.buttonText.text = "Cancel";

        foreach (KeyValuePair <GameObject, LinkElementPlaceholder.LinkElementType> linkingGO in linkingObjects)
        {
            LinkElementPlaceholder LEP = linkingGO.Key.GetComponent <LinkElementPlaceholder>();
            if (LEP != GOToLink && !LEP.elementLinked && LEP.type != GOToLink.type)
            {
                LEP.ShowCanvas(true);
            }
        }
    }