Welt265 Zeilen
BlockType.cs
Alle Blockarten als Enum — inklusive neun Holzarten mit je Stamm, Brettern, Slab und Treppe — dazu Farbe, Name, Texturname, die Blockform (voll, halb, Treppe) und die Regel, welche Blöcke fest sind. Die Farben sind der Fallback, wenn eine Textur fehlt.
Assets/Scripts/BlockType.cs
using UnityEngine;
namespace Blockwerk
{
/// <summary>Alle Blockarten der Welt. Air bedeutet: hier ist nichts.</summary>
public enum BlockType
{
Air = 0,
Grass = 1,
Dirt = 2,
Stone = 3,
Sand = 4,
Leaf = 5,
Water = 6,
// Holz: pro Art ein Stamm (Rinde außen, Jahresringe oben und unten)
// und ein Brettblock, der im Spiel einfach wie das Holz heißt.
OakLog = 10,
OakPlanks = 11,
SpruceLog = 12,
SprucePlanks = 13,
BirchLog = 14,
BirchPlanks = 15,
JungleLog = 16,
JunglePlanks = 17,
AcaciaLog = 18,
AcaciaPlanks = 19,
DarkOakLog = 20,
DarkOakPlanks = 21,
MangroveLog = 22,
MangrovePlanks = 23,
CherryLog = 24,
CherryPlanks = 25,
PaleOakLog = 26,
PaleOakPlanks = 27,
// Slabs füllen nur die untere Hälfte der Zelle, Treppen steigen an.
StoneSlab = 28,
StoneStairs = 29,
OakSlab = 30,
OakStairs = 31,
SpruceSlab = 32,
SpruceStairs = 33,
BirchSlab = 34,
BirchStairs = 35,
JungleSlab = 36,
JungleStairs = 37,
AcaciaSlab = 38,
AcaciaStairs = 39,
DarkOakSlab = 40,
DarkOakStairs = 41,
MangroveSlab = 42,
MangroveStairs = 43,
CherrySlab = 44,
CherryStairs = 45,
PaleOakSlab = 46,
PaleOakStairs = 47
}
public static class BlockInfo
{
/// <summary>Alle Stämme in der Reihenfolge der Holzarten.</summary>
public static readonly BlockType[] Logs =
{
BlockType.OakLog, BlockType.SpruceLog, BlockType.BirchLog,
BlockType.JungleLog, BlockType.AcaciaLog, BlockType.DarkOakLog,
BlockType.MangroveLog, BlockType.CherryLog, BlockType.PaleOakLog
};
/// <summary>Die Bretter dazu — gleiche Reihenfolge wie Logs.</summary>
public static readonly BlockType[] Planks =
{
BlockType.OakPlanks, BlockType.SprucePlanks, BlockType.BirchPlanks,
BlockType.JunglePlanks, BlockType.AcaciaPlanks, BlockType.DarkOakPlanks,
BlockType.MangrovePlanks, BlockType.CherryPlanks, BlockType.PaleOakPlanks
};
/// <summary>Blöcke, die der Spieler setzen kann (Reihenfolge = Hotbar).</summary>
public static readonly BlockType[] Placeable =
{
BlockType.Grass, BlockType.Dirt, BlockType.Stone,
BlockType.StoneSlab, BlockType.StoneStairs,
BlockType.Sand, BlockType.Leaf,
BlockType.OakLog, BlockType.OakPlanks, BlockType.OakSlab, BlockType.OakStairs,
BlockType.SpruceLog, BlockType.SprucePlanks, BlockType.SpruceSlab, BlockType.SpruceStairs,
BlockType.BirchLog, BlockType.BirchPlanks, BlockType.BirchSlab, BlockType.BirchStairs,
BlockType.JungleLog, BlockType.JunglePlanks, BlockType.JungleSlab, BlockType.JungleStairs,
BlockType.AcaciaLog, BlockType.AcaciaPlanks, BlockType.AcaciaSlab, BlockType.AcaciaStairs,
BlockType.DarkOakLog, BlockType.DarkOakPlanks, BlockType.DarkOakSlab, BlockType.DarkOakStairs,
BlockType.MangroveLog, BlockType.MangrovePlanks, BlockType.MangroveSlab, BlockType.MangroveStairs,
BlockType.CherryLog, BlockType.CherryPlanks, BlockType.CherrySlab, BlockType.CherryStairs,
BlockType.PaleOakLog, BlockType.PaleOakPlanks, BlockType.PaleOakSlab, BlockType.PaleOakStairs
};
/// <summary>Stamm: Rinde an den Seiten, Jahresringe oben und unten.</summary>
public static bool IsLog(BlockType type)
{
return WoodKey(type) != null && type.ToString().EndsWith("Log");
}
public static bool IsPlanks(BlockType type)
{
return WoodKey(type) != null && type.ToString().EndsWith("Planks");
}
/// <summary>Slab: der Block füllt nur die untere Hälfte der Zelle.</summary>
public static bool IsSlab(BlockType type)
{
return type.ToString().EndsWith("Slab");
}
/// <summary>Treppe: untere Hälfte plus eine Stufe, in Blickrichtung ansteigend.</summary>
public static bool IsStairs(BlockType type)
{
return type.ToString().EndsWith("Stairs");
}
/// <summary>Wie hoch ein Block seine Zelle füllt.</summary>
public static float Height(BlockType type)
{
return IsSlab(type) ? 0.5f : 1f;
}
/// <summary>Teil des Texturnamens: oak, spruce, dark_oak ...</summary>
public static string WoodKey(BlockType type)
{
// Gilt für Stamm, Bretter, Slab und Treppe einer Holzart gleichermaßen.
string name = type.ToString();
if (name.StartsWith("DarkOak")) return "dark_oak";
if (name.StartsWith("PaleOak")) return "pale_oak";
foreach (string wood in WoodNames)
if (name.StartsWith(wood)) return wood.ToLowerInvariant();
return null;
}
private static readonly string[] WoodNames =
{
"Oak", "Spruce", "Birch", "Jungle", "Acacia", "Mangrove", "Cherry"
};
private static string WoodLabel(string wood)
{
switch (wood)
{
case "oak": return "Oak";
case "spruce": return "Spruce";
case "birch": return "Birch";
case "jungle": return "Jungle";
case "acacia": return "Acacia";
case "dark_oak": return "Dark Oak";
case "mangrove": return "Mangrove";
case "cherry": return "Cherry";
case "pale_oak": return "Pale Oak";
default: return wood;
}
}
private static Color WoodColor(string wood)
{
switch (wood)
{
case "oak": return new Color32(185, 140, 82, 255);
case "spruce": return new Color32(107, 74, 47, 255);
case "birch": return new Color32(215, 201, 163, 255);
case "jungle": return new Color32(164, 113, 63, 255);
case "acacia": return new Color32(181, 100, 47, 255);
case "dark_oak": return new Color32(74, 53, 32, 255);
case "mangrove": return new Color32(124, 63, 43, 255);
case "cherry": return new Color32(217, 169, 158, 255);
case "pale_oak": return new Color32(210, 206, 187, 255);
default: return Color.magenta;
}
}
public static bool IsSolid(BlockType type)
{
return type != BlockType.Air && type != BlockType.Water;
}
public static Color ColorOf(BlockType type)
{
// Slabs und Treppen tragen die Farbe ihres Grundblocks.
if (IsSlab(type) || IsStairs(type))
{
string wood = WoodKey(type);
return wood == null ? new Color32(155, 161, 164, 255) : WoodColor(wood);
}
switch (type)
{
case BlockType.Grass: return new Color32(143, 174, 95, 255);
case BlockType.Dirt: return new Color32(138, 98, 66, 255);
case BlockType.Stone: return new Color32(155, 161, 164, 255);
case BlockType.Sand: return new Color32(220, 201, 160, 255);
case BlockType.Leaf: return new Color32(91, 132, 73, 255);
case BlockType.Water: return new Color32(106, 169, 184, 255);
// Stämme: Rindenfarbe. Bretter: Holzfarbe.
case BlockType.OakLog: return new Color32(156, 122, 74, 255);
case BlockType.OakPlanks: return new Color32(185, 140, 82, 255);
case BlockType.SpruceLog: return new Color32(92, 64, 41, 255);
case BlockType.SprucePlanks: return new Color32(107, 74, 47, 255);
case BlockType.BirchLog: return new Color32(230, 224, 207, 255);
case BlockType.BirchPlanks: return new Color32(215, 201, 163, 255);
case BlockType.JungleLog: return new Color32(127, 97, 60, 255);
case BlockType.JunglePlanks: return new Color32(164, 113, 63, 255);
case BlockType.AcaciaLog: return new Color32(107, 97, 82, 255);
case BlockType.AcaciaPlanks: return new Color32(181, 100, 47, 255);
case BlockType.DarkOakLog: return new Color32(62, 44, 27, 255);
case BlockType.DarkOakPlanks: return new Color32(74, 53, 32, 255);
case BlockType.MangroveLog: return new Color32(106, 58, 38, 255);
case BlockType.MangrovePlanks: return new Color32(124, 63, 43, 255);
case BlockType.CherryLog: return new Color32(63, 48, 56, 255);
case BlockType.CherryPlanks: return new Color32(217, 169, 158, 255);
case BlockType.PaleOakLog: return new Color32(185, 180, 164, 255);
case BlockType.PaleOakPlanks: return new Color32(210, 206, 187, 255);
default: return Color.magenta;
}
}
public static string NameOf(BlockType type)
{
if (IsSlab(type) || IsStairs(type))
{
string suffix = IsStairs(type) ? " Stairs" : " Slab";
string wood = WoodKey(type);
return (wood == null ? "Stone" : WoodLabel(wood)) + suffix;
}
switch (type)
{
case BlockType.Grass: return "Gras";
case BlockType.Dirt: return "Erde";
case BlockType.Stone: return "Stein";
case BlockType.Sand: return "Sand";
case BlockType.Leaf: return "Laub";
case BlockType.Water: return "Wasser";
case BlockType.OakLog: return "Oak Log";
case BlockType.OakPlanks: return "Oak";
case BlockType.SpruceLog: return "Spruce Log";
case BlockType.SprucePlanks: return "Spruce";
case BlockType.BirchLog: return "Birch Log";
case BlockType.BirchPlanks: return "Birch";
case BlockType.JungleLog: return "Jungle Log";
case BlockType.JunglePlanks: return "Jungle";
case BlockType.AcaciaLog: return "Acacia Log";
case BlockType.AcaciaPlanks: return "Acacia";
case BlockType.DarkOakLog: return "Dark Oak Log";
case BlockType.DarkOakPlanks: return "Dark Oak";
case BlockType.MangroveLog: return "Mangrove Log";
case BlockType.MangrovePlanks: return "Mangrove";
case BlockType.CherryLog: return "Cherry Log";
case BlockType.CherryPlanks: return "Cherry";
case BlockType.PaleOakLog: return "Pale Oak Log";
case BlockType.PaleOakPlanks: return "Pale Oak";
default: return type.ToString();
}
}
}
}