Ejemplo n.º 1
0
        public void DestroyMap()
        {
            //clear rooms
            rooms.Clear();
            roomID   = 0;
            lastRoom = null;

            //clear fixed rooms
            fixedRoomsAlreadyChecked.Clear();
            fixedRoomTryingToPut = null;
            fixedRoomsAlreadyPut.Clear();

            //remove every child
            foreach (Transform child in transform)
            {
#if UNITY_EDITOR
                if (Application.isPlaying)
                {
                    Destroy(child.gameObject);
                }
                else
                {
                    EditorApplication.delayCall += () => DestroyImmediate(child.gameObject);
                }
#else
                Destroy(child.gameObject);
#endif
            }
        }
Ejemplo n.º 2
0
        void UpdateFixedRooms()
        {
            //clear rooms already checked
            fixedRoomsAlreadyChecked.Clear();

            //and add to list already put
            if (fixedRoomTryingToPut != null)
            {
                fixedRoomsAlreadyPut.Add(fixedRoomTryingToPut);
                fixedRoomTryingToPut = null;
            }
        }
Ejemplo n.º 3
0
        Room GetRoomPrefab()
        {
            //quando istanzi, controlla se ci sono stanze fisse
            //se non si attacca, vedere se ce ne sono altre
            //se una stanza non viene creata nel suo range, distruggere e ricreare il dungeon

            //quando istanzi, controlla se ci sono stanze fisse
            //aggiungere alla lista delle già checkate, così se non si attacca ne viene provata un'altra
            //quando viene posizionata una stanza pulisci le già checkate per riprovarle tutte, ma se quella creata era una di quelle fisse aggiungila alla lista già piazzate per non riprovarla
            //se la stanza fissa non viene posizionata ma ha il range più alto, si può riprovare al posizionamento successivo, ma assicurarsi di resettare la variabile se si posiziona una stanza non fissa
            //se una stanza non viene creata nel suo range, distruggere e ricreare il dungeon

            //if a room failed at its maxID, recreate dungeon
            if (fixedRoomTryingToPut != null && roomID >= fixedRoomTryingToPut.maxID)
            {
                return(null);
            }

            //check fixed rooms
            foreach (StructFixedRooms checkRoom in fixedRooms)
            {
                //be sure is not already checked
                if (fixedRoomsAlreadyChecked.Contains(checkRoom) || fixedRoomsAlreadyPut.Contains(checkRoom))
                {
                    continue;
                }

                //if there is one who need this ID
                if (roomID >= checkRoom.minID && roomID <= checkRoom.maxID)
                {
                    //add to list already check
                    fixedRoomsAlreadyChecked.Add(checkRoom);

                    //return its prefab
                    fixedRoomTryingToPut = checkRoom;
                    return(checkRoom.roomPrefabs[Random.Range(0, checkRoom.roomPrefabs.Length)]);
                }
            }

            //else check for filler room
            fixedRoomTryingToPut = null;

            //get random value from 1 to 100
            int random            = Mathf.Max(1, Mathf.RoundToInt(Random.value * 100));
            int currentPercentage = 0;

            //foreach filler, check if percentage is inside random value
            foreach (StructFillerRooms filler in fillerRooms)
            {
                //if inside, return its prefab
                if (filler.percentage + currentPercentage >= random)
                {
                    return(filler.roomPrefabs[Random.Range(0, filler.roomPrefabs.Length)]);
                }

                //else, add to currentPercentage, to check next one
                currentPercentage += filler.percentage;
            }

            return(null);
        }