private void Awake()
    {
        // Add this to the global variable
        Globals.blockManager      = this;
        Globals.foregroundTilemap = foregroundTilemap;
        Globals.backgroundTilemap = backgroundTilemap;

        // This mess gets all subtypes of Block and puts the types in a list.
        Type[] allBlockTypes = (
            from domainAssembly in AppDomain.CurrentDomain.GetAssemblies()
            from assemblyType in domainAssembly.GetTypes()
            where assemblyType.IsSubclassOf(typeof(Block))
            select assemblyType).ToArray();

        allBlocks = new Block[allBlockTypes.Length];

        // For loops to populate main allBlocks array.
        for (int i = 0; i < allBlockTypes.Length; i++)
        {
            Type  newBlockType = allBlockTypes[i];
            Block newBlock     = (Block)Activator.CreateInstance(newBlockType);
            Block newBlockTwo  = new Block();
            newBlock.Initialize();
            if (newBlock.blockID == -1)
            {
                newBlock.blockID = i;
            }
            if (allBlocks[newBlock.blockID] != null)
            {
                Debug.LogWarning("Block " + newBlock + " conflicts with block " + allBlocks[newBlock.blockID] + "! (Block ID: " + newBlock.blockID + ")");
            }
            else if (newBlock.blockID > allBlocks.Length || newBlock.blockID < 0)
            {
                Debug.LogWarning("Block " + newBlock + " has invalid ID " + newBlock.blockID + "! (Max ID " + allBlocks.Length + ")");
            }
            blockNames.Add(newBlock.blockName);
            allBlocks[newBlock.blockID] = newBlock;
        }
        selectionDropdown.AddOptions(blockNames);
        WorldGen.GenerateMainMap(); // TODO: Move this to some sort of global initialization method
    }
示例#2
0
    private void Awake()
    {
        // Add this to the global variable
        Globals.blockManager      = this;
        Globals.foregroundTilemap = foregroundTilemap;
        Globals.backgroundTilemap = backgroundTilemap;

        // Initialise allBlocks array.
        allBlocks = new Block[allBlockTypes.Length];

        // For loops to populate main allBlocks array.
        for (int i = 0; i < allBlockTypes.Length; i++)
        {
            // Instead of referencing multiple arrays, we just create a new BlockType object and get values from that.
            BlockType newBlockType = allBlockTypes[i];
            allBlocks[i] = new Block(i, newBlockType.blockName, newBlockType.blockSprite, newBlockType.placeSound, newBlockType.blockSmoothing);
            blockNames.Add(newBlockType.blockName);
        }
        selectionDropdown.AddOptions(blockNames);
        WorldGen.GenerateMainMap();
    }