private void RegisterBlock(Block b, BlockDataAttribute attributes) { b.Id = BlockRegistrationId; BlockRegistrationId++; b.Data = attributes; Texture2D[] loadedTextures = new Texture2D[6]; for (int i = 0; i < 6; i++) { Texture2D blockTexture = (Texture2D)Resources.Load(b.Data.TextureNames[i]); if (blockTexture == null) { Debug.LogWarning("Block: " + b.Data.DisplayName + " references a texture that doesn't exist. Falling back"); blockTexture = (Texture2D)Resources.Load("notexture"); } loadedTextures[i] = blockTexture; } string name = attributes.DisplayName; if (RegisteredBlocks.ContainsKey(name)) { throw new InvalidOperationException("Cannot have two blocks with the same name!"); } RegisteredBlocks[name] = new RegisteredBlock() { Block = b, }; }
public static void LoadBlockType(Block block) { BlockDataAttribute attrib = block.GetType().GetCustomAttributes(typeof(BlockDataAttribute), true).Cast <BlockDataAttribute>().FirstOrDefault(); if (attrib == null) { // Skip blocks with invalid attributes Debug.LogError(block.GetType().Name + " must have a data attribute assigned to load properly."); return; } try { Game.BlockRegistry.RegisterBlock(block, attrib); } catch (InvalidOperationException e) { Debug.LogError(block.GetType().Name + " already loaded, so skipping . . ."); return; } }
private void RegisterBlock(Block b, BlockDataAttribute attributes) { b.Id = BlockRegistrationId; BlockRegistrationId++; b.Data = attributes; Texture2D[] loadedTextures = new Texture2D[6]; for(int i = 0; i < 6; i++) { Texture2D blockTexture = (Texture2D)Resources.Load(b.Data.TextureNames[i]); if (blockTexture == null) { Debug.LogWarning("Block: " + b.Data.DisplayName + " references a texture that doesn't exist. Falling back"); blockTexture = (Texture2D)Resources.Load("notexture"); } loadedTextures[i] = blockTexture; } string name = attributes.DisplayName; if (RegisteredBlocks.ContainsKey(name)) { throw new InvalidOperationException("Cannot have two blocks with the same name!"); } RegisteredBlocks[name] = new RegisteredBlock() { Block = b, }; }