public void Generate()
    {
        isCurrentlyGenerating = true;

        // Make sure we have a VirtualMapGeneratorBheaviour component
        virtualMapGeneratorBehaviour = gameObject.GetComponent <VirtualMapGeneratorBehaviour>();
        if (virtualMapGeneratorBehaviour == null)
        {
            Debug.LogError("You need to attach a VirtualMapGeneratorBehaviour to this gameObject to enable generation!", this);
            return;
        }

        // Make sure we have a PhysicalMapBehaviour component
        physicalMapBehaviour = gameObject.GetComponent <PhysicalMapBehaviour>();
        if (physicalMapBehaviour == null)
        {
            Debug.LogError("You need to attach a PhysicalMapBehaviour to this gameObject to enable generation!", this);
            return;
        }

        // Make sure we have a MapInterpreterBehaviour component
        interpreterBehaviour = gameObject.GetComponent <MapInterpreterBehaviour>();
        if (interpreterBehaviour == null)
        {
            Debug.LogError("You need to attach a MapInterpreterBehaviour to this gameObject to enable generation!", this);
            return;
        }

        // Remove the existing map
        if (rootMapGo != null)
        {
            if (physicalMap != null)
            {
                physicalMap.CleanUp();
                DestroyImmediate(physicalMap);
            }

            if (Application.isPlaying)
            {
                Destroy(rootMapGo);
            }
            else
            {
                DestroyImmediate(rootMapGo);
            }
            virtualMaps = null;
            physicalMap = null;
        }

        // Remove any other existing children as well
        foreach (Transform childTr in this.transform)
        {
            DestroyImmediate(childTr.gameObject);
        }


        if (printTimings)
        {
            preDate = System.DateTime.Now;
        }

        if (!ForceCommonSenseOptions())
        {
            return;
        }

        physicalMapBehaviour.MeasureSizes();
        SetGeneratorValues();

        virtualMapGeneratorBehaviour.Initialise();
        lastUsedSeed = virtualMapGeneratorBehaviour.InitialiseSeed(useSeed, seed);
        virtualMaps  = virtualMapGeneratorBehaviour.GenerateAllMaps(MapWidth, MapHeight, numberOfStoreys);

        mapInterpreter = interpreterBehaviour.Generate();

        physicalMap = physicalMapBehaviour.Generate(virtualMaps, this, mapInterpreter);

        this.rootMapGo = physicalMap.rootMapGo;

        if (printTimings)
        {
            postDate = System.DateTime.Now;
            TimeSpan timeDifference = postDate.Subtract(preDate);
            Debug.Log("Generated in " + timeDifference.TotalMilliseconds.ToString() + " ms");
        }

        BroadcastMessage("DungeonGenerated", SendMessageOptions.DontRequireReceiver);
        isCurrentlyGenerating = false;
    }
Пример #2
0
    override public PhysicalMap Generate(VirtualMap[] maps, GeneratorBehaviour generator, MapInterpreter interpreter)
    {
        Prefabs2DPhysicalMap physMap = ScriptableObject.CreateInstance <Prefabs2DPhysicalMap>();

        physMap.Initialise(maps, generator, interpreter);
        physMap.behaviour = this;
        physMap.Generate();
        return(physMap);
    }