Example #1
0
    void Start()
    {
        // Initial status for the max and mins
        exhalePresMin = Binding <float> .GetBinding("ExhalePressureMin").value();

        exhalePresMax = Binding <float> .GetBinding("ExhalePressureMax").value();

        exhalePressMinFloor = Binding <float> .GetBinding("ExhalePressureThresholdMin").value();

        exhalePressMaxRoof = Binding <float> .GetBinding("ExhalePressureThresholdMax").value();

        exhaleTimeMin = Binding <float> .GetBinding("ExhaleTimeThreshold").value();

        exhaleTimeMax = Binding <float> .GetBinding("ExhaleTimeMax").value();

        exhaleTimeMedium = (exhaleTimeMax - exhaleTimeMin) / 2 + exhaleTimeMin;

        breathCountMin = Binding <int> .GetBinding("BreathsMin").value();

//		breathCountTarget = Binding<int>.GetBinding("BreathsTarget").value();
        maxBreathNumber = Binding <int> .GetBinding("BreathsMax").value();


        masterGenerator = GameObject.FindObjectOfType <MasterGenerator>();

        // Figure out the ranges
        goodBreathRange = exhalePresMax - exhalePresMin;
        overblownRange  = exhalePressMaxRoof - exhalePresMax;
        underblownRange = exhalePresMin - exhalePressMinFloor;

        // Binding the status
        statusProp = new Property <enumStatus>(enumStatus.Initializing);
        statusProp.AddToBinding("Status", BindingDirection.BindingToProperty, AssignmentOnAdd.TakeBindingValue);
        statusProp.AddListener(StatusUpdate);

        // Binding the length of the current breath
        breathLengthProp = new Property <float>(0);
        breathLengthProp.AddToBinding("BreathLength", BindingDirection.BindingToProperty, AssignmentOnAdd.TakeBindingValue);
        breathLengthProp.AddListener(BreathLengthUpdate);

        // Binding to the Breath
        breathStrengthProp = new Property <float>(0);
        breathStrengthProp.AddToBinding("BreathStrength", BindingDirection.BindingToProperty, AssignmentOnAdd.TakeBindingValue);
        breathStrengthProp.AddListener(UpdateBreath);

        // Binding to the currentSet
        goodSetProp = new Property <bool>(false);
        goodSetProp.AddToBinding("SetIsGood", BindingDirection.BindingToProperty, AssignmentOnAdd.TakeBindingValue);
        goodSetProp.AddListener(SetGoodUpdate);

        breathCountGoodProp = new Property <int>(0);
        breathCountGoodProp.AddToBinding("BreathCountGood", BindingDirection.BindingToProperty, AssignmentOnAdd.TakeBindingValue);
        breathCountGoodProp.AddListener(GoodBreathCountUpdate);

        breathGoodProp = new Property <bool>(false);
        breathGoodProp.AddToBinding("BreathIsGood", BindingDirection.BindingToProperty, AssignmentOnAdd.TakeBindingValue);
        breathGoodProp.AddListener(BreathGood);

        breathCountProp = new Property <int>(0);
        breathCountProp.AddToBinding("BreathCount", BindingDirection.BindingToProperty, AssignmentOnAdd.TakeBindingValue);

        setCountProp = new Property <int>(0);
        setCountProp.AddToBinding("SetCount", BindingDirection.BiDirectional, AssignmentOnAdd.TakeBindingValue);
        setCountProp.AddListener(SetCountUpdate);
    }
    //where type 0 is tutorial and type 1 is dungeon and type 2 is arena.
    IEnumerator CreateLevel(int type)
    {
        if (inGameCameraObject == null)
        {
            inGameCameraObject = Instantiate(inGameCameraPrefab);
            mainCamera         = inGameCameraObject.GetComponentInChildren <Camera> ();
        }

        yield return(new WaitForSeconds(.1f));

        if (!PlayerPrefs.HasKey("TexturesRandomized") || RandomizeTexturesAllowed)
        {
            RandomizeTextures();
            PlayerPrefs.SetInt("TexturesRandomized", 1);
        }

        if (type == 1)
        {
            int cappedDungeonLevel = dungeonLevel;
            if (cappedDungeonLevel > 40)
            {
                cappedDungeonLevel = 40;
            }
            masterGenerator = new MasterGenerator(this.gameObject, dungeonData.dungeonParameters[cappedDungeonLevel], radius, maxlength, timeout);
            masterGenerator.LoadPrefabs();
            masterGenerator.Constructing();
        }
        else if (type == 0)
        {
            tutorialObject = Instantiate(tutorialPrefab, new Vector3(0, 0, 0), Quaternion.identity) as GameObject;
            levelTransform = tutorialObject.transform;
        }
        else if (type == 2)
        {
            arenaObject    = Instantiate(arenaPrefab, new Vector3(-150f, 0f, 150f), Quaternion.identity) as GameObject;
            levelTransform = arenaObject.transform;
        }

        if (ui == null)
        {
            ui          = Instantiate(UIPrefab);
            uiInventory = ui.uiInventory;
        }

        TorchFOV = Instantiate(TorchFOVPrefab);

        triggerFloorObject = Instantiate(triggerFloorPrefab, levelTransform) as GameObject;

        torch = Instantiate(torchPrefab) as Torch;
        Instantiate(torchMinimapIndicator, torch.transform.position + new Vector3(0f, -3f, 0f), Quaternion.Euler(new Vector3(90f, 0f, 0f)), torch.transform);


        camTarget         = torch.gameObject;
        enemyTarget       = torch.gameObject;
        torch.health      = torchStartingHealth;
        torch.gameManager = this;
        torch.ui          = ui;
        torch.TorchFOV    = TorchFOV.GetComponentInChildren <Animator> ();

        collectedKeys = 0;

        for (int i = 0; i < playerManagers.Length; i++)
        {
            if (playerManagers [i].playerInstance == null)
            {
//				Debug.Log ("Create Player with id:" + i);
                playerManagers [i].playerInstance = Instantiate(playerPrefab) as GameObject;
                playerManagers [i].playerNumber   = i + 1;
                playerManagers [i].Setup();
                playerManagers [i].playerMovement.mainCamera = mainCamera;
                playerManagers [i].gameManager = this;
            }
            else
            {
                //			playerManagers [i].playerInstance.transform.position = masterGenerator.dungeon_instantiate.startPos;
                playerManagers [i].Setup();
                playerManagers [i].playerInstance.SetActive(true);
            }
        }

        ApplySkins();

        SetNumberOfPlayers(numberOfPlayers);

        //Moving players, torch and Bold to the correct place
        Vector3 startpoint = new Vector3(0f, 0f, 0f);

        if (type == 1)
        {
            startpoint        = masterGenerator.MovePlayersToStart();
            torch.isDamagable = true;
        }
        else if (type == 0)
        {
            startpoint = tutorialObject.transform.Find("Spawnpoint").transform.position;
            playerManagers [0].playerInstance.transform.position = startpoint;
            playerManagers [1].playerInstance.transform.position = startpoint + new Vector3(-2f, 0f, -2f);
            torch.isDamagable = false;
        }
        else if (type == 2)
        {
            startpoint = arenaObject.transform.Find("Spawnpoint").transform.position;
            playerManagers [0].playerInstance.transform.position = startpoint;
            playerManagers [1].playerInstance.transform.position = startpoint + new Vector3(-2f, 0f, -2f);
            torch.isDamagable = true;
        }
        RespawnPosition          = startpoint;
        torch.transform.position = startpoint + new Vector3(6, .5f, 0);

        if (type == 1 || type == 2)
        {
            Pet.transform.position = playerManagers [0].playerInstance.transform.position + new Vector3(3f, 0f, 0f);
            Pet.SetActive(true);
            Bold.SetActive(false);
        }
        else if (type == 0)
        {
            Pet.SetActive(false);
            Bold.SetActive(true);
            Bold.transform.position = playerManagers [0].playerInstance.transform.position;
        }

        torch.torchPickUp.cam = mainCamera;
        if (type == 1)
        {
            ui.dungeonLevelText.text = "Dungeon level " + dungeonLevel;
        }
        else if (type == 0)
        {
            ui.dungeonLevelText.text = "Dungeon Tutorial";
            BoldPetScript.speechCanvas.SetActive(true);
            BoldPetScript.speechText.text = "Welcome to this tutorial! My name is Bold. Use the WASD-keys to move.";
            BoldPetScript.speechImage.gameObject.SetActive(true);
        }
        else if (type == 2)
        {
            ui.dungeonLevelText.text = "ArenaMode";
            arenaManager.StartArena();
        }

        audioSourceMusic.clip = audioDungeon [UnityEngine.Random.Range(0, audioDungeon.Length)];
        if (torch.GetComponent <PartyTorch> () != null)
        {
            audioSourceMusic.clip = audioPartyTorch;
        }
        if (torch.GetComponent <GoldenTorch> () != null)
        {
            audioSourceMusic.clip = audioGoldenTorch;
        }
        audioSourceMusic.Play();
        score = 0;
        SetScore(totalScore);
        SetInGameCoin(coinsInGame);
        homeScreenCam.SetActive(false);
        loadingScreenCanvas.SetActive(false);

        minimap = Instantiate(minimapPrefab);

        ui.timer.Reset();

        StartTime = Time.time;
        mainCamera.GetComponent <CameraController> ().SetMode("Normal");

        yield return(null);
    }