예제 #1
0
    // we might want to change out the start function with the constructor, as this is not a monobehavior
    // Start will generate the origin room, but will not create the models for it's rooms.
    // This requires that minSize and maxSize are defined.
    public void Start(GameObject prefab)
    {
        PathSize = minSize + (int)(Random.value * (maxSize - minSize));

        map           = new List <WRoom>();
        roomLocations = new List <Vector3>();
        Center        = Vector3.zero;
        Location      = Center;
        direction     = Dir.north;
        RoomPrefab    = prefab;
        //Debug.Log(RoomPrefab);
        RoomPrefab.transform.localScale = new Vector3(roomWidth / 2.0f, 0.05f, roomWidth / 2.0f);
        //generate room 1
        WRoom origin = new WRoom(RoomPrefab)
        {
            Location = Location
        };

        //To force it to load it's model into memory, we need to call WRoom.Start(). Only need to use this if we require the floor to be used.
        //origin.Start();
        //add the location of the room to our list of locations.
        roomLocations.Add(origin.Location);
        //add the room to our map, which is just a list of rooms.
        map.Add(origin);
        //make sure the walker functionality knows where it came from.
        lastVisitedRoom = origin;
    }
예제 #2
0
    /// <summary>
    /// Sets the target room object the player is currently in. sets null if the player is not in a room in the floor.
    /// </summary>
    /// <returns></returns>
    private void GetRoomPlayerIsIn()
    {
        target = null;
        //find the room the player is over.
        RaycastHit hit;

        if (Physics.Raycast(playerObject.transform.position + playerObject.transform.up / 2.0f, -playerObject.transform.up, out hit, Mathf.Infinity, 1 << 8))
        {
            //make a target room and make it the same room the player is in.
            target = myfloor.map[0];
            foreach (WRoom o in myfloor.map)
            {
                //o.SetVisionColor(UnvisibleColor);
                //o.SetActive(false);
                if (o.model == null)
                {
                    continue;
                }
                if (hit.transform.position == o.model.transform.position)
                {
                    //this is the room the player is in.
                    target = o;
                }
            }
        }
    }
예제 #3
0
        public void ImportFromDae()
        {
            if (m_CollisionMesh == null)
            {
                MessageBox.Show("You must select a room before you can import collision for it.", "No collision mesh selected");
                return;
            }

            var ofd = new CommonOpenFileDialog()
            {
                Title            = "Import DAE",
                DefaultExtension = "dae",
            };

            ofd.Filters.Add(new CommonFileDialogFilter("Collada", ".dae"));
            if (WSettingsManager.GetSettings().LastCollisionDaePath.FilePath != "")
            {
                ofd.InitialDirectory = WSettingsManager.GetSettings().LastCollisionDaePath.FilePath;
            }

            if (ofd.ShowDialog() == CommonFileDialogResult.Ok)
            {
                WRoom currRoom = World.Map.FocusedScene as WRoom;
                m_CollisionMesh.FromDAEFile(ofd.FileName, currRoom.RoomIndex);

                m_CollisionTree.ItemsSource = new ObservableCollection <CollisionGroupNode>()
                {
                    ActiveCollisionMesh.RootNode
                };

                WSettingsManager.GetSettings().LastCollisionDaePath.FilePath = Path.GetDirectoryName(ofd.FileName);
                WSettingsManager.SaveSettings();
            }
        }
예제 #4
0
    /// <summary>
    /// randomly place an object "o"s position within the constraints of the room "rm" given
    /// </summary>
    /// <param name="o"></param>
    /// <param name="rm"></param>
    private void RandomPlace(GameObject o, WRoom rm)
    {
        float   width = 0.8f;
        Vector3 cen = rm.Location, right = Vector3.right, forward = Vector3.forward;
        float   dx = (Random.value * width - width / 2.0f); //-0.4 to 0.4
        float   dz = (Random.value * width - width / 2.0f); //-0.4 to 0.4

        o.transform.position = cen + RoomWidth * (dx * right + dz * forward);
    }
예제 #5
0
 public void CreateConnection(WRoom other, Dir connection)
 {
     // if the requested connection direction is empty, fill it
     if (connections[(int)connection] == null)
     {
         connections[(int)connection] = other;
     }
     else
     {
         //Debug.Log("WRoom.CreateConnection was given a location with a previous connection, ignoring.");
     }
 }
예제 #6
0
    /*
     * Function for Path Creation(Floor Object)
     * If Floor Object’s Size of Floor is less than Path Size
     * From Current Position
     *  Choose One
     *  -Go Right
     *      Change Direction right by 90 degrees
     *      Move Forward
     *  -Go Left
     *      Change Direction left by 90 degrees
     *      Move Forward
     *  -Go Forward
     *      Move Forward
     *  Add 1 to Size of Floor
     *  Add Room at Current Position with Orientation and connection opposite of orientation
     */

    /// <summary>
    /// Call to create room objects in our map. The map doesn't necessitate that we need a model yet.
    /// Moves the walker one step in a random direction, generating a room if necessary
    /// </summary>
    public void CreatePath()
    {
        if (FloorSize < PathSize)
        {
            //obtain a new direction that can be anything but the direction we came from
            direction = (Dir)(((int)direction + ((int)(Random.value * 3) % 3) + 3) % 4);  // takes a random 0.0 - 1.0 value, multiplies by 3, then makes sure it lies within 0-2, and drops it by 1 (then adds 4 to prevent negatives.).
            //make sure that the lastvisitedroom reflects the room we were on before moving away.
            lastVisitedRoom = map[roomLocations.IndexOf(Location)];
            MoveForward(direction);
            // if there is no room here, make one, else establish a connection if there is not one.
            if (roomLocations.IndexOf(Location) == -1)
            {
                //make the room
                WRoom obj = new WRoom(RoomPrefab);
                obj.ThemePath = ThemePath;
                //make the room exist at this location
                obj.Location = Location;
                //add the room to our list, and add the location to our list.
                roomLocations.Add(obj.Location);
                map.Add(obj);

                //add a connection from this room to the previous room and vice-versa
                //Debug.Log("1.   lastvisited adds other");
                lastVisitedRoom.CreateConnection(obj, direction);
                //Debug.Log("1.   other adds lastvisited");
                obj.CreateConnection(lastVisitedRoom, (Dir)(((int)direction + 2) % 4));
                //Debug.Log("1. done, " + dit);
                FloorSize += 1;
            }
            else  // there is a room at this location, give the room a connection to the previous room (if there wasn't one before. wroom handles for that)
            {
                WRoom obj = map[roomLocations.IndexOf(Location)];
                //add a connection from this room to the previous room and vice-versa
                //Debug.Log("2.   lastvisited adds other");
                lastVisitedRoom.CreateConnection(obj, direction);
                //Debug.Log("2.   other adds lastvisited");
                obj.CreateConnection(lastVisitedRoom, (Dir)(((int)direction + 2) % 4));
                //Debug.Log("2. done, " +dit);
            }
        }
        else
        {
            //Debug.Log("CreatePath: requested to create a path when floorsize equals or exceeds PathSize. No more rooms to make.");
            return;
        }
    }
예제 #7
0
 //called when the scene loads.
 // instantiates the dungeon's first floor, no rooms, no models.
 void Start()
 {
     //GetStatsFromSave();
     CurrentFloor      = -1;
     second            = (int)Time.time;
     myfloor           = new WFloor();
     target            = null;
     myfloor.Yoffset   = -20 * (CurrentFloor + 1);
     myfloor.roomWidth = RoomWidth;
     myfloor.minSize   = MinRooms;
     myfloor.maxSize   = MaxRooms;
     myfloor.ThemePath = ThemePath;
     myfloor.Start(roomprefab);
     //
     //generate the floor's first room, without it's model.
     GenerateNext();
     started             = false;
     playerHasBeenPlaced = false;
     ProceedButton       = GameObject.Instantiate(Resources.Load <GameObject>("CanvasButtonObject"), Vector3.zero, Quaternion.identity, GameObject.Find("UICanvas").transform);
     //(GameObject)UnityEditor.AssetDatabase.LoadAssetAtPath("Assets/p10refabs/CanvasButtonObject.prefab", typeof(GameObject)), Vector3.zero, Quaternion.identity, GameObject.Find("UICanvas").transform);
     ProceedButton.GetComponent <Button>().onClick.AddListener(OnClickEnterFloor);
     ProceedButton.transform.SetAsFirstSibling();
 }