Example #1
0
    void OnDestroy()
    {
        SceneView.onSceneGUIDelegate             -= OnSceneGUI;
        EditorApplication.hierarchyWindowChanged -= OnHierarchyChanged;

        SrpgMtUtils.ShowUnityGrid(true);
        SrpgMtUtils.SetupGizmos(false);

        if (_canvas != null)
        {
            DestroyImmediate(_canvas.gameObject);
            _canvas = null;
        }

        if (_brush != null)
        {
            DestroyImmediate(_brush.gameObject);
            _brush = null;
        }

        if (_currMap != null)
        {
            _currMap.lastEditedTime = DateTime.Now.Ticks;
            _currMap = null;
        }

        if (_currLayer != null)
        {
            _currLayer.lastEditedTime = DateTime.Now.Ticks;
            _currLayer = null;
        }
    }
Example #2
0
    public void SetCurrentMap(SrpgMap newMap)
    {
        _currMap = newMap;

        float mapTotalWidth  = _currMap.mapWidth * _currMap.tileWidth;
        float mapTotalHeight = _currMap.mapHeight * _currMap.tileHeight;

        transform.position   = new Vector3(mapTotalWidth / 2, mapTotalHeight / 2);
        transform.localScale = new Vector3(mapTotalWidth, mapTotalHeight, 1);
    }
Example #3
0
    private void SetupMap()
    {
        if (_currMap == null)
        {
            SrpgMap[] foundMaps = GameObject.FindObjectsOfType <SrpgMap>();
            if (foundMaps.Length > 0)
            {
                Array.Sort(foundMaps, (map1, map2) =>
                {
                    if (map1.lastEditedTime < map2.lastEditedTime)
                    {
                        return(1);
                    }
                    else if (map1.lastEditedTime > map2.lastEditedTime)
                    {
                        return(-1);
                    }
                    else
                    {
                        return(0);
                    }
                });

                SetCurrentMap(foundMaps[0]);
                toolMode = ToolMode.Edit;
                editMenu = EditMenu.Brush;
            }
        }
        else
        {
            if (_currMap.gameObject.activeSelf)
            {
                SetupLayer();
            }
            else
            {
                _currMap = null;
            }
        }

        if (_currMap != null)
        {
            _currMap.transform.position = Vector3.zero;

            Camera mainCamera = GameObject.FindWithTag("MainCamera").GetComponent <Camera>();
            if (mainCamera != null)
            {
                float cameraX = (_currMap.mapWidth * _currMap.tileWidth) / 2;
                //float cameraY = (_currMap.mapHeight * _currMap.tileHeight + _currMap.altitude) / 2;
                float cameraY = (_currMap.mapHeight * _currMap.tileHeight) / 2;
                mainCamera.transform.position = new Vector3(cameraX, cameraY, -10);
                mainCamera.orthographicSize   = Mathf.Max(cameraX, cameraY);
            }
        }
    }
Example #4
0
    public void SetZIndex(int newZIndexStart, int mapHeight)
    {
        _zIndexStart = newZIndexStart;

        SrpgTile[] tiles = GetComponentsInChildren <SrpgTile>();
        foreach (SrpgTile tile in tiles)
        {
            SpriteRenderer rndr = tile.GetComponent <SpriteRenderer>();
            rndr.sortingOrder = SrpgMap.CalcZIndex(_zIndexStart, mapHeight, tile.y);
        }
    }
Example #5
0
    private int _zIndexStart = 10000; // enough big int

    public void SetCurrentMap(SrpgMap newMap)
    {
        SrpgMap prevMap = _currMap;

        _currMap = newMap;

        if (prevMap != _currMap)
        {
            RemoveSpriteObjects();
        }
    }
Example #6
0
    private void SetCurrentMap(SrpgMap newMap)
    {
        _currMap = newMap;
        if (_currMap != null)
        {
            SetupLayer();
        }

        if (_canvas != null)
        {
            _canvas.SetCurrentMap(newMap);
        }

        if (_brush != null)
        {
            _brush.SetCurrentMap(newMap);
        }

        _spriteSelection.Init();
    }
Example #7
0
    public void OnSceneGUI(SceneView sceneView, SrpgCanvas canvas, SrpgBrush brush,
                           SrpgMap map, SrpgLayer layer)
    {
        if (canvas == null || brush == null || map == null)
        {
            return;
        }
        //_canvas = canvas;
        _brush     = brush;
        _currMap   = map;
        _currLayer = layer;

        _brush.ShowHide(SrpgMapTool.toolMode == SrpgMapTool.ToolMode.Edit &&
                        SrpgMapTool.editMenu == SrpgMapTool.EditMenu.Brush);

        if (SrpgMapTool.toolMode != SrpgMapTool.ToolMode.Edit)
        {
            return;
        }

        DrawButtons();

        DoMouseEvent();
    }
 void OnEnable()
 {
     _target = (SrpgMap)target;
 }