Ejemplo n.º 1
0
    protected virtual void OnEnable()
    {
        MapGenScriptiable gen = target as MapGenScriptiable;

        targetWeapons = new ReorderableList(serializedObject, serializedObject.FindProperty("neededWeapons"), true, true, true, true)
        {
            drawElementCallback = DrawWeapon,
            drawHeaderCallback  = (Rect rect) =>
            {
                EditorGUI.LabelField(rect, "Weapon Target");
            }
        };

        usableRooms = new ReorderableList(serializedObject, serializedObject.FindProperty("useableRooms"), true, true, true, true)
        {
            drawElementCallback = DrawUseable,
            drawHeaderCallback  = (Rect rect) =>
            {
                EditorGUI.LabelField(rect, "Usable Rooms");
            }
        };
        SpecialRooms = new ReorderableList(serializedObject, serializedObject.FindProperty("specialRooms"), true, true, true, true)
        {
            drawElementCallback = DrawSpecial,
            drawHeaderCallback  = (Rect rect) =>
            {
                EditorGUI.LabelField(rect, "Special Rooms");
            }
        };
        SceneView.onSceneGUIDelegate += OnSceneGUI;
        gen.Initilise();
    }
Ejemplo n.º 2
0
 //start is the client rooms 0,0 coord in global
 void SetMap(MapGenScriptiable gen, RoomScriptable room, Vector2 start)
 {
     for (int x = (int)start.x; x < start.x + room.Size.x; x++)
     {
         for (int y = (int)start.y; y < start.y + room.Size.y; y++)
         {
             if (!gen.grid[x, y])
             {
                 gen.grid[x, y] = room.roomGrid[x - (int)start.x, y - (int)start.y];
             }
         }
     }
 }
Ejemplo n.º 3
0
    IEnumerator loadMap()
    {
        yield return(null);

        MapGenScriptiable gen = Instantiate(mapGen);

        //Instantiate new copies of the rooms into the gen
        gen.GenMap();
        mapGen = gen;
        DontDestroyOnLoad(mapGen);
        currentRoom = gen.rooms[0];
        player      = Instantiate(playerPrefab);
        player.transform.position = new Vector3(-100, -100, -100);
        DontDestroyOnLoad(player);
    }
Ejemplo n.º 4
0
    RoomScriptable RollDoor(MapGenScriptiable gen, int distanceFromStart)
    {
        float percentile = 0;
        float full       = 0;

        float percent = Random.Range(0, 100);

        if (percent > 0)
        {
            percent = Random.Range(0, 100);
            var rooms = new List <SpecialRoom>();
            foreach (var room in gen.specialRooms.Where(i => !placed.Contains(i) && !specialRoomsTryed.Contains(i)))
            {
                if (distanceFromStart >= room.distanceAfter)
                {
                    rooms.Add(room);
                }
            }
            foreach (var room in rooms)
            {
                percentile++;
                if ((percentile / rooms.Count) * 100 > percent)
                {
                    placed.Add(room);
                    specialRoomsTryed.Add(room);

                    return(room.room);
                }
            }
        }


        percent = Random.Range(0, 100);
        foreach (var room in gen.useableRooms)
        {
            full += room.chanceToPlace;
        }
        foreach (var room in gen.useableRooms)
        {
            percentile += room.chanceToPlace;
            if ((percentile / full) * 100 > percent)
            {
                return(room.room);
            }
        }
        return(gen.useableRooms[Random.Range(0, gen.useableRooms.Count)].room);
    }
Ejemplo n.º 5
0
    void OnAdd(ReorderableList _list)
    {
        MapGenScriptiable gen = target as MapGenScriptiable;

        if (gen.startRoom != null)
        {
            RoomScriptable room = Instantiate(gen.startRoom);
            gen.useableRooms.Add(new MapGenScriptiable.RoomWithWeighting()
            {
                room = room, chanceToPlace = .5f
            });
        }
        else
        {
            Debug.Log("Set StartRoom");
        }
        EditorUtility.SetDirty(target);
    }
Ejemplo n.º 6
0
    //start is the client rooms 0,0 coord in global
    bool CanFit(MapGenScriptiable gen, RoomScriptable room, Vector2 start)
    {
        for (int x = (int)start.x; x < start.x + room.Size.x; x++)
        {
            for (int y = (int)start.y; y < start.y + room.Size.y; y++)
            {
                if (x >= gen.Size.x || x < 0 || y >= gen.Size.y || y < 0)
                {
                    return(false);
                }
                if (gen.grid[x, y] == true && room.roomGrid[x - (int)start.x, y - (int)start.y] == true)
                {
                    return(false);
                }
            }
        }


        return(true);
    }
Ejemplo n.º 7
0
    public override void OnInspectorGUI()
    {
        MapGenScriptiable gen = target as MapGenScriptiable;


        serializedObject.Update();
        usableRooms.DoLayoutList();
        serializedObject.ApplyModifiedProperties();

        serializedObject.Update();
        SpecialRooms.DoLayoutList();
        serializedObject.ApplyModifiedProperties();

        serializedObject.Update();
        targetWeapons.DoLayoutList();
        serializedObject.ApplyModifiedProperties();

        EditorGUI.BeginChangeCheck();
        RoomScriptable startRoom = (RoomScriptable)EditorGUILayout.ObjectField(gen.startRoom, typeof(RoomScriptable), false);

        if (EditorGUI.EndChangeCheck())
        {
            Undo.RecordObject(gen, "gen changed");

            gen.startRoom = startRoom;
            EditorUtility.SetDirty(gen);
        }
        EditorGUI.BeginChangeCheck();
        Vector3 size = EditorGUILayout.Vector2Field("Room Size", gen.Size);

        if (EditorGUI.EndChangeCheck())
        {
            Undo.RecordObject(gen, "gen changed");

            gen.Size = new Vector2(Mathf.Clamp(Mathf.Round(size.x), 1, 128), Mathf.Clamp(Mathf.Round(size.y), 1, 128));
            EditorUtility.SetDirty(gen);
        }

        EditorGUI.BeginChangeCheck();
        int iterations = EditorGUILayout.IntField("Iterations", gen.iterations);

        if (EditorGUI.EndChangeCheck())
        {
            Undo.RecordObject(gen, "gen changed");

            gen.iterations = iterations;
            EditorUtility.SetDirty(gen);
        }
        EditorGUI.BeginChangeCheck();
        int enemies = EditorGUILayout.IntField("Target enemies", gen.targetEnemies);

        if (EditorGUI.EndChangeCheck())
        {
            Undo.RecordObject(gen, "gen changed");


            gen.targetEnemies = enemies;
            EditorUtility.SetDirty(gen);
        }
        EditorGUI.BeginChangeCheck();
        int items = EditorGUILayout.IntField("Target Consumables", gen.targetConsumables);

        if (EditorGUI.EndChangeCheck())
        {
            Undo.RecordObject(gen, "gen changed");


            gen.targetConsumables = items;
            EditorUtility.SetDirty(gen);
        }
        if (GUILayout.Button("Generate Map"))
        {
            Undo.RecordObject(gen, "gen changed");

            gen.GenMap();
            EditorUtility.SetDirty(gen);
        }
        AssetDatabase.SaveAssets();
    }
Ejemplo n.º 8
0
    protected virtual void OnSceneGUI(SceneView sceneView)
    {
        MapGenScriptiable gen = target as MapGenScriptiable;

        Handles.color = Color.black;
        for (int x = 0; x <= gen.Size.x; x++)
        {
            Handles.DrawLine(new Vector3(x, 0, 0), new Vector3(x, 0, gen.Size.y));
        }
        for (int y = 0; y <= gen.Size.y; y++)
        {
            Handles.DrawLine(new Vector3(0, 0, y), new Vector3(gen.Size.x, 0, y));
        }
        //Vector3 lablePos = new Vector3(0, 0, gen.Size.y - 2);
        //Handles.Label(lablePos, "We have no affiliation to the gay party");
        int i = 0;

        foreach (var room in gen.rooms)
        {
            if (!room)
            {
                gen.rooms.Remove(room);
                break;
            }
            Random.InitState(i);
            i++;
            Handles.color = Color.white;
            Color color = new Color(Random.Range(0f, 1f), Random.Range(0f, 1f), Random.Range(0f, 1f), 1);


            for (int x = (int)room.posOnGrid.x; x < room.posOnGrid.x + room.Size.x; x++)
            {
                for (int y = (int)room.posOnGrid.y; y < room.posOnGrid.y + room.Size.y; y++)
                {
                    if (room.roomGrid[x - (int)room.posOnGrid.x, y - (int)room.posOnGrid.y])
                    {
                        color.a = .2f;
                        Handles.DrawSolidRectangleWithOutline(new Vector3[] { new Vector3(x, 0, y), new Vector3(x, 0, y + 1), new Vector3(x + 1, 0, y + 1), new Vector3(x + 1, 0, y) }, color, color);
                    }
                }
            }
            Vector3 lablePos = new Vector3(room.size.x / 2 + room.posOnGrid.x, 0, room.size.y / 2 + room.posOnGrid.y);
            Handles.Label(lablePos, room.distanceFromStart.ToString());
            foreach (var door in room.doors.Where(door => door.connectedScene != null))
            {
                color = Color.red;


                color.a = .2f;
                Vector2 pos = room.posOnGrid + door.GridPos;
                Handles.DrawSolidRectangleWithOutline(new Vector3[] { new Vector3(pos.x, 0, pos.y), new Vector3(pos.x, 0, pos.y + 1), new Vector3(pos.x + 1, 0, pos.y + 1), new Vector3(pos.x + 1, 0, pos.y) }, color, Color.blue);
                foreach (var otherDoor in door.connectedScene.doors.Where(otherDoor => otherDoor.connectedScene == room))
                {
                    Vector2 posO = door.connectedScene.posOnGrid + otherDoor.GridPos;
                    Handles.DrawLine(new Vector3(pos.x + .5f, 0, pos.y + .5f), new Vector3(posO.x + .5f, 0, posO.y + .5f));
                }

                //draw Door
                //
                Vector2 center     = new Vector2(pos.x + .5f, pos.y + .5f);
                Vector2 doorCenter = center + (door.Direction() / 2);

                if (door.direction == RoomScriptable.EnumDirection.NORTH || door.direction == RoomScriptable.EnumDirection.SOUTH)
                {
                    Handles.DrawSolidRectangleWithOutline(new Vector3[] {
                        new Vector3(doorCenter.x - 0.4f, 0, doorCenter.y - 0.1f),
                        new Vector3(doorCenter.x - 0.4f, 0, doorCenter.y + 0.1f),
                        new Vector3(doorCenter.x + 0.4f, 0, doorCenter.y + 0.1f),
                        new Vector3(doorCenter.x + 0.4f, 0, doorCenter.y - 0.1f)
                    },
                                                          color, Color.blue);
                }
                else
                {
                    Handles.DrawSolidRectangleWithOutline(new Vector3[] {
                        new Vector3(doorCenter.x - 0.1f, 0, doorCenter.y - 0.4f),
                        new Vector3(doorCenter.x - 0.1f, 0, doorCenter.y + 0.4f),
                        new Vector3(doorCenter.x + 0.1f, 0, doorCenter.y + 0.4f),
                        new Vector3(doorCenter.x + 0.1f, 0, doorCenter.y - 0.4f)
                    },
                                                          color, Color.blue);
                }
            }
        }
        Random.InitState(System.DateTime.Now.Second);
    }