Example #1
0
 /// Initializes the audio system with the current audio configuration.
 /// @note This should only be called from the main Unity thread.
 public static void Initialize(GvrAudioListener listener, Quality quality)
 {
     if (!initialized)
     {
         // Initialize the audio system.
         AudioConfiguration config = AudioSettings.GetConfiguration();
         sampleRate      = config.sampleRate;
         numChannels     = (int)config.speakerMode;
         framesPerBuffer = config.dspBufferSize;
         if (numChannels != (int)AudioSpeakerMode.Stereo)
         {
             Debug.LogError("Only 'Stereo' speaker mode is supported by GVR Audio.");
             return;
         }
         if (Application.platform != RuntimePlatform.Android)
         {
             // TODO: GvrAudio bug on Android with Unity 2017
             Initialize((int)quality, sampleRate, numChannels, framesPerBuffer);
         }
         listenerTransform = listener.transform;
         if (Application.platform == RuntimePlatform.Android)
         {
             // TODO: GvrAudio bug on Android with Unity 2017
             return;
         }
         initialized = true;
     }
     else if (listener.transform != listenerTransform)
     {
         Debug.LogError("Only one GvrAudioListener component is allowed in the scene.");
         GvrAudioListener.Destroy(listener);
     }
 }
    /// Initializes the audio system with the current audio configuration.
    /// @note This should only be called from the main Unity thread.
    public static void Initialize(GvrAudioListener listener, Quality quality)
    {
        if (!initialized)
        {
#if !UNITY_EDITOR && UNITY_ANDROID
            SetApplicationState();
#endif
            // Initialize the audio system.
            AudioConfiguration config = AudioSettings.GetConfiguration();
            sampleRate      = config.sampleRate;
            numChannels     = (int)config.speakerMode;
            framesPerBuffer = config.dspBufferSize;
            if (numChannels != (int)AudioSpeakerMode.Stereo)
            {
                Debug.LogError("Only 'Stereo' speaker mode is supported by GVR Audio.");
                return;
            }
            Initialize(quality, sampleRate, numChannels, framesPerBuffer);
            listenerTransform = listener.transform;

            initialized = true;
        }
        else if (listener.transform != listenerTransform)
        {
            Debug.LogError("Only one GvrAudioListener component is allowed in the scene.");
            GvrAudioListener.Destroy(listener);
        }
    }
Example #3
0
  /// Shuts down the audio system.
  /// @note This should only be called from the main Unity thread.
  public static void Shutdown (GvrAudioListener listener) {
    if (initialized && listener.transform == listenerTransform) {
      initialized = false;

      Shutdown();
      sampleRate = -1;
      numChannels = -1;
      framesPerBuffer = -1;
    }
  }
    /// Shuts down the audio system.
    /// @note This should only be called from the main Unity thread.
    public static void Shutdown(GvrAudioListener listener)
    {
        if (initialized && listener.transform == listenerTransform)
        {
            initialized = false;

            Shutdown();
            sampleRate      = -1;
            numChannels     = -1;
            framesPerBuffer = -1;
        }
    }
Example #5
0
    void Start()
    {
        GameConfig    = GameConfig.Instance();
        rotationSpeed = GameConfig.playerRotationSpeed;
        forwardSpeed  = GameConfig.playerForwardSpeed;
        audio         = GetComponent <AudioSource>();


        if (photonView.isMine || GameConfig.isSoloGame)
        {
            startPhotonIsMineCalled = true;
            rb           = GetComponent <Rigidbody>();
            forwardSpeed = GameConfig.playerForwardSpeed;
            playerLocal  = this.transform.Find("GvrMain/Head/Main Camera/Main Camera Left");

            avatar.SetActive(false);

            AudioListener listener = GetComponent <AudioListener>();
            listener.enabled = true;

            GvrViewer viewer = GetComponentInChildren <GvrViewer>();
            viewer.enabled = true;

            GvrEye[] eyes = GetComponentsInChildren <GvrEye>(true);
            foreach (GvrEye eye in eyes)
            {
                eye.enabled = true;
            }

            GvrAudioListener gvrListener = GetComponentInChildren <GvrAudioListener>();
            if (gvrListener)
            {
                gvrListener.enabled = true;
            }

            Camera[] cameras = GetComponentsInChildren <Camera>(true);
            foreach (Camera camera in cameras)
            {
                camera.enabled = true;
            }

            GameObject scoring = GameObject.FindWithTag("Scoring System");
            scoringScript = scoring.GetComponent <ScoringSystem>();
            scoringScript.AddPlayer(playerNumber);
//        } else {
//            StartCoroutine("Alive");      // To reinstate lerping when ready.
        }
    }
    void OnDrawGizmosSelected()
    {
        // Draw listener directivity gizmo.
        // Note that this is a very suboptimal way of finding the component, to be used in Unity Editor
        // only, should not be used to access the component in run time.
        GvrAudioListener listener = FindObjectOfType <GvrAudioListener>();

        if (listener != null)
        {
            Gizmos.color = GvrAudio.listenerDirectivityColor;
            DrawDirectivityGizmo(listener.transform, listenerDirectivityAlpha,
                                 listenerDirectivitySharpness, 180);
        }
        // Draw source directivity gizmo.
        Gizmos.color = GvrAudio.sourceDirectivityColor;
        DrawDirectivityGizmo(transform, directivityAlpha, directivitySharpness, 180);
    }
Example #7
0
 /// Shuts down the audio system.
 /// @note This should only be called from the main Unity thread.
 public static void Shutdown(GvrAudioListener listener)
 {
     if (initialized && listener.transform == listenerTransform)
     {
         initialized = false;
         if (Application.platform == RuntimePlatform.Android)
         {
             // TODO: GvrAudio bug on Android with Unity 2017
             return;
         }
         Shutdown();
         sampleRate        = -1;
         numChannels       = -1;
         framesPerBuffer   = -1;
         listenerTransform = null;
     }
 }
Example #8
0
    void Start()
    {
        samplesOffset = 64;
        rec           = null;
        GameObject.FindGameObjectWithTag("sendButton").GetComponent <Text>().text = "Not Changed";
        if (!isLocalPlayer)
        {
            return;
        }
        GameObject.FindGameObjectWithTag("sendButton").GetComponent <Text>().text = "Changed";
        rec = this.GetComponents <AudioSource>()[0];
        if (Microphone.devices == null)
        {
            GameObject.FindGameObjectWithTag("sendButton").GetComponent <Text>().text = "Not There";
            return;
        }
        else
        {
            if (Microphone.devices.Length == 0)
            {
                GameObject.FindGameObjectWithTag("sendButton").GetComponent <Text>().text = "Not There 0";
            }
            else
            {
                GameObject.FindGameObjectWithTag("sendButton").GetComponent <Text>().text = "" + Microphone.devices[0];
            }
        }

        Microphone.GetDeviceCaps(Microphone.devices[0], out minf, out maxf);
        rec.clip = Microphone.Start(Microphone.devices[0], true, 999, maxf);
        while (!(Microphone.GetPosition(Microphone.devices[0]) > 0))
        {
        }
        rec.Play();
        listener            = GetComponent <AudioListener>();
        listener.enabled    = true;
        gvrListener         = GetComponent <GvrAudioListener>();
        gvrListener.enabled = true;
    }
Example #9
0
  /// Initializes the audio system with the current audio configuration.
  /// @note This should only be called from the main Unity thread.
  public static void Initialize (GvrAudioListener listener, Quality quality) {
    if (!initialized) {
#if !UNITY_EDITOR && UNITY_ANDROID
      SetApplicationState();
#endif
      // Initialize the audio system.
      AudioConfiguration config = AudioSettings.GetConfiguration();
      sampleRate = config.sampleRate;
      numChannels = (int)config.speakerMode;
      framesPerBuffer = config.dspBufferSize;
      if (numChannels != (int)AudioSpeakerMode.Stereo) {
        Debug.LogError("Only 'Stereo' speaker mode is supported by GVR Audio.");
        return;
      }
      Initialize(quality, sampleRate, numChannels, framesPerBuffer);
      listenerTransform = listener.transform;

      initialized = true;
    } else if (listener.transform != listenerTransform) {
      Debug.LogError("Only one GvrAudioListener component is allowed in the scene.");
      GvrAudioListener.Destroy(listener);
    }
  }