示例#1
0
        public string JsonFromFields()
        {
            string FullJson           = "{";
            string intermidiateResult = null;

            KAU.PlayerSystem.ICloneToIData typeTOUSeForSerialization             = null;
            Dictionary <System.Type, List <KAU.PlayerSystem.IData> > allCLonable = new Dictionary <System.Type, List <KAU.PlayerSystem.IData> >();

            System.Type typeForAnothLocationion = null;
            foreach (var item in AllFields.Keys)
            {
                typeTOUSeForSerialization = AllFields[item].bindedToAnotherLocation();
                if (typeTOUSeForSerialization == null)
                {
                    intermidiateResult = AllFields[item].ToJsonField();
                    intermidiateResult = intermidiateResult.Substring(1, intermidiateResult.Length - 2); // characters to get after
                    if (!string.IsNullOrEmpty(intermidiateResult))
                    {
                        FullJson += string.Format("{0},", intermidiateResult);
                    }
                }
                else
                {
                    typeForAnothLocationion = typeTOUSeForSerialization.GetType();
                    if (!allCLonable.ContainsKey(typeForAnothLocationion))
                    {
                        allCLonable.Add(typeForAnothLocationion, new List <KAU.PlayerSystem.IData>());
                    }
                    allCLonable[typeForAnothLocationion].Add(AllFields[item]);

                    // intermidiateResult = typeTOUSeForSerialization.ToJsonClone(AllFields[item]);
                    // intermidiateResult = intermidiateResult.Substring(1, intermidiateResult.Length - 2); // characters to get after
                    // if (!string.IsNullOrEmpty(intermidiateResult))
                    // {
                    //     Debug.Log(string.Format(" from clone {0} ", intermidiateResult));

                    //     FullJson += string.Format("{0},", intermidiateResult);
                    // }
                }
            }

            foreach (var item in allCLonable.Keys)
            {
                typeTOUSeForSerialization = allCLonable[item][0].bindedToAnotherLocation();
                intermidiateResult        = typeTOUSeForSerialization.ToJsonClone(allCLonable[item]);
                intermidiateResult        = intermidiateResult.Substring(1, intermidiateResult.Length - 2); // characters to get after
                if (!string.IsNullOrEmpty(intermidiateResult))
                {
                    // Debug.Log(string.Format(" from clone {0} ", intermidiateResult));

                    FullJson += string.Format("{0},", intermidiateResult);
                }
            }
            FullJson  = FullJson.Substring(0, FullJson.Length - 1); // get rid of last comma!
            FullJson += "}";

            return(FullJson);
        }
示例#2
0
        public void FromJsonToProperties(string jsonData)
        {
            KAU.PlayerSystem.ICloneToIData typeTOUSeForSerialization = null;
            Dictionary <KAU.PlayerSystem.ICloneToIData, List <KAU.PlayerSystem.IData> > allCLonable = new Dictionary <KAU.PlayerSystem.ICloneToIData, List <KAU.PlayerSystem.IData> >();

            // Works - even when it does't know the derived type!
            foreach (var item in AllFields.Keys)
            {
                typeTOUSeForSerialization = AllFields[item].bindedToAnotherLocation();

                if (typeTOUSeForSerialization != null)
                {
                    if (!allCLonable.ContainsKey(typeTOUSeForSerialization))
                    {
                        allCLonable.Add(typeTOUSeForSerialization, new List <KAU.PlayerSystem.IData>());
                    }
                    allCLonable[typeTOUSeForSerialization].Add(AllFields[item]);
                }
                else
                {
                    JsonUtility.FromJsonOverwrite(jsonData, AllFields[item]);
                }
            }
            // Fix for old data
            foreach (var item in allCLonable.Keys)
            {
                item.fromJsonClone(jsonData, allCLonable[item]);
            }

            // For each object in all data
            foreach (var item in AllFields.Values)
            {
                // for all root objects
                item.fixBindingAfterDeserialization(item);
            }
        }
示例#3
0
 protected IPropertyData(KAU.PlayerSystem.Hidden.IPropertyData binding, KAU.PlayerSystem.ICloneToIData bindToAnothLoc) : base(binding, bindToAnothLoc)
 {
 }