コード例 #1
0
 public bool IsAsynLoading(string path, out AsynAsset asset)
 {
     for (int i = 0, max = asyn_list.Count; i < max; i++)
     {
         if (asyn_list[i].path == path)
         {
             asset = asyn_list[i];
             return(true);
         }
     }
     asset = default(AsynAsset);
     return(false);
 }
コード例 #2
0
    public void AsynLoad <T>(string path, AssetType type, System.Action <Object> cb) where T : Object
    {
        uint      hash = XCommon.singleton.XHash(path + type);
        AsynAsset asset;

        if (map.ContainsKey(hash) && map[hash].obt != null) //已经加载的 计数器加一
        {
            map[hash].ref_cnt++;
            if (map[hash].is_clone_asset)
            {
                GameObject go = GameObject.Instantiate(map[hash].obt) as GameObject;
                XResources.SetAsynAssetIndex(go.GetInstanceID(), hash);
                cb(go);
            }
            else
            {
                cb(map[hash].obt);
                XResources.SetAsynAssetIndex(map[hash].obt.GetInstanceID(), hash);
            }
        }
        else if (IsAsynLoading(path, out asset)) //已正在加载的 回调cache
        {
            asset.cb.Add(cb);
        }
        else //没有加载的 开始加载
        {
            AsynAsset node = new AsynAsset();
            node.path           = path;
            node.type           = type;
            node.is_clone_asset = XResources.IsCloneAsset <T>();
            node.request        = Resources.LoadAsync <T>(path);
            node.cb             = new List <System.Action <Object> >();
            node.cb.Add(cb);
            asyn_list.Add(node);
            asyn_loading_cnt = asyn_list.Count;
        }
    }
コード例 #3
0
    private void OnLoaded(AsynAsset node)
    {
        Asset asset = new Asset {
            obt = node.request.asset, ref_cnt = node.cb.Count, is_clone_asset = node.is_clone_asset
        };
        uint hash = XCommon.singleton.XHash(node.path + node.type);

        map.Add(hash, asset);
        for (int i = 0, max = node.cb.Count; i < max; i++)
        {
            if (node.is_clone_asset)
            {
                GameObject go = GameObject.Instantiate(node.request.asset) as GameObject;
                node.cb[i](go);
            }
            else
            {
                node.cb[i](node.request.asset);
            }
        }
        node.cb.Clear();
        asyn_list.Remove(node);
        asyn_loading_cnt--;
    }