예제 #1
0
        public static uint DoTileDataPropertiesLayout(uint tileData, Tileset tileset, bool displayBrush = true)
        {
            EditorGUILayout.BeginVertical(EditorStyles.helpBox);

            GUI.enabled = tileData != Tileset.k_TileData_Empty;
            EditorGUIUtility.labelWidth = 100;

            EditorGUI.BeginChangeCheck();
            EditorGUILayout.Toggle("Flip Horizontally", (tileData & Tileset.k_TileFlag_FlipH) != 0);
            if (EditorGUI.EndChangeCheck())
            {
                tileData ^= Tileset.k_TileFlag_FlipH;
            }
            EditorGUI.BeginChangeCheck();
            EditorGUILayout.Toggle("Flip Vertically", (tileData & Tileset.k_TileFlag_FlipV) != 0);
            if (EditorGUI.EndChangeCheck())
            {
                tileData ^= Tileset.k_TileFlag_FlipV;
            }
            EditorGUI.BeginChangeCheck();
            EditorGUILayout.Toggle("Rotate 90º", (tileData & Tileset.k_TileFlag_Rot90) != 0);
            if (EditorGUI.EndChangeCheck())
            {
                tileData ^= Tileset.k_TileFlag_Rot90;
            }

            if (displayBrush)
            {
                EditorGUI.BeginChangeCheck();
                int          brushId = Tileset.GetBrushIdFromTileData(tileData);
                TilesetBrush brush   = tileset.FindBrush(brushId);
                brush = (TilesetBrush)EditorGUILayout.ObjectField("Brush", brush, typeof(TilesetBrush), false);
                if (EditorGUI.EndChangeCheck())
                {
                    brushId = brush != null?tileset.FindBrushId(brush.name) : Tileset.k_BrushId_Default;

                    int tileId = brush != null ? (int)(brush.PreviewTileData() & Tileset.k_TileDataMask_TileId) : Tileset.GetTileIdFromTileData(tileData);
                    tileData &= Tileset.k_TileDataMask_Flags;
                    tileData |= (uint)(brushId << 16) & Tileset.k_TileDataMask_BrushId;
                    tileData |= (uint)(tileId & Tileset.k_TileDataMask_TileId);
                }
            }

            if (GUILayout.Button("Reset"))
            {
                tileData = Tileset.k_TileData_Empty;
            }

            EditorGUIUtility.labelWidth = 0;
            GUI.enabled = true;

            EditorGUILayout.EndVertical();
            return(tileData);
        }
예제 #2
0
        public static uint DoTileDataProperties(Rect position, uint tileData, Tileset tileset, bool displayBrush = true)
        {
            position.height = 90f;
            GUI.BeginGroup(position, EditorStyles.helpBox);
            {
                GUI.enabled = tileData != Tileset.k_TileData_Empty;
                EditorGUIUtility.labelWidth = 100;

                Rect fieldRect = new Rect(2f, 2f, position.width - 4f, EditorGUIUtility.singleLineHeight);
                EditorGUI.BeginChangeCheck();
                EditorGUI.Toggle(fieldRect, "Flip Horizontally", (tileData & Tileset.k_TileFlag_FlipH) != 0);
                if (EditorGUI.EndChangeCheck())
                {
                    tileData ^= Tileset.k_TileFlag_FlipH;
                }
                fieldRect.y += EditorGUIUtility.singleLineHeight;
                EditorGUI.BeginChangeCheck();
                EditorGUI.Toggle(fieldRect, "Flip Vertically", (tileData & Tileset.k_TileFlag_FlipV) != 0);
                if (EditorGUI.EndChangeCheck())
                {
                    tileData ^= Tileset.k_TileFlag_FlipV;
                }
                fieldRect.y += EditorGUIUtility.singleLineHeight;
                EditorGUI.BeginChangeCheck();
                EditorGUI.Toggle(fieldRect, "Rotate 90º", (tileData & Tileset.k_TileFlag_Rot90) != 0);
                if (EditorGUI.EndChangeCheck())
                {
                    tileData ^= Tileset.k_TileFlag_Rot90;
                }

                if (displayBrush)
                {
                    fieldRect.y += EditorGUIUtility.singleLineHeight;
                    EditorGUI.BeginChangeCheck();
                    int          brushId = Tileset.GetBrushIdFromTileData(tileData);
                    TilesetBrush brush   = tileset.FindBrush(brushId);
                    brush = (TilesetBrush)EditorGUI.ObjectField(fieldRect, "Brush", brush, typeof(TilesetBrush), false);
                    if (EditorGUI.EndChangeCheck())
                    {
                        if (brush && brush.Tileset != tileset)
                        {
                            Debug.LogWarning("The brush " + brush.name + " belongs to a different tileset and cannot be selected! ");
                        }
                        else
                        {
                            brushId = brush != null?tileset.FindBrushId(brush.name) : Tileset.k_BrushId_Default;

                            int tileId = brush != null ? (int)(brush.PreviewTileData() & Tileset.k_TileDataMask_TileId) : Tileset.GetTileIdFromTileData(tileData);
                            tileData &= Tileset.k_TileDataMask_Flags;
                            tileData |= (uint)(brushId << 16) & Tileset.k_TileDataMask_BrushId;
                            tileData |= (uint)(tileId & Tileset.k_TileDataMask_TileId);
                        }
                    }
                }

                fieldRect.y += EditorGUIUtility.singleLineHeight + 4f;
                fieldRect.x += 2f; fieldRect.width -= 4f;
                if (GUI.Button(fieldRect, "Reset"))
                {
                    tileData = Tileset.k_TileData_Empty;
                }

                EditorGUIUtility.labelWidth = 0;
                GUI.enabled = true;
            }
            GUI.EndGroup();
            return(tileData);
        }