Exemple #1
0
	void Start (){
		cam = gameObject.GetComponent<Camera> ();
		al = gameObject.GetComponent<AudioListener> ();
		if (follow == false) {
			StartCoroutine (TurnRight (5.0F));
		}
	}
 void Awake()
 {
     masterVolumeSlider = GameObject.Find ("MasterVolume").GetComponent<Slider> ();
     backgroundMusicSlider = GameObject.Find ("MusicVolume").GetComponent<Slider> ();
     listener = GameObject.FindGameObjectWithTag ("MainCamera").GetComponent<AudioListener> ();
     backgroundMusic = GameObject.FindGameObjectWithTag ("BackgroundMusic").GetComponent<AudioSource> ();
 }
    /// <summary>
    /// Play the specified audio clip with the specified volume and pitch.
    /// PlaySound was copied from NGUI
    /// </summary>
    public static AudioSource PlaySound(AudioClip clip, float volume = 1f, float pitch = 1f)
    {
        volume *= 1f;

        if (clip != null && volume > 0.01f)
        {
            if (mListener == null)
            {
                mListener = GameObject.FindObjectOfType(typeof(AudioListener)) as AudioListener;

                if (mListener == null)
                {
                    Camera cam = Camera.main;
                    if (cam == null) cam = GameObject.FindObjectOfType(typeof(Camera)) as Camera;
                    if (cam != null) mListener = cam.gameObject.AddComponent<AudioListener>();
                }
            }

            if (System.DateTime.Now > PlayerTouch.timeLastClipEnds // wait for last clip to play through
                && mListener != null && mListener.enabled && mListener.gameObject.activeInHierarchy)
            {
                PlayerTouch.timeLastClipEnds = System.DateTime.Now.AddSeconds(clip.length);
                AudioSource source = mListener.audio;
                if (source == null) source = mListener.gameObject.AddComponent<AudioSource>();
                source.pitch = pitch;
                source.PlayOneShot(clip, volume);
                return source;
            }
        }
        return null;
    }
    /// <summary>
    /// Play button sound. 播放按鈕音效.
    /// </summary>
    private void PlaySound()
    {
        if (listener == null || source == null)
        {
            GameObject go = FindObjectOfType<AudioListener>().gameObject;

            if (go == null)
            {
                go = GameObject.Find("GlobalAudio");
                if(go == null) listener = new GameObject("GlobalAudio").AddComponent<AudioListener>();
                source = listener.gameObject.AddComponent<AudioSource>();
            }
            else
            {
                listener = go.GetOrAddComponentEX<AudioListener>();
                source = go.GetOrAddComponentEX<AudioSource>();
            }

            source.clip = buttonSound;
            source.playOnAwake = false;
            source.loop = false;
        }

        source.Play();
    }
 void Start()
 {
     #if ENABLE_SPATIALIZER_API
     audioListener = (AudioListener)FindObjectOfType(typeof(AudioListener));
     if (!audioListener) Debug.Log("No AudioListener instance can be found, occlusion will not work.");
     #endif
 }
    /// <summary>
    /// Play the specified audio clip with the specified volume and pitch.
    /// </summary>
    public static AudioSource PlaySound(AudioClip clip, float volume, float pitch)
    {
        volume *= soundVolume;

        if (clip != null && volume > 0.01f)
        {
            if (mListener == null)
            {
                mListener = GameObject.FindObjectOfType(typeof(AudioListener)) as AudioListener;

                if (mListener == null)
                {
                    Camera cam = Camera.main;
                    if (cam == null) cam = GameObject.FindObjectOfType(typeof(Camera)) as Camera;
                    if (cam != null) mListener = cam.gameObject.AddComponent<AudioListener>();
                }
            }

            if (mListener != null)
            {
                AudioSource source = mListener.audio;
                if (source == null) source = mListener.gameObject.AddComponent<AudioSource>();
                source.pitch = pitch;
                source.PlayOneShot(clip, volume);
                return source;
            }
        }
        return null;
    }
Exemple #7
0
    // Use this for initialization
    void Start () {
        audioListener = GetComponent<AudioListener>();

        stream.Open(); //Open the Serial Stream.

        //string value = stream.ReadLine(); //Read the information
        //value = stream.ReadLine(); //Read the information
        //value = stream.ReadLine(); //Read the information
        //if (value != "")
        //{
        //    string[] vec12 = value.Split(',');

        //    // translate using A
        //    // transform.Translate(float.Parse(vec12[3]), float.Parse(vec12[4]), float.Parse(vec12[5]), Space.World);
        //    initPosX = float.Parse(vec12[3]);
        //    initPosY = float.Parse(vec12[4]);
        //    initPosZ = float.Parse(vec12[5]);

        //    // rotate using heading, pitch, roll
        //    float scale = 3.1415926f / 180.00f;
        //    initRotHeading = float.Parse(vec12[9]) * scale;
        //    initRotPitch = float.Parse(vec12[10]) * scale;
        //    initRotRoll = float.Parse(vec12[11]) * scale;
        //}
    }
Exemple #8
0
    // Use this for initialization
    void Start()
    {
        GameObject.Find("CenterPiece").transform.position = new Vector3(Camera.main.transform.position.x, GameObject.Find("CenterPiece").transform.position.y, Camera.main.transform.position.z);

        //Get the cameras audio listener
        CamerasAudioListener = Camera.main.GetComponent<AudioListener>();

        //Alignment
        for (int Child = 0; Child < transform.childCount; Child++)
        {
            //Current Degree
            float DegreeInc = 2 * Mathf.PI / transform.childCount;

            //Positioning
            float x = Camera.main.transform.position.x + (2.0f * Mathf.Cos(DegreeInc * Child));
            float z = Camera.main.transform.position.z + (2.0f * Mathf.Sin(DegreeInc * Child));
            //print(x);
            //print(z);
            transform.GetChild(Child).transform.position = new Vector3(x, transform.GetChild(Child).position.y, z);
            OriginalZPositions.Add(transform.GetChild(Child).transform.localPosition.z);

            //transform.rotation = Quaternion.LookRotation(transform.position - new Vector3(Camera.main.transform.position.x, transform.GetChild(Child).transform.position.y, Camera.main.transform.position.z));
            transform.GetChild(Child).transform.LookAt(new Vector3(Camera.main.transform.position.x, transform.GetChild(Child).transform.position.y, Camera.main.transform.position.z));
        }
        print(OriginalZPositions.Count);
    }
    AudioSource PlaySound(AudioClip clip, float volume, float pitch)
    {
        if (clip != null && volume > 0.01f)
        {
            if (mListener == null)
            {
                mListener = GameObject.FindObjectOfType(typeof(AudioListener)) as AudioListener;

                if (mListener == null)
                {
                    Camera cam = Camera.main;
                    if (cam == null) cam = GameObject.FindObjectOfType(typeof(Camera)) as Camera;
                    if (cam != null) mListener = cam.gameObject.AddComponent<AudioListener>();
                }
            }

            if (mListener != null && mListener.enabled && mListener.gameObject && mListener.gameObject.activeInHierarchy)
            {
                AudioSource source = mListener.GetComponent<AudioSource>();
                if (source == null) source = mListener.gameObject.AddComponent<AudioSource>();
                source.pitch = pitch;
                source.PlayOneShot(clip, volume);
                return source;
            }
        }
        return null;
    }
Exemple #10
0
 void Awake()
 {
     audioListener = gameObject.GetComponent<AudioListener>();
     audioSource = gameObject.GetComponent<AudioSource>();        
     //obtener mute
     audioSource.playOnAwake = !mute;        
 }
 void Awake()
 {
     audioListener = GetComponent<AudioListener>();
     if(playerCamera == null) playerCamera = gameObject.GetComponentInChildren<Camera>();
     gameObject.AddGlobalEventListener(UIEVent.RequestLocalCamera, (EventObject evt)=>{
         if(isLocalPlayer) gameObject.DispatchGlobalEvent(UIEVent.GotLocalCamera, new object[]{transform});
     });
 }
 //It might be cool to also have a variable that controls how good the hearing of this listener is: i.e. a volume multiplier
 void OnEnable()
 {
     if(sceneAudioListener == null)
     {
         sceneAudioListener = (AudioListener)GameObject.FindObjectOfType(typeof(AudioListener));
     }
     allListeners.Add(this);
 }
    // Use this for initialization
    void Start()
    {
        character = GameObject.Find("Player");

        PlayerPrefs.SetInt("1stPerson?", 0);

        aud = this.GetComponent(typeof(AudioListener)) as AudioListener;
    }
 public CarSoundManager(CarActor car, CameraController camera, Game game)
     : base(game)
 {
     cueArray = new Cue[CarSoundEmitters.AudioEmitters.Count];
     car_ = car;
     listener_ = camera.Listener;
     camera_ = camera;
     state_ = camera.CurrentCamera.State;
 }
Exemple #15
0
	// Member Functions
	
	void Awake() 
	{
		s_cInstance = this;
       		
		s_activeAudio = new List<ClipInfo>();
		m_listener = (AudioListener) FindObjectOfType(typeof(AudioListener));
		
		occludeState = OcclusionState.OCCLUSION_FALSE;
    }
    void Start()
    {
        camera = gameObject.GetComponentInChildren<Camera> ();
        audioListener = gameObject.GetComponentInChildren<AudioListener> ();

        if (!isLocalPlayer) {
            camera.enabled = false;
            audioListener.enabled = false;
        }
    }
    // Use this for initialization
    void Start()
    {
        listener = GetComponent<AudioListener> ();
        controller = GameObject.Find ("Controller").GetComponent<Controller>();

        //whatToSay = GameObject.Find ("Speaker").GetComponent<AudioClip> ();
        voiceBox = GameObject.Find ("Speaker").GetComponent<AudioSource> ();

        inputThresh = GameObject.Find ("Input Thresh").GetComponent<Text> ();
    }
	// Use this for initialization
	void Start ()
	{
		canChange=false;
		if(Increase)
		{
			StartMinute=0;
			StartSecond=0;
		}
		allAudioSources = FindObjectsOfType (typeof(AudioSource)) as AudioSource[];
		listener = GameObject.Find ("Main Camera").GetComponent<AudioListener> ();
	}
Exemple #19
0
	void Update() 
	{
		if(m_listener == null)
		{
			m_listener = (AudioListener) FindObjectOfType(typeof(AudioListener));
		}
		else
		{
			//ProcessActiveAudio();
		}
	}
    // Update is called once per frame
    //The If statement includes if InsideCollision bool is true and an input has been made. If so, then change material
    void Update()
    {
        if (currentCamera == null){
            currentCamera = GameObject.Find ("Cam VR");
            listener = currentCamera.GetComponent<AudioListener> ();
        }

        if (Input.GetKey ("space") && InsideCollision){
            GetComponent<Renderer>().sharedMaterial = Textures [1];
        }
    }
Exemple #21
0
 void Awake()
 {
     DontDestroyOnLoad(gameObject);
     sfxSource = gameObject.AddComponent<AudioSource>();
     sfxSource.volume = 0.7f;
     sfxSource.priority = 255;
     confirmPing = (AudioClip) Resources.Load("Audio/Confirm", typeof(AudioClip));
     alertPing = (AudioClip) Resources.Load("Audio/EnemyActivated", typeof(AudioClip));
     listener = FindObjectOfType<AudioListener>();
     listenerObject = listener.gameObject;
     gameObject.transform.position = listenerObject.transform.position;
 }
 void ToggleCam(Camera cam, bool enabled)
 {
     cam.enabled = enabled;
     if (switchAudioListener)
     {
         listener = cam.GetComponent<AudioListener>();
         if (listener)
         {
             listener.enabled = enabled;
         }
     }
 }
	// Use this for initialization
	void Start () {
		index = 0;
		player = GameObject.Find ("Audio Listener");
		cam = GameObject.Find("Main Camera");
		playmov = false;
		playerlistener = player.GetComponent<AudioListener>();

		//disable this audio listener at start
		this.GetComponent<AudioListener> ().enabled = false;

		//load all images into object array
		textures = Resources.LoadAll (imgfolder);
	}
Exemple #24
0
    // Use this for initialization
    void Start()
    {
        //transform.FindChild("Main Camera").GetComponents<AudioListener>().

        AudioListen = transform.FindChild("Main Camera").GetComponent<AudioListener>();

        //PlayerT =  GameObject.Find("Player").transform;
        // BlackScreen.renderer.material.color = Color.clear;
        //BlackScreen.Rotate(new Vector3(270,0,0));

        //
        // StartGameOverSequence();
    }
    // Use this for initialization
    void Start()
    {
        firstPersonCam = transform.Find("FirstPersonCharacter");
        thirdPersonCam = transform.Find("ThirdPersonCharacter");

        thirdPerson = thirdPersonCam.GetComponent<Camera>();
        firstPerson = firstPersonCam.GetComponent<Camera>();

        firstPersonAudio = firstPersonCam.GetComponent<AudioListener>();
        thirdPersonAudio = thirdPersonCam.GetComponent<AudioListener>();

        firstPersonCameraScript = firstPersonCam.GetComponent<PlayerCam>();
        thirdPersonCameraScript = thirdPersonCam.GetComponent<PlayerCam>();
    }
    public Animator animator; // This pawn's Animator (Which should be this gameObject)

    // // // UnityEngine magic methods
    // Use this for initialization when object is allocated in memory
    void Awake() {
        Debug.Log(gameObject.name + "|ComponentsList::Awake: ComponentsList has Awakened.");
        // Grab references to NetworkBehaviors, which MUST be in the root GameObject next to the NetworkIdentity.
        networkPawn = GetComponentInParent<NetworkedObserver>(); // Grab a reference to the NetworkPawn.
        inventory = GetComponentInParent<NetworkedObserverInventory>(); // Grab a reference to the Inventory.
        skin = GetComponent<NetworkedObserverSkinController>(); // Grab a reference to the SkinController.
        sounds = GetComponent<NetworkedObserverSoundController>(); // Grab a reference to the SoundController.
        // Grab references to MonoBehaviors and useful GameObjects in this object's hierarchy.
        fpcamera = GetComponentInChildren<Camera>(); // We expect the First Person camera to be attached to the Head.
        audioListener = GetComponentInChildren<AudioListener>(); // Grab a reference to the AudioListener.
        bodyController = GetComponentInParent<NetworkedObserverBodyController>(); // Grab a reference to the BodyController.
        characterController = GetComponentInParent<CharacterController>(); // Grab a reference to the CharacterController.
        animator = GetComponent<Animator>(); // Grab a reference to the Animator.
        Debug.Log(gameObject.name + "|ComponentsList::Awake: ComponentsList has finished gathering references.");
    }
Exemple #27
0
    public AudioComponent(Game game, string audioFile)
        : base(game)
    {
        Debug.Assert(s_theAudio == null, "You can only construct one AudioComponent");
        s_theAudio = this;
        m_filename = audioFile;
        m_cuePool = new StaticPool<AudioCue>(MAX_AUDIO_CUE);
        m_listener = new AudioListener();
#if AUDIO_DEBUG
        m_numPlaying = 0;
        m_numFailed = 0;
        m_numPlayed = 0;
        m_numStopped = 0;
#endif
    }
 //Call this method to play a sound
 public void SoundPlayer(string name, AudioListener listener, AudioEmitter emitter)
 {
     foreach (Sound sound in AllSounds)
     {
         if (sound.Name == name)
         {
             if (sound.Type == "SoundEffect")
                 sound.PlaySound();
             if (sound.Type == "SoundEffect3D")
                 sound.Play3DSound(listener, emitter);
             if (sound.Type == "LoopedEffect")
                 sound.PlaySound();
         }
     }
 }
Exemple #29
0
    void Start()
    {
        audioListener = GetComponent<AudioListener> ();

        if (!isLocalPlayer) {
            for (int i = 0; i < compoentsToDisable.Length; i++) {
                compoentsToDisable [i].enabled = false;
                audioListener.enabled = false;
            }
        } else {
            sceneCamera = Camera.main;
            if (sceneCamera != null)
            {
                sceneCamera.gameObject.SetActive (false);
            }
        }
    }
 void Awake()
 {
     if (FindObjectOfType<GameManager>() == null) {
         Debug.Log ("instantiating GM for the first time.");
         GMobject = new GameObject("GM");
         AL = GMobject.AddComponent<AudioListener>();
         GM = GMobject.AddComponent<GameManager>();
         GM.audio1 = GMobject.AddComponent<AudioSource>();
         GM.audio2 = GMobject.AddComponent<AudioSource>();
     } else {
         GM = FindObjectOfType<GameManager>();
         GMobject = GameObject.Find("GM");
         AL = GMobject.GetComponent<AudioListener>();
     }
     DontDestroyOnLoad(GM);
     DontDestroyOnLoad(GMobject);
     GM.StartWith("instructions");
 }
 public void PlayCue(string name, AudioListener listener, AudioEmitter emitter)
 {
     soundBank.PlayCue(name, listener, emitter);
 }
 void Init()
 {
     src      = GetComponent <AudioSource>();
     listener = GetComponent <AudioListener>();
 }
Exemple #33
0
    // Update is called once per frame
    void Update()


    {
        float[] spectrum = new float[256];

        AudioListener.GetSpectrumData(spectrum, 0, FFTWindow.Rectangular);
        Debug.Log(Mathf.Log(spectrum[0]));
        multiplyer = Mathf.Abs(Mathf.Round(spectrum[0]) + 1);
        for (int i = 1; i < spectrum.Length - 1; i++)
        {
            Debug.DrawLine(new Vector3(i - 1, Mathf.Log(spectrum[i - 1]) + 10, 2), new Vector3(i - 1, Mathf.Log(spectrum[i - 1]) + 15, 2), Color.cyan);
        }

        startTime -= Time.deltaTime;

        if (Input.GetKeyDown(KeyCode.P))
        {
            //ShuffleList();
            //InitBoard();
            Start();
        }
        //shuffle board ends

        CheckGrid();
        if (Input.GetMouseButtonDown(0))
        {
            Ray ray = Camera.main.ScreenPointToRay
                          (Input.mousePosition);
            RaycastHit2D hit =
                Physics2D.GetRayIntersection(ray, 1000);

            if (hit)
            {
                tile1 = hit.collider.gameObject;
            }
        }
        // if finger up is detected after
        // an initial tile has been chosen
        else if (Input.GetMouseButtonUp(0) && tile1)
        {
            Ray ray = Camera.main.ScreenPointToRay
                          (Input.mousePosition);
            RaycastHit2D hit =
                Physics2D.GetRayIntersection(ray, 1000);

            if (hit)
            {
                tile2 = hit.collider.gameObject;
            }

            if (tile1 && tile2)
            {
                int horzDist = (int)
                               Mathf.Abs(tile1.transform.position.x -
                                         tile2.transform.position.x);
                int vertDist = (int)
                               Mathf.Abs(tile1.transform.position.y -
                                         tile2.transform.position.y);

                if (horzDist == 1 ^ vertDist == 1)
                {
                    Tile temp = tiles[(int)tile1.transform.position.x,
                                      (int)tile1.transform.position.y];
                    tiles[(int)tile1.transform.position.x,
                          (int)tile1.transform.position.y] =
                        tiles[(int)tile2.transform.position.x,
                              (int)tile2.transform.position.y];
                    tiles[(int)tile2.transform.position.x,
                          (int)tile2.transform.position.y] = temp;



                    Vector3 tempPos = tile1.transform.position;
                    tile1.transform.position =
                        tile2.transform.position;
                    tile2.transform.position = tempPos;
                    //reset the touched tiles
                    tile1 = null;
                    tile2 = null;
                }
                else
                {
                    GetComponent <AudioSource>().Play();
                }
            }
        }
    }
    void OnGUI()
    {
        // Make sure everything is initialized
        // Use soundbank path, because Wwise project path can be empty.
        if (String.IsNullOrEmpty(WwiseSetupWizard.Settings.SoundbankPath) && WwiseSetupWizard.Settings.WwiseProjectPath == null)
        {
            WwiseSetupWizard.Settings = WwiseSettings.LoadSettings();
        }

        string initialProject = WwiseSetupWizard.Settings.WwiseProjectPath;

        if (VersionStyle == null)
        {
            InitGuiStyles();
        }
        GUILayout.Label(m_WwiseVersionString, VersionStyle);

        DrawSettingsPart();

        string newProject = WwiseSetupWizard.Settings.WwiseProjectPath; // DrawSettingsPart modifies WwiseSetupWizard.Settings.WwiseProjectPath directly.

        if (initialProject != newProject)
        {
            ApplyNewProject = true;
        }

        GUILayout.BeginVertical();
        GUILayout.FlexibleSpace();

        GUILayout.BeginHorizontal();
        GUILayout.FlexibleSpace();
        if (GUILayout.Button("OK", GUILayout.Width(60)))
        {
            if (string.IsNullOrEmpty(WwiseSetupWizard.Settings.SoundbankPath))
            {
                EditorUtility.DisplayDialog("Error", "Please fill in the required settings", "Ok");
            }

            if (AkWwiseSettingsWindow.m_oldCreateWwiseGlobal != WwiseSetupWizard.Settings.CreateWwiseGlobal)
            {
                AkInitializer[] AkInitializers = UnityEngine.Object.FindObjectsOfType(typeof(AkInitializer)) as AkInitializer[];
                if (WwiseSetupWizard.Settings.CreateWwiseGlobal == true)
                {
                    if (AkInitializers.Length == 0)
                    {
                        //No Wwise object in this scene, create one so that the sound engine is initialized and terminated properly even if the scenes are loaded
                        //in the wrong order.
                        GameObject objWwise = new GameObject("WwiseGlobal");

                        //Attach initializer and terminator components
                        AkInitializer init = objWwise.AddComponent <AkInitializer>();
                        AkWwiseProjectInfo.GetData().CopyInitSettings(init);
                    }
                }
                else
                {
                    if (AkInitializers.Length != 0 && AkInitializers[0].gameObject.name == "WwiseGlobal")
                    {
                        GameObject.DestroyImmediate(AkInitializers[0].gameObject);
                    }
                }
            }

            if (AkWwiseSettingsWindow.m_oldCreateWwiseListener != WwiseSetupWizard.Settings.CreateWwiseListener)
            {
                if (Camera.main != null)
                {
                    AkAudioListener akListener = Camera.main.GetComponentInChildren <AkAudioListener>();

                    if (WwiseSetupWizard.Settings.CreateWwiseListener)
                    {
                        if (akListener == null)
                        {
                            Camera.main.gameObject.AddComponent <AkAudioListener>();
                        }

                        // If Unity had already an audio listener, we want to remove it when adding our own.
                        AudioListener unityListener = Camera.main.GetComponentInChildren <AudioListener>();

                        if (unityListener != null)
                        {
                            Component.DestroyImmediate(unityListener);
                        }
                    }
                    else
                    {
                        if (akListener != null)
                        {
                            Component.DestroyImmediate(akListener);
                        }
                    }
                }
            }

            WwiseSettings.SaveSettings(WwiseSetupWizard.Settings);

            CloseWindow();

            // Pop the Picker window so the user can start working right away
            AkWwiseProjectInfo.GetData(); // Load data
            if (ApplyNewProject)
            {
                //Clear the data, the project path changed.
                AkWwiseProjectInfo.GetData().Reset();
                ApplyNewProject = false;
                AkWwisePicker.WwiseProjectFound = true;
            }
            AkWwiseProjectInfo.Populate();
            AkWwisePicker.PopulateTreeview();
            AkWwisePicker.init();
        }

        if (GUILayout.Button("Cancel", GUILayout.Width(60)))
        {
            WwiseSetupWizard.Settings = WwiseSettings.LoadSettings(true);
            CloseWindow();
        }
        GUILayout.Space(5);
        GUILayout.EndHorizontal();

        GUILayout.Space(5);
        GUILayout.EndVertical();
    }
 void OnEnable()
 {
     audioListener = mainCamera.GetComponent <AudioListener> ();
 }
    private void Start()
    {
        if (this.mixer == null)
        {
            this.mixer = ResourceManager.Load(MixerName) as AudioMixer;
        }
        if (this.audioRoot == null)
        {
            this.audioRoot = new GameObject(ContainerName).transform;
            this.audioRoot.SetParent(transform);
            this.audioRoot.localPosition = Vector3.zero;
        }
        if (this.fadeA_audio == null)
        {
            GameObject fadeA_GO = new GameObject(FadeA, typeof(AudioSource));
            fadeA_GO.transform.SetParent(this.audioRoot);
            this.fadeA_audio             = fadeA_GO.GetComponent <AudioSource>();
            this.fadeA_audio.playOnAwake = false;
        }
        if (this.fadeB_audio == null)
        {
            GameObject fadeB_GO = new GameObject(FadeB, typeof(AudioSource));
            fadeB_GO.transform.SetParent(this.audioRoot);
            this.fadeB_audio             = fadeB_GO.GetComponent <AudioSource>();
            this.fadeB_audio.playOnAwake = false;
        }
        if (this.UI_audio == null)
        {
            GameObject UI_GO = new GameObject(UI, typeof(AudioSource));
            UI_GO.transform.SetParent(this.audioRoot);
            this.UI_audio             = UI_GO.GetComponent <AudioSource>();
            this.UI_audio.playOnAwake = false;
        }
        if (this.effect_audios == null)
        {
            this.effect_PlayStartTime = new float[EffectChannelCount];
            this.effect_audios        = new AudioSource[EffectChannelCount];
            for (int i = 0; i < EffectChannelCount; i++)
            {
                this.effect_PlayStartTime[i] = 0.0f;
                GameObject Effect_GO = new GameObject("Effect_" + i.ToString(), typeof(AudioSource));
                Effect_GO.transform.SetParent(this.audioRoot);
                this.effect_audios[i]             = Effect_GO.GetComponent <AudioSource>();
                this.effect_audios[i].playOnAwake = false;
            }
        }
        if (this.mixer != null)
        {
            //
            this.fadeA_audio.outputAudioMixerGroup = mixer.FindMatchingGroups(BGMGroupName)[0];
            this.fadeB_audio.outputAudioMixerGroup = mixer.FindMatchingGroups(BGMGroupName)[0];

            this.UI_audio.outputAudioMixerGroup = mixer.FindMatchingGroups(UIGroupName)[0];
            for (int i = 0; i < this.effect_audios.Length; i++)
            {
                this.effect_audios[i].outputAudioMixerGroup = mixer.FindMatchingGroups(EffectGroupName)[0];
            }
        }
        if (this.audioListener == null)
        {
            this.audioListener = gameObject.AddComponent <AudioListener>();
        }

        //볼륨초기화.
        this.VolumeInit();
    }
    public void ToggleAudio()
    {
        AudioListener al = Camera.main.GetComponent <AudioListener>();

        AudioListener.volume = AudioListener.volume > 0.5f ? 0 : 1;
    }
 private bool SetOrSwitchAudioOutCapture(AudioOutCapture audioOutCapture, bool extraChecks)
 {
     if (audioOutCapture == null)
     {
         if (this.Logger.IsErrorEnabled)
         {
             this.Logger.LogError("audioOutCapture passed is null or is being destroyed");
         }
         return(false);
     }
     if (!audioOutCapture.enabled)
     {
         if (this.Logger.IsErrorEnabled)
         {
             this.Logger.LogError("audioOutCapture passed is disabled");
         }
         return(false);
     }
     if (extraChecks)
     {
         if (audioOutCapture.gameObject.activeInHierarchy)
         {
             if (this.Logger.IsErrorEnabled)
             {
                 this.Logger.LogError("The GameObject to which the audioOutCapture is attached is not active in hierarchy");
             }
             return(false);
         }
         AudioListener audioListener = audioOutCapture.GetComponent <AudioListener>();
         if (audioListener == null)
         {
             if (this.Logger.IsErrorEnabled)
             {
                 this.Logger.LogError("The AudioListener attached to the same GameObject as the audioOutCapture is null or being destroyed");
             }
             return(false);
         }
         if (!audioListener.enabled)
         {
             if (this.Logger.IsErrorEnabled)
             {
                 this.Logger.LogError("The AudioListener attached to the same GameObject as the audioOutCapture is disabled");
             }
             return(false);
         }
     }
     if (this.ac != null)
     {
         if (this.ac != audioOutCapture)
         {
             if (this.started)
             {
                 this.ac.OnAudioFrame -= this.OnAudioOutFrameFloat;
             }
         }
         else
         {
             if (this.Logger.IsErrorEnabled)
             {
                 this.Logger.LogError("The same audioOutCapture is being used already");
             }
             return(false);
         }
     }
     this.ac = audioOutCapture;
     if (this.started)
     {
         this.ac.OnAudioFrame += this.OnAudioOutFrameFloat;
     }
     return(true);
 }
Exemple #39
0
        private void Start()
        {
            cam      = GetComponent <Camera>();
            listener = GetComponent <AudioListener>();
            var splitters = FindObjectsOfType <CameraSplitter>().ToList();

            int count = splitters.Count;
            int index = SplitscreenIndex;

            switch (count)
            {
            case 2:
                cam.rect = new Rect(0, index == 0 ? 0.5f : 0f, 1, 0.5f);
                break;

            case 3:
                switch (index)
                {
                case 0:
                    cam.rect = new Rect(0, 0.5f, 1, 0.5f);
                    break;

                case 1:
                    cam.rect = new Rect(0, 0, 0.5f, 0.5f);
                    break;

                case 2:
                    cam.rect = new Rect(0.5f, 0, 0.5f, 0.5f);
                    break;
                }
                break;

            case 4:
                switch (index)
                {
                case 0:
                    cam.rect = new Rect(0, 0.5f, 0.5f, 0.5f);
                    break;

                case 1:
                    cam.rect = new Rect(0.5f, 0.5f, 0.5f, 0.5f);
                    break;

                case 2:
                    cam.rect = new Rect(0, 0, 0.5f, 0.5f);
                    break;

                case 3:
                    cam.rect = new Rect(0.5f, 0, 0.5f, 0.5f);
                    break;
                }
                break;

            default:
                cam.rect = new Rect(0, 0, 1, 1);
                break;
            }

            if (listener)
            {
                listener.enabled = index == 0;
            }
        }
Exemple #40
0
 void Start()
 {
     ResetResult();
     audioListener       = GetComponent <AudioListener>();
     dictationRecognizer = InstantiateDictationRecognizer();
 }
Exemple #41
0
 void Update()
 {
     AudioListener.GetSpectrumData(spectrum, 0, FFTWindow.Rectangular);
     transform.localScale = originalScale + Vector3.one * (spectrum[3] * 0.1f);
 }
    void Update()
    {
        if (isEnabled)
        {
            //sampleChannel = Mathf.Clamp(sampleChannel, 0, 1); //force the channel to be valid

            if (sourceType != SourceType.Custom)
            {
                if (sourceType == SourceType.AudioListener)
                {
                    AudioListener.GetSpectrumData(spectrum, sampleChannel, windowUsed); //get the spectrum data
                }
                else
                {
                    audioSource.GetSpectrumData(spectrum, sampleChannel, windowUsed); //get the spectrum data
                }
            }


            // MODIFIED (BEGIN)

            Debug.Log("Muse FFT Spectrum");

            spectrum = new float[Muse_FFT_Size];

            // TO LINK WITH MUSE

            /*
             * for (int i = 0; i < spectrum.Length; i++) //for each float in the output
             * {
             *  spectrum[i] = Muse_FFT_data[i];
             * }
             */



            for (int i = 0; i < spectrum.Length; i++) //for each float in the output
            {
                spectrum[i] = i / 10;
            }


            // MODIFIED (END)



#if UNITY_EDITOR    //allows for editing curve while in play mode, disabled in build for optimisation
            float spectrumLength = bars.Length * (1 + barXSpacing);
            float midPoint       = spectrumLength / 2;

            float   curveAngleRads = 0, curveRadius = 0, halfwayAngleR = 0, halfwayAngleD = 0;
            Vector3 curveCentreVector = Vector3.zero;
            if (barCurveAngle > 0)
            {
                curveAngleRads = (barCurveAngle / 360) * (2 * Mathf.PI);
                curveRadius    = spectrumLength / curveAngleRads;

                halfwayAngleR     = curveAngleRads / 2;
                halfwayAngleD     = barCurveAngle / 2;
                curveCentreVector = new Vector3(0, 0, -curveRadius);
                if (barCurveAngle == 360)
                {
                    curveCentreVector = new Vector3(0, 0, 0);
                }
            }
#endif

            for (int i = 0; i < bars.Length; i++)
            {
                Transform bar = bars [i];

                float value;
                float trueSampleIndex;

                //GET SAMPLES
                if (useLogarithmicFrequency)
                {
                    //LOGARITHMIC FREQUENCY SAMPLING
                    trueSampleIndex = highFrequencyTrim * (highestLogFreq - Mathf.Log(bars.Length + 1 - i, 2)) * logFreqMultiplier; //gets the index equiv of the logified frequency

                    //^that really needs explaining.
                    //'logarithmic frequencies' just means we want more of the lower frequencies and less of the high ones.
                    //a normal log2 graph will quickly go past 1-5 and spend much more time on stuff above that, but we want the opposite
                    //so by doing log2(max(i)) - log2(max(i) - i), we get a flipped log graph
                    //(make a graph of log2(64)-log2(64-x) to see what I mean)
                    //this isn't finished though, because that graph doesn't actually map the bar index (x) to the spectrum index (y).
                    //logFreqMultiplier stretches the grpah upwards so that the highest value (log2(max(i)))hits the highest frequency.
                    //also 1 gets added to barAmount pretty much everywhere, because without it, the log hits (barAmount-1,max(freq))
                }
                else
                {
                    //LINEAR (SCALED) FREQUENCY SAMPLING
                    trueSampleIndex = i * linearSampleStretch;
                }

                //the true sample is usually a decimal, so we need to lerp between the floor and ceiling of it.

                int sampleIndexFloor = Mathf.FloorToInt(trueSampleIndex);
                sampleIndexFloor = Mathf.Clamp(sampleIndexFloor, 0, spectrum.Length - 2);                                 //just keeping it within the spectrum array's range

                float sampleIndexDecimal = trueSampleIndex % 1;                                                           //gets the decimal point of the true sample, for lerping

                value = Mathf.SmoothStep(spectrum[sampleIndexFloor], spectrum[sampleIndexFloor + 1], sampleIndexDecimal); //smoothly interpolate between the two samples using the true index's decimal.

                //MANIPULATE & APPLY SAMPLES
                if (multiplyByFrequency) //multiplies the amplitude by the true sample index
                {
                    value = value * (trueSampleIndex + 1);
                }

                value = Mathf.Sqrt(value); //compress the amplitude values by sqrt(x)



                //DAMPENING
                //Vector3 oldScale = bar.localScale;
                float oldYScale = oldYScales[i], newYScale;
                if (value * barYScale > oldYScale)
                {
                    newYScale = Mathf.Lerp(oldYScale, Mathf.Max(value * barYScale, barMinYScale), attackDamp);
                }
                else
                {
                    newYScale = Mathf.Lerp(oldYScale, Mathf.Max(value * barYScale, barMinYScale), decayDamp);
                }

                bar.localScale = new Vector3(barXScale, newYScale, 1);

                oldYScales[i] = newYScale;


                //set colour
                if (useColorGradient && materialColourCanBeUsed)
                {
                    float newColorVal = colorValueCurve.Evaluate(value);
                    float oldColorVal = oldColorValues[i];

                    if (newColorVal > oldColorVal)
                    {
                        if (colorAttackDamp != 1)
                        {
                            newColorVal = Mathf.Lerp(oldColorVal, newColorVal, colorAttackDamp);
                        }
                    }
                    else
                    {
                        if (colorDecayDamp != 1)
                        {
                            newColorVal = Mathf.Lerp(oldColorVal, newColorVal, colorDecayDamp);
                        }
                    }

                    barMaterials[i].SetFloat(materialValId, newColorVal);

                    oldColorValues[i] = newColorVal;
                }

#if UNITY_EDITOR
                //realtime modifications for Editor only
                if (barCurveAngle > 0)
                {
                    float position      = ((float)i / bars.Length);
                    float thisBarAngleR = (position * curveAngleRads) - halfwayAngleR;
                    float thisBarAngleD = (position * barCurveAngle) - halfwayAngleD;
                    bar.localRotation = Quaternion.Euler(barXRotation, thisBarAngleD, 0);
                    bar.localPosition = new Vector3(Mathf.Sin(thisBarAngleR) * curveRadius, 0, Mathf.Cos(thisBarAngleR) * curveRadius) + curveCentreVector;
                }
                else
                {
                    bar.localPosition = new Vector3(i * (1 + barXSpacing) - midPoint, 0, 0);
                }
#endif
            }
        }
        else           //switched off
        {
            foreach (Transform bar in bars)
            {
                bar.localScale = Vector3.Lerp(bar.localScale, new Vector3(1, barMinYScale, 1), decayDamp);
            }
        }
        if ((Time.unscaledTime - lastMicRestartTime) > micRestartWait)
        {
            RestartMicrophone();
        }
    }
 public void SetAudioListenerAsAudioSourceOutput(AudioListener output)
 {
     audioSource.Output = output;
 }
Exemple #44
0
    static public void CheckWwiseGlobalExistance()
    {
        WwiseSettings settings = WwiseSettings.LoadSettings();

#if UNITY_5_0 || UNITY_5_1 || UNITY_5_2
        if (!settings.OldProject && (String.IsNullOrEmpty(EditorApplication.currentScene) || s_CurrentScene != EditorApplication.currentScene))
#else
        string activeSceneName = UnityEditor.SceneManagement.EditorSceneManager.GetActiveScene().name;
        if (!settings.OldProject && s_CurrentScene != activeSceneName)
#endif
        {
            // Look for a game object which has the initializer component
            AkInitializer[] AkInitializers = UnityEngine.Object.FindObjectsOfType(typeof(AkInitializer)) as AkInitializer[];
            if (AkInitializers.Length == 0)
            {
                if (settings.CreateWwiseGlobal == true)
                {
                    //No Wwise object in this scene, create one so that the sound engine is initialized and terminated properly even if the scenes are loaded
                    //in the wrong order.
                    GameObject objWwise = new GameObject("WwiseGlobal");

                    //Attach initializer and terminator components
                    AkInitializer init = objWwise.AddComponent <AkInitializer>();
                    AkWwiseProjectInfo.GetData().CopyInitSettings(init);
                }
            }
            else
            {
                if (settings.CreateWwiseGlobal == false && AkInitializers[0].gameObject.name == "WwiseGlobal")
                {
                    GameObject.DestroyImmediate(AkInitializers[0].gameObject);
                }
                //All scenes will share the same initializer.  So expose the init settings consistently across scenes.
                AkWwiseProjectInfo.GetData().CopyInitSettings(AkInitializers[0]);
            }

            AkAudioListener[] akAudioListeners = UnityEngine.Object.FindObjectsOfType(typeof(AkAudioListener)) as AkAudioListener[];
            if (akAudioListeners.Length == 0)
            {
                // Remove the audio listener script
                if (Camera.main != null && settings.CreateWwiseListener == true)
                {
                    AudioListener listener = Camera.main.gameObject.GetComponent <AudioListener>();
                    if (listener != null)
                    {
                        Component.DestroyImmediate(listener);
                    }

                    // Add the AkAudioListener script
                    if (Camera.main.gameObject.GetComponent <AkAudioListener>() == null)
                    {
                        Camera.main.gameObject.AddComponent <AkAudioListener>();
                    }
                }
            }
            else
            {
                foreach (AkAudioListener akListener in akAudioListeners)
                {
                    if (settings.CreateWwiseListener == false && akListener.gameObject == Camera.main.gameObject)
                    {
                        Component.DestroyImmediate(akListener);
                    }
                }
            }


#if UNITY_5_0 || UNITY_5_1 || UNITY_5_2
            s_CurrentScene = EditorApplication.currentScene;
#else
            s_CurrentScene = activeSceneName;
#endif
        }
    }
Exemple #45
0
 public WXAudioListener(AudioListener audioListener, GameObject gameObject)
 {
     this.gameObject    = gameObject;
     this.audioListener = audioListener;
 }
 private static void DrawIcon(AudioListener listener)
 {
     Gizmos.DrawIcon(listener.SceneObject.Position,
                     EditorBuiltin.GetSceneViewIcon(SceneViewIcon.AudioListener), false);
 }
 void Start()
 {
     audioListener = GetComponent <AudioListener>();
     audioManager  = GetComponent <AudioManager>();
 }
    void Update()
    {
        var Source = GetComponent <AudioSource>();

        if (!Source)
        {
            Debug.LogError("AudioSource not found.");
            return;
        }

        // 設定した周波数までのパワースペクトラムの総和 / 全帯域のパワースペクトラムの総和 を求める
        // 参考:https://www.vocal.com/noise-reduction/single-channel-wind-noise-detection/
        Source.GetSpectrumData(Spectrum, 0, FFTWindow.Hamming);

        var SumOfPowerSpectrum = 0.0f;

        foreach (var Bin in Spectrum)
        {
            SumOfPowerSpectrum += Bin;
        }
        var LowBandSumOfPowerSpectrum = 0.0f;
        var BinWidth = AudioSettings.outputSampleRate / Spectrum.Length;

        for (int i = 0; i < Mathf.FloorToInt(BreathFrequency / BinWidth); ++i)
        {
            LowBandSumOfPowerSpectrum += Spectrum[i];
        }

        var WND_1 = LowBandSumOfPowerSpectrum / SumOfPowerSpectrum;

        // 音量を求める
        AudioListener.GetOutputData(WaveData, 1);
        var Volume = WaveData.Select(x => x * x).Sum() / WaveData.Length;

        // 吐息レベルを設定する
        if (Volume < VolumeThreashold)
        {
            BreathLevel = 0.0f;
        }
        else if (WND_1 < Threashold)
        {
            BreathLevel = Volume;
        }
        else
        {
            BreathLevel = 0.0f;
        }

        // デバッグ描画
        if (DebugDraw && Sphere && ThreasholdSphere)
        {
            Color SphereColor;
            if (Volume < VolumeThreashold)
            {
                SphereColor = Color.green;
            }
            else if (WND_1 < Threashold)
            {
                SphereColor = Color.cyan;
            }
            else
            {
                SphereColor = Color.yellow;
            }
            Sphere.GetComponent <MeshRenderer>().material.color = SphereColor;
            Sphere.transform.localScale           = Vector3.one * WND_1 * 10;
            ThreasholdSphere.transform.localScale = Vector3.one * Threashold * 10;
        }
    }
 /// <summary>
 /// Set the AudioListener to be used with this WebRtcAudioDsp
 /// </summary>
 /// <param name="audioListener">The audioListener to be used</param>
 /// <returns>Success or failure</returns>
 public bool SetOrSwitchAudioListener(AudioListener audioListener)
 {
     return(this.SetOrSwitchAudioListener(audioListener, true));
 }
 public void Volumen(float v)
 {
     AudioListener.set_volume(v);
     this._volumen = v;
     this.VolumenText.set_text((this._volumen * 100f).ToString("00") + "%");
 }
Exemple #51
0
 // Use this for initialization
 void Start()
 {
     thirdAudio = third.GetComponent <AudioListener> ();
     orbitAudio = orbit.GetComponent <AudioListener> ();
     fpsAudio   = fps.GetComponent <AudioListener> ();
 }
Exemple #52
0
 public static AudioSource PlaySound(AudioListener listener, string sound_location, bool restart_if_playing)
 {
     return(PlaySound(listener, sound_location, restart_if_playing, false));
 }
Exemple #53
0
 internal void SetCurrentListener(AudioListener audioListener)
 {
     m_CurrentListener = audioListener;
 }
Exemple #54
0
    void Update()
    {
        if (isEnabled)
        {
            //sampleChannel = Mathf.Clamp(sampleChannel, 0, 1); //force the channel to be valid

            if (sourceType != SourceType.Custom)
            {
                if (sourceType == SourceType.AudioListener)
                {
#if WEB_MODE
                    SSWebInteract.GetSpectrumData(spectrum);                            //get the spectrum data from the JS lib
#else
                    AudioListener.GetSpectrumData(spectrum, sampleChannel, windowUsed); //get the spectrum data
                    //Debug.Log(spectrum[0]);
#endif
                }
                else if (sourceType == SourceType.FMod)
                {
                    spectrum = SoundController.Instance.GetSpectrum();
                }
                else
                {
                    audioSource.GetSpectrumData(spectrum, sampleChannel, windowUsed); //get the spectrum data
                }
            }


#if UNITY_EDITOR    //allows for editing curve while in play mode, disabled in build for optimisation
            float spectrumLength = bars.Length * (1 + barXSpacing);
            float midPoint       = spectrumLength / 2;

            float   curveAngleRads = 0, curveRadius = 0, halfwayAngleR = 0, halfwayAngleD = 0;
            Vector3 curveCentreVector = Vector3.zero;
            if (barCurveAngle > 0)
            {
                curveAngleRads = (barCurveAngle / 360) * (2 * Mathf.PI);
                curveRadius    = spectrumLength / curveAngleRads;

                halfwayAngleR     = curveAngleRads / 2;
                halfwayAngleD     = barCurveAngle / 2;
                curveCentreVector = new Vector3(0, 0, -curveRadius);
                if (barCurveAngle == 360)
                {
                    curveCentreVector = new Vector3(0, 0, 0);
                }
            }
#endif
#if WEB_MODE
            float freqLim = frequencyLimitHigh * 0.76f; //AnalyserNode.getFloatFrequencyData doesn't fill the array, for some reason
#else
            float freqLim = frequencyLimitHigh;
#endif

            for (int i = 0; i < bars.Length; i++)
            {
                Transform bar = bars [i];

                float value;
                float trueSampleIndex;

                //GET SAMPLES
                if (useLogarithmicFrequency)
                {
                    //LOGARITHMIC FREQUENCY SAMPLING

                    //trueSampleIndex = highFrequencyTrim * (highestLogFreq - Mathf.Log(barAmount + 1 - i, 2)) * logFreqMultiplier; //old version

                    trueSampleIndex = Mathf.Lerp(frequencyLimitLow, freqLim, (highestLogFreq - Mathf.Log(barAmount + 1 - i, 2)) / highestLogFreq) * frequencyScaleFactor;

                    //'logarithmic frequencies' just means we want to bias to the lower frequencies.
                    //by doing log2(max(i)) - log2(max(i) - i), we get a flipped log graph
                    //(make a graph of log2(64)-log2(64-x) to see what I mean)
                    //this isn't finished though, because that graph doesn't actually map the bar index (x) to the spectrum index (y).
                    //then we divide by highestLogFreq to make the graph to map 0-barAmount on the x axis to 0-1 in the y axis.
                    //we then use this to Lerp between frequency limits, and then an index is calculated.
                    //also 1 gets added to barAmount pretty much everywhere, because without it, the log hits (barAmount-1,max(freq))
                }
                else
                {
                    //LINEAR (SCALED) FREQUENCY SAMPLING
                    //trueSampleIndex = i * linearSampleStretch; //don't like this anymore

                    trueSampleIndex = Mathf.Lerp(frequencyLimitLow, freqLim, ((float)i) / barAmount) * frequencyScaleFactor;
                    //sooooo this one's gotten fancier...
                    //firstly a lerp is used between frequency limits to get the 'desired frequency', then it's divided by the outputSampleRate (/2, who knows why) to get its location in the array, then multiplied by numSamples to get an index instead of a fraction.
                }

                //the true sample is usually a decimal, so we need to lerp between the floor and ceiling of it.

                int sampleIndexFloor = Mathf.FloorToInt(trueSampleIndex);
                sampleIndexFloor = Mathf.Clamp(sampleIndexFloor, 0, spectrum.Length - 2);                                                 //just keeping it within the spectrum array's range

                value = Mathf.SmoothStep(spectrum[sampleIndexFloor], spectrum[sampleIndexFloor + 1], trueSampleIndex - sampleIndexFloor); //smoothly interpolate between the two samples using the true index's decimal.

                //MANIPULATE & APPLY SAMPLES
                if (multiplyByFrequency) //multiplies the amplitude by the true sample index
                {
#if WEB_MODE
                    value = value * (Mathf.Log(trueSampleIndex + 1) + 1);  //different due to how the WebAudioAPI outputs spectrum data.
#else
                    value = value * (trueSampleIndex + 1);
#endif
                }

#if !WEB_MODE
                value = Mathf.Sqrt(value); //compress the amplitude values by sqrt(x)
#endif

                //DAMPENING
                //Vector3 oldScale = bar.localScale;
                float oldYScale = oldYScales[i], newYScale;
                if (value * barYScale > oldYScale)
                {
                    newYScale = Mathf.Lerp(oldYScale, Mathf.Max(value * barYScale, barMinYScale), attackDamp);
                }
                else
                {
                    newYScale = Mathf.Lerp(oldYScale, Mathf.Max(value * barYScale, barMinYScale), decayDamp);
                }

                bar.localScale = new Vector3(barXScale, newYScale, 1);

                oldYScales[i] = newYScale;

                //set colour
                if (useColorGradient && materialColourCanBeUsed)
                {
                    float newColorVal = colorValueCurve.Evaluate(value);
                    float oldColorVal = oldColorValues[i];

                    if (newColorVal > oldColorVal)
                    {
                        if (colorAttackDamp != 1)
                        {
                            newColorVal = Mathf.Lerp(oldColorVal, newColorVal, colorAttackDamp);
                        }
                    }
                    else
                    {
                        if (colorDecayDamp != 1)
                        {
                            newColorVal = Mathf.Lerp(oldColorVal, newColorVal, colorDecayDamp);
                        }
                    }

                    barMaterials[i].SetFloat(materialValId, newColorVal);

                    oldColorValues[i] = newColorVal;
                }

#if UNITY_EDITOR
                //realtime modifications for Editor only
                if (barCurveAngle > 0)
                {
                    float position      = ((float)i / bars.Length);
                    float thisBarAngleR = (position * curveAngleRads) - halfwayAngleR;
                    float thisBarAngleD = (position * barCurveAngle) - halfwayAngleD;
                    bar.localRotation = Quaternion.Euler(barXRotation, thisBarAngleD, 0);
                    bar.localPosition = new Vector3(Mathf.Sin(thisBarAngleR) * curveRadius, 0, Mathf.Cos(thisBarAngleR) * curveRadius) + curveCentreVector;
                }
                else
                {
                    bar.localPosition = new Vector3(i * (1 + barXSpacing) - midPoint, 0, 0);
                }
#endif
            }
        }
        else   //switched off
        {
            foreach (Transform bar in bars)
            {
                bar.localScale = Vector3.Lerp(bar.localScale, new Vector3(1, barMinYScale, 1), decayDamp);
            }
        }
        if ((Time.unscaledTime - lastMicRestartTime) > micRestartWait)
        {
            RestartMicrophone();
        }
    }
Exemple #55
0
 void Start()
 {
     audioListener         = this.gameObject.AddComponent(typeof(AudioListener)) as AudioListener;
     audioListener.enabled = true;
 }
Exemple #56
0
    public void SpawnMyplayer()
    {
        listener                   = GameObject.FindGameObjectWithTag("MainCamera").GetComponent <AudioListener> ();
        listener.enabled           = false;
        countDownManager.countDown = count;
        isInGame                   = true;
        redTeam  = 0;
        blueTeam = 0;
        foreach (PhotonPlayer pl in PhotonNetwork.playerList)
        {
            if (pl.GetTeam().ToString() == "red")
            {
                redTeam++;
            }
            else if (pl.GetTeam().ToString() == "blue")
            {
                blueTeam++;
            }
        }
        setButton.gameObject.SetActive(false);
        RoomPanel.gameObject.SetActive(false);
        if (spawnSpots == null)
        {
            Debug.LogError("no SpawnSpot");
            return;
        }
        Debug.Log(spawnSpots.Length);
        CheckPlayers();
        Debug.Log(numberPlayers);

        //use the playerID to decide where to  spawn
        SpawnSpot mySpawnSpot = spawnSpots[playerPrefabsIndex % 8];

        if (playerPrefabsIndex == 0)
        {
            myPlayerGO = (GameObject)PhotonNetwork.Instantiate("logicman_3", mySpawnSpot.transform.position, mySpawnSpot.transform.rotation, 0);
        }
        else if (playerPrefabsIndex == 1)
        {
            myPlayerGO = (GameObject)PhotonNetwork.Instantiate("logicman_1", mySpawnSpot.transform.position, mySpawnSpot.transform.rotation, 0);
        }
        else if (playerPrefabsIndex == 2)
        {
            myPlayerGO = (GameObject)PhotonNetwork.Instantiate("logicman_4", mySpawnSpot.transform.position, mySpawnSpot.transform.rotation, 0);
        }
        else if (playerPrefabsIndex == 3)
        {
            myPlayerGO = (GameObject)PhotonNetwork.Instantiate("logicman2", mySpawnSpot.transform.position, mySpawnSpot.transform.rotation, 0);
        }
        else if (playerPrefabsIndex == 4)
        {
            myPlayerGO = (GameObject)PhotonNetwork.Instantiate("Pirate", mySpawnSpot.transform.position, mySpawnSpot.transform.rotation, 0);
        }
        else if (playerPrefabsIndex == 5)
        {
            myPlayerGO = (GameObject)PhotonNetwork.Instantiate("Policeman", mySpawnSpot.transform.position, mySpawnSpot.transform.rotation, 0);
        }
        else if (playerPrefabsIndex == 6)
        {
            myPlayerGO = (GameObject)PhotonNetwork.Instantiate("ScientistRig", mySpawnSpot.transform.position, mySpawnSpot.transform.rotation, 0);
        }
        else
        {
            myPlayerGO = (GameObject)PhotonNetwork.Instantiate("TrainDriver", mySpawnSpot.transform.position, mySpawnSpot.transform.rotation, 0);
        }
        myPlayerGO.gameObject.GetComponent <AudioListener> ().enabled = true;

        //ENABLED THE DISABLED COMPONENT IN THE PLAYER
        //為了不會控制到別人的PLAYER
        myPlayerGO.GetComponent <RigidBodyFPSWalker> ().enabled = true;
        myPlayerGO.GetComponent <WebBomb> ().enabled            = true;
        myPlayerGO.GetComponent <playertransition> ().enabled   = true;
        myPlayerGO.transform.FindChild("Camera").gameObject.SetActive(true);
        myPlayerGO.GetComponent <RigidBodyFPSWalker> ().speed          = speed;
        myPlayerGO.GetComponent <RigidBodyFPSWalker> ().oriSpeed       = speed;
        myPlayerGO.GetComponent <RigidBodyFPSWalker> ().strengthOfBomb = strength;
        myPlayerGO.GetComponent <RigidBodyFPSWalker> ().numberOfBomb   = bomb;
        myPlayerGO.GetComponent <RigidBodyFPSWalker> ().currentBomb    = bomb;
        standbyCamera.enabled = false;
    }
        private void Audio3DGUI()
        {
            EditorGUILayout.Slider(this.m_DopplerLevel, 0f, 5f, AudioSourceInspector.ms_Styles.dopplerLevelLabel, new GUILayoutOption[0]);
            EditorGUI.BeginChangeCheck();
            AudioSourceInspector.AnimProp(AudioSourceInspector.ms_Styles.spreadLabel, this.m_AudioCurves[2].curveProp, 0f, 360f, true);
            if (this.m_RolloffMode.hasMultipleDifferentValues || (this.m_RolloffMode.enumValueIndex == 2 && this.m_AudioCurves[0].curveProp.hasMultipleDifferentValues))
            {
                EditorGUILayout.TargetChoiceField(this.m_AudioCurves[0].curveProp, AudioSourceInspector.ms_Styles.rolloffLabel, new TargetChoiceHandler.TargetChoiceMenuFunction(AudioSourceInspector.SetRolloffToTarget), new GUILayoutOption[0]);
            }
            else
            {
                EditorGUILayout.PropertyField(this.m_RolloffMode, AudioSourceInspector.ms_Styles.rolloffLabel, new GUILayoutOption[0]);
                if (this.m_RolloffMode.enumValueIndex != 2)
                {
                    EditorGUI.BeginChangeCheck();
                    EditorGUILayout.PropertyField(this.m_MinDistance, new GUILayoutOption[0]);
                    if (EditorGUI.EndChangeCheck())
                    {
                        this.m_MinDistance.floatValue = Mathf.Clamp(this.m_MinDistance.floatValue, 0f, this.m_MaxDistance.floatValue / 1.01f);
                    }
                }
                else
                {
                    using (new EditorGUI.DisabledScope(true))
                    {
                        EditorGUILayout.LabelField(this.m_MinDistance.displayName, AudioSourceInspector.ms_Styles.controlledByCurveLabel, new GUILayoutOption[0]);
                    }
                }
            }
            EditorGUI.BeginChangeCheck();
            EditorGUILayout.PropertyField(this.m_MaxDistance, new GUILayoutOption[0]);
            if (EditorGUI.EndChangeCheck())
            {
                this.m_MaxDistance.floatValue = Mathf.Min(Mathf.Max(Mathf.Max(this.m_MaxDistance.floatValue, 0.01f), this.m_MinDistance.floatValue * 1.01f), 1000000f);
            }
            if (EditorGUI.EndChangeCheck())
            {
                this.m_RefreshCurveEditor = true;
            }
            Rect aspectRect = GUILayoutUtility.GetAspectRect(1.333f, GUI.skin.textField);

            aspectRect.xMin += EditorGUI.indent;
            if (Event.current.type != EventType.Layout && Event.current.type != EventType.Used)
            {
                this.m_CurveEditor.rect = new Rect(aspectRect.x, aspectRect.y, aspectRect.width, aspectRect.height);
            }
            this.UpdateWrappersAndLegend();
            GUI.Label(this.m_CurveEditor.drawRect, GUIContent.none, "TextField");
            this.m_CurveEditor.hRangeLocked = Event.current.shift;
            this.m_CurveEditor.vRangeLocked = EditorGUI.actionKey;
            this.m_CurveEditor.OnGUI();
            if (base.targets.Length == 1)
            {
                AudioSource   audioSource = (AudioSource)this.target;
                AudioListener x           = (AudioListener)UnityEngine.Object.FindObjectOfType(typeof(AudioListener));
                if (x != null)
                {
                    float magnitude = (AudioUtil.GetListenerPos() - audioSource.transform.position).magnitude;
                    this.DrawLabel("Listener", magnitude, aspectRect);
                }
            }
            this.DrawLegend();
            AudioSourceInspector.AudioCurveWrapper[] audioCurves = this.m_AudioCurves;
            for (int i = 0; i < audioCurves.Length; i++)
            {
                AudioSourceInspector.AudioCurveWrapper audioCurveWrapper = audioCurves[i];
                if (this.m_CurveEditor.getCurveWrapperById(audioCurveWrapper.id) != null && this.m_CurveEditor.getCurveWrapperById(audioCurveWrapper.id).changed)
                {
                    AnimationCurve curve = this.m_CurveEditor.getCurveWrapperById(audioCurveWrapper.id).curve;
                    if (curve.length > 0)
                    {
                        audioCurveWrapper.curveProp.animationCurveValue = curve;
                        this.m_CurveEditor.getCurveWrapperById(audioCurveWrapper.id).changed = false;
                        if (audioCurveWrapper.type == AudioSourceInspector.AudioCurveType.Volume)
                        {
                            this.m_RolloffMode.enumValueIndex = 2;
                        }
                    }
                }
            }
        }
Exemple #58
0
 void Awake()
 {
     listener = Camera.main.GetComponent <AudioListener>();
     instance = this;
 }
Exemple #59
0
    private void OnGUI()
    {
        //m_FreqCrossover[0] = m_FreqCrossoverLowestFreq;
        //for (int i = 1; i < m_FreqCrossover.Length; i++)
        //{
        //    m_FreqCrossover[i] = m_FreqCrossover[i - 1] * m_BandRatio;
        //}

        if (m_UseListener)
        {
            AudioListener.GetSpectrumData(m_SpectrumLeft, 0, FFTWindow.Rectangular);
            AudioListener.GetSpectrumData(m_SpectrumRight, 1, FFTWindow.Rectangular);
        }
        else if (m_AudioSource)
        {
            m_AudioSource.GetSpectrumData(m_SpectrumLeft, 0, FFTWindow.Rectangular);
        }

        //GuiHelper.SetOrigin(GuiHelper.Origin.BottomLeft);

        float spectrumFreq = 0.0f;
        int   freqBand     = 0;
        //float barWidth = m_HScale;
        float maxValue = 0.0f;

        //float accumValue = 0.0f;
        //int accumCount = 0;
        //float average = 0.0f;
        //float power = 0.0f;
        for (int i = 0; i < m_SpectrumSize; ++i)
        {
            maxValue = Mathf.Max(maxValue, m_SpectrumLeft[i]);
            maxValue = Mathf.Max(maxValue, m_SpectrumRight[i]);

            //accumValue += m_SpectrumLeft[i];
            //accumValue += m_SpectrumRight[i];
            //accumCount += 2;

            //if (m_SpectrumLeft[i] > 0.0001f) // arbitrary cut-off to filter out noise
            //{
            //	average += m_SpectrumLeft[i] * spectrumFreq;
            //	power += m_SpectrumLeft[i];
            //}
            //if (m_SpectrumRight[i] > 0.0001f) // arbitrary cut-off to filter out noise
            //{
            //	average += m_SpectrumRight[i] * spectrumFreq;
            //	power += m_SpectrumRight[i];
            //}

            spectrumFreq += m_SpectrumFreqStep;

            if (spectrumFreq >= m_FreqCrossover[freqBand] || i == (m_SpectrumSize - 1))
            {
                // decibels relative to full scale
                float dBFS = 20.0f * Mathf.Log10(maxValue);                             // range -infinity -> 0

                // clamp to desired dB range for bar graph
                float value = Mathf.Clamp01(1.0f + (dBFS / m_dBRange));                         // range 0.0 -> 1.0
                SpectrumValues[freqBand] = value;

                if (DebugDraw)
                {
                    ////float centre_x = Screen.width / 2 - (m_FreqCrossover.Length / 2) * barWidth + (freqBand + 0.5f) * barWidth;

                    ////if (InvertedDebugDraw)
                    ////{
                    ////    Vector2 bottom = new Vector2(centre_x, Screen.height - value * m_VScale);
                    ////    Vector2 top = new Vector2(centre_x, Screen.height);
                    ////    //GuiHelper.DrawLine(bottom, top, m_BarTexture, barWidth);
                    ////}
                    ////else
                    ////{
                    ////    Vector2 bottom = new Vector2(centre_x, 0);
                    ////    Vector2 top = new Vector2(centre_x, value * m_VScale);
                    ////    //GuiHelper.DrawLine(bottom, top, m_BarTexture, barWidth);
                    ////}
                }

                // reset for next frequency band
                maxValue = 0.0f;
                //accumValue = 0.0f;
                //accumCount = 0;

                freqBand++;
                if (freqBand >= m_FreqCrossover.Length || freqBand >= SpectrumValues.Length)
                {
                    break;
                }
            }
        }

        // find dominant frequency
        //float dominantHz = (power > 0.0001f) ? (average / power) : 0.0f;
        //Utils.Log(dominantHz.ToString("0"));
    }
Exemple #60
0
    void Update()
    {
        float[] spectrum = new float[1024]; AudioListener.GetSpectrumData(spectrum, 0, FFTWindow.Hamming);
        if (playR)
        {
            if (g > 0)
            {
                g -= changeSpeed * Time.deltaTime;
            }
            r += changeSpeed * Time.deltaTime;
            if (r > 0.6f)
            {
                playB = true;
                playR = false;
            }
        }
        if (playB)
        {
            b += changeSpeed * Time.deltaTime;
            r -= changeSpeed * Time.deltaTime;
            if (b > 0.6f)
            {
                playG = true;
                playB = false;
            }
        }
        if (playG)
        {
            b -= changeSpeed * Time.deltaTime;
            g += changeSpeed * Time.deltaTime;
            if (g > 0.6f)
            {
                playRB = true;
                playG  = false;
            }
        }
        if (playRB)
        {
            if (g > 0)
            {
                g -= changeSpeed * Time.deltaTime;
            }
            if (b < 0.8f && !finishup)
            {
                r += changeSpeed * Time.deltaTime;
                b += changeSpeed * Time.deltaTime * 2;
                if (b > 0.8f)
                {
                    finishup = true;
                }
            }
            if (finishup && !playR)
            {
                r -= changeSpeed * Time.deltaTime;
                b -= changeSpeed * Time.deltaTime;
                if (b < 0.1f)
                {
                    playR    = true;
                    finishup = false;
                    playRB   = false;
                }
            }
        }
        float theLVL  = spectrum[3] * (density);
        float MidLvl  = spectrum[7] * (density);
        float highLvl = spectrum[12] * (density);

        peak     -= 3f * Time.deltaTime;
        MidPeak  -= 3f * Time.deltaTime;
        HighPeak -= 3f * Time.deltaTime;
        Vector3 armsCheck = arms.transform.eulerAngles;

        if (peak > 1)
        {
            rndHead.transform.Rotate(Vector3.forward * 2f * peak);
            rndHead2.transform.Rotate(Vector3.forward * -2f * peak);
        }
        rndHead.transform.Rotate(Vector3.up * 2f);
        rndHead2.transform.Rotate(Vector3.up * -2f);
        checker = armsCheck.x;

        if (armsCheck.x <= 85)
        {
            if (switchArms)
            {
                switchArms = false;
            }
            if (!switchArms)
            {
                switchArms = true;
            }
        }
        if (switchArms && startDance)
        {
            distance += -0.1f;
            arms.transform.Rotate(Vector3.up * 0.1f);
            hands.transform.Rotate(Vector3.up * 0.1f);
            legs.transform.Rotate(Vector3.up * -0.1f);
            butt.transform.Rotate(Vector3.up * -0.1f);
        }
        if (!switchArms && startDance)
        {
            arms.transform.Rotate(Vector3.up * -0.1f);
            hands.transform.Rotate(Vector3.up * -0.1f);
            legs.transform.Rotate(Vector3.up * 0.1f);
            butt.transform.Rotate(Vector3.up * 0.1f);
        }
        if (distance < -8.7f)
        {
            switchArms = false;
            distance   = 0;
        }


        if (!spin)
        {
            tiger.transform.Rotate(Vector3.up * (0.5f));
        }
        if (spin)
        {
            tiger.transform.Rotate(Vector3.down * (0.5f));
        }

        if (beatHit)
        {
            if (spectrum[3] * density < 0.6f)
            {
                count++;

                beatHit = false;
            }
        }
        if (spectrum[3] * density > 0.8f && beatHit == false)
        {
            beatHit = true;
            if (!spin && count == 4)
            {
                spin  = true;
                count = 0;
            }
            if (spin && count == 4)
            {
                spin  = false;
                count = 0;
            }
        }
        if (beatHit && tilt)
        {
            tilt = false;
        }
        if (beatHit && !tilt)
        {
            tilt = true;
        }
        Vector3 tiltHead = lego.transform.eulerAngles;

        if (tilt)
        {
            tiltHead.y = 87;
        }
        if (!tilt)
        {
            tiltHead.y = 94;
        }

        if (theLVL > peak)
        {
            peak = theLVL;
        }
        if (MidLvl > MidPeak)
        {
            MidPeak = MidLvl;
        }
        if (highLvl > HighPeak)
        {
            HighPeak = highLvl;
        }



        for (int i = 0; i < numberOfObjects; i++)
        {
            Vector3 TextpreviousScale = text.transform.localScale;
            Vector3 highPrevScale     = picHigh.transform.localScale;
            Vector3 MidPrevScale      = picLow.transform.localScale;
            Vector3 legoPrevScale     = lego.transform.localScale;
            if (peak < 1)
            {
                TextpreviousScale.x = peak * 1.3f + 1;
                legoPrevScale.y     = peak * 1.3f + 1;
            }
            if (MidPeak < 1)
            {
                MidPrevScale.x = MidPeak + 1;
            }
            if (HighPeak < 1)
            {
                highPrevScale.x = HighPeak * 1.3f + 1;
                legoPrevScale.x = HighPeak * 1.5f + 1;
            }
            if (peak > 1.5f)
            {
                TextpreviousScale.x = peak / 2 + 1;
            }
            if (MidPeak > 1.5f)
            {
                MidPrevScale.x = MidPeak / 15 + 1;
            }
            if (HighPeak > 1.5f)
            {
                highPrevScale.x = HighPeak / 10 + 1;
                legoPrevScale.x = HighPeak / 8 + 1;
            }
            if (peak > 1.5f)
            {
                TextpreviousScale.x = peak / 2 + 1;
            }
            if (MidPeak > 1.5f)
            {
                MidPrevScale.x = MidPeak / 15 + 1;
            }
            if (HighPeak > 1.5f)
            {
                highPrevScale.x = HighPeak / 10 + 1;
            }


            text.transform.localScale    = TextpreviousScale;
            picHigh.transform.localScale = highPrevScale;
            picLow.transform.localScale  = MidPrevScale;
            lego.transform.localScale    = legoPrevScale;
            lego.transform.Rotate(Vector3.forward * Time.deltaTime * 1.5f);
            if (colorAdapt)
            {
                text.material.color = new Color(r, g, peak, 0.7f);
            }
            thepic.material.color = new Color(r, g, b, peak);      //spectrum[3] * (density)   <--- for bounce
            MeshRenderer shirtColor = shirt.GetComponent <MeshRenderer>();
            shirtColor.material.color = new Color(r, g, b, peak);


            Vector3 previousScale = cubes[i].transform.localScale;
            previousScale.y = spectrum[i] * 20;
            cubes[i].transform.localScale = previousScale;

            if (spectrum[i] * density < 0.4f)
            {
                changeColors(i, new Color(0, 0, spectrum[i] * 20));
                holdRot += 0.02f;
            }
            if (spectrum[i] * density > 0.4f && spectrum[i] * density < 0.7f)
            {
                changeColors(i, new Color(0, spectrum[i] * density, 0));
                holdRot += 0.2f;
            }
            if (spectrum[i] * density > 0.7f)
            {
                changeColors(i, new Color(spectrum[i] * density - 1, 0, 0));
                holdRot += 5f;
            }
            cubes[i].transform.rotation = Quaternion.Euler(0, holdRot, 0);
        }
    }