Beispiel #1
0
 void Start()
 {
     player     = transform.parent.GetComponentInChildren <PlayerController>();
     cam        = transform.parent.GetComponentInChildren <Camera>();
     pe         = cam.GetComponent <PostEffect>();
     syncPlayer = GetComponentInParent <PlayerSync>();
     cape       = transform.parent.GetComponentInChildren <Cloth>();
     nvs        = GameObject.FindObjectOfType <NetworkVariables>();
     localhost  = GameObject.FindObjectOfType <LocalConnections>();
 }
Beispiel #2
0
    //private Animator playerAnim;

    void Start()
    {
        //mazeManager = GameObject.FindObjectOfType<MazeManager>();
        //mazeManager.registerPlayer(transform.parent.gameObject);
        agent = GetComponent <NavMeshAgent>();
        nvs   = GameObject.FindObjectOfType <NetworkVariables>();
        cam   = transform.parent.GetComponentInChildren <Cameraman>();
        pSync = transform.parent.GetComponent <PlayerSync>();
        //playerAnim = GameObject.FindGameObjectWithTag ("Player").GetComponentInChildren<Animator> ();
        roomParent = GameObject.Find("Room").transform;
        InvokeRepeating("updateCurrentRoom", 0f, .25f);
    }
Beispiel #3
0
    void Update()
    {
        if (fixStuff)
        {
            if (nvs != null)
            {
                if (nvs.startTimestamp == -1)
                {
                    return;
                }
                sizeX = Mathf.RoundToInt(nvs.mazeSize.x);
                sizeY = Mathf.RoundToInt(nvs.mazeSize.y);

                rooms    = new RoomController[sizeX, sizeY];
                mapRooms = new MapRoom[sizeX, sizeY];
                map.GetComponent <RectTransform>().sizeDelta        = new Vector2(sizeX * nvs.ROOM_GAP, sizeY * nvs.ROOM_GAP);
                map.GetComponent <RectTransform>().anchoredPosition = Vector3.zero;
                fixStuff = false;
            }
            else
            {
                nvs = GameObject.FindObjectOfType <NetworkVariables>();
                return;
            }
        }
        bool showMap = Input.GetKey(KeyCode.Tab);

        if (p1.activeInHierarchy != showMap && !unusedP.Contains(p1))
        {
            p1.SetActive(showMap);
        }
        if (p2.activeInHierarchy != showMap && !unusedP.Contains(p2))
        {
            p2.SetActive(showMap);
        }
        if (p3.activeInHierarchy != showMap && !unusedP.Contains(p3))
        {
            p3.SetActive(showMap);
        }
        if (p4.activeInHierarchy != showMap && !unusedP.Contains(p4))
        {
            p4.SetActive(showMap);
        }

        if (map.gameObject.activeInHierarchy != showMap)
        {
            map.gameObject.SetActive(showMap);
        }
    }
Beispiel #4
0
 void Update()
 {
     currentTimestamp = getCurrentTimestamp();
     if (nvs != null)
     {
         if (nvs.startTimestamp != -1)
         {
             int seconds = currentTimestamp - nvs.startTimestamp;
             timerText.text = string.Format("{0:00}:{1:00}:{2:00}", seconds / 3600, (seconds / 60) % 60, seconds % 60);
         }
     }
     else
     {
         nvs = GameObject.FindObjectOfType <NetworkVariables>();
     }
 }
Beispiel #5
0
    void Start()
    {
        nTrans = GetComponent <NetworkTransform>();
        nTrans.transformSyncMode = NetworkTransform.TransformSyncMode.SyncRigidbody3D;
        nvs = GameObject.FindObjectOfType <NetworkVariables>();

        rb = GetComponent <Rigidbody>();
        rb.collisionDetectionMode = CollisionDetectionMode.Discrete;
        obstacle = GetComponent <NavMeshObstacle>();
        if (obstacle != null)
        {
            if (obstacle.enabled)
            {
                usesObstacle = true;
            }
        }
        roomParent = GameObject.Find("Room").transform;
        checkStartPosition();
        //Invoke("checkStartPosition", .3f);
    }
Beispiel #6
0
    //[SerializeField]
    //private GameObject[] models;

    void Start()
    {
        playerTransform = transform.Find("Player");
        nvs             = GameObject.FindObjectOfType <NetworkVariables>();
        username        = playerTransform.GetComponentInChildren <TextMesh>();
        //models = Resources.LoadAll<GameObject>("Prefabs/Player Models");

        transform.SetParent(GameObject.Find("Players").transform);

        isAdmin = (Application.platform == RuntimePlatform.WindowsEditor || Application.platform == RuntimePlatform.LinuxEditor || Application.platform == RuntimePlatform.OSXEditor);

        if (teleportSmoke != null)
        {
            ClientScene.RegisterPrefab(teleportSmoke);
        }
        if (isLocalPlayer)
        {
            //playerModel = Random.Range (0, models.Length);
            animMenuScript = GameObject.Find("HUD").transform.GetComponentInChildren <AnimationMenu>();

            if (username.text == "USERNAME")
            {
                string[] types = { "adjectives", "animals" };
                username.text = Wordlist.GenerateWordFromList(types);

                Color[] colors = { Color.red, Color.yellow, Color.green, Color.blue, Color.cyan };
                username.color = colors[Random.Range(0, colors.Length)];
                //transform.GetChild(1).transform.GetChild(0).transform.GetChild(0).transform.GetChild(3).GetComponent<Renderer>().material.color = username.color;
                transform.GetChild(1).GetChild(0).GetChild(0).GetChild(2).GetChild(0).GetChild(0).GetChild(1).GetChild(1).GetComponent <Renderer>().material.color = username.color;
            }
            username.transform.localScale = Vector3.zero;
            agent = playerTransform.GetComponent <NavMeshAgent>();
            AnalyticsController.JoinMaze(username.text, username.color, nvs.mazeID);
            IngameChat.postLoginLogOut(true, username.text, username.color);
            startPosition = FindObjectOfType <NetworkStartPosition>().transform.position;
        }
    }
Beispiel #7
0
 void Start()
 {
     if (DistanceTransform == null)
     {
         DistanceTransform = transform.GetChild(0).GetChild(0).GetChild(0);
     }
     if (UpDownTransform == null)
     {
         UpDownTransform = transform.GetChild(0).GetChild(0);
     }
     if (RotationsTransform == null)
     {
         RotationsTransform = transform.GetChild(0);
     }
     if (Player == null)
     {
         Player = transform.parent.Find("Player").gameObject;
     }
     if (cam == null)
     {
         cam = DistanceTransform.GetChild(0).GetComponent <Camera>();
     }
     nvs = GameObject.FindObjectOfType <NetworkVariables>();
 }
Beispiel #8
0
    void OnTriggerEnter(Collider coll)
    {
        //List of players ingame.
        if (coll.CompareTag("Player"))
        {
            PlayerSync player = coll.transform.parent.parent.parent.parent.parent.parent.parent.parent.GetComponent <PlayerSync>();
            if (!playersInTheMiddle.Contains(player))
            {
                playersInTheMiddle.Add(player);
            }


            //Win check
            if (playersInTheMiddle.Count == GameObject.Find("Players").GetComponentsInChildren <PlayerSync>().Length)
            {
                GameObject.Find("HUD").gameObject.SetActive(false);
                NetworkVariables nvs    = GameObject.FindObjectOfType <NetworkVariables>();
                Vector3          walkTo = new Vector3(transform.position.x, player.getController().transform.position.y, transform.position.z);
                player.getController().Walk(walkTo);
                int startTime = nvs.startTimestamp;
                nvs.finishTime = getCurrentTimestamp();
                int    userTime       = nvs.finishTime - startTime;
                string formattedTime  = string.Format("{0:00}:{1:00}:{2:00}", userTime / 3600, (userTime / 60) % 60, userTime % 60);
                int    openedRooms    = -2; //Not counting the start and end room
                int    allRooms       = -1; //This one will not count the start room, but the end room.
                int    puzzleRooms    = 0;
                int    puzzleFinished = 0;

                foreach (RoomController rc in GameObject.FindObjectsOfType <RoomController>())
                {
                    if (rc.displayRoom)
                    {
                        openedRooms++;
                    }
                    if (rc.cameFrom != -1)
                    {
                        allRooms++;
                        //rc.displayRoom = true;
                    }
                    if (rc.getRoomCategory() != RoomObject.RoomCategory.DeadEnd &&
                        rc.getRoomCategory() != RoomObject.RoomCategory.End &&
                        rc.getRoomCategory() != RoomObject.RoomCategory.Start &&
                        rc.getRoomCategory() != RoomObject.RoomCategory.Nothing)
                    {
                        puzzleRooms++;
                    }
                    if (rc.puzzleComplete)
                    {
                        puzzleFinished++;
                    }
                }

                GameObject ws     = Instantiate(winScreen, Vector3.zero, Quaternion.identity) as GameObject;
                WinScreen  screen = ws.GetComponent <WinScreen>();
                screen.timeInSeconds    = userTime;
                screen.roomsOpened      = openedRooms;
                screen.roomCount        = allRooms;
                screen.puzzlesCompleted = puzzleFinished;
                screen.puzzleCount      = puzzleRooms;
                screen.sizeX            = Mathf.RoundToInt(nvs.mazeSize.x);
                screen.sizeY            = Mathf.RoundToInt(nvs.mazeSize.y);
                screen.mazeSeed         = nvs.seed;

                Destroy(GetComponent <BoxCollider>());
                Destroy(this);
            }
        }
    }
Beispiel #9
0
    void Start()
    {
        if (!Application.isPlaying && Application.isEditor || !isServer)
        {
            return;
        }

        nvs                = GameObject.FindObjectOfType <NetworkVariables>();
        nvs.mazeSize       = this.mazeSize;
        nvs.ROOM_GAP       = this.ROOM_GAP;
        nvs.startTimestamp = getCurrentTimestamp();

        if (GetComponent <ControlledMazeManager>() != null)
        {
            StartControlled();
            return;
        }

        if (isServer && string.IsNullOrEmpty(mazeSeed))
        {
            string[] types = { "adjectives", "adjectives", "animals" };
            mazeSeed = Wordlist.GenerateWordFromList(types);
            //mazeSeed = Random.Range(int.MinValue, int.MaxValue) + "!";
        }

        PlayerPrefs.SetString("lastSeed", mazeSeed);
        PlayerPrefs.Save();

        if (isServer)
        {
            nvs.seed   = mazeSeed;
            nvs.mazeID = AnalyticsController.GenerateMazeId(mazeSeed, mazeSize);
        }

        mazeRandom = new System.Random(mazeSeed.GetHashCode());

        playersList = GameObject.Find("Players");

        int   msX = Mathf.RoundToInt(mazeSize.x), msY = Mathf.RoundToInt(mazeSize.y);
        float midPointX = ((msX - 1) * ROOM_GAP) / 2f;
        float midPointY = ((msY - 1) * ROOM_GAP) / 2f;

        startRoom = new Vector2(mazeRandom.Next(1, msX - 2), mazeRandom.Next(1, msY - 2));

        GameObject        roomParent = Instantiate(parentPrefab, new Vector3(-midPointX, 0f, -midPointY), Quaternion.identity) as GameObject;
        NetworkInstanceID parentID   = roomParent.GetComponent <NetworkInstanceID>();

        parentID.objectName = "Room";
        NetworkServer.Spawn(roomParent);

        RoomController[,] allRooms = new RoomController[msX, msY];

        for (int x = 0; x < msX; x++)
        {
            for (int y = 0; y < msY; y++)
            {
                //Generate basic rooms
                GameObject room  = Instantiate(roomPrefab, Vector3.zero, Quaternion.identity) as GameObject;
                string     _name = x * ROOM_GAP + ", " + y * ROOM_GAP;
                room.name = _name;
                RoomController rc = room.GetComponent <RoomController>();
                rc.mazeSeed     = mazeSeed + "" + _name;
                rc.roomPosition = new Vector2(x, y);
                rc.roomGap      = ROOM_GAP;
                room.transform.SetParent(roomParent.transform);
                room.transform.localPosition = new Vector3(x * ROOM_GAP, 0f, y * ROOM_GAP);

                if (Mathf.RoundToInt(startRoom.x) == x && Mathf.RoundToInt(startRoom.y) == y)
                {
                    //rc.categories.Add(RoomObject.RoomCategory.Start);
                    rc.isStart = true; //a very dirty cheat to the start room bug where it can get another room on remote clients
                }
                //Make it update it's parent and name
                NetworkInstanceID roomID = room.GetComponent <NetworkInstanceID>();
                roomID.parentNetId = roomParent.GetComponent <NetworkIdentity>().netId;
                roomID.objectName  = _name;

                //Send it to every client
                NetworkServer.Spawn(room);

                if (Mathf.RoundToInt(startRoom.x) == x && Mathf.RoundToInt(startRoom.y) == y)
                {
                    //Spawn the spawnpoint
                    GameObject spawn = Instantiate(spawnPrefab) as GameObject;
                    spawn.transform.SetParent(rc.transform);
                    spawn.transform.localPosition = Vector3.zero;
                    string n = "Spawn Point";
                    spawn.name = n;

                    //Make it update it's parent and name
                    NetworkInstanceID spawnID = spawn.GetComponent <NetworkInstanceID>();
                    spawnID.parentNetId = roomID.netId;
                    spawnID.objectName  = n;

                    //Send it to every client
                    NetworkServer.Spawn(spawn);
                }
                allRooms[x, y] = rc;
            }
        }

        int roomCountTarget             = Mathf.RoundToInt((msX * msY) * .7f) * 2;
        List <RoomController> open_ends = new List <RoomController>();

        open_ends.Add(allRooms[Mathf.RoundToInt(startRoom.x), Mathf.RoundToInt(startRoom.y)]);

        while (open_ends.Count != 0)
        {
            int            i       = mazeRandom.Next(0, open_ends.Count);
            RoomController current = open_ends[i];
            roomCountTarget -= Mathf.Clamp(Mathf.RoundToInt(roomCountTarget / 10), 0, 100000);

            int roomX = Mathf.RoundToInt(current.roomPosition.x);
            int roomY = Mathf.RoundToInt(current.roomPosition.y);

            int doorChance   = mazeRandom.Next(0, 100) + roomCountTarget;
            int doorsInStart = 4;

            if (doorChance < 10)
            {
                doorsInStart = 1;
            }
            else if (doorChance < 30)
            {
                doorsInStart = 2;
            }
            else if (doorChance < 60)
            {
                doorsInStart = 3;
            }

            List <int> dirs = new List <int>();
            dirs.Add(0);
            dirs.Add(1);
            dirs.Add(2);
            dirs.Add(3);
            for (int d = 0; d < doorsInStart; d++)
            {
                int t   = mazeRandom.Next(0, dirs.Count);
                int dir = dirs[t];

                RoomController nextRoom = allRooms[roomX, roomY]; //Will never be this room, it's just to fix a 'unassigned' error.

                int setDirOnNext = -1;

                if (dir == 0)  //North +1x
                {
                    if (allRooms.GetLength(0) - 1 >= roomX + 1)
                    {
                        nextRoom     = allRooms[roomX + 1, roomY];
                        setDirOnNext = 1;
                        if (nextRoom.hasBeenScanned)
                        {
                            continue;
                        }
                    }
                    else
                    {
                        continue;
                    }
                }
                else if (dir == 1)    //South -1x
                {
                    if (0 <= roomX - 1)
                    {
                        nextRoom     = allRooms[roomX - 1, roomY];
                        setDirOnNext = 0;
                        if (nextRoom.hasBeenScanned)
                        {
                            continue;
                        }
                    }
                    else
                    {
                        continue;
                    }
                }
                else if (dir == 2)    //East -1y
                {
                    if (0 <= roomY - 1)
                    {
                        nextRoom     = allRooms[roomX, roomY - 1];
                        setDirOnNext = 3;
                        if (nextRoom.hasBeenScanned)
                        {
                            continue;
                        }
                    }
                    else
                    {
                        continue;
                    }
                }
                else if (dir == 3)    //West +1y
                {
                    if (allRooms.GetLength(1) - 1 >= roomY + 1)
                    {
                        nextRoom     = allRooms[roomX, roomY + 1];
                        setDirOnNext = 2;
                        if (nextRoom.hasBeenScanned)
                        {
                            continue;
                        }
                    }
                    else
                    {
                        continue;
                    }
                }
                setDoorBoolInRoom(dir, true, ref current);
                nextRoom.cameFrom = setDirOnNext;
                setDoorBoolInRoom(setDirOnNext, true, ref nextRoom);
                nextRoom.hasBeenScanned = true;
                open_ends.Add(nextRoom);
            }
            current.hasBeenScanned = true;
            if (open_ends.Count == 1)
            {
                open_ends[0].isEnd = true;
            }
            open_ends.Remove(current);
            if (current.roomPosition == new Vector2(Mathf.RoundToInt(startRoom.x), Mathf.RoundToInt(startRoom.y)))
            {
                current.displayRoom = true;
            }
        }
    }