private void Update()
    {
        if (GameManager.Instance.currentState == GameManager.GameState.LevelEditor)
        {
                        #if UNITY_STANDALONE || UNITY_WEBPLAYER || UNITY_EDITOR
            GetCameraInputs();
                        #else
            if (isControlActive)
            {
                GetCameraInputs();
            }
                        #endif

            //Makes sure you can't zoom in / out too much.
            Camera.main.orthographicSize = Mathf.Clamp(Camera.main.orthographicSize, _baseSize, _baseSize * 3);

            Vector3 scale = transform.localScale;
            scale.x = Camera.main.orthographicSize / _baseSize;
            scale.y = scale.x;
            transform.localScale = scale;

            //After moving the camera, checks if it's still inside the gameview.
            CheckBoundaries();

            UpdateGrid();
        }

        //Maps interfaces can't zoom. only level editor
        else if (GameManager.Instance.currentState == GameManager.GameState.Map)
        {
            //Camera movement.
            if (LevelEditorInputs.GetCameraLeft())
            {
                transform.Translate(Vector2.left * _translationSpeed * Time.deltaTime);
            }
            if (LevelEditorInputs.GetCameraRight())
            {
                transform.Translate(Vector2.right * _translationSpeed * Time.deltaTime);
            }

            //Screen base size
            float baseSize = _gameviewSize / 2f * Screen.height / Screen.width;

            Camera.main.orthographicSize = Mathf.Clamp(Camera.main.orthographicSize, baseSize, baseSize * 3);
            CheckBoundaries();
        }
    }
    private void GetCameraInputs()
    {
        if (LevelEditorInputs.GetCameraUp(isDraging))
        {
            Camera.main.transform.Translate(Vector2.up * _translationSpeed * Time.deltaTime);
        }
        if (LevelEditorInputs.GetCameraLeft(isDraging))
        {
            Camera.main.transform.Translate(Vector2.left * _translationSpeed * Time.deltaTime);
        }
        if (LevelEditorInputs.GetCameraDown(isDraging))
        {
            Camera.main.transform.Translate(Vector2.down * _translationSpeed * Time.deltaTime);
        }
        if (LevelEditorInputs.GetCameraRight(isDraging))
        {
            Camera.main.transform.Translate(Vector2.right * _translationSpeed * Time.deltaTime);
        }

        //Zoom in/out.
        Camera.main.orthographicSize -= LevelEditorInputs.GetZoomIn() * _zoomSensitivity * Time.deltaTime;
        Camera.main.orthographicSize += LevelEditorInputs.GetZoomOut() * _zoomSensitivity * Time.deltaTime;
    }
Пример #3
0
    /// <summary>
    /// Using the param tColRow, this function goes through all the objects in the given 10x10 sector and verifies if their position
    ///		is equal to tPos which is the current mouse position or mobile tap input position.
    /// If the player is trying to add a block and an object is found with the same position as tPos,
    ///		the player won't be able to add a new block since the spot is already taken.
    ///	If the player is trying to delete a block and an object is found with the same position as tPos,
    ///		the object will be deleted.
    /// </summary>
    /// <param name="tColRow">
    ///		This is 10x10 the sector in which the object to add / delete is in.
    ///		Used to reduce the load when parsing through existing objects since instead of going through all existing objects,
    ///			it only goes through a 10x10 section.
    /// </param>
    /// <param name="tPos">Position of the object to add / delete.</param>
    /// <param name="isAdd">Is the player trying to add a block or delete one.</param>
    private void AddDeleteTile(int[] tColRow, float[] tPos, bool isAdd)
    {
        Vector3 rotation = Vector3.zero;

        for (int i = 0; i < LevelManager.Instance.levelData.objectList[tColRow[0]][tColRow[1]].Count; i++)
        {
            if (LevelManager.Instance.levelData.objectList[tColRow[0]][tColRow[1]][i].transform.position == new Vector3(tPos[0], tPos[1], 0.0f))
            {
                if (isAdd)
                {
                    isAdd = false;
                    if (objType == 3 && objId == 7)
                    {
                        Tile tTile = LevelManager.Instance.serializedData.objectList[tColRow[0]][tColRow[1]][i];
                        if (tTile.type != 3 && tTile.type != 0)
                        {
                            LevelManager.Instance.DeleteObject(tColRow, i);
                            StartCoroutine(PassableEndFrame(tPos, tColRow, tTile.type, tTile.id));
                        }
                    }
                    else
                    {
                        if (LevelEditorInputs.Rotate())
                        {
                            int tRotation = ObjectRotation.GetObectRotation(LevelManager.Instance.levelData.objectList[tColRow[0]][tColRow[1]][i].name);
                            if (tRotation < 0)
                            {
                                //if(LevelManager.Instance.levelData.objectList[tColRow[0]][tColRow[1]][i].tag == "Enemies")
                                //	LevelManager.Instance.levelData.objectList[tColRow[0]][tColRow[1]][i].GetComponent<EnemyAI>().Flip();
                                //else {
                                rotation    = LevelManager.Instance.levelData.objectList[tColRow[0]][tColRow[1]][i].transform.localScale;
                                rotation.x *= tRotation;
                                LevelManager.Instance.levelData.objectList[tColRow[0]][tColRow[1]][i].transform.localScale  = rotation;
                                LevelManager.Instance.serializedData.objectList[tColRow[0]][tColRow[1]][i].horizontalMirror = (rotation.x < 0);
                                //}
                            }
                            else if (tRotation > 0)
                            {
                                rotation    = LevelManager.Instance.levelData.objectList[tColRow[0]][tColRow[1]][i].transform.localEulerAngles;
                                rotation.z += tRotation;
                                LevelManager.Instance.levelData.objectList[tColRow[0]][tColRow[1]][i].transform.localEulerAngles = rotation;
                                LevelManager.Instance.serializedData.objectList[tColRow[0]][tColRow[1]][i].rotation = rotation.z;
                            }
                            else if (LevelManager.Instance.serializedData.objectList[tColRow[0]][tColRow[1]][i].type == 4 &&
                                     LevelManager.Instance.serializedData.objectList[tColRow[0]][tColRow[1]][i].id == 11)
                            {
                                LevelManager.Instance.levelData.objectList[tColRow[0]][tColRow[1]][i].transform.GetChild(0).gameObject.SetActive(true);
                            }
                        }
                    }
                }
                else
                {
                    LevelManager.Instance.DeleteObject(tColRow, i);
                }
            }
        }
        if (isAdd)
        {
            if (objType == 3 && objId == 9)
            {
                SetCursor(true);
                glitchUI.TeleportUI(tPos);
            }
            else if (objType != 3 || objId != 7)
            {
                LevelManager.Instance.AddObject(tPos, tColRow, objType, objId);
            }
        }
    }
Пример #4
0
    private void Update()
    {
        if (!isLocked)
        {
            if (GameManager.Instance.currentState == GameManager.GameState.LevelEditor)
            {
                //If cursor isn't over UI;
                bool tPointerOverUI;

#if UNITY_STANDALONE || UNITY_WEBPLAYER || UNITY_EDITOR
                tPointerOverUI = EventSystem.current.IsPointerOverGameObject();
                if (Input.GetMouseButtonDown(0))
                {
                    //Check if touch an object no matter where you press on it;
                    Ray            ray = Camera.main.ScreenPointToRay(Input.mousePosition);
                    RaycastHit2D[] hit = Physics2D.GetRayIntersectionAll(ray, 10f);
                    foreach (RaycastHit2D o in hit)
                    {
                        transObj = o.transform;
                        break;
                    }
                }
#else
                tPointerOverUI = IsPointerOverUIObject();
#endif
                if (!tPointerOverUI)
                {
                    int[]   objColRow = new int[2];   //0 = column, 1 = row
                    float[] objPos    = new float[2]; //0 = x, 1 = y
                    if (transObj != null)
                    {
                        GetObjPosition(ref objColRow, ref objPos, transObj.position);
                        transObj = null;
                    }
                    else
                    {
                        Vector2 mousePosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
                        GetObjPosition(ref objColRow, ref objPos, mousePosition);
                    }

                    if (LevelEditorInputs.GetBrush())
                    {
                        if (eraser)
                        {
                            AddDeleteTile(objColRow, objPos, false);
                        }
                        else if (!cursor)
                        {
                            if (glitchUI.isActive)
                            {
                                glitchUI.AddTeleport(objPos);
                            }
                            else if (objPos[0] > 0 && objPos[0] < LevelManager.Instance.mapSize.x && objPos[1] > 0 && objPos[1] < LevelManager.Instance.mapSize.y)
                            {
                                AddDeleteTile(objColRow, objPos, true);
                            }
                        }
                    }
                    else if (LevelEditorInputs.GetEraser())
                    {
                        AddDeleteTile(objColRow, objPos, false);
                    }
                }
                GlobalInputs.ClearInputs();
            }
        }
    }