iTween.AudioFrom C# (CSharp) Method

AudioFrom() public static method

Instantly changes an AudioSource's volume and pitch then returns it to it's starting volume and pitch over time with FULL customization options. Default AudioSource attached to GameObject will be used (if one exists) if not supplied.
public static AudioFrom ( GameObject target, Hashtable args ) : void
target GameObject
args Hashtable
return void
    public static void AudioFrom(GameObject target, Hashtable args)
    {
        Vector2 tempAudioProperties;
        Vector2 fromAudioProperties;
        AudioSource tempAudioSource;

        //clean args:
        args = iTween.CleanArgs(args);

        //set tempAudioSource:
        if(args.Contains("audiosource")){
            tempAudioSource=(AudioSource)args["audiosource"];
        }else{
            if(target.GetComponent(typeof(AudioSource))){
                tempAudioSource=target.audio;
            }else{
                //throw error if no AudioSource is available:
                Debug.LogError("iTween Error: AudioFrom requires an AudioSource.");
                return;
            }
        }

        //set tempAudioProperties:
        tempAudioProperties.x=fromAudioProperties.x=tempAudioSource.volume;
        tempAudioProperties.y=fromAudioProperties.y=tempAudioSource.pitch;

        //set augmented fromAudioProperties:
        if(args.Contains("volume")){
            fromAudioProperties.x=(float)args["volume"];
        }
        if(args.Contains("pitch")){
            fromAudioProperties.y=(float)args["pitch"];
        }

        //apply fromAudioProperties:
        tempAudioSource.volume=fromAudioProperties.x;
        tempAudioSource.pitch=fromAudioProperties.y;

        //set new volume and pitch args:
        args["volume"]=tempAudioProperties.x;
        args["pitch"]=tempAudioProperties.y;

        //set a default easeType of linear if none is supplied since eased audio interpolation is nearly unrecognizable:
        if (!args.Contains("easetype")) {
            args.Add("easetype",EaseType.linear);
        }

        //establish iTween:
        args["type"]="audio";
        args["method"]="to";
        Launch(target,args);
    }

Same methods

iTween::AudioFrom ( GameObject target, float volume, float pitch, float time ) : void
iTween