Beispiel #1
0
    public override void OnInspectorGUI()
    {
        MapInterpreterBehaviour t = (MapInterpreterBehaviour)target;

        if (g == null)
        {
            g = t.gameObject.GetComponent <GeneratorBehaviour>();
        }
        if (p == null)
        {
            p = t.gameObject.GetComponent <PhysicalMapBehaviour>();
        }
        if (v == null)
        {
            v = t.gameObject.GetComponent <VirtualMapGeneratorBehaviour>();
        }

        t.drawRocks       = EditorGUILayout.Toggle("Draw Rocks", t.drawRocks);
        t.drawWallCorners = EditorGUILayout.Toggle("Draw Wall Corners", t.drawWallCorners);
        t.drawDoors       = EditorGUILayout.Toggle("Place Doors in Passages", t.drawDoors);

        if (v != null && v.HasRooms)
        {
            t.createColumnsInRooms = EditorGUILayout.Toggle("Draw Columns in Rooms", t.createColumnsInRooms);
        }

        t.useDirectionalFloors = EditorGUILayout.Toggle("Use Directional Floors", t.useDirectionalFloors);

        if (t.useDirectionalFloors)
        {
            t.randomOrientations = false;
        }
        else
        {
            t.randomOrientations = EditorGUILayout.Toggle("Randomize Orientations", t.randomOrientations);
        }

        if (t.useDirectionalFloors)
        {
            t.isolateDirectionalWallsForRooms = EditorGUILayout.Toggle(new GUIContent("Isolate Rooms", "If enabled, room corners will be isolated from the rest of the dungeon."), t.isolateDirectionalWallsForRooms);
        }

        t.usePerimeter = EditorGUILayout.Toggle("Use Perimeter Walls", t.usePerimeter);
//		if (t.usePerimeter) t.internalPerimeter =EditorGUILayout.Toggle("Internal Perimeter",t.internalPerimeter);

        if (g.mapDimensionsType == MapDimensionsType.THREE_DEE)
        {
            t.addCeilingToCorridors = EditorGUILayout.Toggle("Add Ceiling to Corridors", t.addCeilingToCorridors);
            if (v.HasRooms)
            {
                t.addCeilingToRooms = EditorGUILayout.Toggle("Add Ceiling To Rooms", t.addCeilingToRooms);
            }
        }
    }
    public override void OnInspectorGUI()
    {
        PhysicalMapBehaviour t = (PhysicalMapBehaviour)target;

        if (g == null)
        {
            g = t.gameObject.GetComponent <GeneratorBehaviour>();
        }
        if (i == null)
        {
            i = t.gameObject.GetComponent <MapInterpreterBehaviour>();
        }
        if (v == null)
        {
            v = t.gameObject.GetComponent <VirtualMapGeneratorBehaviour>();
        }

        if (v.createStartAndEnd)
        {
            t.createEntranceAndExit = EditorGUILayout.Toggle("Add Entrance and Exit", t.createEntranceAndExit);

            if (t.createEntranceAndExit)
            {
                //			EditorGUILayout.BeginHorizontal();
                t.createPlayer = EditorGUILayout.Toggle("Add Player", t.createPlayer);
                if (t.createPlayer)
                {
                    t.playerPrefab = EditorGUILayout.ObjectField("Player Prefab", t.playerPrefab, typeof(GameObject), true) as GameObject;
                }
                //			EditorGUILayout.EndHorizontal();
            }
        }

        if (!t.AutomaticBatching)
        {
            t.enabledBatching = EditorGUILayout.Toggle("Perform Batching", t.enabledBatching);
        }
        if (!t.AutomaticOrientation && !t.ForcedOrientation)
        {
            t.mapPlaneOrientation = (MapPlaneOrientation)EditorGUILayout.EnumPopup("Orientation", t.mapPlaneOrientation);
        }
    }
Beispiel #3
0
    public override void OnInspectorGUI()
    {
        errorStyle = new GUIStyle();
        errorStyle.normal.textColor = Color.red;

        GeneratorBehaviour           t = (GeneratorBehaviour)target;
        PhysicalMapBehaviour         physicalMapBehaviour   = t.gameObject.GetComponent <PhysicalMapBehaviour>();
        MapInterpreterBehaviour      interpreterBehaviour   = t.gameObject.GetComponent <MapInterpreterBehaviour>();
        VirtualMapGeneratorBehaviour vmapGeneratorBehaviour = t.gameObject.GetComponent <VirtualMapGeneratorBehaviour>();

        targetInstance = t;

        t.mapDimensionsType = (MapDimensionsType)EditorGUILayout.EnumPopup("Map Dimensions Type", t.mapDimensionsType);

        t.MapWidth  = EditorGUILayout.IntSlider("Map Width", t.MapWidth, 2, GeneratorBehaviour.MAX_SIZE);
        t.MapHeight = EditorGUILayout.IntSlider("Map Length", t.MapHeight, 2, GeneratorBehaviour.MAX_SIZE);

        EditorGUILayout.BeginHorizontal();
        t.useSeed = EditorGUILayout.Toggle("Use seed", t.useSeed);
        EditorGUI.BeginDisabledGroup(t.useSeed == false);
        t.seed = EditorGUILayout.IntSlider("Seed", t.seed, 0, 10000);
        EditorGUI.EndDisabledGroup();
        EditorGUILayout.EndHorizontal();

        if (t.mapDimensionsType == MapDimensionsType.THREE_DEE)
        {
            t.multiStorey = EditorGUILayout.Toggle("Multi-Storey", t.multiStorey);
            if (t.multiStorey)
            {
                t.numberOfStoreys = EditorGUILayout.IntSlider("Number of Storeys", t.numberOfStoreys, 1, 10);
            }
            else
            {
                t.numberOfStoreys = 1;
            }
        }
        else
        {
            t.multiStorey     = false;
            t.numberOfStoreys = 1;
        }

        this.showAdvanced = EditorGUILayout.Foldout(this.showAdvanced, "Advanced Options");
        if (this.showAdvanced)
        {
            GUILayout.BeginHorizontal();
            t.printTimings = EditorGUILayout.Toggle("Print Timings", t.printTimings);
            GUILayout.EndHorizontal();
            EditorGUILayout.LabelField("Last used seed: " + t.lastUsedSeed);
            showDebugCoordinates = EditorGUILayout.Toggle("Show Debug Coordinates", showDebugCoordinates);
            showDebugConnections = EditorGUILayout.Toggle("Show Debug Connections", showDebugConnections);
        }

        EditorGUI.BeginDisabledGroup(Application.isPlaying == true);
        bool canGenerate = true;

        if (vmapGeneratorBehaviour == null)
        {
            GUILayout.Label("Attach a Virtual Map Generator Behaviour to enable generation!", errorStyle);
            canGenerate = false;
        }
        if (physicalMapBehaviour == null)
        {
            GUILayout.Label("Attach a Physical Map Behaviour to enable generation!", errorStyle);
            canGenerate = false;
        }
        else if (t.mapDimensionsType == MapDimensionsType.THREE_DEE && !physicalMapBehaviour.SupportsThreeDeeMap)
        {
            GUILayout.Label("The attached Physical Map Behaviour does not support a 3D map!", errorStyle);
            canGenerate = false;
        }
        if (interpreterBehaviour == null)
        {
            GUILayout.Label("Attach a Map Interpreter Behaviour to enable generation!", errorStyle);
            canGenerate = false;
        }

        EditorGUI.BeginDisabledGroup(!canGenerate);
        if (GUILayout.Button("Generate!"))
        {
            t.Generate();
        }
        EditorGUI.EndDisabledGroup();

        #region Save/Load buttons
        EditorGUILayout.BeginHorizontal();
        if (GUILayout.Button("Save"))
        {
            SavePrefab();
        }
        EditorGUILayout.EndHorizontal();
        #endregion
        EditorGUI.EndDisabledGroup();
    }
    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;
    }