Exemplo n.º 1
0
 /// <summary>
 /// 初始化内存读写。
 /// </summary>
 public override void Init(byte[] data)
 {
     LoggerHelper.Error("Error Invoke");
 }
Exemplo n.º 2
0
 /// <summary>
 /// 打开文件读写。
 /// </summary>
 public override void Init(string fileName)
 {
     LoggerHelper.Error("Error Invoke");
 }
Exemplo n.º 3
0
        public static void DecompressToMogoFileAndDirectory(string targetPath, string zipFilePath)
        {
            if (File.Exists(zipFilePath))
            {
                var source = File.OpenRead(zipFilePath);
                MogoFileSystem.Instance.Open();
                MogoFileSystem.Instance.GetAndBackUpIndexInfo();
                using (ZipInputStream decompressor = new ZipInputStream(source))
                {
                    ZipEntry entry;

                    while ((entry = decompressor.GetNextEntry()) != null)
                    {
                        if (entry.IsDirectory)
                        {
                            continue;
                        }
                        string filePath = entry.Name;
                        if (String.IsNullOrEmpty(filePath))
                        {
                            continue;
                        }
                        byte[] data = new byte[2048];
                        int    bytesRead;

                        if (filePath.EndsWith(".u"))
                        {
                            filePath = Path.Combine(targetPath, filePath);

                            string directoryPath = Path.GetDirectoryName(filePath);

                            if (!string.IsNullOrEmpty(directoryPath) && !Directory.Exists(directoryPath))
                            {
                                Directory.CreateDirectory(directoryPath);
                            }
                            using (FileStream streamWriter = File.Create(filePath))
                            {
                                while ((bytesRead = decompressor.Read(data, 0, data.Length)) > 0)
                                {
                                    streamWriter.Write(data, 0, bytesRead);
                                }
                            }
                        }
                        else
                        {
                            var info = MogoFileSystem.Instance.BeginSaveFile(filePath, entry.Size);
                            while ((bytesRead = decompressor.Read(data, 0, data.Length)) > 0)
                            {
                                MogoFileSystem.Instance.WriteFile(info, data, 0, bytesRead);
                            }
                            MogoFileSystem.Instance.EndSaveFile(info);
                        }
                    }
                }
                MogoFileSystem.Instance.SaveIndexInfo();
                MogoFileSystem.Instance.CleanBackUpIndex();
                MogoFileSystem.Instance.Close();
            }
            else
            {
                LoggerHelper.Error("Zip file not exist: " + zipFilePath);
            }
        }
Exemplo n.º 4
0
        private static IEnumerator LoadUIWWWAssets(List <Resource> list, Action loaded)
        {
            int index = 0;
            Dictionary <Material, Resource[]> matPngMapping = null;

            //List<Resource> unloadList = null;
            while (index < list.Count)
            {
                var res = list[index];
                index++;
                if (res.RelativePath.EndsWith("FZY4JW.TTF"))
                {
                    res.IsDone = true;
                    yield return(null);
                }
                else if (res.IsDone)
                {
                    yield return(null);
                }
                else
                {
                    var path = WithSuffix(res.RelativePath);
                    ResourceWachter.Instance.Watch(path);
                    string url = String.Concat(SystemConfig.ResourceFolder, path);
                    if (File.Exists(url))
                    {
                        url = String.Concat(SystemConfig.ASSET_FILE_HEAD, url);
                    }
                    else
                    {
                        url = Utils.GetStreamPath(path);
                    }
                    var www = new WWW(url);
                    yield return(www);

                    res.www = www;
                    if (res.www.assetBundle != null)
                    {
                        res.www.assetBundle.LoadAll();
                        res.IsDone   = true;
                        res.m_object = res.www.assetBundle.mainAsset;
                    }
                    if (res.RelativePath.EndsWith(".mat") && (res.RelativePath.Contains("Resources/MogoUI/") || res.RelativePath.Contains("Resources/GUI/")))
                    {
                        //LoggerHelper.Debug("mat: " + res.RelativePath);
                        if (matPngMapping == null)
                        {
                            matPngMapping = new Dictionary <Material, Resource[]>();
                        }
                        if (res.dependencies == null)
                        {
                            LoggerHelper.Warning("null dep: " + res.RelativePath);
                        }
                        else
                        {
                            var r   = res.dependencies.Where(t => t.RelativePath.EndsWith(".png")).ToArray();
                            var mat = res.m_object as Material;
                            if (r != null && mat != null)
                            {
                                matPngMapping.Add(mat, r);
                            }
                        }
                    }
                    else if (res.RelativePath.EndsWith(".png") && (res.RelativePath.Contains("Resources/Textures/")))// && list.Count != 1 //  || res.RelativePath.Contains("Resources/Images/")
                    {
                        //if (unloadList == null)
                        //    unloadList = new List<Resource>();
                        //unloadList.Add(res);
                        //LoggerHelper.Debug("png: " + res.RelativePath);
                        //res.Release(false);
                        //res.IsDone = false;
                        //res.m_neverUnloadAsset = true;
                        //res.www.assetBundle.Unload(false);
                        //res.www = null;
                        //www.Dispose();
                        res.Release(false);
                    }
                    else if (res.RelativePath.EndsWith("FontMsyh.prefab") || res.RelativePath.EndsWith("FontMsyh2.prefab") ||
                             res.RelativePath.EndsWith("FontMsyh3.prefab") || res.RelativePath.EndsWith("TeachFontMsyh.prefab"))
                    {
                        //LoggerHelper.Error("font prefab: " + res.RelativePath);
                        var prefab = res.m_object as GameObject;
                        if (prefab)
                        {
                            var font = prefab.GetComponent <UIFont>();
                            if (font)
                            {
                                font.dynamicFont = Resources.Load("Font/FZY4JW") as Font;
                            }
                            else
                            {
                                LoggerHelper.Error("null font: " + res.RelativePath);
                            }
                        }
                        else
                        {
                            LoggerHelper.Error("null font prefab: " + res.RelativePath);
                        }
                    }
                }
            }
            if (matPngMapping != null)
            {
                foreach (var item in matPngMapping)
                {
                    if (item.Value != null && item.Value.Length != 0)
                    {
                        if (item.Key.shader.name.EndsWith("ETC"))
                        {
                            LoggerHelper.Warning("ETC shader: " + item.Key.name);
                        }
                        //    for (int i = 0; i < item.Value.Length; i++)
                        //    {
                        //        var tex = item.Value[i];
                        //        if (tex.RelativePath.Contains("_A"))
                        //            item.Key.SetTexture("_AlphaTex", tex.m_object as Texture);
                        //        else
                        //            item.Key.SetTexture("_MainTex", tex.m_object as Texture);
                        //    }
                        //}
                        //else
                        //{
                        for (int i = 0; i < item.Value.Length; i++)//这里很奇怪,赶脚跟打包有关系,不过先不判断一起处理先,这样可以没问题,估计效率影响不会太大
                        {
                            var tex = item.Value[i];
                            if (tex.RelativePath.Contains("_A"))
                            {
                                item.Key.SetTexture("_AlphaTex", tex.m_object as Texture);
                            }
                            else
                            {
                                item.Key.SetTexture("_MainTex", tex.m_object as Texture);
                            }
                        }
                        //item.Key.mainTexture = item.Value[0].m_object as Texture;
                        //}
                    }
                }
                matPngMapping.Clear();
            }
            if (list.Count != 0)
            {
                var prefab = list[list.Count - 1];
                if (prefab.RelativePath.EndsWith(".prefab"))
                {
                    prefab.Release(false);
                }
                else
                {
                    LoggerHelper.Warning("root not prefab: " + prefab.RelativePath);
                }
            }
            //if (unloadList != null)
            //{
            //    for (int i = 0; i < unloadList.Count; i++)
            //    {
            //        unloadList[i].Release(false);
            //    }
            //}
            if (loaded != null)
            {
                loaded();
            }
        }
Exemplo n.º 5
0
        public static Dictionary <int, Dictionary <string, string> > LoadIntMap(SecurityElement xml, string source)
        {
            Dictionary <int, Dictionary <string, string> > dictionary = new Dictionary <int, Dictionary <string, string> >();
            int num = 0;

            foreach (SecurityElement element in xml.Children)
            {
                num++;
                if ((element.Children == null) || (element.Children.Count == 0))
                {
                    LoggerHelper.Warning(string.Concat(new object[] { "empty row in row NO.", num, " of ", source }), true);
                }
                else
                {
                    SecurityElement element2 = element.Children[0] as SecurityElement;
                    if (!element2.Tag.StartsWith("id"))
                    {
                        LoggerHelper.Error(string.Format("First element '{0}' not name as 'id_i', in {1}.", element2.Tag, source), true);
                    }
                    int key = int.Parse(element2.Text);
                    if (dictionary.ContainsKey(key))
                    {
                        LoggerHelper.Warning(string.Format("Key {0} already exist, in {1}.", key, source), true);
                    }
                    else
                    {
                        Dictionary <string, string> dictionary2 = new Dictionary <string, string>();
                        dictionary.Add(key, dictionary2);
                        for (int i = 1; i < element.Children.Count; i++)
                        {
                            string          tag;
                            SecurityElement element3 = element.Children[i] as SecurityElement;
                            if (element3.Tag.Length < 3)
                            {
                                tag = element3.Tag;
                            }
                            else
                            {
                                string str2 = element3.Tag.Substring(element3.Tag.Length - 2, 2);
                                if (((((str2 == "_i") || (str2 == "_s")) || ((str2 == "_f") || (str2 == "_l"))) || (str2 == "_k")) || (str2 == "_m"))
                                {
                                    tag = element3.Tag.Substring(0, element3.Tag.Length - 2);
                                }
                                else
                                {
                                    tag = element3.Tag;
                                }
                            }
                            if ((element3 != null) && !dictionary2.ContainsKey(tag))
                            {
                                if (string.IsNullOrEmpty(element3.Text))
                                {
                                    dictionary2.Add(tag, "");
                                }
                                else
                                {
                                    dictionary2.Add(tag, element3.Text.Trim());
                                }
                            }
                            else
                            {
                                LoggerHelper.Warning(string.Format("Key {0} already exist, index {1} of {2}.", element3.Tag, i, element3.ToString()), true);
                            }
                        }
                    }
                }
            }
            return(dictionary);
        }
Exemplo n.º 6
0
        /// <summary>
        /// 从指定的 XML 文档加载 map 数据。
        /// </summary>
        /// <param name="xml">XML 文档</param>
        /// <returns>map 数据</returns>
        public static Dictionary <Int32, Dictionary <String, String> > LoadIntMap(SecurityElement xml, string source)
        {
            var result = new Dictionary <Int32, Dictionary <String, String> >();

            var index = 0;

            foreach (SecurityElement subMap in xml.Children)
            {
                index++;
                if (subMap.Children == null || subMap.Children.Count == 0)
                {
                    //LoggerHelper.Warning("empty row in row NO." + index + " of " + source);
                    continue;
                }
                var se = subMap.Children[0] as SecurityElement;
                if (!se.Tag.StartsWith("id"))
                {
                    LoggerHelper.Error(String.Format("First element '{0}' not name as 'id_i', in {1}.", se.Tag, source));
                }
                Int32 key = Int32.Parse(se.Text);
                if (result.ContainsKey(key))
                {
                    LoggerHelper.Warning(String.Format("Key {0} already exist, in {1}.", key, source));
                    continue;
                }

                var children = new Dictionary <String, String>();
                result.Add(key, children);
                for (int i = 1; i < subMap.Children.Count; i++)
                {
                    var node = subMap.Children[i] as SecurityElement;
                    //对属性名称部分后缀进行裁剪
                    string tag;
                    if (node.Tag.Length < 3)
                    {
                        tag = node.Tag;
                    }
                    else
                    {
                        var tagTial = node.Tag.Substring(node.Tag.Length - 2, 2);
                        if (tagTial == "_i" || tagTial == "_s" || tagTial == "_f" || tagTial == "_l" || tagTial == "_k" || tagTial == "_m")
                        {
                            tag = node.Tag.Substring(0, node.Tag.Length - 2);
                        }
                        else
                        {
                            tag = node.Tag;
                        }
                    }

                    if (node != null && !children.ContainsKey(tag))
                    {
                        if (String.IsNullOrEmpty(node.Text))
                        {
                            children.Add(tag, "");
                        }
                        else
                        {
                            children.Add(tag, node.Text.Trim());
                        }
                    }
                    else
                    {
                        LoggerHelper.Warning(String.Format("Key {0} already exist, index {1} of {2}.", node.Tag, i, node.ToString()));
                    }
                }
            }
            return(result);
        }