本文整理汇总了C#中IDefinitionManager.GetBlockDefinitions方法的典型用法代码示例。如果您正苦于以下问题:C# IDefinitionManager.GetBlockDefinitions方法的具体用法?C# IDefinitionManager.GetBlockDefinitions怎么用?C# IDefinitionManager.GetBlockDefinitions使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IDefinitionManager
的用法示例。
在下文中一共展示了IDefinitionManager.GetBlockDefinitions方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Deserialize
/// <summary>
/// Deserialisiert die Chunksäule aus dem angegebenen Stream.
/// </summary>
/// <param name="stream">Quellstream</param>
/// <param name="definitionManager">Der verwendete DefinitionManager</param>
/// <param name="columnIndex">Die Position der Säule</param>
/// <param name="planetId">Der Index des Planeten</param>
public void Deserialize(Stream stream, IDefinitionManager definitionManager, int planetId, Index2 columnIndex)
{
using (BinaryReader br = new BinaryReader(stream))
{
bool longIndex = br.ReadByte() > 0;
// Phase 1 (Column Meta: Heightmap, populated, chunkcount)
Chunks = new Chunk[br.ReadByte()]; // Chunk Count
Planet = planetId;
Index = columnIndex;
Populated = br.ReadBoolean(); // Populated
for (int y = 0; y < Chunk.CHUNKSIZE_Y; y++) // Heightmap
for (int x = 0; x < Chunk.CHUNKSIZE_X; x++)
Heights[x, y] = br.ReadUInt16();
int[] counter = new int[Chunks.Length];
for (int i = 0; i < Chunks.Length; i++) // ChangeCounter
counter[i] = br.ReadInt32();
// Phase 2 (Block Definitionen)
List<IBlockDefinition> types = new List<IBlockDefinition>();
Dictionary<ushort, ushort> map = new Dictionary<ushort, ushort>();
int typecount = longIndex ? br.ReadUInt16() : br.ReadByte();
for (int i = 0; i < typecount; i++)
{
string typeName = br.ReadString();
IBlockDefinition[] definitions = definitionManager.GetBlockDefinitions().ToArray();
var blockDefinition = definitions.FirstOrDefault(d => d.GetType().FullName == typeName);
types.Add(blockDefinition);
map.Add((ushort)types.Count, (ushort)(Array.IndexOf(definitions, blockDefinition) + 1));
}
// Phase 3 (Chunk Infos)
for (int c = 0; c < Chunks.Length; c++)
{
IChunk chunk = Chunks[c] = new Chunk(new Index3(columnIndex, c), planetId);
for (int i = 0; i < chunk.Blocks.Length; i++)
{
ushort typeIndex = longIndex ? br.ReadUInt16() : br.ReadByte();
chunk.MetaData[i] = 0;
if (typeIndex > 0)
{
chunk.Blocks[i] = map[typeIndex];
var definition = definitionManager.GetBlockDefinitionByIndex(map[typeIndex]);
if (definition.HasMetaData)
chunk.MetaData[i] = br.ReadInt32();
}
}
chunk.ChangeCounter = counter[c];
}
}
}