Esempio n. 1
0
        public static Dictionary <string, string> GetResourcePathMap()
        {
            var sw = new System.Diagnostics.Stopwatch();

            sw.Start();
            var result = new Dictionary <string, string>();

            foreach (var item in metaOfResource)
            {
                var name = Utils.GetFileName(item.Key);
                if (result.ContainsKey(name))
                {
                    LoggerHelper.Warning("Same resource name; " + name);
                }
                else
                {
                    result.Add(name, item.Key);
                }
            }
            sw.Stop();
            LoggerHelper.Debug("metaOfResource: " + metaOfResource.Count);
            LoggerHelper.Debug("time: " + sw.ElapsedMilliseconds);
            //Mogo.Util.LoggerHelper.Debug(result.PackMap(mapSpriter: '\n'));
            return(result);
        }
Esempio n. 2
0
        public static Dictionary <string, string> ParseMap(this string strMap, char keyValueSpriter = ':', char mapSpriter = ',')
        {
            Dictionary <string, string> dictionary = new Dictionary <string, string>();

            if (!string.IsNullOrEmpty(strMap))
            {
                string[] strArray = strMap.Split(new char[] { mapSpriter });
                for (int i = 0; i < strArray.Length; i++)
                {
                    if (!string.IsNullOrEmpty(strArray[i]))
                    {
                        string[] strArray2 = strArray[i].Split(new char[] { keyValueSpriter });
                        if (strArray2.Length == 2)
                        {
                            if (!dictionary.ContainsKey(strArray2[0]))
                            {
                                dictionary.Add(strArray2[0], strArray2[1]);
                            }
                            else
                            {
                                LoggerHelper.Warning(string.Format("Key {0} already exist, index {1} of {2}.", strArray2[0], i, strMap), true);
                            }
                        }
                        else
                        {
                            LoggerHelper.Warning(string.Format("KeyValuePair are not match: {0}, index {1} of {2}.", strArray[i], i, strMap), true);
                        }
                    }
                }
            }
            return(dictionary);
        }
Esempio n. 3
0
        private void DoReceive()
        {
            //读取流
            do
            {
                bytesRead = 0;
                try
                {
                    int size = MAX_BUFFER_SIZE - m_nRecvBufferSize;
                    if (size > 0)
                    {
                        bytesRead          = m_socket.Receive(m_recvBuffer, m_nRecvBufferSize, size, SocketFlags.None);
                        m_nRecvBufferSize += bytesRead;
                        if (bytesRead == 0)
                        {//读的长度为0
                            bytesRead = 1;
                        }
                    }
                    else
                    {
                        bytesRead = 1;//缓存不够时继续循环,后面会对缓存数据进行处理
                        LoggerHelper.Warning("buffer not enough");
                    }
                }
                catch (ObjectDisposedException)
                {
                    // 网络流已被关闭,结束接收数据
                    LoggerHelper.Error("tcp close");
                }
                catch (IOException ioex)
                {
                    //捕获WSACancelBlockingCall()导致的异常。
                    //原因:强迫终止一个在进行的阻塞调用。
                    //可直接捕获忽略,应该不会有不良影响。
                    //LoggerHelper.Error("WSACancelBlockCall");
                    LoggerHelper.Except(ioex);
                }
                catch (Exception ex)
                {
                    LoggerHelper.Except(ex);
                }
                //LoggerHelper.Debug("DataReceive: " + bytesRead);
                SplitPackets();
            } while (bytesRead > 0);

            lock (m_connectCheckerLocker)
                if (m_ConnectChecker > 0)
                {
                    m_ConnectChecker--;
                    LoggerHelper.Debug("Disconnected.m_ConnectChecker: " + m_ConnectChecker);
                }
                else
                {
                    LoggerHelper.Error("receive bytes " + bytesRead);
                    TimerHeap.AddTimer(1000, 0, OnNetworkDisconnected);
                }

            LoggerHelper.Debug("DataReceiveComplete");
        }
Esempio n. 4
0
 private void DoReceive()
 {
     do
     {
         this.bytesRead = 0;
         try
         {
             int size = 0xffff - this.m_nRecvBufferSize;
             if (size > 0)
             {
                 this.bytesRead          = this.m_socket.Receive(this.m_recvBuffer, this.m_nRecvBufferSize, size, SocketFlags.None);
                 this.m_nRecvBufferSize += this.bytesRead;
                 if (this.bytesRead == 0)
                 {
                     this.bytesRead = 1;
                 }
             }
             else
             {
                 this.bytesRead = 1;
                 LoggerHelper.Warning("buffer not enough", true);
             }
         }
         catch (ObjectDisposedException)
         {
             LoggerHelper.Error("tcp close", true);
         }
         catch (IOException exception)
         {
             LoggerHelper.Except(exception, null);
         }
         catch (Exception exception2)
         {
             LoggerHelper.Except(exception2, null);
         }
         this.SplitPackets();
     }while (this.bytesRead > 0);
     lock (this.m_connectCheckerLocker)
     {
         if (this.m_ConnectChecker > 0)
         {
             this.m_ConnectChecker--;
             LoggerHelper.Debug("Disconnected.m_ConnectChecker: " + this.m_ConnectChecker, true, 0);
         }
         else
         {
             LoggerHelper.Error("receive bytes " + this.bytesRead, true);
             TimerHeap.AddTimer(0x3e8, 0, this.OnNetworkDisconnected);
         }
     }
     LoggerHelper.Debug("DataReceiveComplete", true, 0);
 }
Esempio n. 5
0
        /// <summary>
        /// 将字典字符串转换为键类型为字符串,值类型为整型的字典对象。
        /// </summary>
        /// <param name="strMap">字典字符串</param>
        /// <param name="keyValueSpriter">键值分隔符</param>
        /// <param name="mapSpriter">字典项分隔符</param>
        /// <returns>字典对象</returns>
        public static Dictionary <String, Int32> ParseMapStringInt(this String strMap, Char keyValueSpriter = KEY_VALUE_SPRITER, Char mapSpriter = MAP_SPRITER)
        {
            Dictionary <String, Int32> result = new Dictionary <String, Int32>();
            var strResult = ParseMap(strMap, keyValueSpriter, mapSpriter);

            foreach (var item in strResult)
            {
                int value;
                if (int.TryParse(item.Value, out value))
                {
                    result.Add(item.Key, value);
                }
                else
                {
                    LoggerHelper.Warning(String.Format("Parse failure: {0}", item.Value));
                }
            }
            return(result);
        }
Esempio n. 6
0
        public static Dictionary <string, int> ParseMapStringInt(this string strMap, char keyValueSpriter = ':', char mapSpriter = ',')
        {
            Dictionary <string, int>    dictionary  = new Dictionary <string, int>();
            Dictionary <string, string> dictionary2 = strMap.ParseMap(keyValueSpriter, mapSpriter);

            foreach (KeyValuePair <string, string> pair in dictionary2)
            {
                int num;
                if (int.TryParse(pair.Value, out num))
                {
                    dictionary.Add(pair.Key, num);
                }
                else
                {
                    LoggerHelper.Warning(string.Format("Parse failure: {0}", pair.Value), true);
                }
            }
            return(dictionary);
        }
Esempio n. 7
0
        static public bool GetPointInTerrain(float x, float z, out Vector3 point)
        {
            //Mogo.Util.LoggerHelper.Debug("GetPointInTerrain");
            RaycastHit hit;
            //var flag = Physics.Raycast(new Vector3(x, 500, z), Vector3.down, out hit,1000, (int)LayerMask.Terrain);
            var flag = Physics.Linecast(new Vector3(x, 1000, z), new Vector3(x, -1000, z), out hit, (int)LayerMask.Terrain);

            if (flag)
            {
                //Mogo.Util.LoggerHelper.Debug("hit.point: " + hit.point);
                point = new Vector3(hit.point.x, hit.point.y + 0.2f, hit.point.z);
                return(true);
            }
            else
            {
                point = new Vector3(x, 50, z);
                //Mogo.Util.LoggerHelper.Debug("hit nothing: " + x + " " + z);
                LoggerHelper.Warning("hit noting:" + x + "," + z);
                return(false);
            }
        }
Esempio n. 8
0
        public static Dictionary <T, U> ParseMapAny <T, U>(this string strMap, char keyValueSpriter = ':', char mapSpriter = ',')
        {
            Type type  = typeof(T);
            Type type2 = typeof(U);
            Dictionary <T, U>           dictionary  = new Dictionary <T, U>();
            Dictionary <string, string> dictionary2 = strMap.ParseMap(keyValueSpriter, mapSpriter);

            foreach (KeyValuePair <string, string> pair in dictionary2)
            {
                try
                {
                    T key    = (T)GetValue(pair.Key, type);
                    U local2 = (U)GetValue(pair.Value, type2);
                    dictionary.Add(key, local2);
                }
                catch (Exception)
                {
                    LoggerHelper.Warning(string.Format("Parse failure: {0}, {1}", pair.Key, pair.Value), true);
                }
            }
            return(dictionary);
        }
Esempio n. 9
0
        public static Dictionary <string, Dictionary <string, string> > LoadMap(SecurityElement xml)
        {
            Dictionary <string, Dictionary <string, string> > dictionary = new Dictionary <string, Dictionary <string, string> >();

            foreach (SecurityElement element in xml.Children)
            {
                string key = (element.Children[0] as SecurityElement).Text.Trim();
                if (dictionary.ContainsKey(key))
                {
                    LoggerHelper.Warning(string.Format("Key {0} already exist, in {1}.", key, xml.ToString()), true);
                }
                else
                {
                    Dictionary <string, string> dictionary2 = new Dictionary <string, string>();
                    dictionary.Add(key, dictionary2);
                    for (int i = 1; i < element.Children.Count; i++)
                    {
                        SecurityElement element2 = element.Children[i] as SecurityElement;
                        if ((element2 != null) && !dictionary2.ContainsKey(element2.Tag))
                        {
                            if (string.IsNullOrEmpty(element2.Text))
                            {
                                dictionary2.Add(element2.Tag, "");
                            }
                            else
                            {
                                dictionary2.Add(element2.Tag, element2.Text.Trim());
                            }
                        }
                        else
                        {
                            LoggerHelper.Warning(string.Format("Key {0} already exist, index {1} of {2}.", element2.Tag, i, element2.ToString()), true);
                        }
                    }
                }
            }
            return(dictionary);
        }
Esempio n. 10
0
        /// <summary>
        /// 将字典字符串转换为键类型与值类型都为字符串的字典对象。
        /// </summary>
        /// <param name="strMap">字典字符串</param>
        /// <param name="keyValueSpriter">键值分隔符</param>
        /// <param name="mapSpriter">字典项分隔符</param>
        /// <returns>字典对象</returns>
        public static Dictionary <String, String> ParseMap(this String strMap, Char keyValueSpriter = KEY_VALUE_SPRITER, Char mapSpriter = MAP_SPRITER)
        {
            Dictionary <String, String> result = new Dictionary <String, String>();

            if (String.IsNullOrEmpty(strMap))
            {
                return(result);
            }

            var map = strMap.Split(mapSpriter);//根据字典项分隔符分割字符串,获取键值对字符串

            for (int i = 0; i < map.Length; i++)
            {
                if (String.IsNullOrEmpty(map[i]))
                {
                    continue;
                }

                var keyValuePair = map[i].Split(keyValueSpriter);//根据键值分隔符分割键值对字符串
                if (keyValuePair.Length == 2)
                {
                    if (!result.ContainsKey(keyValuePair[0]))
                    {
                        result.Add(keyValuePair[0], keyValuePair[1]);
                    }
                    else
                    {
                        LoggerHelper.Warning(String.Format("Key {0} already exist, index {1} of {2}.", keyValuePair[0], i, strMap));
                    }
                }
                else
                {
                    LoggerHelper.Warning(String.Format("KeyValuePair are not match: {0}, index {1} of {2}.", map[i], i, strMap));
                }
            }
            return(result);
        }
Esempio n. 11
0
        /// <summary>
        /// 从指定的 XML 文档加载 map 数据。
        /// </summary>
        /// <param name="xml">XML 文档</param>
        /// <returns>map 数据</returns>
        public static Dictionary <String, Dictionary <String, String> > LoadMap(SecurityElement xml)
        {
            var result = new Dictionary <String, Dictionary <String, String> >();

            foreach (SecurityElement subMap in xml.Children)
            {
                String key = (subMap.Children[0] as SecurityElement).Text.Trim();
                if (result.ContainsKey(key))
                {
                    LoggerHelper.Warning(String.Format("Key {0} already exist, in {1}.", key, xml.ToString()));
                    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;
                    if (node != null && !children.ContainsKey(node.Tag))
                    {
                        if (String.IsNullOrEmpty(node.Text))
                        {
                            children.Add(node.Tag, "");
                        }
                        else
                        {
                            children.Add(node.Tag, node.Text.Trim());
                        }
                    }
                    else
                    {
                        LoggerHelper.Warning(String.Format("Key {0} already exist, index {1} of {2}.", node.Tag, i, node.ToString()));
                    }
                }
            }
            return(result);
        }
Esempio n. 12
0
        /// <summary>
        /// 将字典字符串转换为键类型为 T,值类型为 U 的字典对象。
        /// </summary>
        /// <typeparam name="T">字典Key类型</typeparam>
        /// <typeparam name="U">字典Value类型</typeparam>
        /// <param name="strMap">字典字符串</param>
        /// <param name="keyValueSpriter">键值分隔符</param>
        /// <param name="mapSpriter">字典项分隔符</param>
        /// <returns>字典对象</returns>
        public static Dictionary <T, U> ParseMapAny <T, U>(this String strMap, Char keyValueSpriter = KEY_VALUE_SPRITER, Char mapSpriter = MAP_SPRITER)
        {
            var typeT  = typeof(T);
            var typeU  = typeof(U);
            var result = new Dictionary <T, U>();
            //先转为字典
            var strResult = ParseMap(strMap, keyValueSpriter, mapSpriter);

            foreach (var item in strResult)
            {
                try
                {
                    T key   = (T)GetValue(item.Key, typeT);
                    U value = (U)GetValue(item.Value, typeU);

                    result.Add(key, value);
                }
                catch (Exception)
                {
                    LoggerHelper.Warning(String.Format("Parse failure: {0}, {1}", item.Key, item.Value));
                }
            }
            return(result);
        }
Esempio n. 13
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();
            }
        }
Esempio n. 14
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);
        }
Esempio n. 15
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);
        }