/////////////////////////////////////////// /// Init() /// Configures the actual audio source and /// plays the sound. /////////////////////////////////////////// public void Init(string strResource, Transform tf, Hashtable i_hashOptional) { // load the clip AudioClip clip = Resources.Load(strResource) as AudioClip; if (clip == null) { Debug.LogError("No such sound clip for resource " + strResource); Destroy(gameObject); return; } // create the audio source audioSource = gameObject.AddComponent <AudioSource>(); audioSource.clip = clip; // set the default volume (may be overriden) float fDefaultVolume = Constants_OLD.GetConstant <float>("DefaultVolume"); audioSource.volume = fDefaultVolume; ID_Audio dataAudio = IDL_Audio.GetData(strResource); if (dataAudio != null) { audioSource.volume = dataAudio.GetVolume(); audioSource.loop = dataAudio.ShouldLoop(); } // change pitch if necessary if (i_hashOptional.ContainsKey("pitch")) { float fPitch = (float)i_hashOptional["pitch"]; audioSource.pitch = fPitch; } gameObject.transform.parent = tf; gameObject.transform.position = tf.position; audioSource.Play(); // add destroy script -- if the audio doesn't loop if (audioSource.loop == false) { m_fLifetime = clip.length + 0.1f; if (i_hashOptional.ContainsKey("Time")) { m_fLifetime = (float)i_hashOptional["Time"]; } DestroyThis scriptDestroy = gameObject.AddComponent <DestroyThis>(); scriptDestroy.SetLife(m_fLifetime); } }
////////////////////////////////////////// /// Start() ////////////////////////////////////////// void Start() { TextMesh mesh = gameObject.GetComponent <TextMesh>(); if (mesh) { Color colorText = Constants_OLD.GetConstant <Color>(TextColor); mesh.color = colorText; } else { Debug.LogError("Warning: Object has no TextMesh but trying to access it( " + gameObject.name + ")", gameObject); } }
////////////////////////////////////////// /// ConvertData() /// For rollout data that is a list, /// because I couldn't figure out how to /// write a converter for it, this function /// will convert the string value to a list /// of T. ////////////////////////////////////////// private static void ConvertData <T>(string i_strID, Hashtable i_hash) { // this new hash will replace i_hash for i_strID Hashtable hash = new Hashtable(); // loop through every entry in the old hash foreach (DictionaryEntry pair in i_hash) { // get the pair and value object key = pair.Key; // this needs to be obj because keys could be ints or strings string strVal = (string)pair.Value; // then create a list of T from the string value we loaded from xml List <T> list = Constants_OLD.ParseList <T>(strVal); hash[key] = list; } // set the key to our new hash m_hashData[i_strID] = hash; }