Ejemplo n.º 1
0
    protected void LoadTexture(string texPath, Action <Texture> exCallback = null)
    {
        TexturesWaitLoadCount++;
        var texLoader = KTextureLoader.Load(texPath, (isOk, tex) =>
        {
            if (!isOk)
            {
                Log.LogError("无法加载依赖图片: {0}", texPath);
            }

            if (exCallback != null)
            {
                exCallback(tex);
            }

            TexturesWaitLoadCount--;
            if (TexturesWaitLoadCount <= 0)
            {
                foreach (var c in TexturesLoadedCallback)
                {
                    c();
                }
                TexturesLoadedCallback.Clear();
            }
        });

        ResourceLoaders.Add(texLoader);
    }
Ejemplo n.º 2
0
    protected void ProcessUISprite(string resourcePath)
    {
        var loader = KUIAtlasDep.LoadUIAtlas(resourcePath, (atlas) =>
        {
            if (!IsDestroy)
            {
                //UIAtlas atlas = _obj as UIAtlas;
                Debuger.Assert(atlas);

                Debuger.Assert(DependencyComponent);
                var sprite = DependencyComponent as UISprite;

                Debuger.Assert(sprite);
                sprite.atlas = atlas;

                //对UISpriteAnimation处理
                foreach (UISpriteAnimation spriteAnim in this.gameObject.GetComponents <UISpriteAnimation>())
                {
                    spriteAnim.RebuildSpriteList();
                }
            }
            OnFinishLoadDependencies(gameObject); // 返回GameObject而已哦
        });

        ResourceLoaders.Add(loader);
    }
Ejemplo n.º 3
0
    // UILabel...  Bitmap Font
    protected void ProcesBitMapFont(string resPath)
    {
        // Load UIFont Prefab
        var loader = KStaticAssetLoader.Load(resPath, (isOk, o) =>
        {
            if (!IsDestroy)
            {
                var uiFontPrefab = (GameObject)o;
                Logger.Assert(uiFontPrefab);

                uiFontPrefab.transform.parent = DependenciesContainer.transform;

                var uiFont = uiFontPrefab.GetComponent <UIFont>();
                Logger.Assert(uiFont);
                var label = DependencyComponent as UILabel;
                //foreach (UILabel label in gameObject.GetComponents<UILabel>())
                {
                    label.bitmapFont = uiFont;
                }
                OnFinishLoadDependencies(uiFont);
            }
            else
            {
                OnFinishLoadDependencies(null);
            }
        });

        ResourceLoaders.Add(loader);
    }
Ejemplo n.º 4
0
    // CSpineData 加载完后,在读取依赖的SkeletonDataAsset和SpriteCollection
    protected void LoadCSpineData(string path, Action <SkeletonDataAsset> dataCallback)
    {
        var loader = CStaticAssetLoader.Load(path, (isOk, obj) =>
        {
            //string resourcePath = args[0] as string;
            //Action<SkeletonDataAsset> externalCallback = args[1] as Action<SkeletonDataAsset>;
            if (isOk)
            {
                CSpineData spineData = obj as CSpineData;

                LoadSpineDataAsset(spineData.DataAssetPath, (SkeletonDataAsset dataAsset) =>
                {
                    var loader2 = CTk2dSpriteCollectionDep.LoadSpriteCollection(spineData.SpriteCollectionPath, (_obj) =>
                    {
                        tk2dSpriteCollectionData colData = _obj as tk2dSpriteCollectionData;
                        Logger.Assert(colData);

                        dataAsset.spriteCollection = colData;

                        dataCallback(dataAsset);
                    });
                    ResourceLoaders.Add(loader2);
                });
            }
            else
            {
                Logger.LogWarning("[CSpineAnimationDep:LoadCSpineData] Not Ok {0}", path);
                dataCallback(null);
            }
        });

        ResourceLoaders.Add(loader);
    }
Ejemplo n.º 5
0
    protected void ProcessTk2dSprite(string resourcePath)
    {
        if (string.IsNullOrEmpty(resourcePath))
        {
            Logger.LogError("[ProcessTk2dSprite]Null ResourcePath {0}", gameObject.name);
            return;
        }

        var loader = CTk2dSpriteCollectionDep.LoadSpriteCollection(resourcePath, (_obj) =>
        {
            tk2dSpriteCollectionData colData = _obj as tk2dSpriteCollectionData;
            Logger.Assert(colData);
            if (!IsDestroy)
            {
                Logger.Assert(DependencyComponent is tk2dBaseSprite);
                tk2dBaseSprite sprite = (tk2dBaseSprite)DependencyComponent;
                sprite.Collection     = colData;
                sprite.Build();
            }
            OnFinishLoadDependencies(colData);  // 返回GameObject而已哦
            //else
            //    Logger.LogWarning("GameObject maybe destroy!");
        });

        ResourceLoaders.Add(loader);
    }
Ejemplo n.º 6
0
    protected void LoadSpineDataAsset(string path, Action <SkeletonDataAsset> callback)
    {
        var loader = CStaticAssetLoader.Load(path, (_isOk, _obj) =>
        {
            SkeletonDataAsset dataAsset = _obj as SkeletonDataAsset;
            Logger.Assert(dataAsset);
            dataAsset.name = path;
            callback(dataAsset);
        });

        ResourceLoaders.Add(loader);
    }
Ejemplo n.º 7
0
    protected void ProcessUIFont(string resPath)
    {
        var loader = KUIAtlasDep.LoadUIAtlas(resPath, atlas =>
        {
            if (!IsDestroy)
            {
                Debuger.Assert(atlas);

                UIFont uiFont = DependencyComponent as UIFont;
                Debuger.Assert(uiFont);
                //foreach (UIFont uiFont in this.gameObject.GetComponents<UIFont>())
                {
                    uiFont.atlas    = atlas;
                    uiFont.material = atlas.spriteMaterial;
                }
            }
            OnFinishLoadDependencies(gameObject); // 返回GameObject而已哦
        });

        ResourceLoaders.Add(loader);
    }
Ejemplo n.º 8
0
        public static async Task <T> DownloadJsonAsync <T>(string url, List <KeyValuePair <string, string> > header = null)
        {
            var sw = Stopwatch.StartNew();

            try
            {
                var hc  = SharedHttpClient.Value;
                var msg = new HttpRequestMessage(HttpMethod.Get, url);

                if (header != null)
                {
                    foreach (var(key, value) in header)
                    {
                        msg.Headers.Add(key, value);
                    }
                }

                try
                {
                    var data = await hc.SendAsync(msg, AsyncContext.GetCancellationToken());

                    data.EnsureSuccessStatusCode();

                    return(await ResourceLoaders <T> .JsonDotNetLoader(await data.Content.ReadAsStreamAsync()));
                }
                catch (WebException e)
                {
                    if (e.Status == WebExceptionStatus.Timeout)
                    {
                        throw new CommandException($"请求超时.");
                    }

                    throw new CommandException($"数据下载出错: {e.Message}.");
                }
            }
            finally
            {
                Trace.WriteLine($"数据下载完成: URL '{url}', 用时 '{sw.Elapsed.TotalSeconds:F1}s'.");
            }
        }
Ejemplo n.º 9
0
    // 讀SpriteCollection...
    protected void ProcessTileMap_LoadSpriteCollection(string path)
    {
        var loader = CTk2dSpriteCollectionDep.LoadSpriteCollection(path, (_obj) =>
        {
            tk2dSpriteCollectionData colData = _obj as tk2dSpriteCollectionData;
            CDebug.Assert(colData);
            if (!IsDestroy)
            {
                var sprite = (tk2dTileMap)DependencyComponent;

                //foreach (tk2dTileMap sprite in gameObject.GetComponents<tk2dTileMap>())
                {
                    sprite.Editor__SpriteCollection = colData;
                    sprite.ForceBuild();
                }
            }
            OnFinishLoadDependencies(gameObject);  // 返回GameObject而已哦
            //else
            //    CDebug.LogWarning("GameObject maybe destroy!");
        });

        ResourceLoaders.Add(loader);
    }