예제 #1
0
    public GongFa GetGongFa(int gongfaId)
    {
        var newGf = new GongFa();

        newGf.GongFaId = gongfaId;
        var gongfa = DateFile.instance.gongFaDate[gongfaId];

        foreach (var prop in newGf.GetType().GetProperties())
        {
            var gfAttr = prop.GetCustomAttribute <GongFaAttribute>();
            if (gfAttr == null)
            {
                continue;
            }
            try
            {
                prop.SetValue(newGf, DataConvert(gongfa[gfAttr.Index], prop.PropertyType), null);
            }
            catch (System.Exception ex)
            {
                Debug.LogError($"数据转换错误,字段索引:{gfAttr.Index},字段名称;{gfAttr.DisplayName}");
                throw;
            }
        }
        return(newGf);
    }
예제 #2
0
    public void ChangeGongFa(int id)
    {
        c_gongfa = null;
        c_gongfa = GetGongFa(id);
        foreach (var item in properties)
        {
            if (AllInput.TryGetValue(item.Name, out var input))
            {
                var value = item.GetValue(c_gongfa).ToString();
                input.text = item.GetValue(c_gongfa).ToString();
                var tempColor = input.GetComponent <Image>().color;
                input.onEndEdit = new InputField.SubmitEvent();
                input.onEndEdit.AddListener((v) =>
                {
                    if (v == value)
                    {
                        return;
                    }
                    if (string.IsNullOrEmpty(v))
                    {
                        input.text = value;
                        input.GetComponent <Image>().color = Color.red;
                        return;
                    }
                    var gfAttr = item.GetCustomAttribute <GongFaAttribute>();
                    if ((item.PropertyType.Equals(typeof(int)) || item.PropertyType.Equals(typeof(float))) && (gfAttr.Max != int.MaxValue || gfAttr.Min != int.MinValue))
                    {
                        if (item.PropertyType.Equals(typeof(float)) && int.TryParse(v, out var i))
                        {
                            if (gfAttr.Max != int.MaxValue && i > gfAttr.Max)
                            {
                                input.text = value;
                                input.GetComponent <Image>().color = Color.red;
                                return;
                            }
                            if (gfAttr.Min != int.MinValue && i < gfAttr.Min)
                            {
                                input.text = value;
                                input.GetComponent <Image>().color = Color.red;
                                return;
                            }
                        }
                        if (item.PropertyType.Equals(typeof(float)) && float.TryParse(v, out var f))
                        {
                            if (gfAttr.Max != int.MaxValue && f > gfAttr.Max)
                            {
                                input.text = value;
                                input.GetComponent <Image>().color = Color.red;
                                return;
                            }
                            if (gfAttr.Min != int.MinValue && f < gfAttr.Min)
                            {
                                input.text = value;
                                input.GetComponent <Image>().color = Color.red;
                                return;
                            }
                        }
                        if (item.PropertyType.Equals(typeof(decimal)) && decimal.TryParse(v, out var d))
                        {
                            if (gfAttr.Max != int.MaxValue && d > gfAttr.Max)
                            {
                                input.text = value;
                                input.GetComponent <Image>().color = Color.red;
                                return;
                            }
                            if (gfAttr.Min != int.MinValue && d < gfAttr.Min)
                            {
                                input.text = value;
                                input.GetComponent <Image>().color = Color.red;
                                return;
                            }
                        }
                    }
                    input.GetComponent <Image>().color = tempColor;
                    if (!Main.EditHostory.ContainsKey(id))
                    {
                        Main.Logger.Log($"功法改动{id}不存在,添加{id},{gfAttr.Index},{DateFile.instance.gongFaDate[id][gfAttr.Index]},{v}");
                        var editValue = new Dictionary <int, string[]>();
                        editValue.Add(gfAttr.Index, new string[] { DateFile.instance.gongFaDate[id][gfAttr.Index], v });
                        Main.EditHostory.Add(id, editValue);
                    }
                    else
                    {
                        if (!Main.EditHostory[id].ContainsKey(gfAttr.Index))
                        {
                            Main.Logger.Log($"功法改动{id}存在,但不存在{gfAttr.Index}的改动,添加{gfAttr.Index},{DateFile.instance.gongFaDate[id][gfAttr.Index]},{v}");
                            Main.EditHostory[id].Add(gfAttr.Index, new string[] { DateFile.instance.gongFaDate[id][gfAttr.Index], v });
                        }
                        else
                        {
                            Main.Logger.Log($"功法改动{id}和{gfAttr.Index}存在,更改({Main.EditHostory[id][gfAttr.Index][1]})->({v})");
                            Main.EditHostory[id][gfAttr.Index][1] = v;
                        }
                    }
                    DateFile.instance.gongFaDate[id][gfAttr.Index] = v;
                    item.SetValue(c_gongfa, DataConvert(v, item.PropertyType), null);

                    //if (!ChangedGongFa.ContainsKey(id))
                    //{
                    //    ChangedGongFa.Add(id, c_gongfa);
                    //}
                    //else
                    //{
                    //    ChangedGongFa[id] = c_gongfa;
                    //}
                });
            }
        }
    }