Exemplo n.º 1
0
        public void UpdateFieldsList()
        {
            var oldList = new List <StringFieldValue>(Data.Values.ToArray());

            var fields = new List <StringField>();
            var paths  = UnityEditor.AssetDatabase.FindAssets("t: StringField");

            foreach (var m in paths)
            {
                fields.Add(UnityEditor.AssetDatabase.LoadAssetAtPath <StringField>(UnityEditor.AssetDatabase.GUIDToAssetPath(m)));
            }

            fields.Sort((a, b) => { return(a.Id.CompareTo(b.Id)); });

            Data.Values.Clear();

            foreach (var field in fields)
            {
                var e = oldList.FirstOrDefault(p => p.Field == field);
                if (e != null)
                {
                    Data.Values.Add(e);
                }
                else
                {
                    var n = new StringFieldValue()
                    {
                        Field = field, value = field.defaultValue
                    };
                    Data.Values.Add(n);
                }
            }
        }
Exemplo n.º 2
0
        public void DeserializeLanguageSet(string filePath)
        {
            if (File.Exists(filePath) && StringFieldManager.activeManager != null)
            {
                System.Xml.Serialization.XmlSerializer xmlSerializer = new System.Xml.Serialization.XmlSerializer(typeof(StringFieldDataModel));
                FileStream fileStream = new FileStream(filePath, FileMode.Open);
                var        data       = xmlSerializer.Deserialize(fileStream) as StringFieldDataModel;
                fileStream.Close();
                fileStream.Dispose();

                DisplayName = data.Name;
                ISOCode     = data.Code;

                var sortedFields = new List <StringField>(StringFieldManager.activeManager.availableFields);
                sortedFields.Sort((a, b) => { return(a.Id.CompareTo(b.Id)); });

                Data.Values.Clear();

                foreach (var field in sortedFields)
                {
                    var e = data.Records.FirstOrDefault(p => p.Id == field.Id);
                    if (e != null)
                    {
                        Data.Values.Add(new StringFieldValue()
                        {
                            Field = field, value = e.Value
                        });
                    }
                    else
                    {
                        var n = new StringFieldValue()
                        {
                            Field = field, value = field.defaultValue
                        };
                        Data.Values.Add(n);
                    }
                }
            }
            else
            {
                //TODO debug messages
                if (!File.Exists(filePath))
                {
                    Debug.LogError("Unable to deserialize file [" + filePath + "] no such file exists.");
                }

                if (StringFieldManager.activeManager == null)
                {
                    Debug.LogError("Unable to deserialize file [" + filePath + "] there is no active String Field Manager.");
                }
            }
        }