Example #1
0
        public async Task SceneDetails_FromDLModelShouldMapToSceneDetails()
        {
            var newScene = new Scene
            {
                ID = 1,
                SceneDescription = "sceneDescription",
                SceneName        = "sceneName",
                SceneIndex       = 1,
                ParsedID         = "parsedId",
                SceneFiles       = new List <SceneFile> {
                    new SceneFile()
                }
            };
            var result = SceneDetails.FromDLModel(newScene);

            Assert.Equal(newScene.ID, result.ID);
            Assert.Equal(newScene.SceneDescription, result.SceneDescription);
            Assert.Equal(newScene.SceneName, result.SceneName);
            Assert.Equal(newScene.SceneIndex, result.SceneIndex);
            Assert.Equal(newScene.ParsedID, result.ParsedID);
        }
    private String getListAllScenes(SceneDetails[] sceneArray)
    {
        int sceneCount = UnityEngine.SceneManagement.SceneManager.sceneCountInBuildSettings;

        sceneArray = new SceneDetails[sceneCount];
        for (int i = 0; i < sceneCount; i++)
        {
            String       path         = UnityEngine.SceneManagement.SceneUtility.GetScenePathByBuildIndex(i);
            String[]     pathElements = path.Split('/');
            String       name         = pathElements[pathElements.Length - 1];
            SceneDetails sceneDetails = new SceneDetails(name, path);
            sceneArray[i] = sceneDetails;
        }

        String scenesArrayString = "";

        foreach (SceneDetails sceneDetails in sceneArray)
        {
            scenesArrayString += sceneDetails + ";";
        }
        return(scenesArrayString);
    }
    private void Start()
    {
        // 1. Set WorkingDirectory
        string ScenarioName     = ScenarioAtHand.ScenarioName;
        string WorkingDirectory = Application.persistentDataPath + "/" + ScenarioName;

        float WIDTH  = 0;
        float LENGTH = 0;
        float HEIGHT = 0;

        // 2. Load in all scenes in the scenario
        DirectoryInfo dir = new DirectoryInfo(WorkingDirectory);

        DirectoryInfo[] subdirs   = dir.GetDirectories();
        List <string>   AllScenes = new List <string>();

        foreach (DirectoryInfo subdir in subdirs)
        {
            AllScenes.Add(subdir.Name);
        }

        // 3. For each scene, create a scene object and put it in AllSceneObjects
        List <GameObject> AllSceneObjects = new List <GameObject>();

        foreach (string Scene in AllScenes)
        {
            GameObject scene = new GameObject(Scene);
            scene.tag = "Scene";
            scene.transform.position = new Vector3(0, 0, 0);
            scene.AddComponent <SceneInfo>();
            AllSceneObjects.Add(scene);
        }

        // 4. For each scene, load the stored data
        foreach (GameObject Scene in AllSceneObjects)
        {
            WorkingDirectory = Application.persistentDataPath + "/" + ScenarioName + "/" + Scene.name;
            List <string> AllObjectsNames = new List <string>();

            // 4.1 read all the names from the AllNames.txt file.
            if (File.Exists(WorkingDirectory + "/AllNames.txt"))
            {
                string       name;
                StreamReader theReader = new StreamReader(WorkingDirectory + "/AllNames.txt");
                using (theReader)
                {
                    do
                    {
                        name = theReader.ReadLine();
                        if (name != null)
                        {
                            AllObjectsNames.Add(name);
                        }
                    }while (name != null);
                }
                theReader.Close();
            }

            // 4.2 read in all the details into sceneDetails (SceneDetails)
            SceneDetails sceneDetails = new SceneDetails();
            if (File.Exists(WorkingDirectory + "/SceneDetails.dat"))
            {
                BinaryFormatter bf   = new BinaryFormatter();
                FileStream      file = File.Open(WorkingDirectory + "/SceneDetails.dat", FileMode.Open);
                sceneDetails = (SceneDetails)bf.Deserialize(file);
                file.Close();
            }

            // 4.3 Recover the scene based on sceneDetails
            // 4.3.1 Fill in sim info. If it is in design scene
            Scene.GetComponent <SceneInfo>().SimulationTime = sceneDetails.SimTime;
            Scene.GetComponent <SceneInfo>().Width          = sceneDetails.Width;
            Scene.GetComponent <SceneInfo>().Length         = sceneDetails.Length;
            Scene.GetComponent <SceneInfo>().Height         = sceneDetails.Height;
            Scene.GetComponent <SceneInfo>().PlayerX        = sceneDetails.PlayerX;
            Scene.GetComponent <SceneInfo>().PlayerY        = sceneDetails.PlayerY;
            // 4.3.2 Fill in the TimeDensity in SceneInfo
            //       and then effectivetimedensity
            if (Directory.Exists(WorkingDirectory + "/TimeDensity/"))
            {
                BinaryFormatter TimeDensitybf   = new BinaryFormatter();
                FileStream      TimeDensityfile = File.Open(WorkingDirectory + "/TimeDensity/" + "AllData.dat", FileMode.Open);
                List <float>    newTimeDensity  = (List <float>)TimeDensitybf.Deserialize(TimeDensityfile);
                TimeDensityfile.Close();
                Scene.GetComponent <SceneInfo>().TimeDensity = newTimeDensity;
                // Fill in EffectiveTimeDensity for model1, density at height 1.8m
                List <float> newEfftiveTimeDensity = new List <float>();
                int          Width  = Mathf.RoundToInt(sceneDetails.Width);
                int          Length = Mathf.RoundToInt(sceneDetails.Length);
                int          Height = Mathf.RoundToInt(sceneDetails.Height);
                int          Time   = Mathf.RoundToInt(sceneDetails.SimTime);
                for (int i = 0; i < (Width + 1) * (Length + 1) * Time; i++)
                {
                    newEfftiveTimeDensity.Add(newTimeDensity[1 + i * Height]);
                }

                Scene.GetComponent <SceneInfo>().EffectiveTimeDensity = newEfftiveTimeDensity;
            }

            // 4.3.2 Create all the walls
            foreach (wall Wall in sceneDetails.Walls)
            {
                GameObject newWall  = Instantiate(Resources.Load <GameObject>("Prefabs/Wall"));
                Wall       wallinfo = newWall.GetComponent <Wall>();
                wallinfo.FillInfo(AllObjectsNames[Wall.NameIndex], Wall.xpos, Wall.ypos,
                                  Wall.zrot, Wall.Height, Wall.Width, Wall.Opacity);
                newWall.name = wallinfo.Name;
                newWall.transform.SetParent(Scene.transform);

                Vector3 Pos = newWall.transform.position;
                Pos.x = wallinfo.x_pos; Pos.y = wallinfo.Height / 2 + 0.01f; Pos.z = wallinfo.y_pos;
                newWall.transform.position = Pos;

                HEIGHT = wallinfo.Height;

                Vector3 Angles = newWall.transform.eulerAngles;
                Angles.y = wallinfo.z_rot;
                newWall.transform.eulerAngles = Angles;

                Vector3 Scale = newWall.transform.localScale;
                Scale.x = wallinfo.Width; Scale.y = wallinfo.Height;
                newWall.transform.localScale = Scale;

                Vector4 color = newWall.GetComponent <Renderer>().material.color;
                color[3] = wallinfo.Opacity;
                newWall.GetComponent <Renderer>().material.color = color;
            }

            // 4.3.3 Create all the floors
            foreach (floor Floor in sceneDetails.Floors)
            {
                GameObject newFloor  = Instantiate(Resources.Load <GameObject>("Prefabs/InPlayFloor"));
                Floor      floorinfo = newFloor.GetComponent <Floor>();
                floorinfo.FillInfo(AllObjectsNames[Floor.NameIndex], Floor.xpos, Floor.ypos, Floor.Length,
                                   Floor.Width);
                newFloor.name = floorinfo.Name;
                newFloor.transform.SetParent(Scene.transform);

                Vector3 Scale = newFloor.GetComponent <Terrain>().terrainData.size;
                Scale.x = floorinfo.Width; Scale.z = floorinfo.Length;
                newFloor.GetComponent <Terrain>().terrainData.size = Scale;
                WIDTH = floorinfo.Width; LENGTH = floorinfo.Length;

                Vector3 Pos = newFloor.transform.position;
                Pos.x = floorinfo.x_pos - (Scale.x / 2); Pos.z = floorinfo.y_pos - (Scale.z / 2);
                newFloor.transform.position = Pos;

                // Bake the floor
                newFloor.GetComponent <NavMeshLink>().startPoint = new Vector3(0, 0, 0);
                newFloor.GetComponent <NavMeshLink>().endPoint   = new Vector3(Scale.x, 0, Scale.z);
                newFloor.GetComponent <NavMeshSurface>().BuildNavMesh();
            }

            // ADD a light bulb to the scene
            GameObject lightbulb = new GameObject("Scene light");
            lightbulb.AddComponent <Light>();
            lightbulb.GetComponent <Light>().type = LightType.Point;
            lightbulb.transform.SetParent(Scene.transform);
            Vector3 ScenePos = Scene.transform.localPosition;
            lightbulb.transform.localPosition = new Vector3(ScenePos.x, HEIGHT - 0.1f, ScenePos.z);

            // 4.3.4 Create all the ceilings
            foreach (ceiling Ceiling in sceneDetails.Ceilings)
            {
                GameObject newCeiling  = Instantiate(Resources.Load <GameObject>("Prefabs/Ceiling"));
                Ceiling    ceilinginfo = newCeiling.GetComponent <Ceiling>();
                ceilinginfo.FillInfo(AllObjectsNames[Ceiling.NameIndex], Ceiling.xpos, Ceiling.ypos,
                                     Ceiling.zpos, Ceiling.Length, Ceiling.Width, Ceiling.Opacity);
                newCeiling.name = ceilinginfo.Name;
                newCeiling.transform.SetParent(Scene.transform);

                Vector3 Pos = newCeiling.transform.position;
                Pos.x = ceilinginfo.x_pos; Pos.y = ceilinginfo.z_pos; Pos.z = ceilinginfo.y_pos;
                newCeiling.transform.position = Pos;

                Vector3 Scale = newCeiling.transform.localScale;
                Scale.x = ceilinginfo.Width; Scale.z = ceilinginfo.Length;
                newCeiling.transform.localScale = Scale;
            }

            // 4.3.5 Create all the obstacles
            foreach (obstacle Obstacle in sceneDetails.Obstacles)
            {
                GameObject newObstacle  = Instantiate(Resources.Load <GameObject>("Prefabs/Obstacle"));
                Obstacle   obstacleinfo = newObstacle.GetComponent <Obstacle>();
                obstacleinfo.FillInfo(AllObjectsNames[Obstacle.NameIndex], Obstacle.xpos, Obstacle.ypos,
                                      Obstacle.Width, Obstacle.Length, Obstacle.Height, Obstacle.Opacity);
                newObstacle.name = obstacleinfo.Name;
                newObstacle.transform.SetParent(Scene.transform);

                Vector3 Pos = newObstacle.transform.position;
                Pos.x = obstacleinfo.x_pos; Pos.z = obstacleinfo.y_pos;
                newObstacle.transform.position = Pos;

                Vector3 Scale = newObstacle.transform.localScale;
                Scale.x = obstacleinfo.Width; Scale.y = obstacleinfo.Height; Scale.z = obstacleinfo.Length;
                newObstacle.transform.localScale = Scale;

                Vector4 color = newObstacle.GetComponent <Renderer>().material.color;
                color[3] = obstacleinfo.Opacity;
                newObstacle.GetComponent <Renderer>().material.color = color;
            }

            // 4.3.6 Create all the doors
            foreach (door Door in sceneDetails.Doors)
            {
                GameObject newDoor  = Instantiate(Resources.Load <GameObject>("Prefabs/Door"));
                Door       doorinfo = newDoor.GetComponent <Door>();

                // Fill in the values of variables in Door.cs
                doorinfo.Name           = AllObjectsNames[Door.NameIndex];
                doorinfo.WallAttachedTo = Scene.transform.Find(AllObjectsNames[Door.WallNameIndex]).gameObject;
                foreach (GameObject sceneobj in AllSceneObjects)
                {
                    if (sceneobj.name == AllObjectsNames[Door.SceneNameIndex])
                    {
                        doorinfo.NextScene = sceneobj;
                        break;
                    }
                }
                if (Door.Open == 1)
                {
                    doorinfo.Open = true;
                }
                else
                {
                    doorinfo.Open = false;
                }
                doorinfo.Width            = Door.Width;
                doorinfo.Height           = Door.Height;
                doorinfo.RelativePosition = Door.RelativePosition;

                // Create the door gameobject accordingly
                newDoor.name = doorinfo.Name;

                Transform WallTransform = doorinfo.WallAttachedTo.transform;
                newDoor.transform.SetParent(WallTransform);
                Vector3 WallPosition   = WallTransform.position;
                Vector3 WallDimensions = WallTransform.localScale;

                newDoor.transform.localEulerAngles = new Vector3(0, 0, 0); // angle

                float rel_x = doorinfo.RelativePosition / WallDimensions.x;
                float rel_y = ((doorinfo.Height / 2) - WallPosition.y) / WallDimensions.y;
                newDoor.transform.localPosition = new Vector3(rel_x, rel_y, 0); // pos

                newDoor.transform.localScale = new Vector3(doorinfo.Width / WallDimensions.x,
                                                           doorinfo.Height / WallDimensions.y, 1.033f); //scale
            }

            // 4.3.7 Create all the fires
            foreach (fire Fire in sceneDetails.Fires)
            {
                GameObject newFire  = Instantiate(Resources.Load <GameObject>("Prefabs/InPlayFire"));
                Fire       fireinfo = newFire.GetComponent <Fire>();

                fireinfo.FillInfo(AllObjectsNames[Fire.NameIndex], Fire.xpos, Fire.ypos, Fire.zpos, Fire.Width,
                                  Fire.Length, Fire.HRRPUA, Fire.CO_YIELD, Fire.SOOT_YIELD, fireinfo.Fuels[Fire.Fuel]);
                newFire.name = fireinfo.Name;
                newFire.transform.SetParent(Scene.transform);

                Vector3 Pos = newFire.transform.position;
                Pos.x = fireinfo.x_pos; Pos.y = fireinfo.z_pos; Pos.z = fireinfo.y_pos;
                newFire.transform.position = Pos;

                Vector3 Scale = newFire.transform.localScale;
                Scale.x = fireinfo.Width; Scale.z = fireinfo.Length;
                newFire.transform.localScale = Scale;
            }

            // 4.3.8 Create all the pedestrians
            foreach (pedestrian Pedestrian in sceneDetails.Pedestrians)
            {
                GameObject newPedestrian  = Instantiate(Resources.Load <GameObject>("Prefabs/Pedestrian"));
                Pedestrian pedestrianinfo = newPedestrian.GetComponent <Pedestrian>();

                Transform ExitTransform = null;
                foreach (Transform Object in Scene.transform)
                {
                    if (Object.tag == "Wall")
                    {
                        ExitTransform = Object.Find(AllObjectsNames[Pedestrian.ExitNameIndex]);
                        if (ExitTransform != null)
                        {
                            break;
                        }
                    }
                }
                pedestrianinfo.FillInfo(AllObjectsNames[Pedestrian.NameIndex], Pedestrian.xpos,
                                        Pedestrian.ypos, Pedestrian.Speed, Pedestrian.Health, ExitTransform.gameObject);
                newPedestrian.name = pedestrianinfo.Name;
                newPedestrian.transform.SetParent(Scene.transform);

                Vector3 Pos = newPedestrian.transform.position;
                Pos.x = pedestrianinfo.x_pos; Pos.z = pedestrianinfo.y_pos;
                newPedestrian.transform.position = Pos;

                newPedestrian.GetComponent <AICharacterControl>().target = ExitTransform;

                // For now, set agent's speed to be 0.45 ~ 1.5m/s
                newPedestrian.GetComponent <NavMeshAgent>().speed = 0.45f;
            }

            // 4.3.9 Create the player in InPlayScene, the speed is set to be 2 in
            // the inspector for now
            foreach (player Player in sceneDetails.Players)
            {
                GameObject newPlayer  = Instantiate(Resources.Load <GameObject>("Prefabs/Player"));
                Player     playerinfo = newPlayer.GetComponent <Player>();
                playerinfo.FillInfo(AllObjectsNames[Player.NameIndex], Player.xpos, Player.ypos,
                                    Player.Speed, Player.Health);
                newPlayer.name = playerinfo.Name;
                newPlayer.transform.SetParent(Scene.transform);

                Vector3 PlayerPos = newPlayer.transform.position;
                PlayerPos.x = sceneDetails.PlayerX; PlayerPos.z = sceneDetails.PlayerY;
                newPlayer.transform.position = PlayerPos;

                // Put the main camera on it
                GameObject maincamera = GameObject.FindGameObjectWithTag("MainCamera");
                maincamera.transform.SetParent(newPlayer.transform);
                maincamera.transform.localPosition = new Vector3(0, 0, 0);
            }

            // 5. Only activate the scene where the player is in
            if (sceneDetails.Players == null || sceneDetails.Players.Count == 0)
            {
                Scene.SetActive(false);
            }

            // temporary solution
            if (Scene.name == "Outside")
            {
                Scene.SetActive(false);
            }

            // 6. Create all the smoke particles (particle system)
            List <float> timedensity = Scene.GetComponent <SceneInfo>().TimeDensity;
            if (timedensity != null)
            {
                float d          = 1;
                float t          = 1;
                float T          = sceneDetails.SimTime;
                float maxdensity = Mathf.Max(timedensity.ToArray());
                int   xnumber    = (int)((WIDTH / d) + 1);
                int   ynumber    = (int)((LENGTH / d) + 1);
                int   znumber    = (int)((HEIGHT / d));
                int   tnumber    = (int)(T / t);
                for (int x = 0; x < xnumber; x++)
                {
                    for (int y = 0; y < ynumber; y++)
                    {
                        for (int z = 0; z < znumber; z++)
                        {
                            List <float> smokedensity = new List <float>();
                            for (int n = 0; n < tnumber; n++)
                            {
                                int index;
                                index = n * (xnumber * ynumber * znumber) +
                                        y * (xnumber * znumber) +
                                        x * znumber + z;
                                smokedensity.Add(timedensity[index]);
                            }
                            if (Mathf.Max(smokedensity.ToArray()) > (maxdensity / 10))
                            {
                                GameObject newSmoke = Instantiate(Resources.Load <GameObject>("Prefabs/Smoke"));
                                newSmoke.GetComponent <InPlaySmoke>().MaxDensity = maxdensity;
                                newSmoke.GetComponent <InPlaySmoke>().Density    = smokedensity;
                                newSmoke.transform.SetParent(Scene.transform);
                                newSmoke.transform.localPosition =
                                    new Vector3(-(WIDTH / 2) + x * d, 0.5f * d + z * d, -(LENGTH / 2) + y * d);
                            }
                        }
                    }
                }
            }

            // 7. Set currenttime to be 0
            currenttime = 0;
        }
    }
Example #4
0
    public void BuildAndPlayOnClick()
    {
        // 1. Set WorkingDirectory
        string WorkingDirectory = Application.persistentDataPath + "/" + ScenarioName.text;

        // 2. Get a string[] contains all the subdirectories in the scenario (all the scenes)
        DirectoryInfo dir = new DirectoryInfo(WorkingDirectory);

        DirectoryInfo[] subdirs = dir.GetDirectories();

        // 3. Go into each subdirectory to do the simulation
        foreach (DirectoryInfo subdir in subdirs)
        {
            // 4. Create fds input file
            WorkingDirectory = Application.persistentDataPath + "/" + ScenarioName.text + "/" + subdir.Name;
            // 4.1 Read in all object names
            List <string> AllObjectsNames = new List <string>();
            string        name;
            if (File.Exists(WorkingDirectory + "/AllNames.txt"))
            {
                StreamReader theReader = new StreamReader(WorkingDirectory + "/AllNames.txt");
                using (theReader)
                {
                    do
                    {
                        name = theReader.ReadLine();
                        if (name != null)
                        {
                            AllObjectsNames.Add(name);
                        }
                    }while (name != null);
                }
                theReader.Close();
            }
            // 4.2 Read in SceneInfo
            SceneDetails sceneDetails = new SceneDetails();
            if (File.Exists(WorkingDirectory + "/SceneDetails.dat"))
            {
                BinaryFormatter bf   = new BinaryFormatter();
                FileStream      file = File.Open(WorkingDirectory + "/SceneDetails.dat", FileMode.Open);
                sceneDetails = (SceneDetails)bf.Deserialize(file);
                file.Close();
            }
            // 4.3 Write the fds input file
            if (sceneDetails.SimTime != 0)
            {
                StreamWriter writer = new StreamWriter(WorkingDirectory + "/" + subdir.Name + ".fds");
                // 4.3.1 Write the header
                string HEAD_LINE = "&HEAD CHID='" + subdir.Name + "', TITLE='" + subdir.Name + "'/";
                writer.WriteLine(HEAD_LINE);
                // 4.3.2 Setup the dimensions.
                float FDS_x0; float FDS_x1; float FDS_y0; float FDS_y1; float FDS_z0; float FDS_z1;
                FDS_x0 = -sceneDetails.Width / 2;
                FDS_x1 = sceneDetails.Width / 2;
                FDS_y0 = -sceneDetails.Length / 2;
                FDS_y1 = sceneDetails.Width / 2;;
                FDS_z0 = 0;
                FDS_z1 = sceneDetails.Height;
                string XB = "XB=" + FDS_x0 + "," + FDS_x1 + "," + FDS_y0 + "," + FDS_y1 +
                            "," + FDS_z0 + "," + FDS_z1;
                float  MESH_I = FDS_x1 - FDS_x0; // Grid size set to 1
                float  MESH_J = FDS_y1 - FDS_y0;
                float  MESH_K = FDS_z1 - FDS_z0;
                string MESH   = "&MESH " + "IJK=" + MESH_I + "," + MESH_J + "," + MESH_K + ", " +
                                XB + "/";
                writer.WriteLine(MESH);
                // 4.3.3 Write simulation time in .fds
                string FDS_Time_Line = "&TIME T_END=" + sceneDetails.SimTime + "/";
                writer.WriteLine(FDS_Time_Line);

                // 4.3.4 Write all the obstacles in .fds
                float obs_x0; float obs_x1; float obs_y0; float obs_y1; float obs_z0; float obs_z1; string obs_line;
                foreach (obstacle OBSTACLE in sceneDetails.Obstacles)
                {
                    obs_x0   = OBSTACLE.xpos - (OBSTACLE.Width / 2);
                    obs_x1   = OBSTACLE.xpos + (OBSTACLE.Width / 2);
                    obs_y0   = OBSTACLE.ypos - (OBSTACLE.Length / 2);
                    obs_y1   = OBSTACLE.ypos + (OBSTACLE.Length / 2);
                    obs_z0   = 0;
                    obs_z1   = OBSTACLE.Height;
                    obs_line = "&OBST XB=" + obs_x0 + "," + obs_x1 + "," +
                               obs_y0 + "," + obs_y1 + "," +
                               obs_z0 + "," + obs_z1 + "/";
                    writer.WriteLine(obs_line);
                }

                // 4.3.5 Write fires in .fds
                float    fire_x0; float fire_x1; float fire_y0; float fire_y1; float fire_z; string fire_line;
                string[] Fuels = { "ACETONE",           "ACETYLENE",           "ACROLEIN",            "AMMONIA",          "ARGON",
                                   "BENZENE",           "BUTANE",
                                   "CARBON",            "CARBON DIOXIDE",      "CARBON MONOXIDE",     "CHLORINE",
                                   "DODECANE",
                                   "ETHANE",            "ETHANOL",             "ETHYLENE",
                                   "FORMALDEHYDE",
                                   "HELIUM",            "HYDROGEN",            "HYDROGEN ATOM",       "HYDROGEN BROMIDE",
                                   "HYDROGEN CHLORIDE", "HYDROGEN CYANIDE",    "HYDROGEN FLUORIDE",
                                   "HYDROGEN PEROXIDE", "HYDROPEROXY RADICAL", "HYDROXYL RADICAL",
                                   "ISOPROPANOL",
                                   "LJ AIR",
                                   "METHANE",           "METHANOL",
                                   "N-DECANE",          "N-HEPTANE",           "N-HEXANE",            "N-OCTANE",         "NITRIC OXIDE",
                                   "NITROGEN",          "NITROGEN ATOM",       "NITROGEN DIOXIDE",    "NITROUS OXIDE",
                                   "OXYGEN",            "OXYGEN ATOM",
                                   "PROPANE",           "PROPYLENE",
                                   "SOOT",              "SULFUR DDIOXIDE",     "SULFUR HEXAFLUORIDE",
                                   "TOLUENE",
                                   "WATER VAPOR" };
                foreach (fire FIRE in sceneDetails.Fires)
                {
                    // Write the reaction line
                    string REAC_line = "&REAC ID=" + "'" + AllObjectsNames[FIRE.NameIndex] + "'" + System.Environment.NewLine +
                                       "FUEL=" + "'" + Fuels[FIRE.Fuel] + "'" + System.Environment.NewLine +
                                       "CO_YIELD=" + FIRE.CO_YIELD + System.Environment.NewLine +
                                       "SOOT_YIELD=" + FIRE.CO_YIELD + "/";
                    writer.WriteLine(REAC_line);

                    // Set fire position and HRRPUA, for 'VENT' fire
                    // Write the surface line
                    string SURF_LINE = "&SURF ID=" + "'" + AllObjectsNames[FIRE.NameIndex] + "', " + "HRRPUA=" + FIRE.HRRPUA + "/";
                    writer.WriteLine(SURF_LINE);
                    // Write the vent line for "vent" fire
                    fire_x0 = FIRE.xpos - (FIRE.Width / 2);
                    fire_x1 = FIRE.xpos + (FIRE.Width / 2);
                    fire_y0 = FIRE.ypos - (FIRE.Length / 2);
                    fire_y1 = FIRE.ypos + (FIRE.Length / 2);
                    fire_z  = FIRE.zpos;
                    string FIRE_XB = "XB=" + fire_x0 + "," + fire_x1 + "," +
                                     fire_y0 + "," + fire_y1 + "," +
                                     fire_z + "," + fire_z;
                    string FIRE_VENT_LINE = "&VENT " + FIRE_XB + ", " + "SURF_ID=" + "'" + AllObjectsNames[FIRE.NameIndex] + "'/";
                    writer.WriteLine(FIRE_VENT_LINE);
                }

                // 4.3.6 Put in slices to be later used to extract soot density data
                string SLCF_line;
                int    num_of_slices = 0;

                for (float slice_z = FDS_z0 + 1;
                     slice_z < FDS_z1 + 0.5 * 1;
                     slice_z += 1)
                {
                    SLCF_line = "&SLCF PBZ=" + slice_z + ", " + "QUANTITY='DENSITY', SPEC_ID='SOOT'/";
                    writer.WriteLine(SLCF_line);
                    num_of_slices += 1;
                }

                // 4.3.7 End writing the FDS input file.
                writer.WriteLine("&TAIL/");
                writer.Close();

                // 5. Run the fds input file
                Process myProcess = new Process();
                myProcess.StartInfo.WindowStyle     = ProcessWindowStyle.Hidden;
                myProcess.StartInfo.CreateNoWindow  = true;
                myProcess.StartInfo.UseShellExecute = false;
                myProcess.StartInfo.FileName        = "cmd.exe";
                string cmdpath = WorkingDirectory.Replace("/", "\\");
                string path    = "/c" + "cd " + cmdpath + "& fds " + subdir.Name + ".fds";
                myProcess.StartInfo.Arguments = path;
                myProcess.EnableRaisingEvents = true;
                myProcess.Start();
                myProcess.WaitForExit();

                // 6. Extract useful data (smoke density) from fds output file, out it
                // into a matrix form and store it in a binary file
                string           head_name = subdir.Name;
                string           output_name;
                string           directory_location = WorkingDirectory.Replace("/", "\\");
                ProcessStartInfo startInfo          = new ProcessStartInfo();
                startInfo.CreateNoWindow        = true;
                startInfo.UseShellExecute       = false;
                startInfo.RedirectStandardInput = true;
                startInfo.FileName         = "cmd.exe";
                startInfo.WorkingDirectory = directory_location;
                //startInfo.WindowStyle = ProcessWindowStyle.Hidden;

                Process process = new Process();
                process.StartInfo = startInfo;

                process.Start();

                process.StandardInput.WriteLine("& md TimeDensity");

                // Loop to output n t_n.txt files. For the moment, time step is set to be TimeStep
                float time_index = 0; float timestep = 1; float simtime = sceneDetails.SimTime;
                while (time_index * timestep < simtime)
                {
                    process.StandardInput.WriteLine("fds2ascii");
                    process.StandardInput.WriteLine(head_name);
                    process.StandardInput.WriteLine("2");
                    process.StandardInput.WriteLine("1");
                    process.StandardInput.WriteLine("n");
                    if ((time_index + 1) * timestep <= simtime)
                    {
                        process.StandardInput.WriteLine(timestep * time_index + " " + timestep * (time_index + 1));
                    }
                    else
                    {
                        process.StandardInput.WriteLine(timestep * time_index + " " + simtime);
                    }
                    process.StandardInput.WriteLine(num_of_slices);

                    for (int i = 1; i <= num_of_slices; i += 1)
                    {
                        process.StandardInput.WriteLine(i);
                    }
                    output_name = "t" + time_index;
                    process.StandardInput.WriteLine(output_name);
                    process.StandardInput.WriteLine("MOVE " + output_name + " " + "TimeDensity");
                    time_index += 1;
                }
                process.StandardInput.WriteLine("exit");
                process.WaitForExit();

                // Summarize the result by putting it into a list, AllData (A).
                // A[a] = density(t,x,y,z) where:
                // let d be the grid length, T simulation time, ts time step
                // i be the number of points on x axis: i = x/d + 1 (eg. 0, 0.5, 1)
                // j be the number of points on y axis: j = y/d + 1
                // k be the number of points on z axis: k = z/d (eg 0.5, 1; no 0)
                // l be the number of time points: SimTime/TimeStep (0.5, 1.5, ... 29.5, SimTime = 30, TimeStep = 1)
                // =>
                // *** t = quotient(a, i*j*k) + 0.5ts
                // o = remainder(a, i*j*k)
                // *** y = y0 + quotient(o, i*k)*d ***
                // p = remainder(o, i*k)
                // *** x = x0 + quotient(p, k)*d ***
                // *** z = z0 + remainder(p, k)*d ***
                List <float> AllData = new List <float>();
                string[]     DataAtT;
                string       Data;
                StreamReader reader;
                if (Directory.Exists(WorkingDirectory + "/TimeDensity"))
                {
                    for (int n = 0; n < simtime / timestep; n++)
                    {
                        reader = new StreamReader(WorkingDirectory + "/TimeDensity/t" + n);
                        // Skip the first two lines
                        reader.ReadLine();
                        reader.ReadLine();
                        do
                        {
                            Data    = reader.ReadLine();
                            DataAtT = Data.Split(',', '\n');

                            for (int i = 2; i < DataAtT.Length; i++)
                            {
                                if (DataAtT[i] != "")
                                {
                                    AllData.Add(float.Parse(DataAtT[i]));
                                }
                            }
                        }while (!reader.EndOfStream);
                        reader.Close();
                    }
                }
                BinaryFormatter BF          = new BinaryFormatter();
                FileStream      alldatafile = File.Open(WorkingDirectory + "/TimeDensity/AllData.dat", FileMode.OpenOrCreate);
                BF.Serialize(alldatafile, AllData);
                alldatafile.Close();
            }
        }

        // Set ScenarioName in GeneralGameManager.cs
        ScenarioAtHand.ScenarioName = ScenarioName.text;
    }
 public void SetCurrentScene(SceneDetails currScene)
 {
     PrevScene    = CurrentScene;
     CurrentScene = currScene;
 }
Example #6
0
    public void InitializeScene(SceneDetails scene)
    {
        print(scene.name);
        _sm = scene;

        cameraHolder = cameraHolders[0];
        camListener  = camListeners[0];
        mainCam      = mainCams[0];
        camAnim      = camAnims[0];

        if (!sessionStarted)
        {
            if (StateManager.instance.playerSpawner == "")
            {
                characterSpawnerName = _sm.spawner;
            }
            sessionStarted = true;
        }
        startCampfire = GameObject.Find(characterSpawnerName).GetComponent <CampfireController>();

        playerController.playerHealth.SetHealth(StateManager.instance.playerHealth);
        gui.SetHealth();

        Time.timeScale = 1;

        canvasContainer.map.LoadMap(_sm.mapName);
        if (_sm.mapName != "")
        {
            canvasContainer.map.SetPlayerPosition(SceneManager.GetActiveScene().name);
        }

        PlayerSetPos();

        NpcToInteract(null, "Inspect");

        //        print("events");
        bool cs = false;

        if (_sm.introCutScene != null) // play scene intro cutScene
        {
            if (_sm.introCutScene.gameObject.activeSelf && _sm.introCutScene.playOnStartOfScene)
            {
                gui.InstantBlack();
                _sm.introCutScene.StartCs();
                cs = true;
            }
        }

        // SEND MESSAGES ON START OF SCENE

        /*
         *      for (int i = StateManager.instance.messages.Count - 1; i > -1; i --)
         *      {
         *          for (int j = statefulObjectsOnscene.Count - 1; j > -1; j--)
         *          {
         *              if (StateManager.instance.messages[i] == statefulObjectsOnscene[j].name)
         *              {
         *                  MessageReciever msg = statefulObjectsOnscene[j].gameObject.GetComponent<MessageReciever>();
         *                  msg.GetMessage();
         *                  if (msg.csToStart)
         *                      cs = true;
         *                  StateManager.instance.RemoveMessage(StateManager.instance.messages[i]);
         *              }
         *          }
         *      }
         */

        List <string> messengersNames = new List <string>();

        foreach (string m in StateManager.instance.messages.ToList())
        {
            //print (m);
            foreach (Stateful s in statefulObjectsOnscene)
            {
                //print (s);
                if (m == s.name)
                {
                    MessageReciever msg = s.gameObject.GetComponent <MessageReciever>();
                    msg.GetMessage();
                    //print (msg);
                    messengersNames.Add(m);
                    if (msg.csToStart)
                    {
                        cs = true;
                    }
                }
            }
        }

        foreach (string n in messengersNames)
        {
            StateManager.instance.RemoveMessage(n);
        }
        /////////////

        if (!cs)
        {
            gui.Fade("Game");
        }
        mainCam.backgroundColor = RenderSettings.fogColor;

        SetActiveWeapon(StateManager.instance.activeWeapon);

        playerController.SetFlashlight(StateManager.instance.GetFlashlight());
        playerController.playerHealth.health = StateManager.instance.playerHealth;
    }
    public void Save()
    {
        // 1. Get the SaveName;
        string scenarioName = ScenarioName.text;

        // 2. Get all the existing scenes from gamemanager.
        List <GameObject> AllScenes = null;

        if (gamemanager.name == "DesignSceneGameManager")
        {
            AllScenes = gamemanager.GetComponent <DesignSceneGameManager>().AllScenes;
        }

        // 3. Create a folder named with savename.
        WorkingDirectory = Application.persistentDataPath + "/" + scenarioName;
        // If there already exists a scenario with scenarioName, replace it with the new one. Therefore,
        // users should make sure not to use the same scenario name
        if (Directory.Exists(WorkingDirectory))
        {
            Directory.Delete(WorkingDirectory, true);
        }
        Directory.CreateDirectory(WorkingDirectory);

        // 4. For each scene, do the followings
        foreach (GameObject Scene in AllScenes)
        {
            // 4.1 create a sub-folder with the scenarioName name
            WorkingDirectory = Application.persistentDataPath + "/" + scenarioName + "/" + Scene.name;
            Directory.CreateDirectory(WorkingDirectory);

            // 4.2 create a list to store all the names of the objects
            List <string> AllObjectNames = new List <string>();

            // 4.3 Fill in the class SceneDetails according to the design of the scene
            SceneDetails sceneDetails = new SceneDetails();
            sceneDetails.Walls       = new List <wall>();
            sceneDetails.Floors      = new List <floor>();
            sceneDetails.Ceilings    = new List <ceiling>();
            sceneDetails.Obstacles   = new List <obstacle>();
            sceneDetails.Doors       = new List <door>();
            sceneDetails.Fires       = new List <fire>();
            sceneDetails.Pedestrians = new List <pedestrian>();
            sceneDetails.Players     = new List <player>();
            // 4.3.1 Fill in the simulation info
            sceneDetails.SimTime = Scene.GetComponent <SceneInfo>().SimulationTime;
            sceneDetails.Width   = Scene.GetComponent <SceneInfo>().Width;
            sceneDetails.Length  = Scene.GetComponent <SceneInfo>().Length;
            sceneDetails.Height  = Scene.GetComponent <SceneInfo>().Height;
            sceneDetails.PlayerX = Scene.GetComponent <SceneInfo>().PlayerX;
            sceneDetails.PlayerY = Scene.GetComponent <SceneInfo>().PlayerY;
            // 4.3.2 fill in the info of different objects into sceneDetails
            foreach (Transform ChildObjectTransform in Scene.transform)
            {
                // Wall and its doors
                if (ChildObjectTransform.tag == "Wall")
                {
                    wall WallInfo = new wall();
                    Wall wallinfo = ChildObjectTransform.gameObject.GetComponent <Wall>();
                    AllObjectNames.Add(wallinfo.Name);
                    WallInfo.NameIndex = AllObjectNames.Count - 1;
                    WallInfo.xpos      = wallinfo.x_pos;
                    WallInfo.ypos      = wallinfo.y_pos;
                    WallInfo.zrot      = wallinfo.z_rot;
                    WallInfo.Width     = wallinfo.Width;
                    WallInfo.Height    = wallinfo.Height;
                    WallInfo.Opacity   = wallinfo.Opacity;
                    sceneDetails.Walls.Add(WallInfo);

                    // doors that are attached to it
                    foreach (Transform doorTransform in ChildObjectTransform)
                    {
                        if (doorTransform.tag == "Door")
                        {
                            door DoorInfo = new door();
                            Door doorinfo = doorTransform.gameObject.GetComponent <Door>();
                            AllObjectNames.Add(doorinfo.Name);
                            DoorInfo.NameIndex        = AllObjectNames.Count - 1;
                            DoorInfo.RelativePosition = doorinfo.RelativePosition;
                            DoorInfo.Width            = doorinfo.Width;
                            DoorInfo.Height           = doorinfo.Height;
                            if (doorinfo.Open)
                            {
                                DoorInfo.Open = 1;
                            }
                            else
                            {
                                DoorInfo.Open = 0;
                            }
                            DoorInfo.WallNameIndex = WallInfo.NameIndex;
                            AllObjectNames.Add(doorinfo.NextScene.name);
                            DoorInfo.SceneNameIndex = AllObjectNames.Count - 1;
                            sceneDetails.Doors.Add(DoorInfo);
                        }
                    }
                }
                // Floor
                else if (ChildObjectTransform.tag == "Floor")
                {
                    floor FloorInfo = new floor();
                    Floor floorinfo = ChildObjectTransform.gameObject.GetComponent <Floor>();
                    AllObjectNames.Add(floorinfo.Name);
                    FloorInfo.NameIndex = AllObjectNames.Count - 1;
                    FloorInfo.xpos      = floorinfo.x_pos;
                    FloorInfo.ypos      = floorinfo.y_pos;
                    FloorInfo.Width     = floorinfo.Width;
                    FloorInfo.Length    = floorinfo.Length;
                    sceneDetails.Floors.Add(FloorInfo);
                }
                // Ceiling
                else if (ChildObjectTransform.tag == "Ceiling")
                {
                    ceiling CeilingInfo = new ceiling();
                    Ceiling ceilinginfo = ChildObjectTransform.gameObject.GetComponent <Ceiling>();
                    AllObjectNames.Add(ceilinginfo.Name);
                    CeilingInfo.NameIndex = AllObjectNames.Count - 1;
                    CeilingInfo.xpos      = ceilinginfo.x_pos;
                    CeilingInfo.ypos      = ceilinginfo.y_pos;
                    CeilingInfo.zpos      = ceilinginfo.z_pos;
                    CeilingInfo.Width     = ceilinginfo.Width;
                    CeilingInfo.Length    = ceilinginfo.Length;
                    CeilingInfo.Opacity   = ceilinginfo.Opacity;
                    sceneDetails.Ceilings.Add(CeilingInfo);
                }
                // Obstacle
                else if (ChildObjectTransform.tag == "Obstacle")
                {
                    obstacle ObstacleInfo = new obstacle();
                    Obstacle obstacleinfo = ChildObjectTransform.gameObject.GetComponent <Obstacle>();
                    AllObjectNames.Add(obstacleinfo.Name);
                    ObstacleInfo.NameIndex = AllObjectNames.Count - 1;
                    ObstacleInfo.xpos      = obstacleinfo.x_pos;
                    ObstacleInfo.ypos      = obstacleinfo.y_pos;
                    ObstacleInfo.Width     = obstacleinfo.Width;
                    ObstacleInfo.Length    = obstacleinfo.Length;
                    ObstacleInfo.Height    = obstacleinfo.Height;
                    ObstacleInfo.Opacity   = obstacleinfo.Opacity;
                    sceneDetails.Obstacles.Add(ObstacleInfo);
                }
                // Fire
                else if (ChildObjectTransform.tag == "Fire")
                {
                    fire FireInfo = new fire();
                    Fire fireinfo = ChildObjectTransform.gameObject.GetComponent <Fire>();
                    AllObjectNames.Add(fireinfo.Name);
                    FireInfo.NameIndex  = AllObjectNames.Count - 1;
                    FireInfo.xpos       = fireinfo.x_pos;
                    FireInfo.ypos       = fireinfo.y_pos;
                    FireInfo.zpos       = fireinfo.z_pos;
                    FireInfo.Width      = fireinfo.Width;
                    FireInfo.Length     = fireinfo.Length;
                    FireInfo.HRRPUA     = fireinfo.HRRPUA;
                    FireInfo.CO_YIELD   = fireinfo.CO_YIELD;
                    FireInfo.SOOT_YIELD = fireinfo.SOOT_YIELD;
                    FireInfo.Fuel       = Array.IndexOf(fireinfo.Fuels,
                                                        fireinfo.FUEL);
                    sceneDetails.Fires.Add(FireInfo);
                }
                // Pedestrian
                else if (ChildObjectTransform.tag == "Pedestrian")
                {
                    pedestrian PedestrianInfo = new pedestrian();
                    Pedestrian pedestrianinfo = ChildObjectTransform.gameObject.GetComponent <Pedestrian>();
                    AllObjectNames.Add(pedestrianinfo.Name);
                    PedestrianInfo.NameIndex = AllObjectNames.Count - 1;
                    PedestrianInfo.xpos      = pedestrianinfo.x_pos;
                    PedestrianInfo.ypos      = pedestrianinfo.y_pos;
                    PedestrianInfo.Speed     = pedestrianinfo.Speed;
                    PedestrianInfo.Health    = pedestrianinfo.Health;
                    AllObjectNames.Add(pedestrianinfo.Exit.name);
                    PedestrianInfo.ExitNameIndex = AllObjectNames.Count - 1;
                    sceneDetails.Pedestrians.Add(PedestrianInfo);
                }
                else if (ChildObjectTransform.tag == "Player")
                {
                    player PlayerInfo = new player();
                    Player playerinfo = ChildObjectTransform.gameObject.GetComponent <Player>();
                    AllObjectNames.Add(playerinfo.Name);
                    PlayerInfo.NameIndex = AllObjectNames.Count - 1;
                    PlayerInfo.xpos      = playerinfo.x_pos;
                    PlayerInfo.ypos      = playerinfo.y_pos;
                    PlayerInfo.Speed     = playerinfo.Speed;
                    PlayerInfo.Health    = playerinfo.Health;
                    sceneDetails.Players.Add(PlayerInfo);
                }
            }

            // 4.4 Save AllObjectNames into a text file
            StreamWriter NamesTxtFile = new StreamWriter(WorkingDirectory + "/AllNames.txt");
            foreach (string name in AllObjectNames)
            {
                NamesTxtFile.WriteLine(name);
            }
            NamesTxtFile.Close();

            // 4.5 Save sceneDetails into a binary file, SceneDetails.dat
            BinaryFormatter bf   = new BinaryFormatter();
            FileStream      file = File.Open(WorkingDirectory + "/SceneDetails.dat", FileMode.OpenOrCreate);
            bf.Serialize(file, sceneDetails);
            file.Close();
        }
    }
    // Method LoadOnClick() only bring back the stored objects. Extra steps need to be taken to recover to design scene
    // and game scene accordingly.
    public void Load()
    {
        // 1. Set WorkingDirectory
        WorkingDirectory = Application.persistentDataPath + "/" + ScenarioName.text;

        // 2. Get a List<string> contains all the subdirectories in the scenario (all the scenes)
        DirectoryInfo dir = new DirectoryInfo(WorkingDirectory);

        DirectoryInfo[] subdirs   = dir.GetDirectories();
        List <string>   AllScenes = new List <string>();

        foreach (DirectoryInfo subdir in subdirs)
        {
            AllScenes.Add(subdir.Name);
        }

        // 3. For each scene, create a scene object and put it in AllSceneObjects
        List <GameObject> AllSceneObjects = new List <GameObject>();

        foreach (string Scene in AllScenes)
        {
            GameObject scene = new GameObject(Scene);
            scene.tag = "Scene";
            scene.transform.position = new Vector3(0, 0, 0);
            scene.AddComponent <SceneInfo>();
            AllSceneObjects.Add(scene);
        }

        // 4. For each scene, load the stored data
        foreach (GameObject Scene in AllSceneObjects)
        {
            WorkingDirectory = Application.persistentDataPath + "/" + ScenarioName.text + "/" + Scene.name;
            List <string> AllObjectsNames = new List <string>();

            // 4.1 read all the names from the AllNames.txt file.
            if (File.Exists(WorkingDirectory + "/AllNames.txt"))
            {
                string       name;
                StreamReader theReader = new StreamReader(WorkingDirectory + "/AllNames.txt");
                using (theReader)
                {
                    do
                    {
                        name = theReader.ReadLine();
                        if (name != null)
                        {
                            AllObjectsNames.Add(name);
                        }
                    }while (name != null);
                }
                theReader.Close();
            }

            // 4.2 read in all the details into sceneDetails (SceneDetails)
            SceneDetails sceneDetails = new SceneDetails();
            if (File.Exists(WorkingDirectory + "/SceneDetails.dat"))
            {
                BinaryFormatter bf   = new BinaryFormatter();
                FileStream      file = File.Open(WorkingDirectory + "/SceneDetails.dat", FileMode.Open);
                sceneDetails = (SceneDetails)bf.Deserialize(file);
                file.Close();
            }

            // 4.3 Recover the scene based on sceneDetails
            // 4.3.1 Fill in sim info. If it is in design scene, then need AddComponent<AssociatedButton>() as well.
            Scene.GetComponent <SceneInfo>().SimulationTime = sceneDetails.SimTime;
            Scene.GetComponent <SceneInfo>().Width          = sceneDetails.Width;
            Scene.GetComponent <SceneInfo>().Length         = sceneDetails.Length;
            Scene.GetComponent <SceneInfo>().Height         = sceneDetails.Height;
            Scene.GetComponent <SceneInfo>().PlayerX        = sceneDetails.PlayerX;
            Scene.GetComponent <SceneInfo>().PlayerY        = sceneDetails.PlayerY;

            // 4.3.2 Create all the walls
            foreach (wall Wall in sceneDetails.Walls)
            {
                GameObject newWall  = Instantiate(Resources.Load <GameObject>("Prefabs/Wall"));
                Wall       wallinfo = newWall.GetComponent <Wall>();
                wallinfo.FillInfo(AllObjectsNames[Wall.NameIndex], Wall.xpos, Wall.ypos,
                                  Wall.zrot, Wall.Height, Wall.Width, Wall.Opacity);
                newWall.name = wallinfo.Name;
                newWall.transform.SetParent(Scene.transform);

                Vector3 Pos = newWall.transform.position;
                Pos.x = wallinfo.x_pos; Pos.y = wallinfo.Height / 2; Pos.z = wallinfo.y_pos;
                newWall.transform.position = Pos;

                Vector3 Angles = newWall.transform.eulerAngles;
                Angles.y = wallinfo.z_rot;
                newWall.transform.eulerAngles = Angles;

                Vector3 Scale = newWall.transform.localScale;
                Scale.x = wallinfo.Width; Scale.y = wallinfo.Height;
                newWall.transform.localScale = Scale;

                Vector4 color = newWall.GetComponent <Renderer>().material.color;
                color[3] = wallinfo.Opacity;
                newWall.GetComponent <Renderer>().material.color = color;
            }

            // 4.3.3 Create all the floors
            foreach (floor Floor in sceneDetails.Floors)
            {
                GameObject newFloor  = Instantiate(Resources.Load <GameObject>("Prefabs/Floor"));
                Floor      floorinfo = newFloor.GetComponent <Floor>();
                floorinfo.FillInfo(AllObjectsNames[Floor.NameIndex], Floor.xpos, Floor.ypos, Floor.Length,
                                   Floor.Width);
                newFloor.name = floorinfo.Name;
                newFloor.transform.SetParent(Scene.transform);

                Vector3 Pos = newFloor.transform.position;
                Pos.x = floorinfo.x_pos; Pos.z = floorinfo.y_pos;
                newFloor.transform.position = Pos;

                Vector3 Scale = newFloor.transform.localScale;
                Scale.x = floorinfo.Width; Scale.z = floorinfo.Length;
                newFloor.transform.localScale = Scale;
            }

            // 4.3.4 Create all the ceilings
            foreach (ceiling Ceiling in sceneDetails.Ceilings)
            {
                GameObject newCeiling  = Instantiate(Resources.Load <GameObject>("Prefabs/Ceiling"));
                Ceiling    ceilinginfo = newCeiling.GetComponent <Ceiling>();
                ceilinginfo.FillInfo(AllObjectsNames[Ceiling.NameIndex], Ceiling.xpos, Ceiling.ypos,
                                     Ceiling.zpos, Ceiling.Length, Ceiling.Width, Ceiling.Opacity);
                newCeiling.name = ceilinginfo.Name;
                newCeiling.transform.SetParent(Scene.transform);

                Vector3 Pos = newCeiling.transform.position;
                Pos.x = ceilinginfo.x_pos; Pos.y = ceilinginfo.z_pos; Pos.z = ceilinginfo.y_pos;
                newCeiling.transform.position = Pos;

                Vector3 Scale = newCeiling.transform.localScale;
                Scale.x = ceilinginfo.Width; Scale.z = ceilinginfo.Length;
                newCeiling.transform.localScale = Scale;

                Vector4 color = newCeiling.GetComponent <Renderer>().material.color;
                color[3] = ceilinginfo.Opacity;
                newCeiling.GetComponent <Renderer>().material.color = color;
            }

            // 4.3.5 Create all the obstacles
            foreach (obstacle Obstacle in sceneDetails.Obstacles)
            {
                GameObject newObstacle  = Instantiate(Resources.Load <GameObject>("Prefabs/Obstacle"));
                Obstacle   obstacleinfo = newObstacle.GetComponent <Obstacle>();
                obstacleinfo.FillInfo(AllObjectsNames[Obstacle.NameIndex], Obstacle.xpos, Obstacle.ypos,
                                      Obstacle.Width, Obstacle.Length, Obstacle.Height, Obstacle.Opacity);
                newObstacle.name = obstacleinfo.Name;
                newObstacle.transform.SetParent(Scene.transform);

                Vector3 Pos = newObstacle.transform.position;
                Pos.x = obstacleinfo.x_pos; Pos.z = obstacleinfo.y_pos;
                newObstacle.transform.position = Pos;

                Vector3 Scale = newObstacle.transform.localScale;
                Scale.x = obstacleinfo.Width; Scale.y = obstacleinfo.Height;  Scale.z = obstacleinfo.Length;
                newObstacle.transform.localScale = Scale;

                Vector4 color = newObstacle.GetComponent <Renderer>().material.color;
                color[3] = obstacleinfo.Opacity;
                newObstacle.GetComponent <Renderer>().material.color = color;
            }

            // 4.3.6 Create all the doors
            foreach (door Door in sceneDetails.Doors)
            {
                GameObject newDoor  = Instantiate(Resources.Load <GameObject>("Prefabs/Door"));
                Door       doorinfo = newDoor.GetComponent <Door>();

                // Fill in the values of variables in Door.cs
                doorinfo.Name           = AllObjectsNames[Door.NameIndex];
                doorinfo.WallAttachedTo = Scene.transform.Find(AllObjectsNames[Door.WallNameIndex]).gameObject;
                foreach (GameObject sceneobj in AllSceneObjects)
                {
                    if (sceneobj.name == AllObjectsNames[Door.SceneNameIndex])
                    {
                        doorinfo.NextScene = sceneobj;
                        break;
                    }
                }
                if (Door.Open == 1)
                {
                    doorinfo.Open = true;
                }
                else
                {
                    doorinfo.Open = false;
                }
                doorinfo.Width            = Door.Width;
                doorinfo.Height           = Door.Height;
                doorinfo.RelativePosition = Door.RelativePosition;

                // Create the door gameobject accordingly
                newDoor.name = doorinfo.Name;

                Transform WallTransform = doorinfo.WallAttachedTo.transform;
                newDoor.transform.SetParent(WallTransform);
                Vector3 WallPosition   = WallTransform.position;
                Vector3 WallDimensions = WallTransform.localScale;

                newDoor.transform.localEulerAngles = new Vector3(0, 0, 0); // angle

                float rel_x = doorinfo.RelativePosition / WallDimensions.x;
                float rel_y = ((doorinfo.Height / 2) - WallPosition.y) / WallDimensions.y;
                newDoor.transform.localPosition = new Vector3(rel_x, rel_y, 0); // pos

                newDoor.transform.localScale = new Vector3(doorinfo.Width / WallDimensions.x,
                                                           doorinfo.Height / WallDimensions.y, 1.033f); //scale
            }

            // 4.3.7 Create all the fires
            foreach (fire Fire in sceneDetails.Fires)
            {
                GameObject newFire  = Instantiate(Resources.Load <GameObject>("Prefabs/Fire"));
                Fire       fireinfo = newFire.GetComponent <Fire>();

                fireinfo.FillInfo(AllObjectsNames[Fire.NameIndex], Fire.xpos, Fire.ypos, Fire.zpos, Fire.Width,
                                  Fire.Length, Fire.HRRPUA, Fire.CO_YIELD, Fire.SOOT_YIELD, fireinfo.Fuels[Fire.Fuel]);
                newFire.name = fireinfo.Name;
                newFire.transform.SetParent(Scene.transform);

                Vector3 Pos = newFire.transform.position;
                Pos.x = fireinfo.x_pos; Pos.y = fireinfo.z_pos; Pos.z = fireinfo.y_pos;
                newFire.transform.position = Pos;

                Vector3 Scale = newFire.transform.localScale;
                Scale.x = fireinfo.Width; Scale.z = fireinfo.Length;
                newFire.transform.localScale = Scale;
            }

            // 4.3.8 Create all the pedestrians
            foreach (pedestrian Pedestrian in sceneDetails.Pedestrians)
            {
                GameObject newPedestrian  = Instantiate(Resources.Load <GameObject>("Prefabs/DesignScenePedestrian"));
                Pedestrian pedestrianinfo = newPedestrian.GetComponent <Pedestrian>();

                Transform ExitTransform = null;
                foreach (Transform Object in Scene.transform)
                {
                    if (Object.tag == "Wall")
                    {
                        ExitTransform = Object.Find(AllObjectsNames[Pedestrian.ExitNameIndex]);
                        if (ExitTransform != null)
                        {
                            break;
                        }
                    }
                }
                pedestrianinfo.FillInfo(AllObjectsNames[Pedestrian.NameIndex], Pedestrian.xpos,
                                        Pedestrian.ypos, Pedestrian.Speed, Pedestrian.Health, ExitTransform.gameObject);
                newPedestrian.name = pedestrianinfo.Name;
                newPedestrian.transform.SetParent(Scene.transform);

                Vector3 Pos = newPedestrian.transform.position;
                Pos.x = pedestrianinfo.x_pos; Pos.z = pedestrianinfo.y_pos;
                newPedestrian.transform.position = Pos;
            }

            // 4.3.9 Create the player
            if (sceneDetails.Players != null)
            {
                foreach (player Player in sceneDetails.Players)
                {
                    GameObject newPlayer  = Instantiate(Resources.Load <GameObject>("Prefabs/DesignScenePlayer"));
                    Player     playerinfo = newPlayer.GetComponent <Player>();
                    playerinfo.FillInfo(AllObjectsNames[Player.NameIndex], Player.xpos, Player.ypos,
                                        Player.Speed, Player.Health);
                    newPlayer.name = playerinfo.Name;
                    newPlayer.transform.SetParent(Scene.transform);

                    Vector3 PlayerPos = newPlayer.transform.position;
                    PlayerPos.x = playerinfo.x_pos; PlayerPos.z = playerinfo.y_pos;
                    newPlayer.transform.position = PlayerPos;
                }
            }
        }
    }