Esempio n. 1
0
    public T Deserialize <T>(Stream stream)
    {
        T result = default(T);

#if !UNITY_WSA || !UNITY_WINRT
        try
        {
            StreamReader reader = new StreamReader(stream, Encoding.UTF8);
            result = JsonMapper.ToObject <T>(DataEncryptManager.StringDecoder(reader.ReadToEnd()));
            if (result == null)
            {
                result = default(T);
            }
            reader.Dispose();
        }
        catch (Exception ex)
        {
            StreamReader reader = new StreamReader(stream, Encoding.UTF8);
            Debug.Log(reader.ReadToEnd());
            Debug.LogException(ex);
        }
#else
        StreamReader reader = new StreamReader(stream, encoding);
        result = JsonUtility.FromJson <T> (reader.ReadToEnd());
        reader.Dispose();
#endif
        return(result);
    }
Esempio n. 2
0
        public PropertyProperty[] CreatePropertyPropertyArrayWithExcel(string filePath, PropertyPropertyManager iProperty)
        {
            List <string>            keys        = new List <string>();
            Dictionary <string, int> searchdic   = new Dictionary <string, int>();
            Dictionary <string, int> CNSearchdic = new Dictionary <string, int>();
            //获得表数据
            int columnNum = 0, rowNum = 0;
            DataRowCollection collect = ReadExcel(filePath, ref columnNum, ref rowNum, iProperty.TableName());

            //根据excel的定义,第二行开始才是数据
            PropertyProperty[]       array      = new PropertyProperty[rowNum - 2];
            Dictionary <string, int> properties = new Dictionary <string, int>();

            for (int i = 0; i < columnNum; i++)
            {
                if (collect[0][i].ToString() != string.Empty)
                {
                    properties.Add(collect[0][i].ToString(), i);
                }
            }
            for (int i = 2; i < rowNum; i++)
            {
                PropertyProperty item = new PropertyProperty();
                foreach (var singleProperty in properties)
                {
                    PropertyInfo property = typeof(PropertyProperty).GetProperty(singleProperty.Key);
                    if (property != null)
                    {
                        property.SetValue(item,
                                          DataEncryptManager.StringEncoder(TextTrans(collect[i][singleProperty.Value].ToString())));
                    }
                    else
                    {
                        Debug.LogError(singleProperty.Key);
                    }
                }
                //解析每列的数据
                searchdic.Add(DataEncryptManager.StringEncoder(collect[i][0].ToString()), i - 2);
                if (!string.IsNullOrEmpty(collect[i][1].ToString()))
                {
                    var str = Split(Pinyin.GetPinyin(collect[i][1].ToString()));
                    CNSearchdic.Add(str, i - 2);
                    keys.Add(str);
                }
                array[i - 2] = item;
            }
            iProperty.Search   = JsonMapper.ToJson(searchdic);
            iProperty.CNSearch = JsonMapper.ToJson(CNSearchdic);
            CreatePropertyEnum("PropertyPropertyType", keys);
            return(array);
        }
Esempio n. 3
0
        public int GetNum(string id)
        {
            var search = JsonMapper.ToObject <Dictionary <string, int> >(Search);

            if (search.ContainsKey(id))
            {
                return(search[id]);
            }
            else if (search.ContainsKey(DataEncryptManager.StringEncoder(id)))
            {
                return(search[DataEncryptManager.StringEncoder(id)]);
            }
            else
            {
                Debug.Log(id);
                return(-1);
            }
        }
Esempio n. 4
0
        public PropertyConst[] CreatePropertyConstArrayWithExcel(string filePath, ref string search)
        {
            List <string>            keys      = new List <string>();
            Dictionary <string, int> searchdic = new Dictionary <string, int>();
            //获得表数据
            int columnNum = 0, rowNum = 0;
            DataRowCollection collect = ReadExcel(filePath, ref columnNum, ref rowNum, 0);

            //根据excel的定义,第二行开始才是数据
            PropertyConst[]          array      = new PropertyConst[rowNum - 2];
            Dictionary <string, int> properties = new Dictionary <string, int>();

            for (int i = 0; i < columnNum; i++)
            {
                if (collect[0][i].ToString() != string.Empty)
                {
                    properties.Add(collect[0][i].ToString(), i);
                }
            }
            for (int i = 2; i < rowNum; i++)
            {
                keys.Add(collect[i][0] + "," + collect[i][1]);
                PropertyConst item = new PropertyConst();
                foreach (var singleProperty in properties)
                {
                    PropertyInfo property = typeof(PropertyConst).GetProperty(singleProperty.Key);
                    if (property != null)
                    {
                        property.SetValue(item,
                                          DataEncryptManager.StringEncoder(TextTrans(collect[i][singleProperty.Value].ToString())));
                    }
                    else
                    {
                        Debug.LogError(singleProperty.Key);
                    }
                }
                //解析每列的数据
                searchdic.Add(DataEncryptManager.StringEncoder(collect[i][0].ToString()), i - 2);
                array[i - 2] = item;
            }
            search = JsonMapper.ToJson(searchdic);
            CreateEnum("ConstType", keys);
            return(array);
        }
Esempio n. 5
0
    public void Serialize <T>(T obj, Stream stream)
    {
#if !UNITY_WSA || !UNITY_WINRT
        try
        {
            StreamWriter writer   = new StreamWriter(stream, Encoding.UTF8);
            string       jsonData = JsonMapper.ToJson(obj);//先json
            writer.Write(DataEncryptManager.StringEncoder(jsonData));
            writer.Dispose();
        }
        catch (Exception ex)
        {
            Debug.LogException(ex);
        }
#else
        StreamWriter writer = new StreamWriter(stream, encoding);
        writer.Write(JsonUtility.ToJson(obj));
        writer.Dispose();
#endif
    }
Esempio n. 6
0
        static T[] CreatePropertyArrayWithExcelBase <T>(int columnNum, int rowNum, DataRowCollection collect, ref string search) where T : new()
        {
            Dictionary <string, int> searchdic = new Dictionary <string, int>();

            //获得表数据
            //根据excel的定义,第二行开始才是数据
            T[] array = new T[rowNum - 2];
            Dictionary <string, int> properties = new Dictionary <string, int>();

            for (int i = 0; i < columnNum; i++)
            {
                var str = collect[0][i].ToString();
                str = str.Trim();
                if (str != string.Empty)
                {
                    properties.Add(str, i);
                }
            }
            for (int i = 2; i < rowNum; i++)
            {
                T item = new T();
                foreach (var singleProperty in properties)
                {
                    PropertyInfo property = typeof(T).GetProperty(singleProperty.Key);
                    if (property != null)
                    {
                        property.SetValue(item,
                                          DataEncryptManager.StringEncoder(TextTrans(collect[i][singleProperty.Value].ToString())));
                    }
                    else
                    {
                        Debug.LogError($"类型{typeof(T).ToString()}没有值:{singleProperty.Key}");
                    }
                }
                //解析每列的数据
                array[i - 2] = item;
                searchdic.Add(DataEncryptManager.StringEncoder(collect[i][0].ToString()), i - 2);
            }
            search = JsonMapper.ToJson(searchdic);
            return(array);
        }
Esempio n. 7
0
    public static void RefreshText()
    {
        string[]          sdirs       = { "Assets/Art/UIPrefab", "Assets/Editor Default Resources" };
        var               asstIds     = AssetDatabase.FindAssets("t:Prefab", sdirs);
        List <GameObject> gameObjects = new List <GameObject>();

        foreach (var asstId in asstIds)
        {
            string path = AssetDatabase.GUIDToAssetPath(asstId);
            var    pfb  = AssetDatabase.LoadAssetAtPath <GameObject>(path);
            gameObjects.Add(pfb);
        }
        int           i     = 0;
        List <UIText> texts = new List <UIText>();

        foreach (var pfb in gameObjects)
        {
            foreach (var text in pfb.GetComponentsInChildren <MyText>(true))
            {
                bool       exist = false;
                GameObject go    = null;
                foreach (var mono in pfb.GetComponentsInChildren <MonoBehaviour>(true))
                {
                    foreach (var field in mono.GetType().GetFields())
                    {
                        var xx = mono.GetFieldByReflect(field.Name);
                        if (xx.IsNotNull() && xx.GetType() == typeof(MyText))
                        {
                            if (xx.As <MyText>() == text)
                            {
                                go    = mono.gameObject;
                                exist = true;
                                break;
                            }
                        }
                    }
                }
                if (!exist && text.GetComponent("TextAdapt") == null)
                {
                    texts.Add(GetText(true, i, pfb.name, text));
                }
                else
                {
                    texts.Add(GetText(false, i, go?.gameObject.name, text));
                }
                text.Index = i;
                i++;
            }
            try
            {
                PrefabUtility.SavePrefabAsset(pfb);
            }
            catch (Exception e)
            {
                Debug.LogWarning(e.Message);
            }
        }

        //excel文本

        ExcelTool excelTool = new ExcelTool(true);
        PropertyExcelTextManager propertyExcelTextManager = ScriptableObject.CreateInstance <PropertyExcelTextManager>();

        propertyExcelTextManager.PropertyExcelText = excelTool.CreatePropertyExcelTextArrayWithExcel(propertyExcelTextManager);
        List <UIText>     excelTexts = new List <UIText>();
        LanguageTranslate translate  = new LanguageTranslate();

        for (int j = 0; j < propertyExcelTextManager.PropertyExcelText.Length; j++)
        {
            excelTexts.Add(new UIText()
            {
                Fixed              = true,
                Index              = j,
                Name               = DataEncryptManager.StringDecoder(propertyExcelTextManager.PropertyExcelText[j].ConstKey),
                ParentName         = "Excel",
                SimplifiedChineses = new List <string>()
                {
                    translate.ConvertChinSimp(propertyExcelTextManager.PropertyExcelText[j].ConstValue)
                },
                TraditionalChineses = new List <string>()
                {
                    translate.ConvertChinTrad(propertyExcelTextManager.PropertyExcelText[j].ConstValue)
                },
            });
        }
        UITextManager textManager = new UITextManager
        {
            FixedText = texts,
            ExcelText = excelTexts
        };

        AssetDatabase.CreateAsset(textManager, $"{ExcelConfig.assetPath}UITextManager.asset");
        AssetDatabase.SaveAssets();
        AssetDatabase.Refresh();
    }