Пример #1
0
        /// <summary>
        /// 获得加载器
        /// </summary>
        /// <param name="type">类型</param>
        /// <param name="path">路径</param>
        /// <param name="param">附加参数</param>
        /// <param name="async">异步</param>
        /// <returns>加载器</returns>
        public Loader PopLoader(Loader.LoaderType type, string path, object param, bool async)
        {
            LoaderData ld;

            if (!m_loaders.TryGetValue(path, out ld))
            {
                if (m_pools[type].Count > 0)
                {
                    ld = m_pools[type].Dequeue();
                }

                if (ld == null)
                {
                    ld = new LoaderData
                    {
                        Reference = 0,
                        Loader    = CreateLoader(type),
                        Callbacks = new List <LoadMgr.LoadedHandler>()
                    };
                }

                ld.Loader.Init(path, param, null, OnLoadCompleted, async);
                m_loaders.Add(path, ld);
            }

            if (!async)
            {
                ld.Loader.IsAsync = false;
            }

            ++ld.Reference;
            return(ld.Loader);
        }
Пример #2
0
    public void LoadAsset(string path, string name, Action <GameObject, object> callback, object param)
    {
        LoaderData wd = new LoaderData();

        wd.assetName = name;
        wd.assetPath = path;
        wd.callback  = callback;
        wd.param     = param;
        waitings.Add(wd);
    }
Пример #3
0
    public void AddLoaderData(string loadPath, string savePath, string callbackName, Action callbackFunction)
    {
        LoaderData data = new LoaderData();

        data.LoadPath         = loadPath;
        data.SavePath         = savePath;
        data.CallbackName     = callbackName;
        data.CallbackFunction = callbackFunction;

        LoadDataStackList.Add(data);
    }
Пример #4
0
    // ※本来は、これ、アセットバンドル化した物を読み込んでやることだからね!
    private IEnumerator ResourceLoad(LoaderData loaderData)
    {
#if UNITY_IPHONE
        //string path = Application.streamingAssetsPath + "/" + "Utility.lua";
        string path = loaderData.LoadPath;

        StreamReader sr = new StreamReader(path, System.Text.Encoding.GetEncoding("utf-8"));

        // 内容をすべて読み込む
        string text = sr.ReadToEnd();

        // 閉じる
        sr.Close();

        string toPath = loaderData.SavePath;
        File.WriteAllText(toPath, text, System.Text.Encoding.GetEncoding("utf-8"));
        yield return(null);
#else
        //string path = Application.streamingAssetsPath + "/" + "Utility.lua";
        string path = loaderData.LoadPath;
        Debug.Log("-----Resources load-----");
        WWW www = new WWW(path);
        while (!www.isDone)
        {
            yield return(null);
        }

        //string toPath = Application.persistentDataPath + "/LuaUtility.lua";
        string toPath = loaderData.SavePath;
        File.WriteAllBytes(toPath, www.bytes);
#endif
        LoadDataStackList.RemoveAt(0);
        IsLoading = false;

        loaderData.CallbackName     = loaderData.CallbackName;
        loaderData.CallbackFunction = loaderData.CallbackFunction;

        if (loaderData.CallbackName != "")
        {
            string functionName          = loaderData.CallbackName;
            LuaManager.FunctionData data = new LuaManager.FunctionData();
            data.returnValueNum = 0;
            data.functionName   = functionName;
            ArrayList list = new ArrayList();
            data.argList = list;
            ArrayList returnList = LuaManager.Instance.Call(UnityUtility.Instance.scriptName, data);
        }

        if (loaderData.CallbackFunction != null)
        {
            loaderData.CallbackFunction();
        }
    }
Пример #5
0
 // Update is called once per frame
 void Update()
 {
     if (IsLoading == false)
     {
         if (LoadDataStackList.Count > 0)
         {
             LoaderData data = LoadDataStackList[0];
             StartCoroutine(ResourceLoad(data));
             IsLoading = true;
         }
     }
 }
Пример #6
0
    public void LoadAssetAsync <T>(string path, Action <Object> afterLoaded)
    {
        if (afterLoaded == null)
        {
            Debuger.LogError($"try to load async but set a null action,asset path-> {path}");
            return;
        }

        LoaderData data = new LoaderData(path, afterLoaded, typeof(T));

        _waitForLoadQueue.Enqueue(data);
    }
Пример #7
0
        static void Main(string[] args)
        {
            var dataProvider     = new LoaderData(DataFilePath);
            var toXmlTransformer = new XmlConverter();
            var logger           = LoggerFactory.GetLogger("Program");

            var parserUrl   = new XmlDataExporter(logger);
            var xmlDocument = parserUrl.CreateXmlWithData(dataProvider, toXmlTransformer);

            xmlDocument.Save("result_xml.xml");

            Console.ReadLine();
        }
Пример #8
0
        public static LoaderData Get(LoaderType type)
        {
            LoaderData loaderData = null;

            switch (type)
            {
            case LoaderType.Asset:
                loaderData = s_AssetLoaderDataPool.Get();
                break;

            case LoaderType.BundleAsset:
                loaderData = s_BundleAssetLoaderDataPool.Get();
                break;

            case LoaderType.Bundle:
                if (ConstantData.enableAssetBundle)
                {
                    loaderData = s_CacheBundleLoaderDataPool.Get();
                }
                else
                {
                    loaderData = s_BundleLoaderDataPool.Get();
                }
                break;

            case LoaderType.Resource:
                loaderData = s_ResourceLoaderDataPool.Get();
                break;

            case LoaderType.Scene:
                loaderData = s_SceneLoaderDataPool.Get();
                break;

            case LoaderType.Stream:
                loaderData = s_StreamLoaderDataPool.Get();
                break;
            }

            if (null != loaderData && null == loaderData.loader)
            {
                loaderData.loader = LoaderPool.Get(type);
            }

            return(loaderData);
        }
Пример #9
0
        public static void Release(LoaderData loaderData)
        {
            switch (loaderData.loader.type)
            {
            case LoaderType.Asset:
                s_AssetLoaderDataPool.Release(loaderData);
                break;

            case LoaderType.BundleAsset:
                s_BundleAssetLoaderDataPool.Release(loaderData);
                break;

            case LoaderType.Bundle:
                if (ConstantData.enableAssetBundle)
                {
                    s_CacheBundleLoaderDataPool.Release(loaderData);
                }
                else
                {
                    s_BundleLoaderDataPool.Release(loaderData);
                }
                break;

            case LoaderType.Resource:
                s_ResourceLoaderDataPool.Release(loaderData);
                break;

            case LoaderType.Scene:
                s_SceneLoaderDataPool.Release(loaderData);
                break;

            case LoaderType.Stream:
                s_StreamLoaderDataPool.Release(loaderData);
                break;
            }
        }
Пример #10
0
    public void Update()
    {
        if (nowData == null)
        {
            if (waitings.Count == 0)
            {
                return;
            }
            nowData = waitings[0];

            //查找是否已经加载
            if (loadedDic.ContainsKey(nowData.assetPath))
            {
                if (nowData.callback != null)
                {
                    //Debug.LogError("wtf.");
                    //nowData.callback(loadedDic[nowData.assetPath].go, nowData.param);
                    request         = loadedDic[nowData.assetPath].request;
                    nowData.request = request;
                }
                else
                {
                    waitings.RemoveAt(0);
                    nowData = null;
                }
                return;
            }

            //find depend
            string[] str = abmf.GetAllDependencies(nowData.assetPath);
            if (str == null || str.Length == 0)
            {
                //没有依赖,直接加载本资源
                string path = streammingPath + nowData.assetPath;
                request         = AssetBundle.LoadFromFileAsync(path.ToLower());
                nowData.request = request;
            }
            else
            {
                //有依赖,把依赖加入队首
                bool flag = false;
                for (int i = 0; i < str.Length; ++i)
                {
                    if (loadedDic.ContainsKey(str[i]) == true)
                    {
                        continue;
                    }
                    flag = true;
                    LoaderData data = new LoaderData();
                    data.assetPath = str[i];
                    int t = data.assetPath.LastIndexOf("/");
                    data.assetName = data.assetPath.Substring(t + 1, data.assetPath.Length - t - 1);
                    waitings.Insert(0, data);
                }
                if (flag == false)
                {
                    string path = streammingPath + nowData.assetPath;
                    request         = AssetBundle.LoadFromFileAsync(path.ToLower());
                    nowData.request = request;
                }
                else
                {
                    nowData = null;
                    return;
                }
            }
        }

        if (request != null && request.isDone == true && abrequest == null)
        {
            if (nowData.callback == null)
            {
                loadedDic[nowData.assetPath] = nowData;
                abrequest = null;
                request   = null;
                nowData   = null;
                this.waitings.RemoveAt(0);
            }
            else
            {
                abrequest = request.assetBundle.LoadAssetAsync(nowData.assetName, typeof(GameObject));
            }
        }

        if (request != null && request.isDone == true && abrequest != null && abrequest.isDone == true)
        {
            if (nowData.callback != null)
            {
                nowData.callback(abrequest.asset as GameObject, nowData.param);
            }

            loadedDic[nowData.assetPath] = nowData;

            abrequest = null;
            request   = null;
            nowData   = null;
            this.waitings.RemoveAt(0);
        }
    }