Esempio n. 1
0
    void Update()
    {
        FMOD.ATTRIBUTES_3D Attributes3D = new FMOD.ATTRIBUTES_3D();
        Attributes3D.position.x = transform.position.x;
        Attributes3D.position.y = transform.position.y;
        Attributes3D.position.z = transform.position.z;

        Attributes3D.forward.x = transform.forward.x;
        Attributes3D.forward.y = transform.forward.y;
        Attributes3D.forward.z = transform.forward.z;

        Attributes3D.velocity.x = m_ControllerBody.velocity.x;
        Attributes3D.velocity.y = m_ControllerBody.velocity.y;
        Attributes3D.velocity.z = m_ControllerBody.velocity.z;

        m_FootstepState.set3DAttributes(Attributes3D);

        float WalkingCurrent, WalkingTarget, RunningCurrent, RunningTarget;
        m_FootstepsWalking.getValue(out WalkingCurrent);
        m_FootstepsRunning.getValue(out RunningCurrent);
        WalkingTarget = m_Controller.PlayerMoving ? 1f : 0f;
        RunningTarget = WalkingTarget == 1f ? (m_Controller.PlayerWalking ? 0f : 1f) : 0f;

        m_FootstepsWalking.setValue(Mathf.Lerp(WalkingCurrent, WalkingTarget, 0.05f));
        m_FootstepsRunning.setValue(Mathf.Lerp(RunningCurrent, RunningTarget, 0.05f));
    }
Esempio n. 2
0
    // Use this for initialization
    void Start()
    {
        _state = State.IDLE;


        FMOD.Studio.EventDescription walkDescription;
        SoundSystem.instance.ErrorCheck(SoundSystem.instance.GetStudioSoundSystem().getEvent("event:/Steps", out walkDescription));
        SoundSystem.instance.ErrorCheck(walkDescription.createInstance(out _WalkInstance));

        FMOD.Studio.PARAMETER_DESCRIPTION velocityDescription;
        SoundSystem.instance.ErrorCheck(walkDescription.getParameter("Velocidad", out velocityDescription));
        _velocityIndex = velocityDescription.index;

        FMOD.Studio.EventDescription jumpDescription;
        SoundSystem.instance.ErrorCheck(SoundSystem.instance.GetStudioSoundSystem().getEvent("event:/Jump", out jumpDescription));
        SoundSystem.instance.ErrorCheck(jumpDescription.createInstance(out _jumpInstance));

        FMOD.Studio.EventDescription shootDescription;
        SoundSystem.instance.ErrorCheck(SoundSystem.instance.GetStudioSoundSystem().getEvent("event:/Shot", out shootDescription));
        SoundSystem.instance.ErrorCheck(shootDescription.createInstance(out _shootInstance));
        //SoundSystem.instance.ErrorCheck(_shootInstance.setProperty(FMOD.Studio.EVENT_PROPERTY.MINIMUM_DISTANCE, 3.0f));
        //SoundSystem.instance.ErrorCheck(_shootInstance.setProperty(FMOD.Studio.EVENT_PROPERTY.MAXIMUM_DISTANCE, 200.0f));

        _attributes3D = FMODUnity.RuntimeUtils.To3DAttributes(this.gameObject, this.gameObject.GetComponent <Rigidbody>());
        _jumpInstance.set3DAttributes(_attributes3D);
        _WalkInstance.set3DAttributes(_attributes3D);
        _shootInstance.set3DAttributes(_attributes3D);
    }
Esempio n. 3
0
 // Update is called once per frame
 void FixedUpdate()
 {
     _attributes3D = FMODUnity.RuntimeUtils.To3DAttributes(this.gameObject, this.gameObject.GetComponent <Rigidbody>());
     _jumpInstance.set3DAttributes(_attributes3D);
     _WalkInstance.set3DAttributes(_attributes3D);
     _shootInstance.set3DAttributes(_attributes3D);
 }
Esempio n. 4
0
    private IEnumerator WaitForStreamBuffer()
    {
        do
        {
            yield return(null);
        } while (state == FMOD.OPENSTATE.CONNECTING || state == FMOD.OPENSTATE.BUFFERING);

        if (state == FMOD.OPENSTATE.READY)
        {
            Debug.Log("Internet stream loaded");
            radioStream.setMode(FMOD.MODE.OPENUSER | FMOD.MODE._3D | FMOD.MODE._3D_LINEARROLLOFF);
            lowLevelSystem.playSound(radioStream, channelGroup, true, out channel);
            FMOD.ATTRIBUTES_3D attributes  = FMODUnity.RuntimeUtils.To3DAttributes(gameObject);
            FMOD.VECTOR        alt_pan_pos = Vector3.zero.ToFMODVector();
            channel.set3DMinMaxDistance(minDistance, maxDistance);
            channel.setLoopCount(-1);
            channel.setMode(FMOD.MODE.LOOP_NORMAL);
            channel.set3DAttributes(ref attributes.position, ref attributes.velocity, ref alt_pan_pos);
            channel.setPaused(false);
            channel.setVolume(volume);

            isReadyAndPlaying = true;
        }
        else if (state == FMOD.OPENSTATE.ERROR)
        {
            Debug.Log("Error while loading online , check the address or connection");
        }
    }
Esempio n. 5
0
    // Use this for initialization
    public void Init(LevelManager lm, float t)
    {
        _levelManager = lm;
        timeShowing   = t;

        // Event description for creating the scream event instance
        FMOD.Studio.EventDescription screamDescription;
        SoundSystem.instance.ErrorCheck(SoundSystem.instance.GetStudioSoundSystem().getEvent("event:/Scream", out screamDescription));
        SoundSystem.instance.ErrorCheck(screamDescription.createInstance(out _screamInstance));

        // Event description for creating the spawn event instance
        FMOD.Studio.EventDescription spawnDescription;
        SoundSystem.instance.ErrorCheck(SoundSystem.instance.GetStudioSoundSystem().getEvent("event:/HelloCivil", out spawnDescription));
        SoundSystem.instance.ErrorCheck(spawnDescription.createInstance(out _spawnInstance));

        // Set the 3d attributes of this sound depending on this script's owner
        _attributes3D = FMODUnity.RuntimeUtils.To3DAttributes(this.gameObject, this.gameObject.GetComponent <Rigidbody>());
        _screamInstance.set3DAttributes(_attributes3D);
        _spawnInstance.set3DAttributes(_attributes3D);

        // Set the minimum and maximum distances for this sound event
        SoundSystem.instance.ErrorCheck(_screamInstance.setProperty(FMOD.Studio.EVENT_PROPERTY.MINIMUM_DISTANCE, 3.0f));
        SoundSystem.instance.ErrorCheck(_screamInstance.setProperty(FMOD.Studio.EVENT_PROPERTY.MAXIMUM_DISTANCE, 30.0f));


        // Set the minimum and maximum distances for scream event instance
        SoundSystem.instance.ErrorCheck(_spawnInstance.setProperty(FMOD.Studio.EVENT_PROPERTY.MINIMUM_DISTANCE, 3.0f));
        SoundSystem.instance.ErrorCheck(_spawnInstance.setProperty(FMOD.Studio.EVENT_PROPERTY.MAXIMUM_DISTANCE, 30.0f));

        _spawnInstance.start();
    }
Esempio n. 6
0
    private void LateUpdate()
    {
        _listenerAttributes3D = RuntimeUtils.To3DAttributes(sceneListener, sceneListener.GetComponent <Rigidbody>());
        _result = studioSystem.setListenerAttributes(0, _listenerAttributes3D);
        ErrorCheck(_result);
        _result = lowlevelSystem.set3DListenerAttributes(0, ref _listenerAttributes3D.position, ref _listenerAttributes3D.velocity, ref _listenerAttributes3D.forward, ref _listenerAttributes3D.up);
        ErrorCheck(_result);

        lowlevelSystem.update();
        studioSystem.update();
    }
Esempio n. 7
0
    public static FMOD.ATTRIBUTES_3D get3DAudioPosition(Vector3 pos)
    {
        Vector3 camPos = Camera.main.transform.position;

        pos.z = camPos.z;
        Vector3 norm = (camPos - pos).normalized * (Ellipse.isometricDistance(camPos, pos) / 200f);

        camPos -= norm;
        FMOD.ATTRIBUTES_3D fmodPos = FMODUnity.RuntimeUtils.To3DAttributes(camPos);
        return(fmodPos);
    }
Esempio n. 8
0
    // Plays a sound on the position of the object. But does not update the position after.
    public static EventInstance PlayOneShotAtPosition(string eventName, Transform position)
    {
        EventInstance instance = RuntimeManager.CreateInstance(eventName);

        if (string.IsNullOrEmpty(eventName))
        {
            return(instance);
        }

        FMOD.ATTRIBUTES_3D positionAttribute = RuntimeUtils.To3DAttributes(position);
        instance.set3DAttributes(positionAttribute);

        instance.start();
        instance.release();
        instance.clearHandle();
        return(instance);
    }
Esempio n. 9
0
    public static EventInstance PlayOneShotAtPosition(string eventName, Transform position, PARAMETER_ID parameterId, float value)
    {
        EventInstance instance = RuntimeManager.CreateInstance(eventName);

        if (string.IsNullOrEmpty(eventName))
        {
            return(instance);
        }

        instance.setParameterByID(parameterId, value);

        FMOD.ATTRIBUTES_3D positionAttribute = RuntimeUtils.To3DAttributes(position);
        instance.set3DAttributes(positionAttribute);

        instance.start();
        instance.release();
        return(instance);
    }
Esempio n. 10
0
    // Use this for initialization
    void Init()
    {
        if (instance == null)
        {
            instance = this;
            // Specify that the game object with this behaviour doesn't gets destroyed when reloading the scene
            DontDestroyOnLoad(gameObject);
        }


        // Get the studio and low level systems from RuntimeManager, where them have been created
        studioSystem   = FMODUnity.RuntimeManager.StudioSystem;
        lowlevelSystem = FMODUnity.RuntimeManager.LowlevelSystem;

        //studioSystem.getCPUUsage(out _cpuUsage);


        uint version;

        _result = lowlevelSystem.getVersion(out version);
        ErrorCheck(_result);

        UnityEngine.Debug.Log("FMOD version: " + version);


        //System.IntPtr extradriverdata = new System.IntPtr(0);
        // Initialize studio and low level system
        //_result = studioSystem.initialize(128, FMOD.Studio.INITFLAGS.NORMAL, FMOD.INITFLAGS.NORMAL, extradriverdata);
        //ErrorCheck(_result);
        //_result = lowlevelSystem.init(128, FMOD.INITFLAGS.NORMAL, extradriverdata);
        //ErrorCheck(_result);



        _listenerAttributes3D = RuntimeUtils.To3DAttributes(sceneListener, sceneListener.GetComponent <Rigidbody>());
        _result = studioSystem.setListenerAttributes(0, _listenerAttributes3D);
        ErrorCheck(_result);
        _result = lowlevelSystem.set3DListenerAttributes(0, ref _listenerAttributes3D.position, ref _listenerAttributes3D.velocity, ref _listenerAttributes3D.forward, ref _listenerAttributes3D.up);
        ErrorCheck(_result);
    }
Esempio n. 11
0
    private string path = "Assets/3rdPerson+Fly/Sounds/"; // Path of the sound to listen

    void Start()
    {
        path = path + soundName;

        _channel      = new Channel();
        _channelGroup = new FMOD.ChannelGroup();


        _alt_pan_pos = new FMOD.VECTOR();
        _rigidBody   = gameObject.GetComponent <Rigidbody>();

        // Convert game object 3d attributes to FMOD.ATTRIBUTES_3D struct
        _attributes3D = RuntimeUtils.To3DAttributes(gameObject, _rigidBody);

        _soundManager.Create(path, FMOD.MODE.LOOP_NORMAL, out _sound);
        _soundManager.Play(_sound, _channelGroup, false, out _channel, _attributes3D.position, _attributes3D.velocity, _alt_pan_pos);
        _soundManager.ChangeVolume(volume);

        // minDistance: distancia a partir de la cual el sonido comienza a atenuarse
        // maxDistance: distancia a partir de la cual el sonido no se atenúa más (el volumen no es necesariamente 0.0)
        _channel.set3DMinMaxDistance(3.0f, 40.0f);
    }
Esempio n. 12
0
    // Use this for initialization
    void Start()
    {
        channel        = new FMOD.Channel();
        lowLevelSystem = FMODUnity.RuntimeManager.LowlevelSystem;
        FMODUnity.RuntimeManager.LowlevelSystem.getMasterChannelGroup(out channelGroup);

        lowLevelSystem.createSound("Assets\\Sounds\\guitar.mp3", FMOD.MODE.DEFAULT, out guitarSong);
        string songName = "";

        guitarSong.getName(out songName, 20);
        Debug.Log("Playing song: " + songName, gameObject);
        guitarSong.setMode(FMOD.MODE.OPENUSER | FMOD.MODE._3D | FMOD.MODE._3D_LINEARSQUAREROLLOFF);

        lowLevelSystem.playSound(guitarSong, channelGroup, true, out channel);
        channel.set3DMinMaxDistance(minDistance, maxDistance);
        channel.setLoopCount(-1);
        channel.setMode(FMOD.MODE.LOOP_NORMAL);
        FMOD.ATTRIBUTES_3D attributes  = FMODUnity.RuntimeUtils.To3DAttributes(gameObject);
        FMOD.VECTOR        alt_pan_pos = Vector3.zero.ToFMODVector();
        channel.set3DAttributes(ref attributes.position, ref attributes.velocity, ref alt_pan_pos);

        channel.setPaused(false);
    }
Esempio n. 13
0
    void Update()
    {
        FMOD.ATTRIBUTES_3D Attributes3D = new FMOD.ATTRIBUTES_3D();
        Attributes3D.position.x = transform.position.x;
        Attributes3D.position.y = transform.position.y;
        Attributes3D.position.z = transform.position.z;

        Attributes3D.forward.x = transform.forward.x;
        Attributes3D.forward.y = transform.forward.y;
        Attributes3D.forward.z = transform.forward.z;

        m_CrossbowShotEvent.set3DAttributes(Attributes3D);

        if (Input.GetButtonDown("Attack") && !m_IsLoading)
        {
            if (m_Loaded)
            {
                Camera m_Cam = Camera.main;
                GameObject BoltShot = (GameObject)Instantiate(m_BoltPrefab, m_Crossbow.transform.position - m_Crossbow.transform.forward * 1f, m_Cam.transform.rotation);
                Rigidbody BoltBody = BoltShot.GetComponent<Rigidbody>();
                BoltBody.AddForce(m_Cam.transform.forward * m_BoltImpulse, ForceMode.Impulse);
                BoltShot.transform.up = m_Cam.transform.forward;
                m_Loaded = false;
                m_CrossbowCue.trigger();
            }
            else if (m_PlayerChar.PlayerAmmo > 0)
            {
                //reload. insert any code regarding meshes and animations, I've done my part!
                Crossbow.transform.localRotation = ReloadRotation;
                m_IsLoading = true;

                m_CrossbowReload.setValue(1f);
                m_CrossbowCue.trigger();
            }
            else
            {
                //Play Sound to inform Ammo = 0
                Debug.Log("Out of Ammo");
            }

        }

        if (Input.GetButton("Attack") && m_IsLoading)
        {
            m_PlayerReloadCount += Time.deltaTime;

            if (m_PlayerReloadCount >= m_PlayerReloadCountFin)
            {
                m_IsLoading = false;
                m_Loaded = true;
                m_PlayerReloadCount = 0;
                m_PlayerChar.PlayerAmmo -= 1;
                Crossbow.transform.localRotation = ReadyRotation;

            }
        }

        if (Input.GetButtonUp("Attack"))
        {
            m_PlayerReloadCount = 0;
            m_IsLoading = false;
            m_CrossbowReload.setValue(0f);
            Crossbow.transform.localRotation = ReadyRotation;
        }
    }
Esempio n. 14
0
 private void FixedUpdate()
 {
     _attributes3D = FMODUnity.RuntimeUtils.To3DAttributes(this.gameObject, this.gameObject.GetComponent <Rigidbody>());
     _screamInstance.set3DAttributes(_attributes3D);
     _spawnInstance.set3DAttributes(_attributes3D);
 }
Esempio n. 15
0
    void Update()
    {
        IsAttacking = false;
        WasHit = false;
        BeginHunt = false;

        if (!IsDead)
        {
            FootstepTimer -= Time.deltaTime;
            if(FootstepTimer <= 0)
            {
                var CurrentAnimationState = Animations.GetCurrentAnimatorStateInfo(0);
                float FootstepMaxTime = CurrentAnimationState.length / 2;
                FootstepTimer = FootstepMaxTime;
                m_FootstepState.setTimelinePosition(0);
                m_FootstepState.start();
            }

            AttackTimer -= Time.deltaTime;
            if(SeePlayer = FindPlayer())
            {
                if(!Hunting)
                {
                    BeginHunt = true;
                }
                LastKnownPlayerPosition = Player.transform.position;
                Hunting = true;
            }

            if(Hunting)
            {
                Navigator.speed = RunSpeed;
                Navigator.angularSpeed = RunRotSpeed;
                Navigator.acceleration = RunAcceleration;
                Navigator.destination = LastKnownPlayerPosition;

                if(CanAttack && Vector3.Distance(Player.transform.position, transform.position) < 2f)
                {
                    IsAttacking = true;
                    PlayerInfo.PlayerHealth -= Damage;
                    Debug.Log("Player health: " + PlayerInfo.PlayerHealth.ToString());
                }

                if(!SeePlayer && Navigator.remainingDistance < 1f)
                {
                    Hunting = false;
                }
            }
            else
            {
                Navigator.speed = WalkSpeed;
                Navigator.angularSpeed = WalkRotSpeed;
                Navigator.acceleration = WalkAcceleration;
            }

            FMOD.ATTRIBUTES_3D Attributes3D = new FMOD.ATTRIBUTES_3D();
            Attributes3D.position.x = transform.position.x;
            Attributes3D.position.y = transform.position.y;
            Attributes3D.position.z = transform.position.z;

            Attributes3D.forward.x = transform.forward.x;
            Attributes3D.forward.y = transform.forward.y;
            Attributes3D.forward.z = transform.forward.z;

            m_FootstepState.set3DAttributes(Attributes3D);
            m_VoiceAttack.set3DAttributes(Attributes3D);
            m_VoiceDeath.set3DAttributes(Attributes3D);
            m_VoiceHit.set3DAttributes(Attributes3D);
            m_VoiceIdle.set3DAttributes(Attributes3D);
        }
    }
Esempio n. 16
0
	// Update is called once per frame
	void Update () {
        FMOD.ATTRIBUTES_3D attributes = FMODUnity.RuntimeUtils.To3DAttributes(gameObject);
        alt_pan_pos = Vector3.zero.ToFMODVector();
        channel.set3DAttributes(ref attributes.position, ref attributes.velocity, ref alt_pan_pos);
	}
Esempio n. 17
0
    // Update is called once per frame
    void Update()
    {
        FMOD.ATTRIBUTES_3D attributes = FMODUnity.RuntimeUtils.To3DAttributes(Camera.main.transform.position);
        atmoEv.set3DAttributes(attributes);
        musicEv.set3DAttributes(attributes);


        if (audioType == true)
        {
            musicEv.stop(FMOD.Studio.STOP_MODE.IMMEDIATE);
            if (block == true)
            {
                atmoEv.start();
                block = false;
            }
        }
        else
        {
            atmoEv.stop(FMOD.Studio.STOP_MODE.IMMEDIATE);
            if (block == false)
            {
                musicEv.start();
                block = true;
            }
        }


        if (Input.GetKeyDown(KeyCode.X))
        {
            play = !play;
            if (!play)
            {
                atmoEv.setVolume(0);
                musicEv.setVolume(0);
            }
            else
            {
                atmoEv.setVolume(volume);
                musicEv.setVolume(volume);
            }
        }

        if (Input.GetKeyDown("space"))
        {
            FMODUnity.RuntimeManager.PlayOneShot(inputSound, Camera.main.transform.position);
            print("played");
        }

        if (Input.GetKeyDown("[1]"))
        {
            atmoLoc.setValue(0);
            print("forest");
            audioType = true;
        }

        if (Input.GetKeyDown("[2]"))
        {
            atmoLoc.setValue(1);
            print("gravey");
            audioType = true;
        }

        if (Input.GetKeyDown("[3]"))
        {
            atmoLoc.setValue(2);
            print("castle");
            audioType = true;
        }

        if (Input.GetKeyDown("[7]"))
        {
            rainlvl += 0.1f;
            if (rainlvl > 1)
            {
                rainlvl = 1;
            }
            atmoRain.setValue(rainlvl);
            print("rainlvl =" + rainlvl);
        }

        if (Input.GetKeyDown("[8]"))
        {
            rainlvl -= 0.1f;
            if (rainlvl < 0)
            {
                rainlvl = 0;
            }
            atmoRain.setValue(rainlvl);
            print("rainlvl =" + rainlvl);
        }

        if (Input.GetKeyDown("[4]"))
        {
            musicType.setValue(0);
            print("Style 1");
            audioType = false;
        }

        if (Input.GetKeyDown("[5]"))
        {
            musicType.setValue(0.5f);
            print("Style 2");
            audioType = false;
        }

        if (Input.GetKeyDown("[6]"))
        {
            musicType.setValue(1);
            print("Style 3");
            audioType = false;
        }
    }
Esempio n. 18
0
    private void OnHitSomething(GameObject other, Vector3 hitPoint)
    {
        AudioDefs.Surface surface_type;

        // Determine surface type of hit object
        switch (other.tag)
        {
        case "Wood":
            surface_type = AudioDefs.Surface.Wood;
            break;

        case "Stone":
            surface_type = AudioDefs.Surface.Stone;
            break;

        case "Dirt":
            surface_type = AudioDefs.Surface.Dirt;
            break;

        case "Metal":
            surface_type = AudioDefs.Surface.Metal;
            break;

        case "Sandbag":
            surface_type = AudioDefs.Surface.Sandbag;
            break;

        default:
            surface_type = AudioDefs.Surface.None;
            break;
        }

        // Only bother FMOD if there's an impact to play
        if (surface_type != AudioDefs.Surface.None)
        {
            FMOD.Studio.EventInstance ImpactEvent = FMODUnity.RuntimeManager.CreateInstance("event:/SFX/Weapons/Bullet_Impact");
            FMOD.ATTRIBUTES_3D        att         = FMODUnity.RuntimeUtils.To3DAttributes(gameObject);
            ImpactEvent.set3DAttributes(att);

            // Set the surface then play the event
            ImpactEvent.setParameterByName("Surface", (int)surface_type);
            ImpactEvent.start();
            ImpactEvent.release();
        }

        Health otherHealth = other.GetComponent <Health>();

        if (otherHealth)
        {
            bool killed = otherHealth.TakeDamage(damageAmount);

            if (killed)
            {
                // Death audio event here
                Debug.Log("Target destroyed");
            }
        }

        speed              = 0;
        hasHit             = true;
        transform.position = hitPoint;
        GetComponent <MeshRenderer>().enabled = false;
        Destroy(gameObject, persistAfterHitTime);
    }
Esempio n. 19
0
 // Using fixed update because it's physics what is being updated
 void FixedUpdate()
 {
     // Update emitter location
     _attributes3D = RuntimeUtils.To3DAttributes(gameObject, _rigidBody);
     _channel.set3DAttributes(ref _attributes3D.position, ref _attributes3D.velocity, ref _alt_pan_pos);
 }