/// <summary> /// Get an AudioClip at the given full path. Attempts to retrieve it from the AudioClipRegistry first by using folderRoot to extract the clip's name, otherwise attempts to load from disk. /// </summary> /// <param name="musicFilePath">Full path to a file.</param> /// <returns>AudioClip object on successful load, otherwise null.</returns> public static AudioClip getAudioClip(string folderRoot, string musicFilePath) { string clipName = FileLoader.getRelativePathWithoutExtension(folderRoot, musicFilePath); AudioClip music = AudioClipRegistry.Get(clipName); if (music != null) { return(music); } WWW www = new WWW(new Uri(musicFilePath).AbsoluteUri); while (!www.isDone) { } // hold up a bit while it's loading; delay isn't noticeable and loading will fail otherwise AudioType type = AudioType.UNKNOWN; if (musicFilePath.EndsWith(".ogg")) { type = AudioType.OGGVORBIS; } else if (musicFilePath.EndsWith(".wav")) { type = AudioType.WAV; } else { return(null); } music = www.GetAudioClip(false, false, type); music.name = "File at " + musicFilePath; music.LoadAudioData(); AudioClipRegistry.Set(clipName, music); return(music); }
void LateStart() { if (!string.IsNullOrEmpty(SpritePath)) { Image img = GetComponent <Image>(); if (img != null) { img.sprite = SpriteRegistry.Get(SpritePath); if (SetNativeSize) { img.SetNativeSize(); } } ParticleSystem psys = GetComponent <ParticleSystem>(); if (psys != null) { ParticleSystemRenderer prender = GetComponent <ParticleSystemRenderer>(); prender.material.mainTexture = SpriteRegistry.Get(SpritePath).texture; } } if (!string.IsNullOrEmpty(SoundPath)) { AudioSource aSrc = GetComponent <AudioSource>(); aSrc.clip = AudioClipRegistry.Get(SoundPath); aSrc.loop = Loop; } }
void LateStart() { if (this == null) { return; } bool hasError = false; if ((!done && this.handleDictErrors) || (!doneFromLoadedScene && !this.handleDictErrors)) { if (!done && this.handleDictErrors) { done = true; } else { doneFromLoadedScene = true; } bool handleDictErrors = this.handleDictErrors; if (!string.IsNullOrEmpty(SpritePath)) { Image img = GetComponent <Image>(); SpriteRenderer img2 = GetComponent <SpriteRenderer>(); ParticleSystemRenderer img3 = GetComponent <ParticleSystemRenderer>(); if (img != null) { img.sprite = SpriteRegistry.Get(SpritePath); if (img.sprite == null && handleDictErrors) { UnitaleUtil.DisplayLuaError("AutoloadResourcesFromRegistry", "You tried to load the sprite \"" + SpritePath + "\", but it doesn't exist."); return; } else if (img.sprite == null) { hasError = true; } else { //img.sprite.name = SpritePath.ToLower(); TODO: Find a way to store the sprite's path if (SetNativeSize) { img.SetNativeSize(); if (!UnitaleUtil.IsOverworld) { img.rectTransform.localScale = new Vector3(1, 1, 1); img.rectTransform.sizeDelta = new Vector2(img.sprite.texture.width, img.sprite.texture.height); } else { img.rectTransform.localScale = new Vector3(100, 100, 1); img.rectTransform.sizeDelta = new Vector2(img.sprite.texture.width / 100f, img.sprite.texture.height / 100f); } } } } else if (img2 != null) { img2.sprite = SpriteRegistry.Get(SpritePath); if (img2.sprite == null && handleDictErrors) { UnitaleUtil.DisplayLuaError("AutoloadResourcesFromRegistry", "You tried to load the sprite \"" + SpritePath + "\", but it doesn't exist."); return; } else if (img2.sprite == null) { hasError = true; } else { //img2.sprite.name = SpritePath.ToLower(); if (SetNativeSize) { if (!UnitaleUtil.IsOverworld) { img2.transform.localScale = new Vector3(1, 1, 1); img2.GetComponent <RectTransform>().sizeDelta = new Vector2(img2.sprite.texture.width, img2.sprite.texture.height); } else { img2.transform.localScale = new Vector3(100, 100, 1); img2.GetComponent <RectTransform>().sizeDelta = new Vector2(img2.sprite.texture.width / 100f, img2.sprite.texture.height / 100f); } } } } else if (img3 != null) { img3.material.mainTexture = SpriteRegistry.Get(SpritePath).texture; } else { throw new CYFException("The GameObject " + gameObject.name + " doesn't have an Image, Sprite Renderer or Particle System component."); } } if (!string.IsNullOrEmpty(SoundPath) && !hasError) { AudioSource aSrc = GetComponent <AudioSource>(); aSrc.clip = AudioClipRegistry.Get(SoundPath); aSrc.loop = Loop; } this.handleDictErrors = true; } }