コード例 #1
0
        public IEnumerator LoadOrGetTexture(Action <Texture2D> callback)
        {
            if (texture)
            {
                callback.Invoke(texture);
                yield break;
            }

            if (!textureLoading)
            {
                textureLoading = true;
                string location;
                if (Path.IsPathRooted(Location))
                {
                    location = Location;
                }
                else
                {
                    location = Application.streamingAssetsPath + "/" + Location;
                }
                yield return(WurmAssetsLoader.LoadTexture(location, false, OnTextureLoaded));
            }

            while (textureLoading)
            {
                yield return(null);
            }

            callback.Invoke(texture);
        }
コード例 #2
0
        public IEnumerator LoadOrGetSprite(Action <Sprite> callback)
        {
            if (sprite)
            {
                callback.Invoke(sprite);
                yield break;
            }

            if (texture)
            {
                sprite = Sprite.Create(texture, new Rect(0.0f, 0.0f, texture.width, texture.height), new Vector2(0.5f, 0.5f));
                callback.Invoke(sprite);
                yield break;
            }

            if (!textureLoading)
            {
                textureLoading  = true;
                spriteRequested = true;
                string location;
                if (Path.IsPathRooted(Location))
                {
                    location = Location;
                }
                else
                {
                    location = Application.streamingAssetsPath + "/" + Location;
                }
                yield return(WurmAssetsLoader.LoadTexture(location, false, OnTextureLoaded));

                sprite = Sprite.Create(texture, new Rect(0.0f, 0.0f, texture.width, texture.height), new Vector2(0.5f, 0.5f));
            }

            while (textureLoading)
            {
                yield return(null);
            }

            callback.Invoke(sprite);
        }