Exemple #1
0
        private static void loadLifespans()
        {
            string lifespanPath = PathUtil.Combine(Application.streamingAssetsPath,
                                                   ToriiToolkit.StreamingAssetsDataDirectory, lifespansDataFileName);
            JSONArray lifespanArray = JSONUtil.ReadJSONFromDisk(lifespanPath).AsArray;

            foreach (JSONString lifespan in lifespanArray)
            {
                _lifespans.CreateLifespan(lifespan);
            }
        }
Exemple #2
0
        public void Load(string path, int span)
        {
            JSONNode sprite = JSONUtil.ReadJSONFromDisk(path);
            string   type   = sprite["type"].Value;

            if (!sprite["type"].Value.Equals("sprite"))
            {
                throw new ToriiResourceLoadException(
                          "Could not load resource: JSON type '" + sprite["type"] + "' did not match 'sprite'",
                          typeof(Sprite));
            }

            bool streamingAssets = sprite.GetValueOrDefault <JSONBool>("streamingAssets", true);

            string textureValue = sprite["texture"];

            if (string.IsNullOrEmpty(textureValue))
            {
                throw new ArgumentException(
                          "SpriteHandler: \"texture\" JSON key was null or empty! Sprite must have a texture.", "path");
            }

            float ppuValue = sprite.GetValueOrDefault <JSONNumber>("ppu", 100);

            Texture2D texture = streamingAssets
                ? ResourceManager.Load <Texture2D>(PathUtil.Combine(TUI.UIUserDataDirectory, textureValue))
                : ResourceManager.UnityLoad <Texture2D>(PathUtil.Combine(TUI.UIDataDirectory, textureValue));

            Rect rect = sprite.GetValueOrDefault <JSONNode>("rect", new Rect(0, 0, texture.width, texture.height));

            Vector2 pivot =
                sprite.GetValueOrDefault <JSONNode>("pivot", new Vector2(texture.width / 2f, texture.height / 2f));

            Vector4 border = sprite.GetValueOrDefault <JSONNode>("border", Vector4.zero);

            Sprite            s        = Sprite.Create(texture, rect, pivot, ppuValue, 0, SpriteMeshType.FullRect, border);
            Resource <Sprite> resource = new Resource <Sprite>(s, span);

            ResourceManager.RegisterResource(path, resource);
        }