예제 #1
0
    public GameObject InstantiateObject(string path, KVResourceLoader loader, Transform parent)
    {
        if (loader.CheckValid())
        {
            var obj = loader.asset as GameObject;
            if (obj)
            {
                GameObject        gameObject        = Instantiate(obj, parent);
                KVResourceTracker kvResourceTracker = gameObject.AddComponent <KVResourceTracker>();
                kvResourceTracker.key          = path;
                kvResourceTracker.OnDestroyed += OnDestroyTracker;


                List <Object> objList;
                if (!_instantiateObjs.TryGetValue(path, out objList))
                {
                    objList = new List <Object>();
                    _instantiateObjs.Add(path, objList);
                }
                objList.Add(gameObject.gameObject);
                return(gameObject);
            }
        }

        Debug.LogError($"loader({loader.assetPath}) can not Instantiate");
        return(null);
    }
예제 #2
0
    public KVResourceLoader LoadAssetAsync(string path, UnityAction <object> callback = null)
    {
//        path = "Assets/AssetsPackage/" + path;
        Debug.Log($"LoadAssetAsync assetPath:{path}");
        KVResourceLoader loader;

        if (_loadedAsset.TryGetValue(path, out loader))
        {
            loader = _loadedAsset[path];
            callback?.Invoke(loader.asset);
            return(loader);
        }

        if (_loadingAsset.TryGetValue(path, out loader))
        {
            loader.OnAssetLoaded += callback;
            return(loader);
        }

        loader = new KVResourceLoader(path);
        loader.OnAssetLoaded += callback;
        loader.OnAssetLoaded += obj =>
        {
            _loadedAsset.Add(path, loader);
            _loadingAsset.Remove(path);
        };
        _loadingAsset.Add(path, loader);
        return(loader);
    }
예제 #3
0
    public KVResourceLoader InstanceObjectAsync(string path, Transform parent,
                                                UnityAction <object> callback = null)
    {
//        path = "Assets/AssetsPackage/" + path;
        Debug.Log($"LoadAssetAsync assetPath:{path}");
        KVResourceLoader loader;

        if (_loadedAsset.TryGetValue(path, out loader))
        {
            callback?.Invoke(InstantiateObject(path, loader, parent));
            return(loader);
        }

        if (_loadingAsset.TryGetValue(path, out loader))
        {
            callback?.Invoke(InstantiateObject(path, loader, parent));
            return(loader);
        }

        loader = new KVResourceLoader(path);
        loader.OnAssetLoaded += obj =>
        {
            callback?.Invoke(InstantiateObject(path, loader, parent));
            _loadedAsset.Add(path, loader);
            _loadingAsset.Remove(path);
        };
        _loadingAsset.Add(path, loader);
        return(loader);
    }
예제 #4
0
    public KVResourceLoader LoadSceneAsync(string path, UnityAction <object> callback = null)
    {
        Debug.Log($"LoadSceneAsync assetPath:{path}");
        KVResourceLoader loader;

        loader = new KVResourceLoader(path, typeof(Scene));
        loader.OnAssetLoaded += arg0 =>
        {
            callback?.Invoke(null);
//            loader.Dispose();
        };
        return(loader);
    }