private object LoadRecordAtPath(string path, Type recordType,
                                        RecordAttribute recordAttribute)
        {
            if (path == null)
            {
                return(null);
            }
            object record;
            var    recordName = FileUtility.GetFileIdWithoutExtension(path);

            if (File.Exists(path))
            {
                var content = File.ReadAllText(path);
                record = JsonUtility.FromJson(content, recordType);
            }
            else
            {
                record = Activator.CreateInstance(recordType);
                if (recordAttribute.RecordNumberType == RecordNumberType.Singleton)
                {
                    singleRecords.Value.Add(recordType, record);
                }
                else
                {
                    ReflectionUtility.SetProperty(record,
                                                  "RecordName", recordName);
                }
                var content = YojoyEditorAgent.GetBeautifiedJson(JsonUtility.ToJson(record));
                FileUtility.WriteAllText(path, content);
            }
            return(record);
        }
Ejemplo n.º 2
0
        private void Query()
        {
            if (!targetPrefsId.IsValid())
            {
                YojoyEditorAgent.DispalyTip("The prefs id is null!");
                return;
            }
            var prefsValue = GetPrefsValue(targetPrefsId);

            if (prefsValue == null)
            {
                YojoyEditorAgent.DispalyTip("Cannot find target prefs");
                return;
            }
            targetPrefsValue = prefsValue;
        }
        /// <summary>
        /// 保存记录实例
        /// </summary>
        /// <param name="record"></param>
        /// <param name="deleteExist"></param>
        public void SaveRecord(IRecord record, bool deleteExist = false)
        {
            var recordType      = record.GetType();
            var recordAttribute = CheckMustAttribute(recordType);
            var path            = GetPath(recordType, recordAttribute,
                                          record.RecordName);

            if (File.Exists(path) && deleteExist == false)
            {
                return;
            }

            var content = YojoyEditorAgent.GetBeautifiedJson(
                JsonUtility.ToJson(record));

            FileUtility.WriteAllText(path, content);
        }