private void DrawTileEditor()
    {
        if (viewModel.CurrentPrefab != null)
        {
            GUILayout.Label("Tile Settings: " + viewModel.CurrentPrefabPath);
            GNBlockMapTile tile = viewModel.CurrentPrefab.GetComponent <GNBlockMapTile>();
            if (tile)
            {
                UnityEditor.Editor editor = UnityEditor.Editor.CreateEditor(tile);
                bool changed = editor.DrawDefaultInspector();
                if (changed)
                {
                    // blubb
                }
                if (GUILayout.Button("Delete Tile Component in current Prefab"))
                {
                    Undo.DestroyObjectImmediate(viewModel.CurrentPrefab.GetComponent <GNBlockMapTile>());
//                    Repaint();
                }
            }
            else
            {
                if (GUILayout.Button("Create Tile Component in current Prefab"))
                {
                    GNBlockMapTile tile2 = viewModel.CurrentPrefab.AddComponent <GNBlockMapTile>();
                    Undo.RegisterCreatedObjectUndo(tile2, "Painted an Object");
//                    Repaint();
//                    EditorUtility.SetDirty(viewModel.CurrentPrefab);
                }
            }
        }
    }
    private bool IsMultipleCellBlock(GameObject gameObject)
    {
        GNBlockMapTile tile = gameObject.GetComponent <GNBlockMapTile>();

        if (tile && tile.Offset.magnitude > 0)
        {
            return(true);
        }

        MeshFilter meshFilter = gameObject.GetComponent <MeshFilter>();

        if (!meshFilter || !meshFilter.sharedMesh)
        {
            return(false);
        }
        Vector3 sizeHalf = meshFilter.sharedMesh.bounds.extents;

        return(sizeHalf.x > 1.5f || sizeHalf.y > 1.5f || sizeHalf.z > 1.5f);
    }
    private Vector3 GetOffsetFor(GameObject gameObject)
    {
        GNBlockMapTile tile = gameObject.GetComponent <GNBlockMapTile>();

        if (tile)
        {
            return(tile.Offset);
        }

        MeshFilter meshFilter = gameObject.GetComponent <MeshFilter>();

        if (!meshFilter || !meshFilter.sharedMesh)
        {
            return(Vector3.zero);
        }
        Vector3 sizeHalf = meshFilter.sharedMesh.bounds.extents - Vector3.one;

        sizeHalf.z = -sizeHalf.z;
        return(Align(sizeHalf));
    }
    private bool FixObject(GameObject gameObject)
    {
        GNBlockMapTile tile = gameObject.GetComponent <GNBlockMapTile>();

        if (tile != null)
        {
            float           z           = GetTargetZPosition(gameObject);
            GNBlockMapLayer targetLayer = GetTargetLayer(z, false);
            if (targetLayer == null || targetLayer.transform != gameObject.transform.parent)
            {
                Undo.RecordObject(gameObject.transform, "fix position");
                tile.transform.position += tile.Offset;
                Debug.LogWarning(" Moving old collision tile to correct position " + tile.transform.position);
            }

            UnityEngine.Assertions.Assert.AreEqual(tile.transform.parent.GetComponent <GNBlockMapLayer>(), GetTargetLayer(GetTargetZPosition(gameObject), false));
            return(false);
        }

        if (gameObject.isStatic && gameObject.GetComponent <NPVoxCubeSimplifierInstance>() != null)
        {
            // if(gameObject)
            // TODO: check for negative scale and revert them?!?

            Vector3 scle = gameObject.transform.localScale;
            if (scle.x < 0)
            {
                Undo.RecordObject(gameObject.transform, "fix scale");
                scle.Scale(new Vector3(-1, 1, 1));
                Debug.LogWarning(" Removing negative scale from object at position " + gameObject.transform.position);
                gameObject.transform.localScale = scle;
            }
            if (scle.y < 0)
            {
                Undo.RecordObject(gameObject.transform, "fix scale");
                scle.Scale(new Vector3(1, -1, 1));
                Debug.LogWarning(" Removing negative scale from object at position " + gameObject.transform.position);
                gameObject.transform.localScale = scle;
            }
            if (scle.z < 0)
            {
                Undo.RecordObject(gameObject.transform, "fix scale");
                scle.Scale(new Vector3(1, 1, -1));
                Debug.LogWarning(" Removing negative scale from object at position " + gameObject.transform.position);
                gameObject.transform.localScale = scle;
            }
        }

        // Vector3 pos = Align(gameObject.transform.position);
        //  new Vector3(
        //      Mathf.Round(gameObject.transform.localPosition.x / MIN_GRID_RESOLTION) * MIN_GRID_RESOLTION,
        //      Mathf.Round(gameObject.transform.localPosition.y / MIN_GRID_RESOLTION) * MIN_GRID_RESOLTION,
        //      Mathf.Round(gameObject.transform.localPosition.z / MIN_GRID_RESOLTION) * MIN_GRID_RESOLTION
        // );

        // if(gameObject.transform.position.x != pos.x || gameObject.transform.position.y != pos.y || gameObject.transform.position.z != pos.z)
        // {
        //     Debug.LogWarning(" Aligning object to position " + pos);
        //     gameObject.transform.position = pos;
        // }

        return(MoveToCorrectTargetLayer(gameObject));
        // return false;
    }