Esempio n. 1
0
    ObstInfo SpawnObstaclesOnTile(Bounds tileBounds)
    {
        ObstInfo returnVal   = new ObstInfo();
        Vector3  obstaclePos = CreateObstaclePoint(tileBounds);
        float    obstListNum = (float)m_ObstacleList.Length;
        int      randomIndex = (int)Random.Range(0, obstListNum); //assume all players have the same list, used in message
        Obstacle newObs      = SpawnObstacle((uint)GameManager.Instance.getAllObstacleCount(), obstaclePos, randomIndex);

        VHostBehavior.Instance.SendMessageToAllPlayers(new ObstacleGeneratedMessage((uint)obsCount, obstaclePos, (ushort)randomIndex), Valve.Sockets.SendType.Reliable);
        obsCount++;
        return(returnVal);
    }
    public void ActivateHUD()
    {
        //Assesses which cues should be illuminated and their appropriate size


        //Determine closest obstacle within acceptable distance in front of the user as the target obstacle
        float    closestDist = 1000f;
        ObstInfo targetObst  = null;

        foreach (ObstInfo obst in ObstInfos)
        {
            if (obst.IsFront)
            {
                if (obst.ObstMinDist < closestDist && obst.ObstMinDist <= maxDist)
                {
                    targetObst  = obst;
                    closestDist = obst.ObstMinDist;
                }
            }
        }


        //If calibration mode is on, keep all cues visible and reset to default positions and sizes
        if (HUDCalibration)
        {
            cueSizeMultiplier = 1.0f;
            foreach (GameObject Cue in HUDCues)
            {
                Cue.SetActive(true);
                Cue.transform.localScale = Vector3.one;
            }
            HUD_East.transform.localPosition  = new Vector3(0.5f - 0.05f, HUD_East.transform.localPosition.y, HUD_East.transform.localPosition.z);
            HUD_South.transform.localPosition = new Vector3(HUD_South.transform.localPosition.x, -0.5f + 0.05f, HUD_South.transform.localPosition.z);
            HUD_West.transform.localPosition  = new Vector3(-0.5f + 0.05f, HUD_West.transform.localPosition.y, HUD_West.transform.localPosition.z);
            HUD_North.transform.localPosition = new Vector3(HUD_North.transform.localPosition.x, 0.5f - 0.05f, HUD_North.transform.localPosition.z);
        }

        //Reset and turn off all cues
        else
        {
            cueSizeMultiplier = 1.0f;
            foreach (GameObject Cue in HUDCues)
            {
                Cue.SetActive(false);
                Cue.transform.localScale = Vector3.one;
            }
            HUD_East.transform.localPosition  = new Vector3(0.5f - 0.05f, HUD_East.transform.localPosition.y, HUD_East.transform.localPosition.z);
            HUD_South.transform.localPosition = new Vector3(HUD_South.transform.localPosition.x, -0.5f + 0.05f, HUD_South.transform.localPosition.z);
            HUD_West.transform.localPosition  = new Vector3(-0.5f + 0.05f, HUD_West.transform.localPosition.y, HUD_West.transform.localPosition.z);
            HUD_North.transform.localPosition = new Vector3(HUD_North.transform.localPosition.x, 0.5f - 0.05f, HUD_North.transform.localPosition.z);
        }

        //If no target obstacle, do nothing
        if (targetObst == null)
        {
            Debug.Log("No valid targets.");
        }

        else //Turn on and resize cues for current obstacle
        {
            cueSizeMultiplier = CalculateCueMultiplier(cueWidthMaxMultiplier, minDist, maxDist, targetObst.ObstMinDist);

            if (targetObst.ObstXmin >= HUDThreshold) //Turn on right HUD
            {
                GameObject Cue = HUD_East;
                Cue.SetActive(true);
                Cue.transform.localScale    = new Vector3(Vector3.one.x * cueSizeMultiplier, Cue.transform.localScale.y, Cue.transform.localScale.z);
                Cue.transform.localPosition = new Vector3(0.5f - 0.05f * cueSizeMultiplier, Cue.transform.localPosition.y, Cue.transform.localPosition.z);
            }

            if (targetObst.ObstXmax <= -1 * HUDThreshold) //Turn on left HUD
            {
                GameObject Cue = HUD_West;
                Cue.SetActive(true);
                Cue.transform.localScale    = new Vector3(Vector3.one.x * cueSizeMultiplier, Cue.transform.localScale.y, Cue.transform.localScale.z);
                Cue.transform.localPosition = new Vector3(-0.5f + 0.05f * cueSizeMultiplier, Cue.transform.localPosition.y, Cue.transform.localPosition.z);
            }

            if (targetObst.ObstYmin >= HUDThreshold * HUDTopMultiplier) //Turn on top HUD. Modified by HUD Top Multiplier.
            {
                GameObject Cue = HUD_North;
                Cue.SetActive(true);
                Cue.transform.localScale    = new Vector3(Vector3.one.x * cueSizeMultiplier, Cue.transform.localScale.y, Cue.transform.localScale.z);
                Cue.transform.localPosition = new Vector3(Cue.transform.localPosition.x, 0.5f - 0.05f * cueSizeMultiplier, Cue.transform.localPosition.z);
            }

            else if (targetObst.ObstYmax <= -1 * HUDThreshold) //Turn on bottom HUD
            {
                GameObject Cue = HUD_South;
                Cue.SetActive(true);
                Cue.transform.localScale    = new Vector3(Vector3.one.x * cueSizeMultiplier, Cue.transform.localScale.y, Cue.transform.localScale.z);
                Cue.transform.localPosition = new Vector3(Cue.transform.localPosition.x, -0.5f + 0.05f * cueSizeMultiplier, Cue.transform.localPosition.z);
            }

            //Debug.Log("Target obstacle: " + targetObst.ObstName);
            if (debugText.activeSelf)
            {
                debugText.GetComponent <TextMeshProUGUI>().text +=
                    "\nTarget obstacle: " + targetObst.ObstName.ToString() +
                    "\nDistance: " + Mathf.Round(100 * targetObst.ObstMinDist) / 100 +
                    "\nCue Size Multiplier: " + Mathf.Round(100 * cueSizeMultiplier) / 100 +
                    "\nMin and max angle: " + Mathf.Round(targetObst.ObstAngleMin) + ", " + Mathf.Round(targetObst.ObstAngleMax) +
                    "\nMin and max X factor: " + Mathf.Round(100 * targetObst.ObstXmin) / 100 + ", " + Mathf.Round(100 * targetObst.ObstXmax) / 100 +
                    "\nMin and max Y factor: " + Mathf.Round(100 * targetObst.ObstYmin) / 100 + ", " + Mathf.Round(100 * targetObst.ObstYmax) / 100;
            }
        }
    }