Exemplo n.º 1
0
 Item GetWepWeighted(RoomScriptable room)
 {
     if (room.spawnableWeps.Count > 0)
     {
         float percentile = 0;
         float full       = 0;
         float percent    = Random.Range(0, 100);
         foreach (var item in room.spawnableWeps)
         {
             full += item.weight;
         }
         if (full == 0)
         {
             return(room.spawnableWeps[Random.Range(0, room.spawnableWeps.Count)].item);
         }
         foreach (var item in room.spawnableWeps)
         {
             percentile += item.weight;
             if ((percentile / full) * 100 > percent)
             {
                 return(item.item);
             }
         }
         // return room.spawnableWeps[Random.Range(0, room.spawnableWeps.Count)].item;
     }
     return(null);
 }
Exemplo 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];
             }
         }
     }
 }
Exemplo n.º 3
0
 void NewGrid(RoomScriptable room)
 {
     room.roomGrid = new RoomScriptable.DimensionalAnchor()
     {
         Grid = room.roomGrid1D, Columns = (int)room.Size.x, Rows = (int)room.Size.y
     };
     for (int x = 0; x < room.Size.x; x++)
     {
         for (int y = 0; y < room.Size.y; y++)
         {
             room.roomGrid[x, y] = false;
         }
     }
 }
    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);
    }
Exemplo 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);
    }
Exemplo n.º 6
0
 void DeleteFromList(RoomScriptable room, bool fit)
 {
     if (!fit)
     {
         foreach (var roomS in placed)
         {
             if (roomS.room == room)
             {
                 placed.Remove(roomS);
                 break;
             }
         }
     }
     else
     {
         specialRoomsTryed = new List <SpecialRoom>();
     }
 }
Exemplo n.º 7
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);
    }
    public void Loaded(Scene sc, Scene sc2)
    {
        SceneManager.activeSceneChanged -= Loaded;
        Vector3 spawnPos = new Vector3(roomLoading.size.x / 2, 0, 2);

        moving = false;
        foreach (var door in roomLoading.doors.Where(i => i.connectedScene != null))
        {
            GameObject go = Instantiate(roomLoading.doorObject);
            go.transform.position = new Vector3(door.posOnGrid.x + .5f, 0, door.posOnGrid.y + .5f);
            if (door.connectedScene == currentRoom)
            {
                spawnPos   = go.transform.position;
                spawnPos.y = 0;
                player.transform.eulerAngles = Vector3.zero;
                player.transform.Rotate(transform.up, -90 * (int)door.direction);
            }
            go.transform.Translate(new Vector3(door.Direction(false).x / 2, 0, door.Direction(false).y / 2));
            go.transform.Rotate(transform.up, 90 * (int)door.direction);
            go.GetComponentInChildren <DoorInScene>().connectedRoom = door.connectedScene;
        }
        currentRoom          = roomLoading;
        currentRoom.explored = true;
        player.GetComponent <CharacterCont>().amIn = new List <CameraTrigger>();
        player.transform.position = spawnPos;

        transitionTime = false;
        // SpawnEnemies();
        var props               = GameObject.FindGameObjectsWithTag("PropSpawn").ToList();
        var itemSpawns          = GameObject.FindGameObjectsWithTag("ItemSpawn").ToList();
        var itemSpawnsNoDestroy = new List <GameObject>();

        Random.InitState(currentRoom.seed);

        foreach (var item in currentRoom.spawnList)
        {
            if (itemSpawns.Count == 0)
            {
                break;
            }
            var itemSpawn = itemSpawns[Random.Range(0, itemSpawns.Count)];

            if (!currentRoom.grabbedList.Contains(item.Key))
            {
                itemSpawn.GetComponent <ItemInScene>().item      = item.Value;
                itemSpawn.GetComponent <ItemInScene>().itemIndex = item.Key;
                itemSpawn.GetComponent <ItemInScene>().Spawn();
            }
            itemSpawns.Remove(itemSpawn);
            itemSpawnsNoDestroy.Add(itemSpawn);
        }
        foreach (var prop in props)
        {
            prop.GetComponent <ItemContainer>()?.RollRandom(itemSpawnsNoDestroy);
        }
        SpawnEnemies();

        Random.InitState(System.DateTime.Now.Second);

        //SpawnItems();
    }
 IEnumerator SceneLoading(RoomScriptable room)
 {
     op = SceneManager.LoadSceneAsync(room.connectedSceneName);
     op.allowSceneActivation = false;
     yield return(op);
 }
Exemplo n.º 10
0
 public void Load(RoomScriptable room)
 {
     roomLoading = room;
     SceneManager.LoadScene("DoorTransitionScene");
     moving = true;
 }
Exemplo n.º 11
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();
    }
Exemplo n.º 12
0
    void RandomMap()
    {
        rooms  = new List <RoomScriptable>();
        placed = new List <SpecialRoom>();
        List <DoorRoom> doors    = new List <DoorRoom>();
        Vector2         startPos = new Vector2(Mathf.Ceil(gridSize.x / 2) - Mathf.Floor(startRoom.Size.x / 2), 0);
        RoomScriptable  room     = Instantiate(startRoom);

        if (room.Size.x * 2 >= gridSize.x || room.Size.y * 2 >= gridSize.y)
        {
            Debug.Log("Make Grid Bigger");
            return;
        }
        rooms.Add(room);
        room.posOnGrid = startPos;
        //place room
        SetMap(this, room, startPos);
        //store doors
        foreach (var door in room.doors)
        {
            doors.Add(new DoorRoom {
                room = room, door = door
            });
        }

        //loop

        while (true)
        {
            //pop first door on list
            var door = doors[0];
            doors.RemoveAt(0);
            if (door.room.distanceFromStart < iterations)
            {
                for (int i = 0; i < specialRooms.Count - specialRoomsTryed.Count; i++)
                {
                    RoomScriptable roomBase = RollDoor(this, door.room.distanceFromStart + 1);
                    //place room
                    room = Instantiate(roomBase);
                    room.RotateTo((RoomScriptable.Rotated)Random.Range(0, 4));
                    bool fit = false;
                    for (int it = 0; it < 6; it++)
                    {
                        foreach (var connectedDoor in room.doors)
                        {
                            if ((door.door.Direction() + connectedDoor.Direction()).magnitude == 0)
                            {
                                Vector2 pos = door.room.posOnGrid + door.door.GridPos - connectedDoor.GridPos + door.door.Direction();
                                if (CanFit(this, room, pos))
                                {
                                    door.door.connectedScene     = room;
                                    connectedDoor.connectedScene = door.room;
                                    room.posOnGrid = pos;
                                    rooms.Add(room);
                                    foreach (var doorInRoom in room.doors)
                                    {
                                        doors.Add(new DoorRoom {
                                            room = room, door = doorInRoom
                                        });
                                    }
                                    room.distanceFromStart = door.room.distanceFromStart + 1;
                                    fit = true;
                                    SetMap(this, room, pos);
                                    break;
                                }
                            }
                        }
                        if (!fit)
                        {
                            room.RotateTo((RoomScriptable.Rotated)Random.Range(0, 4));
                        }
                        else
                        {
                            break;
                        }
                    }
                    noFit?.Invoke(roomBase, fit);
                    if (fit)
                    {
                        break;
                    }
                }
            }
            if (doors.Count == 0)
            {
                break;
            }
        }
    }
Exemplo n.º 13
0
    protected virtual void OnEnable()
    {
        RoomScriptable room = target as RoomScriptable;

        spawnItems = new ReorderableList(serializedObject, serializedObject.FindProperty("spawnableItems"), true, true, true, true)
        {
            drawElementCallback = DrawUseable,
            drawHeaderCallback  = (Rect rect) =>
            {
                EditorGUI.LabelField(rect, "Spawnable Items");
            }
        };
        spawnWeps = new ReorderableList(serializedObject, serializedObject.FindProperty("spawnableWeps"), true, true, true, true)
        {
            drawElementCallback = DrawSpecial,
            drawHeaderCallback  = (Rect rect) =>
            {
                EditorGUI.LabelField(rect, "Spawnable Weapons");
            }
        };

        if (room.roomGrid1D == null)
        {
            room.roomGrid1D = new bool[1];
            NewGrid(room);
            room.Size  = new Vector2(1, 1);
            room.doors = new List <RoomScriptable.Door>();
        }
        if (!(room.roomGrid1D.Length > 0))
        {
            NewGrid(room);
        }
        if (room.roomGrid.Grid == null)
        {
            room.roomGrid = new RoomScriptable.DimensionalAnchor()
            {
                Grid = room.roomGrid1D, Columns = (int)room.Size.x, Rows = (int)room.Size.y
            }
        }
        ;
        SceneView.onSceneGUIDelegate += OnSceneGUI;
    }

    void DrawUseable(Rect rect, int index, bool isActive, bool isFocused)
    {
        var element = spawnItems.serializedProperty.GetArrayElementAtIndex(index);

        rect.y += 2;
        float posX  = rect.x;
        float width = EditorGUIUtility.currentViewWidth / 2;

        EditorGUI.PropertyField(new Rect(posX, rect.y, width, EditorGUIUtility.singleLineHeight), element.FindPropertyRelative("item"), GUIContent.none);
        posX += width;
        width = EditorGUIUtility.currentViewWidth / 6;
        EditorGUI.TextField(new Rect(posX, rect.y, width, EditorGUIUtility.singleLineHeight), "Weight", GUIStyle.none);
        posX += width;
        width = EditorGUIUtility.currentViewWidth / 6;
        EditorGUI.PropertyField(new Rect(posX, rect.y, width, EditorGUIUtility.singleLineHeight), element.FindPropertyRelative("weight"), GUIContent.none);
    }

    void DrawSpecial(Rect rect, int index, bool isActive, bool isFocused)
    {
        var element = spawnWeps.serializedProperty.GetArrayElementAtIndex(index);

        rect.y += 2;
        float posX  = rect.x;
        float width = EditorGUIUtility.currentViewWidth / 2;

        EditorGUI.PropertyField(new Rect(posX, rect.y, width, EditorGUIUtility.singleLineHeight), element.FindPropertyRelative("item"), GUIContent.none);
        posX += width;
        width = EditorGUIUtility.currentViewWidth / 6;
        EditorGUI.TextField(new Rect(posX, rect.y, width, EditorGUIUtility.singleLineHeight), "Weight", GUIStyle.none);
        posX += width;
        width = EditorGUIUtility.currentViewWidth / 6;
        EditorGUI.PropertyField(new Rect(posX, rect.y, width, EditorGUIUtility.singleLineHeight), element.FindPropertyRelative("weight"), GUIContent.none);
    }
Exemplo n.º 14
0
    public override void OnInspectorGUI()
    {
        RoomScriptable room = target as RoomScriptable;

        EditorGUI.BeginChangeCheck();
        Vector3 size = EditorGUILayout.Vector2Field("Room Size", room.Size);

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

            room.Size = new Vector2(Mathf.Round(size.x), Mathf.Round(size.y));
            NewGrid(room);
            EditorUtility.SetDirty(room);
        }

        serializedObject.Update();
        spawnItems.DoLayoutList();
        spawnWeps.DoLayoutList();
        serializedObject.ApplyModifiedProperties();


        EditorGUI.BeginChangeCheck();
        SceneAsset scene = (SceneAsset)EditorGUILayout.ObjectField("Scene object", (room.connectedScene == null) ? new SceneAsset() : room.connectedScene, typeof(SceneAsset), true);

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

            room.connectedScene     = scene;
            room.connectedSceneName = scene.name;
            EditorUtility.SetDirty(room);
        }
        EditorGUI.BeginChangeCheck();
        GameObject door = (GameObject)EditorGUILayout.ObjectField("Door object", room.doorObject, typeof(GameObject), false);

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

            room.doorObject = door;
            EditorUtility.SetDirty(room);
        }
        EditorGUI.BeginChangeCheck();
        int enemies = EditorGUILayout.IntField("Max enemies", room.maxEnemies);

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

            room.maxEnemies = enemies;
            EditorUtility.SetDirty(room);
        }
        EditorGUI.BeginChangeCheck();
        int items = EditorGUILayout.IntField("Max items", room.maxItems);

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

            room.maxItems = items;
            EditorUtility.SetDirty(room);
        }
        AssetDatabase.SaveAssets();
    }
Exemplo n.º 15
0
    protected virtual void OnSceneGUI(SceneView sceneView)
    {
        RoomScriptable room = target as RoomScriptable;

        Handles.color = Color.black;
        for (int x = 0; x <= room.Size.x; x++)
        {
            Handles.DrawLine(new Vector3(x, 0, 0), new Vector3(x, 0, room.Size.y));
        }
        for (int y = 0; y <= room.Size.y; y++)
        {
            Handles.DrawLine(new Vector3(0, 0, y), new Vector3(room.Size.x, 0, y));
        }
        Handles.color = Color.white;
        // Handles.color = Color.blue;
        for (int x = 0; x < room.Size.x; x++)
        {
            for (int y = 0; y < room.Size.y; y++)
            {
                if (room.roomGrid[x, y])
                {
                    bool set = true;
                    foreach (var door in room.doors)
                    {
                        if (door.GridPos == new Vector2(x, y))
                        {
                            set = false;
                        }
                    }
                    if (set)
                    {
                        Color color = Color.blue;
                        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.red);
                    }
                }
            }
        }
        foreach (var door in room.doors)
        {
            Color color = Color.red;
            color.a = .2f;
            Handles.DrawSolidRectangleWithOutline(new Vector3[] { new Vector3(door.GridPos.x, 0, door.GridPos.y), new Vector3(door.GridPos.x, 0, door.GridPos.y + 1), new Vector3(door.GridPos.x + 1, 0, door.GridPos.y + 1), new Vector3(door.GridPos.x + 1, 0, door.GridPos.y) }, color, Color.blue);



            //draw Door
            //
            Vector2 center     = new Vector2(door.GridPos.x + .5f, door.GridPos.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);
            }
        }
        if (!ActiveEditorTracker.sharedTracker.isLocked)
        {
            return;
        }
        HandleUtility.AddDefaultControl(GUIUtility.GetControlID(FocusType.Passive));
        if (Event.current.type == EventType.mouseDown && Event.current.button == 0)
        {
            mouseDown = true;
        }
        else if (Event.current.type == EventType.mouseUp && Event.current.button == 0)
        {
            mouseDown = false;
            EditorUtility.SetDirty(room);
            AssetDatabase.SaveAssets();
        }
        if (mouseDown && !(Event.current.alt))
        {
            Undo.RecordObject(room, "room changed");

            Ray ray = HandleUtility.GUIPointToWorldRay(Event.current.mousePosition);
            //var ray = Camera.current.ScreenPointToRay(Event.current.mousePosition);
            GameObject plane = GameObject.CreatePrimitive(PrimitiveType.Plane);
            plane.transform.localScale *= 100;
            plane.layer = LayerMask.NameToLayer("TransparentFX");
            RaycastHit hit;
            if (Physics.Raycast(ray, out hit, Mathf.Infinity, 1 << plane.layer))
            {
                if (hit.point.x > 0 && hit.point.z > 0)
                {
                    if (hit.point.x < room.Size.x && hit.point.z < room.Size.y)
                    {
                        room.roomGrid[(int)Mathf.Floor(hit.point.x), (int)Mathf.Floor(hit.point.z)] = true;
                        if (Event.current.control)
                        {
                            room.roomGrid[(int)Mathf.Floor(hit.point.x), (int)Mathf.Floor(hit.point.z)] = false;
                        }

                        if (Event.current.shift && Event.current.type == EventType.mouseDown)
                        {
                            Vector2 pos     = new Vector2((int)Mathf.Floor(hit.point.x), (int)Mathf.Floor(hit.point.z));
                            Vector2 unitVec = new Vector2((hit.point.x % 1) - .5f, (hit.point.z % 1) - .5f);
                            RoomScriptable.EnumDirection dir = RoomScriptable.EnumDirection.NORTH;
                            if (unitVec.y < unitVec.x && unitVec.y > -unitVec.x)
                            {
                                dir = RoomScriptable.EnumDirection.EAST;
                            }
                            else if (unitVec.y > unitVec.x && unitVec.y > -unitVec.x)
                            {
                                dir = RoomScriptable.EnumDirection.NORTH;
                            }
                            else if (unitVec.y < unitVec.x && unitVec.y < -unitVec.x)
                            {
                                dir = RoomScriptable.EnumDirection.SOUTH;
                            }
                            else if (unitVec.y > unitVec.x && unitVec.y < -unitVec.x)
                            {
                                dir = RoomScriptable.EnumDirection.WEST;
                            }

                            RoomScriptable.Door door = new RoomScriptable.Door(pos, dir, RoomScriptable.Rotated.ZERO)
                            {
                                size = room.Size
                            };
                            if (room.doors.Contains(door))
                            {
                                room.doors.Remove(door);
                            }
                            else
                            {
                                room.doors.Add(door);
                            }
                        }
                    }
                }
            }
            DestroyImmediate(plane);
        }
    }