Exemple #1
0
        IEnumerator TryGetVersion()
        {
            var ManifestPath = string.Format("{0}{1}", AssetBundlePath, VersionFileName);

            using (UnityWebRequest uwr = UnityWebRequest.Get(ManifestPath))
            {
                yield return(uwr.SendWebRequest());

                if (uwr.isNetworkError || uwr.error != null)
                {
                    FrameDebug.LogError(String.Format("File -{0}- Download failed{1}", ManifestPath, uwr.error));
                    yield break;
                }
                m_dataMap.Clear();
                var data  = Encoding.UTF8.GetString(uwr.downloadHandler.data);
                var infos = data.Split('\n');
                foreach (var item in infos)
                {
                    var texts    = item.Split('\t');
                    var itemdata = new ResItemData();

                    itemdata.resName            = texts[0];
                    itemdata.resHash            = texts[1];
                    itemdata.resSize            = int.Parse(texts[2]);
                    m_dataMap[itemdata.resName] = itemdata;
                }
                FrameDebug.Log(string.Format("Finish Download Version"));
                verReadFinished = true;
            }
        }
Exemple #2
0
        /// <summary>
        /// 缓存的unity objects
        /// 请求过的物体会在这里缓存起来
        /// </summary>
        public T Load <T>(string path) where T : class, new()
        {
            T      obj  = null;
            Object temp = null;

            if (CachedObjects.TryGetValue(path, out temp))
            {// 尝试在缓存中查找
                obj = temp as T;
                return(obj);
            }
            var fileName = path.Replace("/", DIR_SPLIT);//替换目录分隔符

            if (DownloadedFiles.ContainsKey(fileName))
            {
                FileInfo file       = DownloadedFiles[fileName];
                var      bytes      = File.ReadAllBytes(file.FullName);
                var      ab         = AssetBundle.LoadFromMemory(bytes);
                string   objectName = Path.GetFileName(path);
                temp = ab.LoadAsset(objectName, typeof(T));
                obj  = temp as T;
                ab.Unload(false);//一旦加载完毕,立即释放assetbundle,但不释放bundle中的物体。
                if (obj == null)
                {
                    FrameDebug.LogError(string.Format("the resource {0} load from ab is null", path));
                    return(null);
                }
                CachedObjects.Add(path, temp);
            }
            else
            {
                temp = Resources.Load(path, typeof(T));
                obj  = temp as T;
            }
            return(obj);
        }
Exemple #3
0
        public static string GetAssetBuildPath(BuildTarget target)
        {
            switch (target)
            {
            case BuildTarget.StandaloneWindows64:
                return(GetFullOutPutDir(target) + "Windows");

            default:
                FrameDebug.LogError("Dont Contain target" + target.ToString());
                return(GetFullOutPutDir(target) + "default");
            }
        }
Exemple #4
0
        public static string GetFullOutPutDir(BuildTarget target)
        {
            switch (target)
            {
            case BuildTarget.StandaloneWindows64:
                return(Application.dataPath.Remove(Application.dataPath.Length - 6) + GetOutPutDir(target));

            default:
                FrameDebug.LogError("Dont Contain target" + target.ToString());
                return("AssetBundles");
            }
        }
Exemple #5
0
 void Awake()
 {
     DontDestroyOnLoad(gameObject);
     if (Ins == null)
     {
         Ins    = this;
         Inited = false;
         FindMdule();
     }
     else
     {
         FrameDebug.LogError("Client has been created mutiple times!");
     }
 }
Exemple #6
0
        static string GetTargetName(BuildTarget target)
        {
            switch (target)
            {
            case BuildTarget.StandaloneWindows64:
                return("Windows");

            case BuildTarget.StandaloneWindows:
                return("Windows");

            default:
                FrameDebug.LogError("Null Target Name");
                return("");
            }
        }
Exemple #7
0
        private static byte[] CustomLoader(ref string filepath)
        {
            string scriptPath = string.Empty;

            filepath = filepath.Replace(".", "/") + ".lua";

            scriptPath = Path.Combine(luaScriptsFullPath, filepath);
            if (!File.Exists(scriptPath))
            {
                FrameDebug.LogError("Error Lua Script Path" + scriptPath);
                return(null);
            }
            File.SetAttributes(scriptPath, FileAttributes.Normal);
            return(File.ReadAllBytes(scriptPath));
        }
Exemple #8
0
 public static string GetMD5(string path)
 {
     try
     {
         Stream        st   = new FileStream(path, FileMode.Open, FileAccess.Read);
         MD5           md5  = new MD5CryptoServiceProvider();
         StringBuilder sb   = new StringBuilder();
         var           temp = md5.ComputeHash(st);
         foreach (var item in temp)
         {
             sb.Append(item.ToString("x2"));
         }
         st.Dispose();
         return(sb.ToString());
     }
     catch (Exception ex)
     {
         FrameDebug.LogError(ex.ToString());
         return("");
     }
 }