Exemple #1
0
    public void addStudents(MyPath mypath, SortedDictionary <int, int> pathToRoomIndex)
    {
        path = mypath;

        float distance = path.GetTotalDistance();
        float spacing  = distance / numStudents;

        studentLocations = new float[numStudents];
        studentRooms     = new Dictionary <int, List <int> > ();
        for (int studentIndex = 0; studentIndex < numStudents; studentIndex++)
        {
            float studentDist = 9f + studentIndex * distance * 0.9f / numStudents;

            studentLocations[studentIndex] = studentDist;
            int room = pathToRoomIndex[path.GetIndexAtDistance(studentDist)];
            Debug.Log("Distance: " + studentDist + " Room:" + room);
            if (!studentRooms.ContainsKey(room))
            {
                studentRooms.Add(room, new List <int>());
            }

            //Debug.Log("Adding student " + studentIndex + " to room " + room + " Studentdist: " + studentDist + " totalDist: " + distance );
            studentRooms[room].Add(studentIndex);
        }
    }
    // Returns the index of the room the camera is currently in
    public int GetRoomIndex()
    {
        if (path == null)
        {
            return(0);
        }
        int v;

        pathIndexToRoom.TryGetValue(path.GetIndexAtDistance(distance), out v);

        return(v);
    }
Exemple #3
0
    private Vector3 getStudentPosition(int studentIndex)
    {
        float   loc       = studentLocations[studentIndex];
        int     pathIndex = path.GetIndexAtDistance(loc);
        Vector3 start     = path.GetPoint(pathIndex);
        Vector3 end       = path.GetPoint(pathIndex + 1);

        Vector3 studentPos = path.GetPositonAlongPath(loc);

        float dist = 0.5f + Random.value;

        if (Random.value > 0.5)
        {
            dist = -1 * dist;
        }

        Vector3 diff = end - start;

        Debug.Log("Pos: " + studentPos);

        if (diff.x == 0)
        {
            studentPos.x = studentPos.x + dist;
        }
        else if (diff.z == 0)
        {
            studentPos.z = studentPos.z + dist;
        }
        else
        {
            float direction = diff.x / diff.z;

            studentPos = new Vector3(studentPos.x + (1 / direction) * dist, studentPos.y, studentPos.z + (direction) * dist);
        }

        return(studentPos);
    }