public static void DrawBox(Rect tileRect, bool selected, TesseraPalette palette, int index)
        {
            var entry   = palette.entries[index];
            var c       = entry.color;
            var texture = index == 0 ? Eraser : MakeTexture((int)tileRect.width, (int)tileRect.height, c);

            if (selected)
            {
                var contrast        = GetContrastColor(c);
                var contrastTexture = MakeTexture((int)tileRect.width, (int)tileRect.height, contrast);
                GUI.Box(tileRect, new GUIContent(contrastTexture, entry.name), GUIStyle.none);
                GUI.DrawTexture(new RectOffset(2, 2, 2, 2).Remove(tileRect), texture);
            }
            else
            {
                //GUI.DrawTexture(tileRect, texture);
                GUI.Box(tileRect, new GUIContent(texture, entry.name), GUIStyle.none);
            }
        }
        void OnGUI()
        {
            GUILayout.Label("View", EditorStyles.boldLabel);

            TesseraTilePaintingState.showBackface = EditorGUILayout.Toggle(new GUIContent("Show Backfaces", "Z to toggle"), TesseraTilePaintingState.showBackface);

            TesseraTilePaintingState.opacity = EditorGUILayout.Slider("Opacity", TesseraTilePaintingState.opacity, 0, 1);

            TesseraTilePaintingState.showAll = EditorGUILayout.Toggle(new GUIContent("Show All"), TesseraTilePaintingState.showAll);

            GUILayout.Label("Painting", EditorStyles.boldLabel);

            // TODO: See C:\Program Files\Unity\Hub\Editor\2019.2.3f1\Editor\Data\Resources\PackageManager\BuiltInPackages\com.unity.2d.tilemap\Editor\EditorTools
            // For some further stuff to do here

            GUILayout.Label("Paint Mode");

            GUILayout.BeginHorizontal(new GUILayoutOption[0]);
            GUILayout.FlexibleSpace();
            EditorGUILayout.EditorToolbar(TesseraTileEditorToolBase.tile3dEditorTools);

            GUILayout.FlexibleSpace();
            GUILayout.EndHorizontal();

            GUILayout.Label("Paint Color");

            var r = EditorGUILayout.BeginVertical();

            r.width = position.width;

            var boxStyle = GUI.skin.box;
            var tileSize = 20;

            var boxRect   = boxStyle.margin.Remove(r);
            var innerRect = boxStyle.padding.Remove(boxRect);

            // Get palette
            TesseraPalette palette = null;

            if (Selection.activeGameObject != null)
            {
                if (Selection.activeGameObject.GetComponent <TesseraTile>() is TesseraTile t)
                {
                    palette = t.palette;
                }
            }
            if (palette == null)
            {
                palette = TesseraPalette.defaultPalette;
            }

            var tilesPerRow = (int)(innerRect.width / tileSize);

            if (tilesPerRow > 0)
            {
                innerRect.height = (palette.entryCount + tilesPerRow - 1) / tilesPerRow * tileSize;
                boxRect          = boxStyle.padding.Add(innerRect);

                GUI.Box(boxRect, "");

                for (var i = 0; i < palette.entryCount; i++)
                {
                    var x        = innerRect.x + (i % tilesPerRow) * tileSize;
                    var y        = innerRect.y + (i / tilesPerRow) * tileSize;
                    var tileRect = new Rect(x, y, tileSize, tileSize);

                    var selected = TesseraTilePaintingState.paintIndex == i;
                    if (Event.current.type == EventType.Repaint)
                    {
                        TextureUtil.DrawBox(tileRect, selected, palette, i);
                    }
                }

                if (Event.current.type == EventType.MouseDown)
                {
                    var mousePosition = Event.current.mousePosition;
                    if (innerRect.Contains(mousePosition))
                    {
                        var x = (int)(mousePosition.x - innerRect.x) / tileSize;
                        var y = (int)(mousePosition.y - innerRect.y) / tileSize;
                        var i = x + y * tilesPerRow;
                        TesseraTilePaintingState.paintIndex = i;
                        Repaint();
                    }
                }

                // TODO: Handle tooltip
            }
            EditorGUILayout.EndVertical();

            GUILayout.Space(boxStyle.margin.Add(boxRect).height);

            TesseraTileEditorToolBase.CheckKeyPresses();
        }
Ejemplo n.º 3
0
 public ColorList(SerializedProperty list, TesseraPalette palette)
 {
     this.list    = list;
     this.palette = palette;
 }
Ejemplo n.º 4
0
 private static void AddAdjacency(TesseraPalette palette, AdjacentModel model, Direction d, List <(FaceDetails, Tile)> tiles1, List <(FaceDetails, Tile)> tiles2)