Пример #1
0
    //Instantiates, rotates, and moves room to its position
    IEnumerator InstantiateRoom(int roomType, int roomRotation, Vector2 location, JSONNode walls, int index)
    {
        Transform room;

        if (roomType == 1)
        {
            room = Instantiate(oneDoorRoom) as Transform;
        }
        else if (roomType == 3)
        {
            room = Instantiate(twoDoorRoom) as Transform;
        }
        else if (roomType == 2)
        {
            room = Instantiate(twoDoorCorner) as Transform;
        }
        else if (roomType == 4)
        {
            //print ("no it's happening");
            room = Instantiate(threeDoorRoom) as Transform;
        }
        else
        {
            room = Instantiate(fourDoorRoom) as Transform;
        }

        //Makes each of the walls that hold a single painting.
        for (int i = 0; i < walls.Count; i++)
        {
            Vector2   start   = new Vector2(walls[i]["startx"].AsFloat, walls[i]["starty"].AsFloat);
            Vector2   end     = new Vector2(walls[i]["endx"].AsFloat, walls[i]["endy"].AsFloat);
            Transform newWall = MakeWall(start, end);
            newWall.SetParent(room);
            //Instantiate a painting, and attach the image it needs from the url given.
            Transform      newPainting = Instantiate(painting) as Transform;
            PaintingScript ps          = newPainting.GetComponent <MonoBehaviour>() as PaintingScript;
            ps.ResizePainting(new Vector2(newWall.localScale.x, newWall.localScale.y), walls[i]["url"].ToString());


            float wallLength = (start - end).magnitude * width;

            //We put plaques that float next to the painting, so you can see who made it and what it's called.
            Transform newPlaque = Instantiate(plaque) as Transform;
            newPlaque.position   = newWall.position + newWall.transform.forward * .3f - newWall.transform.right * wallLength * .25f;
            newPainting.position = newWall.position + newWall.transform.forward * .3f;
            //This is all basically voodoo to make the text appear in the right spot, with the right rotation
            TextMesh tm = newPlaque.GetComponent <TextMesh>();
            tm.text            = walls[i]["descr"];
            tm.text            = tm.text.Replace("by ", "\n");
            newPlaque.rotation = newWall.rotation;
            newPlaque.Rotate(new Vector3(0, 180, 0));
            newPlaque.SetParent(room);
            newPainting.rotation = newWall.rotation;
            newPainting.SetParent(room);
            yield return(new WaitForSeconds(.1f));
        }

        //Transform room. We always instantiate and build them at the origin for ease of use, then move them to the right spot.
        room.Rotate(Vector3.up * roomRotation);
        Vector3 movement = new Vector3(width * location.x, 0, width * location.y);

        room.position = room.position + movement;
        if (index < N["rooms"].Count - 1)
        {
            JSONNode nextRoom      = N["rooms"][index + 1];
            Vector2  startLocation = new Vector2(nextRoom["x"].AsFloat, nextRoom["y"].AsFloat);
            //make the next room
            StartCoroutine(InstantiateRoom(nextRoom["room_type"].AsInt, nextRoom["rotation"].AsInt, startLocation, nextRoom["walls"], index + 1));
        }
    }
Пример #2
0
    private void Awake()
    {
        player = new Controller();

        //Assign light variables to proper objects in scene
        lightSwitch    = GameObject.FindGameObjectWithTag("Lights");
        worldLighting  = GameObject.FindGameObjectWithTag("EnvironmentLights");
        backUpLighting = GameObject.FindGameObjectWithTag("BackUpLights");
        lightScript    = lightSwitch.GetComponent <LightScript>();
        //lightCooldown = 10f;
        lightEnable = true;

        //Assign gramophone variables to proper objects in scene
        gramophone  = GameObject.FindGameObjectWithTag("Gramophone");
        worldMusic  = GameObject.FindGameObjectWithTag("WorldMusic");
        musicScript = gramophone.GetComponent <GramophoneScript>();
        //musicCooldown = 10f;
        musicEnable = true;

        //Assign painting variables to proper objects in scene
        painting    = GameObject.FindGameObjectWithTag("Painting");
        paintScript = painting.GetComponent <PaintingScript>();
        //paintCooldown = 15f;
        paintEnable = true;

        prop       = GameObject.FindGameObjectWithTag("Prop");
        propScript = prop.GetComponent <PropScript>();

        //Assign player numbers and colors
        playernum = numplayers;
        numplayers++;

        //Add by Guanchen Liu
        //Assign nathan
        Nathan      = GameObject.Find("Nathan");
        humanScript = Nathan.GetComponent <HumanBehavior>();
        currentItem = selectedItem.None;
        currentCond = ghostCond.None;
        mainCamera  = GameObject.Find("MainCamera");
        sc          = mainCamera.GetComponent <CameraControl>();
        UI          = UIManager.instance.gameObject;
        var UICoolDown = UI.transform.Find("CoolDown").gameObject;

        // lightImage = UICoolDown.transform.GetChild(0).GetComponent<Image>();
        // musicImage = UICoolDown.transform.GetChild(1).GetComponent<Image>();
        // paintImage = UICoolDown.transform.GetChild(2).GetComponent<Image>();


        player.Gameplay.Grabbing.canceled += context => ReleaseObject();

        if (playernum == 0)
        {
            GameObject temp = GameObject.Find("Ghost_1");
            transform.position = temp.transform.position;
            Destroy(temp);
            mesh.material   = color1;
            gameObject.name = "Ghost_1";
        }
        if (playernum == 1)
        {
            GameObject temp = GameObject.Find("Ghost_2");
            transform.position = temp.transform.position;
            Destroy(temp);
            mesh.material   = color2;
            gameObject.name = "Ghost_2";
            backUpLighting.gameObject.SetActive(false);
            var UIScript = UI.GetComponent <UIManager>();
            Time.timeScale = 1.0f;
            UIScript.playStartImage();
        }

        var allGhost = GameObject.FindGameObjectsWithTag("Ghost");

        choreManger = GameObject.Find("ChoreManger").GetComponent <ChoreManger>();
    }